LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LArMCParticle.h
Go to the documentation of this file.
1 
8 #ifndef LAR_MC_PARTICLE_H
9 #define LAR_MC_PARTICLE_H 1
10 
11 #include "Objects/MCParticle.h"
12 
13 #include "Pandora/ObjectCreation.h"
14 #include "Pandora/PandoraObjectFactories.h"
15 
16 #include "Persistency/BinaryFileReader.h"
17 #include "Persistency/BinaryFileWriter.h"
18 #include "Persistency/XmlFileReader.h"
19 #include "Persistency/XmlFileWriter.h"
20 
21 namespace lar_content
22 {
23 
27 class LArMCParticleParameters : public object_creation::MCParticle::Parameters
28 {
29 public:
30  pandora::InputInt m_nuanceCode;
31 };
32 
33 //------------------------------------------------------------------------------------------------------------------------------------------
34 
38 class LArMCParticle : public object_creation::MCParticle::Object
39 {
40 public:
46  LArMCParticle(const LArMCParticleParameters &parameters);
47 
53  int GetNuanceCode() const;
54 
55 private:
57 };
58 
59 //------------------------------------------------------------------------------------------------------------------------------------------
60 
64 class LArMCParticleFactory : public pandora::ObjectFactory<object_creation::MCParticle::Parameters, object_creation::MCParticle::Object>
65 {
66 public:
72  Parameters *NewParameters() const;
73 
80  pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const;
81 
88  pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const;
89 
96  pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const;
97 };
98 
99 //------------------------------------------------------------------------------------------------------------------------------------------
100 //------------------------------------------------------------------------------------------------------------------------------------------
101 
103  object_creation::MCParticle::Object(parameters),
104  m_nuanceCode(parameters.m_nuanceCode.Get())
105 {
106 }
107 
108 //------------------------------------------------------------------------------------------------------------------------------------------
109 
111 {
112  return m_nuanceCode;
113 }
114 
115 //------------------------------------------------------------------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------------------------------------------------------------------
117 
118 inline LArMCParticleFactory::Parameters *LArMCParticleFactory::NewParameters() const
119 {
120  return (new LArMCParticleParameters);
121 }
122 
123 //------------------------------------------------------------------------------------------------------------------------------------------
124 
125 inline pandora::StatusCode LArMCParticleFactory::Create(const Parameters &parameters, const Object *&pObject) const
126 {
127  const LArMCParticleParameters &larMCParticleParameters(dynamic_cast<const LArMCParticleParameters&>(parameters));
128  pObject = new LArMCParticle(larMCParticleParameters);
129 
130  return pandora::STATUS_CODE_SUCCESS;
131 }
132 
133 //------------------------------------------------------------------------------------------------------------------------------------------
134 
135 inline pandora::StatusCode LArMCParticleFactory::Read(Parameters &parameters, pandora::FileReader &fileReader) const
136 {
137  // ATTN: To receive this call-back must have already set file reader mc particle factory to this factory
138  int nuanceCode(0);
139 
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(nuanceCode));
144  }
145  else if (pandora::XML == fileReader.GetFileType())
146  {
147  pandora::XmlFileReader &xmlFileReader(dynamic_cast<pandora::XmlFileReader&>(fileReader));
148  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileReader.ReadVariable("NuanceCode", nuanceCode));
149  }
150  else
151  {
152  return pandora::STATUS_CODE_INVALID_PARAMETER;
153  }
154 
155  LArMCParticleParameters &larMCParticleParameters(dynamic_cast<LArMCParticleParameters&>(parameters));
156  larMCParticleParameters.m_nuanceCode = nuanceCode;
157 
158  return pandora::STATUS_CODE_SUCCESS;
159 }
160 
161 //------------------------------------------------------------------------------------------------------------------------------------------
162 
163 inline pandora::StatusCode LArMCParticleFactory::Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
164 {
165  // ATTN: To receive this call-back must have already set file writer mc particle factory to this factory
166  const LArMCParticle *const pLArMCParticle(dynamic_cast<const LArMCParticle*>(pObject));
167 
168  if (!pLArMCParticle)
169  return pandora::STATUS_CODE_INVALID_PARAMETER;
170 
171  if (pandora::BINARY == fileWriter.GetFileType())
172  {
173  pandora::BinaryFileWriter &binaryFileWriter(dynamic_cast<pandora::BinaryFileWriter&>(fileWriter));
174  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, binaryFileWriter.WriteVariable(pLArMCParticle->GetNuanceCode()));
175  }
176  else if (pandora::XML == fileWriter.GetFileType())
177  {
178  pandora::XmlFileWriter &xmlFileWriter(dynamic_cast<pandora::XmlFileWriter&>(fileWriter));
179  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, xmlFileWriter.WriteVariable("NuanceCode", pLArMCParticle->GetNuanceCode()));
180  }
181  else
182  {
183  return pandora::STATUS_CODE_INVALID_PARAMETER;
184  }
185 
186  return pandora::STATUS_CODE_SUCCESS;
187 }
188 
189 } // namespace lar_content
190 
191 #endif // #ifndef LAR_MC_PARTICLE_H
int GetNuanceCode() const
Get the nuance code.
int m_nuanceCode
The nuance code.
Definition: LArMCParticle.h:56
pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
Persist any additional (derived class only) object parameters using the specified file writer...
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
LAr mc particle class.
Definition: LArMCParticle.h:38
pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const
Create an object with the given parameters.
pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const
Read any additional (derived class only) object parameters from file using the specified file reader...
LArMCParticleFactory responsible for object creation.
Definition: LArMCParticle.h:64
LAr mc particle parameters.
Definition: LArMCParticle.h:27
pandora::InputInt m_nuanceCode
The nuance code.
Definition: LArMCParticle.h:30
LArMCParticle(const LArMCParticleParameters &parameters)
Constructor.
Parameters * NewParameters() const
Create new parameters instance on the heap (memory-management to be controlled by user) ...