Mantid
Loading...
Searching...
No Matches
ExperimentInfo.h
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#pragma once
8
9#include "MantidAPI/DllConfig.h"
11
14
17
18#include <mutex>
19
20namespace Mantid {
21namespace Nexus {
22class File;
23}
24class SpectrumDefinition;
25namespace Kernel {
26class Property;
27}
28namespace Beamline {
29class ComponentInfo;
30class DetectorInfo;
31class SpectrumInfo;
32} // namespace Beamline
33namespace Geometry {
34class ComponentInfo;
35class DetectorInfo;
36class IDetector;
38class ParameterMap;
41} // namespace Geometry
42
43namespace API {
44class Run;
45class Sample;
46class SpectrumInfo;
47
56class MANTID_API_DLL ExperimentInfo {
57public:
61 virtual ~ExperimentInfo();
64 ExperimentInfo &operator=(const ExperimentInfo &);
65
67 void copyExperimentInfoFrom(const ExperimentInfo *other);
69 virtual ExperimentInfo *cloneExperimentInfo() const;
70
72 const std::string toString() const;
73
75 void setInstrument(const Geometry::Instrument_const_sptr &instr);
77 Geometry::Instrument_const_sptr getInstrument() const;
78
80 const Geometry::ParameterMap &instrumentParameters() const;
82 Geometry::ParameterMap &instrumentParameters();
84 const Geometry::ParameterMap &constInstrumentParameters() const;
85 // Add parameters to the instrument parameter map
86 void populateInstrumentParameters();
87
88 void setNumberOfDetectorGroups(const size_t count) const;
89 void setDetectorGrouping(const size_t index, const std::set<detid_t> &detIDs) const;
90
92 const Sample &sample() const;
94 Sample &mutableSample();
95
97 const Run &run() const;
99 Run &mutableRun();
100 void setSharedRun(Kernel::cow_ptr<Run> run);
101 Kernel::cow_ptr<Run> sharedRun();
102
104 Kernel::Property *getLog(const std::string &log) const;
106 double getLogAsSingleValue(const std::string &log) const;
107
109 int getRunNumber() const;
111 Kernel::DeltaEMode::Type getEMode() const;
113 double getEFixed(const detid_t detID) const;
115 double getEFixed(const std::shared_ptr<const Geometry::IDetector> &detector =
116 std::shared_ptr<const Geometry::IDetector>{nullptr}) const;
117 double getEFixedGivenEMode(const std::shared_ptr<const Geometry::IDetector> &detector,
118 const Kernel::DeltaEMode::Type emode) const;
119 double getEFixedForIndirect(const std::shared_ptr<const Geometry::IDetector> &detector,
120 const std::vector<std::string> &parameterNames) const;
122 void setEFixed(const detid_t detID, const double value);
123
125 void saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument = true) const;
127 void saveExperimentInfoNexus(Nexus::File *file, bool saveInstrument, bool saveSample, bool saveLogs) const;
128
129 void loadExperimentInfoNexus(std::string const &nxFilename, Nexus::File *file, std::string &parameterStr,
130 std::string const &prefix);
131
133 void loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
135 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
137 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file);
139 void loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr);
140
143 void loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix);
145 void loadSampleAndLogInfoNexus(Nexus::File *file);
147 void readParameterMap(const std::string &parameterStr);
148
150 std::string getWorkspaceStartDate() const;
151
152 // run/experiment stat time if available, empty otherwise
153 std::string getAvailableWorkspaceStartDate() const;
154 // run end time if available, empty otherwise
155 std::string getAvailableWorkspaceEndDate() const;
156
157 const Geometry::DetectorInfo &detectorInfo() const;
158 Geometry::DetectorInfo &mutableDetectorInfo();
159
160 const SpectrumInfo &spectrumInfo() const;
161 SpectrumInfo &mutableSpectrumInfo();
162
163 const Geometry::ComponentInfo &componentInfo() const;
164 Geometry::ComponentInfo &mutableComponentInfo();
165
168 Geometry::ComponentInfo const &baseComponentInfo() const;
169
170 Geometry::InstrumentMetadata const &instrumentMetadata() const;
171
172 std::string getInstrumentName() const;
173
174 void invalidateSpectrumDefinition(const size_t index);
175 void updateSpectrumDefinitionIfNecessary(const size_t index) const;
176
177protected:
178 size_t numberOfDetectorGroups() const;
180 virtual void populateIfNotLoaded() const;
181
182 void setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions);
183
184 virtual void updateCachedDetectorGrouping(const size_t index) const;
186 std::shared_ptr<Geometry::ParameterMap> m_parmap;
189
196 std::shared_ptr<Geometry::ComponentInfo> m_componentInfo;
197 std::shared_ptr<Geometry::DetectorInfo> m_detectorInfo;
198 std::shared_ptr<Geometry::InstrumentMetadata> m_instrumentMetadata;
199
202 void adoptBeamline();
203
204private:
206 void populateWithParameter(Geometry::ComponentInfo &compInfo, Geometry::PositionAndRotationAccumulator &posAndRot,
207 const size_t compIndex, const std::string &name,
208 const Geometry::XMLInstrumentParameter &paramInfo, const Run &runData);
209
211 void loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName, std::string &instrumentXml);
212
214 void setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName, std::string &instrumentXml);
215
216 // Loads the xml from an instrument file with some basic error handling
217 std::string loadInstrumentXML(const std::string &filename);
218
223
225 mutable std::unordered_map<detid_t, size_t> m_det2group;
226 void cacheDefaultDetectorGrouping() const; // Not thread-safe
227 void invalidateAllSpectrumDefinitions();
228 mutable std::once_flag m_defaultDetectorGroupingCached;
229
230 mutable std::unique_ptr<Beamline::SpectrumInfo> m_spectrumInfo;
231 mutable std::unique_ptr<SpectrumInfo> m_spectrumInfoWrapper;
232 mutable std::mutex m_spectrumInfoMutex;
233
237 mutable std::unique_ptr<Geometry::DetectorInfo> m_baseDetectorInfo;
238 mutable std::unique_ptr<Geometry::ComponentInfo> m_baseComponentInfo;
239 mutable std::mutex m_baseComponentInfoMutex;
240 // This vector stores boolean flags but uses char to do so since std::vector<bool> is not thread-safe.
241 mutable std::vector<char> m_spectrumDefinitionNeedsUpdate;
242};
243
245using ExperimentInfo_sptr = std::shared_ptr<ExperimentInfo>;
246
248using ExperimentInfo_const_sptr = std::shared_ptr<const ExperimentInfo>;
249
250} // namespace API
251} // namespace Mantid
252
253// Instantiated and exported by API/src/PropertyWithValue.cpp
254MANTID_API_EXTERN_TEMPLATE(Mantid::Kernel::PropertyWithValue<std::shared_ptr<Mantid::API::ExperimentInfo>>);
std::string name
Definition Run.cpp:60
MANTID_API_EXTERN_TEMPLATE(Mantid::Kernel::PropertyWithValue< std::shared_ptr< Mantid::API::ExperimentInfo > >)
double value
The value of the point.
Definition FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
int count
counter
Definition Matrix.cpp:37
This class is shared by a few Workspace types and holds information related to a particular experimen...
std::once_flag m_defaultDetectorGroupingCached
Kernel::cow_ptr< Sample > m_sample
The information on the sample environment.
std::shared_ptr< Geometry::ParameterMap > m_parmap
Parameters modifying the base instrument.
std::shared_ptr< Geometry::InstrumentMetadata > m_instrumentMetadata
std::unique_ptr< Geometry::ComponentInfo > m_baseComponentInfo
std::unordered_map< detid_t, size_t > m_det2group
Detector grouping information.
std::shared_ptr< Geometry::DetectorInfo > m_detectorInfo
std::unique_ptr< Geometry::DetectorInfo > m_baseDetectorInfo
Lazily-built 2.0 layers of the base instrument, reset whenever the instrument is set.
virtual ~ExperimentInfo()
Virtual destructor.
std::shared_ptr< Geometry::ComponentInfo > m_componentInfo
The 2.0 instrument layers, of which this object is the primary owner.
std::unique_ptr< Beamline::SpectrumInfo > m_spectrumInfo
std::unique_ptr< SpectrumInfo > m_spectrumInfoWrapper
std::vector< char > m_spectrumDefinitionNeedsUpdate
Geometry::Instrument_const_sptr sptr_instrument
The base (unparametrized) instrument.
Kernel::cow_ptr< Run > m_run
The run information.
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:36
This class stores information about the sample used in particular run.
Definition Sample.h:35
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
ComponentInfo : Provides a component centric view on to the instrument.
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
Interface class for detector objects.
Definition IDetector.h:37
InstrumentMetadata : metadata related to the entire instrument.
Parameter map iterator typedef.
Collects the position and rotation an instrument definition specifies piecemeal, so that each can be ...
This class is used to store information about parameters in XML instrument definition files and instr...
The concrete, templated class for properties.
Base class for properties.
Definition Property.h:95
Implements a copy on write data template.
Definition cow_ptr.h:41
std::shared_ptr< const ExperimentInfo > ExperimentInfo_const_sptr
Shared pointer to const ExperimentInfo.
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::string toString(const T &value)
Convert values to strings.
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