LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::EventReadingAlgorithm Class Reference

EventReadingAlgorithm class. More...

#include "EventReadingAlgorithm.h"

Inheritance diagram for lar_content::EventReadingAlgorithm:

Classes

class  ExternalEventReadingParameters
 External event reading parameters class. More...
 

Public Member Functions

 EventReadingAlgorithm ()
 Default constructor. More...
 
 ~EventReadingAlgorithm ()
 Destructor. More...
 

Private Member Functions

pandora::StatusCode Initialize ()
 
pandora::StatusCode Run ()
 
void MoveToNextEventFile ()
 Proceed to process next event file named in the input list. More...
 
pandora::StatusCode ReplaceEventFileReader (const std::string &fileName)
 Replace the current event file reader with a new reader for the specified file. More...
 
pandora::FileType GetFileType (const std::string &fileName) const
 Analyze a provided file name to extract the file type/extension. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

std::string m_geometryFileName
 Name of the file containing geometry information. More...
 
std::string m_eventFileName
 Name of the current file containing event information. More...
 
pandora::StringVector m_eventFileNameVector
 Vector of file names to be processed. More...
 
unsigned int m_skipToEvent
 Index of first event to consider in first input file. More...
 
bool m_useLArCaloHits
 Whether to read lar calo hits, or standard pandora calo hits. More...
 
unsigned int m_larCaloHitVersion
 LArCaloHit version for LArCaloHitFactory. More...
 
bool m_useLArMCParticles
 Whether to read lar mc particles, or standard pandora mc particles. More...
 
unsigned int m_larMCParticleVersion
 LArMCParticle version for LArMCParticleFactory. More...
 
pandora::FileReader * m_pEventFileReader
 Address of the event file reader. More...
 

Detailed Description

EventReadingAlgorithm class.

Definition at line 30 of file EventReadingAlgorithm.h.

Constructor & Destructor Documentation

lar_content::EventReadingAlgorithm::EventReadingAlgorithm ( )

Default constructor.

Definition at line 26 of file EventReadingAlgorithm.cc.

26  :
27  m_skipToEvent(0),
28  m_useLArCaloHits(true),
30  m_useLArMCParticles(true),
32  m_pEventFileReader(nullptr)
33 {
34 }
bool m_useLArMCParticles
Whether to read lar mc particles, or standard pandora mc particles.
unsigned int m_larCaloHitVersion
LArCaloHit version for LArCaloHitFactory.
unsigned int m_skipToEvent
Index of first event to consider in first input file.
bool m_useLArCaloHits
Whether to read lar calo hits, or standard pandora calo hits.
pandora::FileReader * m_pEventFileReader
Address of the event file reader.
unsigned int m_larMCParticleVersion
LArMCParticle version for LArMCParticleFactory.
lar_content::EventReadingAlgorithm::~EventReadingAlgorithm ( )

Destructor.

Definition at line 38 of file EventReadingAlgorithm.cc.

References m_pEventFileReader.

39 {
40  delete m_pEventFileReader;
41 }
pandora::FileReader * m_pEventFileReader
Address of the event file reader.

Member Function Documentation

FileType lar_content::EventReadingAlgorithm::GetFileType ( const std::string &  fileName) const
private

Analyze a provided file name to extract the file type/extension.

Parameters
fileNamethe file name
Returns
the file type

Definition at line 152 of file EventReadingAlgorithm.cc.

Referenced by Initialize(), and ReplaceEventFileReader().

153 {
154  std::string fileExtension(fileName.substr(fileName.find_last_of(".")));
155  std::transform(fileExtension.begin(), fileExtension.end(), fileExtension.begin(), ::tolower);
156 
157  if (std::string(".xml") == fileExtension)
158  {
159  return XML;
160  }
161  else if (std::string(".pndr") == fileExtension)
162  {
163  return BINARY;
164  }
165  else
166  {
167  std::cout << "EventReadingAlgorithm: Unknown file type specified " << fileName << std::endl;
168  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
169  }
170 }
StatusCode lar_content::EventReadingAlgorithm::Initialize ( )
private

