LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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...
 
bool m_useLArMCParticles
 Whether to read lar mc particles, or standard pandora mc particles. More...
 
pandora::FileReader * m_pEventFileReader
 Address of the event file reader. More...
 

Detailed Description

EventReadingAlgorithm class.

Definition at line 27 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),
29  m_useLArMCParticles(true),
30  m_pEventFileReader(nullptr)
31 {
32 }
bool m_useLArMCParticles
Whether to read lar mc particles, or standard pandora mc particles.
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.
lar_content::EventReadingAlgorithm::~EventReadingAlgorithm ( )

Destructor.

Definition at line 36 of file EventReadingAlgorithm.cc.

References m_pEventFileReader.

37 {
38  delete m_pEventFileReader;
39 }
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 150 of file EventReadingAlgorithm.cc.

Referenced by Initialize(), and ReplaceEventFileReader().

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

Definition at line 43 of file EventReadingAlgorithm.cc.

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

44 {
45  if (!m_geometryFileName.empty())
46  {
47  const FileType geometryFileType(this->GetFileType(m_geometryFileName));
48 
49  if (BINARY == geometryFileType)
50  {
51  BinaryFileReader fileReader(this->GetPandora(), m_geometryFileName);
52  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, fileReader.ReadGeometry());
53  }
54  else if (XML == geometryFileType)
55  {
56  XmlFileReader fileReader(this->GetPandora(), m_geometryFileName);
57  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, fileReader.ReadGeometry());
58  }
59  else
60  {
61  return STATUS_CODE_FAILURE;
62  }
63  }
64 
65  if (!m_eventFileName.empty())
66  {
67  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReplaceEventFileReader(m_eventFileName));
68  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_pEventFileReader->GoToEvent(m_skipToEvent));
69  }
70 
71  return STATUS_CODE_SUCCESS;
72 }
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 97 of file EventReadingAlgorithm.cc.

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

Referenced by Run().

98 {
99  if (m_eventFileNameVector.empty())
100  throw StopProcessingException("All event files processed");
101 
103  m_eventFileNameVector.pop_back();
104  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->ReplaceEventFileReader(m_eventFileName));
105 
106  try
107  {
108  m_pEventFileReader->ReadEvent();
109  }
110  catch (const StatusCodeException &)
111  {
112  this->MoveToNextEventFile();
113  }
114 }
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 172 of file EventReadingAlgorithm.cc.

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

173 {
174  ExternalEventReadingParameters *pExternalParameters(nullptr);
175 
176  if (this->ExternalParametersPresent())
177  {
178  pExternalParameters = dynamic_cast<ExternalEventReadingParameters*>(this->GetExternalParameters());
179 
180  if (!pExternalParameters)
181  return STATUS_CODE_FAILURE;
182  }
183 
184  if (pExternalParameters && !pExternalParameters->m_geometryFileName.empty())
185  {
186  m_geometryFileName = pExternalParameters->m_geometryFileName;
187  }
188  else
189  {
190  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "GeometryFileName", m_geometryFileName));
191  }
192 
193  if (pExternalParameters && !pExternalParameters->m_eventFileNameList.empty())
194  {
195  XmlHelper::TokenizeString(pExternalParameters->m_eventFileNameList, m_eventFileNameVector, ":");
196  }
197  else
198  {
199  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "EventFileNameList", m_eventFileNameVector));
200  }
201 
202  if (!m_eventFileNameVector.empty())
203  {
204  std::reverse(m_eventFileNameVector.begin(), m_eventFileNameVector.end());
206  m_eventFileNameVector.pop_back();
207  }
208 
209  if (pExternalParameters && pExternalParameters->m_skipToEvent.IsInitialized())
210  {
211  m_skipToEvent = pExternalParameters->m_skipToEvent.Get();
212  }
213  else
214  {
215  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SkipToEvent", m_skipToEvent));
216  }
217 
218  if (m_geometryFileName.empty() && m_eventFileName.empty())
219  {
220  std::cout << "EventReadingAlgorithm - nothing to do; neither geometry nor event file specified." << std::endl;
221  return STATUS_CODE_NOT_INITIALIZED;
222  }
223 
224  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
225  "UseLArCaloHits", m_useLArCaloHits));
226 
227  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
228  "UseLArMCParticles", m_useLArMCParticles));
229 
230  return STATUS_CODE_SUCCESS;
231 }
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.
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.
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 118 of file EventReadingAlgorithm.cc.

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

Referenced by Initialize(), and MoveToNextEventFile().

119 {
120  delete m_pEventFileReader;
121  m_pEventFileReader = nullptr;
122 
123  std::cout << "EventReadingAlgorithm: Processing event file: " << fileName << std::endl;
124  const FileType eventFileType(this->GetFileType(fileName));
125 
126  if (BINARY == eventFileType)
127  {
128  m_pEventFileReader = new BinaryFileReader(this->GetPandora(), fileName);
129  }
130  else if (XML == eventFileType)
131  {
132  m_pEventFileReader = new XmlFileReader(this->GetPandora(), fileName);
133  }
134  else
135  {
136  return STATUS_CODE_FAILURE;
137  }
138 
139  if (m_useLArCaloHits)
140  m_pEventFileReader->SetFactory(new LArCaloHitFactory);
141 
143  m_pEventFileReader->SetFactory(new LArMCParticleFactory);
144 
145  return STATUS_CODE_SUCCESS;
146 }
bool m_useLArMCParticles
Whether to read lar mc particles, or standard pandora mc particles.
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.
StatusCode lar_content::EventReadingAlgorithm::Run ( )
private

Definition at line 76 of file EventReadingAlgorithm.cc.

References m_eventFileName, m_pEventFileReader, and MoveToNextEventFile().

77 {
78  if ((nullptr != m_pEventFileReader) && !m_eventFileName.empty())
79  {
80  try
81  {
82  m_pEventFileReader->ReadEvent();
83  }
84  catch (const StatusCodeException &)
85  {
86  this->MoveToNextEventFile();
87  }
88 
89  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RepeatEventPreparation(*this));
90  }
91 
92  return STATUS_CODE_SUCCESS;
93 }
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 79 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 80 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 78 of file EventReadingAlgorithm.h.

Referenced by Initialize(), and ReadSettings().

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

Address of the event file reader.

Definition at line 87 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 82 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 84 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 85 of file EventReadingAlgorithm.h.

Referenced by ReadSettings(), and ReplaceEventFileReader().


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