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;
35class ParameterMap;
37} // namespace Geometry
38
39namespace API {
40class Run;
41class Sample;
42class SpectrumInfo;
43
52class MANTID_API_DLL ExperimentInfo {
53public:
57 virtual ~ExperimentInfo();
60 ExperimentInfo &operator=(const ExperimentInfo &);
61
63 void copyExperimentInfoFrom(const ExperimentInfo *other);
65 virtual ExperimentInfo *cloneExperimentInfo() const;
66
68 const std::string toString() const;
69
71 void setInstrument(const Geometry::Instrument_const_sptr &instr);
73 Geometry::Instrument_const_sptr getInstrument() const;
74
76 const Geometry::ParameterMap &instrumentParameters() const;
78 Geometry::ParameterMap &instrumentParameters();
80 const Geometry::ParameterMap &constInstrumentParameters() const;
81 // Add parameters to the instrument parameter map
82 void populateInstrumentParameters();
83
84 void setNumberOfDetectorGroups(const size_t count) const;
85 void setDetectorGrouping(const size_t index, const std::set<detid_t> &detIDs) const;
86
88 const Sample &sample() const;
90 Sample &mutableSample();
91
93 const Run &run() const;
95 Run &mutableRun();
96 void setSharedRun(Kernel::cow_ptr<Run> run);
97 Kernel::cow_ptr<Run> sharedRun();
98
100 Kernel::Property *getLog(const std::string &log) const;
102 double getLogAsSingleValue(const std::string &log) const;
103
105 int getRunNumber() const;
107 Kernel::DeltaEMode::Type getEMode() const;
109 double getEFixed(const detid_t detID) const;
111 double getEFixed(const std::shared_ptr<const Geometry::IDetector> &detector =
112 std::shared_ptr<const Geometry::IDetector>{nullptr}) const;
113 double getEFixedGivenEMode(const std::shared_ptr<const Geometry::IDetector> &detector,
114 const Kernel::DeltaEMode::Type emode) const;
115 double getEFixedForIndirect(const std::shared_ptr<const Geometry::IDetector> &detector,
116 const std::vector<std::string> &parameterNames) const;
118 void setEFixed(const detid_t detID, const double value);
119
121 void saveExperimentInfoNexus(Nexus::File *file, bool saveLegacyInstrument = true) const;
123 void saveExperimentInfoNexus(Nexus::File *file, bool saveInstrument, bool saveSample, bool saveLogs) const;
124
125 void loadExperimentInfoNexus(std::string const &nxFilename, Nexus::File *file, std::string &parameterStr,
126 std::string const &prefix);
127
129 void loadExperimentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
131 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file, std::string &parameterStr);
133 void loadInstrumentInfoNexus(const std::string &nxFilename, Nexus::File *file);
135 void loadInstrumentParametersNexus(Nexus::File *file, std::string &parameterStr);
136
139 void loadSampleAndLogInfoNexus(Nexus::File *file, std::string const &prefix);
141 void loadSampleAndLogInfoNexus(Nexus::File *file);
143 void readParameterMap(const std::string &parameterStr);
144
146 std::string getWorkspaceStartDate() const;
147
148 // run/experiment stat time if available, empty otherwise
149 std::string getAvailableWorkspaceStartDate() const;
150 // run end time if available, empty otherwise
151 std::string getAvailableWorkspaceEndDate() const;
152
153 const Geometry::DetectorInfo &detectorInfo() const;
154 Geometry::DetectorInfo &mutableDetectorInfo();
155
156 const SpectrumInfo &spectrumInfo() const;
157 SpectrumInfo &mutableSpectrumInfo();
158
159 const Geometry::ComponentInfo &componentInfo() const;
160 Geometry::ComponentInfo &mutableComponentInfo();
161
162 void invalidateSpectrumDefinition(const size_t index);
163 void updateSpectrumDefinitionIfNecessary(const size_t index) const;
164
165protected:
166 size_t numberOfDetectorGroups() const;
168 virtual void populateIfNotLoaded() const;
169
170 void setSpectrumDefinitions(Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions);
171
172 virtual void updateCachedDetectorGrouping(const size_t index) const;
174 std::shared_ptr<Geometry::ParameterMap> m_parmap;
177
178private:
180 void populateWithParameter(Geometry::ParameterMap &paramMap, Geometry::ParameterMap &paramMapForPosAndRot,
181 const std::string &name, const Geometry::XMLInstrumentParameter &paramInfo,
182 const Run &runData);
183
185 void loadEmbeddedInstrumentInfoNexus(Nexus::File *file, std::string &instrumentName, std::string &instrumentXml);
186
188 void setInstumentFromXML(const std::string &nxFilename, std::string &instrumentName, std::string &instrumentXml);
189
190 // Loads the xml from an instrument file with some basic error handling
191 std::string loadInstrumentXML(const std::string &filename);
192
197
199 mutable std::unordered_map<detid_t, size_t> m_det2group;
200 void cacheDefaultDetectorGrouping() const; // Not thread-safe
201 void invalidateAllSpectrumDefinitions();
202 mutable std::once_flag m_defaultDetectorGroupingCached;
203
204 mutable std::unique_ptr<Beamline::SpectrumInfo> m_spectrumInfo;
205 mutable std::unique_ptr<SpectrumInfo> m_spectrumInfoWrapper;
206 mutable std::mutex m_spectrumInfoMutex;
207 // This vector stores boolean flags but uses char to do so since std::vector<bool> is not thread-safe.
208 mutable std::vector<char> m_spectrumDefinitionNeedsUpdate;
209};
210
212using ExperimentInfo_sptr = std::shared_ptr<ExperimentInfo>;
213
215using ExperimentInfo_const_sptr = std::shared_ptr<const ExperimentInfo>;
216
217} // namespace API
218} // 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