Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
BinaryFileReader.h
Go to the documentation of this file.
1
8#ifndef PANDORA_BINARY_FILE_READER_H
9#define PANDORA_BINARY_FILE_READER_H 1
10
11#include "Pandora/Pandora.h"
12
14#include "Objects/TrackState.h"
15
17
18#include <fstream>
19
20namespace pandora
21{
22
27{
28public:
35 BinaryFileReader(const pandora::Pandora &pandora, const std::string &fileName);
36
41
45 template<typename T>
47
48private:
52 StatusCode GoToGeometry(const unsigned int geometryNumber);
53 StatusCode GoToEvent(const unsigned int eventNumber);
56
62 StatusCode ReadSubDetector(bool checkComponentId = true);
63
69 StatusCode ReadLArTPC(bool checkComponentId = true);
70
76 StatusCode ReadLineGap(bool checkComponentId = true);
77
83 StatusCode ReadBoxGap(bool checkComponentId = true);
84
90 StatusCode ReadConcentricGap(bool checkComponentId = true);
91
97 StatusCode ReadCaloHit(bool checkComponentId = true);
98
104 StatusCode ReadTrack(bool checkComponentId = true);
105
111 StatusCode ReadMCParticle(bool checkComponentId = true);
112
118 StatusCode ReadRelationship(bool checkComponentId = true);
119
120 std::ifstream::pos_type m_containerPosition;
121 std::ifstream::pos_type m_containerSize;
122 std::ifstream m_fileStream;
123};
124
125//------------------------------------------------------------------------------------------------------------------------------------------
126
127template<typename T>
129{
130 char *const pMemBlock = new char[sizeof(T)];
131 m_fileStream.read(pMemBlock, sizeof(T));
132
133 t = *(reinterpret_cast<T*>(pMemBlock));
134 delete[] pMemBlock;
135
136 if (!m_fileStream.good())
137 return STATUS_CODE_FAILURE;
138
139 return STATUS_CODE_SUCCESS;
140}
141
142template<>
144{
145 unsigned int stringSize;
146 const StatusCode statusCode(this->ReadVariable(stringSize));
147
148 if (STATUS_CODE_SUCCESS != statusCode)
149 return statusCode;
150
151 char *const pMemBlock = new char[stringSize];
152 m_fileStream.read(pMemBlock, stringSize);
153
154 t = std::string(pMemBlock, stringSize);
155 delete[] pMemBlock;
156
157 if (!m_fileStream.good())
158 return STATUS_CODE_FAILURE;
159
160 return STATUS_CODE_SUCCESS;
161}
162
163template<>
165{
166 float x, y, z;
167 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(x));
168 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(y));
169 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(z));
170 t = CartesianVector(x, y, z);
171
172 return STATUS_CODE_SUCCESS;
173}
174
175template<>
177{
178 CartesianVector position(0.f, 0.f, 0.f), momentum(0.f, 0.f, 0.f);
179 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(position));
180 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReadVariable(momentum));
181 t = TrackState(position, momentum);
182
183 return STATUS_CODE_SUCCESS;
184}
185
186} // namespace pandora
187
188#endif // #ifndef PANDORA_BINARY_FILE_READER_H
Header file for the cartesian vector class.
Header file for the file reader class.
Header file for the pandora class.
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the track state class.
BinaryFileReader class.
StatusCode ReadTrack(bool checkComponentId=true)
Read a track from the current position in the file, recreating the stored object.
StatusCode ReadCaloHit(bool checkComponentId=true)
Read a calo hit from the current position in the file, recreating the stored object.
std::ifstream::pos_type m_containerSize
Size of the current event/geometry container object in the file.
StatusCode ReadHeader()
Read the container header from the current position in the file, checking for properly written contai...
StatusCode ReadSubDetector(bool checkComponentId=true)
Read a sub detector from the current position in the file.
StatusCode GoToNextContainer()
Skip to next container in the file.
StatusCode ReadLineGap(bool checkComponentId=true)
Read a line gap from the current position in the file.
StatusCode ReadConcentricGap(bool checkComponentId=true)
Read a concentric gap from the current position in the file.
StatusCode ReadVariable(T &t)
Read a variable from the file.
StatusCode GoToGeometry(const unsigned int geometryNumber)
Skip to a specified geometry number in the file.
StatusCode ReadRelationship(bool checkComponentId=true)
Read a relationship from the current position in the file, recreating the stored relationship.
StatusCode ReadLArTPC(bool checkComponentId=true)
Read a lar tpc from the current position in the file.
ContainerId GetNextContainerId()
Get the id of the next container in the file without changing the current position in the file.
StatusCode ReadNextEventComponent()
Read the next pandora event component from the current position in the file, recreating the stored co...
StatusCode ReadNextGeometryComponent()
Read the next pandora geometry component from the current position in the file, recreating the stored...
StatusCode ReadBoxGap(bool checkComponentId=true)
Read a box gap from the current position in the file.
std::ifstream m_fileStream
The stream class to read from the file.
std::ifstream::pos_type m_containerPosition
Position of start of the current event/geometry container object in file.
StatusCode ReadMCParticle(bool checkComponentId=true)
Read a mc particle from the current position in the file, recreating the stored object.
StatusCode GoToEvent(const unsigned int eventNumber)
Skip to a specified event number in the file.
CartesianVector class.
FileReader class.
Definition FileReader.h:29
Pandora class.
Definition Pandora.h:40
TrackState class.
Definition TrackState.h:22
ContainerId
The container identification enum.
Definition PandoraIO.h:24
StatusCode
The StatusCode enum.