clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name Df250EmulatorAlgorithm_v3.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0 -D HAVE_EVIO -D HAVE_TMVA=1 -I .Linux_CentOS7.7-x86_64-gcc4.8.5/libraries/DAQ -I libraries/DAQ -I . -I libraries -I libraries/include -I /w/halld-scifs17exp/home/sdobbs/clang/halld_recon/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I libraries -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/evio/evio-4.4.6/Linux-x86_64/include -I /w/halld-scifs17exp/halld2/home/sdobbs/Software/jana/jana_0.8.2/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/root/root-6.08.06/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward -internal-isystem /usr/local/include -internal-isystem /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/sdobbs/work/clang/halld_recon/src -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-01-21-110224-160369-1 -x c++ libraries/DAQ/Df250EmulatorAlgorithm_v3.cc
1 | #include <DAQ/Df250EmulatorAlgorithm_v3.h> |
2 | |
3 | |
4 | |
5 | Df250EmulatorAlgorithm_v3::Df250EmulatorAlgorithm_v3(JEventLoop *loop){ |
6 | |
7 | FORCE_DEFAULT = 0; |
8 | |
9 | USE_CRATE_DEFAULTS = 1; |
10 | |
11 | |
12 | NSA_DEF = 20; |
13 | NSB_DEF = 5; |
14 | THR_DEF = 120; |
15 | NPED_DEF = 4; |
16 | MAXPED_DEF = 512; |
17 | NSAT_DEF = 2; |
18 | |
19 | |
20 | NSA_DEF = 15; |
21 | NSB_DEF = 1; |
22 | THR_DEF = 108; |
23 | NPED_DEF = 4; |
24 | MAXPED_DEF = 512; |
25 | NSAT_DEF = 2; |
26 | |
27 | |
28 | |
29 | VERBOSE = 0; |
30 | |
31 | if(gPARMS){ |
32 | gPARMS->SetDefaultParameter("EMULATION250:USE_CRATE_DEFAULTS", USE_CRATE_DEFAULTS,"Set to >0 to force use of crate-dependent default values"); |
33 | gPARMS->SetDefaultParameter("EMULATION250:FORCE_DEFAULT", FORCE_DEFAULT,"Set to >0 to force use of default values"); |
34 | gPARMS->SetDefaultParameter("EMULATION250:NSA", NSA_DEF,"Set NSA for firmware emulation, will be overwritten by BORConfig if present"); |
35 | gPARMS->SetDefaultParameter("EMULATION250:NSB", NSB_DEF,"Set NSB for firmware emulation, will be overwritten by BORConfig if present"); |
36 | gPARMS->SetDefaultParameter("EMULATION250:THR", THR_DEF,"Set threshold for firmware emulation, will be overwritten by BORConfig if present"); |
37 | gPARMS->SetDefaultParameter("EMULATION250:NPED", NPED_DEF,"Set NPED for firmware emulation, will be overwritten by BORConfig if present"); |
38 | gPARMS->SetDefaultParameter("EMULATION250:MAXPED", MAXPED_DEF,"Set MAXPED for firmware emulation, will be overwritten by BORConfig if present"); |
39 | gPARMS->SetDefaultParameter("EMULATION250:NSAT", NSAT_DEF,"Set NSAT for firmware emulation, will be overwritten by BORConfig if present"); |
40 | gPARMS->SetDefaultParameter("EMULATION250:VERBOSE", VERBOSE,"Set verbosity for f250 emulation"); |
41 | } |
42 | } |
43 | |
44 | void Df250EmulatorAlgorithm_v3::EmulateFirmware(const Df250WindowRawData* rawData, |
45 | std::vector<Df250PulseData*> &pdat_objs) |
46 | { |
47 | |
48 | if (VERBOSE > 0) { |
| 1 | Assuming field 'VERBOSE' is <= 0 | |
|
| |
49 | jout << " Df250EmulatorAlgorithm_v3::EmulateFirmware ==> Starting emulation <==" << endl; |
50 | jout << "rocid : " << rawData->rocid << " slot: " << rawData->slot << " channel: " << rawData->channel << endl; |
51 | } |
52 | |
53 | |
54 | if (rawData == NULL) { |
| 3 | | Assuming 'rawData' is not equal to NULL | |
|
| |
55 | jerr << " ERROR: Df250EmulatorAlgorithm_v3::EmulateFirmware - raw sample data is missing" << endl; |
56 | jerr << " Contact mstaib@jlab.org" << endl; |
57 | return; |
58 | } |
59 | if (rawData->samples.size() == 0) { |
| 5 | | Assuming the condition is false | |
|
| |
60 | jerr << " ERROR: Df250EmulatorAlgorithm_v3::EmulateFirmware - raw sample data has zero size" << endl; |
61 | jerr << "rocid : " << rawData->rocid << " slot: " << rawData->slot << " channel: " << rawData->channel << endl; |
62 | |
63 | return; |
64 | } |
65 | |
66 | |
67 | uint32_t channel = rawData->channel; |
68 | |
69 | |
70 | |
71 | |
72 | const Df250BORConfig *f250BORConfig = NULL; |
73 | rawData->GetSingle(f250BORConfig); |
| 7 | | Calling 'JObject::GetSingle' | |
|
| 12 | | Returning from 'JObject::GetSingle' | |
|
74 | |
75 | uint32_t NSA; |
76 | int32_t NSB; |
77 | uint32_t NPED, MAXPED; |
78 | uint16_t THR; |
79 | uint16_t NSAT; |
80 | |
81 | if (f250BORConfig == NULL || FORCE_DEFAULT){ |
| 13 | | Assuming field 'FORCE_DEFAULT' is 0 | |
|
| |
82 | static int counter = 0; |
83 | NSA = NSA_DEF; |
84 | NSB = NSB_DEF; |
85 | THR = THR_DEF; |
86 | NPED = NPED_DEF; |
87 | MAXPED = MAXPED_DEF; |
88 | NSAT = NSAT_DEF; |
89 | if (counter < 10){ |
90 | counter++; |
91 | if (counter == 10) jout << " WARNING Df250EmulatorAlgorithm_v3::EmulateFirmware No Df250BORConfig == Using default values == LAST WARNING" << endl; |
92 | else jout << " WARNING Df250EmulatorAlgorithm_v3::EmulateFirmware No Df250BORConfig == Using default values " << endl; |
93 | |
94 | } |
95 | |
96 | |
97 | if(USE_CRATE_DEFAULTS) { |
98 | |
99 | |
100 | if( (rawData->rocid >= 11) && (rawData->rocid <= 22) ) { |
101 | NSA = 15; |
102 | NSB = 1; |
103 | THR = 108; |
104 | |
105 | |
106 | NSAT = 2; |
107 | } |
108 | |
109 | else if( (rawData->rocid >= 31) && (rawData->rocid <= 46) ) { |
110 | NSA = 26; |
111 | NSB = 1; |
112 | THR = 105; |
113 | |
114 | |
115 | NSAT = 2; |
116 | } |
117 | |
118 | else if( (rawData->rocid == 73) || (rawData->rocid == 74) || ( (rawData->rocid == 75) && (rawData->slot >= 7) && (rawData->slot <= 16)) ) { |
119 | NSA = 6; |
120 | NSB = 3; |
121 | THR = 300; |
122 | |
123 | |
124 | NSAT = 2; |
125 | } |
126 | |
127 | else if( (rawData->rocid == 71) || (rawData->rocid == 72) || ( (rawData->rocid == 75) && (rawData->slot >= 3) && (rawData->slot <= 6)) ) { |
128 | NSA = 6; |
129 | NSB = 3; |
130 | THR = 150; |
131 | |
132 | |
133 | NSAT = 2; |
134 | } |
135 | |
136 | else if( rawData->rocid == 77 ) { |
137 | NSA = 10; |
138 | NSB = 1; |
139 | THR = 160; |
140 | |
141 | |
142 | NSAT = 2; |
143 | } |
144 | |
145 | else if( (rawData->rocid >= 83) && (rawData->rocid <= 84) ) { |
146 | NSA = 10; |
147 | NSB = 3; |
148 | THR = 130; |
149 | |
150 | |
151 | NSAT = 2; |
152 | } |
153 | |
154 | else if( rawData->rocid == 94 ) { |
155 | NSA = 20; |
156 | NSB = 5; |
157 | THR = 120; |
158 | |
159 | |
160 | NSAT = 2; |
161 | } |
162 | } |
163 | } |
164 | else{ |
165 | NSA = f250BORConfig->NSA; |
166 | NSB = f250BORConfig->NSB; |
167 | THR = f250BORConfig->adc_thres[channel]; |
168 | NPED = f250BORConfig->NPED; |
| 15 | | Value assigned to 'NPED' | |
|
169 | MAXPED = f250BORConfig->MaxPed; |
170 | NSAT = f250BORConfig->NSAT; |
171 | |
172 | } |
173 | |
174 | if (VERBOSE > 0) jout << "Df250EmulatorAlgorithm_v3::EmulateFirmware NSA: " << NSA << " NSB: " << NSB << " THR: " << THR << endl; |
| |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | bool bad_pedestal = false; |
189 | bool bad_timing_pedestal = false; |
190 | bool no_timing_calculation = false; |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | vector<uint16_t> samples = rawData->samples; |
198 | uint16_t NW = samples.size(); |
199 | uint32_t npulses = 0; |
200 | const int max_pulses = 3; |
201 | uint32_t TC[max_pulses] = {}; |
202 | uint32_t TMIN[max_pulses] = {3}; |
203 | |
204 | uint32_t pulse_integral[max_pulses] = {}; |
205 | bool has_overflow_samples[max_pulses] = {false}; |
206 | bool has_underflow_samples[max_pulses] = {false}; |
207 | uint32_t number_samples_above_threshold[max_pulses] = {0}; |
208 | bool NSA_beyond_PTW[max_pulses] = {false}; |
209 | bool vpeak_beyond_NSA[max_pulses] = {false}; |
210 | bool vpeak_not_found[max_pulses] = {false}; |
211 | |
212 | |
213 | if(VERBOSE > 0) { |
| |
214 | for (unsigned int i=0; i < NW; i++) { |
215 | if(VERBOSE > 2) { |
216 | if(samples[i] == 0x1fff) |
217 | jout << "Overflow at sample " << i << endl; |
218 | if(samples[i] == 0x1000) |
219 | jout << "Underflow at sample " << i << endl; |
220 | } |
221 | if (VERBOSE > 5) jout << "Df250EmulatorAlgorithm_v3::EmulateFirmware samples[" << i << "]: " << samples[i] << endl; |
222 | } |
223 | } |
224 | |
225 | |
226 | |
227 | |
228 | unsigned int MAX_SAMPLE = NW-NSAT; |
229 | |
230 | |
231 | for (unsigned int i=0; i < MAX_SAMPLE; i++) { |
| 18 | | Assuming 'i' is >= 'MAX_SAMPLE' | |
|
| 19 | | Loop condition is false. Execution continues on line 312 | |
|
232 | if ((samples[i] & 0xfff) > THR) { |
233 | if (VERBOSE > 1) { |
234 | jout << "threshold crossing at " << i << endl; |
235 | } |
236 | |
237 | |
238 | TC[npulses] = i+1; |
239 | |
240 | |
241 | if( NSAT>1 ){ |
242 | int samples_over_threshold = 1; |
243 | |
244 | if(i==0) { |
245 | |
246 | |
247 | for(unsigned int j=i+1; ((samples[j]&0xfff)>THR) && (j<MAX_SAMPLE+1); j++) { |
248 | |
249 | if ((samples[j] & 0xfff) > THR) |
250 | samples_over_threshold++; |
251 | |
252 | if( samples_over_threshold == NSAT ) { |
253 | |
254 | |
255 | break; |
256 | } |
257 | |
258 | } |
259 | } else { |
260 | for(unsigned int j=i+1; ((samples[j]&0xfff)>THR) && (j<MAX_SAMPLE+1); j++) { |
261 | samples_over_threshold++; |
262 | |
263 | if( samples_over_threshold == NSAT ) |
264 | break; |
265 | } |
266 | } |
267 | |
268 | |
269 | if( samples_over_threshold != NSAT ) |
270 | continue; |
271 | } |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | |
278 | unsigned int ibegin; |
279 | if(NSB > 0) |
280 | ibegin = i > uint32_t(NSB) ? (i - NSB) : 0; |
281 | else { |
282 | ibegin = i - NSB; |
283 | if(ibegin > uint32_t(NW)) |
284 | break; |
285 | } |
286 | unsigned int iend = (i + NSA) < uint32_t(NW) ? (i + NSA) : NW; |
287 | |
288 | NSA_beyond_PTW[npulses] = (i + NSA - 1) >= uint32_t(NW); |
289 | for (i = ibegin; i < iend; ++i) { |
290 | pulse_integral[npulses] += (samples[i] & 0xfff); |
291 | |
292 | if(samples[i] == 0x1fff) { |
293 | has_overflow_samples[npulses] = true; |
294 | } |
295 | if(samples[i] == 0x1000) { |
296 | has_underflow_samples[npulses] = true; |
297 | } |
298 | |
299 | if( (i+1>=TC[npulses]) && ((samples[i] & 0xfff) > THR) ) |
300 | number_samples_above_threshold[npulses]++; |
301 | } |
302 | for (; i < NW && (samples[i] & 0xfff) >= THR; ++i) {} |
303 | if (++npulses == max_pulses) |
304 | break; |
305 | TMIN[npulses] = i; |
306 | } |
307 | } |
308 | |
309 | |
310 | |
311 | |
312 | uint32_t VPEAK[max_pulses] = {}; |
313 | uint32_t TPEAK[max_pulses] = {}; |
314 | uint16_t TMID[max_pulses] = {}; |
315 | uint16_t VMID[max_pulses] = {}; |
316 | uint16_t TFINE[max_pulses] = {}; |
317 | uint32_t pulse_time[max_pulses] = {}; |
318 | |
319 | |
320 | uint32_t pedestal = 0; |
321 | uint32_t VMIN = 0; |
322 | for (unsigned int i=0; i < NPED; i++) { |
| 20 | | Assuming 'i' is >= 'NPED' | |
|
| 21 | | Loop condition is false. Execution continues on line 336 | |
|
323 | pedestal += (samples[i] & 0xfff); |
324 | if(i<4) |
325 | VMIN += (samples[i] & 0xfff); |
326 | |
327 | |
328 | if ((samples[i] & 0xfff) > MAXPED) { |
329 | bad_pedestal = true; |
330 | } |
331 | |
332 | if( (samples[i] == 0x1fff) || (samples[i] == 0x1000) ) { |
333 | bad_pedestal = true; |
334 | } |
335 | } |
336 | VMIN /= NPED; |
| |
337 | |
338 | |
339 | |
340 | for (unsigned int i=0; i < 4; i++) { |
341 | |
342 | if ( ((samples[i] & 0xfff) > MAXPED) || ((samples[i] & 0xfff) > THR) ) { |
343 | bad_timing_pedestal = true; |
344 | } |
345 | |
346 | if ( (samples[i] == 0x1000) || (samples[i] == 0x1fff) ) { |
347 | bad_timing_pedestal = true; |
348 | } |
349 | |
350 | |
351 | |
352 | |
353 | if( (samples[i] & 0xfff) > THR ) { |
354 | no_timing_calculation = true; |
355 | } |
356 | } |
357 | |
358 | |
359 | for (unsigned int p=0; p < npulses; ++p) { |
360 | |
361 | |
362 | |
363 | |
364 | |
365 | if(no_timing_calculation) { |
366 | TMID[p] = TC[p]; |
367 | TFINE[p] = 0; |
368 | VPEAK[p] = 0; |
369 | |
370 | |
371 | } |
372 | |
373 | |
374 | |
375 | |
376 | |
377 | |
378 | |
379 | |
380 | while (true) { |
381 | |
382 | |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | |
391 | unsigned int ipeak; |
392 | for (ipeak = TC[p]; (int)ipeak < NW-1; ++ipeak) { |
393 | |
394 | if ((samples[ipeak] & 0xfff) < (samples[ipeak-1] & 0xfff)) { |
395 | VPEAK[p] = (samples[ipeak-1] & 0xfff); |
396 | TPEAK[p] = ipeak-1; |
397 | break; |
398 | } |
399 | } |
400 | |
401 | |
402 | if(ipeak > TC[p]+NSA) |
403 | vpeak_beyond_NSA[p] = true; |
404 | |
405 | if (VERBOSE > 1) { |
406 | jout << " pulse " << p << ": VMIN: " << VMIN |
407 | << " TC: " << TC[p] << " VPEAK: " << VPEAK[p] << endl; |
408 | } |
409 | |
410 | |
411 | if (VPEAK[p] == 0) { |
412 | TMID[p] = TC[p]; |
413 | TFINE[p] = 0; |
414 | VPEAK[p] = 0; |
415 | vpeak_beyond_NSA[p] = true; |
416 | vpeak_not_found[p] = true; |
417 | break; |
418 | } |
419 | |
420 | |
421 | if(no_timing_calculation) |
422 | break; |
423 | |
424 | |
425 | VMID[p] = (VMIN + VPEAK[p]) >> 1; |
426 | |
427 | |
428 | |
429 | |
430 | |
431 | |
432 | |
433 | for (unsigned int i = TPEAK[p]; i >= 1; --i) { |
434 | if ( ((samples[i-1] & 0xfff) <= VMID[p]) && ((samples[i] & 0xfff) > VMID[p]) ) { |
435 | |
436 | |
437 | TMID[p] = i; |
438 | break; |
439 | } |
440 | } |
441 | |
442 | if (TMID[p] == 0) { |
443 | TFINE[p] = 0; |
444 | } |
445 | else { |
446 | |
447 | int Vnext = (samples[TMID[p]] & 0xfff); |
448 | int Vlast = (samples[TMID[p]-1] & 0xfff); |
449 | if (VERBOSE > 2) { |
450 | jout << " TMIN = " << TMIN[p] << " TMID = " << TMID[p] << " TPEAK = " << TPEAK[p] << endl |
451 | << " VMID = " << VMID[p] << " Vnext = " << Vnext << " Vlast = " << Vlast << endl; |
452 | } |
453 | if (Vnext > Vlast && VMID[p] >= Vlast) |
454 | TFINE[p] = 64 * (VMID[p] - Vlast) / (Vnext - Vlast); |
455 | else |
456 | TFINE[p] = 62; |
457 | if(TFINE[p] == 64) |
458 | TFINE[p] = 0; |
459 | } |
460 | pulse_time[p] = ((TMID[p]-1) << 6) + TFINE[p]; |
461 | break; |
462 | } |
463 | VMIN = (VMIN < 99999)? VMIN : 0; |
464 | |
465 | if (VERBOSE > 1) { |
466 | jout << " pulse " << p << ": VMID: " << VMID[p] << " TMID: " << TMID[p] |
467 | << " TFINE: " << TFINE[p] << " time: " << pulse_time[p] |
468 | << " integral: " << pulse_integral[p] << endl; |
469 | if (VERBOSE > 2) { |
470 | jout << " TMIN = " << TMIN[p] << " TMID = " << TMID[p] << " TPEAK = " << TPEAK[p] << endl; |
471 | |
472 | } |
473 | } |
474 | |
475 | |
476 | Df250PulseData* f250PulseData; |
477 | if( p < pdat_objs.size() ) { |
478 | f250PulseData = pdat_objs[p]; |
479 | |
480 | if(f250PulseData == NULL) { |
481 | jerr << " NULL f250PulseData object!" << endl; |
482 | continue; |
483 | } |
484 | } else { |
485 | |
486 | f250PulseData = new Df250PulseData; |
487 | |
488 | f250PulseData->rocid = rawData->rocid; |
489 | f250PulseData->slot = rawData->slot; |
490 | f250PulseData->channel = rawData->channel; |
491 | f250PulseData->itrigger = rawData->itrigger; |
492 | |
493 | f250PulseData->event_within_block = 1; |
494 | f250PulseData->QF_pedestal = bad_pedestal; |
495 | f250PulseData->pedestal = pedestal; |
496 | |
497 | f250PulseData->integral = pulse_integral[p]; |
498 | f250PulseData->QF_NSA_beyond_PTW = NSA_beyond_PTW[p]; |
499 | f250PulseData->QF_overflow = has_overflow_samples[p]; |
500 | f250PulseData->QF_underflow = has_underflow_samples[p]; |
501 | f250PulseData->nsamples_over_threshold = number_samples_above_threshold[p]; |
502 | |
503 | f250PulseData->course_time = TMID[p]; |
504 | f250PulseData->fine_time = TFINE[p]; |
505 | f250PulseData->QF_vpeak_beyond_NSA = vpeak_beyond_NSA[p]; |
506 | f250PulseData->QF_vpeak_not_found = vpeak_not_found[p]; |
507 | f250PulseData->QF_bad_pedestal = bad_timing_pedestal; |
508 | |
509 | f250PulseData->pulse_number = p; |
510 | f250PulseData->nsamples_integral = NSA + NSB; |
511 | f250PulseData->nsamples_pedestal = NPED; |
512 | f250PulseData->emulated = true; |
513 | |
514 | f250PulseData->AddAssociatedObject(rawData); |
515 | const_cast<Df250WindowRawData*>(rawData)->AddAssociatedObject(f250PulseData); |
516 | pdat_objs.push_back(f250PulseData); |
517 | } |
518 | |
519 | |
520 | f250PulseData->integral_emulated = pulse_integral[p]; |
521 | f250PulseData->pedestal_emulated = pedestal; |
522 | f250PulseData->pulse_peak_emulated = VPEAK[p]; |
523 | f250PulseData->course_time_emulated = TMID[p]; |
524 | f250PulseData->fine_time_emulated = TFINE[p]; |
525 | |
526 | |
527 | uint32_t QF = 0; |
528 | if( bad_pedestal ) QF |= (1<<0); |
529 | if( NSA_beyond_PTW[p] ) QF |= (1<<1); |
530 | if( has_overflow_samples[p] ) QF |= (1<<2); |
531 | if( has_underflow_samples[p] ) QF |= (1<<3); |
532 | if( vpeak_beyond_NSA[p] ) QF |= (1<<4); |
533 | if( vpeak_not_found[p] ) QF |= (1<<5); |
534 | if( bad_timing_pedestal ) QF |= (1<<6); |
535 | f250PulseData->QF_emulated = QF; |
536 | |
537 | if(VERBOSE > 3) { |
538 | cout << boolalpha; |
539 | cout << "bad_pedestal = " << bad_pedestal << endl; |
540 | cout << "NSA_beyond_PTW = " << NSA_beyond_PTW[p] << endl; |
541 | cout << "has_overflow_samples = " << has_overflow_samples[p] << endl; |
542 | cout << "has_underflow_samples = " << has_underflow_samples[p] << endl; |
543 | cout << "vpeak_beyond_NSA = " << vpeak_beyond_NSA[p] << endl; |
544 | cout << "vpeak_not_found = " << vpeak_not_found[p] << endl; |
545 | cout << "bad_timing_pedestal = " << bad_timing_pedestal << endl; |
546 | cout << "total QF = " << QF << endl; |
547 | } |
548 | |
549 | |
550 | if( f250PulseData->emulated ) { |
551 | f250PulseData->integral = f250PulseData->integral_emulated; |
552 | f250PulseData->pedestal = f250PulseData->pedestal_emulated; |
553 | f250PulseData->pulse_peak = f250PulseData->pulse_peak_emulated; |
554 | f250PulseData->course_time = f250PulseData->course_time_emulated; |
555 | f250PulseData->fine_time = f250PulseData->fine_time_emulated; |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | } |
564 | |
565 | } |
566 | |
567 | if (VERBOSE > 0) jout << " Df250EmulatorAlgorithm_v3::EmulateFirmware ==> Emulation complete <==" << endl; |
568 | return; |
569 | } |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #ifndef _JObject_ |
9 | #define _JObject_ |
10 | |
11 | #include <cstdio> |
12 | #include <sstream> |
13 | #include <cassert> |
14 | #include <map> |
15 | #include <vector> |
16 | #include <set> |
17 | #include <string> |
18 | #include <cstdint> |
19 | #include <type_traits> |
20 | #include <typeinfo> |
21 | #include <stdint.h> |
22 | using std::pair; |
23 | using std::map; |
24 | using std::set; |
25 | using std::vector; |
26 | using std::string; |
27 | using std::stringstream; |
28 | |
29 | |
30 | #include "cint.h" |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | #define JOBJECT_PUBLIC(T) \ |
51 | virtual const char* className(void) const {return static_className();} \ |
52 | static const char* static_className(void) {return #T;} \ |
53 | virtual JObject* Clone() const {return CloneObject<T>( *this );} |
54 | |
55 | |
56 | |
57 | |
58 | namespace jana{ |
59 | |
60 | class JFactory_base; |
61 | class JEventLoop; |
62 | |
63 | class JObject{ |
64 | |
65 | public: |
66 | JOBJECT_PUBLIC(JObject); |
67 | |
68 | typedef unsigned long long oid_t; |
69 | |
70 | JObject() : id((oid_t)this),append_types(false),factory(NULL) {} |
71 | JObject( oid_t aId ) : id( aId ),append_types(false),factory(NULL) {} |
72 | |
73 | virtual ~JObject(){ |
74 | for(unsigned int i=0; i<auto_delete.size(); i++)delete auto_delete[i]; |
75 | } |
76 | |
77 | |
78 | JObject(const JObject& o) : |
79 | id( (oid_t)this ), append_types(o.append_types), associated( |
80 | o.associated), auto_delete(), messagelog( |
81 | o.messagelog), factory(o.factory) { |
82 | |
83 | for( auto obj : o.auto_delete ) { |
84 | auto_delete.push_back( obj->Clone() ); |
85 | } |
86 | } |
87 | |
88 | |
89 | JObject( const JObject&& o ) : id( (oid_t)this ), append_types(o.append_types), associated( |
90 | std::move(o.associated)), auto_delete(std::move(o.auto_delete)), messagelog( std::move( |
91 | o.messagelog)), factory(o.factory) { |
92 | factory = nullptr; |
93 | } |
94 | |
95 | |
96 | JObject& operator=( const JObject& o) { |
97 | if( this == &o ) return *this; |
98 | append_types = o.append_types; |
99 | associated = o.associated; |
100 | messagelog = o.messagelog; |
101 | factory = o.factory; |
102 | auto_delete.clear(); |
103 | for( auto obj : o.auto_delete ) { |
104 | auto_delete.push_back( obj->Clone() ); |
105 | } |
106 | return *this; |
107 | } |
108 | |
109 | |
110 | |
111 | template<typename TYPE> |
112 | static typename std::enable_if< |
113 | (std::is_abstract <TYPE>::value || !std::is_copy_constructible<TYPE>::value), JObject*>::type CloneObject( |
114 | const TYPE& obj) { |
115 | |
116 | |
117 | return nullptr; |
118 | } |
119 | template<typename TYPE> |
120 | static typename std::enable_if< |
121 | (!std::is_abstract <TYPE>::value |
122 | && std::is_copy_constructible <TYPE>::value ), JObject*>::type CloneObject( |
123 | const TYPE& obj) { |
124 | |
125 | |
126 | return new TYPE(obj); |
127 | } |
128 | |
129 | |
130 | template<typename T> bool IsA(const T *t) const {return dynamic_cast<const T*>(this)!=0L;} |
131 | |
132 | |
133 | template<typename T> bool IsAT(const T *t) const {return dynamic_cast<const T*>(this)!=0L;} |
134 | |
135 | |
136 | inline void AddAssociatedObject(const JObject *obj); |
137 | inline void AddAssociatedObjectAutoDelete(JObject *obj, bool auto_delete=true); |
138 | inline void RemoveAssociatedObject(const JObject *obj); |
139 | inline void ClearAssociatedObjects(void); |
140 | inline bool IsAssociated(const JObject* locObject) const {return (associated.find(locObject) != associated.end());} |
141 | template<typename T> void Get(vector<const T*> &ptrs, string classname="", int max_depth=1000000) const ; |
142 | template<typename T> void GetT(vector<const T*> &ptrs) const ; |
143 | template<typename T> void GetSingle(const T* &ptrs, string classname="") const ; |
144 | template<typename T> void GetSingleT(const T* &ptrs) const ; |
145 | template<typename T> void GetAssociatedAncestors(set<const JObject*> &already_checked, int &max_depth, set<const T*> &objs_found, string classname="") const; |
146 | template<typename T> void GetAssociatedDescendants(JEventLoop *loop, vector<const T*> &associatedTo, int max_depth=1000000); |
147 | void GetAssociatedDescendants(JEventLoop *loop, vector<const JObject*> &associatedTo, int max_depth=1000000); |
148 | |
149 | template<typename T,typename S> void CopyToVector(T itbegin, T itend, vector<const S*> &v) const; |
150 | |
151 | |
152 | virtual void toStrings(vector<pair<string,string> > &items)const; |
153 | template<typename T> void AddString(vector<pair<string,string> > &items, const char *name, const char *format, const T &val) const; |
154 | |
155 | |
156 | void AddLog(string &message) const {messagelog.push_back(message);} |
157 | void AddLog(vector<string> &messages) const {messagelog.insert(messagelog.end(), messages.begin(), messages.end());} |
158 | void GetLog(vector<string> &messagelog) const {messagelog = this->messagelog;} |
159 | |
160 | |
161 | bool GetAppendTypes(void) const {return append_types;} |
162 | void SetAppendTypes(bool append_types){this->append_types=append_types;} |
163 | void SetFactoryPointer(JFactory_base *factory){this->factory=factory;} |
164 | JFactory_base * GetFactoryPointer(void) const {return factory;} |
165 | string GetName(void) const {return string(className());} |
166 | string GetTag(void) const ; |
167 | string GetNameTag(void) const {return GetName() + (GetTag()=="" ? "":":") + GetTag();} |
168 | |
169 | oid_t id; |
170 | |
171 | private: |
172 | |
173 | bool append_types; |
174 | set<const JObject*> associated; |
175 | |
176 | vector<JObject*> auto_delete; |
177 | mutable vector<string> messagelog; |
178 | JFactory_base *factory; |
179 | |
180 | }; |
181 | |
182 | #if !defined(__CINT__) && !defined(__CLING__) |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | void JObject::AddAssociatedObject(const JObject *obj) |
189 | { |
190 | |
191 | |
192 | assert(obj!=NULL); |
193 | |
194 | associated.insert(obj); |
195 | |
196 | } |
197 | |
198 | |
199 | |
200 | |
201 | void JObject::AddAssociatedObjectAutoDelete(JObject *obj, bool auto_delete) |
202 | { |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | AddAssociatedObject(obj); |
214 | |
215 | if(auto_delete)this->auto_delete.push_back(obj); |
216 | } |
217 | |
218 | |
219 | |
220 | |
221 | void JObject::RemoveAssociatedObject(const JObject *obj) |
222 | { |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | auto iter = associated.find(obj); |
230 | |
231 | if(iter!=associated.end()){ |
232 | associated.erase(iter); |
233 | } |
234 | } |
235 | |
236 | |
237 | |
238 | |
239 | void JObject::ClearAssociatedObjects(void) |
240 | { |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | associated.clear(); |
248 | |
249 | |
250 | for(unsigned int i=0; i<auto_delete.size(); i++)delete auto_delete[i]; |
251 | auto_delete.clear(); |
252 | } |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | template<typename T,typename S> |
263 | void JObject::CopyToVector(T itbegin, T itend, vector<const S*> &v) const |
264 | { |
265 | for(T it=itbegin; it!=itend; it++) v.push_back(*it); |
266 | } |
267 | |
268 | |
269 | |
270 | |
271 | template<typename T> |
272 | void JObject::Get(vector<const T*> &ptrs, string classname, int max_depth) const |
273 | { |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | if(classname=="")classname=T::static_className(); |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | set<const JObject*> already_checked; |
293 | set<const T*> objs_found; |
294 | int my_max_depth = max_depth; |
295 | GetAssociatedAncestors(already_checked, my_max_depth, objs_found, classname); |
296 | |
297 | |
298 | ptrs.clear(); |
299 | CopyToVector(objs_found.begin(), objs_found.end(), ptrs); |
300 | |
301 | |
302 | |
303 | |
304 | } |
305 | |
306 | |
307 | |
308 | |
309 | template<typename T> |
310 | void JObject::GetAssociatedAncestors(set<const JObject*> &already_checked, int &max_depth, set<const T*> &objs_found, string classname) const |
311 | { |
312 | |
313 | |
314 | |
315 | |
316 | |
317 | |
318 | |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | |
325 | |
326 | |
327 | |
328 | |
329 | |
330 | if(already_checked.find(this) == already_checked.end()) already_checked.insert(this); |
331 | |
332 | if(classname=="")classname=T::static_className(); |
333 | max_depth--; |
334 | |
335 | |
336 | for( auto obj : associated ){ |
337 | |
338 | |
339 | if( classname == obj->className() ){ |
340 | objs_found.insert( dynamic_cast<const T*>(obj) ); |
341 | } |
342 | |
343 | |
344 | if(max_depth<=0) continue; |
345 | if(already_checked.find(obj) != already_checked.end()) continue; |
346 | already_checked.insert(obj); |
347 | obj->GetAssociatedAncestors(already_checked, max_depth, objs_found, classname); |
348 | } |
349 | |
350 | max_depth++; |
351 | } |
352 | |
353 | |
354 | |
355 | |
356 | template<typename T> |
357 | void GetAssociatedDescendants(JEventLoop *loop, vector<const T*> &associatedTo, int max_depth=1000000) |
358 | { |
359 | |
360 | |
361 | |
362 | |
363 | |
364 | |
365 | |
366 | |
367 | |
368 | |
369 | |
370 | |
371 | |
372 | |
373 | |
374 | |
375 | |
376 | |
377 | vector<const JObject*> ajobjs; |
378 | GetAssociatedDescendants(loop, ajobjs, max_depth); |
379 | for(uint32_t i=0; i<ajobjs.size(); i++){ |
380 | const T *ptr = dynamic_cast<const T*>(ajobjs[i]); |
381 | if(ptr != NULL) associatedTo.push_back(ptr); |
382 | } |
383 | } |
384 | |
385 | |
386 | |
387 | |
388 | template<typename T> |
389 | void JObject::GetT(vector<const T*> &ptrs) const |
390 | { |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |
401 | |
402 | |
403 | |
404 | |
405 | ptrs.clear(); |
406 | |
407 | |
408 | |
409 | for( auto obj : associated ){ |
410 | const T *ptr = dynamic_cast<const T*>(obj); |
411 | if(ptr != NULL)ptrs.push_back(ptr); |
412 | } |
413 | } |
414 | |
415 | |
416 | |
417 | |
418 | template<class T> |
419 | void JObject::GetSingle(const T* &t, string classname) const |
420 | { |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | |
428 | |
429 | |
430 | |
431 | |
432 | t = NULL; |
433 | |
434 | if(classname=="")classname=T::static_className(); |
| |
435 | |
436 | |
437 | |
438 | for( auto obj : associated ){ |
439 | if( classname == obj->className() ){ |
| 9 | | Value assigned to field 'NPED' | |
|
| |
440 | t = dynamic_cast<const T*>(obj); |
441 | if(t!=NULL)return; |
| |
442 | } |
443 | } |
444 | } |
445 | |
446 | |
447 | |
448 | |
449 | template<class T> |
450 | void JObject::GetSingleT(const T* &t) const |
451 | { |
452 | |
453 | |
454 | |
455 | |
456 | |
457 | |
458 | |
459 | |
460 | |
461 | |
462 | |
463 | |
464 | |
465 | |
466 | |
467 | t = NULL; |
468 | |
469 | |
470 | |
471 | for( auto obj : associated ){ |
472 | t = dynamic_cast<const T*>(obj); |
473 | if(t!=NULL)return; |
474 | } |
475 | } |
476 | |
477 | |
478 | |
479 | |
480 | inline void JObject::toStrings(vector<pair<string,string> > &items) const |
481 | { |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | AddString(items, "JObject", "0x%08x", (unsigned long)this); |
497 | } |
498 | |
499 | |
500 | |
501 | |
502 | template<typename T> |
503 | void JObject::AddString(vector<pair<string,string> > &items, const char *name, const char *format, const T &val) const |
504 | { |
505 | |
506 | |
507 | |
508 | |
509 | |
510 | |
511 | |
512 | |
513 | |
514 | |
515 | |
516 | |
517 | |
518 | |
519 | |
520 | |
521 | |
522 | |
523 | |
524 | |
525 | |
526 | |
527 | |
528 | |
529 | |
530 | char str[256]; |
531 | sprintf(str, format, val); |
532 | |
533 | stringstream ss; |
534 | ss<<name; |
535 | if(append_types){ |
536 | if(typeid(T)==typeid(int)){ |
537 | ss<<":int:"<<val; |
538 | }else if(typeid(T)==typeid(int32_t)){ |
539 | ss<<":int:"<<val; |
540 | }else if(typeid(T)==typeid(unsigned int)){ |
541 | ss<<":uint:"<<val; |
542 | }else if(typeid(T)==typeid(uint32_t)){ |
543 | ss<<":uint:"<<val; |
544 | }else if(typeid(T)==typeid(long)){ |
545 | ss<<":long:"<<val; |
546 | }else if(typeid(T)==typeid(int64_t)){ |
547 | ss<<":long:"<<val; |
548 | }else if(typeid(T)==typeid(unsigned long)){ |
549 | ss<<":ulong:"<<val; |
550 | }else if(typeid(T)==typeid(uint64_t)){ |
551 | ss<<":ulong:"<<val; |
552 | }else if(typeid(T)==typeid(short)){ |
553 | ss<<":short:"<<val; |
554 | }else if(typeid(T)==typeid(int16_t)){ |
555 | ss<<":short:"<<val; |
556 | }else if(typeid(T)==typeid(unsigned short)){ |
557 | ss<<":ushort:"<<val; |
558 | }else if(typeid(T)==typeid(uint16_t)){ |
559 | ss<<":ushort:"<<val; |
560 | }else if(typeid(T)==typeid(float)){ |
561 | ss<<":float:"<<val; |
562 | }else if(typeid(T)==typeid(double)){ |
563 | ss<<":double:"<<val; |
564 | }else if(typeid(T)==typeid(string)){ |
565 | ss<<":string:"<<val; |
566 | }else if(typeid(T)==typeid(const char*)){ |
567 | ss<<":string:"<<val; |
568 | }else if(typeid(T)==typeid(char*)){ |
569 | ss<<":string:"<<val; |
570 | }else{ |
571 | ss<<":unknown:"<<str; |
572 | } |
573 | } |
574 | |
575 | pair<string, string> item; |
576 | item.first = ss.str(); |
577 | item.second = string(str); |
578 | items.push_back(item); |
579 | } |
580 | |
581 | #endif // __CINT__ __CLING__ |
582 | |
583 | |
584 | } |
585 | |
586 | #endif // _JObject_ |
587 | |