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

LArMCParticleFactory responsible for object creation. More...

#include "LArMCParticle.h"

Inheritance diagram for lar_content::LArMCParticleFactory:

Public Member Functions

 LArMCParticleFactory (const unsigned int version=2)
 Constructor. More...
 
Parameters * NewParameters () const
 Create new parameters instance on the heap (memory-management to be controlled by user) More...
 
pandora::StatusCode Read (Parameters &parameters, pandora::FileReader &fileReader) const
 Read any additional (derived class only) object parameters from file using the specified file reader. More...
 
pandora::StatusCode Write (const Object *const pObject, pandora::FileWriter &fileWriter) const
 Persist any additional (derived class only) object parameters using the specified file writer. More...
 
pandora::StatusCode Create (const Parameters &parameters, const Object *&pObject) const
 Create an object with the given parameters. More...
 

Private Attributes

unsigned int m_version
 The LArMCParticle version. More...
 

Detailed Description

LArMCParticleFactory responsible for object creation.

Definition at line 135 of file LArMCParticle.h.

Constructor & Destructor Documentation

lar_content::LArMCParticleFactory::LArMCParticleFactory ( const unsigned int  version = 2)
inline

Constructor.

Parameters
versionthe LArMCParticle version

Definition at line 223 of file LArMCParticle.h.

223  :
224  m_version(version)
225 {
226 }
unsigned int m_version
The LArMCParticle version.

Member Function Documentation

pandora::StatusCode lar_content::LArMCParticleFactory::Create ( const Parameters &  parameters,
const Object *&  pObject 
) const
inline

Create an object with the given parameters.

Parameters
parametersthe parameters to pass in constructor
pObjectto receive the address of the object created

Definition at line 237 of file LArMCParticle.h.

238 {
239  const LArMCParticleParameters &larMCParticleParameters(dynamic_cast<const LArMCParticleParameters &>(parameters));
240  pObject = new LArMCParticle(larMCParticleParameters);
241 
242  return pandora::STATUS_CODE_SUCCESS;
243 }
LArMCParticleFactory::Parameters * lar_content::LArMCParticleFactory::NewParameters ( ) const
inline

Create new parameters instance on the heap (memory-management to be controlled by user)

Returns
the address of the new parameters instance

Definition at line 230 of file LArMCParticle.h.

231 {
232  return (new LArMCParticleParameters);
233 }
pandora::StatusCode lar_content::LArMCParticleFactory::Read ( Parameters &  parameters,
pandora::FileReader &  fileReader 
) const
inline

Read any additional (derived class only) object parameters from file using the specified file reader.

Parameters
parametersthe parameters to pass in constructor
fileReaderthe file reader, used to extract any additional parameters from file

Definition at line 247 of file LArMCParticle.h.

References lar_content::LArMCParticleParameters::m_nuanceCode, lar_content::LArMCParticleParameters::m_process, and m_version.

248 {
249  // ATTN: To receive this call-back must have already set file reader mc particle factory to this factory
250  int nuanceCode(0);
251  int process(0);
252 
253  if (pandora::BINARY == fileReader.GetFileType())
254  {
255  pandora::BinaryFileReader &binaryFileReader(dynamic_cast<pandora::BinaryFileReader &>(fileReader));
256  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(nuanceCode));
257 
258  if (m_version > 1)
259  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileReader.ReadVariable(process));
260  }
261  else if (pandora::XML == fileReader.GetFileType())
262  {
263  pandora::XmlFileReader &xmlFileReader(dynamic_cast<pandora::XmlFileReader &>(fileReader));
264  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("NuanceCode", nuanceCode));
265 
266  if (m_version > 1)
267  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("Process", process));
268  }
269  else
270  {
271  return pandora::STATUS_CODE_INVALID_PARAMETER;
272  }
273 
274  LArMCParticleParameters &larMCParticleParameters(dynamic_cast<LArMCParticleParameters &>(parameters));
275  larMCParticleParameters.m_nuanceCode = nuanceCode;
276  larMCParticleParameters.m_process = process;
277 
278  return pandora::STATUS_CODE_SUCCESS;
279 }
unsigned int m_version
The LArMCParticle version.
pandora::StatusCode lar_content::LArMCParticleFactory::Write ( const Object *const  pObject,
pandora::FileWriter &  fileWriter 
) const
inline

Persist any additional (derived class only) object parameters using the specified file writer.

Parameters
pObjectthe address of the object to persist
fileWriterthe file writer

Definition at line 283 of file LArMCParticle.h.

References lar_content::LArMCParticle::GetNuanceCode(), lar_content::LArMCParticle::GetProcess(), and m_version.

284 {
285  // ATTN: To receive this call-back must have already set file writer mc particle factory to this factory
286  const LArMCParticle *const pLArMCParticle(dynamic_cast<const LArMCParticle *>(pObject));
287 
288  if (!pLArMCParticle)
289  return pandora::STATUS_CODE_INVALID_PARAMETER;
290 
291  if (pandora::BINARY == fileWriter.GetFileType())
292  {
293  pandora::BinaryFileWriter &binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter &>(fileWriter));
294  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArMCParticle->GetNuanceCode()));
295 
296  if (m_version > 1)
297  PANDORA_RETURN_RESULT_IF(
298  pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(static_cast<int>(pLArMCParticle->GetProcess())));
299  }
300  else if (pandora::XML == fileWriter.GetFileType())
301  {
302  pandora::XmlFileWriter &xmlFileWriter(dynamic_cast<pandora::XmlFileWriter &>(fileWriter));
303  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("NuanceCode", pLArMCParticle->GetNuanceCode()));
304 
305  if (m_version > 1)
306  PANDORA_RETURN_RESULT_IF(
307  pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("Process", static_cast<int>(pLArMCParticle->GetProcess())));
308  }
309  else
310  {
311  return pandora::STATUS_CODE_INVALID_PARAMETER;
312  }
313 
314  return pandora::STATUS_CODE_SUCCESS;
315 }
unsigned int m_version
The LArMCParticle version.

Member Data Documentation

unsigned int lar_content::LArMCParticleFactory::m_version
private

The LArMCParticle version.

Definition at line 177 of file LArMCParticle.h.

Referenced by Read(), and Write().


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