14namespace DataHandling {
91template <
class IReader,
class IEventHandler,
class IProgress>
92void ReadEventFile(IReader &loader, IEventHandler &handler, IProgress &progress, int32_t def_clock_scale,
93 bool use_tx_chopper) {
96 if (!loader.read(
reinterpret_cast<char *
>(&hdr_base),
sizeof(hdr_base)))
97 throw std::runtime_error(
"unable to load EventFileHeader-Base");
100 if (!loader.read(
reinterpret_cast<char *
>(&hdr_packed),
sizeof(hdr_packed)))
101 throw std::runtime_error(
"unable to load EventFileHeader-Packed");
104 throw std::runtime_error(
"bad magic number");
107 char txtBuffer[255] = {};
108 snprintf(txtBuffer,
sizeof(txtBuffer),
"invalid file (only format_number=%08Xh or lower)",
110 throw std::runtime_error(txtBuffer);
114 throw std::runtime_error(
"only packed binary format is supported");
117 throw std::runtime_error(
"clock scale cannot be zero");
131 double scale_microsec = hdr_base.
clock_scale / 1000.0;
134 scale_microsec = def_clock_scale / 1000.0;
139 int64_t primary_time = 0;
140 int64_t auxillary_time = 0;
141 bool primary_ok =
false;
142 bool auxillary_ok =
false;
145 uint32_t
x = 0,
y = 0, v = 0, w = 0,
147 uint32_t *ptr_val[
NVAL] = {&
x, &
y, &v, &w, &wa};
161 int32_t nbits_val_oob[
NVAL] = {};
167 int32_t nbits_val = 0;
168 int32_t nbits_val_filled = 0;
169 int32_t nbits_dt_filled = 0;
173 int32_t oob_event = 0,
179 bool event_ended =
false;
185 if (!loader.read(
reinterpret_cast<char *
>(&ch), 1))
188 int32_t nbits_ch_used = 0;
198 oob_event = (ch & 1);
208 for (ind_val = 0; ind_val <
NVAL; ind_val++)
209 *ptr_val[ind_val] = 0;
212 nbits_val_filled = 0;
221 throw std::runtime_error(
"Failure in event decoding");
236 nbits_val_oob[0] = (ch & 0xC0) >> 3;
245 nbits_val_oob[1] = (ch & 0x03) << 3;
246 nbits_val_oob[2] = (ch & 0x0C) << 1;
247 nbits_val_oob[3] = (ch & 0x30) >> 1;
248 nbits_val_oob[4] = (ch & 0xC0) >> 3;
258 nbits_val = (oob_event ? nbits_val_oob[ind_val] : nbits_val_neutron[ind_val]);
260 nbits_val_filled = 0;
263 int32_t nbits_val_to_fill = (nbits_val - nbits_val_filled);
264 if ((8 - nbits_ch_used) >= nbits_val_to_fill) {
265 *ptr_val[ind_val] |= ((ch >> nbits_ch_used) & ((1 << nbits_val_to_fill) - 1)) << nbits_val_filled;
266 nbits_val_filled = 0;
267 nbits_ch_used += nbits_val_to_fill;
270 *ptr_val[ind_val] |= (ch >> nbits_ch_used) << nbits_val_filled;
271 nbits_val_filled += (8 - nbits_ch_used);
275 }
while ((ind_val <
NVAL) && (nbits_ch_used < 8));
281 if (nbits_ch_used == 8)
285 if ((8 - nbits_ch_used) <= 2) {
286 dt |= (ch >> nbits_ch_used) << nbits_dt_filled;
287 nbits_dt_filled += (8 - nbits_ch_used);
288 }
else if ((ch & 0xC0) == 0xC0) {
289 dt |= ((ch & 0x3F) >> nbits_ch_used) << nbits_dt_filled;
290 nbits_dt_filled += (6 - nbits_ch_used);
292 dt |= (ch >> nbits_ch_used) << nbits_dt_filled;
293 nbits_dt_filled += (8 - nbits_ch_used);
305 auxillary_time += dt;
309 bool frame_start_event = (oob_en ? (oob_event && c == -2) : (
x == 0 &&
y == 0 && dt == -1));
311 if (oob_en || !frame_start_event) {
315 if (!use_tx_chopper &&
x == 0) {
319 if (use_tx_chopper &&
x == 1) {
327 if (primary_ok && auxillary_ok)
328 handler.addEvent(
x,
y,
static_cast<double>(primary_time) * scale_microsec,
329 static_cast<double>(auxillary_time) * scale_microsec);
333 if (frame_start_event) {
346 progress.update(loader.selected_position());
constexpr int32_t EVENTFILEHEADER_BASE_MAGIC_NUMBER
constexpr int32_t EVENTFILEHEADER_BASE_FORMAT_NUMBER
void ReadEventFile(IReader &loader, IEventHandler &handler, IProgress &progress, int32_t def_clock_scale, bool use_tx_chopper)
Helper class which provides the Collimation Length for SANS instruments.
int32_t evt_stg_xy_signed