ExperimentInfo.h 8.58 KB
Newer Older
1
2
#ifndef MANTID_API_EXPERIMENTINFO_H_
#define MANTID_API_EXPERIMENTINFO_H_
3

4
#include "MantidAPI/DllConfig.h"
5
#include "MantidAPI/Run.h"
6
7
#include "MantidAPI/Sample.h"

8
9
#include "MantidGeometry/Instrument_fwd.h"
#include "MantidGeometry/IDetector_fwd.h"
10
#include "MantidAPI/SpectraDetectorTypes.h"
11

12
13
14
15
#include "MantidKernel/DeltaEMode.h"

#include <list>

16
17
18
19
20
21
namespace Mantid {
//---------------------------------------------------------------------------
// Forward declaration
//---------------------------------------------------------------------------
namespace Geometry {
class ParameterMap;
22
class XMLInstrumentParameter;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
}

namespace API {
//---------------------------------------------------------------------------
// Forward declaration
//---------------------------------------------------------------------------
class ChopperModel;
class ModeratorModel;

/** This class is shared by a few Workspace types
 * and holds information related to a particular experiment/run:
 *
 * - Instrument (with parameter map)
 * - Run object (sample logs)
 * - Sample object (sample info)
 *
 */
class MANTID_API_DLL ExperimentInfo {
public:
  /// Default constructor
  ExperimentInfo();
  /// Virtual destructor
  virtual ~ExperimentInfo();
  /// Copy constructor
  ExperimentInfo(const ExperimentInfo &);
  /// Copy everything from the given experiment object
  void copyExperimentInfoFrom(const ExperimentInfo *other);
  /// Clone us
51
  virtual ExperimentInfo *cloneExperimentInfo() const;
52
53

  /// Returns a string description of the object
54
  virtual const std::string toString() const;
55
56

  /// Instrument accessors
Owen Arnold's avatar
Owen Arnold committed
57
  virtual void setInstrument(const Geometry::Instrument_const_sptr &instr);
58
  /// Returns the parameterized instrument
59
  virtual Geometry::Instrument_const_sptr getInstrument() const;
60
61
62

  /// Returns the set of parameters modifying the base instrument
  /// (const-version)
63
  virtual const Geometry::ParameterMap &instrumentParameters() const;
64
  /// Returns a modifiable set of instrument parameters
65
  virtual Geometry::ParameterMap &instrumentParameters();
66
  /// Const version
67
  virtual const Geometry::ParameterMap &constInstrumentParameters() const;
68
69
70
71
  // Add parameters to the instrument parameter map
  virtual void populateInstrumentParameters();

  /// Replaces current parameter map with copy of given map
72
  virtual void replaceInstrumentParameters(const Geometry::ParameterMap &pmap);
73
  /// exchange contents of current parameter map with contents of other map)
74
  virtual void swapInstrumentParameters(Geometry::ParameterMap &pmap);
75
76

  /// Cache a lookup of grouped detIDs to member IDs
77
  virtual void cacheDetectorGroupings(const det2group_map &mapping);
78
  /// Returns the detector IDs that make up the group that this ID is part of
79
80
  virtual const std::vector<detid_t> &
  getGroupMembers(const detid_t detID) const;
81
  /// Get a detector or detector group from an ID
82
83
  virtual Geometry::IDetector_const_sptr
  getDetectorByID(const detid_t detID) const;
84
85

  /// Set an object describing the source properties and take ownership
86
  virtual void setModeratorModel(ModeratorModel *source);
87
  /// Returns a reference to the source properties object
88
  virtual ModeratorModel &moderatorModel() const;
89
90
91

  /// Set a chopper description specified by index where 0 is closest to the
  /// source
92
  virtual void setChopperModel(ChopperModel *chopper, const size_t index = 0);
93
  /// Returns a reference to a chopper description
94
  virtual ChopperModel &chopperModel(const size_t index = 0) const;
95
96

  /// Sample accessors
97
  virtual const Sample &sample() const;
98
  /// Writable version of the sample object
99
  virtual Sample &mutableSample();
100
101

  /// Run details object access
102
  virtual const Run &run() const;
103
  /// Writable version of the run object
104
  virtual Run &mutableRun();
105
  /// Access a log for this experiment.
106
  virtual Kernel::Property *getLog(const std::string &log) const;
107
  /// Access a single value from a log for this experiment.
108
  virtual double getLogAsSingleValue(const std::string &log) const;
109
110

