EventFile.cc
Go to the documentation of this file.
1 #include <io/EventFile.h>
2 #include <utl/config.h>
3 
4 #include <io/VEventFile.h>
5 #include <io/StreamerSwitch.h>
6 
7 #include <io/OfflineROOTFile.h>
8 #include <io/CDASEventFile.h>
9 #include <io/FDasEventFile.h>
10 #include <io/CorsikaShowerFile.h>
11 #include <io/SenecaShowerFile.h>
12 #include <io/ArtificialShowerFile.h>
13 
14 #include <IoAuger.h>
15 // Seneca header include added by Jeff Allen (jda292@nyu.edu) on Dec. 5th, 2006
16 #ifdef HAVE_AIRES
17 # include <io/AiresShowerFile.h>
18 #endif
19 #include <io/CONEXFile.h>
20 #include <io/CONEXRandomFile.h>
21 #include <io/IoAugerEventFile.h>
22 #include <io/ZHAireSFile.h>
23 #include <io/REASFile.h>
24 #include <io/REASH5File.h>
25 #include <io/EVAFile.h>
26 #include <io/RadioFileAERA.h>
27 #include <io/RadioFileAERAroot.h>
28 #include <io/SELFASFile.h>
29 #include <evt/Event.h>
30 
31 #include <cstddef>
32 #include <iostream>
33 
34 using namespace std;
35 using namespace io;
36 
37 
38 const StreamerSwitch EventFile::kDefaultSwitch;
39 
40 
41 EventFile::EventFile(const Type type, utl::Branch* const /*b*/) :
42  fType(type),
43  fStreamerSwitch(kDefaultSwitch)
44 { }
45 
46 
47 EventFile::EventFile(const std::string& filename,
48  const Mode mode,
49  const Type type,
50  utl::Branch* const b,
51  const StreamerSwitch& streamerSwitch) :
52  fVEventFile(EventFile::Factory(filename, mode, type, b, streamerSwitch)),
53  fType(type),
54  fStreamerSwitch(streamerSwitch)
55 { }
56 
57 
59 {
60  Close();
61  delete fVEventFile;
62 }
63 
64 
67  const Mode mode,
68  const Type type,
69  utl::Branch* const b,
70  const StreamerSwitch& streamerSwitch)
71 {
72  switch (type) {
73  case eOffline:
74  return new OfflineROOTFile(filename, mode, b, streamerSwitch);
75  case eCDas:
76  return new CDASEventFile(filename, mode, b);
77  case eFDas:
78  return new FDasEventFile(filename, mode, b);
79  case eCorsika:
80  return new CorsikaShowerFile(filename, mode, b);
81  // Added by Jeff Allen (jda292@nyu.edu) on Dec. 5th, 2006. Seneca file
82  case eSeneca:
83  return new SenecaShowerFile(filename, mode, b);
84  case eArtificial:
85  return new ArtificialShowerFile(filename, mode, b);
86 #ifdef HAVE_AIRES
87  case eAires:
88  return new AiresShowerFile(filename, mode, b);
89 #endif
90  case eIoAuger:
91  return new IoAugerEventFile(filename, mode, b);
92  case eCONEX:
93  return new CONEXFile(filename, mode, b);
94  case eCONEXRandom:
95  return new CONEXRandomFile(filename, mode, b);
96  case eZHAireS:
97  return new ZHAireSFile(filename, mode, b);
98  case eREAS:
99  return new REASFile(filename, mode, b);
100  case eREASH5:
101  return new REASH5File(filename, mode, b);
102  //case eReAires:
103  // return new ReAiresFile(filename, mode);
104  case eEVA:
105  return new EVAFile(filename, mode, b);
106  case eRadioAERA:
107  return new RadioFileAERA(filename, mode, b);
108  case eRadioAERAroot:
109  return new RadioFileAERAroot(filename, mode, b);
110  case eSELFAS:
111  return new SELFASFile(filename, mode, b);
112  default:
113  throw utl::IOFailureException("Unknown file type specified");
114  }
115 }
116 
117 
118 void
119 EventFile::Open(const std::string& filename, const Mode mode, utl::Branch* const b)
120 {
121  if (!fVEventFile)
122  fVEventFile = EventFile::Factory(filename, mode, fType, b, fStreamerSwitch);
123 
124  fVEventFile->Open(filename, mode, b);
125 }
126 
127 
128 void
130 {
131  if (fVEventFile)
132  fVEventFile->Close();
133 }
134 
135 
136 void
138 {
139  if (!fVEventFile)
140  throw utl::IOFailureException("Open file before calling Write()");
141 
142  fVEventFile->Write(event);
143 }
144 
145 
147 Status
149 {
150  if (!fVEventFile)
151  throw utl::IOFailureException("Open file before calling Read()");
152 
153  event = evt::Event();
154 
155  return fVEventFile->Read(event);
156 }
157 
158 
159 
161 Status
162 EventFile::FindEvent(const unsigned int eventId)
163 {
164  if (!fVEventFile)
165  throw utl::IOFailureException("Open file before calling FindEvent()");
166 
167  return fVEventFile->FindEvent(eventId);
168 }
169 
170 
172 Status
173 EventFile::GotoPosition(const unsigned int position)
174 {
175  if (!fVEventFile)
176  throw utl::IOFailureException("Open file before calling GotoPosition()");
177 
178  return fVEventFile->GotoPosition(position);
179 }
180 
181 
182 int
184 {
185  return fVEventFile ? fVEventFile->GetNEvents() : -1;
186 }
187 
188 
189 const std::string&
191  const
192 {
193  static const string empty;
194 
195  return fVEventFile ? fVEventFile->GetFilename() : empty;
196 }
virtual void Write(const evt::Event &event)=0
ROOT streamer for top level offline format.
EventFile(const Type type=eOffline, utl::Branch *const b=nullptr)
Definition: EventFile.cc:41
conex file, with random access (NOT sequencial, NO EOF)
Definition: IoCodes.h:42
Read profiles from CONEX.
Definition: CONEXFile.h:36
IoAuger file format.
Definition: IoCodes.h:40
switches to allow excluding certain parts of Event from streaming
Status FindEvent(const unsigned int eventId)
seek Event id set cursor there
Definition: EventFile.cc:162
io::Type fType
Definition: EventFile.h:85
FDas file format.
Definition: IoCodes.h:36
Seneca File Format. Added by Jeff Allen (jda292@nyu.edu) on Dec. 5th, 2006.
Definition: IoCodes.h:43
void Open(const std::string &filename, const Mode mode=eRead, utl::Branch *const b=nullptr)
Definition: EventFile.cc:119
const std::string & GetFilename() const
Definition: VEventFile.h:54
virtual int GetNEvents()=0
virtual Status FindEvent(const unsigned int eventId)=0
seek Event id set cursor there
Mode
Available open modes.
Definition: IoCodes.h:16
virtual Status GotoPosition(const unsigned int position)=0
goto by position in the file
io::StreamerSwitch fStreamerSwitch
Definition: EventFile.h:86
virtual Status Read(evt::Event &event)=0
read current event advance cursor by 1
virtual void Open(const std::string &filename, const Mode mode=eRead, utl::Branch *const b=nullptr)=0
Base class to report exceptions in IO.
Offline native file format.
Definition: IoCodes.h:35
air shower radio simulations generated with EVA
Definition: IoCodes.h:49
Class representing a document branch.
Definition: Branch.h:107
Artificial shower generator: uniform particle density, direction.
Status
Return code for seek operation.
Definition: IoCodes.h:24
int GetNEvents()
Definition: EventFile.cc:183
virtual void Close()=0
air shower radio simulations generated with REAS
Definition: IoCodes.h:46
Read data from the output of CORSIKA.
Status Read(evt::Event &event)
read current event, advance cursor by 1
Definition: EventFile.cc:148
const std::string & GetFilename() const
Definition: EventFile.cc:190
void Close()
Definition: EventFile.cc:129
Read EVA simulation output.
Definition: EVAFile.h:44
air shower radio simulations generated with ZHAireS
Definition: IoCodes.h:45
Interface to file I/O objects.
Definition: EventFile.h:34
Interface for CDAS file reading.
Definition: CDASEventFile.h:19
Read REAS simulation output.
Definition: REASFile.h:34
io::VEventFile * fVEventFile
Definition: EventFile.h:84
Read REASH5 simulation output.
Definition: REASH5File.h:40
Status GotoPosition(const unsigned int position)
goto by position in the file
Definition: EventFile.cc:173
char * filename
Definition: dump1090.h:266
Read SELFAS simulation output.
Definition: SELFASFile.h:38
Utility to open an Aires generated shower file on disc.
Type
The type of file that we are acutally opening.
Definition: IoCodes.h:33
Read data from the output of Seneca.
Interface for FDAS file reading.
Definition: FDasEventFile.h:24
data-format of AERA
Definition: IoCodes.h:50
CDas file format.
Definition: IoCodes.h:37
root-format of AERA
Definition: IoCodes.h:51
Read profiles from CONEXRandom by random access.
static io::VEventFile * Factory(const std::string &filename, const Mode mode, const Type type, utl::Branch *const branch, const io::StreamerSwitch &streamerSwitch)
Definition: EventFile.cc:66
air shower radio simulations generated with REAS
Definition: IoCodes.h:48
void Write(const evt::Event &event)
Definition: EventFile.cc:137

, generated on Tue Sep 26 2023.