1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include <stdint.h> |
9 | #include <vector> |
10 | |
11 | #include "JEventProcessor_DAQ_online.h" |
12 | #include <JANA/JApplication.h> |
13 | #include <JANA/JFactory.h> |
14 | |
15 | using namespace std; |
16 | using namespace jana; |
17 | |
18 | #include <DAQ/DF1TDCHit.h> |
19 | #include <DAQ/Df250PulseIntegral.h> |
20 | #include <DAQ/JEventSource_EVIO.h> |
21 | #include <TTAB/DTranslationTable.h> |
22 | |
23 | #include <TDirectory.h> |
24 | #include <TH2.h> |
25 | #include <TH1.h> |
26 | #include <TProfile.h> |
27 | #include <TProfile2D.h> |
28 | #include <TROOT.h> |
29 | |
30 | |
31 | static const int highcratenum=100; |
32 | |
33 | static TH2I *daq_occ_crates[highcratenum]; |
34 | static TProfile2D *daq_ped_crates[highcratenum]; |
35 | static TProfile2D *daq_TDClocked_crates[highcratenum]; |
36 | static TProfile2D *daq_TDCovr_crates[highcratenum]; |
37 | static TProfile *daq_hits_per_event; |
38 | static TProfile *daq_words_per_event; |
39 | static TH1D *daq_event_size; |
40 | static TH1D *daq_event_tdiff; |
41 | static TH1D *daq_words_by_type; |
42 | static bool ttab_labels_set = false; |
43 | |
44 | |
45 | extern "C"{ |
46 | void InitPlugin(JApplication *app){ |
47 | InitJANAPlugin(app); |
48 | app->AddProcessor(new JEventProcessor_DAQ_online()); |
49 | } |
50 | } |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | JEventProcessor_DAQ_online::JEventProcessor_DAQ_online() |
57 | { |
58 | |
59 | } |
60 | |
61 | |
62 | |
63 | |
64 | JEventProcessor_DAQ_online::~JEventProcessor_DAQ_online() |
65 | { |
66 | |
67 | } |
68 | |
69 | |
70 | |
71 | |
72 | jerror_t JEventProcessor_DAQ_online::init(void) |
73 | { |
74 | printf("JEventProcessor_DAQ_online::init()\n"); |
75 | |
76 | |
77 | japp->RootWriteLock(); |
78 | |
79 | |
80 | maindir = gDirectory(TDirectory::CurrentDirectory()); |
81 | daqdir = maindir->mkdir("DAQ"); |
82 | daqdir->cd(); |
83 | |
84 | |
85 | for (int i=0; i<highcratenum; i++) { |
86 | daq_occ_crates[i] = NULL__null; |
87 | daq_ped_crates[i] = NULL__null; |
88 | daq_TDClocked_crates[i] = NULL__null; |
89 | daq_TDCovr_crates[i] = NULL__null; |
90 | } |
91 | |
92 | daq_hits_per_event = new TProfile("daq_hits_per_event", "Hits/event vs. rocid", 100, 0.5, 100.5); |
93 | daq_words_per_event = new TProfile("daq_words_per_event", "words/event vs. rocid", 100, 0.5, 100.5); |
94 | daq_event_size = new TH1D("daq_event_size", "Event size in kB", 1000, 0.0, 1.0E3); |
95 | daq_event_tdiff = new TH1D("daq_event_tdiff", "Time between events", 10000, 0.0, 1.0E2); |
96 | daq_words_by_type = new TH1D("daq_words_by_type", "Number of words in EVIO file by type", kNEVIOWordTypes, 0, (double)kNEVIOWordTypes); |
97 | |
98 | daq_words_per_event->GetXaxis()->SetBinLabel(1 ,"Trigger Bank"); |
99 | daq_words_per_event->GetXaxis()->SetBinLabel(99 ,"Residual"); |
100 | |
101 | daq_event_size->SetXTitle("Total event size (kB)"); |
102 | daq_event_tdiff->SetXTitle("#deltat between events (ms)"); |
103 | |
104 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kUnknown, "unknown"); |
105 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEVIOEventNumber, "Event Number Word"); |
106 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEVIOTimestamp, "Timestamp"); |
107 | |
108 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250BlockHeader, "f250 Block Header"); |
109 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250BlockTrailer, "f250 Block Trailer"); |
110 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250EventHeader, "f250 Event Header"); |
111 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250TriggerTime, "f250 Trigger Time"); |
112 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250WindowRawData, "f250 Window Raw Data"); |
113 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250WindowSum, "f250 Window Sum"); |
114 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseRawData, "f250 Pulse Raw Data"); |
115 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseIntegral, "f250 Pulse Integral"); |
116 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulseTime, "f250 Pulse Time"); |
117 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250PulsePedestal, "f250 Pulse Pedestal"); |
118 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250EventTrailer, "f250 Event Trailer"); |
119 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250DataNotValid, "f250 Data Not Valid"); |
120 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf250Filler, "f250 Filler Word"); |
121 | |
122 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125BlockHeader, "f125 Block Header"); |
123 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125BlockTrailer, "f125 Block Trailer"); |
124 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125EventHeader, "f125 Event Header"); |
125 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125TriggerTime, "f125 Trigger Time"); |
126 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125WindowRawData, "f125 Window Raw Data"); |
127 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125CDCPulse, "f125 CDC Pulse"); |
128 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125FDCPulse6, "f125 FDC Pulse (integral)"); |
129 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125FDCPulse9, "f125 FDC Pulse (peak)"); |
130 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulseIntegral, "f125 Pulse Integral"); |
131 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulseTime, "f125 Pulse Time"); |
132 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125PulsePedestal, "f125 Pulse Pedestal"); |
133 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125EventTrailer, "f125 Event Trailer"); |
134 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125DataNotValid, "f125 Data Not Valid"); |
135 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kf125Filler, "f125 Filler Word"); |
136 | |
137 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BlockHeader, "F1v2 Block Header"); |
138 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BLockTrailer, "F1v2 Block Trailer"); |
139 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2EventHeader, "F1v2 Event Header"); |
140 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2TriggerTime, "F1v2 Trigger Time"); |
141 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2ChipHeader, "F1v2 Chip Header"); |
142 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2Data, "F1v2 Data"); |
143 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2Filler, "F1v2 Filler"); |
144 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v2BreakWord, "F1v2 Break Word"); |
145 | |
146 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BlockHeader, "F1v3 Block Header"); |
147 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BLockTrailer, "F1v3 Block Trailer"); |
148 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3EventHeader, "F1v3 Event Header"); |
149 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3TriggerTime, "F1v3 Trigger Time"); |
150 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3ChipHeader, "F1v3 Chip Header"); |
151 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3Data, "F1v3 Data"); |
152 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3Filler, "F1v3 Filler"); |
153 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF1v3BreakWord, "F1v3 Break Word"); |
154 | |
155 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalHeader, "CAEN1190 GLobal Header"); |
156 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalTrailer, "CAEN1190 Global Trailer"); |
157 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190GlobalTriggerTime, "CAEN1190 Trigger Time"); |
158 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCHeader, "CAEN1190 TDC Header"); |
159 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCData, "CAEN1190 TDC Data"); |
160 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCError, "CAEN1190 TDC Error"); |
161 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190TDCTrailer, "CAEN1190 TDC Trailer"); |
162 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kCAEN1190Filler, "CAEN1190 Filler"); |
163 | |
164 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfig, "DAQ Config"); |
165 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigf250, "DAQ Config f250"); |
166 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigf125, "DAQ Config f125"); |
167 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigF1, "DAQ Config F1"); |
168 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kConfigCAEN1190, "DAQ Config CAEN1190"); |
169 | |
170 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEPICSheader, "EPICS header"); |
171 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kEPICSdata, "EPICS data"); |
172 | |
173 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kF800FAFA, "0xf800fafa"); |
174 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kD00DD00D, "0xd00dd00d"); |
175 | |
176 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kTotWords, "Total words in all events"); |
177 | daq_words_by_type->GetXaxis()->SetBinLabel(1 + kNevents, "Number of events"); |
178 | |
179 | |
180 | maindir->cd(); |
181 | |
182 | |
183 | japp->RootUnLock(); |
184 | |
185 | return NOERROR; |
186 | } |
187 | |
188 | |
189 | |
190 | |
191 | void JEventProcessor_DAQ_online::AddROCIDLabels(JEventLoop *loop) |
192 | { |
193 | |
194 | |
195 | |
196 | |
197 | const DTranslationTable *ttab = NULL__null; |
198 | loop->GetSingle(ttab); |
199 | |
200 | japp->RootWriteLock(); |
201 | |
202 | |
203 | for(uint32_t rocid=2; rocid<99; rocid++){ |
204 | |
205 | |
206 | bool found_chan = false; |
207 | daq_hits_per_event->GetXaxis()->SetBinLabel(rocid, ""); |
208 | daq_words_per_event->GetXaxis()->SetBinLabel(rocid, ""); |
209 | for(uint32_t slot=2; slot<24; slot++){ |
210 | for(uint32_t channel=0; channel<3; channel++){ |
211 | try{ |
212 | DTranslationTable::csc_t csc = {rocid, slot, channel}; |
213 | const DTranslationTable::DChannelInfo &chinfo = ttab->GetDetectorIndex(csc); |
214 | daq_hits_per_event->GetXaxis()->SetBinLabel(rocid, ttab->DetectorName(chinfo.det_sys).c_str()); |
215 | daq_words_per_event->GetXaxis()->SetBinLabel(rocid, ttab->DetectorName(chinfo.det_sys).c_str()); |
216 | found_chan = true; |
217 | break; |
218 | }catch(JException &e){ |
219 | |
220 | } |
221 | } |
222 | if(found_chan) break; |
223 | } |
224 | } |
225 | |
226 | japp->RootUnLock(); |
227 | } |
228 | |
229 | |
230 | |
231 | |
232 | jerror_t JEventProcessor_DAQ_online::brun(JEventLoop *eventLoop, int32_t runnumber) |
233 | { |
234 | |
235 | return NOERROR; |
236 | } |
237 | |
238 | |
239 | |
240 | |
241 | jerror_t JEventProcessor_DAQ_online::evnt(JEventLoop *loop, uint64_t eventnumber) |
242 | { |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | vector<const DF1TDCHit*> f1tdchits; |
250 | vector<const Df250PulseIntegral*> f250PIs; |
251 | vector<const Df125PulseIntegral*> f125PIs; |
252 | vector<const DCAEN1290TDCHit*> caen1290hits; |
253 | |
254 | loop->Get(f1tdchits); |
255 | loop->Get(f250PIs); |
256 | loop->Get(f125PIs); |
257 | loop->Get(caen1290hits); |
258 | |
259 | ParseEventSize(loop->GetJEvent()); |
260 | |
261 | |
262 | if(!ttab_labels_set){ |
263 | ttab_labels_set = true; |
264 | AddROCIDLabels(loop); |
265 | } |
266 | |
267 | |
268 | uint32_t Nhits_rocid[101]; |
269 | for(uint32_t rocid=0; rocid<101; rocid++) Nhits_rocid[rocid] = 0; |
270 | |
271 | |
272 | japp->RootWriteLock(); |
273 | |
274 | if (daqdir!=NULL__null) daqdir->cd(); |
275 | |
276 | |
277 | |
278 | for(unsigned int i=0; i<f1tdchits.size(); i++) { |
279 | const DF1TDCHit *hit = f1tdchits[i]; |
280 | int rocid = hit->rocid; |
281 | int slot = hit->slot; |
282 | int channel = hit->channel; |
283 | int data_word = hit->data_word; |
284 | |
285 | if(rocid>=0 && rocid<=100) Nhits_rocid[rocid]++; |
286 | |
287 | if (daq_occ_crates[rocid]==NULL__null) { |
288 | printf("JEventProcessor_DAQ_online::evnt creating occupancy histogram for crate %i\n",rocid); |
289 | char cratename[255],title[255]; |
290 | sprintf(cratename,"daq_occ_crate%i",rocid); |
291 | sprintf(title,"Crate %i occupancy (TDC);Slot;Channel",rocid); |
292 | daq_occ_crates[rocid] = new TH2I(cratename,title,21,0.5,21.5,32,-0.5,31.5); |
293 | daq_occ_crates[rocid]->SetStats(0); |
294 | sprintf(cratename,"daq_TDClocked_crate%i",rocid); |
295 | sprintf(title,"Crate %i TDC lock status (TDC);Slot;Channel",rocid); |
296 | daq_TDClocked_crates[rocid] = new TProfile2D(cratename,title,21,0.5,21.5,32,-0.5,31.5); |
297 | daq_TDClocked_crates[rocid]->SetStats(0); |
298 | sprintf(cratename,"daq_TDCovr_crate%i",rocid); |
299 | sprintf(title,"Crate %i TDC overflow status (TDC);Slot;Channel",rocid); |
300 | daq_TDCovr_crates[rocid] = new TProfile2D(cratename,title,21,0.5,21.5,32,-0.5,31.5); |
301 | daq_TDCovr_crates[rocid]->SetStats(0); |
302 | |
303 | } |
304 | daq_occ_crates[rocid]->Fill(slot,channel); |
305 | daq_TDClocked_crates[rocid]->Fill(slot,channel,(data_word>>26)&(1)); |
306 | daq_TDCovr_crates[rocid]->Fill(slot,channel,(data_word>>25)&(1)); |
307 | daq_TDCovr_crates[rocid]->Fill(slot,channel,(data_word>>24)&(1)); |
308 | } |
309 | |
310 | |
311 | for(unsigned int i=0; i<f250PIs.size(); i++) { |
312 | const Df250PulseIntegral *hit = f250PIs[i]; |
313 | int rocid = hit->rocid; |
314 | int slot = hit->slot; |
315 | int channel = hit->channel; |
316 | |
317 | if(rocid>=0 && rocid<=100) { |
318 | Nhits_rocid[rocid]++; |
319 | |
320 | if (daq_occ_crates[rocid]==NULL__null) { |
321 | printf("JEventProcessor_DAQ_online::evnt creating occupancy histogram for crate %i\n",rocid); |
322 | char cratename[255],title[255]; |
323 | sprintf(cratename,"daq_occ_crate%i",rocid); |
324 | sprintf(title,"Crate %i occupancy (F250);Slot;Channel",rocid); |
325 | daq_occ_crates[rocid] = new TH2I(cratename,title,21,0.5,21.5,16,-0.5,15.5); |
326 | daq_occ_crates[rocid]->SetStats(0); |
327 | } |
328 | daq_occ_crates[rocid]->Fill(slot,channel); |
329 | |
330 | if (daq_ped_crates[rocid]==NULL__null) { |
331 | printf("JEventProcessor_DAQ_online::evnt creating pedestal histogram for crate %i\n",rocid); |
332 | char cratename[255],title[255]; |
333 | sprintf(cratename,"daq_ped_crate%i",rocid); |
334 | sprintf(title,"Crate %i Average Pedestal (F250);Slot;Channel",rocid); |
335 | daq_ped_crates[rocid] = new TProfile2D(cratename,title,21,0.5,21.5,16,-0.5,15.5); |
336 | daq_ped_crates[rocid]->SetStats(0); |
337 | } |
338 | if (hit->pedestal > 0) { |
339 | daq_ped_crates[rocid]->Fill(slot,channel,hit->pedestal); |
340 | } |
341 | } |
342 | } |
343 | |
344 | |
345 | for(unsigned int i=0; i<f125PIs.size(); i++) { |
346 | const Df125PulseIntegral *hit = f125PIs[i]; |
347 | int rocid = hit->rocid; |
348 | int slot = hit->slot; |
349 | int channel = hit->channel; |
350 | |
351 | if(rocid>=0 && rocid<=100) { |
352 | Nhits_rocid[rocid]++; |
353 | |
354 | if (daq_occ_crates[rocid]==NULL__null) { |
355 | printf("JEventProcessor_DAQ_online::evnt creating occupancy histogram for crate %i\n",rocid); |
356 | char cratename[255],title[255]; |
357 | sprintf(cratename,"daq_occ_crate%i",rocid); |
358 | sprintf(title,"Crate %i occupancy (F250);Slot;Channel",rocid); |
359 | daq_occ_crates[rocid] = new TH2I(cratename,title,21,0.5,21.5,16,-0.5,15.5); |
360 | daq_occ_crates[rocid]->SetStats(0); |
361 | } |
362 | daq_occ_crates[rocid]->Fill(slot,channel); |
363 | |
364 | if (daq_ped_crates[rocid]==NULL__null) { |
365 | printf("JEventProcessor_DAQ_online::evnt creating pedestal histogram for crate %i\n",rocid); |
366 | char cratename[255],title[255]; |
367 | sprintf(cratename,"daq_ped_crate%i",rocid); |
368 | sprintf(title,"Crate %i Average Pedestal (F250);Slot;Channel",rocid); |
369 | daq_ped_crates[rocid] = new TProfile2D(cratename,title,21,0.5,21.5,16,-0.5,15.5); |
370 | daq_ped_crates[rocid]->SetStats(0); |
371 | } |
372 | if (hit->pedestal > 0) { |
373 | daq_ped_crates[rocid]->Fill(slot,channel,hit->pedestal); |
374 | } |
375 | } |
376 | |
377 | } |
378 | |
379 | |
380 | for(unsigned int i=0; i<caen1290hits.size(); i++) { |
381 | const DCAEN1290TDCHit *hit = caen1290hits[i]; |
382 | int rocid = hit->rocid; |
383 | |
384 | |
385 | |
386 | if(rocid>=0 && rocid<=100) Nhits_rocid[rocid]++; |
387 | } |
388 | |
389 | |
390 | for(uint32_t rocid=0; rocid<101; rocid++) daq_hits_per_event->Fill(rocid, Nhits_rocid[rocid]); |
391 | |
392 | |
393 | maindir->cd(); |
394 | |
395 | japp->RootUnLock(); |
396 | |
397 | return NOERROR; |
398 | } |
399 | |
400 | |
401 | |
402 | |
403 | void JEventProcessor_DAQ_online::ParseEventSize(JEvent &event) |
404 | { |
405 | |
406 | |
407 | |
408 | if(event.GetJEventSource()->className() != string("JEventSource_EVIO")){ |
409 | static bool warned = false; |
410 | if(!warned){ |
411 | cout << "WARNING: This is not an event source of type JEventSource_EVIO!" << endl; |
412 | cout << " Event size statistics filling unavailable!" << endl; |
413 | warned = true; |
414 | } |
415 | return; |
416 | } |
417 | |
418 | void *ref = event.GetRef(); |
419 | if(!ref) return; |
420 | uint32_t *istart = JEventSource_EVIO::GetEVIOBufferFromRef(ref); |
421 | uint32_t evio_buffsize = JEventSource_EVIO::GetEVIOBufferSizeFromRef(ref); |
422 | uint32_t evio_buffwords = evio_buffsize/sizeof(uint32_t); |
423 | uint32_t *iend = &istart[evio_buffwords]; |
424 | |
425 | if( istart==NULL__null ) return; |
426 | if( (evio_buffwords>=10) && (istart[7]==0xc0da0100) ){ |
427 | |
428 | istart= &istart[8]; |
429 | evio_buffsize -= 8*sizeof(uint32_t); |
| Value stored to 'evio_buffsize' is never read |
430 | evio_buffwords -= 8; |
431 | } |
432 | |
433 | |
434 | if( evio_buffwords >= 4 ){ |
435 | if( istart[1] == (0x60<<16) + (0xD<<8) + (0x1<<0) ){ |
436 | if( istart[2] == (0x61<<24) + (0x1<<16) + (0x1<<0) ){ |
437 | |
438 | japp->RootWriteLock(); |
439 | daq_words_by_type->Fill(kEPICSheader, 3.0); |
440 | daq_words_by_type->Fill(kEPICSdata, istart[0]/sizeof(uint32_t) - 3); |
441 | japp->RootUnLock(); |
442 | return; |
443 | } |
444 | } |
445 | } |
446 | |
447 | |
448 | uint32_t physics_event_len = istart[0]; |
449 | if( (istart[1] & 0xFF001000) != 0xFF001000 ) return; |
450 | |
451 | |
452 | uint32_t trigger_bank_len = istart[2]; |
453 | if( (istart[3] & 0xFF202000) != 0xFF202000 ) return; |
454 | uint64_t tlo = istart[2+5]; |
455 | uint64_t thi = istart[2+6]; |
456 | uint64_t timestamp = (thi<<32) + (tlo<<0); |
457 | |
458 | |
459 | uint32_t Nwords[100]; |
460 | uint32_t word_stats[kNEVIOWordTypes]; |
461 | for(uint32_t rocid=0; rocid<100; rocid++) Nwords[rocid] = 0; |
462 | for(uint32_t i=0; i<kNEVIOWordTypes; i++) word_stats[i] = 0; |
463 | |
464 | word_stats[kNevents]++; |
465 | word_stats[kTotWords] += evio_buffwords; |
466 | |
467 | |
468 | uint32_t *iptr = &istart[3+trigger_bank_len]; |
469 | while(iptr < iend){ |
470 | |
471 | uint32_t len = *iptr; |
472 | uint32_t rocid = (iptr[1]>>16) & 0XFF; |
473 | |
474 | if(rocid<100) Nwords[rocid] += len+1; |
475 | |
476 | uint32_t *imyend = &iptr[len+1]; |
477 | if(imyend > iend) imyend = iend; |
478 | |
479 | DataWordStats(iptr, imyend, word_stats); |
480 | |
481 | iptr = &iptr[len +1]; |
482 | } |
483 | |
484 | |
485 | japp->RootWriteLock(); |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | |
492 | |
493 | uint32_t event_num = event.GetEventNumber(); |
494 | static uint32_t recent_event_nums[128]; |
495 | static uint64_t recent_timestamps[128]; |
496 | static uint32_t ievent = 0; |
497 | for(uint32_t i=0; i<ievent; i++){ |
498 | if(i>=128) break; |
499 | if(recent_event_nums[i] == (event_num-1)){ |
500 | double tdiff = (double)(timestamp - recent_timestamps[i])/250.0E6; |
501 | daq_event_tdiff->Fill(tdiff*1000.0); |
502 | break; |
503 | } |
504 | } |
505 | |
506 | |
507 | uint32_t idx = ievent%128; |
508 | recent_event_nums[idx] = event_num; |
509 | recent_timestamps[idx] = timestamp; |
510 | ievent++; |
511 | |
512 | |
513 | double physics_event_len_kB = (double)((physics_event_len+1)*sizeof(uint32_t))/1024.0; |
514 | daq_event_size->Fill(physics_event_len_kB); |
515 | uint32_t TotalWords = 0; |
516 | for(uint32_t rocid=0; rocid<100; rocid++){ |
517 | daq_words_per_event->Fill(rocid, Nwords[rocid]); |
518 | TotalWords += Nwords[rocid]; |
519 | } |
520 | |
521 | daq_words_per_event->Fill(1, trigger_bank_len+1); |
522 | daq_words_per_event->Fill(99, physics_event_len - trigger_bank_len - TotalWords); |
523 | |
524 | for(uint32_t i=0; i<kNEVIOWordTypes; i++){ |
525 | daq_words_by_type->Fill(i, (double)word_stats[i]); |
526 | } |
527 | |
528 | japp->RootUnLock(); |
529 | |
530 | } |
531 | |
532 | |
533 | |
534 | |
535 | void JEventProcessor_DAQ_online::DataWordStats(uint32_t *iptr, uint32_t *iend, uint32_t *word_stats) |
536 | { |
537 | |
538 | |
539 | |
540 | |
541 | iptr++; |
542 | uint32_t rocid = (*iptr++)>>16 & 0x0FFF; |
543 | while(iptr < iend){ |
544 | uint32_t data_block_bank_len = *iptr++; |
545 | uint32_t *iendbank = &iptr[data_block_bank_len]; |
546 | uint32_t det_id = ((*iptr) >> 16) & 0x0FFF; |
547 | iptr++; |
548 | |
549 | uint32_t Ntoprocess = data_block_bank_len - 1; |
550 | |
551 | #if 0 // I don't know if these words are actually implmented ?? |
552 | word_stats[kEVIOEventNumber]++; |
553 | word_stats[kEVIOTimestamp] += 2; |
554 | iptr++; |
555 | iptr++; |
556 | iptr++; |
557 | Ntoprocess -= 3; |
558 | #endif |
559 | uint32_t *irawdata = iptr; |
560 | |
561 | switch(det_id){ |
562 | case 0: |
563 | case 1: |
564 | case 3: |
565 | case 6: |
566 | case 16: |
567 | case 26: |
568 | ParseJLabModuleData(rocid, iptr, iendbank, word_stats); |
569 | break; |
570 | |
571 | case 20: |
572 | ParseCAEN1190(rocid, iptr, iendbank, word_stats); |
573 | break; |
574 | |
575 | case 0x55: |
576 | ParseModuleConfiguration(rocid, iptr, iendbank, word_stats); |
577 | break; |
578 | default: |
579 | break; |
580 | } |
581 | |
582 | uint32_t Nprocessed = (uint32_t)((uint64_t)iptr - (uint64_t)irawdata)/sizeof(uint32_t); |
583 | if(Nprocessed < Ntoprocess) word_stats[kUnknown] += Ntoprocess - Nprocessed; |
584 | iptr = iendbank; |
585 | } |
586 | |
587 | |
588 | } |
589 | |
590 | |
591 | |
592 | |
593 | void JEventProcessor_DAQ_online::ParseJLabModuleData(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats) |
594 | { |
595 | while(iptr < iend){ |
596 | if(*iptr != 0xf800fafa) break; |
597 | word_stats[kF800FAFA]++; |
598 | iptr++; |
599 | } |
600 | |
601 | uint32_t mod_id = ((*iptr) >> 18) & 0x000F; |
602 | switch(mod_id){ |
603 | case DModuleType::FADC250: Parsef250Bank(rocid, iptr, iend, word_stats); break; |
604 | case DModuleType::FADC125: Parsef125Bank(rocid, iptr, iend, word_stats); break; |
605 | case DModuleType::F1TDC32: ParseF1v2TDCBank(rocid, iptr, iend, word_stats); break; |
606 | case DModuleType::F1TDC48: ParseF1v3TDCBank(rocid, iptr, iend, word_stats); break; |
607 | |
608 | |
609 | } |
610 | } |
611 | |
612 | |
613 | |
614 | |
615 | void JEventProcessor_DAQ_online::Parsef250Bank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats) |
616 | { |
617 | while(iptr<iend){ |
618 | |
619 | if(((*iptr>>31) & 0x1) == 0) { word_stats[kUnknown]++ ; iptr++; continue;} |
620 | |
621 | uint32_t window_width; |
622 | uint32_t window_words; |
623 | uint32_t data_type = (*iptr>>27) & 0x0F; |
624 | switch(data_type){ |
625 | case 0: word_stats[kf250BlockHeader]++; iptr++; break; |
626 | case 1: word_stats[kf250BlockTrailer]++; iptr++; break; |
627 | case 2: word_stats[kf250EventHeader]++; iptr++; break; |
628 | case 3: |
629 | word_stats[kf250TriggerTime]++; |
630 | iptr++; |
631 | if(((*iptr>>31) & 0x1) == 0){ word_stats[kf250TriggerTime]++; iptr++; } |
632 | break; |
633 | case 4: |
634 | window_width = (*iptr>>0) & 0x0FFF; |
635 | window_words = 1 + ((window_width+1)/2); |
636 | word_stats[kf250WindowRawData] += window_words; |
637 | iptr = &iptr[window_words]; |
638 | break; |
639 | case 7: word_stats[kf250PulseIntegral]++; iptr++; break; |
640 | case 8: word_stats[kf250PulseTime]++; iptr++; break; |
641 | case 10: word_stats[kf250PulsePedestal]++; iptr++; break; |
642 | case 13: word_stats[kf250EventTrailer]++; iptr++; break; |
643 | case 14: word_stats[kf250DataNotValid]++; iptr++; break; |
644 | case 15: word_stats[kf250Filler]++; iptr++; break; |
645 | |
646 | default: word_stats[kUnknown]++; iptr++; break; |
647 | } |
648 | } |
649 | } |
650 | |
651 | |
652 | |
653 | |
654 | void JEventProcessor_DAQ_online::Parsef125Bank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats) |
655 | { |
656 | while(iptr<iend){ |
657 | |
658 | if(((*iptr>>31) & 0x1) == 0) { word_stats[kUnknown]++ ; iptr++; continue;} |
659 | |
660 | uint32_t window_width; |
661 | uint32_t window_words; |
662 | uint32_t data_type = (*iptr>>27) & 0x0F; |
663 | switch(data_type){ |
664 | case 0: word_stats[kf125BlockHeader]++; iptr++; break; |
665 | case 1: word_stats[kf125BlockTrailer]++; iptr++; break; |
666 | case 2: word_stats[kf125EventHeader]++; iptr++; break; |
667 | case 3: |
668 | word_stats[kf125TriggerTime]++; |
669 | iptr++; |
670 | if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125TriggerTime]++; iptr++; } |
671 | break; |
672 | case 4: |
673 | window_width = (*iptr>>0) & 0x0FFF; |
674 | window_words = 1 + ((window_width+1)/2); |
675 | word_stats[kf125WindowRawData] += window_words; |
676 | iptr = &iptr[window_words]; |
677 | break; |
678 | case 5: word_stats[kf125CDCPulse]++; |
679 | iptr++; |
680 | if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125CDCPulse]++; iptr++; } |
681 | break; |
682 | case 6: word_stats[kf125FDCPulse6]++; |
683 | iptr++; |
684 | if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125FDCPulse6]++; iptr++; } |
685 | break; |
686 | case 7: word_stats[kf125PulseIntegral]++; iptr++; break; |
687 | case 8: word_stats[kf125PulseTime]++; iptr++; break; |
688 | case 9: word_stats[kf125FDCPulse9]++; |
689 | iptr++; |
690 | if(((*iptr>>31) & 0x1) == 0){ word_stats[kf125FDCPulse9]++; iptr++; } |
691 | break; |
692 | case 10: word_stats[kf125PulsePedestal]++; iptr++; break; |
693 | case 13: word_stats[kf125EventTrailer]++; iptr++; break; |
694 | case 14: word_stats[kf125DataNotValid]++; iptr++; break; |
695 | case 15: word_stats[kf125Filler]++; iptr++; break; |
696 | |
697 | default: word_stats[kUnknown]++; iptr++; break; |
698 | } |
699 | } |
700 | } |
701 | |
702 | |
703 | |
704 | |
705 | void JEventProcessor_DAQ_online::ParseF1v2TDCBank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats) |
706 | { |
707 | while(iptr<iend){ |
708 | switch( (*iptr++) & 0xF8000000 ){ |
709 | case 0xC0000000: word_stats[kF1v2ChipHeader]++; break; |
710 | case 0xB8000000: word_stats[kF1v2Data]++; break; |
711 | case 0xF8000000: word_stats[kF1v2Filler]++; break; |
712 | case 0x80000000: word_stats[kF1v2BlockHeader]++; break; |
713 | case 0x88000000: word_stats[kF1v2BLockTrailer]++; break; |
714 | case 0x90000000: word_stats[kF1v2EventHeader]++; break; |
715 | case 0x98000000: word_stats[kF1v2TriggerTime]++; break; |
716 | case 0xF0000000: word_stats[kF1v2BreakWord]++; break; |
717 | default: word_stats[kUnknown]++; break; |
718 | } |
719 | } |
720 | } |
721 | |
722 | |
723 | |
724 | |
725 | void JEventProcessor_DAQ_online::ParseF1v3TDCBank(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats) |
726 | { |
727 | while(iptr<iend){ |
728 | switch( (*iptr++) & 0xF8000000 ){ |
729 | case 0xC0000000: word_stats[kF1v3ChipHeader]++; break; |
730 | case 0xB8000000: word_stats[kF1v3Data]++; break; |
731 | case 0xF8000000: word_stats[kF1v3Filler]++; break; |
732 | case 0x80000000: word_stats[kF1v3BlockHeader]++; break; |
733 | case 0x88000000: word_stats[kF1v3BLockTrailer]++; break; |
734 | case 0x90000000: word_stats[kF1v3EventHeader]++; break; |
735 | case 0x98000000: word_stats[kF1v3TriggerTime]++; break; |
736 | case 0xF0000000: word_stats[kF1v3BreakWord]++; break; |
737 | default: word_stats[kUnknown]++; break; |
738 | } |
739 | } |
740 | } |
741 | |
742 | |
743 | |
744 | |
745 | void JEventProcessor_DAQ_online::ParseCAEN1190(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats) |
746 | { |
747 | while(iptr<iend){ |
748 | |
749 | |
750 | |
751 | if(*iptr == 0xd00dd00d) { |
752 | word_stats[kD00DD00D]++; |
753 | iptr++; |
754 | continue; |
755 | } |
756 | |
757 | uint32_t type = (*iptr++) >> 27; |
758 | switch(type){ |
759 | case 0b01000: word_stats[kCAEN1190GlobalHeader]++; break; |
760 | case 0b10000: word_stats[kCAEN1190GlobalTrailer]++; break; |
761 | case 0b10001: word_stats[kCAEN1190GlobalTriggerTime]++; break; |
762 | case 0b00001: word_stats[kCAEN1190TDCHeader]++; break; |
763 | case 0b00000: word_stats[kCAEN1190TDCData]++; break; |
764 | case 0b00100: word_stats[kCAEN1190TDCError]++; break; |
765 | case 0b00011: word_stats[kCAEN1190TDCTrailer]++; break; |
766 | case 0b11000: word_stats[kCAEN1190Filler]++; break; |
767 | default: word_stats[kUnknown]++; break; |
768 | } |
769 | } |
770 | } |
771 | |
772 | |
773 | |
774 | |
775 | void JEventProcessor_DAQ_online::ParseModuleConfiguration(uint32_t rocid, uint32_t *&iptr, uint32_t *iend, uint32_t *word_stats) |
776 | { |
777 | while(iptr < iend){ |
778 | |
779 | word_stats[kConfig]++; |
780 | uint32_t Nvals = ((*iptr++) >> 24) & 0xFF; |
781 | |
782 | |
783 | for(uint32_t i=0; i< Nvals; i++){ |
784 | |
785 | switch((*iptr++)>>24){ |
786 | case 0x05: word_stats[kConfigf250]++; break; |
787 | case 0x0F: word_stats[kConfigf125]++; break; |
788 | case 0x06: word_stats[kConfigF1]++; break; |
789 | case 0x10: word_stats[kConfigCAEN1190]++; break; |
790 | default: word_stats[kConfig]++; break; |
791 | } |
792 | } |
793 | } |
794 | } |
795 | |
796 | |
797 | |
798 | |
799 | jerror_t JEventProcessor_DAQ_online::erun(void) |
800 | { |
801 | |
802 | |
803 | |
804 | return NOERROR; |
805 | } |
806 | |
807 | |
808 | |
809 | |
810 | jerror_t JEventProcessor_DAQ_online::fini(void) |
811 | { |
812 | |
813 | return NOERROR; |
814 | } |
815 | |