  /// Utility method to get the run number
111
  virtual int getRunNumber() const;
112
  /// Returns the emode for this run
113
  virtual Kernel::DeltaEMode::Type getEMode() const;
114
  /// Easy access to the efixed value for this run & detector ID
115
  virtual double getEFixed(const detid_t detID) const;
116
  /// Easy access to the efixed value for this run & optional detector
117
118
119
  virtual double
  getEFixed(const Geometry::IDetector_const_sptr
                detector = Geometry::IDetector_const_sptr()) const;
120
  /// Set the efixed value for a given detector ID
121
  virtual void setEFixed(const detid_t detID, const double value);
122
123

  /// Saves this experiment description to the open NeXus file
124
  virtual void saveExperimentInfoNexus(::NeXus::File *file) const;
125
  /// Loads an experiment description from the open NeXus file
126
127
128
  virtual void loadExperimentInfoNexus(const std::string &nxFilename,
                                       ::NeXus::File *file,
                                       std::string &parameterStr);
129
  /// Load the instrument from an open NeXus file.
130
131
132
  virtual void loadInstrumentInfoNexus(const std::string &nxFilename,
                                       ::NeXus::File *file,
                                       std::string &parameterStr);
133
  /// Load the instrument from an open NeXus file without reading any parameters
134
135
136
137
138
139
  virtual void loadInstrumentInfoNexus(const std::string &nxFilename,
                                       ::NeXus::File *file);
  /// Load instrument parameters from an open Nexus file in Instument group if
  /// found there
  virtual void loadInstrumentParametersNexus(::NeXus::File *file,
                                             std::string &parameterStr);
Nick Draper's avatar
Nick Draper committed
140

141
  /// Load the sample and log info from an open NeXus file.
142
  virtual void loadSampleAndLogInfoNexus(::NeXus::File *file);
143
  /// Populate the parameter map given a string
144
  virtual void readParameterMap(const std::string &parameterStr);
145
146
147

  /// Returns the start date for this experiment (or current time if no info
  /// available)
148
  virtual std::string getWorkspaceStartDate() const;
149
150

  // run/experiment stat time if available, empty otherwise
151
  virtual std::string getAvailableWorkspaceStartDate() const;
152
  // run end time if available, empty otherwise
153
  virtual std::string getAvailableWorkspaceEndDate() const;
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

  /// Utility to retrieve the validity dates for the given IDF
  static void getValidFromTo(const std::string &IDFfilename,
                             std::string &outValidFrom,
                             std::string &outValidTo);
  /// Get the IDF using the instrument name and date
  static std::string getInstrumentFilename(const std::string &instrumentName,
                                           const std::string &date = "");

protected:
  /// Description of the source object
  boost::shared_ptr<ModeratorModel> m_moderatorModel;
  /// Description of the choppers for this experiment.
  std::list<boost::shared_ptr<ChopperModel>> m_choppers;
  /// The information on the sample environment
  boost::shared_ptr<Sample> m_sample;
  /// The run information
  boost::shared_ptr<Run> m_run;
  /// Parameters modifying the base instrument
  boost::shared_ptr<Geometry::ParameterMap> m_parmap;
  /// The base (unparametrized) instrument
  Geometry::Instrument_const_sptr sptr_instrument;

private:
  /// Fill with given instrument parameter
  void populateWithParameter(Geometry::ParameterMap &paramMap,
                             const std::string &name,
                             const Geometry::XMLInstrumentParameter &paramInfo,
                             const Run &runData);

184
185
186
187
188
  /// Attempt to load instrument embedded in Nexus file. *file must have
  /// instrument group open.
  void loadEmbeddedInstrumentInfoNexus(::NeXus::File *file,
                                       std::string &instrumentName,
                                       std::string &instrumentXML);
189

190
191
192
193
194
  /// Set the instrument given the name and XML leading from IDF file if XML
  /// string is empty
  void setInstumentFromXML(const std::string &nxFilename,
                           std::string &instrumentName,
                           std::string &instrumentXML);
195

196
197
  // Loads the xml from an instrument file with some basic error handling
  std::string loadInstrumentXML(const std::string &filename);
198
199
200
201
202
203
204
205
206
207
208
  /// Detector grouping information
  det2group_map m_detgroups;
  /// Mutex to protect against cow_ptr copying
  mutable Poco::Mutex m_mutex;
};

/// Shared pointer to ExperimentInfo
typedef boost::shared_ptr<ExperimentInfo> ExperimentInfo_sptr;

/// Shared pointer to const ExperimentInfo
typedef boost::shared_ptr<const ExperimentInfo> ExperimentInfo_const_sptr;
209
210
211
212

} // namespace Mantid
} // namespace API

213
#endif /* MANTID_API_EXPERIMENTINFO_H_ */