12 #include <JANA/JApplication.h>
13 #include <JANA/JFactory.h>
14 #include <JANA/JEventLoop.h>
22 #include <TDirectory.h>
26 #include <TProfile2D.h>
47 max_history_buff_size = 400;
49 char daq_block_size_title[256];
52 daq_hits_per_event =
new TProfile(
"daq_hits_per_event",
"Hits/event vs. rocid", 100, 0.5, 100.5);
53 daq_words_per_event =
new TProfile(
"daq_words_per_event",
"words/event vs. rocid", 100, 0.5, 100.5);
54 daq_event_size =
new TH1D(
"daq_event_size",
"Event size in kB", 10000, 0.0, 1.0
E3);
55 daq_block_size =
new TH1D(
"daq_block_size", daq_block_size_title, 1000, 0.0, 1.0
E3);
56 daq_event_tdiff =
new TH1D(
"daq_event_tdiff",
"Time between events", 10000, 0.0, 1.0
E1);
57 daq_words_by_type =
new TH1D(
"daq_words_by_type",
"Number of words in EVIO file by type", kNEVIOWordTypes, 0, (
double)kNEVIOWordTypes);
67 for(
int ibin=1; ibin<=kNEVIOWordTypes; ibin++)
daq_words_by_type->GetXaxis()->SetBinLabel(ibin,
" ");
70 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEVIOHeader,
"EVIO len. & header");
71 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEVIOEventNumber,
"Event Number Word");
76 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250BlockHeader,
"f250 Block Header");
77 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250BlockTrailer,
"f250 Block Trailer");
78 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250EventHeader,
"f250 Event Header");
79 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250TriggerTime,
"f250 Trigger Time");
80 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250WindowRawData,
"f250 Window Raw Data");
81 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250WindowSum,
"f250 Window Sum");
82 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseRawData,
"f250 Pulse Raw Data");
83 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseData,
"f250 Pulse Data");
84 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseIntegral,
"f250 Pulse Integral");
85 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseTime,
"f250 Pulse Time");
86 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulsePedestal,
"f250 Pulse Pedestal");
87 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250EventTrailer,
"f250 Event Trailer");
88 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250DataNotValid,
"f250 Data Not Valid");
92 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125BlockHeader,
"f125 Block Header");
93 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125BlockTrailer,
"f125 Block Trailer");
94 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125EventHeader,
"f125 Event Header");
95 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125TriggerTime,
"f125 Trigger Time");
96 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125WindowRawData,
"f125 Window Raw Data");
98 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125FDCPulse6,
"f125 FDC Pulse (integral)");
99 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125FDCPulse9,
"f125 FDC Pulse (peak)");
100 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulseIntegral,
"f125 Pulse Integral");
101 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulseTime,
"f125 Pulse Time");
102 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulsePedestal,
"f125 Pulse Pedestal");
103 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125EventTrailer,
"f125 Event Trailer");
104 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125DataNotValid,
"f125 Data Not Valid");
108 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BlockHeader,
"F1v2 Block Header");
109 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BLockTrailer,
"F1v2 Block Trailer");
110 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2EventHeader,
"F1v2 Event Header");
111 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2TriggerTime,
"F1v2 Trigger Time");
112 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2ChipHeader,
"F1v2 Chip Header");
115 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BreakWord,
"F1v2 Break Word");
118 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BlockHeader,
"F1v3 Block Header");
119 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BLockTrailer,
"F1v3 Block Trailer");
120 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3EventHeader,
"F1v3 Event Header");
121 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3TriggerTime,
"F1v3 Trigger Time");
122 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3ChipHeader,
"F1v3 Chip Header");
125 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BreakWord,
"F1v3 Break Word");
128 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalHeader,
"CAEN1190 GLobal Header");
129 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalTrailer,
"CAEN1190 Global Trailer");
130 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalTriggerTime,
"CAEN1190 Trigger Time");
131 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCHeader,
"CAEN1190 TDC Header");
132 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCData,
"CAEN1190 TDC Data");
133 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCError,
"CAEN1190 TDC Error");
134 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCTrailer,
"CAEN1190 TDC Trailer");
135 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190Filler,
"CAEN1190 Filler");
136 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190Unknown,
"CAEN1190 Unknown");
142 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigCAEN1190,
"DAQ Config CAEN1190");
152 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kTotWords,
"Total words in all events");
175 JEventLoop loop(&dapp);
179 for(uint32_t rocid=2; rocid<99; rocid++){
182 bool found_chan =
false;
185 for(uint32_t slot=2; slot<24; slot++){
186 for(uint32_t channel=0; channel<3; channel++){
194 }
catch(JException &
e){
198 if(found_chan)
break;
209 uint32_t *istart = buff;
210 uint32_t evio_buffwords = buff[0]+1;
211 uint32_t evio_buffsize = evio_buffwords*
sizeof(uint32_t);
212 uint32_t *iend = &istart[evio_buffwords];
214 if( istart==NULL )
return;
215 if( (evio_buffwords>=10) && (istart[7]==0xc0da0100) ){
218 evio_buffsize -= 8*
sizeof(uint32_t);
223 if( evio_buffwords >= 4 ){
224 if( (istart[1]&0xFFFF00FF) == 0x00700001 ){
235 if( evio_buffwords >= 4 ){
236 if( ((istart[1]>>16)&0xFF) == 0x60 ){
242 uint32_t *iptr = &istart[2];
243 while( iptr < iend ){
245 uint32_t bank_len = (*iptr)&0xFFFF;
246 uint32_t tag = ((*iptr)>>24)&0xFF;
252 }
else if(tag == 0x62){
259 iptr = &iptr[bank_len];
266 if( evio_buffwords < 4 ){
267 cout <<
"Too few words in event (" << evio_buffwords <<
") skipping..." << endl;
272 uint32_t physics_event_len = istart[0];
273 if( (istart[1] & 0xFF001000) != 0xFF001000 )
return;
274 if( physics_event_len+1 > evio_buffwords ){
275 cout <<
"Too many words in physics event: " << physics_event_len+1 <<
" > " << evio_buffwords << endl;
280 uint32_t trigger_bank_len = istart[2];
281 if( (istart[3] & 0xFF202000) != 0xFF202000 )
return;
282 if( trigger_bank_len+2 > evio_buffwords ){
283 cout <<
"Too many words in trigger bank " << trigger_bank_len <<
" > " << evio_buffwords-2 << endl;
293 uint64_t tlo = istart[2+5];
294 uint64_t thi = istart[2+6];
295 uint64_t timestamp = (thi<<32) + (tlo<<0);
296 ts_history.insert(timestamp);
297 if( ts_history.size() > max_history_buff_size ){
298 auto it1 = ts_history.begin();
300 uint64_t
t1 = *(it1);
301 uint64_t t2 = *(++it2);
302 ts_history.erase(it1, it2);
303 double tdiff_ns = (double)(t2 - t1)*4.0;
304 double tdiff_ms = tdiff_ns/1.0E6;
309 uint32_t Nwords[100];
310 uint32_t word_stats[kNEVIOWordTypes];
311 for(uint32_t rocid=0; rocid<100; rocid++) Nwords[rocid] = 0;
312 for(uint32_t i=0; i<kNEVIOWordTypes; i++) word_stats[i] = 0;
314 word_stats[kNevents] += istart[1]&0xFF;
315 word_stats[kTotWords] += evio_buffwords;
317 word_stats[kEVIOHeader] += 4;
320 uint32_t *iptr = &istart[3+trigger_bank_len];
323 uint32_t len = *iptr;
324 uint32_t rocid = (iptr[1]>>16) & 0XFF;
326 if(rocid<100) Nwords[rocid] += len+1;
328 word_stats[kEVIOHeader] += 2;
330 uint32_t *imyend = &iptr[len+1];
331 if(imyend > iend) imyend = iend;
333 uint64_t Nwords = ((uint64_t)imyend - (uint64_t)iptr)/
sizeof(uint32_t);
335 static int Nwarnings = 0;
337 cout <<
"Nwords<2 (?)" << endl;
338 cout <<
" evio_buffwords = " << evio_buffwords << endl;
339 cout <<
" physics_event_len = " << physics_event_len << endl;
340 cout <<
" trigger_bank_len = " << trigger_bank_len << endl;
341 if(++Nwarnings == 10) cout <<
"Last warning!" << endl;
346 DataWordStats(iptr, imyend, word_stats);
352 uint32_t Nwords_added = TotWordCount(word_stats);
353 word_stats[kUnknown] += evio_buffwords - Nwords_added;
360 double physics_event_len_kB = (double)((physics_event_len+1)*
sizeof(uint32_t))/1024.0;
362 static int Nin_block = 1;
364 block_size += physics_event_len_kB;
372 uint32_t TotalWords = 0;
373 for(uint32_t rocid=0; rocid<100; rocid++){
375 TotalWords += Nwords[rocid];
381 for(uint32_t i=0; i<kNEVIOWordTypes; i++){
393 for(uint32_t i=kUnknown; i<kTotWords; i++) N += word_stats[i];
407 uint32_t rocid = (*iptr++)>>16 & 0x0FFF;
409 uint32_t data_block_bank_len = *iptr++;
410 uint32_t *iendbank = &iptr[data_block_bank_len];
411 uint32_t det_id = ((*iptr) >> 16) & 0x0FFF;
413 if(iendbank > iend) iendbank = iend;
415 word_stats[kEVIOHeader] += 2;
420 while( (*iptr==0xF800FAFA) && (iptr<iend) ){
421 word_stats[kF800FAFA]++;
432 ParseJLabModuleData(rocid, iptr, iendbank, word_stats);
436 ParseCAEN1190(rocid, iptr, iendbank, word_stats);
440 ParseModuleConfiguration(rocid, iptr, iendbank, word_stats);
444 ParseTSscalerBank(iptr, iendbank, word_stats);
463 if(*iptr != 0xf800fafa)
break;
464 word_stats[kF800FAFA]++;
468 uint32_t mod_id = ((*iptr) >> 18) & 0x000F;
486 if(((*iptr>>31) & 0x1) == 0) { word_stats[kf250Unknown]++ ; iptr++;
continue;}
488 uint32_t window_width;
489 uint32_t window_words;
490 uint32_t data_type = (*iptr>>27) & 0x0F;
492 case 0: word_stats[kf250BlockHeader]++; iptr++;
break;
493 case 1: word_stats[kf250BlockTrailer]++; iptr++;
break;
494 case 2: word_stats[kf250EventHeader]++; iptr++;
break;
496 word_stats[kf250TriggerTime]++;
498 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf250TriggerTime]++; iptr++; }
501 window_width = (*iptr>>0) & 0x0FFF;
502 window_words = 1 + ((window_width+1)/2);
503 word_stats[kf250WindowRawData] += window_words;
504 iptr = &iptr[window_words];
506 case 7: word_stats[kf250PulseIntegral]++; iptr++;
break;
507 case 8: word_stats[kf250PulseTime]++; iptr++;
break;
508 case 9: word_stats[kf250PulseData]++; iptr++;
509 while( ((*iptr>>31) & 0x1) == 0 ){
510 word_stats[kf250PulseData]++; iptr++;
511 if(iptr == iend)
break;
514 case 10: word_stats[kf250PulsePedestal]++; iptr++;
break;
515 case 13: word_stats[kf250EventTrailer]++; iptr++;
break;
516 case 14: word_stats[kf250DataNotValid]++; iptr++;
break;
517 case 15: word_stats[kf250Filler]++; iptr++;
break;
519 default: word_stats[kf250Unknown]++; iptr++;
break;
531 if(((*iptr>>31) & 0x1) == 0) { word_stats[kf125Unknown]++ ; iptr++;
continue;}
533 uint32_t window_width;
534 uint32_t window_words;
535 uint32_t data_type = (*iptr>>27) & 0x0F;
537 case 0: word_stats[kf125BlockHeader]++; iptr++;
break;
538 case 1: word_stats[kf125BlockTrailer]++; iptr++;
break;
539 case 2: word_stats[kf125EventHeader]++; iptr++;
break;
541 word_stats[kf125TriggerTime]++;
543 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125TriggerTime]++; iptr++; }
546 window_width = (*iptr>>0) & 0x0FFF;
547 window_words = 1 + ((window_width+1)/2);
548 word_stats[kf125WindowRawData] += window_words;
549 iptr = &iptr[window_words];
551 case 5: word_stats[kf125CDCPulse]++;
553 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125CDCPulse]++; iptr++; }
555 case 6: word_stats[kf125FDCPulse6]++;
557 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125FDCPulse6]++; iptr++; }
559 case 7: word_stats[kf125PulseIntegral]++; iptr++;
break;
560 case 8: word_stats[kf125PulseTime]++; iptr++;
break;
561 case 9: word_stats[kf125FDCPulse9]++;
563 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125FDCPulse9]++; iptr++; }
565 case 10: word_stats[kf125PulsePedestal]++; iptr++;
break;
566 case 13: word_stats[kf125EventTrailer]++; iptr++;
break;
567 case 14: word_stats[kf125DataNotValid]++; iptr++;
break;
568 case 15: word_stats[kf125Filler]++; iptr++;
break;
570 default: word_stats[kf125Unknown]++; iptr++;
break;
581 switch( (*iptr++) & 0xF8000000 ){
582 case 0xC0000000: word_stats[kF1v2ChipHeader]++;
break;
583 case 0xB8000000: word_stats[kF1v2Data]++;
break;
584 case 0xF8000000: word_stats[kF1v2Filler]++;
break;
585 case 0x80000000: word_stats[kF1v2BlockHeader]++;
break;
586 case 0x88000000: word_stats[kF1v2BLockTrailer]++;
break;
587 case 0x90000000: word_stats[kF1v2EventHeader]++;
break;
588 case 0x98000000: word_stats[kF1v2TriggerTime]++;
break;
589 case 0xF0000000: word_stats[kF1v2BreakWord]++;
break;
590 default: word_stats[kF1v2Unknown]++;
break;
601 switch( (*iptr++) & 0xF8000000 ){
602 case 0xC0000000: word_stats[kF1v3ChipHeader]++;
break;
603 case 0xB8000000: word_stats[kF1v3Data]++;
break;
604 case 0xF8000000: word_stats[kF1v3Filler]++;
break;
605 case 0x80000000: word_stats[kF1v3BlockHeader]++;
break;
606 case 0x88000000: word_stats[kF1v3BLockTrailer]++;
break;
607 case 0x90000000: word_stats[kF1v3EventHeader]++;
break;
608 case 0x98000000: word_stats[kF1v3TriggerTime]++;
break;
609 case 0xF0000000: word_stats[kF1v3BreakWord]++;
break;
610 default: word_stats[kF1v3Unknown]++;
break;
624 if(*iptr == 0xd00dd00d) {
625 word_stats[kD00DD00D]++;
630 uint32_t type = (*iptr++) >> 27;
632 case 0b01000: word_stats[kCAEN1190GlobalHeader]++;
break;
633 case 0b10000: word_stats[kCAEN1190GlobalTrailer]++;
break;
634 case 0b10001: word_stats[kCAEN1190GlobalTriggerTime]++;
break;
635 case 0b00001: word_stats[kCAEN1190TDCHeader]++;
break;
636 case 0b00000: word_stats[kCAEN1190TDCData]++;
break;
637 case 0b00100: word_stats[kCAEN1190TDCError]++;
break;
638 case 0b00011: word_stats[kCAEN1190TDCTrailer]++;
break;
639 case 0b11000: word_stats[kCAEN1190Filler]++;
break;
640 default: word_stats[kCAEN1190Unknown]++;
break;
652 word_stats[kConfig]++;
653 uint32_t Nvals = ((*iptr++) >> 24) & 0xFF;
656 for(uint32_t i=0; i< Nvals; i++){
658 switch((*iptr++)>>24){
659 case 0x05: word_stats[kConfigf250]++;
break;
660 case 0x0F: word_stats[kConfigf125]++;
break;
661 case 0x06: word_stats[kConfigF1]++;
break;
662 case 0x10: word_stats[kConfigCAEN1190]++;
break;
663 default: word_stats[kConfig]++;
break;
674 word_stats[kTSsync] += (uint32_t)( (uint64_t)iend - (uint64_t)iptr)/
sizeof(uint32_t) ;
void ParseCAEN1190(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
sprintf(text,"Post KinFit Cut")
void DataWordStats(uint32_t *iptr, uint32_t *iend, uint32_t *word_stats)
static TH1D * daq_block_size
static TH1D * daq_event_size
void ParseTSscalerBank(uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
void AddROCIDLabels(void)
void ParseJLabModuleData(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
void Parsef250Bank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
const DChannelInfo & GetDetectorIndex(const csc_t &in_daq_index) const
uint32_t TotWordCount(uint32_t *word_stats)
static TProfile * daq_words_per_event
void Parsef125Bank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
void ParseF1v3TDCBank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
static TH1D * daq_event_tdiff
void ParseModuleConfiguration(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
void ParseF1v2TDCBank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
static const size_t block_size
void ParseEvent(uint32_t *buff)
static string DetectorName(Detector_t type)
static TProfile * daq_hits_per_event