Bug Summary

File:/home/sdobbs/work/clang/halld_recon/src/programs/Utilities/hdevio_scan/DMapEVIOWords.cc
Warning:line 250, column 3
Value stored to 'evio_buffsize' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name DMapEVIOWords.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0 -D HAVE_EVIO -D HAVE_CCDB -D HAVE_RCDB -D HAVE_TMVA=1 -D RCDB_MYSQL=1 -D RCDB_SQLITE=1 -D SQLITE_USE_LEGACY_STRUCT=ON -I .Linux_CentOS7.7-x86_64-gcc4.8.5/programs/Utilities/hdevio_scan -I programs/Utilities/hdevio_scan -I . -I libraries -I libraries/include -I /w/halld-scifs17exp/home/sdobbs/clang/halld_recon/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/evio/evio-4.4.6/Linux-x86_64/include -I external/xstream/include -I /usr/include/tirpc -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/root/root-6.08.06/include -I /w/halld-scifs17exp/halld2/home/sdobbs/Software/jana/jana_0.8.2/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/ccdb/ccdb_1.06.06/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/rcdb/rcdb_0.06.00/cpp/include -I /usr/include/mysql -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlitecpp/SQLiteCpp-2.2.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlite/sqlite-3.13.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/hdds/hdds-4.9.0/Linux_CentOS7.7-x86_64-gcc4.8.5/src -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/xerces-c/xerces-c-3.1.4/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward -internal-isystem /usr/local/include -internal-isystem /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c++0x -fdeprecated-macro -fdebug-compilation-dir /home/sdobbs/work/clang/halld_recon/src -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-01-21-110224-160369-1 -x c++ programs/Utilities/hdevio_scan/DMapEVIOWords.cc
1// $Id:$
2//
3// File: DMapEVIOWords.cc
4// Created: Sat May 28 19:22:47 EDT 2016
5// Creator: davidl (on Linux gluon104.jlab.org 2.6.32-358.23.2.el6.x86_64)
6//
7
8#include <stdint.h>
9#include <vector>
10
11#include "DMapEVIOWords.h"
12#include <JANA/JApplication.h>
13#include <JANA/JFactory.h>
14#include <JANA/JEventLoop.h>
15
16using namespace std;
17using namespace jana;
18
19#include <DANA/DApplication.h>
20#include <TTAB/DTranslationTable.h>
21
22#include <TDirectory.h>
23#include <TH2.h>
24#include <TH1.h>
25#include <TProfile.h>
26#include <TProfile2D.h>
27#include <TROOT.h>
28
29extern uint32_t BLOCK_SIZE;
30extern int32_t RUNNUMBER;
31
32// root hist pointers
33static TH1D *daq_hits_per_event;
34static TProfile *daq_words_per_event;
35static TH1D *daq_event_size;
36static TH1D *daq_block_size; // Adds together BLOCK_SIZE EVIO events (n.b. evio events could already be blocks!)
37static TH1D *daq_event_tdiff;
38static TH1D *daq_words_by_type;
39//static bool ttab_labels_set = false;
40
41
42
43//------------------
44// DMapEVIOWords (Constructor)
45//------------------
46DMapEVIOWords::DMapEVIOWords()
47{
48 max_history_buff_size = 400;
49 Nphysics_events = 0;
50 Nevent_blocks = 0;
51
52 char daq_block_size_title[256];
53 sprintf(daq_block_size_title, "Block size (%d EVIO events) in kB", BLOCK_SIZE);
54
55 daq_hits_per_event = new TH1D("daq_hits_per_event", "Hits/event vs. rocid", 100, 0.5, 100.5);
56 daq_words_per_event = new TProfile("daq_words_per_event", "words/event vs. rocid", 100, 0.5, 100.5);
57 daq_event_size = new TH1D("daq_event_size", "Event size in kB", 10000, 0.0, 1.0E3);
58 daq_block_size = new TH1D("daq_block_size", daq_block_size_title, 1000, 0.0, 1.0E3);
59 daq_event_tdiff = new TH1D("daq_event_tdiff", "Time between events", 10000, 0.0, 1.0E1);
60 daq_words_by_type = new TH1D("daq_words_by_type", "Number of words in EVIO file by type", kNEVIOWordTypes, 0, (double)kNEVIOWordTypes);
61
62 daq_words_per_event->GetXaxis()->SetBinLabel(1 ,"Trigger Bank");
63 daq_words_per_event->GetXaxis()->SetBinLabel(99 ,"Residual");
64 AddROCIDLabels();
65
66 daq_event_size->SetXTitle("Total event size (kB)");
67 daq_event_tdiff->SetXTitle("#deltat between events (ms)");
68
69 // Making sure all labels have at least a single space avoids ROOT bugs when interacting with canvas
70 for(int ibin=1; ibin<=kNEVIOWordTypes; ibin++) daq_words_by_type->GetXaxis()->SetBinLabel(ibin, " ");
71
72 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kUnknown, "unknown");
73 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEVIOHeader, "EVIO len. & header");
74 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEVIOEventNumber, "Event Number Word");
75 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEVIOTimestamp, "Timestamp");
76
77 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kBORData, "BOR record");
78
79 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250BlockHeader, "f250 Block Header");
80 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250BlockTrailer, "f250 Block Trailer");
81 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250EventHeader, "f250 Event Header");
82 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250TriggerTime, "f250 Trigger Time");
83 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250WindowRawData, "f250 Window Raw Data");
84 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250WindowSum, "f250 Window Sum");
85 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseRawData, "f250 Pulse Raw Data");
86 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseData, "f250 Pulse Data");
87 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseIntegral, "f250 Pulse Integral");
88 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseTime, "f250 Pulse Time");
89 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulsePedestal, "f250 Pulse Pedestal");
90 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250EventTrailer, "f250 Event Trailer");
91 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250DataNotValid, "f250 Data Not Valid");
92 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250Filler, "f250 Filler Word");
93 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250Unknown, "f250 Unknown");
94
95 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125BlockHeader, "f125 Block Header");
96 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125BlockTrailer, "f125 Block Trailer");
97 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125EventHeader, "f125 Event Header");
98 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125TriggerTime, "f125 Trigger Time");
99 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125WindowRawData, "f125 Window Raw Data");
100 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125CDCPulse, "f125 CDC Pulse");
101 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125FDCPulse6, "f125 FDC Pulse (integral)");
102 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125FDCPulse9, "f125 FDC Pulse (peak)");
103 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulseIntegral, "f125 Pulse Integral");
104 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulseTime, "f125 Pulse Time");
105 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulsePedestal, "f125 Pulse Pedestal");
106 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125EventTrailer, "f125 Event Trailer");
107 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125DataNotValid, "f125 Data Not Valid");
108 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125Filler, "f125 Filler Word");
109 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125Unknown, "f125 Unknown");
110
111 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BlockHeader, "F1v2 Block Header");
112 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BLockTrailer, "F1v2 Block Trailer");
113 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2EventHeader, "F1v2 Event Header");
114 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2TriggerTime, "F1v2 Trigger Time");
115 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2ChipHeader, "F1v2 Chip Header");
116 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2Data, "F1v2 Data");
117 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2Filler, "F1v2 Filler");
118 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BreakWord, "F1v2 Break Word");
119 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2Unknown, "F1v2 Unknown");
120
121 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BlockHeader, "F1v3 Block Header");
122 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BLockTrailer, "F1v3 Block Trailer");
123 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3EventHeader, "F1v3 Event Header");
124 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3TriggerTime, "F1v3 Trigger Time");
125 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3ChipHeader, "F1v3 Chip Header");
126 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3Data, "F1v3 Data");
127 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3Filler, "F1v3 Filler");
128 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BreakWord, "F1v3 Break Word");
129 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3Unknown, "F1v3 Unknown");
130
131 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalHeader, "CAEN1190 GLobal Header");
132 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalTrailer, "CAEN1190 Global Trailer");
133 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalTriggerTime, "CAEN1190 Trigger Time");
134 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCHeader, "CAEN1190 TDC Header");
135 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCData, "CAEN1190 TDC Data");
136 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCError, "CAEN1190 TDC Error");
137 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCTrailer, "CAEN1190 TDC Trailer");
138 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190Filler, "CAEN1190 Filler");
139 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190Unknown, "CAEN1190 Unknown");
140
141 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfig, "DAQ Config");
142 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigf250, "DAQ Config f250");
143 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigf125, "DAQ Config f125");
144 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigF1, "DAQ Config F1");
145 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigCAEN1190, "DAQ Config CAEN1190");
146
147 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEPICSheader, "EPICS header");
148 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEPICSdata, "EPICS data");
149
150 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kTSsync, "TS sync event data");
151
152 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF800FAFA, "0xf800fafa");
153 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kD00DD00D, "0xd00dd00d");
154
155 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kTotWords, "Total words in all events");
156 daq_words_by_type->GetXaxis()->SetBinLabel(1 + kNevents, "Number of events");
157
158}
159
160//------------------
161// ~DMapEVIOWords (Destructor)
162//------------------
163DMapEVIOWords::~DMapEVIOWords()
164{
165
166}
167
168//------------------
169// Finish
170//------------------
171void DMapEVIOWords::Finish(void)
172{
173 // This is called just before the ROOT file is closed.
174 // Here we scale some histograms by the number of events.
175 double norm = 1.0/(double)Nphysics_events;
176 daq_hits_per_event->Scale(norm);
177
178 // daq_words_per_event is a profile hist that already averages
179 // by number of event blocks. Here we need to scale only by block
180 // size.
181 auto scale = (double)Nevent_blocks/(double)Nphysics_events;
182 daq_words_per_event->Scale(scale);
183}
184
185
186//------------------
187// AddROCIDLabels
188//------------------
189void DMapEVIOWords::AddROCIDLabels(void)
190{
191 // This is called via the hdevio_scan.cc:MapEVIOWords->DMapEvioWords::DMapEVIOWords
192 // It does not pass the command line nor does it give
193 // access to the run number via the main event loop.
194
195
196 /// This is called just once to set the x-axis labels
197 /// of histograms whose x-axis is the rocid so that we
198 /// can label them by detector.
199
200 DApplication dapp(0, NULL__null);
201 //auto jparms = dapp.GetJParameterManager();
202 //int RUNNUMBER = 1234;
203 //jparms->SetDefaultParameter("RUNNUMBER", RUNNUMBER);
204 JEventLoop loop(&dapp);
205 loop.GetJEvent().SetRunNumber(RUNNUMBER);
206 DTranslationTable ttab(&loop);
207
208 // Loop over all rocid values
209 for(uint32_t rocid=2; rocid<99; rocid++){
210 // We don't actually know what slot/channel combos are defined
211 // for this so we loop until we find one.
212 bool found_chan = false;
213 daq_hits_per_event->GetXaxis()->SetBinLabel(rocid, "");
214 daq_words_per_event->GetXaxis()->SetBinLabel(rocid, "");
215 for(uint32_t slot=2; slot<24; slot++){
216 for(uint32_t channel=0; channel<3; channel++){
217 try{
218 DTranslationTable::csc_t csc = {rocid, slot, channel};
219 const DTranslationTable::DChannelInfo &chinfo = ttab.GetDetectorIndex(csc);
220 char lab[256];
221 sprintf(lab, "%s:rocid%d", ttab.DetectorName(chinfo.det_sys).c_str(), rocid);
222 daq_hits_per_event->GetXaxis()->SetBinLabel(rocid, lab);
223 daq_words_per_event->GetXaxis()->SetBinLabel(rocid, lab);
224 found_chan = true;
225 break;
226 }catch(JException &e){
227 // Do nothing
228 }
229 }
230 if(found_chan) break;
231 }
232 }
233}
234
235
236//------------------
237// ParseEvent
238//------------------
239void DMapEVIOWords::ParseEvent(uint32_t *buff)
240{
241 uint32_t *istart = buff;
242 uint32_t evio_buffwords = buff[0]+1;
243 uint32_t evio_buffsize = evio_buffwords*sizeof(uint32_t);
244 uint32_t *iend = &istart[evio_buffwords];
245
246 if( istart==NULL__null ) return;
247 if( (evio_buffwords>=10) && (istart[7]==0xc0da0100) ){
248 // NTH is first 8 words so skip them
249 istart= &istart[8];
250 evio_buffsize -= 8*sizeof(uint32_t);
Value stored to 'evio_buffsize' is never read
251 evio_buffwords -= 8;
252 }
253
254 // Check if this is BOR data
255 if( evio_buffwords >= 4 ){
256 if( (istart[1]&0xFFFF00FF) == 0x00700001 ){
257
258 // FILL HISTOGRAMS
259 // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
260 daq_words_by_type->Fill(kBORData, istart[0]);
261 daq_words_by_type->Fill(kTotWords, istart[0]);
262 return; // no further parsing needed
263 }
264 }
265
266 // Check if this is EPICS data
267 if( evio_buffwords >= 4 ){
268 if( ((istart[1]>>16)&0xFF) == 0x60 ){
269
270 daq_words_by_type->Fill(kEPICSheader, 2.0); // EVIO bank length and header word
271 daq_words_by_type->Fill(kTotWords, istart[0]);
272
273 // Loop over daughter banks
274 uint32_t *iptr = &istart[2];
275 while( iptr < iend ){
276
277 uint32_t bank_len = (*iptr)&0xFFFF;
278 uint32_t tag = ((*iptr)>>24)&0xFF;
279 iptr++;
280
281 if(tag == 0x61){
282 // timestamp bank (count as header)
283 daq_words_by_type->Fill(kEPICSheader, bank_len+1);
284 }else if(tag == 0x62){
285 // EPICS data value
286 daq_words_by_type->Fill(kEPICSdata, bank_len+1);
287 }else{
288 // Unknown tag
289 }
290
291 iptr = &iptr[bank_len];
292 }
293
294 return; // no further parsing needed
295 }
296 }
297
298 if( evio_buffwords < 4 ){
299 cout << "Too few words in event (" << evio_buffwords << ") skipping..." << endl;
300 return;
301 }
302
303 // Physics event length
304 uint32_t physics_event_len = istart[0];
305 if( (istart[1] & 0xFF001000) != 0xFF001000 ) return; // not a physics event
306 if( physics_event_len+1 > evio_buffwords ){
307 cout << "Too many words in physics event: " << physics_event_len+1 << " > " << evio_buffwords << endl;
308 return;
309 }
310
311 // Number of physics events in EVIO block
312 uint64_t M = istart[1] & 0x0FF;
313 Nphysics_events += M;
314 Nevent_blocks++;
315
316 // Trigger bank event length
317 uint32_t trigger_bank_len = istart[2];
318 if( (istart[3] & 0xFF202000) != 0xFF202000 ) return; // not a trigger bank
319 if( trigger_bank_len+2 > evio_buffwords ){
320 cout << "Too many words in trigger bank " << trigger_bank_len << " > " << evio_buffwords-2 << endl;
321 return;
322 }
323
324 // Time difference between events
325 // since events may be out of order due to L3, we
326 // keep track of up to 400 timestamps and only make
327 // entries once we have accumulated that many.
328 // (probably better to look for adjacent event numbers
329 // but that will take a littel refactoring.)
330 uint64_t tlo = istart[2+5];
331 uint64_t thi = istart[2+6];
332 uint64_t timestamp = (thi<<32) + (tlo<<0);
333 ts_history.insert(timestamp);
334 if( ts_history.size() > max_history_buff_size ){
335 auto it1 = ts_history.begin();
336 auto it2 = it1;
337 uint64_t t1 = *(it1);
338 uint64_t t2 = *(++it2);
339 ts_history.erase(it1, it2);
340 double tdiff_ns = (double)(t2 - t1)*4.0;
341 double tdiff_ms = tdiff_ns/1.0E6;
342 daq_event_tdiff->Fill(tdiff_ms);
343 }
344
345 // Allocate memory to hold stats data
346 uint32_t Nwords[100]; // total data words for each ROC (includes event length words)
347 uint32_t word_stats[kNEVIOWordTypes]; // obtained from parsing event
348 for(uint32_t rocid=0; rocid<100; rocid++) Nwords[rocid] = 0;
349 for(uint32_t i=0; i<kNEVIOWordTypes; i++) word_stats[i] = 0;
350
351 word_stats[kNevents] += istart[1]&0xFF;
352 word_stats[kTotWords] += evio_buffwords;
353
354 word_stats[kEVIOHeader] += 4; // physics event and built trigger bank length and header words
355
356 // Loop over data banks
357 uint32_t *iptr = &istart[3+trigger_bank_len];
358 while(iptr < iend){
359
360 uint32_t len = *iptr;
361 uint32_t rocid = (iptr[1]>>16) & 0XFF;
362
363 if(rocid<100) Nwords[rocid] += len+1;
364
365 word_stats[kEVIOHeader] += 2; // ROC data bank length and header words
366
367 uint32_t *imyend = &iptr[len+1];
368 if(imyend > iend) imyend = iend;
369
370 uint64_t Nwords = ((uint64_t)imyend - (uint64_t)iptr)/sizeof(uint32_t);
371 if(Nwords<2){
372 static int Nwarnings = 0;
373 if(Nwarnings<10){
374 cout << "Nwords<2 (?)" << endl;
375 cout << " evio_buffwords = " << evio_buffwords << endl;
376 cout << " physics_event_len = " << physics_event_len << endl;
377 cout << " trigger_bank_len = " << trigger_bank_len << endl;
378 if(++Nwarnings == 10) cout << "Last warning!" << endl;
379 }
380 break;
381 }
382
383 DataWordStats(iptr, imyend, word_stats);
384
385 iptr = imyend;
386 }
387
388 // Updated unknown words counter
389 uint32_t Nwords_added = TotWordCount(word_stats);
390 word_stats[kUnknown] += evio_buffwords - Nwords_added;
391
392 // FILL HISTOGRAMS
393 // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
394
395
396 // Fill event size histos
397 double physics_event_len_kB = (double)((physics_event_len+1)*sizeof(uint32_t))/1024.0;
398 daq_event_size->Fill(physics_event_len_kB);
399 static int Nin_block = 1;
400 static double block_size = 0;
401 block_size += physics_event_len_kB;
402 Nin_block++;
403 if( (Nin_block%BLOCK_SIZE) == 0 ){
404 daq_block_size->Fill(block_size);
405 block_size = 0.0;
406 Nin_block = 0;
407 }
408
409 uint32_t TotalWords = 0;
410 for(uint32_t rocid=0; rocid<100; rocid++){
411 daq_words_per_event->Fill(rocid, Nwords[rocid]);
412 TotalWords += Nwords[rocid];
413 }
414
415 daq_words_per_event->Fill(1, trigger_bank_len+1);
416 daq_words_per_event->Fill(99, physics_event_len - trigger_bank_len - TotalWords);
417
418 for(uint32_t i=0; i<kNEVIOWordTypes; i++){
419 daq_words_by_type->Fill(i, (double)word_stats[i]);
420 }
421
422}
423
424//------------------
425// TotWordCount
426//------------------
427uint32_t DMapEVIOWords::TotWordCount(uint32_t *word_stats)
428{
429 uint32_t N=0;
430 for(uint32_t i=kUnknown; i<kTotWords; i++) N += word_stats[i];
431 return N;
432}
433
434//------------------
435// DataWordStats
436//------------------
437void DMapEVIOWords::DataWordStats(uint32_t *iptr, uint32_t *iend, uint32_t *word_stats)
438{
439 // Upon entry, the iptr will point to the start of the "Physics Event's Data Bank".
440 // It will loop over all sub-banks, tallying the word count as it goes up to
441 // but not including iend.
442
443 iptr++; // advance past length word
444 uint32_t rocid = (*iptr++)>>16 & 0x0FFF;
445 while(iptr < iend){
446 uint32_t data_block_bank_len = *iptr++;
447 uint32_t *iendbank = &iptr[data_block_bank_len];
448 uint32_t det_id = ((*iptr) >> 16) & 0x0FFF;
449
450 if(iendbank > iend) iendbank = iend;
451
452 word_stats[kEVIOHeader] += 2; // data block bank length and header words
453
454 iptr++; // advance to first raw data word
455
456 // Not sure where this comes from, but it needs to be skipped if present
457 while( (*iptr==0xF800FAFA) && (iptr<iend) ){
458 word_stats[kF800FAFA]++;
459 iptr++;
460 }
461
462 switch(det_id){
463 case 0:
464 case 1:
465 case 3:
466 case 6: // flash 250 module, MMD 2014/2/4
467 case 16: // flash 125 module (CDC), DL 2014/6/19
468 case 26: // F1 TDC module (BCAL), MMD 2014-07-31
469 ParseJLabModuleData(rocid, iptr, iendbank, word_stats);
470 break;
471
472 case 20:
473 ParseCAEN1190(rocid, iptr, iendbank, word_stats);
474 break;
475
476 case 0x55:
477 ParseModuleConfiguration(rocid, iptr, iendbank, word_stats);
478 break;
479
480 case 0xE02:
481 ParseTSscalerBank(iptr, iendbank, word_stats);
482 break;
483
484 default:
485 break;
486 }
487
488 iptr = iendbank;
489 }
490
491
492}
493
494//------------------
495// ParseJLabModuleData
496//------------------
497void DMapEVIOWords::ParseJLabModuleData(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
498{
499 while(iptr < iend){
500 if(*iptr != 0xf800fafa) break;
501 word_stats[kF800FAFA]++;
502 iptr++;
503 }
504
505 uint32_t mod_id = ((*iptr) >> 18) & 0x000F;
506 switch(mod_id){
507 case DModuleType::FADC250: Parsef250Bank(rocid, iptr, iend, word_stats); break;
508 case DModuleType::FADC125: Parsef125Bank(rocid, iptr, iend, word_stats); break;
509 case DModuleType::F1TDC32: ParseF1v2TDCBank(rocid, iptr, iend, word_stats); break;
510 case DModuleType::F1TDC48: ParseF1v3TDCBank(rocid, iptr, iend, word_stats); break;
511 //case DModuleType::JLAB_TS: ParseTSBank(rocid, iptr, iend, word_stats); break;
512 //case DModuleType::TID: ParseTIBank(rocid, iptr, iend, word_stats); break;
513 }
514}
515
516//------------------
517// Parsef250Bank
518//------------------
519void DMapEVIOWords::Parsef250Bank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
520{
521 while(iptr<iend){
522
523 if(((*iptr>>31) & 0x1) == 0) { word_stats[kf250Unknown]++ ; iptr++; continue;}
524
525 uint32_t window_width;
526 uint32_t window_words;
527 uint32_t data_type = (*iptr>>27) & 0x0F;
528 switch(data_type){
529 case 0: word_stats[kf250BlockHeader]++; iptr++; break;
530 case 1: word_stats[kf250BlockTrailer]++; iptr++; break;
531 case 2: word_stats[kf250EventHeader]++; iptr++; break;
532 case 3: // Trigger time
533 word_stats[kf250TriggerTime]++;
534 iptr++;
535 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf250TriggerTime]++; iptr++; }
536 break;
537 case 4: // Window Raw Data
538 window_width = (*iptr>>0) & 0x0FFF;
539 window_words = 1 + ((window_width+1)/2); // 1 is for header word + 2 sample per word
540 word_stats[kf250WindowRawData] += window_words;
541 iptr = &iptr[window_words];
542 break;
543 case 7: word_stats[kf250PulseIntegral]++; iptr++; break;
544 case 8: word_stats[kf250PulseTime]++; iptr++; break;
545 case 9: word_stats[kf250PulseData]++; iptr++;
546 while( ((*iptr>>31) & 0x1) == 0 ){
547 word_stats[kf250PulseData]++; iptr++;
548 daq_hits_per_event->Fill(rocid);
549 if(iptr == iend) break;
550 }
551 break;
552 case 10: word_stats[kf250PulsePedestal]++; iptr++; break;
553 case 13: word_stats[kf250EventTrailer]++; iptr++; break;
554 case 14: word_stats[kf250DataNotValid]++; iptr++; break;
555 case 15: word_stats[kf250Filler]++; iptr++; break;
556
557 default: word_stats[kf250Unknown]++; iptr++; break;
558 }
559 }
560}
561
562//------------------
563// Parsef125Bank
564//------------------
565void DMapEVIOWords::Parsef125Bank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
566{
567 while(iptr<iend){
568
569 if(((*iptr>>31) & 0x1) == 0) { word_stats[kf125Unknown]++ ; iptr++; continue;}
570
571 uint32_t window_width;
572 uint32_t window_words;
573 uint32_t data_type = (*iptr>>27) & 0x0F;
574 switch(data_type){
575 case 0: word_stats[kf125BlockHeader]++; iptr++; break;
576 case 1: word_stats[kf125BlockTrailer]++; iptr++; break;
577 case 2: word_stats[kf125EventHeader]++; iptr++; break;
578 case 3: // Trigger time
579 word_stats[kf125TriggerTime]++;
580 iptr++;
581 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125TriggerTime]++; iptr++; }
582 break;
583 case 4: // Window Raw Data
584 window_width = (*iptr>>0) & 0x0FFF;
585 window_words = 1 + ((window_width+1)/2); // 1 is for header word + 2 sample per word
586 word_stats[kf125WindowRawData] += window_words;
587 iptr = &iptr[window_words];
588 break;
589 case 5: word_stats[kf125CDCPulse]++;
590 iptr++;
591 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125CDCPulse]++; iptr++; }
592 daq_hits_per_event->Fill(rocid);
593 break;
594 case 6: word_stats[kf125FDCPulse6]++;
595 iptr++;
596 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125FDCPulse6]++; iptr++; }
597 daq_hits_per_event->Fill(rocid);
598 break;
599 case 7: word_stats[kf125PulseIntegral]++; iptr++; break;
600 case 8: word_stats[kf125PulseTime]++; iptr++; break;
601 case 9: word_stats[kf125FDCPulse9]++;
602 iptr++;
603 if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125FDCPulse9]++; iptr++; }
604 daq_hits_per_event->Fill(rocid);
605 break;
606 case 10: word_stats[kf125PulsePedestal]++; iptr++; break;
607 case 13: word_stats[kf125EventTrailer]++; iptr++; break;
608 case 14: word_stats[kf125DataNotValid]++; iptr++; break;
609 case 15: word_stats[kf125Filler]++; iptr++; break;
610
611 default: word_stats[kf125Unknown]++; iptr++; break;
612 }
613 }
614}
615
616//------------------
617// ParseF1v2TDCBank
618//------------------
619void DMapEVIOWords::ParseF1v2TDCBank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
620{
621 while(iptr<iend){
622 switch( (*iptr++) & 0xF8000000 ){
623 case 0xC0000000: word_stats[kF1v2ChipHeader]++; break;
624 case 0xB8000000: word_stats[kF1v2Data]++; daq_hits_per_event->Fill(rocid); break;
625 case 0xF8000000: word_stats[kF1v2Filler]++; break;
626 case 0x80000000: word_stats[kF1v2BlockHeader]++; break;
627 case 0x88000000: word_stats[kF1v2BLockTrailer]++; break;
628 case 0x90000000: word_stats[kF1v2EventHeader]++; break;
629 case 0x98000000: word_stats[kF1v2TriggerTime]++; break;
630 case 0xF0000000: word_stats[kF1v2BreakWord]++; break;
631 default: word_stats[kF1v2Unknown]++; break;
632 }
633 }
634}
635
636//------------------
637// ParseF1v3TDCBank
638//------------------
639void DMapEVIOWords::ParseF1v3TDCBank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
640{
641 while(iptr<iend){
642 switch( (*iptr++) & 0xF8000000 ){
643 case 0xC0000000: word_stats[kF1v3ChipHeader]++; break;
644 case 0xB8000000: word_stats[kF1v3Data]++; daq_hits_per_event->Fill(rocid); break;
645 case 0xF8000000: word_stats[kF1v3Filler]++; break;
646 case 0x80000000: word_stats[kF1v3BlockHeader]++; break;
647 case 0x88000000: word_stats[kF1v3BLockTrailer]++; break;
648 case 0x90000000: word_stats[kF1v3EventHeader]++; break;
649 case 0x98000000: word_stats[kF1v3TriggerTime]++; break;
650 case 0xF0000000: word_stats[kF1v3BreakWord]++; break;
651 default: word_stats[kF1v3Unknown]++; break;
652 }
653 }
654}
655
656//------------------
657// ParseCAEN1190
658//------------------
659void DMapEVIOWords::ParseCAEN1190(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
660{
661 while(iptr<iend){
662
663 // This word appears to be appended to the data.
664 // Probably in the ROL. Ignore it if found.
665 if(*iptr == 0xd00dd00d) {
666 word_stats[kD00DD00D]++;
667 iptr++;
668 continue;
669 }
670
671 uint32_t type = (*iptr++) >> 27;
672 switch(type){
673 case 0b01000: word_stats[kCAEN1190GlobalHeader]++; break;
674 case 0b10000: word_stats[kCAEN1190GlobalTrailer]++; break;
675 case 0b10001: word_stats[kCAEN1190GlobalTriggerTime]++; break;
676 case 0b00001: word_stats[kCAEN1190TDCHeader]++; break;
677 case 0b00000: word_stats[kCAEN1190TDCData]++; daq_hits_per_event->Fill(rocid); break;
678 case 0b00100: word_stats[kCAEN1190TDCError]++; break;
679 case 0b00011: word_stats[kCAEN1190TDCTrailer]++; break;
680 case 0b11000: word_stats[kCAEN1190Filler]++; break;
681 default: word_stats[kCAEN1190Unknown]++; break;
682 }
683 }
684}
685
686//------------------
687// ParseModuleConfiguration
688//------------------
689void DMapEVIOWords::ParseModuleConfiguration(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
690{
691 while(iptr < iend){
692
693 word_stats[kConfig]++; // Count headers as generic
694 uint32_t Nvals = ((*iptr++) >> 24) & 0xFF;
695
696 // Loop over all parameters in this section
697 for(uint32_t i=0; i< Nvals; i++){
698
699 switch((*iptr++)>>24){
700 case 0x05: word_stats[kConfigf250]++; break;
701 case 0x0F: word_stats[kConfigf125]++; break;
702 case 0x06: word_stats[kConfigF1]++; break;
703 case 0x10: word_stats[kConfigCAEN1190]++; break;
704 default: word_stats[kConfig]++; break;
705 }
706 }
707 }
708}
709
710//------------------
711// ParseTSscalerBank
712//------------------
713void DMapEVIOWords::ParseTSscalerBank(uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats)
714{
715 word_stats[kTSsync] += (uint32_t)( (uint64_t)iend - (uint64_t)iptr)/sizeof(uint32_t) ;
716
717 iptr = iend;
718}