ArtificialShowerFile.cc
Go to the documentation of this file.
1 
9 #include "ArtificialShowerFile.h"
10 
11 #include <evt/Event.h>
12 #include <evt/ShowerSimData.h>
13 #include <evt/GaisserHillas4Parameter.h>
14 #include <evt/DefaultShowerGeometryProducer.h>
15 
16 #include <utl/AugerException.h>
17 #include <utl/ErrorLogger.h>
18 
19 #include <io/IoCodes.h>
20 
21 #include <fwk/CentralConfig.h>
22 #include <utl/config.h>
23 
24 #include <utl/Reader.h>
25 
26 #include <string>
27 #include <fstream>
28 #include <iostream>
29 
30 using namespace evt;
31 using namespace io;
32 using namespace utl;
33 using namespace fwk;
34 
35 using namespace std;
36 
37 
38 namespace io {
39 
40  ArtificialShowerFile::ArtificialShowerFile(const std::string& fileName, const Mode mode, utl::Branch* const b)
41  {
42  Open(fileName, mode, b);
43  }
44 
45 
46  void
47  ArtificialShowerFile::Open(const std::string& /*fileName*/, const Mode mode, utl::Branch* const /*b*/)
48  {
49  if (fIsOpen) {
50  const string msg = "Artificial IO Exception: ArtificiaFileShower has already been opened.\n";
51  throw utl::IOFailureException(msg);
52  }
53  if (mode == eWrite) {
54  const string msg = "Artificial IO Exception: Cannot write to Artificial files.\n";
55  throw utl::IOFailureException(msg);
56  }
57 
58  fIsOpen = true;
59  }
60 
61 
62  void
63  ArtificialShowerFile::ReadXMLParameters()
64  {
65  Branch topB = CentralConfig::GetInstance()->GetTopBranch("ArtificialShowerFile");
66  if (topB) {
67  Branch primaryEnergyB = topB.GetChild("PrimaryEnergy");
68  if (primaryEnergyB)
69  primaryEnergyB.GetData(fPrimaryEnergy);
70  Branch zenithB = topB.GetChild("PrimaryZenith");
71  if (zenithB)
72  zenithB.GetData(fZenith);
73  Branch azimuthB = topB.GetChild("PrimaryAzimuth");
74  if (azimuthB)
75  azimuthB.GetData(fAzimuth);
76  }
77  }
78 
79 
80  Status
81  ArtificialShowerFile::Read(evt::Event& event)
82  {
83  if (fReadEvents > 0)
84  return io::eEOF;
85 
86  ReadXMLParameters();
87 
88  if (event.HasSimShower()) {
89  ERROR("Event not cleared - has SimShower. Cannot read ArtificialShowerFile.");
90  return eFail;
91  }
92  event.MakeSimShower(DefaultShowerGeometryProducer());
93  evt::ShowerSimData& shower = event.GetSimShower();
94 
96  shower.SetEnergy(fPrimaryEnergy);
99  shower.SetShowerNumber(1);
100  shower.SetShowerRunId("1");
101 
102  if (!shower.HasGroundParticles())
103  shower.MakeGroundParticles();
104 
105  if (CreateArtificialShowerFileParticleIterator() != eSuccess)
106  return eFail;
107 
108  shower.GetGroundParticles().SetFileInterface(&fArtificialShowerFileParticleIterator);
109 
110  ++fReadEvents;
111 
112  return eSuccess;
113  }
114 
115 
116  void
117  ArtificialShowerFile::Write(const evt::Event& /*event*/)
118  {
119  const string msg = "Artificial IO Exception: Cannot write to Artificial files.";
120  throw utl::IOFailureException(msg);
121  }
122 
123 
124  Status
125  ArtificialShowerFile::FindEvent(const unsigned int eventId)
126  {
127  return eventId == 1 ? eSuccess : eFail;
128  }
129 
130 
131  Status
132  ArtificialShowerFile::GotoPosition(const unsigned int /*position*/) // unused
133  {
134  return eSuccess;
135  }
136 
137 
138  int
139  ArtificialShowerFile::GetNEvents()
140  {
141  if (fIsOpen)
142  return 1;
143  else {
144  const string msg = "Artificial IO Exception: ArtificiaFileShower is already closed.";
145  throw utl::IOFailureException(msg);
146  }
147  }
148 
149 
150  Status
151  ArtificialShowerFile::CreateArtificialShowerFileParticleIterator()
152  {
153  fArtificialShowerFileParticleIterator = ArtificialShowerFileParticleIterator();
154  fArtificialShowerFileParticleIterator.SetShowerZenith(fZenith);
155  fArtificialShowerFileParticleIterator.SetShowerAzimuth(fAzimuth);
156  return eSuccess;
157  }
158 
159 }
Branch GetTopBranch() const
Definition: Branch.cc:63
bool HasGroundParticles() const
bool HasSimShower() const
Mode
Available open modes.
Definition: IoCodes.h:16
void SetGroundParticleCoordinateSystemAzimuth(const double azimuth)
Set the azimuth angle of the shower. Angle in x-y plane wrt. to the x axis (0 is from east)...
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
Read Only access.
Definition: IoCodes.h:18
Base class to report exceptions in IO.
void SetFileInterface(VShowerFileParticleIterator *const interface)
Interface class to access Shower Simulated parameters.
Definition: ShowerSimData.h:49
Class representing a document branch.
Definition: Branch.h:107
Status
Return code for seek operation.
Definition: IoCodes.h:24
void SetEnergy(const double theEnergy)
Set the energy of the shower primary particle.
Definition: ShowerSimData.h:91
utl::ShowerParticleList & GetGroundParticles()
Get particle list Proxy.
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
void SetPrimaryParticle(const int type)
Set the type of the shower primary particle.
void SetGroundParticleCoordinateSystemZenith(const double zenith)
Set the zenith angle of the shower. Room angle between z-axis and direction from where the shower is ...
void SetShowerNumber(const int sid)
Definition: ShowerSimData.h:75
void SetShowerRunId(const std::string srid)
Definition: ShowerSimData.h:81
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.