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
16#include "MantidKernel/Unit.h"
17#include "MantidKernel/V3D.h"
19
20#include <mutex>
21
22namespace Mantid {
23class SpectrumDefinition;
24namespace Kernel {
25class Property;
26}
27namespace Beamline {
28class ComponentInfo;
29class DetectorInfo;
30class SpectrumInfo;
31} // namespace Beamline
32namespace Geometry {
33class ComponentInfo;
34class DetectorInfo;
35class IDetector;
36class ParameterMap;
38} // namespace Geometry
39
40namespace API {
41class Run;
42class Sample;
43class SpectrumInfo;
44
53class MANTID_API_DLL ExperimentInfo {
54public:
58 virtual ~ExperimentInfo();
61 ExperimentInfo &operator=(const ExperimentInfo &);
62
64 void copyExperimentInfoFrom(const ExperimentInfo *other);
66 virtual ExperimentInfo *cloneExperimentInfo() const;
67
69 const std::string toString() const;
70
72 void setInstrument(const Geometry::Instrument_const_sptr &instr);
74 Geometry::Instrument_const_sptr getInstrument() const;
75
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(const std::string &nxFilename, ::NeXus::File *file, std::string &parameterStr,
128 const Mantid::Kernel::NexusHDF5Descriptor &fileInfo, const std::string &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);
138 void loadInstrumentParametersNexus(::NeXus::File *file, std::string &parameterStr);
139
148 void loadSampleAndLogInfoNexus(::NeXus::File *file, const Mantid::Kernel::NexusHDF5Descriptor &fileInfo,
149 const std::string &prefix);
151 void loadSampleAndLogInfoNexus(::NeXus::File *file);
153 void readParameterMap(const std::string &parameterStr);
154
157 std::string getWorkspaceStartDate() const;
158
159 // run/experiment stat time if available, empty otherwise
160 std::string getAvailableWorkspaceStartDate() const;
161 // run end time if available, empty otherwise
162 std::string getAvailableWorkspaceEndDate() const;
163
164 const Geometry::DetectorInfo &detectorInfo() const;
165 Geometry::DetectorInfo &mutableDetectorInfo();
166
167 const SpectrumInfo &spectrumInfo() const;
168 SpectrumInfo &mutableSpectrumInfo();
169
170 const Geometry::ComponentInfo &componentInfo() const;
171 Geometry::ComponentInfo &mutableComponentInfo();
172
173 void invalidateSpectrumDefinition(const size_t index);
174 void updateSpectrumDefinitionIfNecessary(const size_t index) const;
175
176protected:
177 size_t numberOfDetectorGroups() const;
179 virtual void populateIfNotLoaded() const;
180
181 void setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions);
182
183 virtual void updateCachedDetectorGrouping(const size_t index) const;
185 std::shared_ptr<Geometry::ParameterMap> m_parmap;
188
189private:
191 void populateWithParameter(Geometry::ParameterMap &paramMap, Geometry::ParameterMap &paramMapForPosAndRot,
192 const std::string &name, const Geometry::XMLInstrumentParameter &paramInfo,
193 const Run &runData);
194
197 void loadEmbeddedInstrumentInfoNexus(::NeXus::File *file, std::string &instrumentName, std::string &instrumentXml);
198
201 void setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName, std::string &instrumentXml);
202
203 // Loads the xml from an instrument file with some basic error handling
204 std::string loadInstrumentXML(const std::string &filename);
205
210
212 mutable std::unordered_map<detid_t, size_t> m_det2group;
213 void cacheDefaultDetectorGrouping() const; // Not thread-safe
214 void invalidateAllSpectrumDefinitions();
215 mutable std::once_flag m_defaultDetectorGroupingCached;
216
217 mutable std::unique_ptr<Beamline::SpectrumInfo> m_spectrumInfo;
218 mutable std::unique_ptr<SpectrumInfo> m_spectrumInfoWrapper;
219 mutable std::mutex m_spectrumInfoMutex;
220 // This vector stores boolean flags but uses char to do so since
221 // std::vector<bool> is not thread-safe.
222 mutable std::vector<char> m_spectrumDefinitionNeedsUpdate;
223};
224
226using ExperimentInfo_sptr = std::shared_ptr<ExperimentInfo>;
227
229using ExperimentInfo_const_sptr = std::shared_ptr<const ExperimentInfo>;
230
231} // namespace API
232} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
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::unordered_map< detid_t, size_t > m_det2group
Detector grouping information.
virtual ~ExperimentInfo()
Virtual destructor.
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:38
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....
Definition: SpectrumInfo.h:53
ComponentInfo : Provides a component centric view on to the instrument.
Definition: ComponentInfo.h:40
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
Definition: DetectorInfo.h:49
Interface class for detector objects.
Definition: IDetector.h:43
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.
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