45 printf(
"Unit %d, trigger %d, timestamp %.3fms, tgroup %d, grpmask 0x%02x 0x%02x, complete %d, error %d\n",
91 printf(
"VF48 event: %6d, ",
eventNo);
93 for (
int i=0; i<max; i++)
95 printf(
" %4d",
modules[i]->trigger);
98 printf(
", Timestamps: ");
99 for (
int i=0; i<max; i++)
101 printf(
" %.3f",
modules[i]->timestamps[
modules[i]->tgroup]*1000.0);
126 printf(
"VF48 event: %d\n", e->
eventNo);
127 printf(
"Timestamps: \n");
130 printf(
"Unit %d: ", i);
187 printf(
"--- all buffered events ---\n");
188 for (
unsigned i=0; i<
fBuffer.size(); i++)
190 printf(
"--- end ---\n");
205 assert(num_modules > 0);
223 if (i==unit || unit<0)
230 if (i==unit || unit<0)
241 if (chan_enable_mask & (1<<i))
250 if (i==unit || unit<0)
251 fFreq[unit] = ts_freq_hz;
268 for (
unsigned i=0; i<
fBuffer.size(); i++) {
271 if (e->
modules[unit] == NULL || dup)
308 for (
unsigned i=0; i<
fBuffer.size(); i++) {
361 for (
int j=0; j<8; j++)
428 printf(
"*** Unit %d, trigger %d: Internal timestamp mismatch: group %d timestamp %.6fs should be %.6fs\n", m->
unit, m->
trigger, i, m->
timestamps[i], t),
fBadDataCount++;
436 printf(
"*** Unit %d, trigger %d: Internal trigno mismatch: group %d trigno %u should be %u\n", m->
unit, m->
trigger, i, m->
trigno[i], tn),
fBadDataCount++;
483 printf(
"to event:\n");
503 switch (w & 0xF0000000)
507 printf(
"unit %d, word %5d: 0x%08x: Unknown data\n", unit, i, w);
512 uint32_t trigNo = w & 0x00FFFFFF;
513 printf(
"unit %d, word %5d: 0x%08x: Event header: unit %d, trigger %d\n", unit, i, w, unit, trigNo);
518 uint32_t ts = w&0x00FFFFFF;
519 printf(
"unit %d, word %5d: 0x%08x: Timestamp %d\n", unit, i, w, ts);
524 int group = (w&0x70)>>4;
525 int chan = (w&0x7) | (group<<3);
526 printf(
"unit %d, word %5d: 0x%08x: Group %d, Channel %2d\n", unit, i, w, group, chan);
533 printf(
"unit %d, word %5d: 0x%08x: 64-bit padding\n", unit, i, w);
537 int sample1 = w & 0x3FFF;
538 int sample2 = (w>>16) & 0x3FFF;
539 printf(
"unit %d, word %5d: 0x%08x: samples 0x%04x 0x%04x (%d %d)\n", unit, i, w, sample1, sample2, sample1, sample2);
544 int t = w & 0x00FFFFFF;
545 printf(
"unit %d, word %5d: 0x%08x: Time %d\n", unit, i, w, t);
550 int c = w & 0x00FFFFFF;
551 printf(
"unit %d, word %5d: 0x%08x: Charge %d\n", unit, i, w, c);
556 uint32_t trigNo2 = w & 0x00FFFFFF;
557 printf(
"unit %d, word %5d: 0x%08x: Event trailer: unit %d, trigger %d\n", unit, i, w, unit, trigNo2);
580 for (
unsigned i=0; i<
fBuffer.size(); i++) {
610 for (
int i=0; i<wcount; i++)
611 printf(
"word[%d]: 0x%08x\n", i, wptr[i]);
618 static bool swap =
SWAP;
627 printf(
"UnpackVF48A: UnpackEvent unit %d, group %d, wcount %d, first word: 0x%08x, last word: 0x%08x\n", unit, group, wcount, data[0], data[wcount-1]);
638 int headerTrigNo = -1;
639 int trailerTrigNo = -1;
641 int timestampCount = 0;
642 int timestampFlag = 0;
643 uint32_t timestamp1 = 0;
644 uint32_t timestamp2 = 0;
646 for (
int i=0; i<wcount; i++)
648 uint32_t w = data[i];
651 if (((w&0xF0FFFFFF)==0xF0FFFFFF) && (w != 0xFFFFFFFF))
654 if (swap && (w != 0xdeadbeef)) {
655 uint32_t w0 = w&0x000000FF;
656 uint32_t w1 = w&0x0000FF00;
657 uint32_t w2 = w&0x00FF0000;
658 uint32_t w3 = w&0xFF000000;
659 w = (w0<<(16+8)) | (w1<<8) | (w2>>8) | (w3>>(16+8));
664 switch (w & 0xF0000000)
671 printf(
"unit %d, word %5d: 0x%08x: reading from empty EB FIFO\n", unit, i, w);
678 printf(
"unit %d, word %5d: 0x%08x: DMA marker\n", unit, i, w);
688 printf(
"unit %d, word %5d: 0x%08x: unexpected data\n", unit, i, w);
694 printf(
"*** Unit %d, group %d, trigger %d: Unexpected data at %5d: 0x%08x, skipping to next event header\n", unit, group, headerTrigNo, i, w);
701 int group = (w & 0x00000007);
704 printf(
"unit %d, word %5d: 0x%08x: switch to data from group %d\n", unit, i, w, group);
711 uint32_t trigNo = w & 0x00FFFFFF;
714 printf(
"unit %d, word %5d: 0x%08x: Event header: unit %d, group %d, trigger %d\n", unit, i, w, unit, group, trigNo);
717 if (0 && trigNo > 1) {
718 if (trigNo != c->headerTrigNo+1) {
719 printf(
"*** Unit %d, group %d, trigger %d: Out of sequence trigger %d should be %d\n", unit, group, trigNo, trigNo, c->headerTrigNo+1);
725 headerTrigNo = trigNo;
734 uint32_t ts = w&0x00FFFFFF;
737 printf(
"unit %d, word %5d: 0x%08x: Timestamp %d, count %d\n", unit, i, w, ts, timestampCount);
739 if (timestampCount == 0)
741 else if (timestampCount == 1)
744 printf(
"*** Unit %d, group %d, trigger %d: Unexpected timestamp count: %d\n", unit, group, headerTrigNo, timestampCount);
758 int cgroup = (w&0x70)>>4;
764 printf(
"*** Unit %d, group %d, trigger %d: data at %5d: 0x%08x, Invalid cgroup number %d should be zero\n", unit, group, headerTrigNo, i, w, cgroup);
772 printf(
"*** Unit %d, group %d, trigger %d: data at %5d: 0x%08x, Invalid group number %d should be zero\n", unit, group, headerTrigNo, i, w, group);
779 chan = (w&0x7) | (cgroup<<3);
782 printf(
"unit %d, word %5d: 0x%08x: Group %d, Channel %2d\n", unit, i, w, cgroup, chan);
785 printf(
"*** Unit %d, group %d, trigger %d: data at %5d: 0x%08x, Bad channel number %d\n", unit, group, headerTrigNo, i, w, chan);
791 if (timestampCount) {
792 uint64_t ts48 = timestamp1 | (((uint64_t)timestamp2) << 24);
794 if (ts48 == 0 && headerTrigNo == 1 &&
ts_first[unit][group] != 0) {
795 printf(
"*** Unit %d, group %d, trigger %d: Group %d unexpected event counter and timestamp reset!\n", unit, group, headerTrigNo, group);
802 if (ts48 == 0 && headerTrigNo == 1)
814 if (ts48 ==
ts_last[unit][cgroup])
816 printf(
"*** Unit %d, group %d, trigger %d: Group %d has invalid timestamp %d, should be more than %d\n", unit, group, headerTrigNo, group, (
int)ts48, (
int)
ts_last[unit][cgroup]);
824 double timestamp = (ts48 -
ts_first[unit][group])/
fFreq[unit];
837 if (headerTrigNo < 4) {
838 printf(
"AAA unit %d, group %d, trigNo %d, ts 0x%x 0x%x, base 0x%08x, ts %f\n", unit, group, headerTrigNo, timestamp2, timestamp1, (uint32_t)(
ts_first[unit][group]&0xFFFFFFFF), timestamp);
840 if (headerTrigNo == 2)
845 m->
trigno[cgroup] = headerTrigNo;
855 printf(
"*** Unit %d, group %d, trigger %d: Duplicate data for channel %d: already have %d samples\n", unit, group, headerTrigNo, chan, m->
channels[chan].
numSamples);
877 printf(
"unit %d, word %5d: 0x%08x: out of sequence adc samples\n", unit, i, w);
882 printf(
"*** Unit %d, group %d, trigger %d: Unexpected adc samples data at %5d: 0x%08x (no module %p or bad channel number %d)\n", unit, group, headerTrigNo, i, w, m, chan);
890 int sample1 = w & 0x3FFF;
891 int sample2 = (w>>16) & 0x3FFF;
894 printf(
"unit %d, word %5d: 0x%08x: samples %4d: 0x%04x 0x%04x (%d %d)\n", unit, i, w, cc->
numSamples, sample1, sample2, sample1, sample2);
909 printf(
"*** Previously ignored %d out of sequence adc samples\n", xc);
911 printf(
"*** Unit %d, group %d, trigger %d: Out of sequence adc samples for channel %d at %d, word 0x%08x\n", unit, group, headerTrigNo, cc->
channel, i, w);
928 printf(
"*** Unit %d group %d channel %d has too many samples: %d\n", unit, group, chan, cc->
numSamples);
940 printf(
"unit %d, word %5d: 0x%08x: out of sequence data\n", unit, i, w);
945 printf(
"*** Unit %d, group %d, trigger %d: Unexpected time data at %5d: 0x%08x (no module %p or bad channel number %d)\n", unit, group, headerTrigNo, i, w, m, chan);
955 int t = w & 0x00FFFFFF;
957 printf(
"unit %d, word %5d: 0x%08x: Time %d\n", unit, i, w, t);
967 printf(
"unit %d, word %5d: 0x%08x: out of sequence data\n", unit, i, w);
972 printf(
"*** Unit %d, group %d, trigger %d: Unexpected charge data at %5d: 0x%08x (no module %p or bad channel number %d)\n", unit, group, headerTrigNo, i, w, m, chan);
981 int charge = w & 0x00FFFFFF;
983 printf(
"unit %d, word %5d: 0x%08x: Charge %d\n", unit, i, w, charge);
985 if ((w & 0x0F000000) == 0x00000000)
986 m->
hitMask[chan>>3] = w & 0xFF;
997 printf(
"unit %d, word %5d: 0x%08x: out of sequence data\n", unit, i, w);
1002 printf(
"*** Unit %d, group %d, trigger %d: Unexpected event trailer at %5d: 0x%08x (no module %p or bad channel number %d)\n", unit, group, headerTrigNo, i, w, m, chan);
1015 uint32_t trigNo = w & 0x00FFFFFF;
1017 trailerTrigNo = trigNo;
1020 printf(
"unit %d, word %5d: 0x%08x: Event trailer: unit %d, group %d, trigger %d, module complete mask 0x%x\n", unit, i, w, unit, group, trailerTrigNo, m->
completeGroupMask);
1024 if (trigNo != (uint32_t)headerTrigNo)
1026 printf(
"*** Unit %d, group %d, trigger %d: event trailer trigger mismatch: see %d, should be %d\n", unit, group, headerTrigNo, trigNo, m->
trigger);
1046 int grp =
wgrp[unit];
1049 if (!
wbuf[unit][grp]) {
1051 wbuf[unit][grp] = (uint32_t*)malloc(
wmax[unit][grp]);
1052 assert(
wbuf[unit][grp]);
1053 wptr[unit][grp] = 0;
1054 wacc[unit][grp] =
false;
1064 const uint32_t *data32 = (
const uint32_t*)data;
1068 bool doDump =
false;
1075 for (
int i=0; i<size32; i++)
1077 uint32_t w = data32[i];
1081 if ((w & 0xFFFFFFF0) == 0xFFFFFFF0)
1083 int group = (w & 0x00000007);
1094 else if ((w & 0xF0000000) == 0x80000000)
1097 printf(
"*** Unit %d, group %d, at word %d, skipped %d words preceeding event header 0x%08x\n", unit, grp, i,
wdiscarded[unit], w);
1102 printf(
"UnpackVF48A: Header 0x%08x, unit %d, group %d, at word %d\n", w, unit, grp, i);
1105 if (
wptr[unit][grp] > 1) {
1107 wptr[unit][grp] = 0;
1110 wacc[unit][grp] =
true;
1113 wbuf[unit][grp][
wptr[unit][grp]++] = w;
1115 else if ((w & 0xF0000000) == 0xE0000000)
1117 wbuf[unit][grp][
wptr[unit][grp]++] = w;
1120 printf(
"UnpackVF48A: Trailer 0x%08x, unit %d, group %d, at word %d\n", w, unit, grp, i);
1123 if (0 &&
wptr[unit][grp] == 1) {
1124 printf(
"*** Unit %d, group %d, at word %d, lonely event trailer 0x%08x\n", unit, grp, i, w);
1128 if (
wacc[unit][grp]) {
1131 printf(
"*** Unit %d, group %d, at word %d, missing event header for trailer 0x%08x, %d data words were discarded\n", unit, grp, i, w,
wdiscarded[unit]);
1135 wptr[unit][grp] = 0;
1136 wacc[unit][grp] =
false;
1138 else if (
wacc[unit][grp])
1140 wbuf[unit][grp][
wptr[unit][grp]++] = w;
1147 if (w != 0xdeadbeef)
1148 if (w != 0xdeaddead) {
1156 printf(
"*** Unit %d, bank dump, %d words:\n", unit, size32);
void PrintEvent(const VF48event *e)
static void DumpWords(const uint32_t *wptr, int wcount)
void PrintVF48word(int unit, int i, uint32_t w)
#define VF48_MAX_CHANNELS
void SetNumModules(int num_modules)
void UnpackEvent(int module, int group, const uint32_t *data, int wcount)
void SetTsFreq(int module, double ts_freq_hz)
bool wacc[VF48_MAX_MODULES][VF48_MAX_GROUPS]
bool fChanEnabled[VF48_MAX_MODULES][VF48_MAX_CHANNELS]
unsigned fFlushIncompleteThreshold
void CompleteModule(VF48module *m)
VF48event * FindEvent(int unit, double timestamp, bool dup=false)
void SetChanEnable(int module, int grp, int chan_enable)
void CompleteEvent(VF48event *e)
void SetNumSamples(int module, int num_samples)
int wgrp[VF48_MAX_MODULES]
VF48module * FindModule(int unit, int group, double timestamp)
int wdiscarded[VF48_MAX_MODULES]
void SetModulesMask(uint32_t mask)
void SetTimestampResync(bool enable)
int wptr[VF48_MAX_MODULES][VF48_MAX_GROUPS]
double GetTsFreq(int module)
bool fTimestampResyncEnable
void SetFlushIncompleteThreshold(int threshold)
void UnpackStream(int module, const void *data_ptr, int data_size)
uint64_t ts_first[VF48_MAX_MODULES][VF48_MAX_GROUPS]
void SetCoincTime(double time_sec)
double fFreq[VF48_MAX_MODULES]
int fNumSamples[VF48_MAX_MODULES]
uint32_t fGroupEnabled[VF48_MAX_MODULES]
void AddToEvent(VF48module *m)
uint32_t * wbuf[VF48_MAX_MODULES][VF48_MAX_GROUPS]
void SetGroupEnableMask(int module, int grp_enable_mask)
uint64_t ts_last[VF48_MAX_MODULES][VF48_MAX_GROUPS]
VF48event * GetEvent(bool flush=false)
std::deque< VF48event * > fBuffer
int wmax[VF48_MAX_MODULES][VF48_MAX_GROUPS]
uint16_t samples[VF48_MAX_SAMPLES]
void PrintSummary() const
VF48module * modules[VF48_MAX_MODULES]
VF48channel channels[VF48_MAX_CHANNELS]
uint32_t completeGroupMask
uint64_t timestamp64[VF48_MAX_GROUPS]
double timestamps[VF48_MAX_GROUPS]
int presentMask[VF48_MAX_GROUPS]
uint32_t timestampGroupMask
int hitMask[VF48_MAX_GROUPS]
uint32_t trigno[VF48_MAX_GROUPS]