File: | libraries/DAQ/DEVIOWorkerThread.cc |
Location: | line 359, column 26 |
Description: | Value stored to 'iend' is never read |
1 | /// $Id$ |
2 | // |
3 | // File: DEVIOWorkerThread.cc |
4 | // Created: Mon Mar 28 07:40:07 EDT 2016 |
5 | // Creator: davidl (on Darwin harriet.jlab.org 13.4.0 i386) |
6 | // |
7 | |
8 | #include <unistd.h> |
9 | |
10 | #include "DEVIOWorkerThread.h" |
11 | #include "JEventSource_EVIOpp.h" |
12 | #include "LinkAssociations.h" |
13 | |
14 | #include <swap_bank.h> |
15 | |
16 | using namespace std; |
17 | using namespace std::chrono; |
18 | |
19 | |
20 | |
21 | //--------------------------------- |
22 | // DEVIOWorkerThread (Constructor) |
23 | //--------------------------------- |
24 | DEVIOWorkerThread::DEVIOWorkerThread( |
25 | JEventSource_EVIOpp *event_source |
26 | ,list<DParsedEvent*> &parsed_events |
27 | ,uint32_t &MAX_PARSED_EVENTS |
28 | ,mutex &PARSED_EVENTS_MUTEX |
29 | ,condition_variable &PARSED_EVENTS_CV |
30 | ): |
31 | event_source(event_source) |
32 | ,parsed_events(parsed_events) |
33 | ,MAX_PARSED_EVENTS(MAX_PARSED_EVENTS) |
34 | ,PARSED_EVENTS_MUTEX(PARSED_EVENTS_MUTEX) |
35 | ,PARSED_EVENTS_CV(PARSED_EVENTS_CV) |
36 | ,done(false) |
37 | ,thd(&DEVIOWorkerThread::Run,this) |
38 | { |
39 | // n.b. in principal, the worker thread is started when the |
40 | // above constructor is hit and so may already be in Run() |
41 | // before executing anything below. The "done" variable is |
42 | // therefore initialized first to guarantee that if that |
43 | // happens, it gets to the cv.wait() call where it will wait |
44 | // for someone to notify it. That won't happen before this |
45 | // constructor completes so we do the remaining initializations |
46 | // below. |
47 | |
48 | VERBOSE = 1; |
49 | Nrecycled = 0; // Incremented in JEventSource_EVIOpp::Dispatcher() |
50 | MAX_EVENT_RECYCLES = 1000; // In EVIO events (not L1 trigger events!) overwritten in JEventSource_EVIOpp constructor |
51 | MAX_OBJECT_RECYCLES = 1000; // overwritten in JEventSource_EVIOpp constructor |
52 | run_number_seed = 0; // Set in JEventSource_EVIOpp constructor |
53 | |
54 | in_use = false; |
55 | jobtype = JOB_NONE; |
56 | |
57 | buff_len = 100; // this will grow as needed |
58 | buff = new uint32_t[buff_len]; |
59 | |
60 | PARSE_F250 = true; |
61 | PARSE_F125 = true; |
62 | PARSE_F1TDC = true; |
63 | PARSE_CAEN1290TDC = true; |
64 | PARSE_CONFIG = true; |
65 | PARSE_BOR = true; |
66 | PARSE_EPICS = true; |
67 | PARSE_EVENTTAG = true; |
68 | PARSE_TRIGGER = true; |
69 | |
70 | LINK_TRIGGERTIME = true; |
71 | } |
72 | |
73 | //--------------------------------- |
74 | // ~DEVIOWorkerThread (Destructor) |
75 | //--------------------------------- |
76 | DEVIOWorkerThread::~DEVIOWorkerThread() |
77 | { |
78 | if(buff) delete[] buff; |
79 | for(auto pe : parsed_event_pool) delete pe; |
80 | } |
81 | |
82 | //--------------------------------- |
83 | // Run |
84 | //--------------------------------- |
85 | void DEVIOWorkerThread::Run(void) |
86 | { |
87 | unique_lock<std::mutex> lck(mtx); |
88 | |
89 | // Loop waiting for jobs or until told to quit |
90 | while(!done){ |
91 | |
92 | cv.wait_for(lck, std::chrono::milliseconds(1)); |
93 | |
94 | // In principle, in_use should never be false with a jobtype!=JOB_NONE |
95 | // In practice, this has happened, possibly due to compiler optimization |
96 | // reordering things in JEventSource_EVIOpp::Dispatcher. That led to |
97 | // attempting to process a buffer that was being written to. Avoid that |
98 | // condition by checking the in_use flag is really set. |
99 | if( !in_use ) continue; |
100 | |
101 | try { |
102 | |
103 | if( jobtype & JOB_SWAP ) swap_bank(buff, buff, swap32(buff[0])( (((buff[0]) >> 24) & 0x000000FF) | (((buff[0]) >> 8) & 0x0000FF00) | (((buff[0]) << 8) & 0x00FF0000 ) | (((buff[0]) << 24) & 0xFF000000) )+1 ); |
104 | |
105 | if( jobtype & JOB_FULL_PARSE ) MakeEvents(); |
106 | |
107 | if( jobtype & JOB_ASSOCIATE ) LinkAllAssociations(); |
108 | |
109 | if( !current_parsed_events.empty() ) PublishEvents(); |
110 | |
111 | } catch (exception &e) { |
112 | jerr << e.what() << endl; |
113 | for(auto pe : parsed_event_pool) delete pe; // delete all parsed events any any objects they hold |
114 | parsed_event_pool.clear(); |
115 | current_parsed_events.clear(); // (these are also in parsed_event_pool so were already deleted) |
116 | //exit(-1); |
117 | } |
118 | |
119 | // Reset and mark us as available for use |
120 | jobtype = JOB_NONE; |
121 | in_use = false; |
122 | |
123 | if( jobtype & JOB_QUIT ) break; |
124 | } |
125 | |
126 | in_use = false; |
127 | } |
128 | |
129 | //--------------------------------- |
130 | // Finish |
131 | //--------------------------------- |
132 | void DEVIOWorkerThread::Finish(bool wait_to_complete) |
133 | { |
134 | /// Set the done flag so that the worker thread |
135 | /// will exit once it is done processing its current |
136 | /// job. The thread is notified to wake up in case |
137 | /// it is currently idle. If the wait_to_complete |
138 | /// flag is set (default), then the worker thread is |
139 | /// joined to guarantee the current job's processing |
140 | /// is completed before returning. |
141 | done = true; |
142 | cv.notify_all(); |
143 | if(wait_to_complete) { |
144 | thd.join(); |
145 | } else { |
146 | thd.detach(); |
147 | } |
148 | } |
149 | |
150 | //--------------------------------- |
151 | // Prune |
152 | //--------------------------------- |
153 | void DEVIOWorkerThread::Prune(void) |
154 | { |
155 | /// Delete any DParsedEvent objects not currently in use. |
156 | /// If the DParsedEvent object pool and their internal |
157 | /// hit object pools are allowed to continuously grow, it |
158 | /// will appear as a though there is a memory leak. Occasional |
159 | /// pruning will reduce the average memory footprint. |
160 | /// This is called from MakeEvents() every MAX_EVENT_RECYCLES |
161 | /// EVIO events processed by this worker thread. |
162 | /// Note that this is in EVIO events (i.e. possibly a block |
163 | /// of events) not in L1 trigger events. |
164 | /// |
165 | /// NOTE: We currently do NOT reduce the size of buff |
166 | /// here if it is too big. We may wish to do that at some point! |
167 | |
168 | // Delete extra parsed events |
169 | vector<DParsedEvent*> tmp_events = parsed_event_pool; |
170 | parsed_event_pool.clear(); |
171 | for(auto pe : tmp_events) { |
172 | if(pe->in_use) |
173 | parsed_event_pool.push_back(pe); |
174 | else |
175 | delete pe; |
176 | |
177 | } |
178 | } |
179 | |
180 | //--------------------------------- |
181 | // MakeEvents |
182 | //--------------------------------- |
183 | void DEVIOWorkerThread::MakeEvents(void) |
184 | { |
185 | |
186 | /// Make DParsedEvent objects from data currently in buff. |
187 | /// This will look at the begining of the EVIO event to see |
188 | /// how many L1 events are in it. It will then grab that many |
189 | /// DParsedEvent objects from this threads pool , or create |
190 | /// new ones and add them all to the current_parsed_events |
191 | /// vector. These are then filled out later as the data is |
192 | /// parsed. |
193 | |
194 | if(!current_parsed_events.empty()) throw JException("Attempting call to DEVIOWorkerThread::MakeEvents when current_parsed_events not empty!!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__194); |
195 | |
196 | uint32_t *iptr = buff; |
197 | |
198 | uint32_t M = 1; |
199 | uint64_t event_num = 0; |
200 | |
201 | iptr++; |
202 | uint32_t mask = 0xFF001000; |
203 | if( ((*iptr)&mask) == mask ){ |
204 | // Physics event |
205 | M = *(iptr)&0xFF; |
206 | uint64_t eventnum_lo = iptr[4]; |
207 | uint64_t eventnum_hi = iptr[5]; |
208 | event_num = (eventnum_hi<<32) + (eventnum_lo); |
209 | } |
210 | |
211 | // Try and get M DParsedEvent objects from this thread's pool. |
212 | for(auto pe : parsed_event_pool){ |
213 | if(pe->in_use) continue; |
214 | current_parsed_events.push_back(pe); |
215 | if( current_parsed_events.size() >= M ) break; |
216 | } |
217 | |
218 | // Create new DParsedEvent objects if needed |
219 | while( current_parsed_events.size() < M ){ |
220 | DParsedEvent *pe = new DParsedEvent(MAX_OBJECT_RECYCLES); |
221 | current_parsed_events.push_back(pe); |
222 | parsed_event_pool.push_back(pe); |
223 | } |
224 | |
225 | // Set indexes for the parsed event objects |
226 | // and flag them as being in use. |
227 | for(auto pe : current_parsed_events){ |
228 | |
229 | pe->Clear(); // return previous event's objects to pools and clear vectors |
230 | pe->istreamorder = istreamorder; |
231 | pe->run_number = run_number_seed; |
232 | pe->event_number = event_num++; |
233 | pe->sync_flag = false; |
234 | pe->in_use = true; |
235 | pe->copied_to_factories = false; |
236 | pe->event_status_bits = 0; |
237 | pe->borptrs = NULL__null; // may be set by either ParseBORbank or JEventSource_EVIOpp::GetEvent |
238 | } |
239 | |
240 | // Parse data in buffer to create data objects |
241 | ParseBank(); |
242 | |
243 | // Occasionally prune extra DParsedEvent objects as well as objects |
244 | // from the existing pools to reduce average memory usage. We do |
245 | // this after parsing so that not everything is deleted (objects |
246 | // being used this event will be returned to the pools later.) |
247 | if(++Nrecycled%MAX_EVENT_RECYCLES == 0) Prune(); |
248 | for(auto pe : current_parsed_events){ |
249 | if( ++pe->Nrecycled%pe->MAX_RECYCLES == 0) pe->Prune(); |
250 | } |
251 | } |
252 | |
253 | //--------------------------------- |
254 | // PublishEvents |
255 | //--------------------------------- |
256 | void DEVIOWorkerThread::PublishEvents(void) |
257 | { |
258 | /// Copy our "current_parsed_events" pointers into the global "parsed_events" |
259 | /// list making them available for consumption. |
260 | |
261 | // Lock mutex so other threads can't modify parsed_events |
262 | unique_lock<mutex> lck(PARSED_EVENTS_MUTEX); |
263 | |
264 | // Make sure we don't exceed the maximum number of simultaneous |
265 | // parsed events. If the done flag is set, go ahead and add |
266 | // this regardless |
267 | while( ((current_parsed_events.size()+parsed_events.size())>=MAX_PARSED_EVENTS) && !done ){ |
268 | event_source->NPARSER_STALLED++; |
269 | PARSED_EVENTS_CV.wait_for(lck, std::chrono::milliseconds(1)); |
270 | } |
271 | |
272 | // Loop over all elements of parsed_events and insert |
273 | // these based on istreamorder so that the front element |
274 | // is the most recent. |
275 | bool inserted = false; |
276 | for(auto it = parsed_events.begin(); it!=parsed_events.end(); it++){ |
277 | if( istreamorder < (*it)->istreamorder ){ |
278 | parsed_events.insert(it, current_parsed_events.begin(), current_parsed_events.end()); |
279 | inserted = true; |
280 | break; |
281 | } |
282 | } |
283 | |
284 | // In case this should go at end of list |
285 | if(!inserted) parsed_events.insert(parsed_events.end(), current_parsed_events.begin(), current_parsed_events.end()); |
286 | |
287 | lck.unlock(); |
288 | PARSED_EVENTS_CV.notify_all(); |
289 | |
290 | // Any events should now be published |
291 | current_parsed_events.clear(); |
292 | } |
293 | |
294 | //--------------------------------- |
295 | // ParseBank |
296 | //--------------------------------- |
297 | void DEVIOWorkerThread::ParseBank(void) |
298 | { |
299 | |
300 | uint32_t *iptr = buff; |
301 | uint32_t *iend = &buff[buff[0]+1]; |
302 | |
303 | while(iptr < iend){ |
304 | uint32_t event_len = iptr[0]; |
305 | uint32_t event_head = iptr[1]; |
306 | uint32_t tag = (event_head >> 16) & 0xFFFF; |
307 | |
308 | //_DBG_ << "tag=" << hex << tag << dec << endl; |
309 | |
310 | switch(tag){ |
311 | case 0x0060: ParseEPICSbank(iptr, iend); break; |
312 | case 0x0070: ParseBORbank(iptr, iend); break; |
313 | |
314 | case 0xFFD0: |
315 | case 0xFFD1: |
316 | case 0xFFD2: |
317 | case 0xFFD3: ParseControlEvent(iptr, iend); break; |
318 | |
319 | case 0xFF58: |
320 | case 0xFF78: current_parsed_events.back()->sync_flag = true; |
321 | case 0xFF50: |
322 | case 0xFF70: ParsePhysicsBank(iptr, iend); break; |
323 | |
324 | default: |
325 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<325<<" " << "Unknown outer EVIO bank tag: " << hex << tag << dec << endl; |
326 | iptr = &iptr[event_len+1]; |
327 | if(event_len<1) iptr = iend; |
328 | } |
329 | } |
330 | } |
331 | |
332 | //--------------------------------- |
333 | // ParseEventTagBank |
334 | //--------------------------------- |
335 | void DEVIOWorkerThread::ParseEventTagBank(uint32_t* &iptr, uint32_t *iend) |
336 | { |
337 | iptr = &iptr[(*iptr) + 1]; |
338 | } |
339 | |
340 | //--------------------------------- |
341 | // ParseEPICSbank |
342 | //--------------------------------- |
343 | void DEVIOWorkerThread::ParseEPICSbank(uint32_t* &iptr, uint32_t *iend) |
344 | { |
345 | if(!PARSE_EPICS){ iptr = iend; return; } |
346 | |
347 | time_t timestamp=0; |
348 | |
349 | // Outer bank |
350 | uint32_t *istart = iptr; |
351 | uint32_t epics_bank_len = *iptr++; |
352 | if(epics_bank_len < 1){ |
353 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<353<<" " << "bank_len<1 in EPICS event!" << endl; |
354 | iptr = iend; |
355 | return; |
356 | } |
357 | |
358 | uint32_t *iend_epics = &iptr[epics_bank_len]; |
359 | if( iend_epics < iend ) iend = iend_epics; |
Value stored to 'iend' is never read | |
360 | |
361 | // Advance to first daughter bank |
362 | iptr++; |
363 | |
364 | // Get pointer to first DParsedEvent |
365 | DParsedEvent *pe = current_parsed_events.front(); |
366 | pe->event_status_bits |= (1<<kSTATUS_EPICS_EVENT); |
367 | |
368 | // Loop over daughter banks |
369 | while( iptr < iend_epics ){ |
370 | |
371 | uint32_t bank_len = (*iptr)&0xFFFF; |
372 | uint32_t tag = ((*iptr)>>24)&0xFF; |
373 | iptr++; |
374 | |
375 | if(tag == 0x61){ |
376 | // timestamp bank |
377 | timestamp = *iptr; |
378 | }else if(tag == 0x62){ |
379 | // EPICS data value |
380 | string nameval = (const char*)iptr; |
381 | pe->NEW_DEPICSvalue(timestamp, nameval); |
382 | }else{ |
383 | // Unknown tag. Bail |
384 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<384<<" " << "Unknown tag 0x" << hex << tag << dec << " in EPICS event!" <<endl; |
385 | DumpBinary(istart, iend_epics, 32, &iptr[-1]); |
386 | } |
387 | |
388 | iptr = &iptr[bank_len]; |
389 | } |
390 | |
391 | iptr = iend_epics; |
392 | } |
393 | |
394 | //--------------------------------- |
395 | // ParseBORbank |
396 | //--------------------------------- |
397 | void DEVIOWorkerThread::ParseBORbank(uint32_t* &iptr, uint32_t *iend) |
398 | { |
399 | /// Create BOR config objects from the EVIO bank and store them in |
400 | /// the event (should only be one since BOR events are not entangled). |
401 | /// These objects will eventually be inherited by the JEventSource_EVIOpp |
402 | /// object and passed to all subsequent events. |
403 | |
404 | // Upon entry, iptr should point to length word of a bank of banks with tag=0x70 |
405 | // indicating BOR event. Each bank contained within will represent one crate and |
406 | // will be a bank with tag=0x71 and num the rocid, containing tagsegments. Each tagsegment |
407 | // represents a single module with the tag containing the module type (bits 0-4) and |
408 | // slot (bits 5-10). The data in the tagsegments is uint32_t and maps to a data |
409 | // structure in bor_roc.h depending on the module type. Below is a summary of |
410 | // how this looks in memory: |
411 | // |
412 | // BOR event length |
413 | // BOR header |
414 | // crate bank length |
415 | // crate header |
416 | // module bank len/header |
417 | // module data ... |
418 | // module bank len/header |
419 | // module data ... |
420 | // ... |
421 | // crate bank length |
422 | // crate header |
423 | // ... |
424 | |
425 | if(!PARSE_BOR){ iptr = &iptr[(*iptr) + 1]; return; } |
426 | |
427 | // Make sure there is exactly 1 event in current_parsed_events |
428 | if(current_parsed_events.size() != 1){ |
429 | stringstream ss; |
430 | ss << "DEVIOWorkerThread::ParseBORbank called for EVIO event with " << current_parsed_events.size() << " events in it. (Should be exactly 1!)"; |
431 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__431); |
432 | } |
433 | |
434 | // Create new DBORptrs object and set pointer to it in DParsedEvent |
435 | // (see JEventSource_EVIOpp::GetEvent) |
436 | DParsedEvent *pe = current_parsed_events.front(); |
437 | pe->event_status_bits |= (1<<kSTATUS_BOR_EVENT); |
438 | pe->borptrs = new DBORptrs(); |
439 | DBORptrs* &borptrs = pe->borptrs; |
440 | |
441 | // Make sure we have full event |
442 | uint32_t borevent_len = *iptr++; |
443 | uint32_t bank_len = (uint32_t)((uint64_t)iend - (uint64_t)iptr)/sizeof(uint32_t); |
444 | if(borevent_len > bank_len){ |
445 | stringstream ss; |
446 | ss << "BOR: Size of bank doesn't match amount of data given (" << borevent_len << " > " << bank_len << ")"; |
447 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__447); |
448 | } |
449 | iend = &iptr[borevent_len]; // in case they give us too much data! |
450 | |
451 | // Make sure BOR header word is right |
452 | uint32_t bor_header = *iptr++; |
453 | if(bor_header != 0x700e01){ |
454 | stringstream ss; |
455 | ss << "Bad BOR header: 0x" << hex << bor_header; |
456 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__456); |
457 | } |
458 | |
459 | // Loop over crates |
460 | while(iptr<iend){ |
461 | uint32_t crate_len = *iptr++; |
462 | uint32_t *iend_crate = &iptr[crate_len]; // points to first word after this crate |
463 | uint32_t crate_header = *iptr++; |
464 | // uint32_t rocid = crate_header&0xFF; |
465 | |
466 | // Make sure crate tag is right |
467 | if( (crate_header>>16) != 0x71 ){ |
468 | stringstream ss; |
469 | ss << "Bad BOR crate header: 0x" << hex << (crate_header>>16); |
470 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__470); |
471 | } |
472 | |
473 | // Loop over modules |
474 | while(iptr<iend_crate){ |
475 | uint32_t module_header = *iptr++; |
476 | uint32_t module_len = module_header&0xFFFF; |
477 | uint32_t modType = (module_header>>20)&0x1f; |
478 | // uint32_t slot = (module_header>>25); |
479 | // uint32_t *iend_module = &iptr[module_len]; // points to first word after this module |
480 | |
481 | uint32_t *src = iptr; |
482 | uint32_t *dest = NULL__null; |
483 | uint32_t sizeof_dest = 0; |
484 | |
485 | Df250BORConfig *f250conf = NULL__null; |
486 | Df125BORConfig *f125conf = NULL__null; |
487 | DF1TDCBORConfig *F1TDCconf = NULL__null; |
488 | DCAEN1290TDCBORConfig *caen1190conf = NULL__null; |
489 | |
490 | switch(modType){ |
491 | case DModuleType::FADC250: // f250 |
492 | f250conf = new Df250BORConfig; |
493 | dest = (uint32_t*)&f250conf->rocid; |
494 | sizeof_dest = sizeof(f250config); |
495 | break; |
496 | case DModuleType::FADC125: // f125 |
497 | f125conf = new Df125BORConfig; |
498 | dest = (uint32_t*)&f125conf->rocid; |
499 | sizeof_dest = sizeof(f125config); |
500 | break; |
501 | |
502 | case DModuleType::F1TDC32: // F1TDCv2 |
503 | case DModuleType::F1TDC48: // F1TDCv3 |
504 | F1TDCconf = new DF1TDCBORConfig; |
505 | dest = (uint32_t*)&F1TDCconf->rocid; |
506 | sizeof_dest = sizeof(F1TDCconfig); |
507 | break; |
508 | |
509 | case DModuleType::CAEN1190: // CAEN 1190 TDC |
510 | case DModuleType::CAEN1290: // CAEN 1290 TDC |
511 | caen1190conf = new DCAEN1290TDCBORConfig; |
512 | dest = (uint32_t*)&caen1190conf->rocid; |
513 | sizeof_dest = sizeof(caen1190config); |
514 | break; |
515 | |
516 | default: |
517 | { |
518 | stringstream ss; |
519 | ss << "Unknown BOR module type: " << modType << " (module_header=0x"<<hex<<module_header<<")"; |
520 | jerr << ss.str() << endl; |
521 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__521); |
522 | } |
523 | } |
524 | |
525 | // Check that the bank size and data structure size match. |
526 | if( module_len != (sizeof_dest/sizeof(uint32_t)) ){ |
527 | stringstream ss; |
528 | ss << "BOR module bank size does not match structure! " << module_len << " != " << (sizeof_dest/sizeof(uint32_t)) << " for modType " << modType; |
529 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__529); |
530 | } |
531 | |
532 | // Copy bank data, assuming format is the same |
533 | for(uint32_t i=0; i<module_len; i++) *dest++ = *src++; |
534 | |
535 | // Store object for use in this and subsequent events |
536 | if(f250conf ) borptrs->vDf250BORConfig.push_back(f250conf); |
537 | if(f125conf ) borptrs->vDf125BORConfig.push_back(f125conf); |
538 | if(F1TDCconf ) borptrs->vDF1TDCBORConfig.push_back(F1TDCconf); |
539 | if(caen1190conf) borptrs->vDCAEN1290TDCBORConfig.push_back(caen1190conf); |
540 | |
541 | iptr = &iptr[module_len]; |
542 | } |
543 | |
544 | iptr = iend_crate; // ensure we're pointing past this crate |
545 | } |
546 | |
547 | // Sort the BOR config events now so we don't have to do it for every event |
548 | borptrs->Sort(); |
549 | |
550 | } |
551 | |
552 | //--------------------------------- |
553 | // ParseTSscalerBank |
554 | //--------------------------------- |
555 | void DEVIOWorkerThread::ParseTSscalerBank(uint32_t* &iptr, uint32_t *iend) |
556 | { |
557 | uint32_t Nwords = ((uint64_t)iend - (uint64_t)iptr)/sizeof(uint32_t); |
558 | uint32_t Nwords_expected = (6+32+16+32+16); |
559 | if(Nwords != Nwords_expected){ |
560 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<560<<" " << "TS bank size does not match expected!!" << endl; |
561 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<561<<" " << "Found " << Nwords << " words. Expected " << Nwords_expected << endl; |
562 | |
563 | }else{ |
564 | // n.b. Get the last event here since if this is a block |
565 | // of events, the last should be the actual sync event. |
566 | DParsedEvent *pe = current_parsed_events.back(); |
567 | DL1Info *s = pe->NEW_DL1Info(); |
568 | s->nsync = *iptr++; |
569 | s->trig_number = *iptr++; |
570 | s->live_time = *iptr++; |
571 | s->busy_time = *iptr++; |
572 | s->live_inst = *iptr++; |
573 | s->unix_time = *iptr++; |
574 | for(uint32_t i=0; i<32; i++) s->gtp_sc.push_back ( *iptr++ ); |
575 | for(uint32_t i=0; i<16; i++) s->fp_sc.push_back ( *iptr++ ); |
576 | for(uint32_t i=0; i<32; i++) s->gtp_rate.push_back( *iptr++ ); |
577 | for(uint32_t i=0; i<16; i++) s->fp_rate.push_back ( *iptr++ ); |
578 | } |
579 | |
580 | iptr = iend; |
581 | } |
582 | |
583 | //--------------------------------- |
584 | // Parsef250scalerBank |
585 | //--------------------------------- |
586 | void DEVIOWorkerThread::Parsef250scalerBank(uint32_t* &iptr, uint32_t *iend) |
587 | { |
588 | iptr = &iptr[(*iptr) + 1]; |
589 | } |
590 | |
591 | //--------------------------------- |
592 | // ParseControlEvent |
593 | //--------------------------------- |
594 | void DEVIOWorkerThread::ParseControlEvent(uint32_t* &iptr, uint32_t *iend) |
595 | { |
596 | for(auto pe : current_parsed_events) pe->event_status_bits |= (1<<kSTATUS_CONTROL_EVENT); |
597 | |
598 | iptr = &iptr[(*iptr) + 1]; |
599 | } |
600 | |
601 | //--------------------------------- |
602 | // ParsePhysicsBank |
603 | //--------------------------------- |
604 | void DEVIOWorkerThread::ParsePhysicsBank(uint32_t* &iptr, uint32_t *iend) |
605 | { |
606 | |
607 | for(auto pe : current_parsed_events) pe->event_status_bits |= (1<<kSTATUS_PHYSICS_EVENT); |
608 | |
609 | uint32_t physics_event_len = *iptr++; |
610 | uint32_t *iend_physics_event = &iptr[physics_event_len]; |
611 | iptr++; |
612 | |
613 | // Built Trigger Bank |
614 | uint32_t built_trigger_bank_len = *iptr; |
615 | uint32_t *iend_built_trigger_bank = &iptr[built_trigger_bank_len+1]; |
616 | ParseBuiltTriggerBank(iptr, iend_built_trigger_bank); |
617 | iptr = iend_built_trigger_bank; |
618 | |
619 | // Loop over Data banks |
620 | while( iptr < iend_physics_event ) { |
621 | |
622 | uint32_t data_bank_len = *iptr; |
623 | uint32_t *iend_data_bank = &iptr[data_bank_len+1]; |
624 | |
625 | ParseDataBank(iptr, iend_data_bank); |
626 | |
627 | iptr = iend_data_bank; |
628 | } |
629 | |
630 | iptr = iend_physics_event; |
631 | } |
632 | |
633 | //--------------------------------- |
634 | // ParseBuiltTriggerBank |
635 | //--------------------------------- |
636 | void DEVIOWorkerThread::ParseBuiltTriggerBank(uint32_t* &iptr, uint32_t *iend) |
637 | { |
638 | if(!PARSE_TRIGGER) return; |
639 | |
640 | iptr++; // advance past length word |
641 | uint32_t mask = 0xFF202000; |
642 | if( ((*iptr) & mask) != mask ){ |
643 | stringstream ss; |
644 | ss << "Bad header word in Built Trigger Bank: " << hex << *iptr; |
645 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__645); |
646 | } |
647 | |
648 | uint32_t tag = (*iptr)>>16; // 0xFF2X |
649 | uint32_t Nrocs = (*iptr++) & 0xFF; |
650 | uint32_t Mevents = current_parsed_events.size(); |
651 | |
652 | //-------- Common data (64bit) |
653 | uint32_t common_header64 = *iptr++; |
654 | uint32_t common_header64_len = common_header64 & 0xFFFF; |
655 | uint64_t *iptr64 = (uint64_t*)iptr; |
656 | iptr = &iptr[common_header64_len]; |
657 | |
658 | // First event number |
659 | uint64_t first_event_num = *iptr64++; |
660 | |
661 | // Hi and lo 32bit words in 64bit numbers seem to be |
662 | // switched for events read from ET, but not read from |
663 | // file. Not sure if this is in the swapping routine |
664 | // if(source_type==kETSource) first_event_num = (first_event_num>>32) | (first_event_num<<32); |
665 | |
666 | // Average timestamps |
667 | uint32_t Ntimestamps = (common_header64_len/2)-1; |
668 | if(tag & 0x2) Ntimestamps--; // subtract 1 for run number/type word if present |
669 | vector<uint64_t> avg_timestamps; |
670 | for(uint32_t i=0; i<Ntimestamps; i++) avg_timestamps.push_back(*iptr64++); |
671 | |
672 | // run number and run type |
673 | uint32_t run_number = 0; |
674 | uint32_t run_type = 0; |
675 | if(tag & 0x02){ |
676 | run_number = (*iptr64) >> 32; |
677 | run_type = (*iptr64) & 0xFFFFFFFF; |
678 | iptr64++; |
679 | } |
680 | |
681 | //-------- Common data (16bit) |
682 | uint32_t common_header16 = *iptr++; |
683 | uint32_t common_header16_len = common_header16 & 0xFFFF; |
684 | uint16_t *iptr16 = (uint16_t*)iptr; |
685 | iptr = &iptr[common_header16_len]; |
686 | |
687 | vector<uint16_t> event_types; |
688 | for(uint32_t i=0; i<Mevents; i++) event_types.push_back(*iptr16++); |
689 | |
690 | //-------- ROC data (32bit) |
691 | for(uint32_t iroc=0; iroc<Nrocs; iroc++){ |
692 | uint32_t common_header32 = *iptr++; |
693 | uint32_t common_header32_len = common_header32 & 0xFFFF; |
694 | uint32_t rocid = common_header32 >> 24; |
695 | |
696 | uint32_t Nwords_per_event = common_header32_len/Mevents; |
697 | for(auto pe : current_parsed_events){ |
698 | |
699 | DCODAROCInfo *codarocinfo = pe->NEW_DCODAROCInfo(); |
700 | codarocinfo->rocid = rocid; |
701 | |
702 | uint64_t ts_low = *iptr++; |
703 | uint64_t ts_high = *iptr++; |
704 | codarocinfo->timestamp = (ts_high<<32) + ts_low; |
705 | codarocinfo->misc.clear(); // could be recycled from previous event |
706 | for(uint32_t i=2; i<Nwords_per_event; i++) codarocinfo->misc.push_back(*iptr++); |
707 | |
708 | if(iptr > iend){ |
709 | throw JException("Bad data format in ParseBuiltTriggerBank!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__709); |
710 | } |
711 | } |
712 | } |
713 | |
714 | //-------- Make DCODAEventInfo objects |
715 | uint64_t ievent = 0; |
716 | for(auto pe : current_parsed_events){ |
717 | |
718 | pe->run_number = run_number; // may be overwritten in JEventSource_EVIOpp::GetEvent() |
719 | |
720 | DCODAEventInfo *codaeventinfo = pe->NEW_DCODAEventInfo(); |
721 | codaeventinfo->run_number = run_number; |
722 | codaeventinfo->run_type = run_type; |
723 | codaeventinfo->event_number = first_event_num + ievent; |
724 | codaeventinfo->event_type = event_types.empty() ? 0:event_types[ievent]; |
725 | codaeventinfo->avg_timestamp = avg_timestamps.empty() ? 0:avg_timestamps[ievent]; |
726 | ievent++; |
727 | } |
728 | } |
729 | |
730 | //--------------------------------- |
731 | // ParseDataBank |
732 | //--------------------------------- |
733 | void DEVIOWorkerThread::ParseDataBank(uint32_t* &iptr, uint32_t *iend) |
734 | { |
735 | // Physics Event's Data Bank header |
736 | iptr++; // advance past data bank length word |
737 | uint32_t rocid = ((*iptr)>>16) & 0xFFF; |
738 | iptr++; |
739 | |
740 | // Loop over Data Block Banks |
741 | while(iptr < iend){ |
742 | |
743 | uint32_t data_block_bank_len = *iptr++; |
744 | uint32_t *iend_data_block_bank = &iptr[data_block_bank_len]; |
745 | uint32_t data_block_bank_header = *iptr++; |
746 | |
747 | // Not sure where this comes from, but it needs to be skipped if present |
748 | while( (*iptr==0xF800FAFA) && (iptr<iend) ) iptr++; |
749 | |
750 | uint32_t det_id = (data_block_bank_header>>16) & 0xFFF; |
751 | switch(det_id){ |
752 | |
753 | case 20: |
754 | ParseCAEN1190(rocid, iptr, iend_data_block_bank); |
755 | break; |
756 | |
757 | case 0x55: |
758 | ParseModuleConfiguration(rocid, iptr, iend_data_block_bank); |
759 | break; |
760 | |
761 | case 0x56: |
762 | ParseEventTagBank(iptr, iend_data_block_bank); |
763 | break; |
764 | |
765 | case 0: |
766 | case 1: |
767 | case 3: |
768 | case 6: // flash 250 module, MMD 2014/2/4 |
769 | case 16: // flash 125 module (CDC), DL 2014/6/19 |
770 | case 26: // F1 TDC module (BCAL), MMD 2014-07-31 |
771 | ParseJLabModuleData(rocid, iptr, iend_data_block_bank); |
772 | break; |
773 | |
774 | // These were implemented in the ROL for sync events |
775 | // as 0xEE02 and 0xEE05. However, that violates the |
776 | // spec. which reserves the top 4 bits as status bits |
777 | // (the first "E" should really be a "1". We just check |
778 | // other 12 bits here. |
779 | case 0xE02: |
780 | ParseTSscalerBank(iptr, iend); |
781 | break; |
782 | case 0xE05: |
783 | Parsef250scalerBank(iptr, iend); |
784 | break; |
785 | case 0xE10: // really wish Sascha would share when he does this stuff! |
786 | Parsef250scalerBank(iptr, iend); |
787 | break; |
788 | |
789 | // When we write out single events in the offline, we also can save some |
790 | // higher level data objects to save disk space and speed up |
791 | // specialized processing (e.g. pi0 calibration) |
792 | case 0xD01: |
793 | ParseDVertexBank(iptr, iend); |
794 | break; |
795 | |
796 | case 5: |
797 | // old ROL Beni used had this but I don't think its |
798 | // been used for years. Run 10390 seems to have |
799 | // this though (???) |
800 | break; |
801 | |
802 | |
803 | default: |
804 | jerr<<"Unknown module type ("<<det_id<<" = " << hex << det_id << dec << " ) encountered" << endl; |
805 | // if(VERBOSE>5){ |
806 | cout << "----- First few words to help with debugging -----" << endl; |
807 | cout.flush(); cerr.flush(); |
808 | DumpBinary(&iptr[-2], iend, 32, &iptr[-1]); |
809 | // } |
810 | } |
811 | |
812 | iptr = iend_data_block_bank; |
813 | } |
814 | |
815 | } |
816 | |
817 | //---------------- |
818 | // ParseTIBank |
819 | //---------------- |
820 | void DEVIOWorkerThread::ParseTIBank(uint32_t rocid, uint32_t* &iptr, uint32_t* iend) |
821 | { |
822 | while(iptr<iend && ((*iptr) & 0xF8000000) != 0x88000000) iptr++; // Skip to JLab block trailer |
823 | iptr++; // advance past JLab block trailer |
824 | while(iptr<iend && *iptr == 0xF8000000) iptr++; // skip filler words after block trailer |
825 | //iptr = iend; |
826 | } |
827 | |
828 | //---------------- |
829 | // ParseCAEN1190 |
830 | //---------------- |
831 | void DEVIOWorkerThread::ParseCAEN1190(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
832 | { |
833 | if(!PARSE_CAEN1290TDC){ iptr = &iptr[(*iptr) + 1]; return; } |
834 | |
835 | /// Parse data from a CAEN 1190 or 1290 module |
836 | /// (See ppg. 72-74 of V1290_REV15.pdf manual) |
837 | |
838 | uint32_t slot = 0; |
839 | uint32_t event_count = 0; |
840 | uint32_t word_count = 0; |
841 | uint32_t trigger_time_tag = 0; |
842 | uint32_t tdc_num = 0; |
843 | uint32_t event_id = 0; |
844 | uint32_t bunch_id = 0; |
845 | |
846 | // We need to accomodate multi-event blocks where |
847 | // events are entangled (i.e. hits from event 1 |
848 | // are mixed in between those of event 2,3,4, |
849 | // etc... With CAEN modules, we only know which |
850 | // event a hit came from by looking at the event_id |
851 | // in the TDC header. This value is only 12 bits |
852 | // and could roll over within an event block. This |
853 | // means we need to keep track of the order we |
854 | // encounter them in so it is maintained in the |
855 | // "events" container. The event_id order is kept |
856 | // in the "event_id_order" vector. |
857 | map<uint32_t, DParsedEvent*> events_by_event_id; |
858 | |
859 | auto pe_iter = current_parsed_events.begin(); |
860 | DParsedEvent *pe = NULL__null; |
861 | |
862 | while(iptr<iend){ |
863 | |
864 | // This word appears to be appended to the data. |
865 | // Probably in the ROL. Ignore it if found. |
866 | if(*iptr == 0xd00dd00d) { |
867 | if(VERBOSE>7) cout << " CAEN skipping 0xd00dd00d word" << endl; |
868 | iptr++; |
869 | continue; |
870 | } |
871 | |
872 | uint32_t type = (*iptr) >> 27; |
873 | uint32_t edge = 0; // 1=trailing, 0=leading |
874 | uint32_t channel = 0; |
875 | uint32_t tdc = 0; |
876 | uint32_t error_flags = 0; |
877 | switch(type){ |
878 | case 0b01000: // Global Header |
879 | slot = (*iptr) & 0x1f; |
880 | event_count = ((*iptr)>>5) & 0xffffff; |
881 | if(VERBOSE>7) cout << " CAEN TDC Global Header (slot=" << slot << " , event count=" << event_count << ")" << endl; |
882 | break; |
883 | case 0b10000: // Global Trailer |
884 | slot = (*iptr) & 0x1f; |
885 | word_count = ((*iptr)>>5) & 0x7ffff; |
886 | if(VERBOSE>7) cout << " CAEN TDC Global Trailer (slot=" << slot << " , word count=" << word_count << ")" << endl; |
887 | slot = event_count = word_count = trigger_time_tag = tdc_num = event_id = bunch_id = 0; |
888 | break; |
889 | case 0b10001: // Global Trigger Time Tag |
890 | trigger_time_tag = ((*iptr)>>5) & 0x7ffffff; |
891 | if(VERBOSE>7) cout << " CAEN TDC Global Trigger Time Tag (tag=" << trigger_time_tag << ")" << endl; |
892 | break; |
893 | case 0b00001: // TDC Header |
894 | tdc_num = ((*iptr)>>24) & 0x03; |
895 | event_id = ((*iptr)>>12) & 0x0fff; |
896 | bunch_id = (*iptr) & 0x0fff; |
897 | if(events_by_event_id.find(event_id) == events_by_event_id.end()){ |
898 | if(pe_iter == current_parsed_events.end()){ |
899 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<899<<" " << "CAEN1290TDC parser sees more events than CODA header! (>" << current_parsed_events.size() << ")" << endl; |
900 | for( auto p : events_by_event_id) cout << "id=" << p.first << endl; |
901 | iptr = iend; |
902 | exit(-1); // should we exit, or try and continue?? |
903 | return; |
904 | } |
905 | pe = *pe_iter++; |
906 | events_by_event_id[event_id] = pe; |
907 | }else{ |
908 | pe = events_by_event_id[event_id]; |
909 | } |
910 | if(VERBOSE>7) cout << " CAEN TDC TDC Header (tdc=" << tdc_num <<" , event id=" << event_id <<" , bunch id=" << bunch_id << ")" << endl; |
911 | break; |
912 | case 0b00000: // TDC Measurement |
913 | edge = ((*iptr)>>26) & 0x01; |
914 | channel = ((*iptr)>>21) & 0x1f; |
915 | tdc = ((*iptr)>>0) & 0x1fffff; |
916 | if(VERBOSE>7) cout << " CAEN TDC TDC Measurement (" << (edge ? "trailing":"leading") << " , channel=" << channel << " , tdc=" << tdc << ")" << endl; |
917 | |
918 | // Create DCAEN1290TDCHit object |
919 | pe->NEW_DCAEN1290TDCHit(rocid, slot, channel, 0, edge, tdc_num, event_id, bunch_id, tdc); |
920 | break; |
921 | case 0b00100: // TDC Error |
922 | error_flags = (*iptr) & 0x7fff; |
923 | if(VERBOSE>7) cout << " CAEN TDC TDC Error (err flags=0x" << hex << error_flags << dec << ")" << endl; |
924 | break; |
925 | case 0b00011: // TDC Trailer |
926 | tdc_num = ((*iptr)>>24) & 0x03; |
927 | event_id = ((*iptr)>>12) & 0x0fff; |
928 | word_count = ((*iptr)>>0) & 0x0fff; |
929 | if(VERBOSE>7) cout << " CAEN TDC TDC Trailer (tdc=" << tdc_num <<" , event id=" << event_id <<" , word count=" << word_count << ")" << endl; |
930 | tdc_num = event_id = bunch_id = 0; |
931 | break; |
932 | case 0b11000: // Filler Word |
933 | if(VERBOSE>7) cout << " CAEN TDC Filler Word" << endl; |
934 | break; |
935 | default: |
936 | cout << "Unknown datatype: 0x" << hex << type << " full word: "<< *iptr << dec << endl; |
937 | } |
938 | |
939 | iptr++; |
940 | } |
941 | |
942 | } |
943 | |
944 | //---------------- |
945 | // ParseModuleConfiguration |
946 | //---------------- |
947 | void DEVIOWorkerThread::ParseModuleConfiguration(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
948 | { |
949 | if(!PARSE_CONFIG){ iptr = &iptr[(*iptr) + 1]; return; } |
950 | |
951 | /// Parse a bank of module configuration data. These are configuration values |
952 | /// programmed into the module at the beginning of the run that may be needed |
953 | /// in the offline. For example, the number of samples to sum in a FADC pulse |
954 | /// integral. |
955 | /// |
956 | /// The bank has one or more sections, each describing parameters applicable |
957 | /// to a number of modules as indicated by a 24bit slot mask. |
958 | /// |
959 | /// This bank should appear only once per DAQ event which, if in multi-event |
960 | /// block mode, may have multiple L1 events. The parameters here will apply |
961 | /// to all L1 events in the block. This method will put the config objects |
962 | /// into each event in current_parsed_events. The config objects are duplicated |
963 | /// as needed so each event has its own, indepenent set of config object. |
964 | |
965 | while(iptr < iend){ |
966 | uint32_t slot_mask = (*iptr) & 0xFFFFFF; |
967 | uint32_t Nvals = ((*iptr) >> 24) & 0xFF; |
968 | iptr++; |
969 | |
970 | // Events will be created in the first event (i.e. using its pool) |
971 | // but pointers are saved so we can use them to construct identical |
972 | // objects in all other event later |
973 | DParsedEvent *pe = current_parsed_events.front(); |
974 | |
975 | Df250Config *f250config = NULL__null; |
976 | Df125Config *f125config = NULL__null; |
977 | DF1TDCConfig *f1tdcconfig = NULL__null; |
978 | DCAEN1290TDCConfig *caen1290tdcconfig = NULL__null; |
979 | |
980 | // Loop over all parameters in this section |
981 | for(uint32_t i=0; i< Nvals; i++){ |
982 | if( iptr >= iend){ |
983 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<983<<" " << "DAQ Configuration bank corrupt! slot_mask=0x" << hex << slot_mask << dec << " Nvals="<< Nvals << endl; |
984 | exit(-1); |
985 | } |
986 | |
987 | daq_param_type ptype = (daq_param_type)((*iptr)>>16); |
988 | uint16_t val = (*iptr) & 0xFFFF; |
989 | |
990 | if(VERBOSE>6) cout << " DAQ parameter of type: 0x" << hex << ptype << dec << " found with value: " << val << endl; |
991 | |
992 | // Create config object of correct type if needed and copy |
993 | // parameter value into it. |
994 | switch(ptype>>8){ |
995 | |
996 | // f250 |
997 | case 0x05: |
998 | if( !f250config ) f250config = pe->NEW_Df250Config(rocid, slot_mask); |
999 | switch(ptype){ |
1000 | case kPARAM250_NSA : f250config->NSA = val; break; |
1001 | case kPARAM250_NSB : f250config->NSB = val; break; |
1002 | case kPARAM250_NSA_NSB : f250config->NSA_NSB = val; break; |
1003 | case kPARAM250_NPED : f250config->NPED = val; break; |
1004 | default: _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1004<<" " << "UNKNOWN DAQ Config Parameter type: 0x" << hex << ptype << dec << endl; |
1005 | } |
1006 | break; |
1007 | |
1008 | // f125 |
1009 | case 0x0F: |
1010 | if( !f125config ) f125config = pe->NEW_Df125Config(rocid, slot_mask); |
1011 | switch(ptype){ |
1012 | case kPARAM125_NSA : f125config->NSA = val; break; |
1013 | case kPARAM125_NSB : f125config->NSB = val; break; |
1014 | case kPARAM125_NSA_NSB : f125config->NSA_NSB = val; break; |
1015 | case kPARAM125_NPED : f125config->NPED = val; break; |
1016 | case kPARAM125_WINWIDTH : f125config->WINWIDTH = val; break; |
1017 | case kPARAM125_PL : f125config->PL = val; break; |
1018 | case kPARAM125_NW : f125config->NW = val; break; |
1019 | case kPARAM125_NPK : f125config->NPK = val; break; |
1020 | case kPARAM125_P1 : f125config->P1 = val; break; |
1021 | case kPARAM125_P2 : f125config->P2 = val; break; |
1022 | case kPARAM125_PG : f125config->PG = val; break; |
1023 | case kPARAM125_IE : f125config->IE = val; break; |
1024 | case kPARAM125_H : f125config->H = val; break; |
1025 | case kPARAM125_TH : f125config->TH = val; break; |
1026 | case kPARAM125_TL : f125config->TL = val; break; |
1027 | case kPARAM125_IBIT : f125config->IBIT = val; break; |
1028 | case kPARAM125_ABIT : f125config->ABIT = val; break; |
1029 | case kPARAM125_PBIT : f125config->PBIT = val; break; |
1030 | default: _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1030<<" " << "UNKNOWN DAQ Config Parameter type: 0x" << hex << ptype << dec << endl; |
1031 | } |
1032 | break; |
1033 | |
1034 | // F1TDC |
1035 | case 0x06: |
1036 | if( !f1tdcconfig ) f1tdcconfig = pe->NEW_DF1TDCConfig(rocid, slot_mask); |
1037 | switch(ptype){ |
1038 | case kPARAMF1_REFCNT : f1tdcconfig->REFCNT = val; break; |
1039 | case kPARAMF1_TRIGWIN : f1tdcconfig->TRIGWIN = val; break; |
1040 | case kPARAMF1_TRIGLAT : f1tdcconfig->TRIGLAT = val; break; |
1041 | case kPARAMF1_HSDIV : f1tdcconfig->HSDIV = val; break; |
1042 | case kPARAMF1_BINSIZE : f1tdcconfig->BINSIZE = val; break; |
1043 | case kPARAMF1_REFCLKDIV : f1tdcconfig->REFCLKDIV = val; break; |
1044 | default: _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1044<<" " << "UNKNOWN DAQ Config Parameter type: 0x" << hex << ptype << dec << endl; |
1045 | } |
1046 | break; |
1047 | |
1048 | // caen1290 |
1049 | case 0x10: |
1050 | if( !caen1290tdcconfig ) caen1290tdcconfig = pe->NEW_DCAEN1290TDCConfig(rocid, slot_mask); |
1051 | switch(ptype){ |
1052 | case kPARAMCAEN1290_WINWIDTH : caen1290tdcconfig->WINWIDTH = val; break; |
1053 | case kPARAMCAEN1290_WINOFFSET : caen1290tdcconfig->WINOFFSET = val; break; |
1054 | default: _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1054<<" " << "UNKNOWN DAQ Config Parameter type: 0x" << hex << ptype << dec << endl; |
1055 | } |
1056 | break; |
1057 | |
1058 | default: |
1059 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1059<<" " << "Unknown module type: 0x" << hex << (ptype>>8) << endl; |
1060 | exit(-1); |
1061 | } |
1062 | |
1063 | |
1064 | iptr++; |
1065 | } |
1066 | |
1067 | // Make copies of all config objects for all other events |
1068 | for(auto tpe : current_parsed_events){ |
1069 | |
1070 | if(tpe == pe) continue; // first event already owns objects so skip it |
1071 | |
1072 | if(f250config ) tpe->NEW_Df250Config(f250config); |
1073 | if(f125config ) tpe->NEW_Df125Config(f125config); |
1074 | if(f1tdcconfig ) tpe->NEW_DF1TDCConfig(f1tdcconfig); |
1075 | if(caen1290tdcconfig) tpe->NEW_DCAEN1290TDCConfig(caen1290tdcconfig); |
1076 | } |
1077 | } |
1078 | } |
1079 | |
1080 | //---------------- |
1081 | // ParseJLabModuleData |
1082 | //---------------- |
1083 | void DEVIOWorkerThread::ParseJLabModuleData(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1084 | { |
1085 | |
1086 | while(iptr<iend){ |
1087 | |
1088 | // Get module type from next word (bits 18-21) |
1089 | uint32_t mod_id = ((*iptr) >> 18) & 0x000F; |
1090 | MODULE_TYPE type = (MODULE_TYPE)mod_id; |
1091 | //cout << " rocid=" << rocid << " Encountered module type: " << type << " (=" << DModuleType::GetModule(type).GetName() << ") word=" << hex << (*iptr) << dec << endl; |
1092 | |
1093 | switch(type){ |
1094 | case DModuleType::FADC250: |
1095 | Parsef250Bank(rocid, iptr, iend); |
1096 | break; |
1097 | |
1098 | case DModuleType::FADC125: |
1099 | Parsef125Bank(rocid, iptr, iend); |
1100 | break; |
1101 | |
1102 | case DModuleType::F1TDC32: |
1103 | ParseF1TDCBank(rocid, iptr, iend); |
1104 | break; |
1105 | |
1106 | case DModuleType::F1TDC48: |
1107 | ParseF1TDCBank(rocid, iptr, iend); |
1108 | break; |
1109 | |
1110 | case DModuleType::TID: |
1111 | ParseTIBank(rocid, iptr, iend); |
1112 | /* |
1113 | // Ignore this data and skip over it |
1114 | while(iptr<iend && ((*iptr) & 0xF8000000) != 0x88000000) iptr++; // Skip to JLab block trailer |
1115 | iptr++; // advance past JLab block trailer |
1116 | while(iptr<iend && *iptr == 0xF8000000) iptr++; // skip filler words after block trailer |
1117 | break; |
1118 | */ |
1119 | break; |
1120 | |
1121 | case DModuleType::UNKNOWN: |
1122 | default: |
1123 | jerr<<"Unknown module type ("<<mod_id<<") iptr=0x" << hex << iptr << dec << endl; |
1124 | |
1125 | while(iptr<iend && ((*iptr) & 0xF8000000) != 0x88000000) iptr++; // Skip to JLab block trailer |
1126 | iptr++; // advance past JLab block trailer |
1127 | while(iptr<iend && *iptr == 0xF8000000) iptr++; // skip filler words after block trailer |
1128 | break; |
1129 | } |
1130 | } |
1131 | |
1132 | } |
1133 | |
1134 | //---------------- |
1135 | // Parsef250Bank |
1136 | //---------------- |
1137 | void DEVIOWorkerThread::Parsef250Bank(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1138 | { |
1139 | if(!PARSE_F250){ iptr = &iptr[(*iptr) + 1]; return; } |
1140 | |
1141 | auto pe_iter = current_parsed_events.begin(); |
1142 | DParsedEvent *pe = NULL__null; |
1143 | |
1144 | uint32_t slot = 0; |
1145 | uint32_t itrigger = -1; |
1146 | |
1147 | // Loop over data words |
1148 | for(; iptr<iend; iptr++){ |
1149 | |
1150 | // Skip all non-data-type-defining words at this |
1151 | // level. When we do encounter one, the appropriate |
1152 | // case block below should handle parsing all of |
1153 | // the data continuation words and advance the iptr. |
1154 | if(((*iptr>>31) & 0x1) == 0)continue; |
1155 | |
1156 | uint32_t data_type = (*iptr>>27) & 0x0F; |
1157 | switch(data_type){ |
1158 | case 0: // Block Header |
1159 | slot = (*iptr>>22) & 0x1F; |
1160 | if(VERBOSE>7) cout << " FADC250 Block Header: slot="<<slot<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1161 | break; |
1162 | case 1: // Block Trailer |
1163 | pe_iter = current_parsed_events.begin(); |
1164 | pe = NULL__null; |
1165 | if(VERBOSE>7) cout << " FADC250 Block Trailer"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1166 | break; |
1167 | case 2: // Event Header |
1168 | itrigger = (*iptr>>0) & 0x3FFFFF; |
1169 | pe = *pe_iter++; |
1170 | if(VERBOSE>7) cout << " FADC250 Event Header: itrigger="<<itrigger<<", rocid="<<rocid<<", slot="<<slot<<")" <<" ("<<hex<<*iptr<<dec<<")" <<endl; |
1171 | break; |
1172 | case 3: // Trigger Time |
1173 | { |
1174 | uint64_t t = ((*iptr)&0xFFFFFF)<<0; |
1175 | iptr++; |
1176 | if(((*iptr>>31) & 0x1) == 0){ |
1177 | t += ((*iptr)&0xFFFFFF)<<24; // from word on the street: second trigger time word is optional!!?? |
1178 | if(VERBOSE>7) cout << " Trigger time high word="<<(((*iptr)&0xFFFFFF))<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1179 | }else{ |
1180 | iptr--; |
1181 | } |
1182 | if(VERBOSE>7) cout << " FADC250 Trigger Time: t="<<t<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1183 | if(pe) pe->NEW_Df250TriggerTime(rocid, slot, itrigger, t); |
1184 | } |
1185 | break; |
1186 | case 4: // Window Raw Data |
1187 | // iptr passed by reference and so will be updated automatically |
1188 | if(VERBOSE>7) cout << " FADC250 Window Raw Data"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1189 | MakeDf250WindowRawData(pe, rocid, slot, itrigger, iptr); |
1190 | break; |
1191 | case 5: // Window Sum |
1192 | { |
1193 | uint32_t channel = (*iptr>>23) & 0x0F; |
1194 | uint32_t sum = (*iptr>>0) & 0x3FFFFF; |
1195 | uint32_t overflow = (*iptr>>22) & 0x1; |
1196 | if(VERBOSE>7) cout << " FADC250 Window Sum"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1197 | if(pe) pe->NEW_Df250WindowSum(rocid, slot, channel, itrigger, sum, overflow); |
1198 | } |
1199 | break; |
1200 | case 6: // Pulse Raw Data |
1201 | // MakeDf250PulseRawData(objs, rocid, slot, itrigger, iptr); |
1202 | if(VERBOSE>7) cout << " FADC250 Pulse Raw Data"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1203 | break; |
1204 | case 7: // Pulse Integral |
1205 | { |
1206 | uint32_t channel = (*iptr>>23) & 0x0F; |
1207 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1208 | uint32_t quality_factor = (*iptr>>19) & 0x03; |
1209 | uint32_t sum = (*iptr>>0) & 0x7FFFF; |
1210 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1211 | uint32_t nsamples_pedestal = 1; // The firmware returns an already divided pedestal |
1212 | uint32_t pedestal = 0; // This will be replaced by the one from Df250PulsePedestal in GetObjects |
1213 | if(VERBOSE>7) cout << " FADC250 Pulse Integral: chan="<<channel<<" pulse_number="<<pulse_number<<" sum="<<sum<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1214 | if(pe) pe->NEW_Df250PulseIntegral(rocid, slot, channel, itrigger, pulse_number, quality_factor, sum, pedestal, nsamples_integral, nsamples_pedestal); |
1215 | } |
1216 | break; |
1217 | case 8: // Pulse Time |
1218 | { |
1219 | uint32_t channel = (*iptr>>23) & 0x0F; |
1220 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1221 | uint32_t quality_factor = (*iptr>>19) & 0x03; |
1222 | uint32_t pulse_time = (*iptr>>0) & 0x7FFFF; |
1223 | if(VERBOSE>7) cout << " FADC250 Pulse Time: chan="<<channel<<" pulse_number="<<pulse_number<<" pulse_time="<<pulse_time<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1224 | if(pe) pe->NEW_Df250PulseTime(rocid, slot, channel, itrigger, pulse_number, quality_factor, pulse_time); |
1225 | } |
1226 | break; |
1227 | case 9: // Pulse Data (firmware instroduce in Fall 2016) |
1228 | { |
1229 | // from word 1 |
1230 | uint32_t event_number_within_block = (*iptr>>19) & 0xFF; |
1231 | uint32_t channel = (*iptr>>15) & 0x0F; |
1232 | bool QF_pedestal = (*iptr>>14) & 0x01; |
1233 | uint32_t pedestal = (*iptr>>0 ) & 0x3FFF; |
1234 | |
1235 | // Event headers may be supressed so determine event from hit data |
1236 | if( (event_number_within_block > current_parsed_events.size()) || (event_number_within_block==0) ) throw JException("Bad f250 event number", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1236); |
1237 | pe_iter = current_parsed_events.begin(); |
1238 | advance( pe_iter, (event_number_within_block-1) ); |
1239 | pe = *pe_iter++; |
1240 | |
1241 | itrigger = event_number_within_block; // is this right? |
1242 | uint32_t pulse_number = 0; |
1243 | |
1244 | while( (*++iptr>>31) == 0 ){ |
1245 | |
1246 | if( (*iptr>>30) != 0x01) throw JException("Bad f250 Pulse Data!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1246); |
1247 | |
1248 | // from word 2 |
1249 | uint32_t integral = (*iptr>>12) & 0x3FFFF; |
1250 | bool QF_NSA_beyond_PTW = (*iptr>>11) & 0x01; |
1251 | bool QF_overflow = (*iptr>>10) & 0x01; |
1252 | bool QF_underflow = (*iptr>>9 ) & 0x01; |
1253 | uint32_t nsamples_over_threshold = (*iptr>>0 ) & 0x1FF; |
1254 | |
1255 | iptr++; |
1256 | if( (*iptr>>30) != 0x00) throw JException("Bad f250 Pulse Data!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1256); |
1257 | |
1258 | // from word 3 |
1259 | uint32_t course_time = (*iptr>>21) & 0x1FF;//< 4 ns/count |
1260 | uint32_t fine_time = (*iptr>>15) & 0x3F;//< 0.0625 ns/count |
1261 | uint32_t pulse_peak = (*iptr>>3 ) & 0xFFF; |
1262 | bool QF_vpeak_beyond_NSA = (*iptr>>2 ) & 0x01; |
1263 | bool QF_vpeak_not_found = (*iptr>>1 ) & 0x01; |
1264 | bool QF_bad_pedestal = (*iptr>>0 ) & 0x01; |
1265 | |
1266 | if( pe ) { |
1267 | pe->NEW_Df250PulseData(rocid, slot, channel, itrigger |
1268 | , event_number_within_block |
1269 | , QF_pedestal |
1270 | , pedestal |
1271 | , integral |
1272 | , QF_NSA_beyond_PTW |
1273 | , QF_overflow |
1274 | , QF_underflow |
1275 | , nsamples_over_threshold |
1276 | , course_time |
1277 | , fine_time |
1278 | , pulse_peak |
1279 | , QF_vpeak_beyond_NSA |
1280 | , QF_vpeak_not_found |
1281 | , QF_bad_pedestal |
1282 | , pulse_number++); |
1283 | } |
1284 | } |
1285 | iptr--; // backup so when outer loop advances, it points to next data defining word |
1286 | |
1287 | } |
1288 | break; |
1289 | case 10: // Pulse Pedestal |
1290 | { |
1291 | uint32_t channel = (*iptr>>23) & 0x0F; |
1292 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1293 | uint32_t pedestal = (*iptr>>12) & 0x1FF; |
1294 | uint32_t pulse_peak = (*iptr>>0) & 0xFFF; |
1295 | if(VERBOSE>7) cout << " FADC250 Pulse Pedestal chan="<<channel<<" pulse_number="<<pulse_number<<" pedestal="<<pedestal<<" pulse_peak="<<pulse_peak<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1296 | if(pe) pe->NEW_Df250PulsePedestal(rocid, slot, channel, itrigger, pulse_number, pedestal, pulse_peak); |
1297 | } |
1298 | break; |
1299 | case 13: // Event Trailer |
1300 | // This is marked "suppressed for normal readout – debug mode only" in the |
1301 | // current manual (v2). It does not contain any data so the most we could do here |
1302 | // is return early. I'm hesitant to do that though since it would mean |
1303 | // different behavior for debug mode data as regular data. |
1304 | case 14: // Data not valid (empty module) |
1305 | case 15: // Filler (non-data) word |
1306 | if(VERBOSE>7) cout << " FADC250 Event Trailer, Data not Valid, or Filler word ("<<data_type<<")"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1307 | break; |
1308 | } |
1309 | } |
1310 | |
1311 | // Chop off filler words |
1312 | for(; iptr<iend; iptr++){ |
1313 | if(((*iptr)&0xf8000000) != 0xf8000000) break; |
1314 | } |
1315 | } |
1316 | |
1317 | //---------------- |
1318 | // MakeDf250WindowRawData |
1319 | //---------------- |
1320 | void DEVIOWorkerThread::MakeDf250WindowRawData(DParsedEvent *pe, uint32_t rocid, uint32_t slot, uint32_t itrigger, uint32_t* &iptr) |
1321 | { |
1322 | uint32_t channel = (*iptr>>23) & 0x0F; |
1323 | uint32_t window_width = (*iptr>>0) & 0x0FFF; |
1324 | |
1325 | Df250WindowRawData *wrd = pe->NEW_Df250WindowRawData(rocid, slot, channel, itrigger); |
1326 | |
1327 | for(uint32_t isample=0; isample<window_width; isample +=2){ |
1328 | |
1329 | // Advance to next word |
1330 | iptr++; |
1331 | |
1332 | // Make sure this is a data continuation word, if not, stop here |
1333 | if(((*iptr>>31) & 0x1) != 0x0){ |
1334 | iptr--; // calling method expects us to point to last word in block |
1335 | break; |
1336 | } |
1337 | |
1338 | bool invalid_1 = (*iptr>>29) & 0x1; |
1339 | bool invalid_2 = (*iptr>>13) & 0x1; |
1340 | uint16_t sample_1 = 0; |
1341 | uint16_t sample_2 = 0; |
1342 | if(!invalid_1)sample_1 = (*iptr>>16) & 0x1FFF; |
1343 | if(!invalid_2)sample_2 = (*iptr>>0) & 0x1FFF; |
1344 | |
1345 | // Sample 1 |
1346 | wrd->samples.push_back(sample_1); |
1347 | wrd->invalid_samples |= invalid_1; |
1348 | wrd->overflow |= (sample_1>>12) & 0x1; |
1349 | |
1350 | if(((isample+2) == window_width) && invalid_2)break; // skip last sample if flagged as invalid |
1351 | |
1352 | // Sample 2 |
1353 | wrd->samples.push_back(sample_2); |
1354 | wrd->invalid_samples |= invalid_2; |
1355 | wrd->overflow |= (sample_2>>12) & 0x1; |
1356 | } |
1357 | } |
1358 | |
1359 | //---------------- |
1360 | // Parsef125Bank |
1361 | //---------------- |
1362 | void DEVIOWorkerThread::Parsef125Bank(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1363 | { |
1364 | if(!PARSE_F125){ iptr = &iptr[(*iptr) + 1]; return; } |
1365 | |
1366 | auto pe_iter = current_parsed_events.begin(); |
1367 | DParsedEvent *pe = NULL__null; |
1368 | |
1369 | uint32_t slot=0; |
1370 | uint32_t itrigger = -1; |
1371 | uint32_t last_itrigger = -2; |
1372 | uint32_t last_pulse_time_channel=0; |
1373 | uint32_t last_slot = -1; |
1374 | uint32_t last_channel = -1; |
1375 | |
1376 | // Loop over data words |
1377 | for(; iptr<iend; iptr++){ |
1378 | |
1379 | // Skip all non-data-type-defining words at this |
1380 | // level. When we do encounter one, the appropriate |
1381 | // case block below should handle parsing all of |
1382 | // the data continuation words and advance the iptr. |
1383 | if(((*iptr>>31) & 0x1) == 0)continue; |
1384 | |
1385 | uint32_t data_type = (*iptr>>27) & 0x0F; |
1386 | switch(data_type){ |
1387 | case 0: // Block Header |
1388 | slot = (*iptr>>22) & 0x1F; |
1389 | if(VERBOSE>7) cout << " FADC125 Block Header: slot="<<slot<<endl; |
1390 | break; |
1391 | case 1: // Block Trailer |
1392 | pe_iter = current_parsed_events.begin(); |
1393 | pe = NULL__null; |
1394 | break; |
1395 | case 2: // Event Header |
1396 | //slot_event_header = (*iptr>>22) & 0x1F; |
1397 | itrigger = (*iptr>>0) & 0x3FFFFFF; |
1398 | pe = *pe_iter++; |
1399 | if(VERBOSE>7) cout << " FADC125 Event Header: itrigger="<<itrigger<<" last_itrigger="<<last_itrigger<<", rocid="<<rocid<<", slot="<<slot <<endl; |
1400 | break; |
1401 | case 3: // Trigger Time |
1402 | { |
1403 | uint64_t t = ((*iptr)&0xFFFFFF)<<0; |
1404 | iptr++; |
1405 | if(((*iptr>>31) & 0x1) == 0){ |
1406 | t += ((*iptr)&0xFFFFFF)<<24; // from word on the street: second trigger time word is optional!!?? |
1407 | }else{ |
1408 | iptr--; |
1409 | } |
1410 | if(VERBOSE>7) cout << " FADC125 Trigger Time (t="<<t<<")"<<endl; |
1411 | if(pe) pe->NEW_Df125TriggerTime(rocid, slot, itrigger, t); |
1412 | } |
1413 | break; |
1414 | case 4: // Window Raw Data |
1415 | // iptr passed by reference and so will be updated automatically |
1416 | if(VERBOSE>7) cout << " FADC125 Window Raw Data"<<endl; |
1417 | MakeDf125WindowRawData(pe, rocid, slot, itrigger, iptr); |
1418 | break; |
1419 | |
1420 | case 5: // CDC pulse data (new) (GlueX-doc-2274-v8) |
1421 | { |
1422 | // Word 1: |
1423 | uint32_t word1 = *iptr; |
1424 | uint32_t channel = (*iptr>>20) & 0x7F; |
1425 | uint32_t pulse_number = (*iptr>>15) & 0x1F; |
1426 | uint32_t pulse_time = (*iptr>>4 ) & 0x7FF; |
1427 | uint32_t quality_factor = (*iptr>>3 ) & 0x1; //time QF bit |
1428 | uint32_t overflow_count = (*iptr>>0 ) & 0x7; |
1429 | if(VERBOSE>7){ |
1430 | cout << " FADC125 CDC Pulse Data word1: " << hex << (*iptr) << dec << endl; |
1431 | cout << " FADC125 CDC Pulse Data (chan="<<channel<<" pulse="<<pulse_number<<" time="<<pulse_time<<" QF="<<quality_factor<<" OC="<<overflow_count<<")"<<endl; |
1432 | } |
1433 | |
1434 | // Word 2: |
1435 | ++iptr; |
1436 | if(iptr>=iend){ |
1437 | jerr << " Truncated f125 CDC hit (block ends before continuation word!)" << endl; |
1438 | continue; |
1439 | } |
1440 | if( ((*iptr>>31) & 0x1) != 0 ){ |
1441 | jerr << " Truncated f125 CDC hit (missing continuation word!)" << endl; |
1442 | continue; |
1443 | } |
1444 | uint32_t word2 = *iptr; |
1445 | uint32_t pedestal = (*iptr>>23) & 0xFF; |
1446 | uint32_t sum = (*iptr>>9 ) & 0x3FFF; |
1447 | uint32_t pulse_peak = (*iptr>>0 ) & 0x1FF; |
1448 | if(VERBOSE>7){ |
1449 | cout << " FADC125 CDC Pulse Data word2: " << hex << (*iptr) << dec << endl; |
1450 | cout << " FADC125 CDC Pulse Data (pedestal="<<pedestal<<" sum="<<sum<<" peak="<<pulse_peak<<")"<<endl; |
1451 | } |
1452 | |
1453 | // Create hit objects |
1454 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1455 | uint32_t nsamples_pedestal = 1; // The firmware pedestal divided by 2^PBIT where PBIT is a config. parameter |
1456 | |
1457 | if( pe ) { |
1458 | pe->NEW_Df125CDCPulse(rocid, slot, channel, itrigger |
1459 | , pulse_number // NPK |
1460 | , pulse_time // le_time |
1461 | , quality_factor // time_quality_bit |
1462 | , overflow_count // overflow_count |
1463 | , pedestal // pedestal |
1464 | , sum // integral |
1465 | , pulse_peak // first_max_amp |
1466 | , word1 // word1 |
1467 | , word2 // word2 |
1468 | , nsamples_pedestal // nsamples_pedestal |
1469 | , nsamples_integral // nsamples_integral |
1470 | , false); // emulated |
1471 | } |
1472 | } |
1473 | break; |
1474 | |
1475 | case 6: // FDC pulse data-integral (new) (GlueX-doc-2274-v8) |
1476 | { |
1477 | // Word 1: |
1478 | uint32_t word1 = *iptr; |
1479 | uint32_t channel = (*iptr>>20) & 0x7F; |
1480 | uint32_t pulse_number = (*iptr>>15) & 0x1F; |
1481 | uint32_t pulse_time = (*iptr>>4 ) & 0x7FF; |
1482 | uint32_t quality_factor = (*iptr>>3 ) & 0x1; //time QF bit |
1483 | uint32_t overflow_count = (*iptr>>0 ) & 0x7; |
1484 | if(VERBOSE>7){ |
1485 | cout << " FADC125 FDC Pulse Data(integral) word1: " << hex << (*iptr) << dec << endl; |
1486 | cout << " FADC125 FDC Pulse Data (chan="<<channel<<" pulse="<<pulse_number<<" time="<<pulse_time<<" QF="<<quality_factor<<" OC="<<overflow_count<<")"<<endl; |
1487 | } |
1488 | |
1489 | // Word 2: |
1490 | ++iptr; |
1491 | if(iptr>=iend){ |
1492 | jerr << " Truncated f125 FDC hit (block ends before continuation word!)" << endl; |
1493 | continue; |
1494 | } |
1495 | if( ((*iptr>>31) & 0x1) != 0 ){ |
1496 | jerr << " Truncated f125 FDC hit (missing continuation word!)" << endl; |
1497 | continue; |
1498 | } |
1499 | uint32_t word2 = *iptr; |
1500 | uint32_t pulse_peak = 0; |
1501 | uint32_t sum = (*iptr>>19) & 0xFFF; |
1502 | uint32_t peak_time = (*iptr>>11) & 0xFF; |
1503 | uint32_t pedestal = (*iptr>>0 ) & 0x7FF; |
1504 | if(VERBOSE>7){ |
1505 | cout << " FADC125 FDC Pulse Data(integral) word2: " << hex << (*iptr) << dec << endl; |
1506 | cout << " FADC125 FDC Pulse Data (integral="<<sum<<" time="<<peak_time<<" pedestal="<<pedestal<<")"<<endl; |
1507 | } |
1508 | |
1509 | // Create hit objects |
1510 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1511 | uint32_t nsamples_pedestal = 1; // The firmware pedestal divided by 2^PBIT where PBIT is a config. parameter |
1512 | |
1513 | if( pe ) { |
1514 | pe->NEW_Df125FDCPulse(rocid, slot, channel, itrigger |
1515 | , pulse_number // NPK |
1516 | , pulse_time // le_time |
1517 | , quality_factor // time_quality_bit |
1518 | , overflow_count // overflow_count |
1519 | , pedestal // pedestal |
1520 | , sum // integral |
1521 | , pulse_peak // peak_amp |
1522 | , peak_time // peak_time |
1523 | , word1 // word1 |
1524 | , word2 // word2 |
1525 | , nsamples_pedestal // nsamples_pedestal |
1526 | , nsamples_integral // nsamples_integral |
1527 | , false); // emulated |
1528 | } |
1529 | } |
1530 | break; |
1531 | |
1532 | case 7: // Pulse Integral |
1533 | { |
1534 | if(VERBOSE>7) cout << " FADC125 Pulse Integral"<<endl; |
1535 | uint32_t channel = (*iptr>>20) & 0x7F; |
1536 | uint32_t sum = (*iptr>>0) & 0xFFFFF; |
1537 | uint32_t quality_factor = 0; |
1538 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1539 | uint32_t nsamples_pedestal = 1; // The firmware returns an already divided pedestal |
1540 | uint32_t pedestal = 0; // This will be replaced by the one from Df250PulsePedestal in GetObjects |
1541 | uint32_t pulse_number = 0; |
1542 | if (last_slot == slot && last_channel == channel) pulse_number = 1; |
1543 | last_slot = slot; |
1544 | last_channel = channel; |
1545 | if( pe ) pe->NEW_Df125PulseIntegral(rocid, slot, channel, itrigger, pulse_number, quality_factor, sum, pedestal, nsamples_integral, nsamples_pedestal); |
1546 | } |
1547 | break; |
1548 | case 8: // Pulse Time |
1549 | { |
1550 | if(VERBOSE>7) cout << " FADC125 Pulse Time"<<endl; |
1551 | uint32_t channel = (*iptr>>20) & 0x7F; |
1552 | uint32_t pulse_number = (*iptr>>18) & 0x03; |
1553 | uint32_t pulse_time = (*iptr>>0) & 0xFFFF; |
1554 | uint32_t quality_factor = 0; |
1555 | if( pe ) pe->NEW_Df125PulseTime(rocid, slot, channel, itrigger, pulse_number, quality_factor, pulse_time); |
1556 | last_pulse_time_channel = channel; |
1557 | } |
1558 | break; |
1559 | |
1560 | case 9: // FDC pulse data-peak (new) (GlueX-doc-2274-v8) |
1561 | { |
1562 | // Word 1: |
1563 | uint32_t word1 = *iptr; |
1564 | uint32_t channel = (*iptr>>20) & 0x7F; |
1565 | uint32_t pulse_number = (*iptr>>15) & 0x1F; |
1566 | uint32_t pulse_time = (*iptr>>4 ) & 0x7FF; |
1567 | uint32_t quality_factor = (*iptr>>3 ) & 0x1; //time QF bit |
1568 | uint32_t overflow_count = (*iptr>>0 ) & 0x7; |
1569 | if(VERBOSE>7){ |
1570 | cout << " FADC125 FDC Pulse Data(peak) word1: " << hex << (*iptr) << dec << endl; |
1571 | cout << " FADC125 FDC Pulse Data (chan="<<channel<<" pulse="<<pulse_number<<" time="<<pulse_time<<" QF="<<quality_factor<<" OC="<<overflow_count<<")"<<endl; |
1572 | } |
1573 | |
1574 | // Word 2: |
1575 | ++iptr; |
1576 | if(iptr>=iend){ |
1577 | jerr << " Truncated f125 FDC hit (block ends before continuation word!)" << endl; |
1578 | continue; |
1579 | } |
1580 | if( ((*iptr>>31) & 0x1) != 0 ){ |
1581 | jerr << " Truncated f125 FDC hit (missing continuation word!)" << endl; |
1582 | continue; |
1583 | } |
1584 | uint32_t word2 = *iptr; |
1585 | uint32_t pulse_peak = (*iptr>>19) & 0xFFF; |
1586 | uint32_t sum = 0; |
1587 | uint32_t peak_time = (*iptr>>11) & 0xFF; |
1588 | uint32_t pedestal = (*iptr>>0 ) & 0x7FF; |
1589 | if(VERBOSE>7){ |
1590 | cout << " FADC125 FDC Pulse Data(peak) word2: " << hex << (*iptr) << dec << endl; |
1591 | cout << " FADC125 FDC Pulse Data (integral="<<sum<<" time="<<peak_time<<" pedestal="<<pedestal<<")"<<endl; |
1592 | } |
1593 | |
1594 | // Create hit objects |
1595 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1596 | uint32_t nsamples_pedestal = 1; // The firmware pedestal divided by 2^PBIT where PBIT is a config. parameter |
1597 | |
1598 | if( pe ) { |
1599 | pe->NEW_Df125FDCPulse(rocid, slot, channel, itrigger |
1600 | , pulse_number // NPK |
1601 | , pulse_time // le_time |
1602 | , quality_factor // time_quality_bit |
1603 | , overflow_count // overflow_count |
1604 | , pedestal // pedestal |
1605 | , sum // integral |
1606 | , pulse_peak // peak_amp |
1607 | , peak_time // peak_time |
1608 | , word1 // word1 |
1609 | , word2 // word2 |
1610 | , nsamples_pedestal // nsamples_pedestal |
1611 | , nsamples_integral // nsamples_integral |
1612 | , false); // emulated |
1613 | } |
1614 | } |
1615 | break; |
1616 | |
1617 | case 10: // Pulse Pedestal (consistent with Beni's hand-edited version of Cody's document) |
1618 | { |
1619 | if(VERBOSE>7) cout << " FADC125 Pulse Pedestal"<<endl; |
1620 | //channel = (*iptr>>20) & 0x7F; |
1621 | uint32_t channel = last_pulse_time_channel; // not enough bits to hold channel number so rely on proximity to Pulse Time in data stream (see "FADC125 dataformat 250 modes.docx") |
1622 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1623 | uint32_t pedestal = (*iptr>>12) & 0x1FF; |
1624 | uint32_t pulse_peak = (*iptr>>0) & 0xFFF; |
1625 | uint32_t nsamples_pedestal = 1; // The firmware returns an already divided pedestal |
1626 | if( pe ) pe->NEW_Df125PulsePedestal(rocid, slot, channel, itrigger, pulse_number, pedestal, pulse_peak, nsamples_pedestal); |
1627 | } |
1628 | break; |
1629 | |
1630 | case 13: // Event Trailer |
1631 | case 14: // Data not valid (empty module) |
1632 | case 15: // Filler (non-data) word |
1633 | if(VERBOSE>7) cout << " FADC125 ignored data type: " << data_type <<endl; |
1634 | break; |
1635 | } |
1636 | } |
1637 | |
1638 | // Chop off filler words |
1639 | for(; iptr<iend; iptr++){ |
1640 | if(((*iptr)&0xf8000000) != 0xf8000000) break; |
1641 | } |
1642 | } |
1643 | |
1644 | //---------------- |
1645 | // MakeDf125WindowRawData |
1646 | //---------------- |
1647 | void DEVIOWorkerThread::MakeDf125WindowRawData(DParsedEvent *pe, uint32_t rocid, uint32_t slot, uint32_t itrigger, uint32_t* &iptr) |
1648 | { |
1649 | uint32_t channel = (*iptr>>20) & 0x7F; |
1650 | uint32_t window_width = (*iptr>>0) & 0x0FFF; |
1651 | |
1652 | Df125WindowRawData *wrd = pe->NEW_Df125WindowRawData(rocid, slot, channel, itrigger); |
1653 | |
1654 | for(uint32_t isample=0; isample<window_width; isample +=2){ |
1655 | |
1656 | // Advance to next word |
1657 | iptr++; |
1658 | |
1659 | // Make sure this is a data continuation word, if not, stop here |
1660 | if(((*iptr>>31) & 0x1) != 0x0)break; |
1661 | |
1662 | bool invalid_1 = (*iptr>>29) & 0x1; |
1663 | bool invalid_2 = (*iptr>>13) & 0x1; |
1664 | uint16_t sample_1 = 0; |
1665 | uint16_t sample_2 = 0; |
1666 | if(!invalid_1)sample_1 = (*iptr>>16) & 0x1FFF; |
1667 | if(!invalid_2)sample_2 = (*iptr>>0) & 0x1FFF; |
1668 | |
1669 | // Sample 1 |
1670 | wrd->samples.push_back(sample_1); |
1671 | wrd->invalid_samples |= invalid_1; |
1672 | wrd->overflow |= (sample_1>>12) & 0x1; |
1673 | |
1674 | if((isample+2) == window_width && invalid_2)break; // skip last sample if flagged as invalid |
1675 | |
1676 | // Sample 2 |
1677 | wrd->samples.push_back(sample_2); |
1678 | wrd->invalid_samples |= invalid_2; |
1679 | wrd->overflow |= (sample_2>>12) & 0x1; |
1680 | } |
1681 | } |
1682 | |
1683 | //---------------- |
1684 | // ParseF1TDCBank |
1685 | //---------------- |
1686 | void DEVIOWorkerThread::ParseF1TDCBank(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1687 | { |
1688 | if(!PARSE_F1TDC){ iptr = &iptr[(*iptr) + 1]; return; } |
1689 | |
1690 | uint32_t *istart = iptr; |
1691 | |
1692 | auto pe_iter = current_parsed_events.begin(); |
1693 | DParsedEvent *pe = NULL__null; |
1694 | |
1695 | uint32_t slot = 0; |
1696 | uint32_t modtype = 0; |
1697 | uint32_t itrigger = -1; |
1698 | uint32_t trig_time_f1header = 0; |
1699 | |
1700 | // Some early data had a marker word at just before the actual F1 data |
1701 | if(*iptr == 0xf1daffff) iptr++; |
1702 | |
1703 | // Loop over data words |
1704 | for(; iptr<iend; iptr++){ |
1705 | |
1706 | // Skip all non-data-type-defining words at this |
1707 | // level. When we do encounter one, the appropriate |
1708 | // case block below should handle parsing all of |
1709 | // the data continuation words and advance the iptr. |
1710 | if(((*iptr>>31) & 0x1) == 0)continue; |
1711 | |
1712 | uint32_t data_type = (*iptr>>27) & 0x0F; |
1713 | switch(data_type){ |
1714 | case 0: // Block Header |
1715 | slot = (*iptr)>>22 & 0x001F; |
1716 | modtype = (*iptr)>>18 & 0x000F; // should match a DModuleType::type_id_t |
1717 | if(VERBOSE>7) cout << " F1 Block Header: slot=" << slot << " modtype=" << modtype << endl; |
1718 | break; |
1719 | |
1720 | case 1: // Block Trailer |
1721 | pe_iter = current_parsed_events.begin(); |
1722 | pe = NULL__null; |
1723 | if(VERBOSE>7) cout << " F1 Block Trailer" << endl; |
1724 | break; |
1725 | |
1726 | case 2: // Event Header |
1727 | { |
1728 | pe = *pe_iter++; |
1729 | itrigger = (*iptr)>>0 & 0x0003FFFFF; |
1730 | if(VERBOSE>7) { |
1731 | uint32_t slot_event_header = (*iptr)>>22 & 0x00000001F; |
1732 | cout << " F1 Event Header: slot=" << slot_event_header << " itrigger=" << itrigger << endl; |
1733 | } |
1734 | } |
1735 | break; |
1736 | |
1737 | case 3: // Trigger time |
1738 | { |
1739 | uint64_t t = ((*iptr)&0xFFFFFF)<<0; |
1740 | iptr++; |
1741 | if(((*iptr>>31) & 0x1) == 0){ |
1742 | t += ((*iptr)&0xFFFFFF)<<24; // from word on the street: second trigger time word is optional!!?? |
1743 | }else{ |
1744 | iptr--; |
1745 | } |
1746 | if(VERBOSE>7) cout << " F1TDC Trigger Time (t="<<t<<")"<<endl; |
1747 | if(pe) pe->NEW_DF1TDCTriggerTime(rocid, slot, itrigger, t); |
1748 | } |
1749 | break; |
1750 | |
1751 | case 8: // F1 Chip Header |
1752 | trig_time_f1header = ((*iptr)>> 7) & 0x1FF; |
1753 | if(VERBOSE>7) { |
1754 | uint32_t chip_f1header = ((*iptr)>> 3) & 0x07; |
1755 | uint32_t chan_on_chip_f1header = ((*iptr)>> 0) & 0x07; // this is always 7 in real data! |
1756 | uint32_t itrigger_f1header = ((*iptr)>>16) & 0x3F; |
1757 | cout << " Found F1 header: chip=" << chip_f1header << " chan=" << chan_on_chip_f1header << " itrig=" << itrigger_f1header << " trig_time=" << trig_time_f1header << endl; |
1758 | } |
1759 | break; |
1760 | |
1761 | case 7: // F1 Data |
1762 | { |
1763 | uint32_t chip = (*iptr>>19) & 0x07; |
1764 | uint32_t chan_on_chip = (*iptr>>16) & 0x07; |
1765 | uint32_t time = (*iptr>> 0) & 0xFFFF; |
1766 | uint32_t channel = F1TDC_channel(chip, chan_on_chip, modtype); |
1767 | if(VERBOSE>7) cout << " Found F1 data : chip=" << chip << " chan=" << chan_on_chip << " time=" << time << endl; |
1768 | if(pe) pe->NEW_DF1TDCHit(rocid, slot, channel, itrigger, trig_time_f1header, time, *iptr, MODULE_TYPE(modtype)); |
1769 | } |
1770 | break; |
1771 | |
1772 | case 15: // Filler word |
1773 | if(VERBOSE>7) cout << " F1 filler word" << endl; |
1774 | case 14: // Data not valid (how to handle this?) |
1775 | break; |
1776 | |
1777 | default: |
1778 | cerr<<endl; |
1779 | cout.flush(); cerr.flush(); |
1780 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1780<<" "<<"Unknown data word in F1TDC block. Dumping for debugging:" << endl; |
1781 | for(const uint32_t *iiptr = istart; iiptr<iend; iiptr++){ |
1782 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1782<<" "<<"0x"<<hex<<*iiptr<<dec; |
1783 | if(iiptr == iptr)cerr<<" <----"; |
1784 | switch( (*iiptr) & 0xF8000000 ){ |
1785 | case 0x80000000: cerr << " F1 Block Header"; break; |
1786 | case 0x90000000: cerr << " F1 Event Header"; break; |
1787 | case 0x98000000: cerr << " F1 Trigger time"; break; |
1788 | case 0xC0000000: cerr << " F1 Header"; break; |
1789 | case 0xB8000000: cerr << " F1 Data"; break; |
1790 | case 0x88000000: cerr << " F1 Block Trailer"; break; |
1791 | case 0xF8000000: cerr << " Filler word"; break; |
1792 | case 0xF0000000: cerr << " <module has no valid data>"; break; |
1793 | default: break; |
1794 | } |
1795 | cerr<<endl; |
1796 | if(iiptr > (iptr+4)) break; |
1797 | } |
1798 | throw JException("Unexpected word type in F1TDC block!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1798); |
1799 | break; |
1800 | } |
1801 | } |
1802 | |
1803 | // Skip filler words |
1804 | while(iptr<iend && (*iptr&0xF8000000)==0xF8000000)iptr++; |
1805 | } |
1806 | |
1807 | //---------------- |
1808 | // ParseDVertexBank |
1809 | //---------------- |
1810 | void DEVIOWorkerThread::ParseDVertexBank(uint32_t* &iptr, uint32_t *iend) |
1811 | { |
1812 | uint32_t Nwords = ((uint64_t)iend - (uint64_t)iptr)/sizeof(uint32_t); |
1813 | uint32_t Nwords_expected = 11; // ? |
1814 | if(Nwords != Nwords_expected){ |
1815 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1815<<" " << "DVertex size does not match expected!!" << endl; |
1816 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1816<<" " << "Found " << Nwords << " words. Expected " << Nwords_expected << endl; |
1817 | }else{ |
1818 | DParsedEvent *pe = current_parsed_events.back(); |
1819 | DVertex *the_vertex = pe->NEW_DVertex(); |
1820 | |
1821 | uint64_t in_word = *iptr++; // 1st word, lo word; 2nd word, hi word |
1822 | uint64_t in_word_hi = *iptr++; |
1823 | in_word |= in_word_hi<<32; |
1824 | //uint64_t hi_word = *iptr++; |
1825 | double vertex_x_pos; |
1826 | memcpy(&vertex_x_pos, &in_word, sizeof(double)); |
1827 | in_word = *iptr++; in_word_hi = *iptr++; |
1828 | in_word |= in_word_hi<<32; |
1829 | double vertex_y_pos; |
1830 | memcpy(&vertex_y_pos, &in_word, sizeof(double)); |
1831 | in_word = *iptr++; in_word_hi = *iptr++; |
1832 | in_word |= in_word_hi<<32; |
1833 | double vertex_z_pos; |
1834 | memcpy(&vertex_z_pos, &in_word, sizeof(double)); |
1835 | in_word = *iptr++; in_word_hi = *iptr++; |
1836 | in_word |= in_word_hi<<32; |
1837 | double vertex_t; |
1838 | memcpy(&vertex_t, &in_word, sizeof(double)); |
1839 | |
1840 | DVector3 vertex_position(vertex_x_pos, vertex_y_pos, vertex_z_pos); |
1841 | the_vertex->dSpacetimeVertex = DLorentzVector(vertex_position, vertex_t); |
1842 | the_vertex->dKinFitNDF = *iptr++; |
1843 | |
1844 | in_word = *iptr++; in_word_hi = *iptr++; |
1845 | in_word |= in_word_hi<<32; |
1846 | memcpy(&(the_vertex->dKinFitChiSq), &in_word, sizeof(double)); |
1847 | } |
1848 | } |
1849 | |
1850 | |
1851 | //---------------- |
1852 | // LinkAllAssociations |
1853 | //---------------- |
1854 | void DEVIOWorkerThread::LinkAllAssociations(void) |
1855 | { |
1856 | |
1857 | /// Find objects that should be linked as "associated objects" |
1858 | /// of one another and add to each other's list. |
1859 | for( auto pe : current_parsed_events){ |
1860 | |
1861 | //----------------- Sort hit objects |
1862 | |
1863 | // fADC250 |
1864 | if(pe->vDf250PulseIntegral.size()>1) sort(pe->vDf250PulseIntegral.begin(), pe->vDf250PulseIntegral.end(), SortByPulseNumber<Df250PulseIntegral> ); |
1865 | if(pe->vDf250PulseTime.size()>1 ) sort(pe->vDf250PulseTime.begin(), pe->vDf250PulseTime.end(), SortByPulseNumber<Df250PulseTime> ); |
1866 | if(pe->vDf250PulsePedestal.size()>1) sort(pe->vDf250PulsePedestal.begin(), pe->vDf250PulsePedestal.end(), SortByPulseNumber<Df250PulsePedestal> ); |
1867 | |
1868 | // fADC125 |
1869 | if(pe->vDf125PulseIntegral.size()>1) sort(pe->vDf125PulseIntegral.begin(), pe->vDf125PulseIntegral.end(), SortByPulseNumber<Df125PulseIntegral> ); |
1870 | if(pe->vDf125CDCPulse.size()>1 ) sort(pe->vDf125CDCPulse.begin(), pe->vDf125CDCPulse.end(), SortByChannel<Df125CDCPulse> ); |
1871 | if(pe->vDf125FDCPulse.size()>1 ) sort(pe->vDf125FDCPulse.begin(), pe->vDf125FDCPulse.end(), SortByChannel<Df125FDCPulse> ); |
1872 | if(pe->vDf125PulseTime.size()>1 ) sort(pe->vDf125PulseTime.begin(), pe->vDf125PulseTime.end(), SortByPulseNumber<Df125PulseTime> ); |
1873 | if(pe->vDf125PulsePedestal.size()>1) sort(pe->vDf125PulsePedestal.begin(), pe->vDf125PulsePedestal.end(), SortByPulseNumber<Df125PulsePedestal> ); |
1874 | |
1875 | // F1TDC |
1876 | if(pe->vDF1TDCHit.size()>1 ) sort(pe->vDF1TDCHit.begin(), pe->vDF1TDCHit.end(), SortByModule<DF1TDCHit> ); |
1877 | |
1878 | // CAEN1290TDC |
1879 | if(pe->vDCAEN1290TDCHit.size()>1 ) sort(pe->vDCAEN1290TDCHit.begin(), pe->vDCAEN1290TDCHit.end(), SortByModule<DCAEN1290TDCHit> ); |
1880 | |
1881 | |
1882 | //----------------- Link hit objects |
1883 | |
1884 | // Connect Df250 pulse objects |
1885 | LinkPulse(pe->vDf250PulseTime, pe->vDf250PulseIntegral); |
1886 | LinkPulsePedCopy(pe->vDf250PulsePedestal, pe->vDf250PulseIntegral); |
1887 | |
1888 | // Connect Df125 pulse objects |
1889 | LinkPulse(pe->vDf125PulseTime, pe->vDf125PulseIntegral); |
1890 | LinkPulsePedCopy(pe->vDf125PulsePedestal, pe->vDf125PulseIntegral); |
1891 | |
1892 | // Connect Df250 window raw data objects |
1893 | if(!pe->vDf250WindowRawData.empty()){ |
1894 | LinkConfig(pe->vDf250Config, pe->vDf250WindowRawData); |
1895 | LinkModule(pe->vDf250TriggerTime, pe->vDf250WindowRawData); |
1896 | LinkChannel(pe->vDf250WindowRawData, pe->vDf250PulseIntegral); |
1897 | LinkChannel(pe->vDf250WindowRawData, pe->vDf250PulseTime); |
1898 | LinkChannel(pe->vDf250WindowRawData, pe->vDf250PulsePedestal); |
1899 | } |
1900 | |
1901 | // Connect Df125 window raw data objects |
1902 | if(!pe->vDf125WindowRawData.empty()){ |
1903 | LinkConfig(pe->vDf125Config, pe->vDf125WindowRawData); |
1904 | LinkModule(pe->vDf125TriggerTime, pe->vDf125WindowRawData); |
1905 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125PulseIntegral); |
1906 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125PulseTime); |
1907 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125PulsePedestal); |
1908 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125CDCPulse); |
1909 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125FDCPulse); |
1910 | } |
1911 | |
1912 | //----------------- Optionally link config objects (on by default) |
1913 | if(LINK_CONFIG){ |
1914 | if(pe->vDf250Config.size()>1 ) sort(pe->vDf250Config.begin(), pe->vDf250Config.end(), SortByROCID<Df250Config> ); |
1915 | if(pe->vDf125Config.size()>1 ) sort(pe->vDf125Config.begin(), pe->vDf125Config.end(), SortByROCID<Df125Config> ); |
1916 | if(pe->vDF1TDCConfig.size()>1 ) sort(pe->vDF1TDCConfig.begin(), pe->vDF1TDCConfig.end(), SortByROCID<DF1TDCConfig> ); |
1917 | if(pe->vDCAEN1290TDCConfig.size()>1) sort(pe->vDCAEN1290TDCConfig.begin(), pe->vDCAEN1290TDCConfig.end(), SortByROCID<DCAEN1290TDCConfig> ); |
1918 | |
1919 | LinkConfigSamplesCopy(pe->vDf250Config, pe->vDf250PulseIntegral); |
1920 | LinkConfigSamplesCopy(pe->vDf250Config, pe->vDf250PulseData); |
1921 | LinkConfigSamplesCopy(pe->vDf125Config, pe->vDf125PulseIntegral); |
1922 | LinkConfigSamplesCopy(pe->vDf125Config, pe->vDf125CDCPulse); |
1923 | LinkConfigSamplesCopy(pe->vDf125Config, pe->vDf125FDCPulse); |
1924 | LinkConfig(pe->vDF1TDCConfig, pe->vDF1TDCHit); |
1925 | LinkConfig(pe->vDCAEN1290TDCConfig, pe->vDCAEN1290TDCHit); |
1926 | } |
1927 | |
1928 | //----------------- Optionally link trigger time objects (off by default) |
1929 | if(LINK_TRIGGERTIME){ |
1930 | if(pe->vDf250TriggerTime.size()>1 ) sort(pe->vDf250TriggerTime.begin(), pe->vDf250TriggerTime.end(), SortByModule<Df250TriggerTime> ); |
1931 | if(pe->vDf125TriggerTime.size()>1 ) sort(pe->vDf125TriggerTime.begin(), pe->vDf125TriggerTime.end(), SortByModule<Df125TriggerTime> ); |
1932 | if(pe->vDF1TDCTriggerTime.size()>1 ) sort(pe->vDF1TDCTriggerTime.begin(), pe->vDF1TDCTriggerTime.end(), SortByModule<DF1TDCTriggerTime> ); |
1933 | |
1934 | LinkModule(pe->vDf250TriggerTime, pe->vDf250PulseIntegral); |
1935 | LinkModule(pe->vDf125TriggerTime, pe->vDf125PulseIntegral); |
1936 | LinkModule(pe->vDf125TriggerTime, pe->vDf125CDCPulse); |
1937 | LinkModule(pe->vDf125TriggerTime, pe->vDf125FDCPulse); |
1938 | LinkModule(pe->vDF1TDCTriggerTime, pe->vDF1TDCHit); |
1939 | } |
1940 | } |
1941 | |
1942 | } |
1943 | |
1944 | //---------------- |
1945 | // DumpBinary |
1946 | //---------------- |
1947 | void DEVIOWorkerThread::DumpBinary(const uint32_t *iptr, const uint32_t *iend, uint32_t MaxWords, const uint32_t *imark) |
1948 | { |
1949 | /// This is used for debugging. It will print to the screen the words |
1950 | /// starting at the address given by iptr and ending just before iend |
1951 | /// or for MaxWords words, whichever comes first. If iend is NULL, |
1952 | /// then MaxWords will be printed. If MaxWords is zero then it is ignored |
1953 | /// and only iend is checked. If both iend==NULL and MaxWords==0, then |
1954 | /// only the word at iptr is printed. |
1955 | |
1956 | cout << "Dumping binary: istart=" << hex << iptr << " iend=" << iend << " MaxWords=" << dec << MaxWords << endl; |
1957 | |
1958 | if(iend==NULL__null && MaxWords==0) MaxWords=1; |
1959 | if(MaxWords==0) MaxWords = (uint32_t)0xffffffff; |
1960 | |
1961 | uint32_t Nwords=0; |
1962 | while(iptr!=iend && Nwords<MaxWords){ |
1963 | |
1964 | // line1 is hex and line2 is decimal |
1965 | stringstream line1, line2; |
1966 | |
1967 | // print words in columns 8 words wide. First part is |
1968 | // reserved for word number |
1969 | uint32_t Ncols = 8; |
1970 | line1 << setw(5) << Nwords; |
1971 | line2 << string(5, ' '); |
1972 | |
1973 | // Loop over columns |
1974 | for(uint32_t i=0; i<Ncols; i++, iptr++, Nwords++){ |
1975 | |
1976 | if(iptr == iend) break; |
1977 | if(Nwords>=MaxWords) break; |
1978 | |
1979 | stringstream iptr_hex; |
1980 | iptr_hex << hex << "0x" << *iptr; |
1981 | |
1982 | string mark = (iptr==imark ? "*":" "); |
1983 | |
1984 | line1 << setw(12) << iptr_hex.str() << mark; |
1985 | line2 << setw(12) << *iptr << mark; |
1986 | } |
1987 | |
1988 | cout << line1.str() << endl; |
1989 | cout << line2.str() << endl; |
1990 | cout << endl; |
1991 | } |
1992 | } |
1993 | |
1994 |