-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathBinaryFileReader.cc
813 lines (678 loc) · 33.3 KB
/
BinaryFileReader.cc
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
61
62
63
64
65
66
67
68
69
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
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
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
/**
* @file PandoraSDK/src/Persistency/BinaryFileReader.cc
*
* @brief Implementation of the binary file reader class.
*
* $Log: $
*/
#include "Api/PandoraApi.h"
#include "Objects/CaloHit.h"
#include "Objects/Track.h"
#include "Persistency/BinaryFileReader.h"
namespace pandora
{
BinaryFileReader::BinaryFileReader(const pandora::Pandora &pandora, const std::string &fileName) :
FileReader(pandora, fileName),
m_containerPosition(0),
m_containerSize(0)
{
m_fileType = BINARY;
m_fileStream.open(fileName.c_str(), std::ios::in | std::ios::binary);
if (!m_fileStream.is_open() || !m_fileStream.good())
throw StatusCodeException(STATUS_CODE_FAILURE);
}
//------------------------------------------------------------------------------------------------------------------------------------------
BinaryFileReader::~BinaryFileReader()
{
m_fileStream.close();
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadHeader()
{
std::string fileHash;
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(fileHash));
if (PANDORA_FILE_HASH != fileHash)
return STATUS_CODE_FAILURE;
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(m_containerId));
if ((EVENT_CONTAINER != m_containerId) && (GEOMETRY_CONTAINER != m_containerId))
return STATUS_CODE_FAILURE;
m_containerPosition = m_fileStream.tellg();
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(m_containerSize));
if (0 == m_containerSize)
return STATUS_CODE_FAILURE;
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::GoToNextContainer()
{
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadHeader());
m_fileStream.seekg(m_containerPosition + m_containerSize, std::ios::beg);
if (!m_fileStream.good())
return STATUS_CODE_FAILURE;
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
ContainerId BinaryFileReader::GetNextContainerId()
{
const std::ifstream::pos_type initialPosition(m_fileStream.tellg());
std::string fileHash;
const StatusCode fileHashStatusCode(this->ReadVariable(fileHash));
if (STATUS_CODE_SUCCESS != fileHashStatusCode)
throw StatusCodeException(fileHashStatusCode);
if (PANDORA_FILE_HASH != fileHash)
throw StatusCodeException(STATUS_CODE_FAILURE);
ContainerId containerId(UNKNOWN_CONTAINER);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(containerId));
m_fileStream.seekg(initialPosition, std::ios::beg);
if (!m_fileStream.good())
throw StatusCodeException(STATUS_CODE_FAILURE);
return containerId;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::GoToGeometry(const unsigned int geometryNumber)
{
int nGeometriesRead(0);
m_fileStream.seekg(0, std::ios::beg);
if (!m_fileStream.good())
return STATUS_CODE_FAILURE;
if (GEOMETRY_CONTAINER != this->GetNextContainerId())
--nGeometriesRead;
while (nGeometriesRead < static_cast<int>(geometryNumber))
{
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->GoToNextGeometry());
++nGeometriesRead;
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::GoToEvent(const unsigned int eventNumber)
{
int nEventsRead(0);
m_fileStream.seekg(0, std::ios::beg);
if (!m_fileStream.good())
return STATUS_CODE_FAILURE;
if (EVENT_CONTAINER != this->GetNextContainerId())
--nEventsRead;
while (nEventsRead < static_cast<int>(eventNumber))
{
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->GoToNextEvent());
++nEventsRead;
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadNextGeometryComponent()
{
ComponentId componentId(UNKNOWN_COMPONENT);
const StatusCode statusCode(this->ReadVariable(componentId));
if (STATUS_CODE_SUCCESS != statusCode)
{
if (STATUS_CODE_NOT_FOUND != statusCode)
throw StatusCodeException(statusCode);
return STATUS_CODE_NOT_FOUND;
}
switch (componentId)
{
case SUB_DETECTOR_COMPONENT:
return this->ReadSubDetector(false);
case LAR_TPC_COMPONENT:
return this->ReadLArTPC(false);
case LINE_GAP_COMPONENT:
return this->ReadLineGap(false);
case BOX_GAP_COMPONENT:
return this->ReadBoxGap(false);
case CONCENTRIC_GAP_COMPONENT:
return this->ReadConcentricGap(false);
case GEOMETRY_END_COMPONENT:
m_containerId = UNKNOWN_CONTAINER;
return STATUS_CODE_NOT_FOUND;
default:
throw StatusCodeException(STATUS_CODE_FAILURE);
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadNextEventComponent()
{
ComponentId componentId(UNKNOWN_COMPONENT);
const StatusCode statusCode(this->ReadVariable(componentId));
if (STATUS_CODE_SUCCESS != statusCode)
{
if (STATUS_CODE_NOT_FOUND != statusCode)
throw StatusCodeException(statusCode);
return STATUS_CODE_NOT_FOUND;
}
switch (componentId)
{
case CALO_HIT_COMPONENT:
return this->ReadCaloHit(false);
case TRACK_COMPONENT:
return this->ReadTrack(false);
case MC_PARTICLE_COMPONENT:
return this->ReadMCParticle(false);
case RELATIONSHIP_COMPONENT:
return this->ReadRelationship(false);
case EVENT_END_COMPONENT:
m_containerId = UNKNOWN_CONTAINER;
return STATUS_CODE_NOT_FOUND;
default:
throw StatusCodeException(STATUS_CODE_FAILURE);
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadSubDetector(bool checkComponentId)
{
if (GEOMETRY_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (SUB_DETECTOR_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::Geometry::SubDetector::Parameters *pParameters = m_pSubDetectorFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pSubDetectorFactory->Read(*pParameters, *this));
std::string subDetectorName;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(subDetectorName));
SubDetectorType subDetectorType(SUB_DETECTOR_OTHER);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(subDetectorType));
float innerRCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(innerRCoordinate));
float innerZCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(innerZCoordinate));
float innerPhiCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(innerPhiCoordinate));
unsigned int innerSymmetryOrder(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(innerSymmetryOrder));
float outerRCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(outerRCoordinate));
float outerZCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(outerZCoordinate));
float outerPhiCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(outerPhiCoordinate));
unsigned int outerSymmetryOrder(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(outerSymmetryOrder));
bool isMirroredInZ(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(isMirroredInZ));
unsigned int nLayers(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(nLayers));
pParameters->m_subDetectorName = subDetectorName;
pParameters->m_subDetectorType = subDetectorType;
pParameters->m_innerRCoordinate = innerRCoordinate;
pParameters->m_innerZCoordinate = innerZCoordinate;
pParameters->m_innerPhiCoordinate = innerPhiCoordinate;
pParameters->m_innerSymmetryOrder = innerSymmetryOrder;
pParameters->m_outerRCoordinate = outerRCoordinate;
pParameters->m_outerZCoordinate = outerZCoordinate;
pParameters->m_outerPhiCoordinate = outerPhiCoordinate;
pParameters->m_outerSymmetryOrder = outerSymmetryOrder;
pParameters->m_isMirroredInZ = isMirroredInZ;
pParameters->m_nLayers = nLayers;
for (unsigned int iLayer = 0; iLayer < nLayers; ++iLayer)
{
float closestDistanceToIp(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(closestDistanceToIp));
float nRadiationLengths(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(nRadiationLengths));
float nInteractionLengths(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(nInteractionLengths));
PandoraApi::Geometry::LayerParameters layerParameters;
layerParameters.m_closestDistanceToIp = closestDistanceToIp;
layerParameters.m_nRadiationLengths = nRadiationLengths;
layerParameters.m_nInteractionLengths = nInteractionLengths;
pParameters->m_layerParametersVector.push_back(layerParameters);
}
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Geometry::SubDetector::Create(*m_pPandora, *pParameters, *m_pSubDetectorFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadLArTPC(bool checkComponentId)
{
if (GEOMETRY_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (LAR_TPC_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::Geometry::LArTPC::Parameters *pParameters = m_pLArTPCFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pLArTPCFactory->Read(*pParameters, *this));
unsigned int larTPCVolumeId;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(larTPCVolumeId));
float centerX(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(centerX));
float centerY(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(centerY));
float centerZ(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(centerZ));
float widthX(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(widthX));
float widthY(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(widthY));
float widthZ(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(widthZ));
float wirePitchU(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(wirePitchU));
float wirePitchV(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(wirePitchV));
float wirePitchW(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(wirePitchW));
float wireAngleU(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(wireAngleU));
float wireAngleV(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(wireAngleV));
float wireAngleW(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(wireAngleW));
float sigmaUVW(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(sigmaUVW));
bool isDriftInPositiveX(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(isDriftInPositiveX));
pParameters->m_larTPCVolumeId = larTPCVolumeId;
pParameters->m_centerX = centerX;
pParameters->m_centerY = centerY;
pParameters->m_centerZ = centerZ;
pParameters->m_widthX = widthX;
pParameters->m_widthY = widthY;
pParameters->m_widthZ = widthZ;
pParameters->m_wirePitchU = wirePitchU;
pParameters->m_wirePitchV = wirePitchV;
pParameters->m_wirePitchW = wirePitchW;
pParameters->m_wireAngleU = wireAngleU;
pParameters->m_wireAngleV = wireAngleV;
pParameters->m_wireAngleW = wireAngleW;
pParameters->m_sigmaUVW = sigmaUVW;
pParameters->m_isDriftInPositiveX = isDriftInPositiveX;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Geometry::LArTPC::Create(*m_pPandora, *pParameters, *m_pLArTPCFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadLineGap(bool checkComponentId)
{
if (GEOMETRY_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (LINE_GAP_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::Geometry::LineGap::Parameters *pParameters = m_pLineGapFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pLineGapFactory->Read(*pParameters, *this));
LineGapType lineGapType(TPC_WIRE_GAP_VIEW_U);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(lineGapType));
float lineStartX(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(lineStartX));
float lineEndX(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(lineEndX));
float lineStartZ(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(lineStartZ));
float lineEndZ(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(lineEndZ));
pParameters->m_lineGapType = lineGapType;
pParameters->m_lineStartX = lineStartX;
pParameters->m_lineEndX = lineEndX;
pParameters->m_lineStartZ = lineStartZ;
pParameters->m_lineEndZ = lineEndZ;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Geometry::LineGap::Create(*m_pPandora, *pParameters, *m_pLineGapFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadBoxGap(bool checkComponentId)
{
if (GEOMETRY_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (BOX_GAP_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::Geometry::BoxGap::Parameters *pParameters = m_pBoxGapFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pBoxGapFactory->Read(*pParameters, *this));
CartesianVector vertex(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(vertex));
CartesianVector side1(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(side1));
CartesianVector side2(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(side2));
CartesianVector side3(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(side3));
pParameters->m_vertex = vertex;
pParameters->m_side1 = side1;
pParameters->m_side2 = side2;
pParameters->m_side3 = side3;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Geometry::BoxGap::Create(*m_pPandora, *pParameters, *m_pBoxGapFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadConcentricGap(bool checkComponentId)
{
if (GEOMETRY_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (CONCENTRIC_GAP_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::Geometry::ConcentricGap::Parameters *pParameters = m_pConcentricGapFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pConcentricGapFactory->Read(*pParameters, *this));
float minZCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(minZCoordinate));
float maxZCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(maxZCoordinate));
float innerRCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(innerRCoordinate));
float innerPhiCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(innerPhiCoordinate));
unsigned int innerSymmetryOrder(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(innerSymmetryOrder));
float outerRCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(outerRCoordinate));
float outerPhiCoordinate(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(outerPhiCoordinate));
unsigned int outerSymmetryOrder(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(outerSymmetryOrder));
pParameters->m_minZCoordinate = minZCoordinate;
pParameters->m_maxZCoordinate = maxZCoordinate;
pParameters->m_innerRCoordinate = innerRCoordinate;
pParameters->m_innerPhiCoordinate = innerPhiCoordinate;
pParameters->m_innerSymmetryOrder = innerSymmetryOrder;
pParameters->m_outerRCoordinate = outerRCoordinate;
pParameters->m_outerPhiCoordinate = outerPhiCoordinate;
pParameters->m_outerSymmetryOrder = outerSymmetryOrder;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Geometry::ConcentricGap::Create(*m_pPandora, *pParameters, *m_pConcentricGapFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadCaloHit(bool checkComponentId)
{
if (EVENT_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (CALO_HIT_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::CaloHit::Parameters *pParameters = m_pCaloHitFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pCaloHitFactory->Read(*pParameters, *this));
CellGeometry cellGeometry(RECTANGULAR);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(cellGeometry));
CartesianVector positionVector(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(positionVector));
CartesianVector expectedDirection(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(expectedDirection));
CartesianVector cellNormalVector(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(cellNormalVector));
float cellThickness(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(cellThickness));
float nCellRadiationLengths(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(nCellRadiationLengths));
float nCellInteractionLengths(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(nCellInteractionLengths));
float time(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(time));
float inputEnergy(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(inputEnergy));
float mipEquivalentEnergy(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(mipEquivalentEnergy));
float electromagneticEnergy(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(electromagneticEnergy));
float hadronicEnergy(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(hadronicEnergy));
bool isDigital(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(isDigital));
HitType hitType(ECAL);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(hitType));
HitRegion hitRegion(BARREL);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(hitRegion));
unsigned int layer(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(layer));
bool isInOuterSamplingLayer(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(isInOuterSamplingLayer));
const void *pParentAddress(nullptr);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(pParentAddress));
float cellSize0(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(cellSize0));
float cellSize1(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(cellSize1));
pParameters->m_positionVector = positionVector;
pParameters->m_expectedDirection = expectedDirection;
pParameters->m_cellNormalVector = cellNormalVector;
pParameters->m_cellGeometry = cellGeometry;
pParameters->m_cellSize0 = cellSize0;
pParameters->m_cellSize1 = cellSize1;
pParameters->m_cellThickness = cellThickness;
pParameters->m_nCellRadiationLengths = nCellRadiationLengths;
pParameters->m_nCellInteractionLengths = nCellInteractionLengths;
pParameters->m_time = time;
pParameters->m_inputEnergy = inputEnergy;
pParameters->m_mipEquivalentEnergy = mipEquivalentEnergy;
pParameters->m_electromagneticEnergy = electromagneticEnergy;
pParameters->m_hadronicEnergy = hadronicEnergy;
pParameters->m_isDigital = isDigital;
pParameters->m_hitType = hitType;
pParameters->m_hitRegion = hitRegion;
pParameters->m_layer = layer;
pParameters->m_isInOuterSamplingLayer = isInOuterSamplingLayer;
pParameters->m_pParentAddress = pParentAddress;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(*m_pPandora, *pParameters, *m_pCaloHitFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadTrack(bool checkComponentId)
{
if (EVENT_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (TRACK_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::Track::Parameters *pParameters = m_pTrackFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pTrackFactory->Read(*pParameters, *this));
float d0(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(d0));
float z0(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(z0));
int particleId(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(particleId));
int charge(0);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(charge));
float mass(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(mass));
CartesianVector momentumAtDca(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(momentumAtDca));
TrackState trackStateAtStart(0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(trackStateAtStart));
TrackState trackStateAtEnd(0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(trackStateAtEnd));
TrackState trackStateAtCalorimeter(0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(trackStateAtCalorimeter));
float timeAtCalorimeter(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(timeAtCalorimeter));
bool reachesCalorimeter(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(reachesCalorimeter));
bool isProjectedToEndCap(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(isProjectedToEndCap));
bool canFormPfo(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(canFormPfo));
bool canFormClusterlessPfo(false);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(canFormClusterlessPfo));
const void *pParentAddress(nullptr);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(pParentAddress));
pParameters->m_d0 = d0;
pParameters->m_z0 = z0;
pParameters->m_particleId = particleId;
pParameters->m_charge = charge;
pParameters->m_mass = mass;
pParameters->m_momentumAtDca = momentumAtDca;
pParameters->m_trackStateAtStart = trackStateAtStart;
pParameters->m_trackStateAtEnd = trackStateAtEnd;
pParameters->m_trackStateAtCalorimeter = trackStateAtCalorimeter;
pParameters->m_timeAtCalorimeter = timeAtCalorimeter;
pParameters->m_reachesCalorimeter = reachesCalorimeter;
pParameters->m_isProjectedToEndCap = isProjectedToEndCap;
pParameters->m_canFormPfo = canFormPfo;
pParameters->m_canFormClusterlessPfo = canFormClusterlessPfo;
pParameters->m_pParentAddress = pParentAddress;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Track::Create(*m_pPandora, *pParameters, *m_pTrackFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadMCParticle(bool checkComponentId)
{
if (EVENT_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (MC_PARTICLE_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
PandoraApi::MCParticle::Parameters *pParameters = m_pMCParticleFactory->NewParameters();
try
{
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pMCParticleFactory->Read(*pParameters, *this));
float energy(0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(energy));
CartesianVector momentum(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(momentum));
CartesianVector vertex(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(vertex));
CartesianVector endpoint(0.f, 0.f, 0.f);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(endpoint));
int particleId(-std::numeric_limits<int>::max());
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(particleId));
MCParticleType mcParticleType(MC_3D);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(mcParticleType));
const void *pParentAddress(nullptr);
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(pParentAddress));
pParameters->m_energy = energy;
pParameters->m_momentum = momentum;
pParameters->m_vertex = vertex;
pParameters->m_endpoint = endpoint;
pParameters->m_particleId = particleId;
pParameters->m_mcParticleType = mcParticleType;
pParameters->m_pParentAddress = pParentAddress;
PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::MCParticle::Create(*m_pPandora, *pParameters, *m_pMCParticleFactory));
delete pParameters;
}
catch (StatusCodeException &statusCodeException)
{
delete pParameters;
return statusCodeException.GetStatusCode();
}
return STATUS_CODE_SUCCESS;
}
//------------------------------------------------------------------------------------------------------------------------------------------
StatusCode BinaryFileReader::ReadRelationship(bool checkComponentId)
{
if (EVENT_CONTAINER != m_containerId)
return STATUS_CODE_FAILURE;
if (checkComponentId)
{
ComponentId componentId(UNKNOWN_COMPONENT);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(componentId));
if (RELATIONSHIP_COMPONENT != componentId)
return STATUS_CODE_FAILURE;
}
RelationshipId relationshipId(UNKNOWN_RELATIONSHIP);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(relationshipId));
const void *address1(nullptr);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(address1));
const void *address2(nullptr);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(address2));
float weight(1.f);
PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(weight));
switch (relationshipId)
{
case CALO_HIT_TO_MC_RELATIONSHIP:
return PandoraApi::SetCaloHitToMCParticleRelationship(*m_pPandora, address1, address2, weight);
case TRACK_TO_MC_RELATIONSHIP:
return PandoraApi::SetTrackToMCParticleRelationship(*m_pPandora, address1, address2, weight);
case MC_PARENT_DAUGHTER_RELATIONSHIP:
return PandoraApi::SetMCParentDaughterRelationship(*m_pPandora, address1, address2);
case TRACK_PARENT_DAUGHTER_RELATIONSHIP:
return PandoraApi::SetTrackParentDaughterRelationship(*m_pPandora, address1, address2);
case TRACK_SIBLING_RELATIONSHIP:
return PandoraApi::SetTrackSiblingRelationship(*m_pPandora, address1, address2);
default:
return STATUS_CODE_FAILURE;
}
return STATUS_CODE_SUCCESS;
}
} // namespace pandora