Definition at line 45 of file EventReadingAlgorithm.cc.

References GetFileType(), m_eventFileName, m_geometryFileName, m_pEventFileReader, m_skipToEvent, and ReplaceEventFileReader().

46 {
47  if (!m_geometryFileName.empty())
48  {
49  const FileType geometryFileType(this->GetFileType(m_geometryFileName));
50 
51  if (BINARY == geometryFileType)
52  {
53  BinaryFileReader fileReader(this->GetPandora(), m_geometryFileName);
54  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, fileReader.ReadGeometry());
55  }
56  else if (XML == geometryFileType)
57  {
58  XmlFileReader fileReader(this->GetPandora(), m_geometryFileName);
59  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, fileReader.ReadGeometry());
60  }
61  else
62  {
63  return STATUS_CODE_FAILURE;
64  }
65  }
66 
67  if (!m_eventFileName.empty())
68  {
69  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReplaceEventFileReader(m_eventFileName));
70  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pEventFileReader->GoToEvent(m_skipToEvent));
71  }
72 
73  return STATUS_CODE_SUCCESS;
74 }
std::string m_geometryFileName
Name of the file containing geometry information.
pandora::StatusCode ReplaceEventFileReader(const std::string &fileName)
Replace the current event file reader with a new reader for the specified file.
unsigned int m_skipToEvent
Index of first event to consider in first input file.
pandora::FileType GetFileType(const std::string &fileName) const
Analyze a provided file name to extract the file type/extension.
pandora::FileReader * m_pEventFileReader
Address of the event file reader.
std::string m_eventFileName
Name of the current file containing event information.
void lar_content::EventReadingAlgorithm::MoveToNextEventFile ( )
private

Proceed to process next event file named in the input list.

Definition at line 99 of file EventReadingAlgorithm.cc.

References m_eventFileName, m_eventFileNameVector, m_pEventFileReader, and ReplaceEventFileReader().

Referenced by Run().

100 {
101  if (m_eventFileNameVector.empty())
102  throw StopProcessingException("All event files processed");
103 
105  m_eventFileNameVector.pop_back();
106  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReplaceEventFileReader(m_eventFileName));
107 
108  try
109  {
110  m_pEventFileReader->ReadEvent();
111  }
112  catch (const StatusCodeException &)
113  {
114  this->MoveToNextEventFile();
115  }
116 }
pandora::StatusCode ReplaceEventFileReader(const std::string &fileName)
Replace the current event file reader with a new reader for the specified file.
pandora::StringVector m_eventFileNameVector
Vector of file names to be processed.
pandora::FileReader * m_pEventFileReader
Address of the event file reader.
std::string m_eventFileName
Name of the current file containing event information.
void MoveToNextEventFile()
Proceed to process next event file named in the input list.
StatusCode lar_content::EventReadingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 174 of file EventReadingAlgorithm.cc.

References m_eventFileName, lar_content::EventReadingAlgorithm::ExternalEventReadingParameters::m_eventFileNameList, m_eventFileNameVector, lar_content::EventReadingAlgorithm::ExternalEventReadingParameters::m_geometryFileName, m_geometryFileName, m_larCaloHitVersion, m_larMCParticleVersion, lar_content::EventReadingAlgorithm::ExternalEventReadingParameters::m_skipToEvent, m_skipToEvent, m_useLArCaloHits, and m_useLArMCParticles.

