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