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"
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::Nexus::NexusDescriptor &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
142 void loadSampleAndLogInfoNexus(Nexus::File *file, const Mantid::Nexus::NexusDescriptor &fileInfo,
143 const std::string &prefix);
145 void loadSampleAndLogInfoNexus(Nexus::File *file);
147 void readParameterMap(const std::string &parameterStr);
148
151 std::string getWorkspaceStartDate() const;
152
153 // run/experiment stat time if available, empty otherwise
154 std::string getAvailableWorkspaceStartDate() const;
155 // run end time if available, empty otherwise
156 std::string getAvailableWorkspaceEndDate() const;
157
158 const Geometry::DetectorInfo &detectorInfo() const;
159 Geometry::DetectorInfo &mutableDetectorInfo();
160
161 const SpectrumInfo &spectrumInfo() const;
162 SpectrumInfo &mutableSpectrumInfo();
163
164 const Geometry::ComponentInfo &componentInfo() const;
165 Geometry::ComponentInfo &mutableComponentInfo();
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
191 void loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName, std::string &instrumentXml);
192
195 void setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName, std::string &instrumentXml);
196
197 // Loads the xml from an instrument file with some basic error handling
198 std::string loadInstrumentXML(const std::string &filename);
199
204
206 mutable std::unordered_map<detid_t, size_t> m_det2group;
207 void cacheDefaultDetectorGrouping() const; // Not thread-safe
208 void invalidateAllSpectrumDefinitions();
209 mutable std::once_flag m_defaultDetectorGroupingCached;
210
211 mutable std::unique_ptr<Beamline::SpectrumInfo> m_spectrumInfo;
212 mutable std::unique_ptr<SpectrumInfo> m_spectrumInfoWrapper;
213 mutable std::mutex m_spectrumInfoMutex;
214 // This vector stores boolean flags but uses char to do so since
215 // std::vector<bool> is not thread-safe.
216 mutable std::vector<char> m_spectrumDefinitionNeedsUpdate;
217};
218
220using ExperimentInfo_sptr = std::shared_ptr<ExperimentInfo>;
221
223using ExperimentInfo_const_sptr = std::shared_ptr<const ExperimentInfo>;
224
225} // namespace API
226} // 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:35
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
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