-
Notifications
You must be signed in to change notification settings - Fork 122
/
LoadEventNexus.h
235 lines (178 loc) · 8.34 KB
/
LoadEventNexus.h
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
#ifndef MANTID_DATAHANDLING_LOADEVENTNEXUS_H_
#define MANTID_DATAHANDLING_LOADEVENTNEXUS_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IFileLoader.h"
#include "MantidDataObjects/EventWorkspace.h"
#include <nexus/NeXusFile.hpp>
#include <nexus/NeXusException.hpp>
#include "MantidDataObjects/Events.h"
namespace Mantid
{
namespace DataHandling
{
/** This class defines the pulse times for a specific bank.
* Since some instruments (ARCS, VULCAN) have multiple preprocessors,
* this means that some banks have different lists of pulse times.
*/
class BankPulseTimes
{
public:
BankPulseTimes(::NeXus::File & file);
BankPulseTimes(std::vector<Kernel::DateAndTime> & times);
~BankPulseTimes();
bool equals(size_t otherNumPulse, std::string otherStartTime);
/// String describing the start time
std::string startTime;
/// Size of the array of pulse times
size_t numPulses;
/// Array of the pulse times
Kernel::DateAndTime * pulseTimes;
};
/** @class LoadEventNexus LoadEventNexus.h Nexus/LoadEventNexus.h
Load Event Nexus files.
Required Properties:
<UL>
<LI> Filename - The name of and path to the input NeXus file </LI>
<LI> Workspace - The name of the workspace to output</LI>
</UL>
@date Sep 27, 2010
Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
*/
class DLLExport LoadEventNexus : public API::IFileLoader<Kernel::NexusDescriptor>
{
public:
/// Sets documentation strings for this algorithm
virtual void initDocs();
LoadEventNexus();
virtual ~LoadEventNexus();
virtual const std::string name() const { return "LoadEventNexus";};
virtual int version() const { return 1;};
virtual const std::string category() const { return "DataHandling\\Nexus";}
/// Returns a confidence value that this algorithm can load a file
int confidence(Kernel::NexusDescriptor & descriptor) const;
/** Sets whether the pixel counts will be pre-counted.
* @param value :: true if you want to precount. */
void setPrecount(bool value)
{
precount = value;
}
public:
void init();
void exec();
/// The name and path of the input file
std::string m_filename;
/// The workspace being filled out
DataObjects::EventWorkspace_sptr WS;
/// Filter by a minimum time-of-flight
double filter_tof_min;
/// Filter by a maximum time-of-flight
double filter_tof_max;
/// Filter by start time
Kernel::DateAndTime filter_time_start;
/// Filter by stop time
Kernel::DateAndTime filter_time_stop;
/// chunk number
int chunk;
/// number of chunks
int totalChunks;
/// for multiple chunks per bank
int firstChunkForBank;
/// number of chunks per bank
size_t eventsPerChunk;
/// Was the instrument loaded?
bool instrument_loaded_correctly;
/// Limits found to tof
double longest_tof;
/// Limits found to tof
double shortest_tof;
/// Count of all the "bad" tofs found. These are events with TOF > 2e8 microsec
size_t bad_tofs;
/// A count of events discarded because they came from a pixel that's not in the IDF
size_t discarded_events;
/// Do we pre-count the # of events in each pixel ID?
bool precount;
/// Tolerance for CompressEvents; use -1 to mean don't compress.
double compressTolerance;
/// Do we load the sample logs?
bool loadlogs;
/// Pointer to the vector of events
typedef std::vector<Mantid::DataObjects::TofEvent> * EventVector_pt;
/// Vector where index = event_id; value = ptr to std::vector<TofEvent> in the event list.
std::vector<EventVector_pt> eventVectors;
/// Mutex to protect eventVectors from each task
Poco::Mutex m_eventVectorMutex;
/// Maximum (inclusive) event ID possible for this instrument
int32_t eventid_max;
/// Vector where (index = pixel ID+pixelID_to_wi_offset), value = workspace index)
std::vector<size_t> pixelID_to_wi_vector;
/// Offset in the pixelID_to_wi_vector to use.
detid_t pixelID_to_wi_offset;
/// True if the event_id is spectrum no not pixel ID
bool event_id_is_spec;
/// One entry of pulse times for each preprocessor
std::vector<BankPulseTimes*> m_bankPulseTimes;
/// Pulse times for ALL banks, taken from proton_charge log.
BankPulseTimes* m_allBanksPulseTimes;
/// Flag for dealing with a simulated file
bool m_haveWeights;
/// Pointer to the vector of weighted events
typedef std::vector<Mantid::DataObjects::WeightedEvent> * WeightedEventVector_pt;
/// Vector where index = event_id; value = ptr to std::vector<WeightedEvent> in the event list.
std::vector<WeightedEventVector_pt> weightedEventVectors;
DataObjects::EventWorkspace_sptr createEmptyEventWorkspace();
/// Map detector IDs to event lists.
template <class T>
void makeMapToEventLists(std::vector<T> & vectors);
void loadEvents(API::Progress * const prog, const bool monitors);
void createSpectraMapping(const std::string &nxsfile,
const bool monitorsOnly, const std::string & bankName = "");
void deleteBanks(API::MatrixWorkspace_sptr workspace, std::vector<std::string> bankNames);
bool hasEventMonitors();
void runLoadMonitors();
/// Set the filters on TOF.
void setTimeFilters(const bool monitors);
static void loadEntryMetadata(const std::string &nexusfilename, Mantid::API::MatrixWorkspace_sptr WS,
const std::string &entry_name);
/// Load instrument from Nexus file if possible, else from IDF spacified by Nexus file
static bool loadInstrument(const std::string &nexusfilename, API::MatrixWorkspace_sptr localWorkspace,
const std::string & top_entry_name, Algorithm * alg);
/// Load instrument for Nexus file
static bool runLoadIDFFromNexus(const std::string &nexusfilename, API::MatrixWorkspace_sptr localWorkspace, Algorithm * alg);
/// Load instrument from IDF file specified by Nexus file
static bool runLoadInstrument(const std::string &nexusfilename, API::MatrixWorkspace_sptr localWorkspace,
const std::string & top_entry_name, Algorithm * alg);
static BankPulseTimes * runLoadNexusLogs(const std::string &nexusfilename, API::MatrixWorkspace_sptr localWorkspace,
Algorithm * alg);
/// Load a spectra mapping from the given file
bool loadSpectraMapping(const std::string& filename, const bool monitorsOnly, const std::string& entry_name);
private:
// ISIS specific methods for dealing with wide events
static void loadTimeOfFlight(const std::string &nexusfilename, DataObjects::EventWorkspace_sptr WS,
const std::string &entry_name, const std::string &classType);
static void loadTimeOfFlightData(::NeXus::File& file, DataObjects::EventWorkspace_sptr WS,
const std::string& binsName,size_t start_wi = 0, size_t end_wi = 0);
public:
/// name of top level NXentry to use
std::string m_top_entry_name;
/// Set the top entry field name
void setTopEntryName();
/// whether or not to launch multiple ProcessBankData jobs per bank
bool splitProcessing;
};
} // namespace DataHandling
} // namespace Mantid
#endif /*MANTID_DATAHANDLING_LOADEVENTNEXUS_H_*/