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