1 | #include "DEventWriterEVIO.h" |
2 | #include "HDEVIOWriter.h" |
3 | |
4 | |
5 | |
6 | size_t gEVIONumOutputThreads = 0; |
7 | map<string, HDEVIOWriter *>* gEVIOOutputters = NULL__null; |
8 | map<string, pthread_t>* gEVIOOutputThreads = NULL__null; |
9 | |
10 | DEventWriterEVIO::DEventWriterEVIO(JEventLoop* locEventLoop) |
11 | { |
12 | COMPACT = true; |
13 | PREFER_EMULATED = false; |
14 | DEBUG_FILES = false; |
15 | |
16 | ofs_debug_input = NULL__null; |
17 | ofs_debug_output = NULL__null; |
18 | |
19 | gPARMS->SetDefaultParameter("EVIOOUT:COMPACT" , COMPACT, "Drop words where we can to reduce output file size. This shouldn't loose any vital information, but can be turned off to help with debugging."); |
20 | gPARMS->SetDefaultParameter("EVIOOUT:PREFER_EMULATED" , PREFER_EMULATED, "If true, then sample data will not be written to output, but emulated hits will. Otherwise, do exactly the opposite."); |
21 | gPARMS->SetDefaultParameter("EVIOOUT:DEBUG_FILES" , DEBUG_FILES, "Write input and output debug files in addition to the standard output."); |
22 | |
23 | |
24 | japp->WriteLock("EVIOWriter"); |
25 | { |
26 | ++gEVIONumOutputThreads; |
27 | if(gEVIOOutputters == NULL__null) |
28 | gEVIOOutputters = new map<string, HDEVIOWriter *>(); |
29 | if(gEVIOOutputThreads == NULL__null) |
30 | gEVIOOutputThreads = new map<string, pthread_t>(); |
31 | } |
32 | japp->Unlock("EVIOWriter"); |
33 | |
34 | if(DEBUG_FILES){ |
35 | ofs_debug_input = new ofstream("hdevio_debug_input.evio"); |
36 | if( !ofs_debug_input->is_open() ){ |
37 | jerr << "Unable to open \"hdevio_debug_input.evio\"!" << endl; |
38 | delete ofs_debug_input; |
39 | ofs_debug_input = NULL__null; |
40 | }else{ |
41 | jout << "Opened \"hdevio_debug_input.evio\" for debug output" << endl; |
42 | } |
43 | |
44 | ofs_debug_output = new ofstream("hdevio_debug_output_preswap.evio"); |
45 | if( !ofs_debug_output->is_open() ){ |
46 | jerr << "Unable to open \"hdevio_debug_output_preswap.evio\"!" << endl; |
47 | delete ofs_debug_output; |
48 | ofs_debug_output = NULL__null; |
49 | }else{ |
50 | jout << "Opened \"hdevio_debug_output_preswap.evio\" for debug output" << endl; |
51 | } |
52 | } |
53 | } |
54 | |
55 | bool DEventWriterEVIO::Write_EVIOEvent(JEventLoop* locEventLoop, string locOutputFileNameSubString) const |
56 | { |
57 | JEvent& locEvent = locEventLoop->GetJEvent(); |
58 | |
59 | |
60 | JEventSource* locEventSource = locEvent.GetJEventSource(); |
61 | if(locEventSource == NULL__null) |
62 | return false; |
63 | |
64 | #if !HAVE_EVIO1 |
65 | jerr << "Compiled without EVIO! Cannot write event." << << endl; |
66 | return false; |
67 | #endif // HAVE_EVIO |
68 | |
69 | JEventSource_EVIO* locEvioSource = dynamic_cast<JEventSource_EVIO*>(locEventSource); |
70 | if(locEvioSource == NULL__null) |
71 | { |
72 | jerr << "WARNING!!! You MUST use this only with EVIO formatted data!!!" << endl; |
73 | return false; |
74 | } |
75 | |
76 | |
77 | if(DEBUG_FILES){ |
78 | JEvent &jevent = locEventLoop->GetJEvent(); |
79 | JEventSource *jes = jevent.GetJEventSource(); |
80 | JEventSource_EVIO *jesevio = dynamic_cast<JEventSource_EVIO*>(jes); |
81 | if(!jesevio){ |
82 | static bool warned = false; |
83 | if(!warned) jerr << "Event source not a JEventSource_EVIO type!" << endl; |
84 | warned = true; |
85 | }else{ |
86 | uint32_t *buff; |
87 | uint32_t buff_size; |
88 | jesevio->GetEVIOBuffer(jevent, buff, buff_size); |
89 | if(ofs_debug_input) ofs_debug_input->write((char*)buff, buff_size*sizeof(uint32_t)); |
90 | } |
91 | } |
92 | |
93 | string locOutputFileName = Get_OutputFileName(locEventLoop, locOutputFileNameSubString); |
94 | japp->WriteLock("EVIOWriter"); |
95 | { |
96 | |
97 | if(gEVIOOutputters->find(locOutputFileName) == gEVIOOutputters->end()) |
98 | { |
99 | |
100 | if(!Open_OutputFile(locEventLoop, locOutputFileName)) |
101 | return false; |
102 | } |
103 | |
104 | |
105 | HDEVIOWriter *locEVIOWriter = (*gEVIOOutputters)[locOutputFileName]; |
106 | |
107 | vector<uint32_t> *buff = locEVIOWriter->GetBufferFromPool(); |
108 | WriteEventToBuffer(locEventLoop, *buff); |
109 | |
110 | |
111 | if(ofs_debug_output) ofs_debug_output->write((const char*)&(*buff)[0], buff->size()*sizeof(uint32_t)); |
112 | |
113 | |
114 | locEVIOWriter->AddBufferToOutput(buff); |
115 | } |
116 | japp->Unlock("EVIOWriter"); |
117 | |
118 | return true; |
119 | } |
120 | |
121 | string DEventWriterEVIO::Get_OutputFileName(JEventLoop* locEventLoop, string locOutputFileNameSubString) const |
122 | { |
123 | |
124 | JEvent& locEvent = locEventLoop->GetJEvent(); |
125 | JEventSource* locEventSource = locEvent.GetJEventSource(); |
126 | if(locEventSource == NULL__null) |
127 | return "no_name.evio"; |
128 | |
129 | |
130 | string locSourceFileName = locEventSource->GetSourceName(); |
131 | size_t locSlashIndex = locSourceFileName.find_last_of("/"); |
132 | string locSourceFileName_Pathless = (locSlashIndex != string::npos) ? locSourceFileName.substr(locSlashIndex + 1) : locSourceFileName; |
133 | |
134 | |
135 | size_t locDotIndex = locSourceFileName_Pathless.find_last_of("."); |
136 | if(locDotIndex != string::npos) |
137 | { |
138 | string locSuffix = locSourceFileName_Pathless.substr(locDotIndex + 1); |
139 | if((locSuffix == "root") || (locSuffix == "evio") || (locSuffix == "hddm")) |
140 | locSourceFileName_Pathless = locSourceFileName_Pathless.substr(0, locDotIndex); |
141 | } |
142 | |
143 | return (locSourceFileName_Pathless + string(".") + locOutputFileNameSubString + string(".evio")); |
144 | } |
145 | |
146 | bool DEventWriterEVIO::Open_OutputFile(JEventLoop* locEventLoop, string locOutputFileName) const |
147 | { |
148 | |
149 | |
150 | #if !HAVE_EVIO1 |
151 | jerr << "Compiled without EVIO! Cannot open file:" << locOutputFileName << endl; |
152 | return false; |
153 | #endif // HAVE_EVIO |
154 | |
155 | |
156 | |
157 | HDEVIOWriter *locEVIOout = new HDEVIOWriter(locOutputFileName); |
158 | pthread_t locEVIOout_thr; |
159 | int result = pthread_create(&locEVIOout_thr, NULL__null, HDEVIOOutputThread, locEVIOout); |
160 | bool success = (result == 0); |
161 | |
162 | |
163 | if(!success) |
164 | jerr << "Unable to open EVIO file: error code = " << result << endl; |
165 | else |
166 | { |
167 | jout << "Output EVIO file " << locOutputFileName << " created." << endl; |
168 | (*gEVIOOutputters)[locOutputFileName] = locEVIOout; |
169 | (*gEVIOOutputThreads)[locOutputFileName] = locEVIOout_thr; |
170 | } |
171 | |
172 | return success; |
173 | |
174 | } |
175 | |
176 | DEventWriterEVIO::~DEventWriterEVIO(void) |
177 | { |
178 | #if HAVE_EVIO1 |
179 | japp->WriteLock("EVIOWriter"); |
180 | { |
181 | --gEVIONumOutputThreads; |
182 | if(gEVIONumOutputThreads > 0) |
183 | { |
184 | japp->Unlock("EVIOWriter"); |
185 | return; |
186 | } |
187 | |
188 | if(gEVIOOutputters == NULL__null) |
189 | { |
190 | japp->Unlock("EVIOWriter"); |
191 | return; |
192 | } |
193 | |
194 | |
195 | map<string, HDEVIOWriter *>::iterator locIterator = gEVIOOutputters->begin(); |
196 | for(; locIterator != gEVIOOutputters->end(); ++locIterator) |
197 | { |
198 | string locOutputFileName = locIterator->first; |
199 | HDEVIOWriter *locEVIOOutputter = locIterator->second; |
200 | pthread_t locEVIOOutputThread = (*gEVIOOutputThreads)[locOutputFileName]; |
201 | |
202 | |
203 | locEVIOOutputter->Quit(); |
204 | |
205 | void *retval=NULL__null; |
206 | int result = pthread_join(locEVIOOutputThread, &retval); |
207 | if(result!=0) |
208 | jerr << "Problem closing EVIO file: error code = " << result << endl; |
209 | delete locEVIOOutputter; |
210 | std::cout << "Closed EVIO file " << locOutputFileName << std::endl; |
211 | } |
212 | delete gEVIOOutputters; |
213 | gEVIOOutputters = NULL__null; |
214 | delete gEVIOOutputThreads; |
215 | gEVIOOutputThreads = NULL__null; |
216 | } |
217 | japp->Unlock("EVIOWriter"); |
218 | #endif // HAVE_EVIO |
219 | } |
220 | |
221 | |
222 | |
223 | |
224 | void DEventWriterEVIO::WriteEventToBuffer(JEventLoop *loop, vector<uint32_t> &buff) const |
225 | { |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | if( loop->GetJEvent().GetStatusBit(kSTATUS_BOR_EVENT) ){ |
232 | WriteBORData(loop, buff); |
233 | return; |
234 | } |
235 | |
236 | |
237 | vector<const Df250TriggerTime*> f250tts; |
238 | vector<const Df250PulseIntegral*> f250pis; |
239 | vector<const Df250WindowRawData*> f250wrds; |
240 | vector<const Df125TriggerTime*> f125tts; |
241 | vector<const Df125PulseIntegral*> f125pis; |
242 | vector<const Df125CDCPulse*> f125cdcpulses; |
243 | vector<const Df125FDCPulse*> f125fdcpulses; |
244 | vector<const Df125WindowRawData*> f125wrds; |
245 | vector<const Df125Config*> f125configs; |
246 | vector<const DCAEN1290TDCHit*> caen1290hits; |
247 | vector<const DCAEN1290TDCConfig*> caen1290configs; |
248 | vector<const DF1TDCHit*> F1hits; |
249 | vector<const DF1TDCTriggerTime*> F1tts; |
250 | vector<const DF1TDCConfig*> F1configs; |
251 | vector<const DEPICSvalue*> epicsValues; |
252 | vector<const DCODAEventInfo*> coda_events; |
253 | vector<const DCODAROCInfo*> coda_rocinfos; |
254 | |
255 | loop->Get(f250tts); |
256 | loop->Get(f250pis); |
257 | loop->Get(f250wrds); |
258 | loop->Get(f125tts); |
259 | loop->Get(f125pis); |
260 | loop->Get(f125cdcpulses); |
261 | loop->Get(f125fdcpulses); |
262 | loop->Get(f125wrds); |
263 | loop->Get(f125configs); |
264 | loop->Get(caen1290hits); |
265 | loop->Get(caen1290configs); |
266 | loop->Get(F1hits); |
267 | loop->Get(F1tts); |
268 | loop->Get(F1configs); |
269 | loop->Get(epicsValues); |
270 | loop->Get(coda_events); |
271 | loop->Get(coda_rocinfos); |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | const DL3Trigger *l3trigger = NULL__null; |
278 | JFactory_base *fac = loop->GetFactory("DL3Trigger"); |
279 | if(fac){ |
280 | int nobjs = fac->GetNrows(false, true); |
281 | if(nobjs>0){ |
282 | loop->GetSingle(l3trigger, "", false); |
283 | } |
284 | } |
285 | |
286 | |
287 | |
288 | |
289 | if( !epicsValues.empty() ){ |
290 | WriteEPICSData(buff, epicsValues); |
291 | return; |
292 | } |
293 | |
294 | |
295 | set<uint32_t> rocids; |
296 | rocids.insert(1); |
297 | for(uint32_t i=0; i<f250pis.size(); i++) rocids.insert( f250pis[i]->rocid ); |
298 | for(uint32_t i=0; i<f250wrds.size(); i++) rocids.insert( f250wrds[i]->rocid ); |
299 | for(uint32_t i=0; i<f125pis.size(); i++) rocids.insert( f125pis[i]->rocid ); |
300 | for(uint32_t i=0; i<f125cdcpulses.size();i++) rocids.insert( f125cdcpulses[i]->rocid); |
301 | for(uint32_t i=0; i<f125fdcpulses.size();i++) rocids.insert( f125fdcpulses[i]->rocid); |
302 | for(uint32_t i=0; i<f125wrds.size(); i++) rocids.insert( f125wrds[i]->rocid ); |
303 | for(uint32_t i=0; i<caen1290hits.size(); i++) rocids.insert( caen1290hits[i]->rocid ); |
304 | for(uint32_t i=0; i<F1hits.size(); i++) rocids.insert( F1hits[i]->rocid ); |
305 | |
306 | |
307 | if(COMPACT){ |
308 | vector<const DCODAROCInfo*> my_coda_rocinfos; |
309 | for(uint32_t i=0; i<coda_rocinfos.size(); i++){ |
310 | const DCODAROCInfo *rocinfo = coda_rocinfos[i]; |
311 | if(rocids.find(coda_rocinfos[i]->rocid)!=rocids.end()){ |
312 | my_coda_rocinfos.push_back(rocinfo); |
313 | } |
314 | } |
315 | |
316 | |
317 | coda_rocinfos = my_coda_rocinfos; |
318 | } |
319 | |
320 | |
321 | buff.clear(); |
322 | buff.push_back(0); |
323 | buff.push_back( 0xFF701001); |
324 | |
325 | |
326 | uint32_t built_trigger_bank_len_idx = buff.size(); |
327 | buff.push_back(0); |
328 | buff.push_back(0xFF232000 + coda_rocinfos.size()); |
329 | |
330 | |
331 | |
332 | uint32_t run_number = loop->GetJEvent().GetRunNumber(); |
333 | uint32_t run_type = 1; |
334 | uint64_t event_number = loop->GetJEvent().GetEventNumber(); |
335 | uint64_t avg_timestamp = time(NULL__null); |
336 | if(!coda_events.empty()){ |
337 | run_number = coda_events[0]->run_number; |
338 | run_type = coda_events[0]->run_type; |
339 | event_number = coda_events[0]->event_number; |
340 | avg_timestamp = coda_events[0]->avg_timestamp; |
341 | } |
342 | |
343 | buff.push_back(0xD30A0006); |
344 | buff.push_back(event_number & 0xFFFFFFFF); |
345 | buff.push_back(event_number>>32); |
346 | buff.push_back(avg_timestamp & 0xFFFFFFFF); |
347 | buff.push_back(avg_timestamp>>32); |
348 | |
349 | buff.push_back(run_type); |
350 | buff.push_back(run_number); |
351 | |
352 | |
353 | uint16_t event_type = 1; |
354 | if(!coda_events.empty()){ |
355 | event_type = coda_events[0]->event_type; |
356 | } |
357 | buff.push_back(0xD3850001); |
358 | buff.push_back((uint32_t)event_type); |
359 | |
360 | unsigned int Nevents = loop->GetNevents(); |
361 | |
362 | |
363 | |
364 | for(uint32_t i=0; i<coda_rocinfos.size(); i++){ |
365 | const DCODAROCInfo *rocinfo = coda_rocinfos[i]; |
366 | |
367 | |
368 | uint32_t len = 2 + rocinfo->misc.size(); |
369 | buff.push_back( (rocinfo->rocid<<24) + 0x00010000 + len); |
370 | buff.push_back(rocinfo->timestamp & 0xFFFFFFFF); |
371 | buff.push_back(rocinfo->timestamp>>32); |
372 | if(!rocinfo->misc.empty()){ |
373 | buff.insert(buff.end(), rocinfo->misc.begin(), rocinfo->misc.end()); |
374 | } |
375 | } |
376 | |
377 | |
378 | buff[built_trigger_bank_len_idx] = buff.size() - built_trigger_bank_len_idx - 1; |
379 | |
380 | |
381 | WriteEventTagData(buff, loop->GetJEvent().GetStatus(), l3trigger); |
382 | |
383 | |
384 | WriteCAEN1290Data(buff, caen1290hits, caen1290configs, Nevents); |
385 | |
386 | |
387 | WriteF1Data(buff, F1hits, F1tts, F1configs, Nevents); |
388 | |
389 | |
390 | Writef250Data(buff, f250pis, f250tts, f250wrds, Nevents); |
391 | |
392 | |
393 | Writef125Data(buff, f125pis, f125cdcpulses, f125fdcpulses, f125tts, f125wrds, f125configs, Nevents); |
394 | |
395 | |
396 | if(!buff.empty()) buff[0] = buff.size()-1; |
397 | } |
398 | |
399 | |
400 | |
401 | |
402 | void DEventWriterEVIO::WriteCAEN1290Data(vector<uint32_t> &buff, |
403 | vector<const DCAEN1290TDCHit*> &caen1290hits, |
404 | vector<const DCAEN1290TDCConfig*> &caen1290configs, |
405 | unsigned int Nevents) const |
406 | { |
407 | |
408 | |
409 | map<uint32_t, map<uint32_t, vector<const DCAEN1290TDCHit*> > > modules; |
410 | map<uint32_t, set<const DCAEN1290TDCConfig*> > configs; |
411 | for(uint32_t i=0; i<caen1290hits.size(); i++){ |
412 | const DCAEN1290TDCHit *hit = caen1290hits[i]; |
413 | modules[hit->rocid][hit->slot].push_back(hit); |
414 | } |
415 | |
416 | |
417 | for(uint32_t i=0; i<caen1290configs.size(); i++){ |
418 | const DCAEN1290TDCConfig *config = caen1290configs[i]; |
419 | configs[config->rocid].insert(config); |
420 | } |
421 | |
422 | |
423 | map<uint32_t, map<uint32_t, vector<const DCAEN1290TDCHit*> > >::iterator it; |
424 | for(it=modules.begin(); it!=modules.end(); it++){ |
425 | uint32_t rocid = it->first; |
426 | |
427 | |
428 | uint32_t data_bank_idx = buff.size(); |
429 | buff.push_back(0); |
430 | buff.push_back( (rocid<<16) + 0x1001 ); |
431 | |
432 | |
433 | set<const DCAEN1290TDCConfig*> &confs = configs[rocid]; |
434 | if(!confs.empty()){ |
435 | |
436 | uint32_t config_bank_idx = buff.size(); |
437 | buff.push_back(0); |
438 | buff.push_back( 0x00550101 ); |
439 | |
440 | set<const DCAEN1290TDCConfig*>::iterator it_conf; |
441 | for(it_conf=confs.begin(); it_conf!=confs.end(); it_conf++){ |
442 | const DCAEN1290TDCConfig *conf = *it_conf; |
443 | |
444 | uint32_t header_idx = buff.size(); |
445 | buff.push_back(0); |
446 | uint32_t Nvals = 0; |
447 | if(conf->WINWIDTH != 0xFFFF) {buff.push_back( (kPARAMCAEN1290_WINWIDTH <<16) + conf->WINWIDTH ); Nvals++;} |
448 | if(conf->WINOFFSET != 0xFFFF) {buff.push_back( (kPARAMCAEN1290_WINOFFSET <<16) + conf->WINOFFSET ); Nvals++;} |
449 | |
450 | buff[header_idx] = (Nvals<<24) + conf->slot_mask; |
451 | } |
452 | |
453 | |
454 | buff[config_bank_idx] = buff.size() - config_bank_idx - 1; |
455 | } |
456 | |
457 | |
458 | uint32_t data_block_bank_idx = buff.size(); |
459 | buff.push_back(0); |
460 | buff.push_back( 0x00140101 ); |
461 | |
462 | |
463 | map<uint32_t, vector<const DCAEN1290TDCHit*> >::iterator it2; |
464 | for(it2=it->second.begin(); it2!=it->second.end(); it2++){ |
465 | uint32_t slot = it2->first; |
466 | |
467 | |
468 | uint32_t global_header_idx = buff.size(); |
469 | buff.push_back( 0x40000100 + (0x01<<5) + slot ); |
470 | |
471 | |
472 | vector<const DCAEN1290TDCHit*> &hits = it2->second; |
473 | uint32_t last_id = 0x0; |
474 | for(uint32_t i=0; i<hits.size(); i++){ |
475 | const DCAEN1290TDCHit *hit = hits[i]; |
476 | |
477 | |
478 | uint32_t id = (hit->tdc_num<<24) + (hit->event_id<<12) + (hit->bunch_id); |
479 | if(id != last_id){ |
480 | |
481 | buff.push_back( 0x08000000 + id ); |
482 | last_id = id; |
483 | } |
484 | |
485 | |
486 | buff.push_back( (hit->edge<<26) + (hit->channel<<21) + (hit->time&0x1fffff) ); |
487 | } |
488 | |
489 | |
490 | uint32_t Nwords_in_block = buff.size()-global_header_idx+1; |
491 | buff.push_back( 0x80000000 + (Nwords_in_block<<5) + (slot) ); |
492 | } |
493 | |
494 | |
495 | buff[data_block_bank_idx] = buff.size() - data_block_bank_idx - 1; |
496 | |
497 | |
498 | buff[data_bank_idx] = buff.size() - data_bank_idx - 1; |
499 | } |
500 | } |
501 | |
502 | |
503 | |
504 | |
505 | void DEventWriterEVIO::WriteF1Data(vector<uint32_t> &buff, |
506 | vector<const DF1TDCHit*> &F1hits, |
507 | vector<const DF1TDCTriggerTime*> &F1tts, |
508 | vector<const DF1TDCConfig*> &F1configs, |
509 | unsigned int Nevents) const |
510 | { |
511 | |
512 | |
513 | map<uint32_t, map<uint32_t, vector<const DF1TDCHit*> > > modules; |
514 | map<uint32_t, map<uint32_t, MODULE_TYPE> > mod_types; |
515 | for(uint32_t i=0; i<F1hits.size(); i++){ |
516 | const DF1TDCHit *hit = F1hits[i]; |
517 | modules[hit->rocid][hit->slot].push_back(hit); |
518 | mod_types[hit->rocid][hit->slot] = hit->modtype; |
519 | } |
520 | |
521 | |
522 | map<uint32_t, set<const DF1TDCConfig*> > configs; |
523 | for(uint32_t i=0; i<F1configs.size(); i++){ |
524 | const DF1TDCConfig *config = F1configs[i]; |
525 | configs[config->rocid].insert(config); |
526 | } |
527 | |
528 | |
529 | map<uint32_t, map<uint32_t, vector<const DF1TDCHit*> > >::iterator it; |
530 | for(it=modules.begin(); it!=modules.end(); it++){ |
531 | uint32_t rocid = it->first; |
532 | |
533 | |
534 | uint32_t data_bank_idx = buff.size(); |
535 | buff.push_back(0); |
536 | buff.push_back( (rocid<<16) + 0x1001 ); |
537 | |
538 | |
539 | set<const DF1TDCConfig*> &confs = configs[rocid]; |
540 | if(!confs.empty()){ |
541 | |
542 | uint32_t config_bank_idx = buff.size(); |
543 | buff.push_back(0); |
544 | buff.push_back( 0x00550101 ); |
545 | |
546 | set<const DF1TDCConfig*>::iterator it_conf; |
547 | for(it_conf=confs.begin(); it_conf!=confs.end(); it_conf++){ |
548 | const DF1TDCConfig *conf = *it_conf; |
549 | |
550 | uint32_t header_idx = buff.size(); |
551 | buff.push_back(0); |
552 | uint32_t Nvals = 0; |
553 | if(conf->REFCNT != 0xFFFF) {buff.push_back( (kPARAMF1_REFCNT <<16) + conf->REFCNT ); Nvals++;} |
554 | if(conf->TRIGWIN != 0xFFFF) {buff.push_back( (kPARAMF1_TRIGWIN <<16) + conf->TRIGWIN ); Nvals++;} |
555 | if(conf->TRIGLAT != 0xFFFF) {buff.push_back( (kPARAMF1_TRIGLAT <<16) + conf->TRIGLAT ); Nvals++;} |
556 | if(conf->HSDIV != 0xFFFF) {buff.push_back( (kPARAMF1_HSDIV <<16) + conf->HSDIV ); Nvals++;} |
557 | if(conf->BINSIZE != 0xFFFF) {buff.push_back( (kPARAMF1_BINSIZE <<16) + conf->BINSIZE ); Nvals++;} |
558 | if(conf->REFCLKDIV != 0xFFFF) {buff.push_back( (kPARAMF1_REFCLKDIV <<16) + conf->REFCLKDIV ); Nvals++;} |
559 | |
560 | buff[header_idx] = (Nvals<<24) + conf->slot_mask; |
561 | } |
562 | |
563 | |
564 | buff[config_bank_idx] = buff.size() - config_bank_idx - 1; |
565 | } |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | uint32_t data_block_bank_idx = buff.size(); |
578 | buff.push_back(0); |
579 | buff.push_back( 0x001A0101 ); |
580 | |
581 | |
582 | map<uint32_t, vector<const DF1TDCHit*> >::iterator it2; |
583 | for(it2=it->second.begin(); it2!=it->second.end(); it2++){ |
584 | uint32_t slot = it2->first; |
585 | MODULE_TYPE modtype = mod_types[rocid][slot]; |
586 | |
587 | |
588 | const DF1TDCTriggerTime *tt = NULL__null; |
589 | for(uint32_t i=0; i<F1tts.size(); i++){ |
590 | if( (F1tts[i]->rocid==rocid) && (F1tts[i]->slot==slot) ){ |
591 | tt = F1tts[i]; |
592 | break; |
593 | } |
594 | } |
595 | |
596 | |
597 | uint32_t itrigger = (tt==NULL__null) ? (Nevents&0x3FFFFF):tt->DDAQAddress::itrigger; |
598 | uint64_t trig_time = (tt==NULL__null) ? time(NULL__null):tt->time; |
599 | |
600 | |
601 | uint32_t block_header_idx = buff.size(); |
602 | buff.push_back( 0x80000101 + (modtype<<18) + (slot<<22) ); |
603 | buff.push_back( 0x90000000 + (slot<<22) + itrigger); |
604 | |
605 | |
606 | buff.push_back(0x98000000 + ((trig_time>>0 )&0x00FFFFFF)); |
607 | buff.push_back(0x00000000 + ((trig_time>>24)&0x00FFFFFF)); |
608 | |
609 | |
610 | vector<const DF1TDCHit*> &hits = it2->second; |
611 | for(uint32_t i=0; i<hits.size(); i++){ |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | |
619 | |
620 | |
621 | |
622 | |
623 | |
624 | |
625 | |
626 | |
627 | |
628 | |
629 | |
630 | uint32_t data_word = hits[i]->data_word; |
631 | uint32_t chip_header = 0xC0000000; |
632 | chip_header += (data_word&0x07000000); |
633 | chip_header += (hits[i]->trig_time<<7)&0x01FF; |
634 | chip_header += (data_word>>16)&0x3F; |
635 | buff.push_back( chip_header ); |
636 | |
637 | |
638 | buff.push_back( data_word ); |
639 | } |
640 | |
641 | |
642 | uint32_t Nwords_in_block = buff.size()-block_header_idx+1; |
643 | buff.push_back( 0x88000000 + (slot<<22) + Nwords_in_block ); |
644 | } |
645 | |
646 | |
647 | buff[data_block_bank_idx] = buff.size() - data_block_bank_idx - 1; |
648 | |
649 | |
650 | buff[data_bank_idx] = buff.size() - data_bank_idx - 1; |
651 | } |
652 | } |
653 | |
654 | |
655 | |
656 | |
657 | void DEventWriterEVIO::Writef250Data(vector<uint32_t> &buff, |
658 | vector<const Df250PulseIntegral*> &f250pis, |
659 | vector<const Df250TriggerTime*> &f250tts, |
660 | vector<const Df250WindowRawData*> &f250wrds, |
661 | unsigned int Nevents) const |
662 | { |
663 | |
664 | |
665 | map<uint32_t, map<uint32_t, vector<const Df250PulseIntegral*> > > modules; |
666 | map<uint32_t, set<const Df250Config*> > configs; |
667 | for(uint32_t i=0; i<f250pis.size(); i++){ |
668 | const Df250PulseIntegral *pi = f250pis[i]; |
669 | modules[pi->rocid][pi->slot].push_back(pi); |
670 | |
671 | const Df250Config *config = NULL__null; |
672 | pi->GetSingle(config); |
673 | if(config) configs[pi->rocid].insert(config); |
674 | } |
675 | |
676 | |
677 | |
678 | |
679 | for(uint32_t i=0; i<f250wrds.size(); i++) modules[f250wrds[i]->rocid][f250wrds[i]->slot]; |
680 | |
681 | |
682 | map<uint32_t, map<uint32_t, vector<const Df250PulseIntegral*> > >::iterator it; |
683 | for(it=modules.begin(); it!=modules.end(); it++){ |
684 | uint32_t rocid = it->first; |
685 | |
686 | |
687 | uint32_t data_bank_idx = buff.size(); |
688 | buff.push_back(0); |
689 | buff.push_back( (rocid<<16) + 0x1001 ); |
690 | |
691 | |
692 | set<const Df250Config*> &confs = configs[rocid]; |
693 | if(!confs.empty()){ |
694 | |
695 | uint32_t config_bank_idx = buff.size(); |
696 | buff.push_back(0); |
697 | buff.push_back( 0x00550101 ); |
698 | |
699 | set<const Df250Config*>::iterator it_conf; |
700 | for(it_conf=confs.begin(); it_conf!=confs.end(); it_conf++){ |
701 | const Df250Config *conf = *it_conf; |
702 | |
703 | uint32_t header_idx = buff.size(); |
704 | buff.push_back(0); |
705 | uint32_t Nvals = 0; |
706 | if(conf->NSA != 0xFFFF) {buff.push_back( (kPARAM250_NSA <<16) + conf->NSA ); Nvals++;} |
707 | if(conf->NSB != 0xFFFF) {buff.push_back( (kPARAM250_NSB <<16) + conf->NSB ); Nvals++;} |
708 | if(conf->NSA_NSB != 0xFFFF) {buff.push_back( (kPARAM250_NSA_NSB<<16) + conf->NSA_NSB); Nvals++;} |
709 | if(conf->NPED != 0xFFFF) {buff.push_back( (kPARAM250_NPED <<16) + conf->NPED ); Nvals++;} |
710 | |
711 | buff[header_idx] = (Nvals<<24) + conf->slot_mask; |
712 | } |
713 | |
714 | |
715 | buff[config_bank_idx] = buff.size() - config_bank_idx - 1; |
716 | } |
717 | |
718 | |
719 | |
720 | |
721 | |
722 | |
723 | |
724 | |
725 | |
726 | |
727 | |
728 | uint32_t data_block_bank_idx = buff.size(); |
729 | buff.push_back(0); |
730 | buff.push_back(0x00060101); |
731 | |
732 | |
733 | map<uint32_t, vector<const Df250PulseIntegral*> >::iterator it2; |
734 | for(it2=it->second.begin(); it2!=it->second.end(); it2++){ |
735 | uint32_t slot = it2->first; |
736 | |
737 | |
738 | const Df250TriggerTime *tt = NULL__null; |
739 | for(uint32_t i=0; i<f250tts.size(); i++){ |
740 | if( (f250tts[i]->rocid==rocid) && (f250tts[i]->slot==slot) ){ |
741 | tt = f250tts[i]; |
742 | break; |
743 | } |
744 | } |
745 | |
746 | |
747 | |
748 | |
749 | uint32_t itrigger = (tt==NULL__null) ? (Nevents&0x3FFFFF):tt->itrigger; |
750 | uint64_t trig_time = (tt==NULL__null) ? time(NULL__null):tt->time; |
751 | |
752 | |
753 | uint32_t block_header_idx = buff.size(); |
754 | buff.push_back( 0x80040101 + (slot<<22) ); |
755 | buff.push_back( 0x90000000 + (slot<<22) + itrigger); |
756 | |
757 | |
758 | buff.push_back(0x98000000 + ((trig_time>>0 )&0x00FFFFFF)); |
759 | buff.push_back(0x00000000 + ((trig_time>>24)&0x00FFFFFF)); |
760 | |
761 | |
762 | vector<const Df250PulseIntegral*> &pis = it2->second; |
763 | for(uint32_t i=0; i<pis.size(); i++){ |
764 | const Df250PulseIntegral *pi = pis[i]; |
765 | const Df250PulseTime *pt = NULL__null; |
766 | const Df250PulsePedestal *pp = NULL__null; |
767 | pi->GetSingle(pt); |
768 | pi->GetSingle(pp); |
769 | |
770 | |
771 | if(pi->emulated == PREFER_EMULATED){ |
772 | buff.push_back(0xB8000000 + (pi->channel<<23) + (pi->pulse_number<<21) + (pi->quality_factor<<19) + (pi->integral&0x7FFFF) ); |
773 | } |
774 | |
775 | |
776 | if(pt && (pt->emulated == PREFER_EMULATED) ){ |
777 | buff.push_back(0xC0000000 + (pt->channel<<23) + (pt->pulse_number<<21) + (pt->quality_factor<<19) + (pt->time&0x7FFFF) ); |
778 | } |
779 | |
780 | |
781 | if(pp && (pp->emulated == PREFER_EMULATED) ){ |
782 | buff.push_back(0xD0000000 + (pp->channel<<23) + (pp->pulse_number<<21) + (pp->pedestal<<12) + (pp->pulse_peak&0x0FFF) ); |
783 | } |
784 | } |
785 | |
786 | |
787 | |
788 | |
789 | if(!PREFER_EMULATED){ |
790 | for(uint32_t i=0; i<f250wrds.size(); i++){ |
791 | const Df250WindowRawData *wrd = f250wrds[i]; |
792 | if(wrd->rocid!=rocid || wrd->slot!=slot) continue; |
793 | |
794 | |
795 | |
796 | |
797 | |
798 | buff.push_back(0xA0000000 + (wrd->channel<<23) + (wrd->samples.size()) ); |
799 | for(uint32_t j=0; j<(wrd->samples.size()+1)/2; j++){ |
800 | uint32_t idx1 = 2*j; |
801 | uint32_t idx2 = idx1 + 1; |
802 | uint32_t sample_1 = wrd->samples[idx1]; |
803 | uint32_t sample_2 = idx2<wrd->samples.size() ? wrd->samples[idx2]:0; |
804 | uint32_t invalid1 = 0; |
805 | uint32_t invalid2 = idx2>=wrd->samples.size(); |
806 | buff.push_back( (invalid1<<29) + (sample_1<<16) + (invalid2<<13) + (sample_2<<0) ); |
807 | } |
808 | } |
809 | } |
810 | |
811 | |
812 | uint32_t Nwords_in_block = buff.size()-block_header_idx+1; |
813 | buff.push_back( 0x88000000 + (slot<<22) + Nwords_in_block ); |
814 | } |
815 | |
816 | |
817 | buff[data_block_bank_idx] = buff.size() - data_block_bank_idx - 1; |
818 | |
819 | |
820 | buff[data_bank_idx] = buff.size() - data_bank_idx - 1; |
821 | } |
822 | } |
823 | |
824 | |
825 | |
826 | |
827 | void DEventWriterEVIO::Writef125Data(vector<uint32_t> &buff, |
828 | vector<const Df125PulseIntegral*> &f125pis, |
829 | vector<const Df125CDCPulse*> &f125cdcpulses, |
830 | vector<const Df125FDCPulse*> &f125fdcpulses, |
831 | vector<const Df125TriggerTime*> &f125tts, |
832 | vector<const Df125WindowRawData*> &f125wrds, |
833 | vector<const Df125Config*> &f125configs, |
834 | unsigned int Nevents) const |
835 | { |
836 | |
837 | |
838 | map<uint32_t, set<uint32_t> > modules; |
839 | map<uint32_t, map<uint32_t, vector<const Df125PulseIntegral*> > > pi_hits; |
840 | map<uint32_t, map<uint32_t, vector<const Df125CDCPulse* > > > cdc_hits; |
841 | map<uint32_t, map<uint32_t, vector<const Df125FDCPulse* > > > fdc_hits; |
842 | map<uint32_t, map<uint32_t, vector<const Df125WindowRawData*> > > wrd_hits; |
843 | for(uint32_t i=0; i<f125pis.size(); i++){ |
844 | const Df125PulseIntegral *hit = f125pis[i]; |
845 | modules[hit->rocid].insert(hit->slot); |
846 | pi_hits[hit->rocid][hit->slot].push_back( hit ); |
847 | } |
848 | for(uint32_t i=0; i<f125cdcpulses.size(); i++){ |
849 | const Df125CDCPulse *hit = f125cdcpulses[i]; |
850 | modules[hit->rocid].insert(hit->slot); |
851 | cdc_hits[hit->rocid][hit->slot].push_back( hit ); |
852 | } |
853 | for(uint32_t i=0; i<f125fdcpulses.size(); i++){ |
854 | const Df125FDCPulse *hit = f125fdcpulses[i]; |
855 | modules[hit->rocid].insert(hit->slot); |
856 | fdc_hits[hit->rocid][hit->slot].push_back( hit ); |
857 | } |
858 | for(uint32_t i=0; i<f125wrds.size(); i++){ |
859 | const Df125WindowRawData *hit = f125wrds[i]; |
860 | modules[hit->rocid].insert(hit->slot); |
861 | wrd_hits[hit->rocid][hit->slot].push_back( hit ); |
862 | } |
863 | |
864 | |
865 | map<uint32_t, set<const Df125Config*> > configs; |
866 | for(uint32_t i=0; i<f125configs.size(); i++){ |
867 | const Df125Config *config = f125configs[i]; |
868 | configs[config->rocid].insert(config); |
869 | } |
870 | |
871 | |
872 | map<uint32_t, set<uint32_t> >::iterator it; |
873 | for(it=modules.begin(); it!=modules.end(); it++){ |
874 | uint32_t rocid = it->first; |
875 | |
876 | |
877 | uint32_t data_bank_idx = buff.size(); |
878 | buff.push_back(0); |
879 | buff.push_back( (rocid<<16) + 0x1001 ); |
880 | |
881 | |
882 | set<const Df125Config*> &confs = configs[rocid]; |
883 | if(!confs.empty()){ |
884 | |
885 | uint32_t config_bank_idx = buff.size(); |
886 | buff.push_back(0); |
887 | buff.push_back( 0x00550101 ); |
888 | |
889 | set<const Df125Config*>::iterator it_conf; |
890 | for(it_conf=confs.begin(); it_conf!=confs.end(); it_conf++){ |
891 | const Df125Config *conf = *it_conf; |
892 | |
893 | uint32_t header_idx = buff.size(); |
894 | buff.push_back(0); |
895 | uint32_t Nvals = 0; |
896 | if(conf->NSA != 0xFFFF) {buff.push_back( (kPARAM125_NSA <<16) + conf->NSA ); Nvals++;} |
897 | if(conf->NSB != 0xFFFF) {buff.push_back( (kPARAM125_NSB <<16) + conf->NSB ); Nvals++;} |
898 | if(conf->NSA_NSB != 0xFFFF) {buff.push_back( (kPARAM125_NSA_NSB <<16) + conf->NSA_NSB ); Nvals++;} |
899 | if(conf->NPED != 0xFFFF) {buff.push_back( (kPARAM125_NPED <<16) + conf->NPED ); Nvals++;} |
900 | if(conf->WINWIDTH!= 0xFFFF) {buff.push_back( (kPARAM125_WINWIDTH<<16) + conf->WINWIDTH); Nvals++;} |
901 | |
902 | |
903 | if(conf->PL != 0xFFFF) {buff.push_back( (kPARAM125_PL <<16) + conf->PL ); Nvals++;} |
904 | if(conf->NW != 0xFFFF) {buff.push_back( (kPARAM125_NW <<16) + conf->NW ); Nvals++;} |
905 | if(conf->NPK != 0xFFFF) {buff.push_back( (kPARAM125_NPK <<16) + conf->NPK ); Nvals++;} |
906 | if(conf->P1 != 0xFFFF) {buff.push_back( (kPARAM125_P1 <<16) + conf->P1 ); Nvals++;} |
907 | if(conf->P2 != 0xFFFF) {buff.push_back( (kPARAM125_P2 <<16) + conf->P2 ); Nvals++;} |
908 | if(conf->PG != 0xFFFF) {buff.push_back( (kPARAM125_PG <<16) + conf->PG ); Nvals++;} |
909 | if(conf->IE != 0xFFFF) {buff.push_back( (kPARAM125_IE <<16) + conf->IE ); Nvals++;} |
910 | if(conf->H != 0xFFFF) {buff.push_back( (kPARAM125_H <<16) + conf->H ); Nvals++;} |
911 | if(conf->TH != 0xFFFF) {buff.push_back( (kPARAM125_TH <<16) + conf->TH ); Nvals++;} |
912 | if(conf->TL != 0xFFFF) {buff.push_back( (kPARAM125_TL <<16) + conf->TL ); Nvals++;} |
913 | if(conf->IBIT != 0xFFFF) {buff.push_back( (kPARAM125_IBIT <<16) + conf->IBIT ); Nvals++;} |
914 | if(conf->ABIT != 0xFFFF) {buff.push_back( (kPARAM125_ABIT <<16) + conf->ABIT ); Nvals++;} |
915 | if(conf->PBIT != 0xFFFF) {buff.push_back( (kPARAM125_PBIT <<16) + conf->PBIT ); Nvals++;} |
916 | |
917 | buff[header_idx] = (Nvals<<24) + conf->slot_mask; |
918 | } |
919 | |
920 | |
921 | buff[config_bank_idx] = buff.size() - config_bank_idx - 1; |
922 | } |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | |
930 | |
931 | |
932 | |
933 | |
934 | uint32_t data_block_bank_idx = buff.size(); |
935 | buff.push_back(0); |
936 | buff.push_back(0x00100101); |
937 | |
938 | |
939 | set<uint32_t>::iterator it2; |
940 | for(it2=it->second.begin(); it2!=it->second.end(); it2++){ |
941 | uint32_t slot = *it2; |
942 | |
943 | |
944 | const Df125TriggerTime *tt = NULL__null; |
945 | for(uint32_t i=0; i<f125tts.size(); i++){ |
946 | if( (f125tts[i]->rocid==rocid) && (f125tts[i]->slot==slot) ){ |
947 | tt = f125tts[i]; |
948 | break; |
949 | } |
950 | } |
951 | |
952 | |
953 | |
954 | |
955 | uint32_t itrigger = (tt==NULL__null) ? (Nevents&0x3FFFFF):tt->DDAQAddress::itrigger; |
956 | uint64_t trig_time = (tt==NULL__null) ? time(NULL__null):tt->time; |
957 | |
958 | |
959 | uint32_t block_header_idx = buff.size(); |
960 | buff.push_back( 0x80080101 + (slot<<22) ); |
961 | buff.push_back( 0x90000000 + itrigger); |
962 | |
963 | |
964 | buff.push_back(0x98000000 + ((trig_time>>0 )&0x00FFFFFF)); |
965 | buff.push_back(0x00000000 + ((trig_time>>24)&0x00FFFFFF)); |
966 | |
967 | |
968 | vector<const Df125PulseIntegral*> &pis = pi_hits[rocid][slot]; |
969 | for(uint32_t i=0; i<pis.size(); i++){ |
970 | const Df125PulseIntegral *pi = pis[i]; |
971 | const Df125PulseTime *pt = NULL__null; |
972 | const Df125PulsePedestal *pp = NULL__null; |
973 | pi->GetSingle(pt); |
974 | pi->GetSingle(pp); |
975 | |
976 | |
977 | if(pi->emulated == PREFER_EMULATED){ |
978 | buff.push_back(0xB8000000 + (pi->channel<<20) + (pi->integral&0x7FFFF) ); |
979 | } |
980 | |
981 | |
982 | if(pt && (pt->emulated == PREFER_EMULATED) ){ |
983 | buff.push_back(0xC0000000 + (pt->channel<<20) + (pt->pulse_number<<18) + (pt->time&0x7FFFF) ); |
984 | } |
985 | |
986 | |
987 | if(pp && (pp->emulated == PREFER_EMULATED) ){ |
988 | buff.push_back(0xD0000000 + (pp->pulse_number<<21) + (pp->pedestal<<12) + (pp->pulse_peak&0x0FFF) ); |
989 | } |
990 | } |
991 | |
992 | |
993 | vector<const Df125CDCPulse*> &cdcpulses = cdc_hits[rocid][slot]; |
994 | for(uint32_t i=0; i<cdcpulses.size(); i++){ |
995 | const Df125CDCPulse *pulse = cdcpulses[i]; |
996 | |
997 | if(pulse->emulated == PREFER_EMULATED){ |
998 | buff.push_back( pulse->word1 ); |
999 | buff.push_back( pulse->word2 ); |
1000 | } |
1001 | } |
1002 | |
1003 | |
1004 | vector<const Df125FDCPulse*> &fdcpulses = fdc_hits[rocid][slot]; |
1005 | for(uint32_t i=0; i<fdcpulses.size(); i++){ |
1006 | const Df125FDCPulse *pulse = fdcpulses[i]; |
1007 | |
1008 | if(pulse->emulated == PREFER_EMULATED){ |
1009 | buff.push_back( pulse->word1 ); |
1010 | buff.push_back( pulse->word2 ); |
1011 | } |
1012 | } |
1013 | |
1014 | |
1015 | |
1016 | |
1017 | if(!PREFER_EMULATED){ |
1018 | vector<const Df125WindowRawData*> &wrds = wrd_hits[rocid][slot]; |
1019 | for(uint32_t i=0; i<wrds.size(); i++){ |
1020 | const Df125WindowRawData *wrd = wrds[i]; |
1021 | |
1022 | |
1023 | |
1024 | |
1025 | |
1026 | buff.push_back(0xA0000000 + (wrd->channel<<20) + (wrd->channel<<15) + (wrd->samples.size()) ); |
1027 | for(uint32_t j=0; j<(wrd->samples.size()+1)/2; j++){ |
1028 | uint32_t idx1 = 2*j; |
1029 | uint32_t idx2 = idx1 + 1; |
1030 | uint32_t sample_1 = wrd->samples[idx1]; |
1031 | uint32_t sample_2 = idx2<wrd->samples.size() ? wrd->samples[idx2]:0; |
1032 | uint32_t invalid1 = 0; |
1033 | uint32_t invalid2 = idx2>=wrd->samples.size(); |
1034 | buff.push_back( (invalid1<<29) + (sample_1<<16) + (invalid2<<13) + (sample_2<<0) ); |
1035 | } |
1036 | } |
1037 | } |
1038 | |
1039 | |
1040 | uint32_t Nwords_in_block = buff.size()-block_header_idx+1; |
1041 | buff.push_back( 0x88000000 + (slot<<22) + Nwords_in_block ); |
1042 | } |
1043 | |
1044 | |
1045 | buff[data_block_bank_idx] = buff.size() - data_block_bank_idx - 1; |
1046 | |
1047 | |
1048 | buff[data_bank_idx] = buff.size() - data_bank_idx - 1; |
1049 | } |
1050 | } |
1051 | |
1052 | |
1053 | |
1054 | |
1055 | void DEventWriterEVIO::WriteEPICSData(vector<uint32_t> &buff, |
1056 | vector<const DEPICSvalue*> epicsValues) const |
1057 | { |
1058 | |
1059 | |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | |
1067 | |
1068 | |
1069 | |
1070 | |
1071 | |
1072 | |
1073 | if(epicsValues.size() == 0) return; |
1074 | |
1075 | |
1076 | uint32_t epics_bank_idx = buff.size(); |
1077 | buff.push_back(0); |
1078 | buff.push_back( (0x60<<16) + (0xD<<8) + (0x1<<0) ); |
1079 | |
1080 | |
1081 | buff.push_back( (0x61<<24) + (0x1<<16) + (1<<0) ); |
1082 | buff.push_back( (uint32_t)epicsValues[0]->timestamp ); |
1083 | |
1084 | |
1085 | for(uint32_t i=0; i<epicsValues.size(); i++){ |
1086 | const DEPICSvalue *epicsval = epicsValues[i]; |
1087 | const string &str = epicsval->nameval; |
1088 | uint32_t Nbytes = str.size()+1; |
1089 | uint32_t Nwords = (Nbytes+3)/4; |
1090 | uint32_t Npad = (Nwords*4) - Nbytes; |
1091 | |
1092 | buff.push_back( (0x62<<24) + (Npad<<22) + (0x7<<16) + (Nwords<<0) ); |
1093 | |
1094 | |
1095 | uint32_t buff_str_idx = buff.size(); |
1096 | buff.resize( buff_str_idx + Nwords ); |
1097 | |
1098 | unsigned char *ichar = (unsigned char*)&buff[buff_str_idx]; |
1099 | for(unsigned int j=0; j<Nbytes; j++) ichar[j] = str[j]; |
1100 | } |
1101 | |
1102 | |
1103 | buff[epics_bank_idx] = buff.size() - epics_bank_idx - 1; |
1104 | } |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | void DEventWriterEVIO::WriteEventTagData(vector<uint32_t> &buff, |
1110 | uint64_t event_status, |
1111 | const DL3Trigger* l3trigger) const |
1112 | { |
1113 | |
1114 | |
1115 | |
1116 | |
1117 | |
1118 | |
1119 | uint32_t eventtag_bank_idx = buff.size(); |
1120 | |
1121 | uint64_t L3_status = 0; |
1122 | uint32_t L3_decision = 0; |
1123 | uint32_t L3_algorithm = 0; |
1124 | if(l3trigger){ |
1125 | L3_status = l3trigger->status; |
1126 | L3_decision = l3trigger->L3_decision; |
1127 | L3_algorithm = l3trigger->algorithm; |
1128 | } |
1129 | |
1130 | |
1131 | |
1132 | |
1133 | switch(L3_decision){ |
1134 | case DL3Trigger::kKEEP_EVENT : event_status |= kSTATUS_L3PASS; break; |
1135 | case DL3Trigger::kDISCARD_EVENT: event_status |= kSTATUS_L3FAIL; break; |
1136 | case DL3Trigger::kNO_DECISION : break; |
1137 | } |
1138 | |
1139 | |
1140 | buff.push_back(0); |
1141 | buff.push_back( 0x00560101 ); |
1142 | |
1143 | |
1144 | buff.push_back( (event_status>> 0)&0xFFFFFFFF ); |
1145 | buff.push_back( (event_status>>32)&0xFFFFFFFF ); |
1146 | |
1147 | |
1148 | buff.push_back( (L3_status>> 0)&0xFFFFFFFF ); |
1149 | buff.push_back( (L3_status>>32)&0xFFFFFFFF ); |
1150 | |
1151 | |
1152 | buff.push_back( L3_decision ); |
1153 | |
1154 | |
1155 | buff.push_back( L3_algorithm ); |
1156 | |
1157 | |
1158 | buff[eventtag_bank_idx] = buff.size() - eventtag_bank_idx - 1; |
1159 | } |
1160 | |
1161 | |
1162 | |
1163 | |
1164 | |
1165 | void DEventWriterEVIO::WriteBORData(JEventLoop *loop, vector<uint32_t> &buff) const |
1166 | { |
1167 | |
1168 | |
1169 | |
1170 | |
1171 | |
1172 | |
1173 | |
1174 | |
1175 | void *ref = loop->GetJEvent().GetRef(); |
1176 | uint32_t *in_buff = JEventSource_EVIO::GetEVIOBufferFromRef(ref); |
1177 | uint32_t buff_size = JEventSource_EVIO::GetEVIOBufferSizeFromRef(ref); |
| Value stored to 'buff_size' during its initialization is never read |
1178 | |
1179 | uint32_t Nwords = in_buff[0]; |
1180 | |
1181 | for(uint32_t i=0; i<Nwords+1; i++) buff.push_back( in_buff[i] ); |
1182 | |
1183 | } |