APRILContent
Algorithm of Particle Reconstruction for ILC - implementation with PandoraSDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations
APRILTrack.h
Go to the documentation of this file.
1 
8 #ifndef APRIL_TRACK_H
9 #define APRIL_TRACK_H 1
10 
11 #include "Objects/Track.h"
12 #include "Api/PandoraApi.h"
13 
14 #include "Pandora/ObjectCreation.h"
15 #include "Pandora/PandoraObjectFactories.h"
16 
17 #include "Persistency/BinaryFileReader.h"
18 #include "Persistency/BinaryFileWriter.h"
19 #include "Persistency/XmlFileReader.h"
20 #include "Persistency/XmlFileWriter.h"
21 
22 
23 namespace april_content
24 {
25 
26 typedef std::vector<pandora::InputTrackState> LCInputTrackStates;
27 typedef std::vector<pandora::TrackState> APRILTrackStates;
28 
29 
33 class APRILTrackParameters : public object_creation::Track::Parameters
34 {
35 public:
36  LCInputTrackStates m_trackStates;
37 };
38 
42 class APRILTrack: public object_creation::Track::Object
43 {
44 
45 public:
46  APRILTrack(const APRILTrackParameters &parameters);
47  virtual ~APRILTrack() {};
48 
49  const APRILTrackStates &GetTrackStates() const;
50 
51 protected:
52 
53  APRILTrackStates m_trackStates;
54 
55 };
56 
60 class APRILTrackFactory : public pandora::ObjectFactory<object_creation::Track::Parameters, object_creation::Track::Object>
61 {
62 public:
68  Parameters *NewParameters() const;
69 
76  pandora::StatusCode Read(Parameters &, pandora::FileReader &) const;
77 
84  pandora::StatusCode Write(const Object *const , pandora::FileWriter &) const;
85 
92  pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const;
93 };
94 
95 //------------------------------------------------------------------------------------------------------------------------------------------
96 //------------------------------------------------------------------------------------------------------------------------------------------
97 
98 inline APRILTrack::APRILTrack(const APRILTrackParameters &parameters) :
99  object_creation::Track::Object(parameters),
100  m_trackStates()
101 {
102  for (auto const& inputTrackState: parameters.m_trackStates ) {
103  m_trackStates.push_back( inputTrackState.Get() );
104  }
105 
106 }
107 
108 //------------------------------------------------------------------------------------------------------------------------------------------
109 
110 inline const APRILTrackStates &APRILTrack::GetTrackStates() const
111 {
112  return m_trackStates;
113 }
114 
115 //------------------------------------------------------------------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------------------------------------------------------------------
117 
118 inline APRILTrackFactory::Parameters *APRILTrackFactory::NewParameters() const
119 {
120  return (new APRILTrackParameters);
121 }
122 
123 //------------------------------------------------------------------------------------------------------------------------------------------
124 
125 inline pandora::StatusCode APRILTrackFactory::Create(const Parameters &parameters, const Object *&pObject) const
126 {
127  const APRILTrackParameters &lcTrackParameters(dynamic_cast<const APRILTrackParameters&>(parameters));
128  pObject = new APRILTrack(lcTrackParameters);
129 
130  return pandora::STATUS_CODE_SUCCESS;
131 }
132 
133 //------------------------------------------------------------------------------------------------------------------------------------------
134 
135 inline pandora::StatusCode APRILTrackFactory::Read(Parameters &parameters, pandora::FileReader &fileReader) const
136 {
137  // ATTN: To receive this call-back must have already set file reader track factory to this factory
138  LCInputTrackStates trackStates;
139  int nTrackStates;
140  if (pandora::BINARY == fileReader.GetFileType())
141  {
142  pandora::BinaryFileReader &binaryFileReader(dynamic_cast<pandora::BinaryFileReader&>(fileReader));
143  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(nTrackStates));
144  for (int i = 0; i < nTrackStates; ++i)
145  {
146  pandora::TrackState trackState(0.0,0.0,0.0,0.0,0.0,0.0);
147  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(trackState));
148  trackStates.push_back( pandora::InputTrackState(trackState) );
149  }
150  }
151  else if (pandora::XML == fileReader.GetFileType())
152  {
153  pandora::XmlFileReader &xmlFileReader(dynamic_cast<pandora::XmlFileReader&>(fileReader));
154  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("NumberOfTrackStates", nTrackStates));
155  for (int i = 0; i < nTrackStates; ++i)
156  {
157  pandora::TrackState trackState(0.0,0.0,0.0,0.0,0.0,0.0);
158  std::stringstream trackStateName;
159  trackStateName << "TrackState" << i;
160  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable(trackStateName.str(), trackState));
161  trackStates.push_back( pandora::InputTrackState(trackState) );
162  }
163  }
164  else
165  {
166  return pandora::STATUS_CODE_INVALID_PARAMETER;
167  }
168 
169  APRILTrackParameters &lcTrackParameters(dynamic_cast<APRILTrackParameters&>(parameters));
170  lcTrackParameters.m_trackStates = trackStates;
171 
172  return pandora::STATUS_CODE_SUCCESS;
173 }
174 
175 //------------------------------------------------------------------------------------------------------------------------------------------
176 
177 inline pandora::StatusCode APRILTrackFactory::Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
178 {
179  // ATTN: To receive this call-back must have already set file writer track factory to this factory
180  const APRILTrack *const pAPRILTrack(dynamic_cast<const APRILTrack*>(pObject));
181 
182  if (!pAPRILTrack)
183  return pandora::STATUS_CODE_INVALID_PARAMETER;
184 
185  const APRILTrackStates& trackStates = pAPRILTrack->GetTrackStates();
186  int nTrackStates = trackStates.size();
187 
188  if (pandora::BINARY == fileWriter.GetFileType())
189  {
190  pandora::BinaryFileWriter &binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter&>(fileWriter));
191  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(nTrackStates));
192  for (auto const& trackState : trackStates)
193  {
194  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(trackState));
195  }
196  }
197  else if (pandora::XML == fileWriter.GetFileType())
198  {
199  pandora::XmlFileWriter &xmlFileWriter(dynamic_cast<pandora::XmlFileWriter&>(fileWriter));
200  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("NumberOfTrackStates", nTrackStates));
201  int trackStateCounter=0;
202  for (auto const& trackState : trackStates)
203  {
204  std::stringstream trackStateName;
205  trackStateName << "TrackState" << trackStateCounter;
206  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable(trackStateName.str(), trackState));
207  ++trackStateCounter;
208  }
209  }
210  else
211  {
212  return pandora::STATUS_CODE_INVALID_PARAMETER;
213  }
214 
215  return pandora::STATUS_CODE_SUCCESS;
216 }
217 
218 }//namespace
219 
220 
221 
222 #endif
pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const
Create an object with the given parameters.
Definition: APRILTrack.h:125
pandora::StatusCode Read(Parameters &, pandora::FileReader &) const
Read any additional (derived class only) object parameters from file using the specified file reader...
Definition: APRILTrack.h:135
APRILTrack extension of the Track class for LC-content.
Definition: APRILTrack.h:42
LCInputTrackStates m_trackStates
Vector of TrackStates.
Definition: APRILTrack.h:36
Parameters * NewParameters() const
Create new parameters instance on the heap (memory-management to be controlled by user) ...
Definition: APRILTrack.h:118
Track class.
Definition: Track.h:48
APRILTrack Parameters, allow multiple track states at the calorimeter.
Definition: APRILTrack.h:33
APRILTrackFactory responsible for APRILTrack creation.
Definition: APRILTrack.h:60
pandora::StatusCode Write(const Object *const , pandora::FileWriter &) const
Persist any additional (derived class only) object parameters using the specified file writer...
Definition: APRILTrack.h:177