File indexing completed on 2026-09-27 09:20:25
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef PANDORA_BINARY_FILE_READER_H
0009 #define PANDORA_BINARY_FILE_READER_H 1
0010
0011 #include "Pandora/Pandora.h"
0012
0013 #include "Objects/CartesianVector.h"
0014 #include "Objects/TrackState.h"
0015
0016 #include "Persistency/FileReader.h"
0017
0018 #include <fstream>
0019
0020 namespace pandora
0021 {
0022
0023
0024
0025
0026 class BinaryFileReader : public FileReader
0027 {
0028 public:
0029
0030
0031
0032
0033
0034
0035 BinaryFileReader(const pandora::Pandora &pandora, const std::string &fileName);
0036
0037
0038
0039
0040 ~BinaryFileReader();
0041
0042
0043
0044
0045 template <typename T>
0046 StatusCode ReadVariable(T &t);
0047
0048 private:
0049 StatusCode ReadHeader();
0050 StatusCode GoToNextContainer();
0051 ContainerId GetNextContainerId();
0052 StatusCode GoToGeometry(const unsigned int geometryNumber);
0053 StatusCode GoToEvent(const unsigned int eventNumber);
0054 StatusCode ReadNextGlobalHeaderComponent();
0055 StatusCode ReadNextGeometryComponent();
0056 StatusCode ReadNextEventComponent();
0057
0058
0059
0060
0061
0062
0063 StatusCode ReadVersion(bool checkComponentId = true);
0064
0065
0066
0067
0068
0069
0070 StatusCode ReadSubDetector(bool checkComponentId = true);
0071
0072
0073
0074
0075
0076
0077 StatusCode ReadLArTPC(bool checkComponentId = true);
0078
0079
0080
0081
0082
0083
0084 StatusCode ReadLineGap(bool checkComponentId = true);
0085
0086
0087
0088
0089
0090
0091 StatusCode ReadBoxGap(bool checkComponentId = true);
0092
0093
0094
0095
0096
0097
0098 StatusCode ReadConcentricGap(bool checkComponentId = true);
0099
0100
0101
0102
0103
0104
0105 StatusCode ReadCaloHit(bool checkComponentId = true);
0106
0107
0108
0109
0110
0111
0112 StatusCode ReadTrack(bool checkComponentId = true);
0113
0114
0115
0116
0117
0118
0119 StatusCode ReadMCParticle(bool checkComponentId = true);
0120
0121
0122
0123
0124
0125
0126 StatusCode ReadRelationship(bool checkComponentId = true);
0127
0128
0129
0130
0131
0132
0133 StatusCode ReadEventInformation(bool checkComponentId = true);
0134
0135 std::ifstream::pos_type m_containerPosition;
0136 std::ifstream::pos_type m_containerSize;
0137 std::ifstream m_fileStream;
0138 };
0139
0140
0141
0142 template <typename T>
0143 inline StatusCode BinaryFileReader::ReadVariable(T &t)
0144 {
0145 char *const pMemBlock = new char[sizeof(T)];
0146 m_fileStream.read(pMemBlock, sizeof(T));
0147
0148 t = *(reinterpret_cast<T *>(pMemBlock));
0149 delete[] pMemBlock;
0150
0151 if (!m_fileStream.good())
0152 return STATUS_CODE_FAILURE;
0153
0154 return STATUS_CODE_SUCCESS;
0155 }
0156
0157 template <>
0158 inline StatusCode BinaryFileReader::ReadVariable(std::string &t)
0159 {
0160 unsigned int stringSize;
0161 const StatusCode statusCode(this->ReadVariable(stringSize));
0162
0163 if (STATUS_CODE_SUCCESS != statusCode)
0164 return statusCode;
0165
0166 char *const pMemBlock = new char[stringSize];
0167 m_fileStream.read(pMemBlock, stringSize);
0168
0169 t = std::string(pMemBlock, stringSize);
0170 delete[] pMemBlock;
0171
0172 if (!m_fileStream.good())
0173 return STATUS_CODE_FAILURE;
0174
0175 return STATUS_CODE_SUCCESS;
0176 }
0177
0178 template <>
0179 inline StatusCode BinaryFileReader::ReadVariable(CartesianVector &t)
0180 {
0181 float x, y, z;
0182 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(x));
0183 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(y));
0184 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(z));
0185 t = CartesianVector(x, y, z);
0186
0187 return STATUS_CODE_SUCCESS;
0188 }
0189
0190 template <>
0191 inline StatusCode BinaryFileReader::ReadVariable(TrackState &t)
0192 {
0193 CartesianVector position(0.f, 0.f, 0.f), momentum(0.f, 0.f, 0.f);
0194 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(position));
0195 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(momentum));
0196 t = TrackState(position, momentum);
0197
0198 return STATUS_CODE_SUCCESS;
0199 }
0200
0201 }
0202
0203 #endif