175 {
176  ExternalEventReadingParameters *pExternalParameters(nullptr);
177 
178  if (this->ExternalParametersPresent())
179  {
180  pExternalParameters = dynamic_cast<ExternalEventReadingParameters *>(this->GetExternalParameters());
181 
182  if (!pExternalParameters)
183  return STATUS_CODE_FAILURE;
184  }
185 
186  if (pExternalParameters && !pExternalParameters->m_geometryFileName.empty())
187  {
188  m_geometryFileName = pExternalParameters->m_geometryFileName;
189  }
190  else
191  {
192  PANDORA_RETURN_RESULT_IF_AND_IF(
193  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "GeometryFileName", m_geometryFileName));
194  }
195 
196  if (pExternalParameters && !pExternalParameters->m_eventFileNameList.empty())
197  {
198  XmlHelper::TokenizeString(pExternalParameters->m_eventFileNameList, m_eventFileNameVector, ":");
199  }
200  else
201  {
202  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
203  XmlHelper::ReadVectorOfValues(xmlHandle, "EventFileNameList", m_eventFileNameVector));
204  }
205 
206  if (!m_eventFileNameVector.empty())
207  {
208  std::reverse(m_eventFileNameVector.begin(), m_eventFileNameVector.end());
210  m_eventFileNameVector.pop_back();
211  }
212 
213  if (pExternalParameters && pExternalParameters->m_skipToEvent.IsInitialized())
214  {
215  m_skipToEvent = pExternalParameters->m_skipToEvent.Get();
216  }
217  else
218  {
219  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SkipToEvent", m_skipToEvent));
220  }
221 
222  if (m_geometryFileName.empty() && m_eventFileName.empty())
223  {
224  std::cout << "EventReadingAlgorithm - nothing to do; neither geometry nor event file specified." << std::endl;
225  return STATUS_CODE_NOT_INITIALIZED;
226  }
227 
228  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseLArCaloHits", m_useLArCaloHits));
229 
230  PANDORA_RETURN_RESULT_IF_AND_IF(
231  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "LArCaloHitVersion", m_larCaloHitVersion));
232 
233  PANDORA_RETURN_RESULT_IF_AND_IF(
234  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "LArMCParticleVersion", m_larMCParticleVersion));
235 
236  PANDORA_RETURN_RESULT_IF_AND_IF(
237  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "UseLArMCParticles", m_useLArMCParticles));
238 
239  return STATUS_CODE_SUCCESS;
240 }
std::string m_geometryFileName
Name of the file containing geometry information.
bool m_useLArMCParticles
Whether to read lar mc particles, or standard pandora mc particles.
unsigned int m_larCaloHitVersion
LArCaloHit version for LArCaloHitFactory.
pandora::StringVector m_eventFileNameVector
Vector of file names to be processed.
unsigned int m_skipToEvent
Index of first event to consider in first input file.
bool m_useLArCaloHits
Whether to read lar calo hits, or standard pandora calo hits.
unsigned int m_larMCParticleVersion
LArMCParticle version for LArMCParticleFactory.
std::string m_eventFileName
Name of the current file containing event information.
StatusCode lar_content::EventReadingAlgorithm::ReplaceEventFileReader ( const std::string &  fileName)
private

Replace the current event file reader with a new reader for the specified file.

Parameters
fileNamethe file name

Definition at line 120 of file EventReadingAlgorithm.cc.

References GetFileType(), m_larCaloHitVersion, m_larMCParticleVersion, m_pEventFileReader, m_useLArCaloHits, and m_useLArMCParticles.

Referenced by Initialize(), and MoveToNextEventFile().

121 {
122  delete m_pEventFileReader;
123  m_pEventFileReader = nullptr;
124 
125  std::cout << "EventReadingAlgorithm: Processing event file: " << fileName << std::endl;
126  const FileType eventFileType(this->GetFileType(fileName));
127 
128  if (BINARY == eventFileType)
129  {
130  m_pEventFileReader = new BinaryFileReader(this->GetPandora(), fileName);
131  }
132  else if (XML == eventFileType)
133  {
134  m_pEventFileReader = new XmlFileReader(this->GetPandora(), fileName);
135  }
136  else
137  {
138  return STATUS_CODE_FAILURE;
139  }
140 
141  if (m_useLArCaloHits)
142  m_pEventFileReader->SetFactory(new LArCaloHitFactory(m_larCaloHitVersion));
143 
145  m_pEventFileReader->SetFactory(new LArMCParticleFactory(m_larMCParticleVersion));
146 
147  return STATUS_CODE_SUCCESS;
148 }
bool m_useLArMCParticles
Whether to read lar mc particles, or standard pandora mc particles.
unsigned int m_larCaloHitVersion
LArCaloHit version for LArCaloHitFactory.
bool m_useLArCaloHits
Whether to read lar calo hits, or standard pandora calo hits.
pandora::FileType GetFileType(const std::string &fileName) const
Analyze a provided file name to extract the file type/extension.
pandora::FileReader * m_pEventFileReader
Address of the event file reader.
unsigned int m_larMCParticleVersion
LArMCParticle version for LArMCParticleFactory.
StatusCode lar_content::EventReadingAlgorithm::Run ( )
private

