-
Notifications
You must be signed in to change notification settings - Fork 122
/
FileBackedExperimentInfo.cpp
316 lines (278 loc) · 8.64 KB
/
FileBackedExperimentInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
//----------------------------------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------------------------------
#include "MantidAPI/FileBackedExperimentInfo.h"
#include <sstream>
#include <nexus/NeXusException.hpp>
#include <nexus/NeXusFile.hpp>
namespace Mantid {
namespace API {
namespace {
/// static logger object
Kernel::Logger g_log("FileBackedExperimentInfo");
}
/**
* Create an object based on a NeXus file and path
* @param filename The full path to the file
* @param nxpath Path to the location of the experiment information
*/
FileBackedExperimentInfo::FileBackedExperimentInfo(const std::string &filename,
const std::string &nxpath)
: ExperimentInfo(), m_loaded(false), m_filename(filename), m_nxpath(nxpath) {}
/**
* This clones the FileBackedExperimentInfo and will not cause a load
* of the information.
* @return A clone of the object.
*/
ExperimentInfo *FileBackedExperimentInfo::cloneExperimentInfo() const {
return new FileBackedExperimentInfo(*this);
}
/// @returns A human-readable description of the object
const std::string FileBackedExperimentInfo::toString() const {
populateIfNotLoaded();
return ExperimentInfo::toString();
}
/// @return A pointer to the parametrized instrument
Geometry::Instrument_const_sptr
FileBackedExperimentInfo::getInstrument() const {
populateIfNotLoaded();
return ExperimentInfo::getInstrument();
}
/**
* @return A reference to a const version of the parameter map
*/
const Geometry::ParameterMap &
FileBackedExperimentInfo::instrumentParameters() const {
populateIfNotLoaded();
return ExperimentInfo::instrumentParameters();
}
/**
* @return A reference to a non-const version of the parameter map
*/
Geometry::ParameterMap &FileBackedExperimentInfo::instrumentParameters() {
populateIfNotLoaded();
return ExperimentInfo::instrumentParameters();
}
/**
* @return A reference to a const version of the parameter map
*/
const Geometry::ParameterMap &
FileBackedExperimentInfo::constInstrumentParameters() const {
populateIfNotLoaded();
return ExperimentInfo::constInstrumentParameters();
}
/**
* Populate object with instrument parameters
*/
void FileBackedExperimentInfo::populateInstrumentParameters() {
populateIfNotLoaded();
return ExperimentInfo::populateInstrumentParameters();
}
/**
* Populate object and then replace parameter map
* @param pmap The new parameter map
*/
void FileBackedExperimentInfo::replaceInstrumentParameters(
const Geometry::ParameterMap &pmap) {
populateIfNotLoaded();
ExperimentInfo::replaceInstrumentParameters(pmap);
}
/**
* Populate object and then swap parameter map
* @param pmap The new parameter map
*/
void FileBackedExperimentInfo::swapInstrumentParameters(
Geometry::ParameterMap &pmap) {
populateIfNotLoaded();
ExperimentInfo::swapInstrumentParameters(pmap);
}
/**
* Populate the object and cache the groupings
* @param mapping A set of the detector mappings
*/
void
FileBackedExperimentInfo::cacheDetectorGroupings(const det2group_map &mapping) {
populateIfNotLoaded();
ExperimentInfo::cacheDetectorGroupings(mapping);
}
/**
* Populate the object and returns the members of the group for a given ID
* @param detID A detector ID to lookup
*/
const std::vector<detid_t> &
FileBackedExperimentInfo::getGroupMembers(const detid_t detID) const {
populateIfNotLoaded();
return ExperimentInfo::getGroupMembers(detID);
}
/**
* Populate the object and return a detector by ID
* @param detID A detector ID to lookup
*/
Geometry::IDetector_const_sptr
FileBackedExperimentInfo::getDetectorByID(const detid_t detID) const {
populateIfNotLoaded();
return ExperimentInfo::getDetectorByID(detID);
}
/**
* Populate the object and set the moderator model
* @param source A pointer to the model of the moderator
*/
void FileBackedExperimentInfo::setModeratorModel(ModeratorModel *source) {
populateIfNotLoaded();
ExperimentInfo::setModeratorModel(source);
}
/**
* @return The object governing the moderator model
*/
ModeratorModel &FileBackedExperimentInfo::moderatorModel() const {
populateIfNotLoaded();
return ExperimentInfo::moderatorModel();
}
/**
* Populate the object & set the model governing the chopper
* @param chopper The model governing the chopper
* @param index The index of the chopper
*/
void FileBackedExperimentInfo::setChopperModel(ChopperModel *chopper,
const size_t index) {
populateIfNotLoaded();
ExperimentInfo::setChopperModel(chopper, index);
}
/**
* Populate the object & return the model of the chopper
* @param index The index of the chopper
*/
ChopperModel &FileBackedExperimentInfo::chopperModel(const size_t index) const {
populateIfNotLoaded();
return ExperimentInfo::chopperModel(index);
}
/**
* Populate object and return the Sample
* @return A const reference to the Sample
*/
const Sample &FileBackedExperimentInfo::sample() const {
populateIfNotLoaded();
return ExperimentInfo::sample();
}
/**
* Populate object and return a non-const reference to the sample
* @return A non-const reference to the Sample
*/
Sample &FileBackedExperimentInfo::mutableSample() {
populateIfNotLoaded();
return ExperimentInfo::mutableSample();
}
/**
* Populate object and return a const reference to the run
* @return A const reference to the Run
*/
const Run &FileBackedExperimentInfo::run() const {
populateIfNotLoaded();
return ExperimentInfo::run();
}
/**
* Populate object and return a non-const reference to the run
* @return A non-const reference to the Run
*/
Run &FileBackedExperimentInfo::mutableRun() {
populateIfNotLoaded();
return ExperimentInfo::mutableRun();
}
/**
* Return a pointer to a log entry
* @param log A string name of the log
* @return A pointer to the log entry
*/
Kernel::Property *
FileBackedExperimentInfo::getLog(const std::string &log) const {
populateIfNotLoaded();
return ExperimentInfo::getLog(log);
}
/**
* Return a pointer to a log entry
* @param log A string name of the log
* @return A pointer to the log entry
*/
double
FileBackedExperimentInfo::getLogAsSingleValue(const std::string &log) const {
populateIfNotLoaded();
return ExperimentInfo::getLogAsSingleValue(log);
}
/**
* @return The run number
*/
int FileBackedExperimentInfo::getRunNumber() const {
populateIfNotLoaded();
return ExperimentInfo::getRunNumber();
}
/**
* @return The inelastic energy mode
*/
Kernel::DeltaEMode::Type FileBackedExperimentInfo::getEMode() const {
populateIfNotLoaded();
return ExperimentInfo::getEMode();
}
/**
* @return The efixed for a given detector
* @param detID The ID of the detector
*/
double FileBackedExperimentInfo::getEFixed(const detid_t detID) const {
populateIfNotLoaded();
return ExperimentInfo::getEFixed(detID);
}
/**
* Return the efixed value for a given detector
* @param detector The detector object
*/
double FileBackedExperimentInfo::getEFixed(
const Geometry::IDetector_const_sptr detector) const {
populateIfNotLoaded();
return ExperimentInfo::getEFixed(detector);
}
/**
* Set the efixed value for a given detector
* @param detID The ID of the detector
* @param value The value of EFixed
*/
void FileBackedExperimentInfo::setEFixed(const detid_t detID,
const double value) {
populateIfNotLoaded();
ExperimentInfo::setEFixed(detID, value);
}
//------------------------------------------------------------------------------------------------------
// Private members
//------------------------------------------------------------------------------------------------------
/**
* Check if the object has been populated and load the information if
* it has not
*/
void FileBackedExperimentInfo::populateIfNotLoaded() const {
if (m_loaded)
return;
populateFromFile();
}
/**
* Populate this object with the data from the file
*/
void FileBackedExperimentInfo::populateFromFile() const {
try {
::NeXus::File nxFile(m_filename);
nxFile.openPath(m_nxpath);
// The loadExperimentInfo calls things such as mutableSample()
// and if m_loaded is not true then this function is
// will be called recursively.
m_loaded = true;
std::string parameterStr;
const_cast<FileBackedExperimentInfo *>(this)
->loadExperimentInfoNexus(&nxFile, parameterStr);
const_cast<FileBackedExperimentInfo *>(this)
->readParameterMap(parameterStr);
} catch (::NeXus::Exception &exc) {
std::ostringstream os;
os << "Unable to load experiment information from NeXus file: "
<< exc.what() << "\n";
throw std::runtime_error(os.str());
}
}
} // namespace API
} // namespace Mantid