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_ << "0x" << hex << (uint64_t)iptr << dec << ": event_len=" << event_len << "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)/sizeof(uint32_t); |
495 | break; |
496 | case DModuleType::FADC125: // f125 |
497 | f125conf = new Df125BORConfig; |
498 | dest = (uint32_t*)&f125conf->rocid; |
499 | sizeof_dest = sizeof(f125config)/sizeof(uint32_t); |
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)/sizeof(uint32_t); |
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)/sizeof(uint32_t); |
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 ){ |
527 | stringstream ss; |
528 | ss << "BOR module bank size does not match structure! " << module_len << " > " << sizeof_dest << " 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 | // Set extra words to "0" at end of structure |
534 | // in case we are processing data from older firmware |
535 | for(uint32_t i=0; i<sizeof_dest; i++) *dest++ = i<module_len ? (*src++):0; |
536 | |
537 | // Store object for use in this and subsequent events |
538 | if(f250conf ) borptrs->vDf250BORConfig.push_back(f250conf); |
539 | if(f125conf ) borptrs->vDf125BORConfig.push_back(f125conf); |
540 | if(F1TDCconf ) borptrs->vDF1TDCBORConfig.push_back(F1TDCconf); |
541 | if(caen1190conf) borptrs->vDCAEN1290TDCBORConfig.push_back(caen1190conf); |
542 | |
543 | iptr = &iptr[module_len]; |
544 | } |
545 | |
546 | iptr = iend_crate; // ensure we're pointing past this crate |
547 | } |
548 | |
549 | // Sort the BOR config events now so we don't have to do it for every event |
550 | borptrs->Sort(); |
551 | |
552 | } |
553 | |
554 | //--------------------------------- |
555 | // ParseTSscalerBank |
556 | //--------------------------------- |
557 | void DEVIOWorkerThread::ParseTSscalerBank(uint32_t* &iptr, uint32_t *iend) |
558 | { |
559 | uint32_t Nwords = ((uint64_t)iend - (uint64_t)iptr)/sizeof(uint32_t); |
560 | uint32_t Nwords_expected = (6+32+16+32+16); |
561 | if(Nwords != Nwords_expected){ |
562 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<562<<" " << "TS bank size does not match expected!!" << endl; |
563 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<563<<" " << "Found " << Nwords << " words. Expected " << Nwords_expected << endl; |
564 | |
565 | }else{ |
566 | // n.b. Get the last event here since if this is a block |
567 | // of events, the last should be the actual sync event. |
568 | DParsedEvent *pe = current_parsed_events.back(); |
569 | DL1Info *s = pe->NEW_DL1Info(); |
570 | s->nsync = *iptr++; |
571 | s->trig_number = *iptr++; |
572 | s->live_time = *iptr++; |
573 | s->busy_time = *iptr++; |
574 | s->live_inst = *iptr++; |
575 | s->unix_time = *iptr++; |
576 | for(uint32_t i=0; i<32; i++) s->gtp_sc.push_back ( *iptr++ ); |
577 | for(uint32_t i=0; i<16; i++) s->fp_sc.push_back ( *iptr++ ); |
578 | for(uint32_t i=0; i<32; i++) s->gtp_rate.push_back( *iptr++ ); |
579 | for(uint32_t i=0; i<16; i++) s->fp_rate.push_back ( *iptr++ ); |
580 | } |
581 | |
582 | iptr = iend; |
583 | } |
584 | |
585 | //--------------------------------- |
586 | // Parsef250scalerBank |
587 | //--------------------------------- |
588 | void DEVIOWorkerThread::Parsef250scalerBank(uint32_t* &iptr, uint32_t *iend) |
589 | { |
590 | iptr = &iptr[(*iptr) + 1]; |
591 | } |
592 | |
593 | //--------------------------------- |
594 | // ParseControlEvent |
595 | //--------------------------------- |
596 | void DEVIOWorkerThread::ParseControlEvent(uint32_t* &iptr, uint32_t *iend) |
597 | { |
598 | for(auto pe : current_parsed_events) pe->event_status_bits |= (1<<kSTATUS_CONTROL_EVENT); |
599 | |
600 | iptr = &iptr[(*iptr) + 1]; |
601 | } |
602 | |
603 | //--------------------------------- |
604 | // ParsePhysicsBank |
605 | //--------------------------------- |
606 | void DEVIOWorkerThread::ParsePhysicsBank(uint32_t* &iptr, uint32_t *iend) |
607 | { |
608 | |
609 | for(auto pe : current_parsed_events) pe->event_status_bits |= (1<<kSTATUS_PHYSICS_EVENT); |
610 | |
611 | uint32_t physics_event_len = *iptr++; |
612 | uint32_t *iend_physics_event = &iptr[physics_event_len]; |
613 | iptr++; |
614 | |
615 | // Built Trigger Bank |
616 | uint32_t built_trigger_bank_len = *iptr; |
617 | uint32_t *iend_built_trigger_bank = &iptr[built_trigger_bank_len+1]; |
618 | ParseBuiltTriggerBank(iptr, iend_built_trigger_bank); |
619 | iptr = iend_built_trigger_bank; |
620 | |
621 | // Loop over Data banks |
622 | while( iptr < iend_physics_event ) { |
623 | |
624 | uint32_t data_bank_len = *iptr; |
625 | uint32_t *iend_data_bank = &iptr[data_bank_len+1]; |
626 | |
627 | ParseDataBank(iptr, iend_data_bank); |
628 | |
629 | iptr = iend_data_bank; |
630 | } |
631 | |
632 | iptr = iend_physics_event; |
633 | } |
634 | |
635 | //--------------------------------- |
636 | // ParseBuiltTriggerBank |
637 | //--------------------------------- |
638 | void DEVIOWorkerThread::ParseBuiltTriggerBank(uint32_t* &iptr, uint32_t *iend) |
639 | { |
640 | if(!PARSE_TRIGGER) return; |
641 | |
642 | iptr++; // advance past length word |
643 | uint32_t mask = 0xFF202000; |
644 | if( ((*iptr) & mask) != mask ){ |
645 | stringstream ss; |
646 | ss << "Bad header word in Built Trigger Bank: " << hex << *iptr; |
647 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__647); |
648 | } |
649 | |
650 | uint32_t tag = (*iptr)>>16; // 0xFF2X |
651 | uint32_t Nrocs = (*iptr++) & 0xFF; |
652 | uint32_t Mevents = current_parsed_events.size(); |
653 | |
654 | // sanity check: |
655 | if(Mevents == 0) { |
656 | stringstream ss; |
657 | ss << "DEVIOWorkerThread::ParseBuiltTriggerBank() called with zero events! "<<endl; |
658 | throw JException(ss.str(), __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__658); |
659 | } |
660 | |
661 | |
662 | //-------- Common data (64bit) |
663 | uint32_t common_header64 = *iptr++; |
664 | uint32_t common_header64_len = common_header64 & 0xFFFF; |
665 | uint64_t *iptr64 = (uint64_t*)iptr; |
666 | iptr = &iptr[common_header64_len]; |
667 | |
668 | // First event number |
669 | uint64_t first_event_num = *iptr64++; |
670 | |
671 | // Hi and lo 32bit words in 64bit numbers seem to be |
672 | // switched for events read from ET, but not read from |
673 | // file. Not sure if this is in the swapping routine |
674 | if(event_source->source_type==event_source->kETSource) first_event_num = (first_event_num>>32) | (first_event_num<<32); |
675 | |
676 | // Average timestamps |
677 | uint32_t Ntimestamps = (common_header64_len/2)-1; |
678 | if(tag & 0x2) Ntimestamps--; // subtract 1 for run number/type word if present |
679 | vector<uint64_t> avg_timestamps; |
680 | for(uint32_t i=0; i<Ntimestamps; i++) avg_timestamps.push_back(*iptr64++); |
681 | |
682 | // run number and run type |
683 | uint32_t run_number = 0; |
684 | uint32_t run_type = 0; |
685 | if(tag & 0x02){ |
686 | run_number = (*iptr64) >> 32; |
687 | run_type = (*iptr64) & 0xFFFFFFFF; |
688 | iptr64++; |
689 | } |
690 | |
691 | //-------- Common data (16bit) |
692 | uint32_t common_header16 = *iptr++; |
693 | uint32_t common_header16_len = common_header16 & 0xFFFF; |
694 | uint16_t *iptr16 = (uint16_t*)iptr; |
695 | iptr = &iptr[common_header16_len]; |
696 | |
697 | vector<uint16_t> event_types; |
698 | for(uint32_t i=0; i<Mevents; i++) event_types.push_back(*iptr16++); |
699 | |
700 | //-------- ROC data (32bit) |
701 | for(uint32_t iroc=0; iroc<Nrocs; iroc++){ |
702 | uint32_t common_header32 = *iptr++; |
703 | uint32_t common_header32_len = common_header32 & 0xFFFF; |
704 | uint32_t rocid = common_header32 >> 24; |
705 | |
706 | uint32_t Nwords_per_event = common_header32_len/Mevents; |
707 | for(auto pe : current_parsed_events){ |
708 | |
709 | DCODAROCInfo *codarocinfo = pe->NEW_DCODAROCInfo(); |
710 | codarocinfo->rocid = rocid; |
711 | |
712 | uint64_t ts_low = *iptr++; |
713 | uint64_t ts_high = *iptr++; |
714 | codarocinfo->timestamp = (ts_high<<32) + ts_low; |
715 | codarocinfo->misc.clear(); // could be recycled from previous event |
716 | for(uint32_t i=2; i<Nwords_per_event; i++) codarocinfo->misc.push_back(*iptr++); |
717 | |
718 | if(iptr > iend){ |
719 | throw JException("Bad data format in ParseBuiltTriggerBank!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__719); |
720 | } |
721 | } |
722 | } |
723 | |
724 | //-------- Make DCODAEventInfo objects |
725 | uint64_t ievent = 0; |
726 | for(auto pe : current_parsed_events){ |
727 | |
728 | pe->run_number = run_number; // may be overwritten in JEventSource_EVIOpp::GetEvent() |
729 | |
730 | DCODAEventInfo *codaeventinfo = pe->NEW_DCODAEventInfo(); |
731 | codaeventinfo->run_number = run_number; |
732 | codaeventinfo->run_type = run_type; |
733 | codaeventinfo->event_number = first_event_num + ievent; |
734 | codaeventinfo->event_type = event_types.empty() ? 0:event_types[ievent]; |
735 | codaeventinfo->avg_timestamp = avg_timestamps.empty() ? 0:avg_timestamps[ievent]; |
736 | ievent++; |
737 | } |
738 | } |
739 | |
740 | //--------------------------------- |
741 | // ParseDataBank |
742 | //--------------------------------- |
743 | void DEVIOWorkerThread::ParseDataBank(uint32_t* &iptr, uint32_t *iend) |
744 | { |
745 | // Physics Event's Data Bank header |
746 | iptr++; // advance past data bank length word |
747 | uint32_t rocid = ((*iptr)>>16) & 0xFFF; |
748 | iptr++; |
749 | |
750 | // Loop over Data Block Banks |
751 | while(iptr < iend){ |
752 | |
753 | uint32_t data_block_bank_len = *iptr++; |
754 | uint32_t *iend_data_block_bank = &iptr[data_block_bank_len]; |
755 | uint32_t data_block_bank_header = *iptr++; |
756 | |
757 | // Not sure where this comes from, but it needs to be skipped if present |
758 | while( (*iptr==0xF800FAFA) && (iptr<iend) ) iptr++; |
759 | |
760 | uint32_t det_id = (data_block_bank_header>>16) & 0xFFF; |
761 | switch(det_id){ |
762 | |
763 | case 20: |
764 | ParseCAEN1190(rocid, iptr, iend_data_block_bank); |
765 | break; |
766 | |
767 | case 0x55: |
768 | ParseModuleConfiguration(rocid, iptr, iend_data_block_bank); |
769 | break; |
770 | |
771 | case 0x56: |
772 | ParseEventTagBank(iptr, iend_data_block_bank); |
773 | break; |
774 | |
775 | case 0: |
776 | case 1: |
777 | case 3: |
778 | case 6: // flash 250 module, MMD 2014/2/4 |
779 | case 16: // flash 125 module (CDC), DL 2014/6/19 |
780 | case 26: // F1 TDC module (BCAL), MMD 2014-07-31 |
781 | ParseJLabModuleData(rocid, iptr, iend_data_block_bank); |
782 | break; |
783 | |
784 | // These were implemented in the ROL for sync events |
785 | // as 0xEE02 and 0xEE05. However, that violates the |
786 | // spec. which reserves the top 4 bits as status bits |
787 | // (the first "E" should really be a "1". We just check |
788 | // other 12 bits here. |
789 | case 0xE02: |
790 | ParseTSscalerBank(iptr, iend); |
791 | break; |
792 | case 0xE05: |
793 | Parsef250scalerBank(iptr, iend); |
794 | break; |
795 | case 0xE10: // really wish Sascha would share when he does this stuff! |
796 | Parsef250scalerBank(iptr, iend); |
797 | break; |
798 | |
799 | // When we write out single events in the offline, we also can save some |
800 | // higher level data objects to save disk space and speed up |
801 | // specialized processing (e.g. pi0 calibration) |
802 | case 0xD01: |
803 | ParseDVertexBank(iptr, iend); |
804 | break; |
805 | |
806 | case 5: |
807 | // old ROL Beni used had this but I don't think its |
808 | // been used for years. Run 10390 seems to have |
809 | // this though (???) |
810 | break; |
811 | |
812 | |
813 | default: |
814 | jerr<<"Unknown module type ("<<det_id<<" = " << hex << det_id << dec << " ) encountered" << endl; |
815 | // if(VERBOSE>5){ |
816 | cout << "----- First few words to help with debugging -----" << endl; |
817 | cout.flush(); cerr.flush(); |
818 | DumpBinary(&iptr[-2], iend, 32, &iptr[-1]); |
819 | // } |
820 | } |
821 | |
822 | iptr = iend_data_block_bank; |
823 | } |
824 | |
825 | } |
826 | |
827 | //---------------- |
828 | // ParseTIBank |
829 | //---------------- |
830 | void DEVIOWorkerThread::ParseTIBank(uint32_t rocid, uint32_t* &iptr, uint32_t* iend) |
831 | { |
832 | while(iptr<iend && ((*iptr) & 0xF8000000) != 0x88000000) iptr++; // Skip to JLab block trailer |
833 | iptr++; // advance past JLab block trailer |
834 | while(iptr<iend && *iptr == 0xF8000000) iptr++; // skip filler words after block trailer |
835 | //iptr = iend; |
836 | } |
837 | |
838 | //---------------- |
839 | // ParseCAEN1190 |
840 | //---------------- |
841 | void DEVIOWorkerThread::ParseCAEN1190(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
842 | { |
843 | if(!PARSE_CAEN1290TDC){ iptr = &iptr[(*iptr) + 1]; return; } |
844 | |
845 | /// Parse data from a CAEN 1190 or 1290 module |
846 | /// (See ppg. 72-74 of V1290_REV15.pdf manual) |
847 | |
848 | uint32_t slot = 0; |
849 | uint32_t event_count = 0; |
850 | uint32_t word_count = 0; |
851 | uint32_t trigger_time_tag = 0; |
852 | uint32_t tdc_num = 0; |
853 | uint32_t event_id = 0; |
854 | uint32_t bunch_id = 0; |
855 | |
856 | // We need to accomodate multi-event blocks where |
857 | // events are entangled (i.e. hits from event 1 |
858 | // are mixed in between those of event 2,3,4, |
859 | // etc... With CAEN modules, we only know which |
860 | // event a hit came from by looking at the event_id |
861 | // in the TDC header. This value is only 12 bits |
862 | // and could roll over within an event block. This |
863 | // means we need to keep track of the order we |
864 | // encounter them in so it is maintained in the |
865 | // "events" container. The event_id order is kept |
866 | // in the "event_id_order" vector. |
867 | map<uint32_t, DParsedEvent*> events_by_event_id; |
868 | |
869 | auto pe_iter = current_parsed_events.begin(); |
870 | DParsedEvent *pe = NULL__null; |
871 | |
872 | while(iptr<iend){ |
873 | |
874 | // This word appears to be appended to the data. |
875 | // Probably in the ROL. Ignore it if found. |
876 | if(*iptr == 0xd00dd00d) { |
877 | if(VERBOSE>7) cout << " CAEN skipping 0xd00dd00d word" << endl; |
878 | iptr++; |
879 | continue; |
880 | } |
881 | |
882 | uint32_t type = (*iptr) >> 27; |
883 | uint32_t edge = 0; // 1=trailing, 0=leading |
884 | uint32_t channel = 0; |
885 | uint32_t tdc = 0; |
886 | uint32_t error_flags = 0; |
887 | switch(type){ |
888 | case 0b01000: // Global Header |
889 | slot = (*iptr) & 0x1f; |
890 | event_count = ((*iptr)>>5) & 0xffffff; |
891 | if(VERBOSE>7) cout << " CAEN TDC Global Header (slot=" << slot << " , event count=" << event_count << ")" << endl; |
892 | break; |
893 | case 0b10000: // Global Trailer |
894 | slot = (*iptr) & 0x1f; |
895 | word_count = ((*iptr)>>5) & 0x7ffff; |
896 | if(VERBOSE>7) cout << " CAEN TDC Global Trailer (slot=" << slot << " , word count=" << word_count << ")" << endl; |
897 | slot = event_count = word_count = trigger_time_tag = tdc_num = event_id = bunch_id = 0; |
898 | break; |
899 | case 0b10001: // Global Trigger Time Tag |
900 | trigger_time_tag = ((*iptr)>>5) & 0x7ffffff; |
901 | if(VERBOSE>7) cout << " CAEN TDC Global Trigger Time Tag (tag=" << trigger_time_tag << ")" << endl; |
902 | break; |
903 | case 0b00001: // TDC Header |
904 | tdc_num = ((*iptr)>>24) & 0x03; |
905 | event_id = ((*iptr)>>12) & 0x0fff; |
906 | bunch_id = (*iptr) & 0x0fff; |
907 | if(events_by_event_id.find(event_id) == events_by_event_id.end()){ |
908 | if(pe_iter == current_parsed_events.end()){ |
909 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<909<<" " << "CAEN1290TDC parser sees more events than CODA header! (>" << current_parsed_events.size() << ")" << endl; |
910 | for( auto p : events_by_event_id) cout << "id=" << p.first << endl; |
911 | iptr = iend; |
912 | exit(-1); // should we exit, or try and continue?? |
913 | return; |
914 | } |
915 | pe = *pe_iter++; |
916 | events_by_event_id[event_id] = pe; |
917 | }else{ |
918 | pe = events_by_event_id[event_id]; |
919 | } |
920 | if(VERBOSE>7) cout << " CAEN TDC TDC Header (tdc=" << tdc_num <<" , event id=" << event_id <<" , bunch id=" << bunch_id << ")" << endl; |
921 | break; |
922 | case 0b00000: // TDC Measurement |
923 | edge = ((*iptr)>>26) & 0x01; |
924 | channel = ((*iptr)>>21) & 0x1f; |
925 | tdc = ((*iptr)>>0) & 0x1fffff; |
926 | if(VERBOSE>7) cout << " CAEN TDC TDC Measurement (" << (edge ? "trailing":"leading") << " , channel=" << channel << " , tdc=" << tdc << ")" << endl; |
927 | |
928 | // Create DCAEN1290TDCHit object |
929 | if(pe) pe->NEW_DCAEN1290TDCHit(rocid, slot, channel, 0, edge, tdc_num, event_id, bunch_id, tdc); |
930 | break; |
931 | case 0b00100: // TDC Error |
932 | error_flags = (*iptr) & 0x7fff; |
933 | if(VERBOSE>7) cout << " CAEN TDC TDC Error (err flags=0x" << hex << error_flags << dec << ")" << endl; |
934 | break; |
935 | case 0b00011: // TDC Trailer |
936 | tdc_num = ((*iptr)>>24) & 0x03; |
937 | event_id = ((*iptr)>>12) & 0x0fff; |
938 | word_count = ((*iptr)>>0) & 0x0fff; |
939 | if(VERBOSE>7) cout << " CAEN TDC TDC Trailer (tdc=" << tdc_num <<" , event id=" << event_id <<" , word count=" << word_count << ")" << endl; |
940 | tdc_num = event_id = bunch_id = 0; |
941 | break; |
942 | case 0b11000: // Filler Word |
943 | if(VERBOSE>7) cout << " CAEN TDC Filler Word" << endl; |
944 | break; |
945 | default: |
946 | cout << "Unknown datatype: 0x" << hex << type << " full word: "<< *iptr << dec << endl; |
947 | } |
948 | |
949 | iptr++; |
950 | } |
951 | |
952 | } |
953 | |
954 | //---------------- |
955 | // ParseModuleConfiguration |
956 | //---------------- |
957 | void DEVIOWorkerThread::ParseModuleConfiguration(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
958 | { |
959 | if(!PARSE_CONFIG){ iptr = &iptr[(*iptr) + 1]; return; } |
960 | |
961 | /// Parse a bank of module configuration data. These are configuration values |
962 | /// programmed into the module at the beginning of the run that may be needed |
963 | /// in the offline. For example, the number of samples to sum in a FADC pulse |
964 | /// integral. |
965 | /// |
966 | /// The bank has one or more sections, each describing parameters applicable |
967 | /// to a number of modules as indicated by a 24bit slot mask. |
968 | /// |
969 | /// This bank should appear only once per DAQ event which, if in multi-event |
970 | /// block mode, may have multiple L1 events. The parameters here will apply |
971 | /// to all L1 events in the block. This method will put the config objects |
972 | /// into each event in current_parsed_events. The config objects are duplicated |
973 | /// as needed so each event has its own, indepenent set of config object. |
974 | |
975 | while(iptr < iend){ |
976 | uint32_t slot_mask = (*iptr) & 0xFFFFFF; |
977 | uint32_t Nvals = ((*iptr) >> 24) & 0xFF; |
978 | iptr++; |
979 | |
980 | // Events will be created in the first event (i.e. using its pool) |
981 | // but pointers are saved so we can use them to construct identical |
982 | // objects in all other event later |
983 | DParsedEvent *pe = current_parsed_events.front(); |
984 | |
985 | Df250Config *f250config = NULL__null; |
986 | Df125Config *f125config = NULL__null; |
987 | DF1TDCConfig *f1tdcconfig = NULL__null; |
988 | DCAEN1290TDCConfig *caen1290tdcconfig = NULL__null; |
989 | |
990 | // Loop over all parameters in this section |
991 | for(uint32_t i=0; i< Nvals; i++){ |
992 | if( iptr >= iend){ |
993 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<993<<" " << "DAQ Configuration bank corrupt! slot_mask=0x" << hex << slot_mask << dec << " Nvals="<< Nvals << endl; |
994 | exit(-1); |
995 | } |
996 | |
997 | daq_param_type ptype = (daq_param_type)((*iptr)>>16); |
998 | uint16_t val = (*iptr) & 0xFFFF; |
999 | |
1000 | if(VERBOSE>6) cout << " DAQ parameter of type: 0x" << hex << ptype << dec << " found with value: " << val << endl; |
1001 | |
1002 | // Create config object of correct type if needed and copy |
1003 | // parameter value into it. |
1004 | switch(ptype>>8){ |
1005 | |
1006 | // f250 |
1007 | case 0x05: |
1008 | if( !f250config ) f250config = pe->NEW_Df250Config(rocid, slot_mask); |
1009 | switch(ptype){ |
1010 | case kPARAM250_NSA : f250config->NSA = val; break; |
1011 | case kPARAM250_NSB : f250config->NSB = val; break; |
1012 | case kPARAM250_NSA_NSB : f250config->NSA_NSB = val; break; |
1013 | case kPARAM250_NPED : f250config->NPED = val; break; |
1014 | default: _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1014<<" " << "UNKNOWN DAQ Config Parameter type: 0x" << hex << ptype << dec << endl; |
1015 | } |
1016 | break; |
1017 | |
1018 | // f125 |
1019 | case 0x0F: |
1020 | if( !f125config ) f125config = pe->NEW_Df125Config(rocid, slot_mask); |
1021 | switch(ptype){ |
1022 | case kPARAM125_NSA : f125config->NSA = val; break; |
1023 | case kPARAM125_NSB : f125config->NSB = val; break; |
1024 | case kPARAM125_NSA_NSB : f125config->NSA_NSB = val; break; |
1025 | case kPARAM125_NPED : f125config->NPED = val; break; |
1026 | case kPARAM125_WINWIDTH : f125config->WINWIDTH = val; break; |
1027 | case kPARAM125_PL : f125config->PL = val; break; |
1028 | case kPARAM125_NW : f125config->NW = val; break; |
1029 | case kPARAM125_NPK : f125config->NPK = val; break; |
1030 | case kPARAM125_P1 : f125config->P1 = val; break; |
1031 | case kPARAM125_P2 : f125config->P2 = val; break; |
1032 | case kPARAM125_PG : f125config->PG = val; break; |
1033 | case kPARAM125_IE : f125config->IE = val; break; |
1034 | case kPARAM125_H : f125config->H = val; break; |
1035 | case kPARAM125_TH : f125config->TH = val; break; |
1036 | case kPARAM125_TL : f125config->TL = val; break; |
1037 | case kPARAM125_IBIT : f125config->IBIT = val; break; |
1038 | case kPARAM125_ABIT : f125config->ABIT = val; break; |
1039 | case kPARAM125_PBIT : f125config->PBIT = val; break; |
1040 | default: _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1040<<" " << "UNKNOWN DAQ Config Parameter type: 0x" << hex << ptype << dec << endl; |
1041 | } |
1042 | break; |
1043 | |
1044 | // F1TDC |
1045 | case 0x06: |
1046 | if( !f1tdcconfig ) f1tdcconfig = pe->NEW_DF1TDCConfig(rocid, slot_mask); |
1047 | switch(ptype){ |
1048 | case kPARAMF1_REFCNT : f1tdcconfig->REFCNT = val; break; |
1049 | case kPARAMF1_TRIGWIN : f1tdcconfig->TRIGWIN = val; break; |
1050 | case kPARAMF1_TRIGLAT : f1tdcconfig->TRIGLAT = val; break; |
1051 | case kPARAMF1_HSDIV : f1tdcconfig->HSDIV = val; break; |
1052 | case kPARAMF1_BINSIZE : f1tdcconfig->BINSIZE = val; break; |
1053 | case kPARAMF1_REFCLKDIV : f1tdcconfig->REFCLKDIV = 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 | // caen1290 |
1059 | case 0x10: |
1060 | if( !caen1290tdcconfig ) caen1290tdcconfig = pe->NEW_DCAEN1290TDCConfig(rocid, slot_mask); |
1061 | switch(ptype){ |
1062 | case kPARAMCAEN1290_WINWIDTH : caen1290tdcconfig->WINWIDTH = val; break; |
1063 | case kPARAMCAEN1290_WINOFFSET : caen1290tdcconfig->WINOFFSET = val; break; |
1064 | default: _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1064<<" " << "UNKNOWN DAQ Config Parameter type: 0x" << hex << ptype << dec << endl; |
1065 | } |
1066 | break; |
1067 | |
1068 | default: |
1069 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1069<<" " << "Unknown module type: 0x" << hex << (ptype>>8) << endl; |
1070 | exit(-1); |
1071 | } |
1072 | |
1073 | |
1074 | iptr++; |
1075 | } |
1076 | |
1077 | // Make copies of all config objects for all other events |
1078 | for(auto tpe : current_parsed_events){ |
1079 | |
1080 | if(tpe == pe) continue; // first event already owns objects so skip it |
1081 | |
1082 | if(f250config ) tpe->NEW_Df250Config(f250config); |
1083 | if(f125config ) tpe->NEW_Df125Config(f125config); |
1084 | if(f1tdcconfig ) tpe->NEW_DF1TDCConfig(f1tdcconfig); |
1085 | if(caen1290tdcconfig) tpe->NEW_DCAEN1290TDCConfig(caen1290tdcconfig); |
1086 | } |
1087 | } |
1088 | } |
1089 | |
1090 | //---------------- |
1091 | // ParseJLabModuleData |
1092 | //---------------- |
1093 | void DEVIOWorkerThread::ParseJLabModuleData(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1094 | { |
1095 | |
1096 | while(iptr<iend){ |
1097 | |
1098 | // Get module type from next word (bits 18-21) |
1099 | uint32_t mod_id = ((*iptr) >> 18) & 0x000F; |
1100 | MODULE_TYPE type = (MODULE_TYPE)mod_id; |
1101 | //cout << " rocid=" << rocid << " Encountered module type: " << type << " (=" << DModuleType::GetModule(type).GetName() << ") word=" << hex << (*iptr) << dec << endl; |
1102 | |
1103 | switch(type){ |
1104 | case DModuleType::FADC250: |
1105 | Parsef250Bank(rocid, iptr, iend); |
1106 | break; |
1107 | |
1108 | case DModuleType::FADC125: |
1109 | Parsef125Bank(rocid, iptr, iend); |
1110 | break; |
1111 | |
1112 | case DModuleType::F1TDC32: |
1113 | ParseF1TDCBank(rocid, iptr, iend); |
1114 | break; |
1115 | |
1116 | case DModuleType::F1TDC48: |
1117 | ParseF1TDCBank(rocid, iptr, iend); |
1118 | break; |
1119 | |
1120 | case DModuleType::TID: |
1121 | ParseTIBank(rocid, iptr, iend); |
1122 | /* |
1123 | // Ignore this data and skip over it |
1124 | while(iptr<iend && ((*iptr) & 0xF8000000) != 0x88000000) iptr++; // Skip to JLab block trailer |
1125 | iptr++; // advance past JLab block trailer |
1126 | while(iptr<iend && *iptr == 0xF8000000) iptr++; // skip filler words after block trailer |
1127 | break; |
1128 | */ |
1129 | break; |
1130 | |
1131 | case DModuleType::UNKNOWN: |
1132 | default: |
1133 | jerr<<"Unknown module type ("<<mod_id<<") iptr=0x" << hex << iptr << dec << endl; |
1134 | |
1135 | while(iptr<iend && ((*iptr) & 0xF8000000) != 0x88000000) iptr++; // Skip to JLab block trailer |
1136 | iptr++; // advance past JLab block trailer |
1137 | while(iptr<iend && *iptr == 0xF8000000) iptr++; // skip filler words after block trailer |
1138 | break; |
1139 | } |
1140 | } |
1141 | |
1142 | } |
1143 | |
1144 | //---------------- |
1145 | // Parsef250Bank |
1146 | //---------------- |
1147 | void DEVIOWorkerThread::Parsef250Bank(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1148 | { |
1149 | if(!PARSE_F250){ iptr = &iptr[(*iptr) + 1]; return; } |
1150 | |
1151 | auto pe_iter = current_parsed_events.begin(); |
1152 | DParsedEvent *pe = NULL__null; |
1153 | |
1154 | uint32_t slot = 0; |
1155 | uint32_t itrigger = -1; |
1156 | |
1157 | // Loop over data words |
1158 | for(; iptr<iend; iptr++){ |
1159 | |
1160 | // Skip all non-data-type-defining words at this |
1161 | // level. When we do encounter one, the appropriate |
1162 | // case block below should handle parsing all of |
1163 | // the data continuation words and advance the iptr. |
1164 | if(((*iptr>>31) & 0x1) == 0)continue; |
1165 | |
1166 | uint32_t data_type = (*iptr>>27) & 0x0F; |
1167 | switch(data_type){ |
1168 | case 0: // Block Header |
1169 | slot = (*iptr>>22) & 0x1F; |
1170 | if(VERBOSE>7) cout << " FADC250 Block Header: slot="<<slot<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1171 | break; |
1172 | case 1: // Block Trailer |
1173 | pe_iter = current_parsed_events.begin(); |
1174 | pe = NULL__null; |
1175 | if(VERBOSE>7) cout << " FADC250 Block Trailer"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1176 | break; |
1177 | case 2: // Event Header |
1178 | itrigger = (*iptr>>0) & 0x3FFFFF; |
1179 | pe = *pe_iter++; |
1180 | if(VERBOSE>7) cout << " FADC250 Event Header: itrigger="<<itrigger<<", rocid="<<rocid<<", slot="<<slot<<")" <<" ("<<hex<<*iptr<<dec<<")" <<endl; |
1181 | break; |
1182 | case 3: // Trigger Time |
1183 | { |
1184 | uint64_t t = ((*iptr)&0xFFFFFF)<<0; |
1185 | iptr++; |
1186 | if(((*iptr>>31) & 0x1) == 0){ |
1187 | t += ((*iptr)&0xFFFFFF)<<24; // from word on the street: second trigger time word is optional!!?? |
1188 | if(VERBOSE>7) cout << " Trigger time high word="<<(((*iptr)&0xFFFFFF))<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1189 | }else{ |
1190 | iptr--; |
1191 | } |
1192 | if(VERBOSE>7) cout << " FADC250 Trigger Time: t="<<t<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1193 | if(pe) pe->NEW_Df250TriggerTime(rocid, slot, itrigger, t); |
1194 | } |
1195 | break; |
1196 | case 4: // Window Raw Data |
1197 | // iptr passed by reference and so will be updated automatically |
1198 | if(VERBOSE>7) cout << " FADC250 Window Raw Data"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1199 | if(pe) MakeDf250WindowRawData(pe, rocid, slot, itrigger, iptr); |
1200 | break; |
1201 | case 5: // Window Sum |
1202 | { |
1203 | uint32_t channel = (*iptr>>23) & 0x0F; |
1204 | uint32_t sum = (*iptr>>0) & 0x3FFFFF; |
1205 | uint32_t overflow = (*iptr>>22) & 0x1; |
1206 | if(VERBOSE>7) cout << " FADC250 Window Sum"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1207 | if(pe) pe->NEW_Df250WindowSum(rocid, slot, channel, itrigger, sum, overflow); |
1208 | } |
1209 | break; |
1210 | case 6: // Pulse Raw Data |
1211 | // MakeDf250PulseRawData(objs, rocid, slot, itrigger, iptr); |
1212 | if(VERBOSE>7) cout << " FADC250 Pulse Raw Data"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1213 | break; |
1214 | case 7: // Pulse Integral |
1215 | { |
1216 | uint32_t channel = (*iptr>>23) & 0x0F; |
1217 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1218 | uint32_t quality_factor = (*iptr>>19) & 0x03; |
1219 | uint32_t sum = (*iptr>>0) & 0x7FFFF; |
1220 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1221 | uint32_t nsamples_pedestal = 1; // The firmware returns an already divided pedestal |
1222 | uint32_t pedestal = 0; // This will be replaced by the one from Df250PulsePedestal in GetObjects |
1223 | if(VERBOSE>7) cout << " FADC250 Pulse Integral: chan="<<channel<<" pulse_number="<<pulse_number<<" sum="<<sum<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1224 | if(pe) pe->NEW_Df250PulseIntegral(rocid, slot, channel, itrigger, pulse_number, quality_factor, sum, pedestal, nsamples_integral, nsamples_pedestal); |
1225 | } |
1226 | break; |
1227 | case 8: // Pulse Time |
1228 | { |
1229 | uint32_t channel = (*iptr>>23) & 0x0F; |
1230 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1231 | uint32_t quality_factor = (*iptr>>19) & 0x03; |
1232 | uint32_t pulse_time = (*iptr>>0) & 0x7FFFF; |
1233 | if(VERBOSE>7) cout << " FADC250 Pulse Time: chan="<<channel<<" pulse_number="<<pulse_number<<" pulse_time="<<pulse_time<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1234 | if(pe) pe->NEW_Df250PulseTime(rocid, slot, channel, itrigger, pulse_number, quality_factor, pulse_time); |
1235 | } |
1236 | break; |
1237 | case 9: // Pulse Data (firmware instroduce in Fall 2016) |
1238 | { |
1239 | // from word 1 |
1240 | uint32_t event_number_within_block = (*iptr>>19) & 0xFF; |
1241 | uint32_t channel = (*iptr>>15) & 0x0F; |
1242 | bool QF_pedestal = (*iptr>>14) & 0x01; |
1243 | uint32_t pedestal = (*iptr>>0 ) & 0x3FFF; |
1244 | |
1245 | // event_number_within_block=0 indicates error |
1246 | if(event_number_within_block==0){ |
1247 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1247<<" "<<"event_number_within_block==0. This indicates a bug in firmware." << endl; |
1248 | exit(-1); |
1249 | } |
1250 | |
1251 | // Event headers may be supressed so determine event from hit data |
1252 | if( (event_number_within_block > current_parsed_events.size()) ) throw JException("Bad f250 event number", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1252); |
1253 | pe_iter = current_parsed_events.begin(); |
1254 | advance( pe_iter, event_number_within_block-1 ); |
1255 | pe = *pe_iter++; |
1256 | |
1257 | itrigger = event_number_within_block; // is this right? |
1258 | uint32_t pulse_number = 0; |
1259 | |
1260 | while( (*++iptr>>31) == 0 ){ |
1261 | |
1262 | if( (*iptr>>30) != 0x01) throw JException("Bad f250 Pulse Data!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1262); |
1263 | |
1264 | // from word 2 |
1265 | uint32_t integral = (*iptr>>12) & 0x3FFFF; |
1266 | bool QF_NSA_beyond_PTW = (*iptr>>11) & 0x01; |
1267 | bool QF_overflow = (*iptr>>10) & 0x01; |
1268 | bool QF_underflow = (*iptr>>9 ) & 0x01; |
1269 | uint32_t nsamples_over_threshold = (*iptr>>0 ) & 0x1FF; |
1270 | |
1271 | iptr++; |
1272 | if( (*iptr>>30) != 0x00) throw JException("Bad f250 Pulse Data!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1272); |
1273 | |
1274 | // from word 3 |
1275 | uint32_t course_time = (*iptr>>21) & 0x1FF;//< 4 ns/count |
1276 | uint32_t fine_time = (*iptr>>15) & 0x3F;//< 0.0625 ns/count |
1277 | uint32_t pulse_peak = (*iptr>>3 ) & 0xFFF; |
1278 | bool QF_vpeak_beyond_NSA = (*iptr>>2 ) & 0x01; |
1279 | bool QF_vpeak_not_found = (*iptr>>1 ) & 0x01; |
1280 | bool QF_bad_pedestal = (*iptr>>0 ) & 0x01; |
1281 | |
1282 | if( pe ) { |
1283 | pe->NEW_Df250PulseData(rocid, slot, channel, itrigger |
1284 | , event_number_within_block |
1285 | , QF_pedestal |
1286 | , pedestal |
1287 | , integral |
1288 | , QF_NSA_beyond_PTW |
1289 | , QF_overflow |
1290 | , QF_underflow |
1291 | , nsamples_over_threshold |
1292 | , course_time |
1293 | , fine_time |
1294 | , pulse_peak |
1295 | , QF_vpeak_beyond_NSA |
1296 | , QF_vpeak_not_found |
1297 | , QF_bad_pedestal |
1298 | , pulse_number++); |
1299 | } |
1300 | } |
1301 | iptr--; // backup so when outer loop advances, it points to next data defining word |
1302 | |
1303 | } |
1304 | break; |
1305 | case 10: // Pulse Pedestal |
1306 | { |
1307 | uint32_t channel = (*iptr>>23) & 0x0F; |
1308 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1309 | uint32_t pedestal = (*iptr>>12) & 0x1FF; |
1310 | uint32_t pulse_peak = (*iptr>>0) & 0xFFF; |
1311 | if(VERBOSE>7) cout << " FADC250 Pulse Pedestal chan="<<channel<<" pulse_number="<<pulse_number<<" pedestal="<<pedestal<<" pulse_peak="<<pulse_peak<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1312 | if(pe) pe->NEW_Df250PulsePedestal(rocid, slot, channel, itrigger, pulse_number, pedestal, pulse_peak); |
1313 | } |
1314 | break; |
1315 | case 13: // Event Trailer |
1316 | // This is marked "suppressed for normal readout – debug mode only" in the |
1317 | // current manual (v2). It does not contain any data so the most we could do here |
1318 | // is return early. I'm hesitant to do that though since it would mean |
1319 | // different behavior for debug mode data as regular data. |
1320 | case 14: // Data not valid (empty module) |
1321 | case 15: // Filler (non-data) word |
1322 | if(VERBOSE>7) cout << " FADC250 Event Trailer, Data not Valid, or Filler word ("<<data_type<<")"<<" ("<<hex<<*iptr<<dec<<")"<<endl; |
1323 | break; |
1324 | } |
1325 | } |
1326 | |
1327 | // Chop off filler words |
1328 | for(; iptr<iend; iptr++){ |
1329 | if(((*iptr)&0xf8000000) != 0xf8000000) break; |
1330 | } |
1331 | } |
1332 | |
1333 | //---------------- |
1334 | // MakeDf250WindowRawData |
1335 | //---------------- |
1336 | void DEVIOWorkerThread::MakeDf250WindowRawData(DParsedEvent *pe, uint32_t rocid, uint32_t slot, uint32_t itrigger, uint32_t* &iptr) |
1337 | { |
1338 | uint32_t channel = (*iptr>>23) & 0x0F; |
1339 | uint32_t window_width = (*iptr>>0) & 0x0FFF; |
1340 | |
1341 | Df250WindowRawData *wrd = pe->NEW_Df250WindowRawData(rocid, slot, channel, itrigger); |
1342 | |
1343 | for(uint32_t isample=0; isample<window_width; isample +=2){ |
1344 | |
1345 | // Advance to next word |
1346 | iptr++; |
1347 | |
1348 | // Make sure this is a data continuation word, if not, stop here |
1349 | if(((*iptr>>31) & 0x1) != 0x0){ |
1350 | iptr--; // calling method expects us to point to last word in block |
1351 | break; |
1352 | } |
1353 | |
1354 | bool invalid_1 = (*iptr>>29) & 0x1; |
1355 | bool invalid_2 = (*iptr>>13) & 0x1; |
1356 | uint16_t sample_1 = 0; |
1357 | uint16_t sample_2 = 0; |
1358 | if(!invalid_1)sample_1 = (*iptr>>16) & 0x1FFF; |
1359 | if(!invalid_2)sample_2 = (*iptr>>0) & 0x1FFF; |
1360 | |
1361 | // Sample 1 |
1362 | wrd->samples.push_back(sample_1); |
1363 | wrd->invalid_samples |= invalid_1; |
1364 | wrd->overflow |= (sample_1>>12) & 0x1; |
1365 | |
1366 | if(((isample+2) == window_width) && invalid_2)break; // skip last sample if flagged as invalid |
1367 | |
1368 | // Sample 2 |
1369 | wrd->samples.push_back(sample_2); |
1370 | wrd->invalid_samples |= invalid_2; |
1371 | wrd->overflow |= (sample_2>>12) & 0x1; |
1372 | } |
1373 | } |
1374 | |
1375 | //---------------- |
1376 | // Parsef125Bank |
1377 | //---------------- |
1378 | void DEVIOWorkerThread::Parsef125Bank(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1379 | { |
1380 | if(!PARSE_F125){ iptr = &iptr[(*iptr) + 1]; return; } |
1381 | |
1382 | auto pe_iter = current_parsed_events.begin(); |
1383 | DParsedEvent *pe = NULL__null; |
1384 | |
1385 | uint32_t slot=0; |
1386 | uint32_t itrigger = -1; |
1387 | uint32_t last_itrigger = -2; |
1388 | uint32_t last_pulse_time_channel=0; |
1389 | uint32_t last_slot = -1; |
1390 | uint32_t last_channel = -1; |
1391 | |
1392 | // Loop over data words |
1393 | for(; iptr<iend; iptr++){ |
1394 | |
1395 | // Skip all non-data-type-defining words at this |
1396 | // level. When we do encounter one, the appropriate |
1397 | // case block below should handle parsing all of |
1398 | // the data continuation words and advance the iptr. |
1399 | if(((*iptr>>31) & 0x1) == 0)continue; |
1400 | |
1401 | uint32_t data_type = (*iptr>>27) & 0x0F; |
1402 | switch(data_type){ |
1403 | case 0: // Block Header |
1404 | slot = (*iptr>>22) & 0x1F; |
1405 | if(VERBOSE>7) cout << " FADC125 Block Header: slot="<<slot<<endl; |
1406 | break; |
1407 | case 1: // Block Trailer |
1408 | pe_iter = current_parsed_events.begin(); |
1409 | pe = NULL__null; |
1410 | break; |
1411 | case 2: // Event Header |
1412 | //slot_event_header = (*iptr>>22) & 0x1F; |
1413 | itrigger = (*iptr>>0) & 0x3FFFFFF; |
1414 | pe = *pe_iter++; |
1415 | if(VERBOSE>7) cout << " FADC125 Event Header: itrigger="<<itrigger<<" last_itrigger="<<last_itrigger<<", rocid="<<rocid<<", slot="<<slot <<endl; |
1416 | break; |
1417 | case 3: // Trigger Time |
1418 | { |
1419 | uint64_t t = ((*iptr)&0xFFFFFF)<<0; |
1420 | iptr++; |
1421 | if(((*iptr>>31) & 0x1) == 0){ |
1422 | t += ((*iptr)&0xFFFFFF)<<24; // from word on the street: second trigger time word is optional!!?? |
1423 | }else{ |
1424 | iptr--; |
1425 | } |
1426 | if(VERBOSE>7) cout << " FADC125 Trigger Time (t="<<t<<")"<<endl; |
1427 | if(pe) pe->NEW_Df125TriggerTime(rocid, slot, itrigger, t); |
1428 | } |
1429 | break; |
1430 | case 4: // Window Raw Data |
1431 | // iptr passed by reference and so will be updated automatically |
1432 | if(VERBOSE>7) cout << " FADC125 Window Raw Data"<<endl; |
1433 | if(pe) MakeDf125WindowRawData(pe, rocid, slot, itrigger, iptr); |
1434 | break; |
1435 | |
1436 | case 5: // CDC pulse data (new) (GlueX-doc-2274-v8) |
1437 | { |
1438 | // Word 1: |
1439 | uint32_t word1 = *iptr; |
1440 | uint32_t channel = (*iptr>>20) & 0x7F; |
1441 | uint32_t pulse_number = (*iptr>>15) & 0x1F; |
1442 | uint32_t pulse_time = (*iptr>>4 ) & 0x7FF; |
1443 | uint32_t quality_factor = (*iptr>>3 ) & 0x1; //time QF bit |
1444 | uint32_t overflow_count = (*iptr>>0 ) & 0x7; |
1445 | if(VERBOSE>7){ |
1446 | cout << " FADC125 CDC Pulse Data word1: " << hex << (*iptr) << dec << endl; |
1447 | cout << " FADC125 CDC Pulse Data (chan="<<channel<<" pulse="<<pulse_number<<" time="<<pulse_time<<" QF="<<quality_factor<<" OC="<<overflow_count<<")"<<endl; |
1448 | } |
1449 | |
1450 | // Word 2: |
1451 | ++iptr; |
1452 | if(iptr>=iend){ |
1453 | jerr << " Truncated f125 CDC hit (block ends before continuation word!)" << endl; |
1454 | continue; |
1455 | } |
1456 | if( ((*iptr>>31) & 0x1) != 0 ){ |
1457 | jerr << " Truncated f125 CDC hit (missing continuation word!)" << endl; |
1458 | continue; |
1459 | } |
1460 | uint32_t word2 = *iptr; |
1461 | uint32_t pedestal = (*iptr>>23) & 0xFF; |
1462 | uint32_t sum = (*iptr>>9 ) & 0x3FFF; |
1463 | uint32_t pulse_peak = (*iptr>>0 ) & 0x1FF; |
1464 | if(VERBOSE>7){ |
1465 | cout << " FADC125 CDC Pulse Data word2: " << hex << (*iptr) << dec << endl; |
1466 | cout << " FADC125 CDC Pulse Data (pedestal="<<pedestal<<" sum="<<sum<<" peak="<<pulse_peak<<")"<<endl; |
1467 | } |
1468 | |
1469 | // Create hit objects |
1470 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1471 | uint32_t nsamples_pedestal = 1; // The firmware pedestal divided by 2^PBIT where PBIT is a config. parameter |
1472 | |
1473 | if( pe ) { |
1474 | pe->NEW_Df125CDCPulse(rocid, slot, channel, itrigger |
1475 | , pulse_number // NPK |
1476 | , pulse_time // le_time |
1477 | , quality_factor // time_quality_bit |
1478 | , overflow_count // overflow_count |
1479 | , pedestal // pedestal |
1480 | , sum // integral |
1481 | , pulse_peak // first_max_amp |
1482 | , word1 // word1 |
1483 | , word2 // word2 |
1484 | , nsamples_pedestal // nsamples_pedestal |
1485 | , nsamples_integral // nsamples_integral |
1486 | , false); // emulated |
1487 | } |
1488 | } |
1489 | break; |
1490 | |
1491 | case 6: // FDC pulse data-integral (new) (GlueX-doc-2274-v8) |
1492 | { |
1493 | // Word 1: |
1494 | uint32_t word1 = *iptr; |
1495 | uint32_t channel = (*iptr>>20) & 0x7F; |
1496 | uint32_t pulse_number = (*iptr>>15) & 0x1F; |
1497 | uint32_t pulse_time = (*iptr>>4 ) & 0x7FF; |
1498 | uint32_t quality_factor = (*iptr>>3 ) & 0x1; //time QF bit |
1499 | uint32_t overflow_count = (*iptr>>0 ) & 0x7; |
1500 | if(VERBOSE>7){ |
1501 | cout << " FADC125 FDC Pulse Data(integral) word1: " << hex << (*iptr) << dec << endl; |
1502 | cout << " FADC125 FDC Pulse Data (chan="<<channel<<" pulse="<<pulse_number<<" time="<<pulse_time<<" QF="<<quality_factor<<" OC="<<overflow_count<<")"<<endl; |
1503 | } |
1504 | |
1505 | // Word 2: |
1506 | ++iptr; |
1507 | if(iptr>=iend){ |
1508 | jerr << " Truncated f125 FDC hit (block ends before continuation word!)" << endl; |
1509 | continue; |
1510 | } |
1511 | if( ((*iptr>>31) & 0x1) != 0 ){ |
1512 | jerr << " Truncated f125 FDC hit (missing continuation word!)" << endl; |
1513 | continue; |
1514 | } |
1515 | uint32_t word2 = *iptr; |
1516 | uint32_t pulse_peak = 0; |
1517 | uint32_t sum = (*iptr>>19) & 0xFFF; |
1518 | uint32_t peak_time = (*iptr>>11) & 0xFF; |
1519 | uint32_t pedestal = (*iptr>>0 ) & 0x7FF; |
1520 | if(VERBOSE>7){ |
1521 | cout << " FADC125 FDC Pulse Data(integral) word2: " << hex << (*iptr) << dec << endl; |
1522 | cout << " FADC125 FDC Pulse Data (integral="<<sum<<" time="<<peak_time<<" pedestal="<<pedestal<<")"<<endl; |
1523 | } |
1524 | |
1525 | // Create hit objects |
1526 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1527 | uint32_t nsamples_pedestal = 1; // The firmware pedestal divided by 2^PBIT where PBIT is a config. parameter |
1528 | |
1529 | if( pe ) { |
1530 | pe->NEW_Df125FDCPulse(rocid, slot, channel, itrigger |
1531 | , pulse_number // NPK |
1532 | , pulse_time // le_time |
1533 | , quality_factor // time_quality_bit |
1534 | , overflow_count // overflow_count |
1535 | , pedestal // pedestal |
1536 | , sum // integral |
1537 | , pulse_peak // peak_amp |
1538 | , peak_time // peak_time |
1539 | , word1 // word1 |
1540 | , word2 // word2 |
1541 | , nsamples_pedestal // nsamples_pedestal |
1542 | , nsamples_integral // nsamples_integral |
1543 | , false); // emulated |
1544 | } |
1545 | } |
1546 | break; |
1547 | |
1548 | case 7: // Pulse Integral |
1549 | { |
1550 | if(VERBOSE>7) cout << " FADC125 Pulse Integral"<<endl; |
1551 | uint32_t channel = (*iptr>>20) & 0x7F; |
1552 | uint32_t sum = (*iptr>>0) & 0xFFFFF; |
1553 | uint32_t quality_factor = 0; |
1554 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1555 | uint32_t nsamples_pedestal = 1; // The firmware returns an already divided pedestal |
1556 | uint32_t pedestal = 0; // This will be replaced by the one from Df250PulsePedestal in GetObjects |
1557 | uint32_t pulse_number = 0; |
1558 | if (last_slot == slot && last_channel == channel) pulse_number = 1; |
1559 | last_slot = slot; |
1560 | last_channel = channel; |
1561 | if( pe ) pe->NEW_Df125PulseIntegral(rocid, slot, channel, itrigger, pulse_number, quality_factor, sum, pedestal, nsamples_integral, nsamples_pedestal); |
1562 | } |
1563 | break; |
1564 | case 8: // Pulse Time |
1565 | { |
1566 | if(VERBOSE>7) cout << " FADC125 Pulse Time"<<endl; |
1567 | uint32_t channel = (*iptr>>20) & 0x7F; |
1568 | uint32_t pulse_number = (*iptr>>18) & 0x03; |
1569 | uint32_t pulse_time = (*iptr>>0) & 0xFFFF; |
1570 | uint32_t quality_factor = 0; |
1571 | if( pe ) pe->NEW_Df125PulseTime(rocid, slot, channel, itrigger, pulse_number, quality_factor, pulse_time); |
1572 | last_pulse_time_channel = channel; |
1573 | } |
1574 | break; |
1575 | |
1576 | case 9: // FDC pulse data-peak (new) (GlueX-doc-2274-v8) |
1577 | { |
1578 | // Word 1: |
1579 | uint32_t word1 = *iptr; |
1580 | uint32_t channel = (*iptr>>20) & 0x7F; |
1581 | uint32_t pulse_number = (*iptr>>15) & 0x1F; |
1582 | uint32_t pulse_time = (*iptr>>4 ) & 0x7FF; |
1583 | uint32_t quality_factor = (*iptr>>3 ) & 0x1; //time QF bit |
1584 | uint32_t overflow_count = (*iptr>>0 ) & 0x7; |
1585 | if(VERBOSE>7){ |
1586 | cout << " FADC125 FDC Pulse Data(peak) word1: " << hex << (*iptr) << dec << endl; |
1587 | cout << " FADC125 FDC Pulse Data (chan="<<channel<<" pulse="<<pulse_number<<" time="<<pulse_time<<" QF="<<quality_factor<<" OC="<<overflow_count<<")"<<endl; |
1588 | } |
1589 | |
1590 | // Word 2: |
1591 | ++iptr; |
1592 | if(iptr>=iend){ |
1593 | jerr << " Truncated f125 FDC hit (block ends before continuation word!)" << endl; |
1594 | continue; |
1595 | } |
1596 | if( ((*iptr>>31) & 0x1) != 0 ){ |
1597 | jerr << " Truncated f125 FDC hit (missing continuation word!)" << endl; |
1598 | continue; |
1599 | } |
1600 | uint32_t word2 = *iptr; |
1601 | uint32_t pulse_peak = (*iptr>>19) & 0xFFF; |
1602 | uint32_t sum = 0; |
1603 | uint32_t peak_time = (*iptr>>11) & 0xFF; |
1604 | uint32_t pedestal = (*iptr>>0 ) & 0x7FF; |
1605 | if(VERBOSE>7){ |
1606 | cout << " FADC125 FDC Pulse Data(peak) word2: " << hex << (*iptr) << dec << endl; |
1607 | cout << " FADC125 FDC Pulse Data (integral="<<sum<<" time="<<peak_time<<" pedestal="<<pedestal<<")"<<endl; |
1608 | } |
1609 | |
1610 | // Create hit objects |
1611 | uint32_t nsamples_integral = 0; // must be overwritten later in GetObjects with value from Df125Config value |
1612 | uint32_t nsamples_pedestal = 1; // The firmware pedestal divided by 2^PBIT where PBIT is a config. parameter |
1613 | |
1614 | if( pe ) { |
1615 | pe->NEW_Df125FDCPulse(rocid, slot, channel, itrigger |
1616 | , pulse_number // NPK |
1617 | , pulse_time // le_time |
1618 | , quality_factor // time_quality_bit |
1619 | , overflow_count // overflow_count |
1620 | , pedestal // pedestal |
1621 | , sum // integral |
1622 | , pulse_peak // peak_amp |
1623 | , peak_time // peak_time |
1624 | , word1 // word1 |
1625 | , word2 // word2 |
1626 | , nsamples_pedestal // nsamples_pedestal |
1627 | , nsamples_integral // nsamples_integral |
1628 | , false); // emulated |
1629 | } |
1630 | } |
1631 | break; |
1632 | |
1633 | case 10: // Pulse Pedestal (consistent with Beni's hand-edited version of Cody's document) |
1634 | { |
1635 | if(VERBOSE>7) cout << " FADC125 Pulse Pedestal"<<endl; |
1636 | //channel = (*iptr>>20) & 0x7F; |
1637 | 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") |
1638 | uint32_t pulse_number = (*iptr>>21) & 0x03; |
1639 | uint32_t pedestal = (*iptr>>12) & 0x1FF; |
1640 | uint32_t pulse_peak = (*iptr>>0) & 0xFFF; |
1641 | uint32_t nsamples_pedestal = 1; // The firmware returns an already divided pedestal |
1642 | if( pe ) pe->NEW_Df125PulsePedestal(rocid, slot, channel, itrigger, pulse_number, pedestal, pulse_peak, nsamples_pedestal); |
1643 | } |
1644 | break; |
1645 | |
1646 | case 13: // Event Trailer |
1647 | case 14: // Data not valid (empty module) |
1648 | case 15: // Filler (non-data) word |
1649 | if(VERBOSE>7) cout << " FADC125 ignored data type: " << data_type <<endl; |
1650 | break; |
1651 | } |
1652 | } |
1653 | |
1654 | // Chop off filler words |
1655 | for(; iptr<iend; iptr++){ |
1656 | if(((*iptr)&0xf8000000) != 0xf8000000) break; |
1657 | } |
1658 | } |
1659 | |
1660 | //---------------- |
1661 | // MakeDf125WindowRawData |
1662 | //---------------- |
1663 | void DEVIOWorkerThread::MakeDf125WindowRawData(DParsedEvent *pe, uint32_t rocid, uint32_t slot, uint32_t itrigger, uint32_t* &iptr) |
1664 | { |
1665 | uint32_t channel = (*iptr>>20) & 0x7F; |
1666 | uint32_t window_width = (*iptr>>0) & 0x0FFF; |
1667 | |
1668 | Df125WindowRawData *wrd = pe->NEW_Df125WindowRawData(rocid, slot, channel, itrigger); |
1669 | |
1670 | for(uint32_t isample=0; isample<window_width; isample +=2){ |
1671 | |
1672 | // Advance to next word |
1673 | iptr++; |
1674 | |
1675 | // Make sure this is a data continuation word, if not, stop here |
1676 | if(((*iptr>>31) & 0x1) != 0x0)break; |
1677 | |
1678 | bool invalid_1 = (*iptr>>29) & 0x1; |
1679 | bool invalid_2 = (*iptr>>13) & 0x1; |
1680 | uint16_t sample_1 = 0; |
1681 | uint16_t sample_2 = 0; |
1682 | if(!invalid_1)sample_1 = (*iptr>>16) & 0x1FFF; |
1683 | if(!invalid_2)sample_2 = (*iptr>>0) & 0x1FFF; |
1684 | |
1685 | // Sample 1 |
1686 | wrd->samples.push_back(sample_1); |
1687 | wrd->invalid_samples |= invalid_1; |
1688 | wrd->overflow |= (sample_1>>12) & 0x1; |
1689 | |
1690 | if((isample+2) == window_width && invalid_2)break; // skip last sample if flagged as invalid |
1691 | |
1692 | // Sample 2 |
1693 | wrd->samples.push_back(sample_2); |
1694 | wrd->invalid_samples |= invalid_2; |
1695 | wrd->overflow |= (sample_2>>12) & 0x1; |
1696 | } |
1697 | } |
1698 | |
1699 | //---------------- |
1700 | // ParseF1TDCBank |
1701 | //---------------- |
1702 | void DEVIOWorkerThread::ParseF1TDCBank(uint32_t rocid, uint32_t* &iptr, uint32_t *iend) |
1703 | { |
1704 | if(!PARSE_F1TDC){ iptr = &iptr[(*iptr) + 1]; return; } |
1705 | |
1706 | uint32_t *istart = iptr; |
1707 | |
1708 | auto pe_iter = current_parsed_events.begin(); |
1709 | DParsedEvent *pe = NULL__null; |
1710 | |
1711 | uint32_t slot = 0; |
1712 | uint32_t modtype = 0; |
1713 | uint32_t itrigger = -1; |
1714 | uint32_t trig_time_f1header = 0; |
1715 | |
1716 | // Some early data had a marker word at just before the actual F1 data |
1717 | if(*iptr == 0xf1daffff) iptr++; |
1718 | |
1719 | // Loop over data words |
1720 | for(; iptr<iend; iptr++){ |
1721 | |
1722 | // Skip all non-data-type-defining words at this |
1723 | // level. When we do encounter one, the appropriate |
1724 | // case block below should handle parsing all of |
1725 | // the data continuation words and advance the iptr. |
1726 | if(((*iptr>>31) & 0x1) == 0)continue; |
1727 | |
1728 | uint32_t data_type = (*iptr>>27) & 0x0F; |
1729 | switch(data_type){ |
1730 | case 0: // Block Header |
1731 | slot = (*iptr)>>22 & 0x001F; |
1732 | modtype = (*iptr)>>18 & 0x000F; // should match a DModuleType::type_id_t |
1733 | if(VERBOSE>7) cout << " F1 Block Header: slot=" << slot << " modtype=" << modtype << endl; |
1734 | break; |
1735 | |
1736 | case 1: // Block Trailer |
1737 | pe_iter = current_parsed_events.begin(); |
1738 | pe = NULL__null; |
1739 | if(VERBOSE>7) cout << " F1 Block Trailer" << endl; |
1740 | break; |
1741 | |
1742 | case 2: // Event Header |
1743 | { |
1744 | pe = *pe_iter++; |
1745 | itrigger = (*iptr)>>0 & 0x0003FFFFF; |
1746 | if(VERBOSE>7) { |
1747 | uint32_t slot_event_header = (*iptr)>>22 & 0x00000001F; |
1748 | cout << " F1 Event Header: slot=" << slot_event_header << " itrigger=" << itrigger << endl; |
1749 | } |
1750 | } |
1751 | break; |
1752 | |
1753 | case 3: // Trigger time |
1754 | { |
1755 | uint64_t t = ((*iptr)&0xFFFFFF)<<0; |
1756 | iptr++; |
1757 | if(((*iptr>>31) & 0x1) == 0){ |
1758 | t += ((*iptr)&0xFFFFFF)<<24; // from word on the street: second trigger time word is optional!!?? |
1759 | }else{ |
1760 | iptr--; |
1761 | } |
1762 | if(VERBOSE>7) cout << " F1TDC Trigger Time (t="<<t<<")"<<endl; |
1763 | if(pe) pe->NEW_DF1TDCTriggerTime(rocid, slot, itrigger, t); |
1764 | } |
1765 | break; |
1766 | |
1767 | case 8: // F1 Chip Header |
1768 | trig_time_f1header = ((*iptr)>> 7) & 0x1FF; |
1769 | if(VERBOSE>7) { |
1770 | uint32_t chip_f1header = ((*iptr)>> 3) & 0x07; |
1771 | uint32_t chan_on_chip_f1header = ((*iptr)>> 0) & 0x07; // this is always 7 in real data! |
1772 | uint32_t itrigger_f1header = ((*iptr)>>16) & 0x3F; |
1773 | cout << " Found F1 header: chip=" << chip_f1header << " chan=" << chan_on_chip_f1header << " itrig=" << itrigger_f1header << " trig_time=" << trig_time_f1header << endl; |
1774 | } |
1775 | break; |
1776 | |
1777 | case 7: // F1 Data |
1778 | { |
1779 | uint32_t chip = (*iptr>>19) & 0x07; |
1780 | uint32_t chan_on_chip = (*iptr>>16) & 0x07; |
1781 | uint32_t time = (*iptr>> 0) & 0xFFFF; |
1782 | uint32_t channel = F1TDC_channel(chip, chan_on_chip, modtype); |
1783 | if(VERBOSE>7) cout << " Found F1 data : chip=" << chip << " chan=" << chan_on_chip << " time=" << time << endl; |
1784 | if(pe) pe->NEW_DF1TDCHit(rocid, slot, channel, itrigger, trig_time_f1header, time, *iptr, MODULE_TYPE(modtype)); |
1785 | } |
1786 | break; |
1787 | |
1788 | case 15: // Filler word |
1789 | if(VERBOSE>7) cout << " F1 filler word" << endl; |
1790 | case 14: // Data not valid (how to handle this?) |
1791 | break; |
1792 | |
1793 | default: |
1794 | cerr<<endl; |
1795 | cout.flush(); cerr.flush(); |
1796 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1796<<" "<<"Unknown data word in F1TDC block. Dumping for debugging:" << endl; |
1797 | for(const uint32_t *iiptr = istart; iiptr<iend; iiptr++){ |
1798 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1798<<" "<<"0x"<<hex<<*iiptr<<dec; |
1799 | if(iiptr == iptr)cerr<<" <----"; |
1800 | switch( (*iiptr) & 0xF8000000 ){ |
1801 | case 0x80000000: cerr << " F1 Block Header"; break; |
1802 | case 0x90000000: cerr << " F1 Event Header"; break; |
1803 | case 0x98000000: cerr << " F1 Trigger time"; break; |
1804 | case 0xC0000000: cerr << " F1 Header"; break; |
1805 | case 0xB8000000: cerr << " F1 Data"; break; |
1806 | case 0x88000000: cerr << " F1 Block Trailer"; break; |
1807 | case 0xF8000000: cerr << " Filler word"; break; |
1808 | case 0xF0000000: cerr << " <module has no valid data>"; break; |
1809 | default: break; |
1810 | } |
1811 | cerr<<endl; |
1812 | if(iiptr > (iptr+4)) break; |
1813 | } |
1814 | throw JException("Unexpected word type in F1TDC block!", __FILE__"libraries/DAQ/DEVIOWorkerThread.cc", __LINE__1814); |
1815 | break; |
1816 | } |
1817 | } |
1818 | |
1819 | // Skip filler words |
1820 | while(iptr<iend && (*iptr&0xF8000000)==0xF8000000)iptr++; |
1821 | } |
1822 | |
1823 | //---------------- |
1824 | // ParseDVertexBank |
1825 | //---------------- |
1826 | void DEVIOWorkerThread::ParseDVertexBank(uint32_t* &iptr, uint32_t *iend) |
1827 | { |
1828 | uint32_t Nwords = ((uint64_t)iend - (uint64_t)iptr)/sizeof(uint32_t); |
1829 | uint32_t Nwords_expected = 11; // ? |
1830 | if(Nwords != Nwords_expected){ |
1831 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1831<<" " << "DVertex size does not match expected!!" << endl; |
1832 | _DBG_std::cerr<<"libraries/DAQ/DEVIOWorkerThread.cc"<< ":"<<1832<<" " << "Found " << Nwords << " words. Expected " << Nwords_expected << endl; |
1833 | }else{ |
1834 | DParsedEvent *pe = current_parsed_events.back(); |
1835 | DVertex *the_vertex = pe->NEW_DVertex(); |
1836 | |
1837 | uint64_t in_word = *iptr++; // 1st word, lo word; 2nd word, hi word |
1838 | uint64_t in_word_hi = *iptr++; |
1839 | in_word |= in_word_hi<<32; |
1840 | //uint64_t hi_word = *iptr++; |
1841 | double vertex_x_pos; |
1842 | memcpy(&vertex_x_pos, &in_word, sizeof(double)); |
1843 | in_word = *iptr++; in_word_hi = *iptr++; |
1844 | in_word |= in_word_hi<<32; |
1845 | double vertex_y_pos; |
1846 | memcpy(&vertex_y_pos, &in_word, sizeof(double)); |
1847 | in_word = *iptr++; in_word_hi = *iptr++; |
1848 | in_word |= in_word_hi<<32; |
1849 | double vertex_z_pos; |
1850 | memcpy(&vertex_z_pos, &in_word, sizeof(double)); |
1851 | in_word = *iptr++; in_word_hi = *iptr++; |
1852 | in_word |= in_word_hi<<32; |
1853 | double vertex_t; |
1854 | memcpy(&vertex_t, &in_word, sizeof(double)); |
1855 | |
1856 | DVector3 vertex_position(vertex_x_pos, vertex_y_pos, vertex_z_pos); |
1857 | the_vertex->dSpacetimeVertex = DLorentzVector(vertex_position, vertex_t); |
1858 | the_vertex->dKinFitNDF = *iptr++; |
1859 | |
1860 | in_word = *iptr++; in_word_hi = *iptr++; |
1861 | in_word |= in_word_hi<<32; |
1862 | memcpy(&(the_vertex->dKinFitChiSq), &in_word, sizeof(double)); |
1863 | } |
1864 | } |
1865 | |
1866 | |
1867 | //---------------- |
1868 | // LinkAllAssociations |
1869 | //---------------- |
1870 | void DEVIOWorkerThread::LinkAllAssociations(void) |
1871 | { |
1872 | |
1873 | /// Find objects that should be linked as "associated objects" |
1874 | /// of one another and add to each other's list. |
1875 | for( auto pe : current_parsed_events){ |
1876 | |
1877 | //----------------- Sort hit objects |
1878 | |
1879 | // fADC250 (n.b. Df250PulseData values overwritten in JEventSource_EVIOpp::LinkBORassociations) |
1880 | if(pe->vDf250PulseData.size()>1 ) sort(pe->vDf250PulseData.begin(), pe->vDf250PulseData.end(), SortByPulseNumber<Df250PulseData> ); |
1881 | if(pe->vDf250PulseIntegral.size()>1) sort(pe->vDf250PulseIntegral.begin(), pe->vDf250PulseIntegral.end(), SortByPulseNumber<Df250PulseIntegral> ); |
1882 | if(pe->vDf250PulseTime.size()>1 ) sort(pe->vDf250PulseTime.begin(), pe->vDf250PulseTime.end(), SortByPulseNumber<Df250PulseTime> ); |
1883 | if(pe->vDf250PulsePedestal.size()>1) sort(pe->vDf250PulsePedestal.begin(), pe->vDf250PulsePedestal.end(), SortByPulseNumber<Df250PulsePedestal> ); |
1884 | |
1885 | // fADC125 |
1886 | if(pe->vDf125PulseIntegral.size()>1) sort(pe->vDf125PulseIntegral.begin(), pe->vDf125PulseIntegral.end(), SortByPulseNumber<Df125PulseIntegral> ); |
1887 | if(pe->vDf125CDCPulse.size()>1 ) sort(pe->vDf125CDCPulse.begin(), pe->vDf125CDCPulse.end(), SortByChannel<Df125CDCPulse> ); |
1888 | if(pe->vDf125FDCPulse.size()>1 ) sort(pe->vDf125FDCPulse.begin(), pe->vDf125FDCPulse.end(), SortByChannel<Df125FDCPulse> ); |
1889 | if(pe->vDf125PulseTime.size()>1 ) sort(pe->vDf125PulseTime.begin(), pe->vDf125PulseTime.end(), SortByPulseNumber<Df125PulseTime> ); |
1890 | if(pe->vDf125PulsePedestal.size()>1) sort(pe->vDf125PulsePedestal.begin(), pe->vDf125PulsePedestal.end(), SortByPulseNumber<Df125PulsePedestal> ); |
1891 | |
1892 | // F1TDC |
1893 | if(pe->vDF1TDCHit.size()>1 ) sort(pe->vDF1TDCHit.begin(), pe->vDF1TDCHit.end(), SortByModule<DF1TDCHit> ); |
1894 | |
1895 | // CAEN1290TDC |
1896 | if(pe->vDCAEN1290TDCHit.size()>1 ) sort(pe->vDCAEN1290TDCHit.begin(), pe->vDCAEN1290TDCHit.end(), SortByModule<DCAEN1290TDCHit> ); |
1897 | |
1898 | |
1899 | //----------------- Link hit objects |
1900 | |
1901 | // Connect Df250 pulse objects |
1902 | LinkPulse(pe->vDf250PulseTime, pe->vDf250PulseIntegral); |
1903 | LinkPulsePedCopy(pe->vDf250PulsePedestal, pe->vDf250PulseIntegral); |
1904 | |
1905 | // Connect Df125 pulse objects |
1906 | LinkPulse(pe->vDf125PulseTime, pe->vDf125PulseIntegral); |
1907 | LinkPulsePedCopy(pe->vDf125PulsePedestal, pe->vDf125PulseIntegral); |
1908 | |
1909 | // Connect Df250 window raw data objects |
1910 | if(!pe->vDf250WindowRawData.empty()){ |
1911 | LinkConfig(pe->vDf250Config, pe->vDf250WindowRawData); |
1912 | LinkModule(pe->vDf250TriggerTime, pe->vDf250WindowRawData); |
1913 | LinkChannel(pe->vDf250WindowRawData, pe->vDf250PulseIntegral); |
1914 | LinkChannel(pe->vDf250WindowRawData, pe->vDf250PulseTime); |
1915 | LinkChannel(pe->vDf250WindowRawData, pe->vDf250PulsePedestal); |
1916 | } |
1917 | |
1918 | // Connect Df125 window raw data objects |
1919 | if(!pe->vDf125WindowRawData.empty()){ |
1920 | LinkConfig(pe->vDf125Config, pe->vDf125WindowRawData); |
1921 | LinkModule(pe->vDf125TriggerTime, pe->vDf125WindowRawData); |
1922 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125PulseIntegral); |
1923 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125PulseTime); |
1924 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125PulsePedestal); |
1925 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125CDCPulse); |
1926 | LinkChannel(pe->vDf125WindowRawData, pe->vDf125FDCPulse); |
1927 | } |
1928 | |
1929 | //----------------- Optionally link config objects (on by default) |
1930 | if(LINK_CONFIG){ |
1931 | if(pe->vDf250Config.size()>1 ) sort(pe->vDf250Config.begin(), pe->vDf250Config.end(), SortByROCID<Df250Config> ); |
1932 | if(pe->vDf125Config.size()>1 ) sort(pe->vDf125Config.begin(), pe->vDf125Config.end(), SortByROCID<Df125Config> ); |
1933 | if(pe->vDF1TDCConfig.size()>1 ) sort(pe->vDF1TDCConfig.begin(), pe->vDF1TDCConfig.end(), SortByROCID<DF1TDCConfig> ); |
1934 | if(pe->vDCAEN1290TDCConfig.size()>1) sort(pe->vDCAEN1290TDCConfig.begin(), pe->vDCAEN1290TDCConfig.end(), SortByROCID<DCAEN1290TDCConfig> ); |
1935 | |
1936 | LinkConfigSamplesCopy(pe->vDf250Config, pe->vDf250PulseIntegral); |
1937 | LinkConfigSamplesCopy(pe->vDf250Config, pe->vDf250PulseData); |
1938 | LinkConfigSamplesCopy(pe->vDf125Config, pe->vDf125PulseIntegral); |
1939 | LinkConfigSamplesCopy(pe->vDf125Config, pe->vDf125CDCPulse); |
1940 | LinkConfigSamplesCopy(pe->vDf125Config, pe->vDf125FDCPulse); |
1941 | LinkConfig(pe->vDF1TDCConfig, pe->vDF1TDCHit); |
1942 | LinkConfig(pe->vDCAEN1290TDCConfig, pe->vDCAEN1290TDCHit); |
1943 | } |
1944 | |
1945 | //----------------- Optionally link trigger time objects (off by default) |
1946 | if(LINK_TRIGGERTIME){ |
1947 | if(pe->vDf250TriggerTime.size()>1 ) sort(pe->vDf250TriggerTime.begin(), pe->vDf250TriggerTime.end(), SortByModule<Df250TriggerTime> ); |
1948 | if(pe->vDf125TriggerTime.size()>1 ) sort(pe->vDf125TriggerTime.begin(), pe->vDf125TriggerTime.end(), SortByModule<Df125TriggerTime> ); |
1949 | if(pe->vDF1TDCTriggerTime.size()>1 ) sort(pe->vDF1TDCTriggerTime.begin(), pe->vDF1TDCTriggerTime.end(), SortByModule<DF1TDCTriggerTime> ); |
1950 | |
1951 | LinkModule(pe->vDf250TriggerTime, pe->vDf250PulseIntegral); |
1952 | LinkModule(pe->vDf125TriggerTime, pe->vDf125PulseIntegral); |
1953 | LinkModule(pe->vDf125TriggerTime, pe->vDf125CDCPulse); |
1954 | LinkModule(pe->vDf125TriggerTime, pe->vDf125FDCPulse); |
1955 | LinkModule(pe->vDF1TDCTriggerTime, pe->vDF1TDCHit); |
1956 | } |
1957 | } |
1958 | |
1959 | } |
1960 | |
1961 | //---------------- |
1962 | // DumpBinary |
1963 | //---------------- |
1964 | void DEVIOWorkerThread::DumpBinary(const uint32_t *iptr, const uint32_t *iend, uint32_t MaxWords, const uint32_t *imark) |
1965 | { |
1966 | /// This is used for debugging. It will print to the screen the words |
1967 | /// starting at the address given by iptr and ending just before iend |
1968 | /// or for MaxWords words, whichever comes first. If iend is NULL, |
1969 | /// then MaxWords will be printed. If MaxWords is zero then it is ignored |
1970 | /// and only iend is checked. If both iend==NULL and MaxWords==0, then |
1971 | /// only the word at iptr is printed. |
1972 | |
1973 | cout << "Dumping binary: istart=" << hex << iptr << " iend=" << iend << " MaxWords=" << dec << MaxWords << endl; |
1974 | |
1975 | if(iend==NULL__null && MaxWords==0) MaxWords=1; |
1976 | if(MaxWords==0) MaxWords = (uint32_t)0xffffffff; |
1977 | |
1978 | uint32_t Nwords=0; |
1979 | while(iptr!=iend && Nwords<MaxWords){ |
1980 | |
1981 | // line1 is hex and line2 is decimal |
1982 | stringstream line1, line2; |
1983 | |
1984 | // print words in columns 8 words wide. First part is |
1985 | // reserved for word number |
1986 | uint32_t Ncols = 8; |
1987 | line1 << setw(5) << Nwords; |
1988 | line2 << string(5, ' '); |
1989 | |
1990 | // Loop over columns |
1991 | for(uint32_t i=0; i<Ncols; i++, iptr++, Nwords++){ |
1992 | |
1993 | if(iptr == iend) break; |
1994 | if(Nwords>=MaxWords) break; |
1995 | |
1996 | stringstream iptr_hex; |
1997 | iptr_hex << hex << "0x" << *iptr; |
1998 | |
1999 | string mark = (iptr==imark ? "*":" "); |
2000 | |
2001 | line1 << setw(12) << iptr_hex.str() << mark; |
2002 | line2 << setw(12) << *iptr << mark; |
2003 | } |
2004 | |
2005 | cout << line1.str() << endl; |
2006 | cout << line2.str() << endl; |
2007 | cout << endl; |
2008 | } |
2009 | } |
2010 | |
2011 |