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"
10
13
15#include "MantidKernel/Unit.h"
16#include "MantidKernel/V3D.h"
18
19#include <mutex>
20
21namespace Mantid {
22class SpectrumDefinition;
23namespace Kernel {
24class Property;
25}
26namespace Beamline {
27class ComponentInfo;
28class DetectorInfo;
29class SpectrumInfo;
30} // namespace Beamline
31namespace Geometry {
32class ComponentInfo;
33class DetectorInfo;
34class IDetector;
36class ParameterMap;
39} // namespace Geometry
40
41namespace API {
42class Run;
43class Sample;
44class SpectrumInfo;
45
54class MANTID_API_DLL ExperimentInfo {
55public:
59 virtual ~ExperimentInfo();
62 ExperimentInfo &operator=(const ExperimentInfo &);
63
65 void copyExperimentInfoFrom(const ExperimentInfo *other);
67 virtual ExperimentInfo *cloneExperimentInfo() const;
68
70 const std::string toString() const;
71
73 void setInstrument(const Geometry::Instrument_const_sptr &instr);
75 Geometry::Instrument_const_sptr getInstrument() const;
76
78 const Geometry::ParameterMap &instrumentParameters() const;
80 Geometry::ParameterMap &instrumentParameters();
82 const Geometry::ParameterMap &constInstrumentParameters() const;
83 // Add parameters to the instrument parameter map
84 void populateInstrumentParameters();
85
86 void setNumberOfDetectorGroups(const size_t count) const;
87 void setDetectorGrouping(const size_t index, const std::set<detid_t> &detIDs) const;
88
90 const Sample &sample() const;
92 Sample &mutableSample();
93
95 const Run &run() const;
97 Run &mutableRun();
98 void setSharedRun(Kernel::cow_ptr<Run> run);
99 Kernel::cow_ptr<Run> sharedRun();
100
102 Kernel::Property *getLog(const std::string &log) const;
104 double getLogAsSingleValue(const std::string &log) const;
105
107 int getRunNumber() const;
109 Kernel::DeltaEMode::Type getEMode() const;
111 double getEFixed(const detid_t detID) const;
113 double getEFixed(const std::shared_ptr<const Geometry::IDetector> &detector =
114 std::shared_ptr<const Geometry::IDetector>{nullptr}) const;
115 double getEFixedGivenEMode(const std::shared_ptr<const Geometry::IDetector> &detector,
116 const Kernel::DeltaEMode::Type emode) const;
117 double getEFixedForIndirect(const std::shared_ptr<const Geometry::IDetector> &detector,
118 const std::vector<std::string> &parameterNames) const;
120 void setEFixed(const detid_t detID, const double value);
121
123 void saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument = true) const;
125 void saveExperimentInfoNexus(Nexus::File *file, bool saveInstrument, bool saveSample, bool saveLogs) const;
126
127 void loadExperimentInfoNexus(std::string const &nxFilename, Nexus::File *file, std::string &parameterStr,
128 std::string const &prefix);
129
131 void loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
133 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
135 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file);
137 void loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr);
138
141 void loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix);
143 void loadSampleAndLogInfoNexus(Nexus::File *file);
145 void readParameterMap(const std::string &parameterStr);
146
148 std::string getWorkspaceStartDate() const;
149
150 // run/experiment stat time if available, empty otherwise
151 std::string getAvailableWorkspaceStartDate() const;
152 // run end time if available, empty otherwise
153 std::string getAvailableWorkspaceEndDate() const;
154
155 const Geometry::DetectorInfo &detectorInfo() const;
156 Geometry::DetectorInfo &mutableDetectorInfo();
157
158 const SpectrumInfo &spectrumInfo() const;
159 SpectrumInfo &mutableSpectrumInfo();
160
161 const Geometry::ComponentInfo &componentInfo() const;
162 Geometry::ComponentInfo &mutableComponentInfo();
163
164 Geometry::InstrumentMetadata const &instrumentMetadata() const;
165
166 std::string getInstrumentName() const;
167
168 void invalidateSpectrumDefinition(const size_t index);
169 void updateSpectrumDefinitionIfNecessary(const size_t index) const;
170
171protected:
172 size_t numberOfDetectorGroups() const;
174 virtual void populateIfNotLoaded() const;
175
176 void setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions);
177
178 virtual void updateCachedDetectorGrouping(const size_t index) const;
180 std::shared_ptr<Geometry::ParameterMap> m_parmap;
183
190 std::shared_ptr<Geometry::ComponentInfo> m_componentInfo;
191 std::shared_ptr<Geometry::DetectorInfo> m_detectorInfo;
192 std::shared_ptr<Geometry::InstrumentMetadata> m_instrumentMetadata;
193
196 void adoptBeamline();
197
198private:
200 void populateWithParameter(Geometry::ParameterMap &paramMap, Geometry::PositionAndRotationAccumulator &posAndRot,
201 const std::string &name, const Geometry::XMLInstrumentParameter &paramInfo,
202 const Run &runData);
203
205 void loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName, std::string &instrumentXml);
206
208 void setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName, std::string &instrumentXml);
209
210 // Loads the xml from an instrument file with some basic error handling
211 std::string loadInstrumentXML(const std::string &filename);
212
217
219 mutable std::unordered_map<detid_t, size_t> m_det2group;
220 void cacheDefaultDetectorGrouping() const; // Not thread-safe
221 void invalidateAllSpectrumDefinitions();
222 mutable std::once_flag m_defaultDetectorGroupingCached;
223
224 mutable std::unique_ptr<Beamline::SpectrumInfo> m_spectrumInfo;
225 mutable std::unique_ptr<SpectrumInfo> m_spectrumInfoWrapper;
226 mutable std::mutex m_spectrumInfoMutex;
227 // This vector stores boolean flags but uses char to do so since std::vector<bool> is not thread-safe.
228 mutable std::vector<char> m_spectrumDefinitionNeedsUpdate;
229};
230
232using ExperimentInfo_sptr = std::shared_ptr<ExperimentInfo>;
233
235using ExperimentInfo_const_sptr = std::shared_ptr<const ExperimentInfo>;
236
237} // namespace API
238} // namespace Mantid
std::string name
Definition Run.cpp:60
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::unordered_map< detid_t, size_t > m_det2group
Detector grouping information.
std::shared_ptr< Geometry::DetectorInfo > m_detectorInfo
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:33
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:43
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...
Base class for properties.
Definition Property.h:94
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