28 int usage(
const char* errstr =
nullptr)
31 printf(
"Error: %s\n\n", errstr);
34 printf(
"Utility for printing HLD events. 22.10.2018. S.Linev\n");
35 printf(
" hldprint source [args]\n");
36 printf(
"Following sources are supported:\n");
37 printf(
" hld://path/file.hld - HLD file reading\n");
38 printf(
" file.hld - HLD file reading (file extension MUST be '.hld')\n");
39 printf(
" dabcnode - DABC stream server\n");
40 printf(
" dabcnode:port - DABC stream server with custom port\n");
41 printf(
" mbss://dabcnode/Transport - DABC transport server\n");
42 printf(
" lmd://path/file.lmd - LMD file reading\n");
43 printf(
"Arguments:\n");
44 printf(
" -tmout value - maximal time in seconds for waiting next event (default 5)\n");
45 printf(
" -maxage value - maximal age time for events, if expired queue are cleaned (default off)\n");
46 printf(
" -num number - number of events to print, 0 - all events (default 10)\n");
47 printf(
" -all - print all events (equivalent to -num 0)\n");
48 printf(
" -skip number - number of events to skip before start printing\n");
49 printf(
" -event id - search for given event id before start printing\n");
50 printf(
" -find id - search for given trigger id before start printing\n");
51 printf(
" -sub - try to scan for subsub events (default false)\n");
52 printf(
" -stat - accumulate different kinds of statistics (default false)\n");
53 printf(
" -raw - printout of raw data (default false)\n");
54 printf(
" -onlyerr - printout only TDC data with errors\n");
55 printf(
" -cts id - printout raw data as CTS subsubevent (default none)\n");
56 printf(
" -tdc id - printout raw data as TDC subsubevent (default none)\n");
57 printf(
" -new id - printout raw data as new TDC subsubevent (default none)\n");
58 printf(
" -adc id - printout raw data as ADC subsubevent (default none)\n");
59 printf(
" -hub id - identify hub inside subevent (default none) \n");
60 printf(
" -auto - automatically assign ID for TDCs (0x0zzz or 0x1zzz) and HUBs (0x8zzz) (default false)\n");
61 printf(
" -range mask - select bits which are used to detect TDC or ADC (default 0xff)\n");
62 printf(
" -onlyraw subsubid - printout of raw data only for specified subsubevent\n");
63 printf(
" -onlytdc tdcid - printout raw data only of specified tdc subsubevent (default none)\n");
64 printf(
" -onlych chid - print only specified TDC channel (default off)\n");
65 printf(
" -onlynew subsubid - printout raw data only for specified TDC4 subsubevent\n");
66 printf(
" -onlymonitor id - printout only event/subevent created by hadaq::Monitor module (default off) \n");
67 printf(
" -skipintdc nmsg - skip in tdc first nmsgs (default 0)\n");
68 printf(
" -tot boundary - minimal allowed value for ToT (default 20 ns)\n");
69 printf(
" -stretcher value - approximate stretcher length for falling edge (default 20 ns)\n");
70 printf(
" -ignorecalibr - ignore calibration messages (default off)\n");
71 printf(
" -fullid value - printout only events with specified fullid (default all)\n");
72 printf(
" -rate - display only events and data rate\n");
73 printf(
" -bw - disable colors\n");
74 printf(
" -allepoch - epoch should be provided for each channel (default off)\n");
75 printf(
" -400 - new 400 MHz design, 12bit coarse, 9bit fine, min = 0x5, max = 0xc0\n");
76 printf(
" -340 - new 340 MHz design, 12bit coarse, 9bit fine, min = 0x5, max = 0xc0\n");
77 printf(
" -mhz value - new design with arbitrary MHz, 12bit coarse, 9bit fine, min = 0x5, max = 0xc0\n");
78 printf(
" -fine-min value - minimal fine counter value, used for liner time calibration (default 31)\n");
79 printf(
" -fine-max value - maximal fine counter value, used for liner time calibration (default 491)\n");
80 printf(
" -fine-min4 value - minimal fine counter value TDC v4, used for liner time calibration (default 28)\n");
81 printf(
" -fine-max4 value - maximal fine counter value TDC v4, used for liner time calibration (default 350)\n");
82 printf(
" -bubble - display TDC data as bubble, require 19 words in TDC subevent\n");
83 printf(
" -again [N=1] - repeat same printout N times, only for debug purposes\n\n");
84 printf(
"Example - display only data from TDC 0x1226:\n\n");
85 printf(
" hldprint localhost:6789 -num 1 -auto -onlytdc 0x1226\n\n");
86 printf(
"Show statistic over all events in HLD file:\n\n");
87 printf(
" hldprint file.hld -all -stat\n");
89 return errstr ? 1 : 0;
132 case 0:
return "header";
133 case 1:
return "ch0";
134 case 2:
return "epoch";
135 case 3:
return "nodata";
136 case 4:
return "seq";
137 case 5:
return "tot";
182 "Number of valid triggers",
183 "Number of release signals send",
184 "Number of valid timing triggers received",
185 "Valid NOtiming trigger number",
186 "Invalid trigger number",
187 "Multi timing trigger number",
188 "Spurious trigger number",
189 "Wrong readout number",
193 "Total empty channels",
221 unsigned pos = 0, last = 1, nflip = 0;
228 unsigned data = bubble[n] & 0xFFFF;
229 if (n <
BUBBLE_SIZE-1) data = data | ((bubble[n+1] & 0xFFFF) << 16);
232 if ((n==0) && ((data & 1) == 0)) {
return -1; }
234 for (
unsigned b=0;b<16;b++) {
235 if ((data & 1) != last) {
244 fliparr[pos] = nflip;
254 if ((data & 0xFF) == 0x0B) b1 = pos+3;
264 if ((data & 0xFF) == 0xD0) b2 = pos+5;
268 if (((pos ==
BUBBLE_SIZE*16 - 8)) && (b2 == 0) && ((data & 0xFF) == 0xA0))
278 if (nflip == 2)
return 0;
280 if ((nflip == 4) && (b1>0) && (b2==0)) { p1 = b1;
return 0x10; }
282 if ((nflip == 4) && (b1==0) && (b2>0)) { p2 = b2;
return 0x01; }
284 if ((nflip == 6) && (b1>0) && (b2>0)) { p1 = b1; p2 = b2;
return 0x11; }
292 if (fliparr[mid] + 1 == fliparr[p2])
return 0x20;
294 if ((fliparr[mid] + 3 == fliparr[p2]) && (b2>0)) { p2 = b2;
return 0x21; }
297 if (fliparr[p1] == fliparr[mid])
return 0x02;
299 if ((fliparr[p1] + 2 == fliparr[mid]) && (b1>0)) { p1 = b1;
return 0x12; }
311 for (
unsigned d=0;d<len;d++) {
312 unsigned origin = bubble[d], swap = 0;
313 for (
unsigned dd = 0;dd<16;++dd) {
314 swap = (swap << 1) | (origin & 1);
315 origin = origin >> 1;
330 unsigned origin = bubble[d];
331 for (
unsigned dd = 0;dd<16;++dd) {
332 if ((pos>=p1) && (pos<=p2))
333 *ptr++ = (origin & 0x1) ?
'1' :
'0';
334 origin = origin >> 1;
348 if (ix>=sz)
return false;
349 if ((len==0) || (ix + len > sz)) len = sz - ix;
351 if (prefix==0)
return false;
353 unsigned lastch = 0xFFFF;
354 unsigned bubble[190];
355 unsigned bcnt = 0, msg = 0, chid = 0;
358 for (
unsigned cnt=0;cnt<=len;cnt++,ix++) {
359 chid = 0xFFFF; msg = 0;
363 chid = (msg >> 22) & 0x7F;
366 if (chid != lastch) {
367 if (lastch != 0xFFFF) {
368 printf(
"%*s ch%02u: ", prefix,
"", lastch);
376 if ((chk & 0xF0) == 0x10) left--;
377 if ((chk & 0x0F) == 0x01) right++;
379 if (chk==0) printf(
" norm");
else
383 if (((chk & 0xF0) < 0x20) && ((chk & 0x0F) < 0x02)) {
390 printf(
"bubble data error length = %u, expected %u", bcnt,
BUBBLE_SIZE);
395 lastch = chid; bcnt = 0;
398 bubble[bcnt++] = msg & 0xFFFF;
446 if (len == 0)
return;
450 if (ix >= sz)
return;
452 if ((len==0) || (ix + len > sz)) len = sz - ix;
455 if (sz>99) wlen = 3;
else
456 if (sz>999) wlen = 4;
459 uint64_t lastepoch = 0;
460 double coarse_unit = 1./2.8e8;
461 double localtm0 = 0.;
463 char sbeg[1000], sdata[1000];
465 for (
unsigned cnt=0;cnt<len;cnt++,ix++) {
466 unsigned msg = sub->
Data(ix);
468 const char *kind =
"unckn";
472 if (prefix > 0) snprintf(sbeg,
sizeof(sbeg),
"%*s[%*u] %08x ", prefix,
"", wlen, ix, msg);
475 unsigned mode = (msg >> 27) & 0xF;
476 unsigned channel = (msg >> 21) & 0x3F;
477 unsigned coarse = (msg >> 9) & 0xFFF;
478 unsigned fine = msg & 0x1FF;
482 double localtm = ((lastepoch << 12) | coarse) * coarse_unit;
484 localtm -= coarse_unit;
488 snprintf(sdata,
sizeof(sdata),
"mode:0x%x ch:%u coarse:%u fine:%u tm0:%6.3fns", mode, channel, coarse, fine, (localtm - localtm0)*1e9);
498 unsigned major = (msg >> 24) & 0xF;
499 unsigned minor = (msg >> 20) & 0xF;
500 ttype = (msg >> 16) & 0xF;
501 unsigned trigger = msg & 0xFFFF;
502 snprintf(sdata,
sizeof(sdata),
"version:%u.%u typ:0x%x trigger:%u", major, minor, ttype, trigger);
514 unsigned eflags = (msg >> 24) & 0xF;
515 unsigned maxdc = (msg >> 20) & 0xF;
516 unsigned tptime = (msg >> 16) & 0xF;
517 unsigned freq = msg & 0xFFFF;
518 snprintf(sdata,
sizeof(sdata),
"eflags:0x%x maxdc:%u tptime:%u freq:%u", eflags, maxdc, tptime, freq);
523 unsigned cpc = (msg >> 24) & 0x7;
524 unsigned ccs = (msg >> 20) & 0xF;
525 unsigned ccdiv = (msg >> 16) & 0xF;
526 unsigned freq = msg & 0xFFFF;
527 snprintf(sdata,
sizeof(sdata),
"cpc:0x%x ccs:0x%x ccdiv:%u freq:%5.3fMHz", cpc, ccs, ccdiv, freq*1e-2);
536 unsigned platformid = (msg >> 20) & 0xff;
537 unsigned major = (msg >> 16) & 0xf;
538 unsigned minor = (msg >> 12) & 0xf;
539 unsigned sub = (msg >> 8) & 0xf;
540 unsigned numch = (msg & 0x7F) + 1;
541 snprintf(sdata,
sizeof(sdata),
"platform:0x%x version:%u.%u.%u numch:%u", platformid, major, minor, sub, numch);
548 unsigned epoch = msg & 0xFFFFFFF;
549 bool err = (msg & 0x10000000) != 0;
550 snprintf(sdata,
sizeof(sdata),
"0x%07x%s", epoch, (err ?
" errflag" :
""));
555 unsigned channel = (msg >> 21) & 0x7F;
556 unsigned coarse = (msg >> 9) & 0xFFF;
557 unsigned pattern = msg & 0x1FF;
559 double localtm = ((lastepoch << 12) | coarse) * coarse_unit;
560 unsigned mask = 0x100, cnt = 8;
561 while (((pattern & mask) == 0) && (cnt > 0)) {
565 localtm -= coarse_unit/8*cnt;
567 snprintf(sdata,
sizeof(sdata),
"ch:%u coarse:%u pattern:0x%03x tm0:%5.1f", channel, coarse, pattern, (localtm - localtm0)*1e9);
584 unsigned mode = (msg >> 21) & 0xF;
585 unsigned coarse = (msg >> 9) & 0xFFF;
586 unsigned fine = msg & 0x1FF;
587 bool isrising = (mode == 0) || (mode == 2);
589 double localtm = ((lastepoch << 12) | coarse) * coarse_unit;
591 localtm -= coarse_unit;
595 if (isrising) localtm0 = localtm;
599 snprintf(sdata,
sizeof(sdata),
"mode:0x%x coarse:%u fine:%u tm:%6.3fns", mode, coarse, fine, isrising ? localtm*1e9 : (localtm - localtm0)*1e9);
603 if (prefix > 0) printf(
"%s%s %s\n", sbeg, kind, sdata);
610 if (len == 0)
return;
621 unsigned msg0 = sub->
Data(ix);
629 if ((len==0) || (ix + len > sz)) len = sz - ix;
632 if (sz>99) wlen = 3;
else
633 if (sz>999) wlen = 4;
635 unsigned long long epoch(0);
640 bool haschannel0(
false);
641 unsigned channel(0), maxch(0), coarse(0), fine(0), ndebug(0), nheader(0), isrising(0), dkind(0), dvalue(0), rawtime(0);
642 int epoch_channel(-11);
644 static unsigned NumCh = 66;
646 double last_rising[NumCh], last_falling[NumCh];
647 int leading_trailing[NumCh], num_leading[NumCh], num_trailing[NumCh];
649 for (
unsigned n=0;n<NumCh;n++) {
652 leading_trailing[n] = 0;
658 unsigned bubble[100];
659 int bubble_len = -1, nbubble = 0;
660 unsigned bubble_ix = 0, bubble_ch = 0, bubble_eix = 0;
662 char sbuf[100], sfine[100], sbeg[100];
663 unsigned calibr[2] = { 0xffff, 0xffff };
666 const char* hdrkind =
"";
667 bool with_calibr =
false, bad_fine =
false;
669 for (
unsigned cnt=0;cnt<len;cnt++,ix++) {
670 unsigned msg = sub->
Data(ix);
674 channel = (msg >> 22) & 0x7F;
675 if (bubble_len==0) { bubble_eix = bubble_ix = ix; bubble_ch = channel; }
676 if (bubble_ch == channel) { bubble[bubble_len++] = msg & 0xFFFF; bubble_eix = ix; }
678 if ((bubble_len >= 100) || (cnt==len-1) || (channel!=bubble_ch) || (!israw && (bubble_len > 0))) {
680 printf(
"%*s[%*u..%*u] Ch:%02x bubble: ", prefix,
"", wlen, bubble_ix, wlen, bubble_eix, bubble_ch);
685 bubble_len = 0; bubble_eix = bubble_ix = ix;
686 if (bubble_ch != channel) {
688 bubble[bubble_len++] = msg & 0xFFFF;
696 snprintf(sbeg,
sizeof(sbeg),
"%*s[%*u] %08x ", prefix,
"", wlen, ix, msg);
707 if (prefix>0) printf(
"%s tdc trailer ttyp:0x%01x rnd:0x%02x err:0x%04x\n", sbeg, (msg >> 24) & 0xF, (msg >> 16) & 0xFF, msg & 0xFFFF);
711 switch ((msg >> 24) & 0x0F) {
712 case 0x01: hdrkind =
"double edges";
break;
713 case 0x0F: hdrkind =
"bubbles"; bubble_len = 0;
break;
714 default: hdrkind =
"normal";
break;
718 printf(
"%s tdc header fmt:0x01%x hwtyp:0x%02x %s\n", sbeg, ((msg >> 24) & 0x0F), ((msg >> 8) & 0xFF), hdrkind);
722 dkind = (msg >> 24) & 0x1F;
723 dvalue = msg & 0xFFFFFF;
725 if (dkind == 0x10) rawtime = dvalue;
else
727 rawtime += (dvalue << 16);
728 time_t t = (time_t) rawtime;
729 snprintf(sbuf,
sizeof(sbuf),
" design 0x%08x %s", rawtime, ctime(&t));
730 int len = strlen(sbuf);
731 if (sbuf[len-1]==10) sbuf[len-1] = 0;
732 }
else if (dkind == 0xE)
733 snprintf(sbuf,
sizeof(sbuf),
" %3.1fC", dvalue/16.);
736 printf(
"%s tdc debug 0x%02x: 0x%06x %s%s\n", sbeg, dkind, dvalue,
debug_name[dkind], sbuf);
739 epoch = msg & 0xFFFFFFF;
740 tm = (epoch << 11) *5.;
742 if (prefix > 0) printf(
"%s epoch %u tm %6.3f ns\n", sbeg, msg & 0xFFFFFFF, tm);
745 calibr[0] = msg & 0x3fff;
746 calibr[1] = (msg >> 14) & 0x3fff;
748 if ((prefix > 0) && (
onlych < 0))
749 printf(
"%s tdc calibr v1 0x%04x v2 0x%04x\n", sbeg, calibr[0], calibr[1]);
754 channel = (msg >> 22) & 0x7F;
755 if (channel == 0) haschannel0 =
true;
756 if (epoch_channel==-1) epoch_channel = channel;
757 isrising = (msg >> 11) & 0x1;
758 if (maxch<channel) maxch = channel;
759 if (channel < NumCh) {
761 num_leading[channel]++;
762 if (++leading_trailing[channel] > 1) seq_err[channel] =
true;
764 if (--leading_trailing[channel] < 0) seq_err[channel] =
true;
765 num_trailing[channel]++;
766 leading_trailing[channel] = 0;
774 coarse = (msg & 0x7FF);
775 fine = (msg >> 12) & 0x3FF;
778 coarse = (coarse << 1) | ((fine & 0x200) ? 1 : 0);
780 bad_fine = (fine == 0x1ff);
783 bad_fine = (fine == 0x3ff);
793 tm -= (fine & 0x1FF)*10e-3;
794 if (fine & 0x200) tm -= 0x800 * 5.;
797 }
else if (ncalibr<2) {
799 double corr = calibr[ncalibr++]*5./0x3ffe;
800 if (!isrising) corr*=10.;
810 last_rising[channel] = tm;
812 last_falling[channel] = tm;
813 if (last_rising[channel] > 0) {
814 double tot = last_falling[channel] - last_rising[channel];
818 last_rising[channel] = 0;
822 if ((fine >= 600) && (fine != 0x3ff))
825 snprintf(sfine,
sizeof(sfine),
"0x%03x", fine);
827 if ((prefix > 0) && ((
onlych < 0) || ((
unsigned)
onlych == channel)))
828 printf(
"%s %s ch:%2u isrising:%u tc:0x%03x tf:%s tm:%6.3f ns%s\n",
830 channel, isrising, coarse, sfine, tm - ch0tm, sbuf);
831 if ((channel==0) && (ch0tm==0)) ch0tm = tm;
834 if (prefix > 0) printf(
"%s undefined\n", sbeg);
839 if (len < 2) {
if (nheader!=1) errmask |=
tdcerr_NoData; }
else
840 if (!haschannel0 && (ndebug==0) && (nbubble==0)) errmask |=
tdcerr_MissCh0;
842 for (
unsigned n=1;n<NumCh;n++)
843 if ((num_leading[n] > 0) && (num_trailing[n] > 0))
844 if (seq_err[n] || (num_leading[n]!=num_trailing[n]))
848 if (substat->maxch < maxch) substat->maxch = maxch;
856 if ((ix>=sz) || (len==0))
return;
857 if ((len==0) || (ix + len > sz)) len = sz - ix;
859 unsigned data = sub->
Data(ix++); len--;
860 unsigned trigtype = (data & 0xFFFF);
862 unsigned nInputs = (data >> 16) & 0xf;
863 unsigned nITCInputs = (data >> 20) & 0xf;
864 unsigned bIdleDeadTime = (data >> 25) & 0x1;
865 unsigned bTriggerStats = (data >> 26) & 0x1;
866 unsigned bIncludeTimestamp = (data >> 27) & 0x1;
867 unsigned nExtTrigFlag = (data >> 28) & 0x3;
869 printf(
"%*sITC status bitmask: 0x%04x \n", prefix,
"", trigtype);
870 printf(
"%*sNumber of inputs counters: %u \n", prefix,
"", nInputs);
871 printf(
"%*sNumber of ITC counters: %u \n", prefix,
"", nITCInputs);
872 printf(
"%*sIdle/dead counter: %s\n", prefix,
"", bIdleDeadTime ?
"yes" :
"no");
873 printf(
"%*sTrigger statistic: %s\n", prefix,
"", bTriggerStats ?
"yes" :
"no");
874 printf(
"%*sTimestamp: %s\n", prefix,
"", bIncludeTimestamp ?
"yes" :
"no");
877 for (
unsigned ninp=0;ninp<nInputs;++ninp) {
878 unsigned wrd1 = sub->
Data(ix++); len--;
879 unsigned wrd2 = sub->
Data(ix++); len--;
880 printf(
"%*sInput %u level 0x%08x edge 0x%08x\n", prefix,
"", ninp, wrd1, wrd2);
883 for (
unsigned ninp=0;ninp<nITCInputs;++ninp) {
884 unsigned wrd1 = sub->
Data(ix++); len--;
885 unsigned wrd2 = sub->
Data(ix++); len--;
886 printf(
"%*sITC Input %u level 0x%08x edge 0x%08x\n", prefix,
"", ninp, wrd1, wrd2);
890 unsigned wrd1 = sub->
Data(ix++); len--;
891 unsigned wrd2 = sub->
Data(ix++); len--;
892 printf(
"%*sIdle 0x%08x dead 0x%08x time\n", prefix,
"", wrd1, wrd2);
896 unsigned wrd1 = sub->
Data(ix++); len--;
897 unsigned wrd2 = sub->
Data(ix++); len--;
898 unsigned wrd3 = sub->
Data(ix++); len--;
899 printf(
"%*sTrigger stats 0x%08x 0x%08x 0x%08x\n", prefix,
"", wrd1, wrd2, wrd3);
902 if (bIncludeTimestamp) {
903 unsigned wrd1 = sub->
Data(ix++); len--;
904 printf(
"%*sTimestamp 0x%08x\n", prefix,
"", wrd1);
907 printf(
"%*sExternal trigger flag: 0x%x ", prefix,
"", nExtTrigFlag);
908 if(nExtTrigFlag==0x1) {
909 data = sub->
Data(ix++); len--;
910 unsigned fTrigSyncId = (data & 0xFFFFFF);
911 unsigned fTrigSyncIdStatus = data >> 24;
912 printf(
"MBS VULOM syncid 0x%06x status 0x%02x\n", fTrigSyncId, fTrigSyncIdStatus);
913 }
else if(nExtTrigFlag==0x2) {
915 data = sub->
Data(ix++); len--;
916 unsigned fTrigSyncId = data;
918 data = sub->
Data(ix++); len--;
919 unsigned fTrigSyncIdStatus = data;
924 printf(
"MAINZ A2 recv syncid 0x%08x status 0x%08x\n", fTrigSyncId, fTrigSyncIdStatus);
925 }
else if(nExtTrigFlag==0x0) {
929 if (sub->
Data(ix) == 0xabad1dea) {
936 unsigned fTrigSyncId = (sub->
Data(ix+1) >> 16) & 0xffff;
937 long unsigned fTrigTm = (((uint64_t) (sub->
Data(ix+1) & 0xffff)) << 32) | sub->
Data(ix+2);
938 unsigned fSyncPulsePeriod = sub->
Data(ix+3);
939 unsigned fSyncPulseLength = sub->
Data(ix+4);
941 printf(
" id 0x%04x tm %lu period %u lentgh %u\n", fTrigSyncId, fTrigTm, fSyncPulsePeriod, fSyncPulseLength);
946 printf(
"unknown word 0x%08x found, expects 0xabad1dea\n", sub->
Data(ix));
949 printf(
" NOT RECOGNIZED!\n");
953 unsigned errmask = 0;
963 if ((ix>=sz) || (len==0))
return;
964 if ((len==0) || (ix + len > sz)) len = sz - ix;
967 if (sz>99) wlen = 3;
else
968 if (sz>999) wlen = 4;
970 for (
unsigned cnt=0;cnt<len;cnt++,ix++) {
971 unsigned msg = sub->
Data(ix);
972 if (prefix>0) printf(
"%*s[%*u] %08x ", prefix,
"", wlen, ix, msg);
980 unsigned trbSubEvSize = sub->
GetSize() / 4 - 4, ix = 0;
983 while (ix < trbSubEvSize) {
984 unsigned addr1 = sub->
Data(ix++);
985 unsigned addr2 = sub->
Data(ix++);
986 unsigned value = sub->
Data(ix++);
988 printf(
" %3d: %04x %04x = %08x\n", cnt++, addr1, addr2, value);
1005 if (std::find(
hubs.begin(),
hubs.end(),
id) !=
hubs.end())
return true;
1007 if (!
autoid || ((
id & 0xF000) != 0x8000))
return false;
1016 if (std::find(
tdcs.begin(),
tdcs.end(),
id) !=
tdcs.end())
return true;
1019 if (((
id & 0xF000) == 0x0000) || ((
id & 0xF000) == 0x1000)) {
1025 for (
unsigned n=0;n<
tdcs.size();n++)
1036 for (
unsigned n=0;n<
newtdcs.size();n++)
1052 if ((argc<2) || !strcmp(argv[1],
"-help") || !strcmp(argv[1],
"?"))
return usage();
1054 long number = 10, skip = 0, nagain = 0;
1055 unsigned find_trigid = 0, find_eventid = 0;
1056 double tmout(-1.), maxage(-1.), debug_delay(-1), mhz(400.);
1057 bool dofind =
false;
1058 unsigned tdcmask(0), ctsid(0);
1061 while (++n < argc) {
1062 if ((strcmp(argv[n],
"-num")==0) && (n+1<argc)) {
dabc::str_to_lint(argv[++n], &number); }
else
1063 if (strcmp(argv[n],
"-all")==0) { number = 0; }
else
1064 if ((strcmp(argv[n],
"-skip")==0) && (n+1<argc)) {
dabc::str_to_lint(argv[++n], &skip); }
else
1065 if ((strcmp(argv[n],
"-event")==0) && (n+1<argc)) {
dabc::str_to_uint(argv[++n], &find_eventid); dofind =
true; }
else
1066 if ((strcmp(argv[n],
"-find")==0) && (n+1<argc)) {
dabc::str_to_uint(argv[++n], &find_trigid); dofind =
true; }
else
1067 if ((strcmp(argv[n],
"-cts")==0) && (n+1<argc)) {
dabc::str_to_uint(argv[++n], &ctsid);
ctsids.push_back(ctsid); }
else
1068 if ((strcmp(argv[n],
"-tdc")==0) && (n+1<argc)) {
dabc::str_to_uint(argv[++n], &tdcmask);
tdcs.push_back(tdcmask); }
else
1069 if ((strcmp(argv[n],
"-new")==0) && (n+1<argc)) {
dabc::str_to_uint(argv[++n], &tdcmask);
newtdcs.push_back(tdcmask); }
else
1086 if ((strcmp(argv[n],
"-tmout")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &tmout); }
else
1087 if ((strcmp(argv[n],
"-maxage")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &maxage); }
else
1088 if ((strcmp(argv[n],
"-delay")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &debug_delay); }
else
1089 if ((strcmp(argv[n],
"-mhz")==0) && (n+1<argc)) {
1093 if (strcmp(argv[n],
"-bubble")==0) {
bubble_mode =
true; }
else
1096 if (strcmp(argv[n],
"-onlyerr")==0) {
only_errors =
true; }
else
1097 if (strcmp(argv[n],
"-raw")==0) {
printraw =
true; }
else
1098 if (strcmp(argv[n],
"-sub")==0) {
printsub =
true; }
else
1099 if (strcmp(argv[n],
"-auto")==0) {
autoid =
true;
printsub =
true; }
else
1100 if (strcmp(argv[n],
"-stat")==0) {
dostat =
true; }
else
1102 if (strcmp(argv[n],
"-bw")==0) {
use_colors =
false; }
else
1103 if (strcmp(argv[n],
"-sub")==0) {
printsub =
true; }
else
1104 if (strcmp(argv[n],
"-ignorecalibr")==0) {
use_calibr =
false; }
else
1107 if ((strcmp(argv[n],
"-help")==0) || (strcmp(argv[n],
"?")==0))
return usage();
else
1108 if (strcmp(argv[n],
"-again")==0) {
1109 if ((n+1 < argc) && (argv[n+1][0] !=
'-'))
dabc::str_to_lint(argv[++n], &nagain);
1112 return usage(
"Unknown option");
1117 printf(
"Try to open %s\n", argv[1]);
1120 std::string src = argv[1];
1121 if ((src.find(
".hld") != std::string::npos) && (src.find(
"hld://") != 0)) {
1122 src = std::string(
"hld://") + src;
1126 if ((src.find(
"hld://") == 0) || (src.find(
".hld") != std::string::npos)) ishld =
true;
1128 if (tmout < 0) tmout = ishld ? 0.5 : 5.;
1136 src = std::string(
"mbss://") + src;
1150 std::map<unsigned,SubevStat> idstat;
1151 std::map<unsigned,SubevStat> substat;
1152 std::map<unsigned,SubevStat> subsubstat;
1153 long cnt(0), cnt0(0), lastcnt(0), printcnt(0);
1154 uint64_t lastsz{0}, currsz{0};
1161 while (nagain-- >= 0) {
1165 if (ref.
null())
return 1;
1170 cnt = cnt0 = lastcnt = printcnt = 0;
1171 lastsz = currsz = 0;
1176 evnt = ref.
NextEvent(maxage > 0 ? maxage/2. : 1., maxage);
1195 }
else if (curr - lastevtm > tmout) {
1202 double tm = curr - last;
1205 printf(
"\rTm:%6.1fs Ev:%8ld Rate:%8.2f Ev/s %6.2f MB/s", first.
SpentTillNow(), cnt, (cnt-lastcnt)/tm, (currsz-lastsz)/tm/1024./1024.);
1216 if (!evnt)
continue;
1218 if (skip>0) { skip--;
continue; }
1222 if (evnt->
GetSeqNr() != find_eventid)
continue;
1225 if (!sub || (sub->GetTrigNr() != find_trigid))
continue;
1232 bool print_header(
false);
1235 print_header =
true;
1244 bool print_sub_header(
false);
1247 print_sub_header =
true;
1250 unsigned trbSubEvSize = sub->
GetSize() / 4 - 4, ix = 0,
1251 maxhublen = 0, lasthubid = 0, lasthublen = 0,
1252 maxhhublen = 0, lasthhubid = 0, lasthhublen = 0,
1253 data, datalen, datakind;
1272 if (standalone_subevnt && (ix == 0)) {
1274 datalen = trbSubEvSize - 2;
1275 datakind = sub->
GetId();
1277 data = sub->
Data(ix++);
1278 datalen = (data >> 16) & 0xFFFF;
1279 datakind = data & 0xFFFF;
1283 if (maxhhublen > 0) {
1284 if (datalen >= maxhhublen) datalen = maxhhublen-1;
1285 maxhhublen -= (datalen+1);
1290 bool as_raw =
false, as_cts =
false, as_tdc =
false, as_new =
false, as_adc =
false,
1293 if (maxhublen > 0) {
1298 subsubstat[datakind].accumulate(datalen);
1299 }
else if (!
showrate && print_subsubhdr) {
1300 printf(
" *** HHUB size %3u id 0x%04x full %08x\n", datalen, datakind, data);
1302 maxhhublen = datalen;
1303 lasthhubid = datakind;
1304 lasthhublen = datalen;
1308 if (datalen >= maxhublen) {
1309 snprintf(errbuf,
sizeof(errbuf),
" wrong format, want size 0x%04x", datalen);
1310 datalen = maxhublen-1;
1312 maxhublen -= (datalen+1);
1324 print_subsubhdr =
true;
1327 print_subsubhdr =
true;
1328 }
else if (
is_cts(datakind)) {
1330 }
else if (
is_adc(datakind)) {
1332 }
else if ((maxhublen==0) &&
is_hub(datakind)) {
1335 subsubstat[datakind].accumulate(datalen);
1336 }
else if (!
showrate && print_subsubhdr) {
1337 printf(
" *** HUB size %3u id 0x%04x full %08x\n", datalen, datakind, data);
1339 maxhublen = datalen;
1340 lasthubid = datakind;
1341 lasthublen = datalen;
1345 print_subsubhdr =
true;
1354 unsigned errmask(0);
1358 if (as_tdc)
PrintTdcData(sub, ix, datalen, 0, errmask);
1360 if (errmask==0) { ix+=datalen;
continue; }
1362 print_subsubhdr =
true;
1366 if (as_raw || as_tdc || as_new || as_adc) {
1367 if (!print_header) {
1368 print_header =
true;
1372 if (!print_sub_header) {
1375 printf(
" *** HUB size %3u id 0x%04x\n", lasthublen, lasthubid);
1377 printf(
" *** HHUB size %3u id 0x%04x\n", lasthhublen, lasthhubid);
1378 print_sub_header =
true;
1383 if (lasthhubid!=0) prefix = 15;
else if (lasthubid!=0) prefix = 12;
1386 if (
printraw &&
autoid && as_tdc) { as_tdc =
false; as_raw =
true; }
1388 if (print_subsubhdr) {
1389 const char *kind =
"Subsubevent";
1390 if (as_tdc) kind =
"TDC ";
else
1391 if (as_new) kind =
"TDC ";
else
1392 if (as_cts) kind =
"CTS ";
else
1393 if (as_adc) kind =
"ADC ";
1395 printf(
"%*s*** %s size %3u id 0x%04x", prefix-3,
"", kind, datalen, datakind);
1396 if(standalone_subevnt && (ix == 0))
1399 printf(
" full %08x", data);
1400 printf(
"%s\n", errbuf);
1403 if (as_tdc)
PrintTdcData(sub, ix, datalen, prefix, errmask);
else
1405 if (as_adc)
PrintAdcData(sub, ix, datalen, prefix);
else
1406 if (as_cts)
PrintCtsData(sub, ix, datalen, prefix);
else
1413 if (errmask & mask) printf(
" err_%s",
TdcErrName(n));
1418 SubevStat &substat = subsubstat[datakind];
1423 substat.
istdc =
true;
1424 unsigned errmask(0);
1436 if ((number>0) && (printcnt>=number))
break;
1447 printf(
"Statistic: %ld events analyzed\n", printcnt);
1450 if (printcnt > 1000) width = 6;
1452 printf(
" Events ids:\n");
1453 for (
auto &entry : idstat)
1454 printf(
" 0x%04x : cnt %*lu averlen %6.1f\n", entry.first, width, entry.second.num, entry.second.aver_size());
1456 printf(
" Subevents ids:\n");
1457 for (
auto &entry : substat)
1458 printf(
" 0x%04x : cnt %*lu averlen %6.1f\n", entry.first, width, entry.second.num, entry.second.aver_size());
1460 printf(
" Subsubevents ids:\n");
1461 for (
auto &entry : subsubstat) {
1464 printf(
" 0x%04x : cnt %*lu averlen %6.1f", entry.first, width, substat.
num, substat.
aver_size());
1466 if (substat.
istdc) {
1467 printf(
" TDC ch:%2u", substat.
maxch);
1468 for (
unsigned n=0;n<substat.
tdcerr.size();n++)
1469 if (substat.
tdcerr[n] > 0) {
Uniform Resource Locator interpreter.
bool HasOption(const std::string &optname) const
std::string GetProtocol() const
std::string GetOptions() const
hadaq::RawEvent * NextEvent(double tm=1.0, double maxage=-1.)
Retrieve next event from the server.
bool null() const
Return true if handle not initialized.
bool Disconnect()
Disconnect from MBS server.
static ReadoutHandle Connect(const std::string &url)
Connect with data source.
const char * TdcErrName(int cnt)
int main(int argc, char *argv[])
int usage(const char *errstr=nullptr)
const char * getCol(const char *col_name)
void PrintAdcData(hadaq::RawSubevent *sub, unsigned ix, unsigned len, unsigned prefix)
std::vector< unsigned > newtdcs
void PrintBubble(unsigned *bubble, unsigned len=0)
void PrintTdcData(hadaq::RawSubevent *sub, unsigned ix, unsigned len, unsigned prefix, unsigned &errmask, SubevStat *substat=nullptr)
void PrintCtsData(hadaq::RawSubevent *sub, unsigned ix, unsigned len, unsigned prefix)
bool is_newtdc(unsigned id)
const char * debug_name[32]
void PrintMonitorData(hadaq::RawSubevent *sub)
std::vector< unsigned > ctsids
void PrintTdc4Data(hadaq::RawSubevent *sub, unsigned ix, unsigned len, unsigned prefix)
std::vector< unsigned > tdcs
unsigned BubbleCheck(unsigned *bubble, int &p1, int &p2)
void PrintBubbleBinary(unsigned *bubble, int p1=-1, int p2=-1)
unsigned skip_msgs_in_tdc
std::vector< unsigned > hubs
bool PrintBubbleData(hadaq::RawSubevent *sub, unsigned ix, unsigned len, unsigned prefix)
bool InstallSignalHandlers()
Method is used to install DABC-specific Ctrl-C handler It allows to correctly stop program execution ...
bool CtrlCPressed()
Returns true when CtrlC was pressed in handler.
bool str_to_uint(const char *val, unsigned *res)
Convert string to unsigned integer value One could use hexadecimal (in form 0xabc100) or decimal form...
bool str_to_double(const char *val, double *res)
Convert string to double value.
bool str_to_lint(const char *val, long *res)
Convert string to long integer value.
bool str_to_int(const char *val, int *res)
Convert string to integer value.
@ EvtDecoding_AloneSubevt
double tdcerr_rel(unsigned n)
void IncTdcError(unsigned id)
void accumulate(unsigned sz)
std::vector< long unsigned > tdcerr
SubevStat(const SubevStat &src)
Class for acquiring and holding timestamps.
double SpentTillNow() const
Method return time in second, spent from the time kept in TimeStamp instance If time was not set befo...
uint32_t GetDecoding() const
RawSubevent * NextSubevent(RawSubevent *prev=0)
uint32_t GetSeqNr() const
Hadaq subevent structure.
uint32_t Data(unsigned idx) const
swap-save access to any data.
void Dump(bool print_raw_data=false)
Print subevent header and optionally raw data.
unsigned Alignment() const
void PrintRawData(unsigned ix=0, unsigned len=0xffffffff, unsigned prefix=6)
Print raw data, optionally one can position and portion to print.