1 #ifndef mu2e_artdaq_core_Overlays_ArtFragment_hh
2 #define mu2e_artdaq_core_Overlays_ArtFragment_hh
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "cetlib_except/exception.h"
15 #define DATA_BLOCKS_PER_MU2E_FRAGMENT 2500
21 std::ostream &operator<<(std::ostream &, ArtFragment
const &);
26 typedef uint16_t adc_t;
28 ArtFragment(artdaq::Fragment
const &f) : artdaq_Fragment_(f) {
32 const adc_t *curPos = dataBegin();
33 if (dataBegin() != dataEnd()) {
34 while (curPos < dataEnd()) {
37 index[block_count_ - 1] = curIndex + *(curPos);
38 curIndex += *(curPos);
39 curPos = curPos + *(curPos) / 2;
46 adc_t
const *dataBegin()
const {
47 return reinterpret_cast<mu2e::ArtFragment::adc_t
const *
>(&*artdaq_Fragment_.dataBegin());
50 adc_t
const *dataEnd()
const {
51 return reinterpret_cast<mu2e::ArtFragment::adc_t
const *
>(&*artdaq_Fragment_.dataEnd());
55 size_t block_count()
const {
return block_count_; }
57 size_t byte_count()
const {
return index[block_count_ - 1]; }
60 size_t blockIndexBytes(
size_t offset)
const {
61 if (offset >= block_count()) {
63 }
else if (offset == 0) {
66 return index[offset - 1];
69 size_t blockEndBytes(
size_t offset)
const {
70 if (offset >= block_count()) {
77 size_t blockSizeBytes(
size_t offset)
const {
78 if (offset > block_count() - 1) {
80 }
else if (offset == 0) {
83 return index[offset] - index[offset - 1];
87 adc_t
const *dataAtBytes(
size_t offset)
const {
return dataBegin() + (offset / 2); }
90 adc_t
const *dataAtBlockIndex(
size_t offset)
const {
return dataAtBytes(blockIndexBytes(offset)); }
92 void printPacketAtByte(
size_t byteIdx)
const {
94 <<
"Packet Bits (128): " << std::endl;
95 for (
int adcIdx = 0; adcIdx < 8; adcIdx++) {
97 for (
int offset = 15; offset >= 0; offset--) {
98 if (((*((adc_t
const *)(dataAtBytes(byteIdx) + adcIdx))) & (1 << offset)) != 0) {
105 }
else if (offset == 0) {
106 std::cout << std::endl;
110 std::cout << std::endl;
115 artdaq::Fragment
const &artdaq_Fragment_;
117 size_t index[DATA_BLOCKS_PER_MU2E_FRAGMENT];