14#ifndef FDDETDATAFORMATS_INCLUDE_FDDATAFORMATS_DAPHNE_DAPHNEFRAME_HPP_
15#define FDDETDATAFORMATS_INCLUDE_FDDATAFORMATS_DAPHNE_DAPHNEFRAME_HPP_
145 inline bool is_found(
int idx )
const;
146 inline void set_found( uint8_t val,
int idx );
171 return reinterpret_cast<const word_t*
>(
this);
174 return reinterpret_cast<word_t*
>(
this);
200 inline uint16_t
get_adc(
int i)
const;
201 inline void set_adc(
int i, uint16_t val);
229 if (i < 0 || i >= s_num_adcs)
230 throw std::out_of_range(
"ADC index out of range");
233 int word_index = s_bits_per_adc * i / s_bits_per_word;
234 assert(word_index < s_num_adc_words);
236 int first_bit_position = (s_bits_per_adc * i) % s_bits_per_word;
238 int bits_from_first_word = std::min(s_bits_per_adc, s_bits_per_word - first_bit_position);
239 uint16_t adc = adc_words[word_index] >> first_bit_position;
241 if (bits_from_first_word < s_bits_per_adc) {
242 assert(word_index + 1 < s_num_adc_words);
243 adc |= adc_words[word_index + 1] << bits_from_first_word;
246 return adc & 0x3FFFu;
256 throw std::out_of_range(
"ADC index out of range");
258 throw std::out_of_range(
"ADC value out of range");
267 uint32_t mask = (1 << (first_bit_position)) - 1;
268 adc_words[word_index] = ((val << first_bit_position) & ~mask) | (
adc_words[word_index] & mask);
273 adc_words[word_index + 1] = ((val >> bits_in_first_word) & mask) | (
adc_words[word_index + 1] & ~mask);
286 if (idx < 0 || idx > 4)
287 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
288 const word_t* tw = as_words();
290 return static_cast<uint8_t
>((tw[2*idx] >> 31) & 0x1);
299 if (idx < 0 || idx > 4)
300 throw std::out_of_range(
"peak index out of range (must be 0-4)");
302 throw std::out_of_range(
"Found value out of range (must be 0-1)");
304 tw[2*idx] = (tw[2*idx] & ~(1u << 31)) | ((val & 0x1) << 31);
314 if (idx < 0 || idx > 4)
315 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
316 const word_t* tw = as_words();
317 return (tw[2*idx] >> 8) & 0x7FFFFF;
326 if (idx < 0 || idx > 4)
327 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
329 throw std::out_of_range(
"ADC_Integral value out of range (must be 0-8388607)");
331 tw[2*idx] = (tw[2*idx] & ~(0x7FFFFFu << 8)) | ((val & 0x7FFFFF) << 8);
341 if (idx < 0 || idx > 4)
342 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
343 const word_t* tw = as_words();
344 return static_cast<uint8_t
>(tw[2*idx] & 0xF);
353 if (idx < 0 || idx > 4)
354 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
356 throw std::out_of_range(
"Num_SubPeaks value out of range (must be 0-15)");
358 tw[2*idx] = (tw[2*idx] & ~0xF) | (val & 0xF);
368 if (idx < 0 || idx > 4)
369 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
370 const word_t* tw = as_words();
371 return static_cast<uint16_t
>((tw[2*idx+1] >> 23) & 0x1FF);
380 if (idx < 0 || idx > 4)
381 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
383 throw std::out_of_range(
"Time_Over_Baseline value out of range (must be 0-511)");
385 tw[2*idx+1] = (tw[2*idx+1] & ~(0x1FFu << 23)) | ((val & 0x1FF) << 23);
395 if (idx < 0 || idx > 4)
396 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
397 const word_t* tw = as_words();
398 return static_cast<uint16_t
>((tw[2*idx+1] >> 14) & 0x1FF);
408 if (idx < 0 || idx > 4)
409 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
411 throw std::out_of_range(
"Time_Peak value out of range (must be 0-511)");
413 tw[2*idx+1] = (tw[2*idx+1] & ~(0x1FFu << 14)) | ((val & 0x1FF) << 14);
423 if (idx < 0 || idx > 4)
424 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
425 const word_t* tw = as_words();
427 return static_cast<uint16_t
>(tw[2*idx+1] & 0x3FFF);
436 if (idx < 0 || idx > 4)
437 throw std::out_of_range(
"Peak index out of range (must be 0-4)");
439 throw std::out_of_range(
"ADC Max value out of range (must be 0-16383)");
441 tw[2*idx+1] = (tw[2*idx+1] & ~0x3FFFu) | (val & 0x3FFF);
459 if (idx < 0 || idx > 4)
460 throw std::out_of_range(
"Time_Start index out of range (must be 0-4)");
462 const word_t* tw = as_words();
464 int shift = 22 - 10 * idx;
465 return static_cast<uint16_t
>((tw[10] >> shift) & 0x3FF);
467 int shift = 22 - 10 * (idx - 3);
468 return static_cast<uint16_t
>((tw[11] >> shift) & 0x3FF);
486 if (idx < 0 || idx > 4)
487 throw std::out_of_range(
"Time_Start index out of range (must be 0–4)");
489 throw std::out_of_range(
"Time_Start value out of range (must be 0–1023)");
495 int shift = 22 - 10 * idx;
496 tw[10] = (tw[10] & ~(mask << shift)) | ((val & mask) << shift);
498 int shift = 22 - 10 * (idx - 3);
499 tw[11] = (tw[11] & ~(mask << shift)) | ((val & mask) << shift);