Mantid
Loading...
Searching...
No Matches
ConvToMDBase.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#include <utility>
8
10#include "MantidAPI/Run.h"
12
13namespace Mantid::MDAlgorithms {
14
15// logger for conversion
16Kernel::Logger ConvToMDBase::g_Log("MD-Algorithms");
17
30 std::shared_ptr<MDAlgorithms::MDEventWSWrapper> inWSWrapper, bool ignoreZeros) {
31
32 m_ignoreZeros = ignoreZeros;
33 m_InWS2D = WSD.getInWS();
34 // preprocessed detectors information:
35 // check if detector information has been precalculated:
36 if (!WSD.m_PreprDetTable)
37 throw(std::runtime_error("Detector information has to be precalculated "
38 "before ConvToMDBase::initialize is deployed"));
39
40 // number of valid spectra is equal to actual number of valid detectors in
41 // spectra-det map
42 m_NSpectra = WSD.m_PreprDetTable->getLogs()->getPropertyValueAsType<uint32_t>("ActualDetectorsNum");
43 m_detIDMap = WSD.m_PreprDetTable->getColVector<size_t>("detIDMap");
44 m_detID = WSD.m_PreprDetTable->getColVector<int>("DetectorID");
45
46 // set up output MD workspace wrapper
47 m_OutWSWrapper = std::move(inWSWrapper);
48 // get the index which identify the run the source workspace came from.
49 // This index will mark the workspace' events for diffetent worksapces to
50 // combine
51 m_ExpInfoIndex = WSD.getPropertyValueAsType<uint16_t>("EXP_INFO_INDEX");
52
53 m_NDims = m_OutWSWrapper->nDimensions();
54 // allocate space for single MDEvent coordinates
55 m_Coord.resize(m_NDims);
56
57 // retrieve the class which does the conversion of workspace data into MD WS
58 // coordinates;
60
61 // initialize the MD coordinates conversion class
62 m_QConverter->initialize(WSD);
63 // initialize units conversion which can/or can not be necessary depending on
64 // input ws/converter requested units;
66 m_UnitConversion.initialize(WSD, m_QConverter->inputUnitID(emode, m_InWS2D));
67
68 size_t n_spectra = m_InWS2D->getNumberHistograms();
69
70 // get property which controls multithreaded run. If present, this property
71 // describes number of threads (or one) deployed to run conversion
72 // (this can be for debugging or other tricky reasons)
73 m_NumThreads = -1;
74 try {
75 Kernel::Property *pProperty = m_InWS2D->run().getProperty("NUM_THREADS");
76 auto *thrProperty = dynamic_cast<Kernel::PropertyWithValue<double> *>(pProperty);
77 if (thrProperty) {
78 auto nDThrheads = double(*(thrProperty));
79 try {
80 m_NumThreads = boost::lexical_cast<int>(nDThrheads);
81 g_Log.information() << "***--> NUM_THREADS property set to: " << m_NumThreads << '\n';
82 if (m_NumThreads < 0)
83 g_Log.information() << "***--> This resets number of threads to the "
84 "number of physical cores\n ";
85 else if (m_NumThreads == 0)
86 g_Log.information() << "***--> This disables multithreading\n ";
87 else if (m_NumThreads > 0)
88 g_Log.information() << "***--> Multithreading processing will launch " << m_NumThreads << " Threads\n";
89 } catch (...) {
90 };
91 }
93 }
94
95 // Record any special coordinate system known to the description.
97
98 return n_spectra;
99}
100
103 : m_NDims(0), // wrong non-initialized
104 m_ExpInfoIndex(0), // defauld associated experiment-info index is 0
105 m_NSpectra(0), // no valid spectra by default.
106 m_NumThreads(-1), // run with all cores availible
107 m_ignoreZeros(false), // 0-s added to workspace
108 m_coordinateSystem(Mantid::Kernel::None) {}
109
114 const Mantid::API::MatrixWorkspace_sptr &underlyingWorkspace) {
115 if (m_QConverter) {
116 m_QConverter->setDisplayNormalization(mdWorkspace, underlyingWorkspace);
117 }
118}
119
120} // namespace Mantid::MDAlgorithms
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
Definition: LogManager.cpp:332
Exception for when an item is not found in a collection.
Definition: Exception.h:145
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
The concrete, templated class for properties.
Base class for properties.
Definition: Property.h:94
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
API::MatrixWorkspace_const_sptr m_InWS2D
Definition: ConvToMDBase.h:57
std::vector< size_t > m_detIDMap
Definition: ConvToMDBase.h:71
static Mantid::Kernel::Logger g_Log
Definition: ConvToMDBase.h:76
std::vector< int32_t > m_detID
Definition: ConvToMDBase.h:72
Mantid::Kernel::SpecialCoordinateSystem m_coordinateSystem
Any special coordinate system used.
Definition: ConvToMDBase.h:90
virtual void setDisplayNormalization(Mantid::API::IMDEventWorkspace_sptr mdWorkspace, const Mantid::API::MatrixWorkspace_sptr &underlyingWorkspace)
Set the normalization options.
ConvToMDBase()
empty default constructor
std::vector< coord_t > m_Coord
Definition: ConvToMDBase.h:78
virtual size_t initialize(const MDWSDescription &WSD, std::shared_ptr< MDEventWSWrapper > inWSWrapper, bool ignoreZeros)
method which initiates all main class variables
size_t m_NDims
number of target ws dimensions
Definition: ConvToMDBase.h:65
std::shared_ptr< MDEventWSWrapper > m_OutWSWrapper
Definition: ConvToMDBase.h:60
UnitsConversionHelper m_UnitConversion
Definition: ConvToMDBase.h:80
helper class describes the properties of target MD workspace, which should be obtained as the result ...
API::MatrixWorkspace_const_sptr getInWS() const
std::string AlgID
the string which describes ChildAlgorithm, used to convert source ws to target MD ws.
Mantid::Kernel::SpecialCoordinateSystem getCoordinateSystem() const
Kernel::DeltaEMode::Type getEMode() const
DataObjects::TableWorkspace_const_sptr m_PreprDetTable
void initialize(const MDWSDescription &targetWSDescr, const std::string &unitsTo, bool forceViaTOF=false)
Initialize unit conversion helper This method is interface to internal initialize method,...
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Helper class which provides the Collimation Length for SANS instruments.
Type
Define the available energy transfer modes It is important to assign enums proper numbers,...
Definition: DeltaEMode.h:29