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
33 std::shared_ptr<MDAlgorithms::MDEventWSWrapper> inWSWrapper, bool ignoreZeros,
34 bool useLogTimes) {
35 m_ignoreZeros = ignoreZeros;
36 m_useLogTimes = useLogTimes;
37 m_InWS2D = WSD.getInWS();
38 // preprocessed detectors information:
39 // check if detector information has been precalculated:
40 if (!WSD.m_PreprDetTable)
41 throw(std::runtime_error("Detector information has to be precalculated "
42 "before ConvToMDBase::initialize is deployed"));
43
44 // number of valid spectra is equal to actual number of valid detectors in
45 // spectra-det map
46 m_NSpectra = WSD.m_PreprDetTable->getLogs()->getPropertyValueAsType<uint32_t>("ActualDetectorsNum");
47 m_detIDMap = WSD.m_PreprDetTable->getColVector<size_t>("detIDMap");
48 m_detID = WSD.m_PreprDetTable->getColVector<int>("DetectorID");
49
50 // set up output MD workspace wrapper
51 m_OutWSWrapper = std::move(inWSWrapper);
52 // get the index which identify the run the source workspace came from.
53 // This index will mark the workspace' events for diffetent worksapces to
54 // combine
55 m_ExpInfoIndex = WSD.getPropertyValueAsType<uint16_t>("EXP_INFO_INDEX");
56
57 m_NDims = m_OutWSWrapper->nDimensions();
58 // allocate space for single MDEvent coordinates
59 m_Coord.resize(m_NDims);
60
61 // retrieve the class which does the conversion of workspace data into MD WS
62 // coordinates;
63 m_QConverter = MDTransfFactory::Instance().create(WSD.AlgID);
64
65 // initialize the MD coordinates conversion class
66 m_QConverter->initialize(WSD);
67 // initialize units conversion which can/or can not be necessary depending on
68 // input ws/converter requested units;
70 m_UnitConversion.initialize(WSD, m_QConverter->inputUnitID(emode, m_InWS2D));
71
72 size_t n_spectra = m_InWS2D->getNumberHistograms();
73
74 // get property which controls multithreaded run. If present, this property
75 // describes number of threads (or one) deployed to run conversion
76 // (this can be for debugging or other tricky reasons)
77 m_NumThreads = -1;
78 try {
79 Kernel::Property *pProperty = m_InWS2D->run().getProperty("NUM_THREADS");
80 auto *thrProperty = dynamic_cast<Kernel::PropertyWithValue<double> *>(pProperty);
81 if (thrProperty) {
82 auto nDThrheads = double(*(thrProperty));
83 try {
84 m_NumThreads = boost::lexical_cast<int>(nDThrheads);
85 g_Log.information() << "***--> NUM_THREADS property set to: " << m_NumThreads << '\n';
86 if (m_NumThreads < 0)
87 g_Log.information() << "***--> This resets number of threads to the "
88 "number of physical cores\n ";
89 else if (m_NumThreads == 0)
90 g_Log.information() << "***--> This disables multithreading\n ";
91 else if (m_NumThreads > 0)
92 g_Log.information() << "***--> Multithreading processing will launch " << m_NumThreads << " Threads\n";
93 } catch (...) {
94 };
95 }
97 }
98
99 // Record any special coordinate system known to the description.
101
102 return n_spectra;
103}
104
107 : m_NDims(0), // wrong non-initialized
108 m_ExpInfoIndex(0), // defauld associated experiment-info index is 0
109 m_NSpectra(0), // no valid spectra by default.
110 m_NumThreads(-1), // run with all cores availible
111 m_ignoreZeros(false), // 0-s added to workspace
112 m_coordinateSystem(Mantid::Kernel::None) {}
113
118 const Mantid::API::MatrixWorkspace_sptr &underlyingWorkspace) {
119 if (m_QConverter) {
120 m_QConverter->setDisplayNormalization(mdWorkspace, underlyingWorkspace);
121 }
122}
123
124} // namespace Mantid::MDAlgorithms
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
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:136
The concrete, templated class for properties.
Base class for properties.
Definition Property.h:94
API::MatrixWorkspace_const_sptr m_InWS2D
std::vector< size_t > m_detIDMap
virtual size_t initialize(const MDWSDescription &WSD, std::shared_ptr< MDEventWSWrapper > inWSWrapper, bool ignoreZeros, bool useLogTimes=false)
method which initiates all main class variables
static Mantid::Kernel::Logger g_Log
std::vector< int32_t > m_detID
Mantid::Kernel::SpecialCoordinateSystem m_coordinateSystem
Any special coordinate system used.
virtual void setDisplayNormalization(Mantid::API::IMDEventWorkspace_sptr mdWorkspace, const Mantid::API::MatrixWorkspace_sptr &underlyingWorkspace)
Set the normalization options.
ConvToMDBase()
empty default constructor
bool m_useLogTimes
Flag to use log values corresponding to event pulse time instead of average values.
std::vector< coord_t > m_Coord
size_t m_NDims
number of target ws dimensions
std::shared_ptr< MDEventWSWrapper > m_OutWSWrapper
UnitsConversionHelper m_UnitConversion
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