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;
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
77 const Geometry::ParameterMap &instrumentParameters() const;
79 Geometry::ParameterMap &instrumentParameters();
81 const Geometry::ParameterMap &constInstrumentParameters() const;
82 // Add parameters to the instrument parameter map
83 void populateInstrumentParameters();
84
85 void setNumberOfDetectorGroups(const size_t count) const;
86 void setDetectorGrouping(const size_t index, const std::set<detid_t> &detIDs) const;
87
89 const Sample &sample() const;
91 Sample &mutableSample();
92
94 const Run &run() const;
96 Run &mutableRun();
97 void setSharedRun(Kernel::cow_ptr<Run> run);
98 Kernel::cow_ptr<Run> sharedRun();
99
101 Kernel::Property *getLog(const std::string &log) const;
103 double getLogAsSingleValue(const std::string &log) const;
104
106 int getRunNumber() const;
108 Kernel::DeltaEMode::Type getEMode() const;
110 double getEFixed(const detid_t detID) const;
112 double getEFixed(const std::shared_ptr<const Geometry::IDetector> &detector =
113 std::shared_ptr<const Geometry::IDetector>{nullptr}) const;
114 double getEFixedGivenEMode(const std::shared_ptr<const Geometry::IDetector> &detector,
115 const Kernel::DeltaEMode::Type emode) const;
116 double getEFixedForIndirect(const std::shared_ptr<const Geometry::IDetector> &detector,
117 const std::vector<std::string> &parameterNames) const;
119 void setEFixed(const detid_t detID, const double value);
120
122 void saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument = true) const;
124 void saveExperimentInfoNexus(Nexus::File *file, bool saveInstrument, bool saveSample, bool saveLogs) const;
125
126 void loadExperimentInfoNexus(std::string const &nxFilename, Nexus::File *file, std::string &parameterStr,
127 std::string const &prefix);
128
130 void loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
132 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
134 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file);
136 void loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr);
137
140 void loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix);
142 void loadSampleAndLogInfoNexus(Nexus::File *file);
144 void readParameterMap(const std::string &parameterStr);
145
147 std::string getWorkspaceStartDate() const;
148
149 // run/experiment stat time if available, empty otherwise
150 std::string getAvailableWorkspaceStartDate() const;
151 // run end time if available, empty otherwise
152 std::string getAvailableWorkspaceEndDate() const;
153
154 const Geometry::DetectorInfo &detectorInfo() const;
155 Geometry::DetectorInfo &mutableDetectorInfo();
156
157 const SpectrumInfo &spectrumInfo() const;
158 SpectrumInfo &mutableSpectrumInfo();
159
160 const Geometry::ComponentInfo &componentInfo() const;
161 Geometry::ComponentInfo &mutableComponentInfo();
162
163 Geometry::InstrumentMetadata const &instrumentMetadata() const;
164
165 std::string getInstrumentName() const;
166
167 void invalidateSpectrumDefinition(const size_t index);
168 void updateSpectrumDefinitionIfNecessary(const size_t index) const;
169
170protected:
171 size_t numberOfDetectorGroups() const;
173 virtual void populateIfNotLoaded() const;
174
175 void setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions);
176
177 virtual void updateCachedDetectorGrouping(const size_t index) const;
179 std::shared_ptr<Geometry::ParameterMap> m_parmap;
182
183private:
185 void populateWithParameter(Geometry::ParameterMap &paramMap, Geometry::ParameterMap &paramMapForPosAndRot,
186 const std::string &name, const Geometry::XMLInstrumentParameter &paramInfo,
187 const Run &runData);
188
190 void loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName, std::string &instrumentXml);
191
193 void setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName, std::string &instrumentXml);
194
195 // Loads the xml from an instrument file with some basic error handling
196 std::string loadInstrumentXML(const std::string &filename);
197
202
204 mutable std::unordered_map<detid_t, size_t> m_det2group;
205 void cacheDefaultDetectorGrouping() const; // Not thread-safe
206 void invalidateAllSpectrumDefinitions();
207 mutable std::once_flag m_defaultDetectorGroupingCached;
208
209 mutable std::unique_ptr<Beamline::SpectrumInfo> m_spectrumInfo;
210 mutable std::unique_ptr<SpectrumInfo> m_spectrumInfoWrapper;
211 mutable std::mutex m_spectrumInfoMutex;
212 // This vector stores boolean flags but uses char to do so since std::vector<bool> is not thread-safe.
213 mutable std::vector<char> m_spectrumDefinitionNeedsUpdate;
214};
215
217using ExperimentInfo_sptr = std::shared_ptr<ExperimentInfo>;
218
220using ExperimentInfo_const_sptr = std::shared_ptr<const ExperimentInfo>;
221
222} // namespace API
223} // 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::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: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.
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