LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LArCaloHit.h
Go to the documentation of this file.
1 
8 #ifndef LAR_CALO_HIT_H
9 #define LAR_CALO_HIT_H 1
10 
11 #include "Objects/CaloHit.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 LArCaloHitParameters : public object_creation::CaloHit::Parameters
28 {
29 public:
30  pandora::InputUInt m_larTPCVolumeId;
31 };
32 
33 //------------------------------------------------------------------------------------------------------------------------------------------
34 
38 class LArCaloHit : public object_creation::CaloHit::Object
39 {
40 public:
46  LArCaloHit(const LArCaloHitParameters &parameters);
47 
53  unsigned int GetLArTPCVolumeId() const;
54 
55 private:
56  unsigned int m_larTPCVolumeId;
57 };
58 
59 //------------------------------------------------------------------------------------------------------------------------------------------
60 
64 class LArCaloHitFactory : public pandora::ObjectFactory<object_creation::CaloHit::Parameters, object_creation::CaloHit::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 
102 inline LArCaloHit::LArCaloHit(const LArCaloHitParameters &parameters) :
103  object_creation::CaloHit::Object(parameters),
105 {
106 }
107 
108 //------------------------------------------------------------------------------------------------------------------------------------------
109 
110 inline unsigned int LArCaloHit::GetLArTPCVolumeId() const
111 {
112  return m_larTPCVolumeId;
113 }
114 
115 //------------------------------------------------------------------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------------------------------------------------------------------
117 
118 inline LArCaloHitFactory::Parameters *LArCaloHitFactory::NewParameters() const
119 {
120  return (new LArCaloHitParameters);
121 }
122 
123 //------------------------------------------------------------------------------------------------------------------------------------------
124 
125 inline pandora::StatusCode LArCaloHitFactory::Create(const Parameters &parameters, const Object *&pObject) const
126 {
127  const LArCaloHitParameters &larCaloHitParameters(dynamic_cast<const LArCaloHitParameters&>(parameters));
128  pObject = new LArCaloHit(larCaloHitParameters);
129 
130  return pandora::STATUS_CODE_SUCCESS;
131 }
132 
133 //------------------------------------------------------------------------------------------------------------------------------------------
134 
135 inline pandora::StatusCode LArCaloHitFactory::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  unsigned int larTPCVolumeId(std::numeric_limits<unsigned int>::max());
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(larTPCVolumeId));
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("LArTPCVolumeId", larTPCVolumeId));
149  }
150  else
151  {
152  return pandora::STATUS_CODE_INVALID_PARAMETER;
153  }
154 
155  LArCaloHitParameters &larCaloHitParameters(dynamic_cast<LArCaloHitParameters&>(parameters));
156  larCaloHitParameters.m_larTPCVolumeId = larTPCVolumeId;
157 
158  return pandora::STATUS_CODE_SUCCESS;
159 }
160 
161 //------------------------------------------------------------------------------------------------------------------------------------------
162 
163 inline pandora::StatusCode LArCaloHitFactory::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 LArCaloHit *const pLArCaloHit(dynamic_cast<const LArCaloHit*>(pObject));
167 
168  if (!pLArCaloHit)
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(pLArCaloHit->GetLArTPCVolumeId()));
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("LArTPCVolumeId", pLArCaloHit->GetLArTPCVolumeId()));
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_CALO_HIT_H
Parameters * NewParameters() const
Create new parameters instance on the heap (memory-management to be controlled by user) ...
Definition: LArCaloHit.h:118
pandora::StatusCode Read(Parameters &parameters, pandora::FileReader &fileReader) const
Read any additional (derived class only) object parameters from file using the specified file reader...
Definition: LArCaloHit.h:135
pandora::InputUInt m_larTPCVolumeId
The lar tpc volume id.
Definition: LArCaloHit.h:30
unsigned int GetLArTPCVolumeId() const
Get the lar tpc volume id.
Definition: LArCaloHit.h:110
LAr calo hit class.
Definition: LArCaloHit.h:38
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
unsigned int m_larTPCVolumeId
The lar tpc volume id.
Definition: LArCaloHit.h:56
LAr calo hit parameters.
Definition: LArCaloHit.h:27
Int_t max
Definition: plot.C:27
pandora::StatusCode Write(const Object *const pObject, pandora::FileWriter &fileWriter) const
Persist any additional (derived class only) object parameters using the specified file writer...
Definition: LArCaloHit.h:163
pandora::StatusCode Create(const Parameters &parameters, const Object *&pObject) const
Create an object with the given parameters.
Definition: LArCaloHit.h:125
LArCaloHitFactory responsible for object creation.
Definition: LArCaloHit.h:64
LArCaloHit(const LArCaloHitParameters &parameters)
Constructor.
Definition: LArCaloHit.h:102