Definition at line 78 of file EventReadingAlgorithm.cc.

References m_eventFileName, m_pEventFileReader, and MoveToNextEventFile().

79 {
80  if ((nullptr != m_pEventFileReader) && !m_eventFileName.empty())
81  {
82  try
83  {
84  m_pEventFileReader->ReadEvent();
85  }
86  catch (const StatusCodeException &)
87  {
88  this->MoveToNextEventFile();
89  }
90 
91  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RepeatEventPreparation(*this));
92  }
93 
94  return STATUS_CODE_SUCCESS;
95 }
pandora::FileReader * m_pEventFileReader
Address of the event file reader.
std::string m_eventFileName
Name of the current file containing event information.
void MoveToNextEventFile()
Proceed to process next event file named in the input list.

Member Data Documentation

std::string lar_content::EventReadingAlgorithm::m_eventFileName
private

Name of the current file containing event information.

Definition at line 82 of file EventReadingAlgorithm.h.

Referenced by Initialize(), MoveToNextEventFile(), ReadSettings(), and Run().

pandora::StringVector lar_content::EventReadingAlgorithm::m_eventFileNameVector
private

Vector of file names to be processed.

Definition at line 83 of file EventReadingAlgorithm.h.

Referenced by MoveToNextEventFile(), and ReadSettings().

std::string lar_content::EventReadingAlgorithm::m_geometryFileName
private

Name of the file containing geometry information.

Definition at line 81 of file EventReadingAlgorithm.h.

Referenced by Initialize(), and ReadSettings().

unsigned int lar_content::EventReadingAlgorithm::m_larCaloHitVersion
private

LArCaloHit version for LArCaloHitFactory.

Definition at line 87 of file EventReadingAlgorithm.h.

Referenced by ReadSettings(), and ReplaceEventFileReader().

unsigned int lar_content::EventReadingAlgorithm::m_larMCParticleVersion
private

LArMCParticle version for LArMCParticleFactory.

Definition at line 89 of file EventReadingAlgorithm.h.

Referenced by ReadSettings(), and ReplaceEventFileReader().

pandora::FileReader* lar_content::EventReadingAlgorithm::m_pEventFileReader
private

Address of the event file reader.

Definition at line 91 of file EventReadingAlgorithm.h.

Referenced by Initialize(), MoveToNextEventFile(), ReplaceEventFileReader(), Run(), and ~EventReadingAlgorithm().

unsigned int lar_content::EventReadingAlgorithm::m_skipToEvent
private

Index of first event to consider in first input file.

Definition at line 85 of file EventReadingAlgorithm.h.

Referenced by Initialize(), and ReadSettings().

bool lar_content::EventReadingAlgorithm::m_useLArCaloHits
private

Whether to read lar calo hits, or standard pandora calo hits.

Definition at line 86 of file EventReadingAlgorithm.h.

Referenced by ReadSettings(), and ReplaceEventFileReader().

bool lar_content::EventReadingAlgorithm::m_useLArMCParticles
private

Whether to read lar mc particles, or standard pandora mc particles.

Definition at line 88 of file EventReadingAlgorithm.h.

Referenced by ReadSettings(), and ReplaceEventFileReader().


The documentation for this class was generated from the following files: