clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name DBCALShower_factory_KLOE.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_CCDB -D HAVE_RCDB -D HAVE_EVIO -D HAVE_TMVA=1 -D RCDB_MYSQL=1 -D RCDB_SQLITE=1 -D SQLITE_USE_LEGACY_STRUCT=ON -I .Linux_CentOS7.7-x86_64-gcc4.8.5/libraries/BCAL -I libraries/BCAL -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 external/xstream/include -I /usr/include/tirpc -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/root/root-6.08.06/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/ccdb/ccdb_1.06.06/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/rcdb/rcdb_0.06.00/cpp/include -I /usr/include/mysql -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlitecpp/SQLiteCpp-2.2.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlite/sqlite-3.13.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/hdds/hdds-4.9.0/Linux_CentOS7.7-x86_64-gcc4.8.5/src -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/xerces-c/xerces-c-3.1.4/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/evio/evio-4.4.6/Linux-x86_64/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/BCAL/DBCALShower_factory_KLOE.cc
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include <cassert> |
9 | #include <math.h> |
10 | #include <map> |
11 | |
12 | #include "BCAL/DBCALHit.h" |
13 | #include "BCAL/DBCALTDCHit.h" |
14 | #include "BCAL/DBCALPoint.h" |
15 | #include "BCAL/DBCALGeometry.h" |
16 | #include "BCAL/DBCALShower_factory_KLOE.h" |
17 | |
18 | #include "DANA/DApplication.h" |
19 | |
20 | #include "units.h" |
21 | |
22 | using namespace std; |
23 | |
24 | |
25 | |
26 | |
27 | jerror_t DBCALShower_factory_KLOE::init() |
28 | { |
29 | |
30 | ethr_cell=0.0001; |
31 | |
32 | CLUST_THRESH = 0.03; |
33 | |
34 | elyr = 1; |
35 | xlyr = 2; |
36 | ylyr = 3; |
37 | zlyr = 4; |
38 | tlyr = 5; |
39 | |
40 | |
41 | MERGE_THRESH_DIST = 40.0; |
42 | MERGE_THRESH_TIME = 2.5; |
43 | MERGE_THRESH_ZDIST = 30.0; |
44 | MERGE_THRESH_XYDIST = 40.0; |
45 | |
46 | |
47 | BREAK_THRESH_TRMS= 5.0; |
48 | |
49 | gPARMS->SetDefaultParameter( "BCALRECON:CLUST_THRESH", CLUST_THRESH ); |
50 | gPARMS->SetDefaultParameter( "BCALRECON:MERGE_THRESH_DIST", MERGE_THRESH_DIST ); |
51 | gPARMS->SetDefaultParameter( "BCALRECON:MERGE_THRESH_TIME", MERGE_THRESH_TIME ); |
52 | gPARMS->SetDefaultParameter( "BCALRECON:MERGE_THRESH_ZDIST", MERGE_THRESH_ZDIST ); |
53 | gPARMS->SetDefaultParameter( "BCALRECON:MERGE_THRESH_XYDIST", MERGE_THRESH_XYDIST ); |
54 | gPARMS->SetDefaultParameter( "BCALRECON:BREAK_THRESH_TRMS", BREAK_THRESH_TRMS ); |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | m_scaleZ_p0 = 0.99798; |
79 | m_scaleZ_p1 = 0.000361096; |
80 | m_scaleZ_p2 = -2.17338e-06; |
81 | m_scaleZ_p3 = 1.32201e-09; |
82 | |
83 | m_nonlinZ_p0 = -0.0201272; |
84 | m_nonlinZ_p1 = 0.000103649; |
85 | m_nonlinZ_p2 = 0; |
86 | m_nonlinZ_p3 = 0; |
87 | |
88 | |
89 | return NOERROR; |
90 | } |
91 | |
92 | |
93 | |
94 | |
95 | jerror_t DBCALShower_factory_KLOE::brun(JEventLoop *loop, int32_t runnumber) |
96 | { |
97 | |
98 | DApplication* app = dynamic_cast<DApplication*>(loop->GetJApplication()); |
99 | DGeometry* geom = app->GetDGeometry(runnumber); |
100 | geom->GetTargetZ(m_z_target_center); |
101 | |
102 | vector<const DBCALGeometry*> bcalGeomVect; |
103 | loop->Get( bcalGeomVect ); |
104 | bcalGeom = bcalGeomVect[0]; |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | ATTEN_LENGTH = bcalGeom->GetBCAL_attenutation_length(); |
111 | C_EFFECTIVE = bcalGeom->GetBCAL_c_effective(); |
112 | |
113 | fiberLength = bcalGeom->GetBCAL_length(); |
114 | zOffset = bcalGeom->GetBCAL_center(); |
115 | |
116 | |
117 | int modmin = 0; |
118 | int modmax = bcalGeom->GetBCAL_Nmodules(); |
119 | int rowmin1=0; |
120 | int rowmax1= bcalGeom->GetBCAL_NInnerLayers(); |
121 | int rowmin2= rowmax1; |
122 | int rowmax2= bcalGeom->GetBCAL_NOuterLayers()+rowmin2; |
123 | int colmin1=0; |
124 | int colmax1=bcalGeom->GetBCAL_NInnerSectors(); |
125 | int colmin2=0; |
126 | int colmax2=bcalGeom->GetBCAL_NOuterSectors(); |
127 | |
128 | float r_inner= bcalGeom->GetBCAL_inner_rad(); |
129 | |
130 | for (int i = (rowmin1+1); i < (rowmax1+1); i++){ |
131 | |
132 | int cellId = bcalGeom->cellId(1,i,1); |
133 | |
134 | rt[i]=bcalGeom->r(cellId)-r_inner; |
135 | } |
136 | |
137 | for (int i = (rowmin2+1); i < (rowmax2+1); i++){ |
138 | int cellId = bcalGeom->cellId(1,i,1); |
139 | rt[i]=bcalGeom->r(cellId)-r_inner; |
140 | } |
141 | |
142 | |
143 | float r[modulemax_bcal][layermax_bcal][colmax_bcal]; |
144 | float phi[modulemax_bcal][layermax_bcal][colmax_bcal]; |
145 | |
146 | |
147 | for (int k = modmin; k < modmax; k++){ |
148 | for (int i = rowmin1; i < rowmax1; i++){ |
149 | for (int j = colmin1; j < colmax1; j++){ |
150 | |
151 | |
152 | int cellId = bcalGeom->cellId(k+1,i+1,j+1); |
153 | r[k][i][j]=bcalGeom->r(cellId); |
154 | phi[k][i][j]=bcalGeom->phi(cellId); |
155 | |
156 | xx[k][i][j]=r[k][i][j]*cos(phi[k][i][j]); |
157 | yy[k][i][j]=r[k][i][j]*sin(phi[k][i][j]); |
158 | } |
159 | } |
160 | |
161 | for (int i = rowmin2; i < rowmax2; i++){ |
162 | for (int j = colmin2; j < colmax2; j++){ |
163 | int cellId = bcalGeom->cellId(k+1,i+1,j+1); |
164 | r[k][i][j]=bcalGeom->r(cellId); |
165 | phi[k][i][j]=bcalGeom->phi(cellId); |
166 | |
167 | xx[k][i][j]=r[k][i][j]*cos(phi[k][i][j]); |
168 | yy[k][i][j]=r[k][i][j]*sin(phi[k][i][j]); |
169 | } |
170 | } |
171 | } |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | return NOERROR; |
179 | } |
180 | |
181 | |
182 | |
183 | |
184 | jerror_t DBCALShower_factory_KLOE::evnt(JEventLoop *loop, uint64_t eventnumber) |
185 | { |
186 | |
187 | CellRecon(loop); |
| 1 | Calling 'DBCALShower_factory_KLOE::CellRecon' | |
|
188 | CeleToArray(); |
189 | PreCluster(loop); |
190 | ClusNorm(); |
191 | ClusAnalysis(); |
192 | Trakfit(); |
193 | |
194 | |
195 | vector<DBCALShower*> clusters; |
196 | int id = 0; |
197 | for (int i = 1; i < (clstot+1); i++){ |
198 | |
199 | int j=clspoi[i]; |
200 | |
201 | if( e_cls[j] < CLUST_THRESH ) continue; |
202 | |
203 | |
204 | DBCALShower *shower = new DBCALShower; |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | vector<const DBCALPoint*> pointsInShower; |
235 | FindPointsInShower(j, loop, pointsInShower); |
236 | |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | double E=0,x=0,y=0,z=0,t=0; |
245 | int N_cell=0; |
246 | double sig_x=0,sig_y=0,sig_z=0,sig_t=0; |
247 | double sum_z_wt=0; |
248 | for(unsigned int j=0; j<pointsInShower.size(); j++){ |
249 | double cell_E = pointsInShower[j]->E(); |
250 | double cell_r = pointsInShower[j]->r(); |
251 | double cell_phi = pointsInShower[j]->phi(); |
252 | E += cell_E; |
253 | x += cell_E*cell_r*cos(cell_phi); |
254 | sig_x += cell_E*cell_r*cos(cell_phi)*cell_r*cos(cell_phi); |
255 | y += cell_E*cell_r*sin(cell_phi); |
256 | sig_y += cell_E*cell_r*sin(cell_phi)*cell_r*sin(cell_phi); |
257 | |
258 | |
259 | double z_wt = 1/(pointsInShower[j]->sigZ()*pointsInShower[j]->sigZ()); |
260 | double cell_z = pointsInShower[j]->z(); |
261 | double cell_t = pointsInShower[j]->t(); |
262 | |
263 | sum_z_wt += z_wt; |
264 | z += z_wt*cell_z; |
265 | sig_z += z_wt*cell_z*cell_z; |
266 | |
267 | t += cell_E*cell_t; |
268 | sig_t += cell_E*cell_t*cell_t; |
269 | N_cell++; |
270 | |
271 | shower->AddAssociatedObject(pointsInShower[j]); |
272 | } |
273 | |
274 | x /= E; |
275 | sig_x /= E; |
276 | sig_x = sqrt(sig_x - x*x)/sqrt(N_cell); |
277 | y /= E; |
278 | sig_y /= E; |
279 | sig_y = sqrt(sig_y - y*y)/sqrt(N_cell); |
280 | z /= sum_z_wt; |
281 | sig_z /= sum_z_wt; |
282 | sig_z = sqrt(sig_z - z*z)/sqrt(N_cell); |
283 | t /= E; |
284 | sig_t /= E; |
285 | sig_t = sqrt(sig_t - t*t)/sqrt(N_cell); |
286 | |
287 | shower->id = id++; |
288 | shower->E_raw = E; |
289 | shower->x = x; |
290 | shower->y = y; |
291 | shower->z = z + m_z_target_center; |
292 | shower->t = t; |
293 | shower->N_cell = N_cell; |
294 | |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | float r = sqrt( shower->x * shower->x + shower->y * shower->y ); |
308 | |
309 | float zEntry = ( shower->z - m_z_target_center ) * ( bcalGeom->GetBCAL_inner_rad() / r ); |
310 | |
311 | float scale = m_scaleZ_p0 + m_scaleZ_p1*zEntry + |
312 | m_scaleZ_p2*(zEntry*zEntry) + m_scaleZ_p3*(zEntry*zEntry*zEntry); |
313 | float nonlin = m_nonlinZ_p0 + m_nonlinZ_p1*zEntry + |
314 | m_nonlinZ_p2*(zEntry*zEntry) + m_nonlinZ_p3*(zEntry*zEntry*zEntry); |
315 | |
316 | shower->E = pow( (shower->E_raw ) / scale, 1 / ( 1 + nonlin ) ); |
317 | |
318 | |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | _data.push_back(shower); |
325 | } |
326 | |
327 | return NOERROR; |
328 | } |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | void DBCALShower_factory_KLOE::FindPointsInShower(int indx, JEventLoop *loop, vector<const DBCALPoint*> &pointsInShower) |
335 | { |
336 | |
337 | |
338 | |
339 | |
340 | |
341 | |
342 | |
343 | |
344 | |
345 | |
346 | |
347 | |
348 | |
349 | |
350 | |
351 | |
352 | vector<const DBCALPoint*> points; |
353 | loop->Get(points); |
354 | |
355 | int start_indx = indx; |
356 | do{ |
357 | int module = narr[1][indx]; |
358 | int layer = narr[2][indx]; |
359 | int sector = narr[3][indx]; |
360 | |
361 | |
362 | for(unsigned int i=0; i<points.size(); i++){ |
363 | if(points[i]->module() !=module)continue; |
364 | if(points[i]->layer() !=layer)continue; |
365 | if(points[i]->sector() !=sector)continue; |
366 | pointsInShower.push_back(points[i]); |
367 | } |
368 | |
369 | |
370 | indx = next[indx]; |
371 | }while(indx != start_indx); |
372 | |
373 | } |
374 | |
375 | |
376 | |
377 | |
378 | |
379 | void DBCALShower_factory_KLOE::CellRecon(JEventLoop *loop) |
380 | { |
381 | |
382 | |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |
401 | memset( ecel_a, 0, modulemax_bcal * layermax_bcal * |
402 | colmax_bcal * sizeof( float ) ); |
403 | memset( tcel_a, 0, modulemax_bcal * layermax_bcal * |
404 | colmax_bcal * sizeof( float ) ); |
405 | memset( ecel_b, 0, modulemax_bcal * layermax_bcal * |
406 | colmax_bcal * sizeof( float ) ); |
407 | memset( tcel_b, 0, modulemax_bcal * layermax_bcal * |
408 | colmax_bcal * sizeof( float ) ); |
409 | |
410 | |
411 | |
412 | |
413 | |
414 | |
415 | |
416 | vector<const DBCALPoint*> points; |
417 | loop->Get(points); |
| 2 | | Calling 'JEventLoop::Get' | |
|
418 | if(points.size() <=0) return; |
419 | |
420 | for (vector<const DBCALPoint*>::const_iterator point_iter = points.begin(); |
421 | point_iter != points.end(); |
422 | ++point_iter) { |
423 | const DBCALPoint &point = **point_iter; |
424 | int module = point.module(); |
425 | int layer = point.layer(); |
426 | int sector = point.sector(); |
427 | double r = point.r(); |
428 | double phi = point.phi(); |
429 | double x = r*cos(phi); |
430 | double y = r*sin(phi); |
431 | |
432 | xcel[module-1][layer-1][sector-1] = x; |
433 | ycel[module-1][layer-1][sector-1] = y; |
434 | |
435 | |
436 | zcel[module-1][layer-1][sector-1] = point.z()+m_z_target_center-zOffset; |
437 | tcel[module-1][layer-1][sector-1] = point.t(); |
438 | ecel[module-1][layer-1][sector-1] = point.E(); |
439 | |
440 | |
441 | |
442 | double EUp=0,EDown=0,tUp=0,tDown=0; |
443 | vector<const DBCALUnifiedHit*> assoc_hits; |
444 | point.Get(assoc_hits); |
445 | for (unsigned int i=0; i<assoc_hits.size(); i++) { |
446 | if (assoc_hits[i]->end == DBCALGeometry::kUpstream) { |
447 | EUp = assoc_hits[i]->E; |
448 | tUp = assoc_hits[i]->t; |
449 | } |
450 | if (assoc_hits[i]->end == DBCALGeometry::kDownstream) { |
451 | EDown = assoc_hits[i]->E; |
452 | tDown = assoc_hits[i]->t; |
453 | } |
454 | |
455 | } |
456 | |
457 | ecel_a[module-1][layer-1][sector-1] = EUp; |
458 | |
459 | tcel_a[module-1][layer-1][sector-1] = tUp; |
460 | tcell_anor[module-1][layer-1][sector-1] = tUp; |
461 | |
462 | ecel_b[module-1][layer-1][sector-1] = EDown; |
463 | tcel_b[module-1][layer-1][sector-1] = tDown; |
464 | tcell_bnor[module-1][layer-1][sector-1] = tDown; |
465 | } |
466 | } |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | void DBCALShower_factory_KLOE::CeleToArray(void) |
473 | { |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | |
497 | |
498 | |
499 | |
500 | |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | |
507 | |
508 | |
509 | |
510 | celtot=0; |
511 | |
512 | for (int k = 0; k < modulemax_bcal; k++){ |
513 | for (int i = 0; i < layermax_bcal; i++){ |
514 | for (int j = 0; j < colmax_bcal; j++){ |
515 | |
516 | float ea = ecel_a[k][i][j]; |
517 | float eb = ecel_b[k][i][j]; |
518 | float ta = tcel_a[k][i][j]; |
519 | float tb = tcel_b[k][i][j]; |
520 | |
521 | if( (min(ea,eb)>ethr_cell) & (fabs(ta-tb)<35.) & (ta!=0.) & (tb!=0.)) { |
522 | celtot=celtot+1; |
523 | } else { |
524 | continue; |
525 | } |
526 | |
527 | |
528 | if(celtot>cellmax_bcal) { |
529 | break; |
530 | } |
531 | |
532 | narr[1][celtot]=k+1; |
533 | narr[2][celtot]=i+1; |
534 | narr[3][celtot]=j+1; |
535 | |
536 | |
537 | |
538 | celdata[1][celtot]=ea/0.145; |
539 | celdata[2][celtot]=eb/0.145; |
540 | |
541 | nclus[celtot] = celtot; |
542 | next[celtot] = celtot; |
543 | |
544 | e_cel[celtot] = ecel[k][i][j]; |
545 | x_cel[celtot] = xcel[k][i][j]; |
546 | y_cel[celtot] = ycel[k][i][j]; |
547 | z_cel[celtot] = zcel[k][i][j]; |
548 | t_cel[celtot] = tcel[k][i][j]; |
549 | |
550 | ta_cel[celtot]=tcell_anor[k][i][j]; |
551 | tb_cel[celtot]=tcell_bnor[k][i][j]; |
552 | } |
553 | } |
554 | } |
555 | } |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | void DBCALShower_factory_KLOE::PreCluster(JEventLoop *loop) |
563 | { |
564 | |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | int k=1; |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | |
579 | |
580 | |
581 | int modmin = 0; |
582 | int modmax = bcalGeom->GetBCAL_Nmodules(); |
583 | |
584 | |
585 | |
586 | int rowmax1= bcalGeom->GetBCAL_NInnerLayers(); |
587 | int rowmin2= rowmax1+1; |
588 | |
589 | int colmax1=bcalGeom->GetBCAL_NInnerSectors(); |
590 | int colmax2=bcalGeom->GetBCAL_NOuterSectors(); |
591 | |
592 | float r_middle= bcalGeom->GetBCAL_middle_rad(); |
593 | |
594 | |
595 | float thick_inner=bcalGeom->rSize(bcalGeom->cellId(1,bcalGeom->GetBCAL_NInnerLayers(),1)); |
596 | |
597 | float thick_outer=bcalGeom->rSize(bcalGeom->cellId(1,bcalGeom->GetBCAL_NInnerLayers()+1,1)); |
598 | |
599 | |
600 | float dis_in_out=bcalGeom->r(bcalGeom->cellId(1,bcalGeom->GetBCAL_NInnerLayers()+1,1))-bcalGeom->r(bcalGeom->cellId(1,bcalGeom->GetBCAL_NInnerLayers(),1)); |
601 | |
602 | float degree_permodule=360.0/(modmax-modmin); |
603 | float half_degree_permodule=degree_permodule/2.0; |
604 | |
605 | |
606 | float width_1=2.0*(r_middle-thick_inner/2.0)* |
607 | sin(half_degree_permodule*3.141593/180)/colmax1; |
608 | |
609 | float width_2=2.0*(r_middle+thick_outer/2.0)* |
610 | sin(half_degree_permodule*3.141593/180)/colmax2; |
611 | |
612 | |
613 | |
614 | float disthres=width_2*1.5-width_1*0.5+0.0001; |
615 | |
616 | for (int i = 1; i < (celtot+1); i++){ |
617 | |
618 | int maxnn=0; |
619 | float emin=0.; |
620 | |
621 | |
622 | for (int j = 1; j < (celtot+1); j++){ |
623 | if ( (j!=i) & (nclus[j]!=nclus[i]) & (e_cel[j]>emin)) { |
624 | |
625 | int k1= narr[1][i]; |
626 | int k2= narr[1][j]; |
627 | int i1= narr[2][i]; |
628 | int i2= narr[2][j]; |
629 | |
630 | |
631 | int modiff = k1-k2; |
632 | int amodif = abs(modiff); |
633 | |
634 | |
635 | if ( (abs(i1-i2)<=k) & ((amodif<=1) || (amodif==47)) ) { |
636 | |
637 | int j1= narr[3][i]; |
638 | int j2= narr[3][j]; |
639 | |
640 | if(amodif==0) { |
641 | |
642 | if ( (i1<=rowmax1) & (i2<=rowmax1) & (abs(j2-j1)<=k) ) { |
643 | emin=e_cel[j]; |
644 | maxnn=j; |
645 | } |
646 | |
647 | |
648 | |
649 | if ( (i1>=rowmin2) & (i2>=rowmin2) & (abs(j2-j1)<=k) ) { |
650 | emin=e_cel[j]; |
651 | maxnn=j; |
652 | } |
653 | } |
654 | |
655 | if(amodif>0) { |
656 | if( (modiff==1) || (modiff==-47) ) { |
657 | if ( (i1<=rowmax1) & (i2<=rowmax1) ){ |
658 | if(abs((j1+colmax1)-j2)<=k){ |
659 | emin=e_cel[j]; |
660 | maxnn=j; |
661 | } |
662 | } |
663 | |
664 | if ( (i1>=rowmin2) & (i2>=rowmin2) ) { |
665 | if(abs((j1+colmax2)-j2)<=k){ |
666 | emin=e_cel[j]; |
667 | maxnn=j; |
668 | } |
669 | } |
670 | } |
671 | |
672 | if ( (modiff==-1) || (modiff==47) ) { |
673 | |
674 | if ( (i1<=rowmax1) & (i2<=rowmax1) ){ |
675 | if(abs((j2+colmax1)-j1)<=k){ |
676 | emin=e_cel[j]; |
677 | maxnn=j; |
678 | } |
679 | } |
680 | |
681 | if ( (i1>=rowmin2) & (i2>=rowmin2) ){ |
682 | if(abs((j2+colmax2)-j1)<=k){ |
683 | emin=e_cel[j]; |
684 | maxnn=j; |
685 | } |
686 | } |
687 | } |
688 | } |
689 | |
690 | |
691 | |
692 | |
693 | if( ( (i1 == rowmax1) & (i2 == rowmin2) ) || |
694 | ( (i1 == rowmin2) & (i2 == rowmax1) ) ) { |
695 | |
696 | float delta_xx=xx[k1-1][i1-1][j1-1]-xx[k2-1][i2-1][j2-1]; |
697 | float delta_yy=yy[k1-1][i1-1][j1-1]-yy[k2-1][i2-1][j2-1]; |
698 | |
699 | |
700 | float dis = sqrt( delta_xx * delta_xx + delta_yy * delta_yy ); |
701 | |
702 | dis = sqrt( dis*dis - dis_in_out * dis_in_out ); |
703 | |
704 | if( dis < disthres ){ |
705 | emin = e_cel[j]; |
706 | maxnn = j; |
707 | } |
708 | } |
709 | } |
710 | } |
711 | } |
712 | |
713 | if(maxnn>0){ |
714 | |
715 | Connect(maxnn,i); |
716 | } |
717 | } |
718 | } |
719 | |
720 | |
721 | |
722 | |
723 | |
724 | |
725 | void DBCALShower_factory_KLOE::Connect(int n,int m) |
726 | { |
727 | |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | |
736 | |
737 | |
738 | |
739 | |
740 | |
741 | |
742 | |
743 | |
744 | |
745 | |
746 | |
747 | |
748 | |
749 | |
750 | |
751 | |
752 | |
753 | |
754 | |
755 | |
756 | |
757 | |
758 | |
759 | |
760 | if(nclus[n]!=nclus[m]){ |
761 | int j=m; |
762 | nclus[j]=nclus[n]; |
763 | while(next[j]!=m){ |
764 | j=next[j]; |
765 | nclus[j]=nclus[n]; |
766 | } |
767 | next[j]=next[n]; |
768 | next[n]=m; |
769 | } |
770 | } |
771 | |
772 | |
773 | |
774 | |
775 | |
776 | void DBCALShower_factory_KLOE::ClusNorm(void) |
777 | { |
778 | |
779 | memset( e_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
780 | memset( x_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
781 | memset( y_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
782 | memset( z_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
783 | memset( t_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
784 | memset( ea_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
785 | memset( eb_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
786 | memset( ta_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
787 | memset( tb_cls, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
788 | memset( tsqr_a, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
789 | memset( tsqr_b, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
790 | memset( trms_a, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
791 | memset( trms_b, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
792 | memset( e2_a, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
793 | memset( e2_b, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
794 | memset( clspoi, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
795 | memset( ncltot, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
796 | memset( ntopol, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | |
804 | |
805 | |
806 | |
807 | clstot=0; |
808 | |
809 | for (int ix = 1; ix < (celtot+1); ix++){ |
810 | |
811 | |
812 | |
813 | |
814 | |
815 | int n=nclus[ix]; |
816 | int j=0; |
817 | |
818 | for (int i = 1; i < (clstot+1); i++){ |
819 | if(n==clspoi[i]) j=i; |
820 | } |
821 | |
822 | if(j==0) { |
823 | clstot=clstot+1; |
824 | clspoi[clstot]=n; |
825 | } |
826 | |
827 | |
828 | |
829 | |
830 | if(e_cel[ix]<0.000000001)continue; |
831 | |
832 | x_cls[n]=(e_cls[n]*x_cls[n]+e_cel[ix]*x_cel[ix]) |
833 | /(e_cls[n]+e_cel[ix]); |
834 | |
835 | y_cls[n]=(e_cls[n]*y_cls[n]+e_cel[ix]*y_cel[ix]) |
836 | /(e_cls[n]+e_cel[ix]); |
837 | |
838 | z_cls[n]=(e_cls[n]*z_cls[n]+e_cel[ix]*z_cel[ix]) |
839 | /(e_cls[n]+e_cel[ix]); |
840 | |
841 | t_cls[n]=(e_cls[n]*t_cls[n]+e_cel[ix]*t_cel[ix]) |
842 | /(e_cls[n]+e_cel[ix]); |
843 | |
844 | e_cls[n]=e_cls[n]+e_cel[ix]; |
845 | |
846 | |
847 | |
848 | |
849 | |
850 | |
851 | ta_cls[n]=(ea_cls[n]*ta_cls[n]+celdata[1][ix]*ta_cel[ix]) |
852 | /(ea_cls[n]+celdata[1][ix]); |
853 | tsqr_a[n]=(ea_cls[n]*tsqr_a[n]+celdata[1][ix]*ta_cel[ix]* |
854 | ta_cel[ix])/(ea_cls[n]+celdata[1][ix]); |
855 | ea_cls[n]=ea_cls[n]+celdata[1][ix]; |
856 | e2_a[n]=e2_a[n]+celdata[1][ix]*celdata[1][ix]; |
857 | tb_cls[n]=(eb_cls[n]*tb_cls[n]+celdata[2][ix]*tb_cel[ix])/ |
858 | (eb_cls[n]+celdata[2][ix]); |
859 | tsqr_b[n]=(eb_cls[n]*tsqr_b[n]+celdata[2][ix]*tb_cel[ix]* |
860 | tb_cel[ix])/(eb_cls[n]+celdata[2][ix]); |
861 | eb_cls[n]=eb_cls[n]+celdata[2][ix]; |
862 | e2_b[n]=e2_b[n]+celdata[2][ix]*celdata[2][ix]; |
863 | |
864 | |
865 | |
866 | |
867 | |
868 | ncltot[n]++; |
869 | |
870 | if( narr[1][n] != narr[1][ix] || narr[2][n] != narr[2][ix] ) |
871 | ntopol[n]++; |
872 | |
873 | |
874 | |
875 | } |
876 | |
877 | for (int n = 1; n < (clstot+1); n++){ |
878 | |
879 | int ix=clspoi[n]; |
880 | if( ncltot[ix] > 1) { |
881 | |
882 | float effnum = ea_cls[ix] * ea_cls[ix] / e2_a[ix]; |
883 | trms_a[ix] = effnum / ( effnum - 1 ) * |
884 | ( tsqr_a[ix] - ta_cls[ix] * ta_cls[ix] ); |
885 | |
886 | effnum = eb_cls[ix] * eb_cls[ix] / e2_b[ix]; |
887 | trms_b[ix] = effnum / ( effnum - 1 ) * |
888 | ( tsqr_b[ix] - tb_cls[ix] * tb_cls[ix] ); |
889 | |
890 | if( trms_a[ix] <= 0.0 ) trms_a[ix] = 0.; |
891 | if( trms_b[ix] <= 0.0 ) trms_b[ix] = 0.; |
892 | trms_a[ix] = sqrt( trms_a[ix] ); |
893 | trms_b[ix] = sqrt( trms_b[ix] ); |
894 | } |
895 | else { |
896 | trms_a[ix] = 0.; |
897 | trms_b[ix] = 0.; |
898 | } |
899 | } |
900 | } |
901 | |
902 | |
903 | |
904 | |
905 | void DBCALShower_factory_KLOE::ClusAnalysis() |
906 | { |
907 | |
908 | |
909 | bool newClust = false; |
910 | |
911 | |
912 | |
913 | |
914 | |
915 | for (int i = 0; i < 2; i++){ |
916 | for (int j = 1; j < (clstot+1); j++){ |
917 | int ix=clspoi[j]; |
918 | if(e_cls[ix]>0.0){ |
919 | float dist=sqrt(trms_a[ix]*trms_a[ix]+trms_b[ix]*trms_b[ix]); |
920 | if(dist>BREAK_THRESH_TRMS) { |
921 | Clus_Break(ix); |
922 | newClust = true; |
923 | } |
924 | } |
925 | } |
926 | |
927 | if( newClust ){ |
928 | |
929 | ClusNorm(); |
930 | newClust = false; |
931 | } |
932 | } |
933 | |
934 | |
935 | |
936 | |
937 | |
938 | int icls[3]; |
939 | for (int i = 1; i < clstot; i++){ |
940 | icls[1]=0; |
941 | icls[2]=0; |
942 | for (int j = (i+1); j < (clstot+1); j++){ |
943 | |
944 | int ix=clspoi[i]; |
945 | int iy=clspoi[j]; |
946 | |
947 | |
948 | if ( (e_cls[ix]>0.0) & (e_cls[iy]>0.0) ) { |
949 | |
950 | float delta_x=x_cls[ix]-x_cls[iy]; |
951 | float delta_y=y_cls[ix]-y_cls[iy]; |
952 | float delta_z=z_cls[ix]-z_cls[iy]; |
953 | float dist=sqrt(delta_x*delta_x+delta_y*delta_y+delta_z*delta_z); |
954 | |
955 | float tdif=fabs(t_cls[ix]-t_cls[iy]); |
956 | |
957 | |
958 | |
959 | |
960 | if ( (dist<MERGE_THRESH_DIST) & (tdif<MERGE_THRESH_TIME) ){ |
961 | float zdif=fabs(z_cls[ix]-z_cls[iy]); |
962 | float distran=sqrt(delta_x*delta_x+delta_y*delta_y); |
963 | |
964 | if ( (zdif<MERGE_THRESH_ZDIST) & (distran<MERGE_THRESH_XYDIST) ){ |
965 | if(e_cls[ix]>=e_cls[iy]) { |
966 | icls[1]=ix; |
967 | icls[2]=iy; |
968 | } |
969 | else { |
970 | icls[1]=iy; |
971 | icls[2]=ix; |
972 | } |
973 | } |
974 | } |
975 | |
976 | } |
977 | |
978 | if(min(icls[1],icls[2])>0){ |
979 | |
980 | Connect(icls[1],icls[2]); |
981 | newClust = true; |
982 | } |
983 | } |
984 | } |
985 | |
986 | if( newClust ){ |
987 | |
988 | ClusNorm(); |
989 | } |
990 | } |
991 | |
992 | |
993 | |
994 | |
995 | void DBCALShower_factory_KLOE::Clus_Break(int nclust) |
996 | { |
997 | int nseed[5],selnum,selcel[cellmax_bcal+1]; |
998 | float tdif,tdif_a,tdif_b,tseed[5]; |
999 | |
1000 | |
1001 | for (int i =0; i < 5; i++){ |
1002 | nseed[i]=0; |
1003 | tseed[i]=0; |
1004 | } |
1005 | |
1006 | |
1007 | |
1008 | int n=nclust; |
1009 | tdif_a=ta_cel[n]-ta_cls[nclust]; |
1010 | tdif_b=tb_cel[n]-tb_cls[nclust]; |
1011 | |
1012 | |
1013 | |
1014 | if(tdif_a>0.0) { |
1015 | if(tdif_b>0){ |
1016 | selnum=1; |
1017 | } |
1018 | else { |
1019 | selnum=2; |
1020 | } |
1021 | } |
1022 | |
1023 | else { |
1024 | if(tdif_b>0.0) { |
1025 | selnum=3; |
1026 | } |
1027 | else { |
1028 | selnum=4; |
1029 | } |
1030 | } |
1031 | |
1032 | |
1033 | |
1034 | if(selnum>0) { |
1035 | float tdif=sqrt(tdif_a*tdif_a+tdif_b*tdif_b); |
1036 | if(tdif>tseed[selnum]){ |
1037 | nseed[selnum]=n; |
1038 | tseed[selnum]=tdif; |
1039 | } |
1040 | selcel[n]=selnum; |
1041 | } |
1042 | |
1043 | |
1044 | |
1045 | while(next[n]!=nclust) { |
1046 | n=next[n]; |
1047 | tdif_a=ta_cel[n]-ta_cls[nclust]; |
1048 | tdif_b=tb_cel[n]-tb_cls[nclust]; |
1049 | |
1050 | |
1051 | |
1052 | |
1053 | if(tdif_a>0.0) { |
1054 | |
1055 | if(tdif_b>0.0) { |
1056 | selnum=1; |
1057 | } |
1058 | else { |
1059 | selnum=2; |
1060 | } |
1061 | } |
1062 | |
1063 | else { |
1064 | if(tdif_b>0.0) { |
1065 | selnum=3; |
1066 | } |
1067 | else { |
1068 | selnum=4; |
1069 | } |
1070 | } |
1071 | |
1072 | |
1073 | |
1074 | |
1075 | |
1076 | |
1077 | if(selnum>0){ |
1078 | tdif=sqrt(tdif_a*tdif_a+tdif_b*tdif_b); |
1079 | |
1080 | if(tdif>tseed[selnum]){ |
1081 | nseed[selnum]=n; |
1082 | tseed[selnum]=tdif; |
1083 | } |
1084 | |
1085 | selcel[n]=selnum; |
1086 | } |
1087 | |
1088 | |
1089 | |
1090 | } |
1091 | |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | |
1097 | for (int i =1; i < 5; i++){ |
1098 | |
1099 | if(nseed[i]>0) { |
1100 | |
1101 | nclus[nseed[i]]=nseed[i]; |
1102 | next[nseed[i]]=nseed[i]; |
1103 | |
1104 | for (int j =1; j < (celtot+1); j++){ |
1105 | if ( (nclus[j]==nclust) & (j!=nseed[i]) ){ |
1106 | if(selcel[j]==i) { |
1107 | nclus[j]=j; |
1108 | next[j]=j; |
1109 | Connect(nseed[i],j); |
1110 | } |
1111 | } |
1112 | } |
1113 | } |
1114 | } |
1115 | } |
1116 | |
1117 | |
1118 | |
1119 | |
1120 | |
1121 | |
1122 | |
1123 | |
1124 | |
1125 | void DBCALShower_factory_KLOE::Trakfit( void ) |
1126 | { |
1127 | |
1128 | float emin=0.0001; |
1129 | |
1130 | memset( clslyr, 0, ( clsmax_bcal + 1 ) * |
1131 | ( layermax_bcal + 1 ) * 6 * sizeof( float ) ); |
1132 | |
1133 | memset( apx, 0, ( clsmax_bcal + 1 ) * 4 * sizeof( float ) ); |
1134 | memset( eapx, 0, ( clsmax_bcal + 1 ) * 4 * sizeof( float ) ); |
1135 | memset( ctrk, 0, ( clsmax_bcal + 1 ) * 4 * sizeof( float ) ); |
1136 | memset( ectrk, 0, ( clsmax_bcal + 1 ) * 4 * sizeof( float ) ); |
1137 | |
1138 | for (int ix = 1; ix < (celtot+1); ix++){ |
1139 | |
1140 | int n = nclus[ix]; |
1141 | |
1142 | |
1143 | |
1144 | |
1145 | |
1146 | int lyr = narr[2][ix]; |
1147 | |
1148 | |
1149 | clslyr[xlyr][lyr][n]=(clslyr[elyr][lyr][n]*clslyr[xlyr][lyr][n] |
1150 | +e_cel[ix]*x_cel[ix])/(clslyr[elyr][lyr][n]+e_cel[ix]); |
1151 | |
1152 | clslyr[ylyr][lyr][n]=(clslyr[elyr][lyr][n]*clslyr[ylyr][lyr][n] |
1153 | +e_cel[ix]*y_cel[ix])/(clslyr[elyr][lyr][n]+e_cel[ix]); |
1154 | |
1155 | |
1156 | clslyr[zlyr][lyr][n]=(clslyr[elyr][lyr][n]*clslyr[zlyr][lyr][n] |
1157 | +e_cel[ix]*z_cel[ix])/(clslyr[elyr][lyr][n]+e_cel[ix]); |
1158 | |
1159 | |
1160 | clslyr[tlyr][lyr][n]=(clslyr[elyr][lyr][n]*clslyr[tlyr][lyr][n] |
1161 | +e_cel[ix]*t_cel[ix])/(clslyr[elyr][lyr][n]+e_cel[ix]); |
1162 | |
1163 | |
1164 | clslyr[elyr][lyr][n]=clslyr[elyr][lyr][n]+e_cel[ix]; |
1165 | |
1166 | |
1167 | } |
1168 | |
1169 | memset( nlrtot, 0, ( clsmax_bcal + 1 ) * sizeof( float ) ); |
1170 | |
1171 | for (int n = 1; n < ( clstot + 1 ); n++){ |
1172 | |
1173 | int ix=clspoi[n]; |
1174 | |
1175 | for (int i = 1; i < (layermax_bcal+1); i++){ |
1176 | |
1177 | if( clslyr[elyr][i][ix] > 0.0 ) nlrtot[ix]++; |
1178 | } |
1179 | |
1180 | for (int i = 0; i < ( layermax_bcal + 1 ); i++){ |
1181 | |
1182 | x[i]=0.0; |
1183 | y[i]=0.0; |
1184 | z[i]=0.0; |
1185 | e[i]=0.0; |
1186 | sigx[i]=0.0; |
1187 | sigy[i]=0.0; |
1188 | sigz[i]=0.0; |
1189 | } |
1190 | |
1191 | int nltot=0; |
1192 | |
1193 | for (int il = 1; il < (layermax_bcal+1); il++){ |
1194 | |
1195 | if(clslyr[elyr][il][ix]>emin) { |
1196 | |
1197 | nltot=nltot+1; |
1198 | x[nltot]= clslyr[xlyr][il][ix]; |
1199 | y[nltot]= clslyr[ylyr][il][ix]; |
1200 | z[nltot]= clslyr[zlyr][il][ix]; |
1201 | e[nltot]= clslyr[elyr][il][ix]; |
1202 | |
1203 | sigy[nltot] = 1.0/e[nltot]; |
1204 | sigx[nltot] = 1.0/e[nltot]; |
1205 | sigz[nltot] = 1.0/sqrt(e[nltot]); |
1206 | } |
1207 | } |
1208 | |
1209 | |
1210 | |
1211 | |
1212 | |
1213 | |
1214 | |
1215 | |
1216 | sigx[1]=0.5; |
1217 | sigx[2]=0.5; |
1218 | sigx[3]=0.5; |
1219 | sigx[4]=0.5; |
1220 | sigx[5]=0.5; |
1221 | sigx[6]=0.8; |
1222 | sigx[7]=0.9; |
1223 | sigx[8]=1.2; |
1224 | sigx[9]=1.3; |
1225 | |
1226 | sigy[1]=0.5; |
1227 | sigy[2]=0.5; |
1228 | sigy[3]=0.5; |
1229 | sigy[4]=0.5; |
1230 | sigy[5]=0.5; |
1231 | sigy[6]=0.8; |
1232 | sigy[7]=0.9; |
1233 | sigy[8]=1.2; |
1234 | sigy[9]=1.3; |
1235 | |
1236 | |
1237 | sigz[1]=0.5; |
1238 | sigz[2]=0.5; |
1239 | sigz[3]=0.5; |
1240 | sigz[4]=0.5; |
1241 | sigz[5]=0.5; |
1242 | sigz[6]=0.8; |
1243 | sigz[7]=0.9; |
1244 | sigz[8]=1.2; |
1245 | sigz[9]=1.3; |
1246 | |
1247 | if( nltot > 1 ){ |
1248 | |
1249 | Fit_ls(); |
1250 | |
1251 | for (int i = 1; i < 4; i++){ |
1252 | |
1253 | ctrk[i][ix]=ctrk_ix[i]; |
1254 | ectrk[i][ix]=ectrk_ix[i]; |
1255 | apx[i][ix]=apx_ix[i]; |
1256 | eapx[i][ix]=eapx_ix[i]; |
1257 | } |
1258 | } |
1259 | else{ |
1260 | |
1261 | |
1262 | |
1263 | apx[1][ix] = x[1]; |
1264 | apx[2][ix] = y[1]; |
1265 | apx[3][ix] = z[1]; |
1266 | eapx[1][ix] = sigx[1]; |
1267 | eapx[2][ix] = sigy[1]; |
1268 | eapx[3][ix] = sigz[1]; |
1269 | ectrk[1][ix] = 0.0; |
1270 | ectrk[2][ix] = 0.0; |
1271 | ectrk[3][ix] = 0.0; |
1272 | ctrk[1][ix] = 999.0; |
1273 | ctrk[2][ix] = 999.0; |
1274 | ctrk[3][ix] = 999.0; |
1275 | } |
1276 | } |
1277 | } |
1278 | |
1279 | |
1280 | |
1281 | |
1282 | void DBCALShower_factory_KLOE::Fit_ls() |
1283 | { |
1284 | float a,b,c; |
1285 | float d,e,f,chi2,q,norm; |
1286 | float siga,sigb,sigc,sigd,sige,sigf; |
1287 | float sigb2,sigd2,sigf2; |
1288 | |
1289 | |
1290 | Linefit(1,1,a,b,siga,sigb,chi2,q); |
1291 | |
1292 | Linefit(2,1,c,d,sigc,sigd,chi2,q); |
1293 | |
1294 | Linefit(3,1,e,f,sige,sigf,chi2,q); |
1295 | sigb2=sigb*sigb; |
1296 | sigd2=sigd*sigd; |
1297 | sigf2=sigf*sigf; |
1298 | |
1299 | apx_ix[1]=a; |
1300 | apx_ix[2]=c; |
1301 | apx_ix[3]=e; |
1302 | eapx_ix[1]=siga; |
1303 | eapx_ix[2]=sigc; |
1304 | eapx_ix[3]=sige; |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | |
1311 | norm=sqrt(b*b+d*d+f*f); |
1312 | |
1313 | ctrk_ix[1]=b/norm; |
1314 | ctrk_ix[2]=d/norm; |
1315 | ctrk_ix[3]=f/norm; |
1316 | |
1317 | float norm3=norm*norm*norm; |
1318 | |
1319 | ectrk_ix[1]=sqrt((d*d+f*f)*(d*d+f*f)*sigb2+b*b*d*d*sigd2+b*b*f*f*sigf2)/norm3; |
1320 | ectrk_ix[2]=sqrt((b*b+f*f)*(b*b+f*f)*sigd2+d*d*b*b*sigb2+d*d*f*f*sigf2)/norm3; |
1321 | ectrk_ix[3]=sqrt((b*b+d*d)*(b*b+d*d)*sigf2+f*f*b*b*sigb2+f*f*d*d*sigd2)/norm3; |
1322 | |
1323 | return; |
1324 | } |
1325 | |
1326 | |
1327 | |
1328 | |
1329 | |
1330 | void DBCALShower_factory_KLOE::Linefit(int ixyz,int mwt,float &a, |
1331 | float &b,float &siga,float &sigb,float &chi2,float &q) |
1332 | { |
1333 | |
1334 | |
1335 | |
1336 | |
1337 | |
1338 | |
1339 | float sig[layermax_bcal+1],etemp; |
1340 | float xtemp[layermax_bcal+1],ytemp[layermax_bcal+1]; |
1341 | |
1342 | |
1343 | |
1344 | |
1345 | |
1346 | |
1347 | |
1348 | |
1349 | |
1350 | |
1351 | |
1352 | |
1353 | float sigdat,ss,st2,sx,sxoss,sy,t,wt; |
1354 | sx=0.0; |
1355 | sy=0.0; |
1356 | st2=0.0; |
1357 | b=0.0; |
1358 | |
1359 | int ndata=0; |
1360 | |
1361 | |
1362 | |
1363 | if(ixyz==1) { |
1364 | for (int i = 1; i < (layermax_bcal+1); i++){ |
1365 | xtemp[i]=rt[i]; |
1366 | ytemp[i]=x[i]; |
1367 | sig[i]=sigx[i]; |
1368 | etemp=e[i]; |
1369 | if(etemp>0.0001)ndata=ndata+1; |
1370 | |
1371 | } |
1372 | } |
1373 | else if(ixyz==2) { |
1374 | for (int i = 1; i < (layermax_bcal+1); i++){ |
1375 | xtemp[i]=rt[i]; |
1376 | ytemp[i]=y[i]; |
1377 | sig[i]=sigy[i]; |
1378 | etemp=e[i]; |
1379 | if(etemp>0.000001)ndata=ndata+1; |
1380 | } |
1381 | } |
1382 | else if(ixyz==3) { |
1383 | for (unsigned int i = 1; i < (layermax_bcal+1); i++){ |
1384 | xtemp[i]=rt[i]; |
1385 | ytemp[i]=z[i]; |
1386 | sig[i]=sigz[i]; |
1387 | etemp=e[i]; |
1388 | if(etemp>0.000001)ndata=ndata+1; |
1389 | } |
1390 | } |
1391 | |
1392 | if(mwt!=0) { |
1393 | ss=0.0; |
1394 | for (int i = 1; i < (ndata+1); i++){ |
1395 | wt=1.0/(sig[i]*sig[i]); |
1396 | ss=ss+wt; |
1397 | sx=sx+xtemp[i]*wt; |
1398 | sy=sy+ytemp[i]*wt; |
1399 | } |
1400 | } |
1401 | |
1402 | else { |
1403 | for (int i = 1; i < (ndata+1); i++){ |
1404 | sx=sx+xtemp[i]; |
1405 | sy=sy+ytemp[i]; |
1406 | } |
1407 | ss=float(ndata); |
1408 | } |
1409 | |
1410 | sxoss=sx/ss; |
1411 | |
1412 | if(mwt!=0) { |
1413 | for (int i = 1; i < (ndata+1); i++){ |
1414 | t=(xtemp[i]-sxoss)/sig[i]; |
1415 | st2=st2+t*t; |
1416 | b=b+t*ytemp[i]/sig[i]; |
1417 | } |
1418 | |
1419 | } |
1420 | |
1421 | else { |
1422 | |
1423 | for (int i = 1; i < (ndata+1); i++){ |
1424 | t=xtemp[i]-sxoss; |
1425 | st2=st2+t*t; |
1426 | b=b+t*ytemp[i]; |
1427 | } |
1428 | } |
1429 | |
1430 | b=b/st2; |
1431 | a=(sy-sx*b)/ss; |
1432 | siga=sqrt((1.0+sx*sx/(ss*st2))/ss); |
1433 | sigb=sqrt(1.0/st2); |
1434 | chi2=0.0; |
1435 | |
1436 | if(mwt==0) { |
1437 | for (int i = 1; i < (ndata+1); i++){ |
1438 | chi2=chi2+(ytemp[i]-a-b*xtemp[i])*(ytemp[i]-a-b*xtemp[i]); |
1439 | } |
1440 | q=1.0; |
1441 | sigdat=sqrt(chi2/(ndata-2)); |
1442 | siga=siga*sigdat; |
1443 | sigb=sigb*sigdat; |
1444 | } |
1445 | else { |
1446 | for (int i = 1; i < (ndata+1); i++){ |
1447 | chi2=chi2+((ytemp[i]-a-b*xtemp[i])/ |
1448 | sig[i])*((ytemp[i]-a-b*xtemp[i])/sig[i]); |
1449 | } |
1450 | q=Gammq(0.5*(ndata-2),0.5*chi2); |
1451 | } |
1452 | |
1453 | } |
1454 | |
1455 | |
1456 | |
1457 | |
1458 | |
1459 | |
1460 | float DBCALShower_factory_KLOE::Gammq(float a_gammq,float x_gammq) |
1461 | { |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | float gammq; |
1467 | |
1468 | |
1469 | |
1470 | |
1471 | |
1472 | float gammcf=0,gamser; |
1473 | |
1474 | if(a_gammq==0.0) { |
1475 | gammq=999.0; |
1476 | return gammq; |
1477 | } |
1478 | |
1479 | |
1480 | |
1481 | if(x_gammq<0. || a_gammq<= 0.0) { |
1482 | |
1483 | return 999.0; |
1484 | } |
1485 | |
1486 | if(x_gammq<(a_gammq+1.)) { |
1487 | Gser(gamser,a_gammq,x_gammq); |
1488 | gammq=1.0-gamser; |
1489 | } |
1490 | else { |
1491 | Gcf(gammcf,a_gammq,x_gammq); |
1492 | gammq=gammcf; |
1493 | } |
1494 | return gammq; |
1495 | } |
1496 | |
1497 | |
1498 | |
1499 | |
1500 | |
1501 | void DBCALShower_factory_KLOE::Gser(float &gamser,float a_gser,float x_gser) |
1502 | { |
1503 | |
1504 | int itmax=100; |
1505 | float eps=3.0e-7; |
1506 | float gln; |
1507 | |
1508 | |
1509 | |
1510 | |
1511 | |
1512 | float ap, del,sum; |
1513 | |
1514 | gln=Gammln(a_gser); |
1515 | |
1516 | if(x_gser<=0.0) { |
1517 | if(x_gser<0.0) cout<<"x_gser<0 in gser"<<"\n"; |
1518 | gamser=0.0; |
1519 | return; |
1520 | } |
1521 | |
1522 | ap=a_gser; |
1523 | sum=1.0/a_gser; |
1524 | del=sum; |
1525 | |
1526 | |
1527 | for (int n = 1; n < (itmax+1); n++){ |
1528 | ap=ap+1.0; |
1529 | del=del*x_gser/ap; |
1530 | sum=sum+del; |
1531 | |
1532 | if(fabs(del)<fabs(sum)*eps) { |
1533 | gamser=sum*exp(-x_gser+a_gser*log(x_gser)-gln); |
1534 | return; |
1535 | } |
1536 | |
1537 | } |
1538 | |
1539 | |
1540 | return; |
1541 | } |
1542 | |
1543 | |
1544 | |
1545 | |
1546 | |
1547 | void DBCALShower_factory_KLOE::Gcf(float &gammcf,float a_gcf,float x_gcf) |
1548 | { |
1549 | |
1550 | |
1551 | int itmax=100; |
1552 | float eps=3.0e-7; |
1553 | float fpmin=1.0e-30; |
1554 | |
1555 | float gln; |
1556 | |
1557 | |
1558 | |
1559 | |
1560 | |
1561 | |
1562 | |
1563 | |
1564 | |
1565 | |
1566 | float an,b,c,d,del,h; |
1567 | |
1568 | gln=Gammln(a_gcf); |
1569 | b=x_gcf+1.0-a_gcf; |
1570 | c=1.0/fpmin; |
1571 | d=1.0/b; |
1572 | h=d; |
1573 | |
1574 | |
1575 | for (int i = 1; i < (itmax+1); i++){ |
1576 | an=-i*(i-a_gcf); |
1577 | b=b+2.0; |
1578 | d=an*d+b; |
1579 | if(fabs(d)<fpmin)d=fpmin; |
1580 | c=b+an/c; |
1581 | if(fabs(c)<fpmin)c=fpmin; |
1582 | d=1.0/d; |
1583 | del=d*c; |
1584 | h=h*del; |
1585 | if(fabs(del-1.0)<eps) { |
1586 | gammcf=exp(-x_gcf+a_gcf*log(x_gcf)-gln)*h; |
1587 | return; |
1588 | } |
1589 | |
1590 | return; |
1591 | } |
1592 | } |
1593 | |
1594 | |
1595 | |
1596 | |
1597 | float DBCALShower_factory_KLOE::Gammln(float xx_gln) |
1598 | { |
1599 | |
1600 | |
1601 | float ser,stp,tmp,x_gln,y_gln; |
1602 | float cof[7]; |
1603 | float gammln; |
1604 | |
1605 | |
1606 | |
1607 | |
1608 | |
1609 | |
1610 | |
1611 | |
1612 | stp=2.5066282746310005; |
1613 | cof[1]=76.18009172947146; |
1614 | cof[2]=-86.50532032941677; |
1615 | cof[3]=24.01409824083091; |
1616 | cof[4]=-1.231739572450155; |
1617 | cof[5]=.1208650973866179e-2; |
1618 | cof[6]=-.5395239384953e-5; |
1619 | |
1620 | x_gln=xx_gln; |
1621 | y_gln=x_gln; |
1622 | tmp=x_gln+5.5; |
1623 | tmp=(x_gln+0.5)*log(tmp)-tmp; |
1624 | |
1625 | ser=1.000000000190015; |
1626 | |
1627 | for (int j = 1; j < 7; j++){ |
1628 | y_gln=y_gln+1.0; |
1629 | ser=ser+cof[j]/y_gln; |
1630 | } |
1631 | |
1632 | |
1633 | gammln=tmp+log(stp*ser/x_gln); |
1634 | return gammln; |
1635 | } |
1636 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #ifndef _JEventLoop_ |
9 | #define _JEventLoop_ |
10 | |
11 | #include <sys/time.h> |
12 | |
13 | #include <vector> |
14 | #include <list> |
15 | #include <string> |
16 | #include <utility> |
17 | #include <typeinfo> |
18 | #include <string.h> |
19 | #include <map> |
20 | #include <utility> |
21 | using std::vector; |
22 | using std::list; |
23 | using std::string; |
24 | using std::type_info; |
25 | |
26 | #include <JANA/jerror.h> |
27 | #include <JANA/JObject.h> |
28 | #include <JANA/JException.h> |
29 | #include <JANA/JEvent.h> |
30 | #include <JANA/JThread.h> |
31 | #include <JANA/JFactory_base.h> |
32 | #include <JANA/JCalibration.h> |
33 | #include <JANA/JGeometry.h> |
34 | #include <JANA/JResourceManager.h> |
35 | #include <JANA/JStreamLog.h> |
36 | |
37 | |
38 | #include "cint.h" |
39 | |
40 | |
41 | |
42 | namespace jana{ |
43 | |
44 | |
45 | template<class T> class JFactory; |
46 | class JApplication; |
47 | class JEventProcessor; |
48 | |
49 | |
50 | class JEventLoop{ |
51 | public: |
52 | |
53 | friend class JApplication; |
54 | |
55 | enum data_source_t{ |
56 | DATA_NOT_AVAILABLE = 1, |
57 | DATA_FROM_CACHE, |
58 | DATA_FROM_SOURCE, |
59 | DATA_FROM_FACTORY |
60 | }; |
61 | |
62 | typedef struct{ |
63 | string caller_name; |
64 | string caller_tag; |
65 | string callee_name; |
66 | string callee_tag; |
67 | double start_time; |
68 | double end_time; |
69 | data_source_t data_source; |
70 | }call_stack_t; |
71 | |
72 | typedef struct{ |
73 | const char* factory_name; |
74 | string tag; |
75 | const char* filename; |
76 | int line; |
77 | }error_call_stack_t; |
78 | |
79 | JEventLoop(JApplication *app); |
80 | virtual ~JEventLoop(); |
81 | virtual const char* className(void){return static_className();} |
82 | static const char* static_className(void){return "JEventLoop";} |
83 | |
84 | JApplication* GetJApplication(void) const {return app;} |
85 | void RefreshProcessorListFromJApplication(void); |
86 | virtual jerror_t AddFactory(JFactory_base* factory); |
87 | jerror_t RemoveFactory(JFactory_base* factory); |
88 | JFactory_base* GetFactory(const string data_name, const char *tag="", bool allow_deftag=true); |
89 | vector<JFactory_base*> GetFactories(void) const {return factories;} |
90 | void GetFactoryNames(vector<string> &factorynames); |
91 | void GetFactoryNames(map<string,string> &factorynames); |
92 | map<string,string> GetDefaultTags(void) const {return default_tags;} |
93 | jerror_t ClearFactories(void); |
94 | jerror_t PrintFactories(int sparsify=0); |
95 | jerror_t Print(const string data_name, const char *tag=""); |
96 | |
97 | JCalibration* GetJCalibration(); |
98 | template<class T> bool GetCalib(string namepath, map<string,T> &vals); |
99 | template<class T> bool GetCalib(string namepath, vector<T> &vals); |
100 | template<class T> bool GetCalib(string namepath, T &val); |
101 | |
102 | JGeometry* GetJGeometry(); |
103 | template<class T> bool GetGeom(string namepath, map<string,T> &vals); |
104 | template<class T> bool GetGeom(string namepath, T &val); |
105 | |
106 | JResourceManager* GetJResourceManager(void); |
107 | string GetResource(string namepath); |
108 | template<class T> bool GetResource(string namepath, T vals, int event_number=0); |
109 | |
110 | void Initialize(void); |
111 | jerror_t Loop(void); |
112 | jerror_t OneEvent(uint64_t event_number); |
113 | jerror_t OneEvent(void); |
114 | inline void Pause(void){pause = 1;} |
115 | inline void Resume(void){pause = 0;} |
116 | inline void Quit(void){quit = 1;} |
117 | inline bool GetQuit(void) const {return quit;} |
118 | void QuitProgram(void); |
119 | |
120 | |
121 | bool HasRandomAccess(void); |
122 | void AddToEventQueue(uint64_t event_number){ next_events_to_process.push_back(event_number); } |
123 | void AddToEventQueue(list<uint64_t> &event_numbers) { next_events_to_process.insert(next_events_to_process.end(), event_numbers.begin(), event_numbers.end()); } |
124 | list<uint64_t> GetEventQueue(void){ return next_events_to_process; } |
125 | void ClearEventQueue(void){ next_events_to_process.clear(); } |
126 | |
127 | template<class T> JFactory<T>* GetSingle(const T* &t, const char *tag="", bool exception_if_not_one=true); |
128 | template<class T> JFactory<T>* Get(vector<const T*> &t, const char *tag="", bool allow_deftag=true); |
129 | template<class T> JFactory<T>* GetFromFactory(vector<const T*> &t, const char *tag="", data_source_t &data_source=null_data_source, bool allow_deftag=true); |
130 | template<class T> jerror_t GetFromSource(vector<const T*> &t, JFactory_base *factory=NULL); |
131 | inline JEvent& GetJEvent(void){return event;} |
132 | inline void SetJEvent(JEvent *event){this->event = *event;} |
133 | inline void SetAutoFree(int auto_free){this->auto_free = auto_free;} |
134 | inline pthread_t GetPThreadID(void) const {return pthread_id;} |
135 | double GetInstantaneousRate(void) const {return rate_instantaneous;} |
136 | double GetIntegratedRate(void) const {return rate_integrated;} |
137 | double GetLastEventProcessingTime(void) const {return delta_time_single;} |
138 | unsigned int GetNevents(void) const {return Nevents;} |
139 | |
140 | inline bool CheckEventBoundary(uint64_t event_numberA, uint64_t event_numberB); |
141 | |
142 | inline bool GetCallStackRecordingStatus(void){ return record_call_stack; } |
143 | inline void DisableCallStackRecording(void){ record_call_stack = false; } |
144 | inline void EnableCallStackRecording(void){ record_call_stack = true; } |
145 | inline void CallStackStart(JEventLoop::call_stack_t &cs, const string &caller_name, const string &caller_tag, const string callee_name, const string callee_tag); |
146 | inline void CallStackEnd(JEventLoop::call_stack_t &cs); |
147 | inline vector<call_stack_t> GetCallStack(void){return call_stack;} |
148 | inline void AddToCallStack(call_stack_t &cs){if(record_call_stack) call_stack.push_back(cs);} |
149 | inline void AddToErrorCallStack(error_call_stack_t &cs){error_call_stack.push_back(cs);} |
150 | inline vector<error_call_stack_t> GetErrorCallStack(void){return error_call_stack;} |
151 | void PrintErrorCallStack(void); |
152 | |
153 | const JObject* FindByID(JObject::oid_t id); |
154 | template<class T> const T* FindByID(JObject::oid_t id); |
155 | JFactory_base* FindOwner(const JObject *t); |
156 | JFactory_base* FindOwner(JObject::oid_t id); |
157 | |
158 | |
159 | template<class T> void SetRef(T *t); |
160 | template<class T> T* GetRef(void); |
161 | template<class T> vector<T*> GetRefsT(void); |
162 | vector<pair<const char*, void*> > GetRefs(void){ return user_refs; } |
163 | template<class T> void RemoveRef(T *t); |
164 | |
165 | |
166 | uint64_t GetStatus(void){return event.GetStatus();} |
167 | bool GetStatusBit(uint32_t bit){return event.GetStatusBit(bit);} |
168 | bool SetStatusBit(uint32_t bit, bool val=true){return event.SetStatusBit(bit, val);} |
169 | bool ClearStatusBit(uint32_t bit){return event.ClearStatusBit(bit);} |
170 | void ClearStatus(void){event.ClearStatus();} |
171 | void SetStatusBitDescription(uint32_t bit, string description){event.SetStatusBitDescription(bit, description);} |
172 | string GetStatusBitDescription(uint32_t bit){return event.GetStatusBitDescription(bit);} |
173 | void GetStatusBitDescriptions(map<uint32_t, string> &status_bit_descriptions){return event.GetStatusBitDescriptions(status_bit_descriptions);} |
174 | string StatusWordToString(void); |
175 | |
176 | private: |
177 | JEvent event; |
178 | vector<JFactory_base*> factories; |
179 | vector<JEventProcessor*> processors; |
180 | vector<error_call_stack_t> error_call_stack; |
181 | vector<call_stack_t> call_stack; |
182 | JApplication *app; |
183 | JThread *jthread; |
184 | bool initialized; |
185 | bool print_parameters_called; |
186 | int pause; |
187 | int quit; |
188 | int auto_free; |
189 | pthread_t pthread_id; |
190 | map<string, string> default_tags; |
191 | vector<pair<string,string> > auto_activated_factories; |
192 | bool record_call_stack; |
193 | string caller_name; |
194 | string caller_tag; |
195 | vector<uint64_t> event_boundaries; |
196 | int32_t event_boundaries_run; |
197 | list<uint64_t> next_events_to_process; |
198 | |
199 | uint64_t Nevents; |
200 | uint64_t Nevents_rate; |
201 | double delta_time_single; |
202 | double delta_time_rate; |
203 | double delta_time; |
204 | double rate_instantaneous; |
205 | double rate_integrated; |
206 | |
207 | static data_source_t null_data_source; |
208 | |
209 | vector<pair<const char*, void*> > user_refs; |
210 | }; |
211 | |
212 | |
213 | |
214 | #ifdef G__DICTIONARY |
215 | typedef JEventLoop::call_stack_t call_stack_t; |
216 | typedef JEventLoop::error_call_stack_t error_call_stack_t; |
217 | #endif |
218 | |
219 | #if !defined(__CINT__) && !defined(__CLING__) |
220 | |
221 | |
222 | |
223 | |
224 | template<class T> |
225 | JFactory<T>* JEventLoop::GetSingle(const T* &t, const char *tag, bool exception_if_not_one) |
226 | { |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | vector<const T*> v; |
239 | JFactory<T> *fac = Get(v, tag); |
240 | |
241 | if(v.size()!=1){ |
242 | t = NULL; |
243 | if(exception_if_not_one) throw v.size(); |
244 | } |
245 | |
246 | t = v[0]; |
247 | |
248 | return fac; |
249 | } |
250 | |
251 | |
252 | |
253 | |
254 | template<class T> |
255 | JFactory<T>* JEventLoop::Get(vector<const T*> &t, const char *tag, bool allow_deftag) |
256 | { |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | |
265 | |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | const char *mytag = tag==NULL ? "":tag; |
| |
291 | if(strlen(mytag)==0 && allow_deftag){ |
| |
292 | map<string, string>::const_iterator iter = default_tags.find(T::static_className()); |
293 | if(iter!=default_tags.end())tag = iter->second.c_str(); |
| 5 | | Assuming the condition is true | |
|
| |
| |
294 | } |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | call_stack_t cs; |
302 | |
303 | |
304 | if(record_call_stack) CallStackStart(cs, caller_name, caller_tag, T::static_className(), tag); |
| 8 | | Assuming field 'record_call_stack' is false | |
|
| |
305 | |
306 | |
307 | JFactory<T>* factory=NULL; |
308 | try{ |
309 | factory = GetFromFactory(t, tag, cs.data_source, allow_deftag); |
| 10 | | Passing value via 2nd parameter 'tag' | |
|
| 11 | | Calling 'JEventLoop::GetFromFactory' | |
|
310 | if(!factory){ |
311 | |
312 | |
313 | |
314 | |
315 | |
316 | |
317 | |
318 | string p; |
319 | try{ |
320 | gPARMS->GetParameter("JANA:AUTOFACTORYCREATE", p); |
321 | }catch(...){} |
322 | if(p.size()==0){ |
323 | jout<<std::endl; |
324 | _DBG__; |
325 | jout<<"No factory of type \""<<T::static_className()<<"\" with tag \""<<tag<<"\" exists."<<std::endl; |
326 | jout<<"If you are reading objects from a file, I can auto-create a factory"<<std::endl; |
327 | jout<<"of the appropriate type to hold the objects, but this feature is turned"<<std::endl; |
328 | jout<<"off by default. To turn it on, set the \"JANA:AUTOFACTORYCREATE\""<<std::endl; |
329 | jout<<"configuration parameter. This can usually be done by passing the"<<std::endl; |
330 | jout<<"following argument to the program from the command line:"<<std::endl; |
331 | jout<<std::endl; |
332 | jout<<" -PJANA:AUTOFACTORYCREATE=1"<<std::endl; |
333 | jout<<std::endl; |
334 | jout<<"Note that since the most commonly expected occurance of this situation."<<std::endl; |
335 | jout<<"is an error, the program will now throw an exception so that the factory."<<std::endl; |
336 | jout<<"call stack can be printed."<<std::endl; |
337 | jout<<std::endl; |
338 | throw exception(); |
339 | }else{ |
340 | AddFactory(new JFactory<T>(tag)); |
341 | jout<<__FILE__<<":"<<__LINE__<<" Auto-created "<<T::static_className()<<":"<<tag<<" factory"<<std::endl; |
342 | |
343 | |
344 | |
345 | factory = GetFromFactory(t, tag, cs.data_source, allow_deftag); |
346 | } |
347 | } |
348 | }catch(exception &e){ |
349 | |
350 | |
351 | error_call_stack_t ecs; |
352 | ecs.factory_name = T::static_className(); |
353 | ecs.tag = tag; |
354 | ecs.filename = NULL; |
355 | error_call_stack.push_back(ecs); |
356 | throw e; |
357 | } |
358 | |
359 | |
360 | if(record_call_stack) CallStackEnd(cs); |
361 | |
362 | return factory; |
363 | } |
364 | |
365 | |
366 | |
367 | |
368 | template<class T> |
369 | JFactory<T>* JEventLoop::GetFromFactory(vector<const T*> &t, const char *tag, data_source_t &data_source, bool allow_deftag) |
370 | { |
371 | |
372 | |
373 | vector<JFactory_base*>::iterator iter=factories.begin(); |
374 | JFactory<T> *factory = NULL; |
375 | string className(T::static_className()); |
376 | |
377 | |
378 | |
379 | const char *mytag = tag==NULL ? "":tag; |
| 12 | | Assuming 'tag' is equal to NULL | |
|
| 13 | | Assuming pointer value is null | |
|
| |
380 | if(strlen(mytag)==0 && allow_deftag){ |
| |
381 | map<string, string>::const_iterator iter = default_tags.find(className); |
382 | if(iter!=default_tags.end())tag = iter->second.c_str(); |
| 16 | | Assuming the condition is false | |
|
| |
383 | } |
384 | |
385 | for(; iter!=factories.end(); iter++){ |
| 18 | | Calling 'operator!=<jana::JFactory_base **, std::vector<jana::JFactory_base *>>' | |
|
| 21 | | Returning from 'operator!=<jana::JFactory_base **, std::vector<jana::JFactory_base *>>' | |
|
| 22 | | Loop condition is true. Entering loop body | |
|
386 | |
387 | |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | if(className == (*iter)->GetDataClassName())factory = (JFactory<T>*)(*iter); |
| |
396 | if(factory == NULL)continue; |
| 24 | | Assuming 'factory' is not equal to NULL | |
|
| |
397 | const char *factag = factory->Tag()==NULL ? "":factory->Tag(); |
| 26 | | Assuming the condition is true | |
|
| |
398 | if(!strcmp(factag, tag)){ |
| 28 | | Null pointer passed to 2nd parameter expecting 'nonnull' |
|
399 | break; |
400 | }else{ |
401 | factory=NULL; |
402 | } |
403 | } |
404 | |
405 | |
406 | if(!factory){ |
407 | data_source = DATA_NOT_AVAILABLE; |
408 | return NULL; |
409 | } |
410 | |
411 | |
412 | |
413 | |
414 | if(factory->evnt_was_called()){ |
415 | factory->CopyFrom(t); |
416 | data_source = DATA_FROM_CACHE; |
417 | return factory; |
418 | } |
419 | |
420 | |
421 | if(factory->GetCheckSourceFirst()){ |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | jerror_t err = GetFromSource(t, factory); |
428 | if(err == NOERROR){ |
429 | |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | |
439 | |
440 | |
441 | |
442 | |
443 | factory->SetFactoryPointers(); |
444 | data_source = DATA_FROM_SOURCE; |
445 | |
446 | return factory; |
447 | } |
448 | } |
449 | |
450 | |
451 | |
452 | factory->Get(t); |
453 | factory->SetFactoryPointers(); |
454 | data_source = DATA_FROM_FACTORY; |
455 | |
456 | return factory; |
457 | } |
458 | |
459 | |
460 | |
461 | |
462 | template<class T> |
463 | jerror_t JEventLoop::GetFromSource(vector<const T*> &t, JFactory_base *factory) |
464 | { |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
475 | if(!factory)throw OBJECT_NOT_AVAILABLE; |
476 | |
477 | return event.GetObjects(t, factory); |
478 | } |
479 | |
480 | |
481 | |
482 | |
483 | inline void JEventLoop::CallStackStart(JEventLoop::call_stack_t &cs, const string &caller_name, const string &caller_tag, const string callee_name, const string callee_tag) |
484 | { |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | struct itimerval tmr; |
492 | getitimer(ITIMER_PROF, &tmr); |
493 | |
494 | cs.caller_name = this->caller_name; |
495 | cs.caller_tag = this->caller_tag; |
496 | this->caller_name = cs.callee_name = callee_name; |
497 | this->caller_tag = cs.callee_tag = callee_tag; |
498 | cs.start_time = tmr.it_value.tv_sec + tmr.it_value.tv_usec/1.0E6; |
499 | } |
500 | |
501 | |
502 | |
503 | |
504 | inline void JEventLoop::CallStackEnd(JEventLoop::call_stack_t &cs) |
505 | { |
506 | |
507 | |
508 | |
509 | |
510 | struct itimerval tmr; |
511 | getitimer(ITIMER_PROF, &tmr); |
512 | cs.end_time = tmr.it_value.tv_sec + tmr.it_value.tv_usec/1.0E6; |
513 | caller_name = cs.caller_name; |
514 | caller_tag = cs.caller_tag; |
515 | call_stack.push_back(cs); |
516 | } |
517 | |
518 | |
519 | |
520 | |
521 | inline bool JEventLoop::CheckEventBoundary(uint64_t event_numberA, uint64_t event_numberB) |
522 | { |
523 | |
524 | |
525 | |
526 | |
527 | |
528 | |
529 | |
530 | |
531 | |
532 | |
533 | |
534 | if(event.GetRunNumber()!=event_boundaries_run){ |
535 | event_boundaries.clear(); |
536 | JCalibration *jcalib = GetJCalibration(); |
537 | if(jcalib)jcalib->GetEventBoundaries(event_boundaries); |
538 | event_boundaries_run = event.GetRunNumber(); |
539 | } |
540 | |
541 | |
542 | for(unsigned int i=0; i<event_boundaries.size(); i++){ |
543 | uint64_t eb = event_boundaries[i]; |
544 | if((eb - event_numberA)*(eb - event_numberB) < 0.0 || eb==event_numberA){ |
545 | |
546 | return true; |
547 | } |
548 | } |
549 | |
550 | return false; |
551 | } |
552 | |
553 | |
554 | |
555 | |
556 | template<class T> |
557 | const T* JEventLoop::FindByID(JObject::oid_t id) |
558 | { |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | |
573 | |
574 | for(unsigned int i=0; i<factories.size(); i++){ |
575 | if(factories[i]->GetDataClassName() != T::static_className())continue; |
576 | |
577 | |
578 | |
579 | const JObject *my_obj = factories[i]->GetByID(id); |
580 | if(my_obj)return dynamic_cast<const T*>(my_obj); |
581 | } |
582 | |
583 | return NULL; |
584 | } |
585 | |
586 | |
587 | |
588 | |
589 | template<class T> |
590 | bool JEventLoop::GetCalib(string namepath, map<string,T> &vals) |
591 | { |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | |
599 | vals.clear(); |
600 | |
601 | JCalibration *calib = GetJCalibration(); |
602 | if(!calib){ |
603 | _DBG_<<"Unable to get JCalibration object for run "<<event.GetRunNumber()<<std::endl; |
604 | return true; |
605 | } |
606 | |
607 | return calib->Get(namepath, vals, event.GetEventNumber()); |
608 | } |
609 | |
610 | |
611 | |
612 | |
613 | template<class T> bool JEventLoop::GetCalib(string namepath, vector<T> &vals) |
614 | { |
615 | |
616 | |
617 | |
618 | vals.clear(); |
619 | |
620 | JCalibration *calib = GetJCalibration(); |
621 | if(!calib){ |
622 | _DBG_<<"Unable to get JCalibration object for run "<<event.GetRunNumber()<<std::endl; |
623 | return true; |
624 | } |
625 | |
626 | return calib->Get(namepath, vals, event.GetEventNumber()); |
627 | } |
628 | |
629 | |
630 | |
631 | |
632 | template<class T> bool JEventLoop::GetCalib(string namepath, T &val) |
633 | { |
634 | |
635 | |
636 | |
637 | |
638 | |
639 | |
640 | vector<T> vals; |
641 | bool ret = GetCalib(namepath, vals); |
642 | if(vals.empty()) return true; |
643 | val = vals[0]; |
644 | |
645 | return ret; |
646 | } |
647 | |
648 | |
649 | |
650 | |
651 | template<class T> |
652 | bool JEventLoop::GetGeom(string namepath, map<string,T> &vals) |
653 | { |
654 | |
655 | |
656 | |
657 | |
658 | |
659 | |
660 | |
661 | vals.clear(); |
662 | |
663 | JGeometry *geom = GetJGeometry(); |
664 | if(!geom){ |
665 | _DBG_<<"Unable to get JGeometry object for run "<<event.GetRunNumber()<<std::endl; |
666 | return true; |
667 | } |
668 | |
669 | return geom->Get(namepath, vals); |
670 | } |
671 | |
672 | |
673 | |
674 | |
675 | template<class T> bool JEventLoop::GetGeom(string namepath, T &val) |
676 | { |
677 | |
678 | |
679 | |
680 | JGeometry *geom = GetJGeometry(); |
681 | if(!geom){ |
682 | _DBG_<<"Unable to get JGeometry object for run "<<event.GetRunNumber()<<std::endl; |
683 | return true; |
684 | } |
685 | |
686 | return geom->Get(namepath, val); |
687 | } |
688 | |
689 | |
690 | |
691 | |
692 | template<class T> |
693 | void JEventLoop::SetRef(T *t) |
694 | { |
695 | pair<const char*, void*> p(typeid(T).name(), (void*)t); |
696 | user_refs.push_back(p); |
697 | } |
698 | |
699 | |
700 | |
701 | |
702 | template<class T> bool JEventLoop::GetResource(string namepath, T vals, int event_number) |
703 | { |
704 | JResourceManager *resource_manager = GetJResourceManager(); |
705 | if(!resource_manager){ |
706 | string mess = string("Unable to get the JResourceManager object (namepath=\"")+namepath+"\")"; |
707 | throw JException(mess); |
708 | } |
709 | |
710 | return resource_manager->Get(namepath, vals, event_number); |
711 | } |
712 | |
713 | |
714 | |
715 | |
716 | template<class T> |
717 | T* JEventLoop::GetRef(void) |
718 | { |
719 | |
720 | for(unsigned int i=0; i<user_refs.size(); i++){ |
721 | if(user_refs[i].first == typeid(T).name()) return (T*)user_refs[i].second; |
722 | } |
723 | |
724 | return NULL; |
725 | } |
726 | |
727 | |
728 | |
729 | |
730 | template<class T> |
731 | vector<T*> JEventLoop::GetRefsT(void) |
732 | { |
733 | vector<T*> refs; |
734 | for(unsigned int i=0; i<user_refs.size(); i++){ |
735 | if(user_refs[i].first == typeid(T).name()){ |
736 | refs.push_back((T*)user_refs[i].second); |
737 | } |
738 | } |
739 | |
740 | return refs; |
741 | } |
742 | |
743 | |
744 | |
745 | |
746 | template<class T> |
747 | void JEventLoop::RemoveRef(T *t) |
748 | { |
749 | vector<pair<const char*, void*> >::iterator iter; |
750 | for(iter=user_refs.begin(); iter!= user_refs.end(); iter++){ |
751 | if(iter->second == (void*)t){ |
752 | user_refs.erase(iter); |
753 | return; |
754 | } |
755 | } |
756 | _DBG_<<" Attempt to remove user reference not in event loop!" << std::endl; |
757 | } |
758 | |
759 | |
760 | #endif //__CINT__ __CLING__ |
761 | |
762 | } |
763 | |
764 | |
765 | |
766 | #endif // _JEventLoop_ |
767 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | #ifndef _STL_ITERATOR_H |
61 | #define _STL_ITERATOR_H 1 |
62 | |
63 | #include <bits/cpp_type_traits.h> |
64 | #include <ext/type_traits.h> |
65 | #include <bits/move.h> |
66 | |
67 | namespace std _GLIBCXX_VISIBILITY(default) |
68 | { |
69 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | template<typename _Iterator> |
96 | class reverse_iterator |
97 | : public iterator<typename iterator_traits<_Iterator>::iterator_category, |
98 | typename iterator_traits<_Iterator>::value_type, |
99 | typename iterator_traits<_Iterator>::difference_type, |
100 | typename iterator_traits<_Iterator>::pointer, |
101 | typename iterator_traits<_Iterator>::reference> |
102 | { |
103 | protected: |
104 | _Iterator current; |
105 | |
106 | typedef iterator_traits<_Iterator> __traits_type; |
107 | |
108 | public: |
109 | typedef _Iterator iterator_type; |
110 | typedef typename __traits_type::difference_type difference_type; |
111 | typedef typename __traits_type::pointer pointer; |
112 | typedef typename __traits_type::reference reference; |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | reverse_iterator() : current() { } |
121 | |
122 | |
123 | |
124 | |
125 | explicit |
126 | reverse_iterator(iterator_type __x) : current(__x) { } |
127 | |
128 | |
129 | |
130 | |
131 | reverse_iterator(const reverse_iterator& __x) |
132 | : current(__x.current) { } |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | template<typename _Iter> |
139 | reverse_iterator(const reverse_iterator<_Iter>& __x) |
140 | : current(__x.base()) { } |
141 | |
142 | |
143 | |
144 | |
145 | iterator_type |
146 | base() const |
147 | { return current; } |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | reference |
160 | operator*() const |
161 | { |
162 | _Iterator __tmp = current; |
163 | return *--__tmp; |
164 | } |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | pointer |
172 | operator->() const |
173 | { return &(operator*()); } |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | reverse_iterator& |
181 | operator++() |
182 | { |
183 | --current; |
184 | return *this; |
185 | } |
186 | |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | reverse_iterator |
193 | operator++(int) |
194 | { |
195 | reverse_iterator __tmp = *this; |
196 | --current; |
197 | return __tmp; |
198 | } |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | reverse_iterator& |
206 | operator--() |
207 | { |
208 | ++current; |
209 | return *this; |
210 | } |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | reverse_iterator |
218 | operator--(int) |
219 | { |
220 | reverse_iterator __tmp = *this; |
221 | ++current; |
222 | return __tmp; |
223 | } |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | reverse_iterator |
231 | operator+(difference_type __n) const |
232 | { return reverse_iterator(current - __n); } |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | reverse_iterator& |
241 | operator+=(difference_type __n) |
242 | { |
243 | current -= __n; |
244 | return *this; |
245 | } |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | reverse_iterator |
253 | operator-(difference_type __n) const |
254 | { return reverse_iterator(current + __n); } |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | reverse_iterator& |
263 | operator-=(difference_type __n) |
264 | { |
265 | current += __n; |
266 | return *this; |
267 | } |
268 | |
269 | |
270 | |
271 | |
272 | |
273 | |
274 | reference |
275 | operator[](difference_type __n) const |
276 | { return *(*this + __n); } |
277 | }; |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | template<typename _Iterator> |
290 | inline bool |
291 | operator==(const reverse_iterator<_Iterator>& __x, |
292 | const reverse_iterator<_Iterator>& __y) |
293 | { return __x.base() == __y.base(); } |
294 | |
295 | template<typename _Iterator> |
296 | inline bool |
297 | operator<(const reverse_iterator<_Iterator>& __x, |
298 | const reverse_iterator<_Iterator>& __y) |
299 | { return __y.base() < __x.base(); } |
300 | |
301 | template<typename _Iterator> |
302 | inline bool |
303 | operator!=(const reverse_iterator<_Iterator>& __x, |
304 | const reverse_iterator<_Iterator>& __y) |
305 | { return !(__x == __y); } |
306 | |
307 | template<typename _Iterator> |
308 | inline bool |
309 | operator>(const reverse_iterator<_Iterator>& __x, |
310 | const reverse_iterator<_Iterator>& __y) |
311 | { return __y < __x; } |
312 | |
313 | template<typename _Iterator> |
314 | inline bool |
315 | operator<=(const reverse_iterator<_Iterator>& __x, |
316 | const reverse_iterator<_Iterator>& __y) |
317 | { return !(__y < __x); } |
318 | |
319 | template<typename _Iterator> |
320 | inline bool |
321 | operator>=(const reverse_iterator<_Iterator>& __x, |
322 | const reverse_iterator<_Iterator>& __y) |
323 | { return !(__x < __y); } |
324 | |
325 | template<typename _Iterator> |
326 | inline typename reverse_iterator<_Iterator>::difference_type |
327 | operator-(const reverse_iterator<_Iterator>& __x, |
328 | const reverse_iterator<_Iterator>& __y) |
329 | { return __y.base() - __x.base(); } |
330 | |
331 | template<typename _Iterator> |
332 | inline reverse_iterator<_Iterator> |
333 | operator+(typename reverse_iterator<_Iterator>::difference_type __n, |
334 | const reverse_iterator<_Iterator>& __x) |
335 | { return reverse_iterator<_Iterator>(__x.base() - __n); } |
336 | |
337 | |
338 | |
339 | template<typename _IteratorL, typename _IteratorR> |
340 | inline bool |
341 | operator==(const reverse_iterator<_IteratorL>& __x, |
342 | const reverse_iterator<_IteratorR>& __y) |
343 | { return __x.base() == __y.base(); } |
344 | |
345 | template<typename _IteratorL, typename _IteratorR> |
346 | inline bool |
347 | operator<(const reverse_iterator<_IteratorL>& __x, |
348 | const reverse_iterator<_IteratorR>& __y) |
349 | { return __y.base() < __x.base(); } |
350 | |
351 | template<typename _IteratorL, typename _IteratorR> |
352 | inline bool |
353 | operator!=(const reverse_iterator<_IteratorL>& __x, |
354 | const reverse_iterator<_IteratorR>& __y) |
355 | { return !(__x == __y); } |
356 | |
357 | template<typename _IteratorL, typename _IteratorR> |
358 | inline bool |
359 | operator>(const reverse_iterator<_IteratorL>& __x, |
360 | const reverse_iterator<_IteratorR>& __y) |
361 | { return __y < __x; } |
362 | |
363 | template<typename _IteratorL, typename _IteratorR> |
364 | inline bool |
365 | operator<=(const reverse_iterator<_IteratorL>& __x, |
366 | const reverse_iterator<_IteratorR>& __y) |
367 | { return !(__y < __x); } |
368 | |
369 | template<typename _IteratorL, typename _IteratorR> |
370 | inline bool |
371 | operator>=(const reverse_iterator<_IteratorL>& __x, |
372 | const reverse_iterator<_IteratorR>& __y) |
373 | { return !(__x < __y); } |
374 | |
375 | template<typename _IteratorL, typename _IteratorR> |
376 | #if __cplusplus >= 201103L |
377 | |
378 | inline auto |
379 | operator-(const reverse_iterator<_IteratorL>& __x, |
380 | const reverse_iterator<_IteratorR>& __y) |
381 | -> decltype(__y.base() - __x.base()) |
382 | #else |
383 | inline typename reverse_iterator<_IteratorL>::difference_type |
384 | operator-(const reverse_iterator<_IteratorL>& __x, |
385 | const reverse_iterator<_IteratorR>& __y) |
386 | #endif |
387 | { return __y.base() - __x.base(); } |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |
401 | template<typename _Container> |
402 | class back_insert_iterator |
403 | : public iterator<output_iterator_tag, void, void, void, void> |
404 | { |
405 | protected: |
406 | _Container* container; |
407 | |
408 | public: |
409 | |
410 | typedef _Container container_type; |
411 | |
412 | |
413 | explicit |
414 | back_insert_iterator(_Container& __x) : container(&__x) { } |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | #if __cplusplus < 201103L |
428 | back_insert_iterator& |
429 | operator=(typename _Container::const_reference __value) |
430 | { |
431 | container->push_back(__value); |
432 | return *this; |
433 | } |
434 | #else |
435 | back_insert_iterator& |
436 | operator=(const typename _Container::value_type& __value) |
437 | { |
438 | container->push_back(__value); |
439 | return *this; |
440 | } |
441 | |
442 | back_insert_iterator& |
443 | operator=(typename _Container::value_type&& __value) |
444 | { |
445 | container->push_back(std::move(__value)); |
446 | return *this; |
447 | } |
448 | #endif |
449 | |
450 | |
451 | back_insert_iterator& |
452 | operator*() |
453 | { return *this; } |
454 | |
455 | |
456 | back_insert_iterator& |
457 | operator++() |
458 | { return *this; } |
459 | |
460 | |
461 | back_insert_iterator |
462 | operator++(int) |
463 | { return *this; } |
464 | }; |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
475 | |
476 | |
477 | template<typename _Container> |
478 | inline back_insert_iterator<_Container> |
479 | back_inserter(_Container& __x) |
480 | { return back_insert_iterator<_Container>(__x); } |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | |
492 | template<typename _Container> |
493 | class front_insert_iterator |
494 | : public iterator<output_iterator_tag, void, void, void, void> |
495 | { |
496 | protected: |
497 | _Container* container; |
498 | |
499 | public: |
500 | |
501 | typedef _Container container_type; |
502 | |
503 | |
504 | explicit front_insert_iterator(_Container& __x) : container(&__x) { } |
505 | |
506 | |
507 | |
508 | |
509 | |
510 | |
511 | |
512 | |
513 | |
514 | |
515 | |
516 | |
517 | #if __cplusplus < 201103L |
518 | front_insert_iterator& |
519 | operator=(typename _Container::const_reference __value) |
520 | { |
521 | container->push_front(__value); |
522 | return *this; |
523 | } |
524 | #else |
525 | front_insert_iterator& |
526 | operator=(const typename _Container::value_type& __value) |
527 | { |
528 | container->push_front(__value); |
529 | return *this; |
530 | } |
531 | |
532 | front_insert_iterator& |
533 | operator=(typename _Container::value_type&& __value) |
534 | { |
535 | container->push_front(std::move(__value)); |
536 | return *this; |
537 | } |
538 | #endif |
539 | |
540 | |
541 | front_insert_iterator& |
542 | operator*() |
543 | { return *this; } |
544 | |
545 | |
546 | front_insert_iterator& |
547 | operator++() |
548 | { return *this; } |
549 | |
550 | |
551 | front_insert_iterator |
552 | operator++(int) |
553 | { return *this; } |
554 | }; |
555 | |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | template<typename _Container> |
568 | inline front_insert_iterator<_Container> |
569 | front_inserter(_Container& __x) |
570 | { return front_insert_iterator<_Container>(__x); } |
571 | |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | |
579 | |
580 | |
581 | |
582 | |
583 | |
584 | |
585 | |
586 | template<typename _Container> |
587 | class insert_iterator |
588 | : public iterator<output_iterator_tag, void, void, void, void> |
589 | { |
590 | protected: |
591 | _Container* container; |
592 | typename _Container::iterator iter; |
593 | |
594 | public: |
595 | |
596 | typedef _Container container_type; |
597 | |
598 | |
599 | |
600 | |
601 | |
602 | insert_iterator(_Container& __x, typename _Container::iterator __i) |
603 | : container(&__x), iter(__i) {} |
604 | |
605 | |
606 | |
607 | |
608 | |
609 | |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | |
619 | |
620 | |
621 | |
622 | |
623 | |
624 | |
625 | |
626 | |
627 | |
628 | #if __cplusplus < 201103L |
629 | insert_iterator& |
630 | operator=(typename _Container::const_reference __value) |
631 | { |
632 | iter = container->insert(iter, __value); |
633 | ++iter; |
634 | return *this; |
635 | } |
636 | #else |
637 | insert_iterator& |
638 | operator=(const typename _Container::value_type& __value) |
639 | { |
640 | iter = container->insert(iter, __value); |
641 | ++iter; |
642 | return *this; |
643 | } |
644 | |
645 | insert_iterator& |
646 | operator=(typename _Container::value_type&& __value) |
647 | { |
648 | iter = container->insert(iter, std::move(__value)); |
649 | ++iter; |
650 | return *this; |
651 | } |
652 | #endif |
653 | |
654 | |
655 | insert_iterator& |
656 | operator*() |
657 | { return *this; } |
658 | |
659 | |
660 | insert_iterator& |
661 | operator++() |
662 | { return *this; } |
663 | |
664 | |
665 | insert_iterator& |
666 | operator++(int) |
667 | { return *this; } |
668 | }; |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | |
677 | |
678 | |
679 | |
680 | |
681 | template<typename _Container, typename _Iterator> |
682 | inline insert_iterator<_Container> |
683 | inserter(_Container& __x, _Iterator __i) |
684 | { |
685 | return insert_iterator<_Container>(__x, |
686 | typename _Container::iterator(__i)); |
687 | } |
688 | |
689 | |
690 | |
691 | _GLIBCXX_END_NAMESPACE_VERSION |
692 | } |
693 | |
694 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) |
695 | { |
696 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
697 | |
698 | |
699 | |
700 | |
701 | |
702 | |
703 | |
704 | |
705 | using std::iterator_traits; |
706 | using std::iterator; |
707 | template<typename _Iterator, typename _Container> |
708 | class __normal_iterator |
709 | { |
710 | protected: |
711 | _Iterator _M_current; |
712 | |
713 | typedef iterator_traits<_Iterator> __traits_type; |
714 | |
715 | public: |
716 | typedef _Iterator iterator_type; |
717 | typedef typename __traits_type::iterator_category iterator_category; |
718 | typedef typename __traits_type::value_type value_type; |
719 | typedef typename __traits_type::difference_type difference_type; |
720 | typedef typename __traits_type::reference reference; |
721 | typedef typename __traits_type::pointer pointer; |
722 | |
723 | _GLIBCXX_CONSTEXPR __normal_iterator() : _M_current(_Iterator()) { } |
724 | |
725 | explicit |
726 | __normal_iterator(const _Iterator& __i) : _M_current(__i) { } |
727 | |
728 | |
729 | template<typename _Iter> |
730 | __normal_iterator(const __normal_iterator<_Iter, |
731 | typename __enable_if< |
732 | (std::__are_same<_Iter, typename _Container::pointer>::__value), |
733 | _Container>::__type>& __i) |
734 | : _M_current(__i.base()) { } |
735 | |
736 | |
737 | reference |
738 | operator*() const |
739 | { return *_M_current; } |
740 | |
741 | pointer |
742 | operator->() const |
743 | { return _M_current; } |
744 | |
745 | __normal_iterator& |
746 | operator++() |
747 | { |
748 | ++_M_current; |
749 | return *this; |
750 | } |
751 | |
752 | __normal_iterator |
753 | operator++(int) |
754 | { return __normal_iterator(_M_current++); } |
755 | |
756 | |
757 | __normal_iterator& |
758 | operator--() |
759 | { |
760 | --_M_current; |
761 | return *this; |
762 | } |
763 | |
764 | __normal_iterator |
765 | operator--(int) |
766 | { return __normal_iterator(_M_current--); } |
767 | |
768 | |
769 | reference |
770 | operator[](const difference_type& __n) const |
771 | { return _M_current[__n]; } |
772 | |
773 | __normal_iterator& |
774 | operator+=(const difference_type& __n) |
775 | { _M_current += __n; return *this; } |
776 | |
777 | __normal_iterator |
778 | operator+(const difference_type& __n) const |
779 | { return __normal_iterator(_M_current + __n); } |
780 | |
781 | __normal_iterator& |
782 | operator-=(const difference_type& __n) |
783 | { _M_current -= __n; return *this; } |
784 | |
785 | __normal_iterator |
786 | operator-(const difference_type& __n) const |
787 | { return __normal_iterator(_M_current - __n); } |
788 | |
789 | const _Iterator& |
790 | base() const |
791 | { return _M_current; } |
792 | }; |
793 | |
794 | |
795 | |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
804 | inline bool |
805 | operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, |
806 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
807 | { return __lhs.base() == __rhs.base(); } |
808 | |
809 | template<typename _Iterator, typename _Container> |
810 | inline bool |
811 | operator==(const __normal_iterator<_Iterator, _Container>& __lhs, |
812 | const __normal_iterator<_Iterator, _Container>& __rhs) |
813 | { return __lhs.base() == __rhs.base(); } |
814 | |
815 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
816 | inline bool |
817 | operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
818 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
819 | { return __lhs.base() != __rhs.base(); } |
820 | |
821 | template<typename _Iterator, typename _Container> |
822 | inline bool |
823 | operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, |
824 | const __normal_iterator<_Iterator, _Container>& __rhs) |
825 | { return __lhs.base() != __rhs.base(); } |
| 19 | | Assuming the condition is true | |
|
| 20 | | Returning the value 1, which participates in a condition later | |
|
826 | |
827 | |
828 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
829 | inline bool |
830 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, |
831 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
832 | { return __lhs.base() < __rhs.base(); } |
833 | |
834 | template<typename _Iterator, typename _Container> |
835 | inline bool |
836 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs, |
837 | const __normal_iterator<_Iterator, _Container>& __rhs) |
838 | { return __lhs.base() < __rhs.base(); } |
839 | |
840 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
841 | inline bool |
842 | operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, |
843 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
844 | { return __lhs.base() > __rhs.base(); } |
845 | |
846 | template<typename _Iterator, typename _Container> |
847 | inline bool |
848 | operator>(const __normal_iterator<_Iterator, _Container>& __lhs, |
849 | const __normal_iterator<_Iterator, _Container>& __rhs) |
850 | { return __lhs.base() > __rhs.base(); } |
851 | |
852 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
853 | inline bool |
854 | operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
855 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
856 | { return __lhs.base() <= __rhs.base(); } |
857 | |
858 | template<typename _Iterator, typename _Container> |
859 | inline bool |
860 | operator<=(const __normal_iterator<_Iterator, _Container>& __lhs, |
861 | const __normal_iterator<_Iterator, _Container>& __rhs) |
862 | { return __lhs.base() <= __rhs.base(); } |
863 | |
864 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
865 | inline bool |
866 | operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
867 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
868 | { return __lhs.base() >= __rhs.base(); } |
869 | |
870 | template<typename _Iterator, typename _Container> |
871 | inline bool |
872 | operator>=(const __normal_iterator<_Iterator, _Container>& __lhs, |
873 | const __normal_iterator<_Iterator, _Container>& __rhs) |
874 | { return __lhs.base() >= __rhs.base(); } |
875 | |
876 | |
877 | |
878 | |
879 | |
880 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
881 | #if __cplusplus >= 201103L |
882 | |
883 | inline auto |
884 | operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, |
885 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
886 | -> decltype(__lhs.base() - __rhs.base()) |
887 | #else |
888 | inline typename __normal_iterator<_IteratorL, _Container>::difference_type |
889 | operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, |
890 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
891 | #endif |
892 | { return __lhs.base() - __rhs.base(); } |
893 | |
894 | template<typename _Iterator, typename _Container> |
895 | inline typename __normal_iterator<_Iterator, _Container>::difference_type |
896 | operator-(const __normal_iterator<_Iterator, _Container>& __lhs, |
897 | const __normal_iterator<_Iterator, _Container>& __rhs) |
898 | { return __lhs.base() - __rhs.base(); } |
899 | |
900 | template<typename _Iterator, typename _Container> |
901 | inline __normal_iterator<_Iterator, _Container> |
902 | operator+(typename __normal_iterator<_Iterator, _Container>::difference_type |
903 | __n, const __normal_iterator<_Iterator, _Container>& __i) |
904 | { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); } |
905 | |
906 | _GLIBCXX_END_NAMESPACE_VERSION |
907 | } |
908 | |
909 | #if __cplusplus >= 201103L |
910 | |
911 | namespace std _GLIBCXX_VISIBILITY(default) |
912 | { |
913 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
914 | |
915 | |
916 | |
917 | |
918 | |
919 | |
920 | |
921 | |
922 | |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | template<typename _Iterator> |
930 | class move_iterator |
931 | { |
932 | protected: |
933 | _Iterator _M_current; |
934 | |
935 | typedef iterator_traits<_Iterator> __traits_type; |
936 | |
937 | public: |
938 | typedef _Iterator iterator_type; |
939 | typedef typename __traits_type::iterator_category iterator_category; |
940 | typedef typename __traits_type::value_type value_type; |
941 | typedef typename __traits_type::difference_type difference_type; |
942 | |
943 | typedef _Iterator pointer; |
944 | typedef value_type&& reference; |
945 | |
946 | move_iterator() |
947 | : _M_current() { } |
948 | |
949 | explicit |
950 | move_iterator(iterator_type __i) |
951 | : _M_current(__i) { } |
952 | |
953 | template<typename _Iter> |
954 | move_iterator(const move_iterator<_Iter>& __i) |
955 | : _M_current(__i.base()) { } |
956 | |
957 | iterator_type |
958 | base() const |
959 | { return _M_current; } |
960 | |
961 | reference |
962 | operator*() const |
963 | { return std::move(*_M_current); } |
964 | |
965 | pointer |
966 | operator->() const |
967 | { return _M_current; } |
968 | |
969 | move_iterator& |
970 | operator++() |
971 | { |
972 | ++_M_current; |
973 | return *this; |
974 | } |
975 | |
976 | move_iterator |
977 | operator++(int) |
978 | { |
979 | move_iterator __tmp = *this; |
980 | ++_M_current; |
981 | return __tmp; |
982 | } |
983 | |
984 | move_iterator& |
985 | operator--() |
986 | { |
987 | --_M_current; |
988 | return *this; |
989 | } |
990 | |
991 | move_iterator |
992 | operator--(int) |
993 | { |
994 | move_iterator __tmp = *this; |
995 | --_M_current; |
996 | return __tmp; |
997 | } |
998 | |
999 | move_iterator |
1000 | operator+(difference_type __n) const |
1001 | { return move_iterator(_M_current + __n); } |
1002 | |
1003 | move_iterator& |
1004 | operator+=(difference_type __n) |
1005 | { |
1006 | _M_current += __n; |
1007 | return *this; |
1008 | } |
1009 | |
1010 | move_iterator |
1011 | operator-(difference_type __n) const |
1012 | { return move_iterator(_M_current - __n); } |
1013 | |
1014 | move_iterator& |
1015 | operator-=(difference_type __n) |
1016 | { |
1017 | _M_current -= __n; |
1018 | return *this; |
1019 | } |
1020 | |
1021 | reference |
1022 | operator[](difference_type __n) const |
1023 | { return std::move(_M_current[__n]); } |
1024 | }; |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | template<typename _IteratorL, typename _IteratorR> |
1030 | inline bool |
1031 | operator==(const move_iterator<_IteratorL>& __x, |
1032 | const move_iterator<_IteratorR>& __y) |
1033 | { return __x.base() == __y.base(); } |
1034 | |
1035 | template<typename _Iterator> |
1036 | inline bool |
1037 | operator==(const move_iterator<_Iterator>& __x, |
1038 | const move_iterator<_Iterator>& __y) |
1039 | { return __x.base() == __y.base(); } |
1040 | |
1041 | template<typename _IteratorL, typename _IteratorR> |
1042 | inline bool |
1043 | operator!=(const move_iterator<_IteratorL>& __x, |
1044 | const move_iterator<_IteratorR>& __y) |
1045 | { return !(__x == __y); } |
1046 | |
1047 | template<typename _Iterator> |
1048 | inline bool |
1049 | operator!=(const move_iterator<_Iterator>& __x, |
1050 | const move_iterator<_Iterator>& __y) |
1051 | { return !(__x == __y); } |
1052 | |
1053 | template<typename _IteratorL, typename _IteratorR> |
1054 | inline bool |
1055 | operator<(const move_iterator<_IteratorL>& __x, |
1056 | const move_iterator<_IteratorR>& __y) |
1057 | { return __x.base() < __y.base(); } |
1058 | |
1059 | template<typename _Iterator> |
1060 | inline bool |
1061 | operator<(const move_iterator<_Iterator>& __x, |
1062 | const move_iterator<_Iterator>& __y) |
1063 | { return __x.base() < __y.base(); } |
1064 | |
1065 | template<typename _IteratorL, typename _IteratorR> |
1066 | inline bool |
1067 | operator<=(const move_iterator<_IteratorL>& __x, |
1068 | const move_iterator<_IteratorR>& __y) |
1069 | { return !(__y < __x); } |
1070 | |
1071 | template<typename _Iterator> |
1072 | inline bool |
1073 | operator<=(const move_iterator<_Iterator>& __x, |
1074 | const move_iterator<_Iterator>& __y) |
1075 | { return !(__y < __x); } |
1076 | |
1077 | template<typename _IteratorL, typename _IteratorR> |
1078 | inline bool |
1079 | operator>(const move_iterator<_IteratorL>& __x, |
1080 | const move_iterator<_IteratorR>& __y) |
1081 | { return __y < __x; } |
1082 | |
1083 | template<typename _Iterator> |
1084 | inline bool |
1085 | operator>(const move_iterator<_Iterator>& __x, |
1086 | const move_iterator<_Iterator>& __y) |
1087 | { return __y < __x; } |
1088 | |
1089 | template<typename _IteratorL, typename _IteratorR> |
1090 | inline bool |
1091 | operator>=(const move_iterator<_IteratorL>& __x, |
1092 | const move_iterator<_IteratorR>& __y) |
1093 | { return !(__x < __y); } |
1094 | |
1095 | template<typename _Iterator> |
1096 | inline bool |
1097 | operator>=(const move_iterator<_Iterator>& __x, |
1098 | const move_iterator<_Iterator>& __y) |
1099 | { return !(__x < __y); } |
1100 | |
1101 | |
1102 | template<typename _IteratorL, typename _IteratorR> |
1103 | inline auto |
1104 | operator-(const move_iterator<_IteratorL>& __x, |
1105 | const move_iterator<_IteratorR>& __y) |
1106 | -> decltype(__x.base() - __y.base()) |
1107 | { return __x.base() - __y.base(); } |
1108 | |
1109 | template<typename _Iterator> |
1110 | inline auto |
1111 | operator-(const move_iterator<_Iterator>& __x, |
1112 | const move_iterator<_Iterator>& __y) |
1113 | -> decltype(__x.base() - __y.base()) |
1114 | { return __x.base() - __y.base(); } |
1115 | |
1116 | template<typename _Iterator> |
1117 | inline move_iterator<_Iterator> |
1118 | operator+(typename move_iterator<_Iterator>::difference_type __n, |
1119 | const move_iterator<_Iterator>& __x) |
1120 | { return __x + __n; } |
1121 | |
1122 | template<typename _Iterator> |
1123 | inline move_iterator<_Iterator> |
1124 | make_move_iterator(_Iterator __i) |
1125 | { return move_iterator<_Iterator>(__i); } |
1126 | |
1127 | template<typename _Iterator, typename _ReturnType |
1128 | = typename conditional<__move_if_noexcept_cond |
1129 | <typename iterator_traits<_Iterator>::value_type>::value, |
1130 | _Iterator, move_iterator<_Iterator>>::type> |
1131 | inline _ReturnType |
1132 | __make_move_if_noexcept_iterator(_Iterator __i) |
1133 | { return _ReturnType(__i); } |
1134 | |
1135 | |
1136 | |
1137 | _GLIBCXX_END_NAMESPACE_VERSION |
1138 | } |
1139 | |
1140 | #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter) |
1141 | #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \ |
1142 | std::__make_move_if_noexcept_iterator(_Iter) |
1143 | #else |
1144 | #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter) |
1145 | #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter) |
1146 | #endif // C++11 |
1147 | |
1148 | #endif |