EventFileReader.cc
Go to the documentation of this file.
1 
14 #include "EventFileReader.h"
15 
16 #include <fwk/CentralConfig.h>
17 #include <fwk/RunController.h>
18 
19 #include <det/Detector.h>
20 #include <sdet/SDetector.h>
21 
22 #include <io/EventFileChain.h>
23 #include <io/OfflineROOTFile.h>
24 
25 #include <evt/Header.h>
26 #include <evt/Event.h>
27 
28 #include <sevt/SEvent.h>
29 #include <sevt/Header.h>
30 #include <sevt/EventTrigger.h>
31 
32 #include <fevt/FEvent.h>
33 #include <fevt/Eye.h>
34 #include <fevt/EyeHeader.h>
35 
36 #include <utl/ErrorLogger.h>
37 #include <utl/Reader.h>
38 #include <utl/TimeStamp.h>
39 #include <utl/config.h>
40 
41 #include <revt/REvent.h>
42 #include <revt/Header.h>
43 
44 #include <io/CDASToOfflineEventConverter.h>
45 #include <AugerEvent.h>
46 #include <IoSdData.h>
47 
48 #include <MdEvent.h>
49 #include <mevt/MEvent.h>
50 #include <mevt/Header.h>
51 #include <mdet/MDetector.h>
52 
53 #include <TStopwatch.h>
54 
55 #include <fstream>
56 
57 using namespace std;
58 using namespace utl;
59 using sevt::SEvent;
60 using namespace io;
61 using sdet::SDetector;
62 using namespace fwk;
63 using namespace EventFileReaderOG;
64 
65 
66 // DV: we want this in the data segment to get the initialization
67 // at the library load time
68 namespace EventFileReaderOG {
69  TStopwatch gStopwatch;
70 }
71 
72 
73 EventFileReader::~EventFileReader()
74 {
75  delete fEventFiles;
76 }
77 
78 
81 {
82  Branch topBranch =
83  CentralConfig::GetInstance()->GetTopBranch("EventFileReader");
84 
85  fReportFilenames = bool(topBranch.GetChild("ReportFilenames"));
86  fIgnoreExpeptions = bool(topBranch.GetChild("IgnoreExceptions"));
87 
88  fBranch = topBranch.GetFirstChild();
89  if (fReportFilenames) // need to exclude this particular flag
90  fBranch = fBranch.GetNextSibling();
91  if (fIgnoreExpeptions) // need to exclude this particular flag
92  fBranch = fBranch.GetNextSibling();
93 
94  fEventFiles = nullptr;
95  fEventsRead = 0;
96  fCurrentFilename = "n/a"; // to trigger output of first file even if it is ""
97 
98  return eSuccess;
99 }
100 
101 
103 EventFileReader::OpenFiles()
104 {
105  if (!fBranch) {
106  ostringstream info;
107  info << "No more data to read. ";
108  if (fReportFilenames) {
109  info << "Last file: '" << fCurrentFilename << "'";
110  }
111  info << '.';
112  INFO(info);
113  return eBreakLoop;
114  }
115 
116  //Branch* nB = new Branch(fBranch);
117  fEventFiles = new EventFileChain(fBranch);
118  fEventFiles->SetIgnoreExceptions(fIgnoreExpeptions);
119  fBranch = fBranch.GetNextSibling(); // move to next sibling in input file
120  return eSuccess;
121 }
122 
123 
125 EventFileReader::Run(evt::Event& event)
126 {
127  if (!fEventFiles) {
128  VModule::ResultFlag result = OpenFiles();
129  if (result != eSuccess)
130  return result;
131  }
132 
133  const io::Status status = fEventFiles->Read(event);
134 
135  if (status == io::eEOF || status == io::eEndOfFiles) {
136 
137  delete fEventFiles;
138  fEventFiles = nullptr;
139  return eBreakLoop;
140 
141  } else if (status == io::eFail) {
142 
143  INFO("Failed to read event.");
144  return eFailure;
145 
146  } else if (status == io::eSkipEvent) {
147 
148  INFO("Failed to read event, will skip it");
149  return eContinueLoop;
150 
151  }
152 
153  ++fEventsRead;
154  ++RunController::GetInstance().GetRunData().GetNamedCounters()["EventFileReader/TotalEvents"];
155 
156  const string& file = fEventFiles->GetCurrentFilename();
157 
158  if (fCurrentFilename != file) {
159 
160  if (fReportFilenames) {
161  ostringstream info;
162  info << "Switching to file '" << file << "'.";
163  INFO(info);
164  }
165  fCurrentFilename = file;
166  RunController::GetInstance().GetRunData().SetCurrentFilename(file);
167  ++RunController::GetInstance().GetRunData().GetNamedCounters()["EventFileReader/Files"];
168 
169  }
170 
171  const evt::Header& header = event.GetHeader();
172 
173  io::Type fileType = fEventFiles->GetFileType();
174  if (fileType != eCONEXRandom &&
175  fileType != eCONEX &&
176  fileType != eCorsika &&
177  fileType != eAires &&
178  fileType != eSeneca &&
179  fileType != eRadioAERA && // for eRadioAERA it is already done in the reader
180  fileType != eRadioAERAroot &&
181  fileType != eREAS &&
182  fileType != eZHAireS &&
183  fileType != eEVA &&
184  fileType != eSELFAS) {
185  // This configures the detector.
186  // For simulations the time is defined by the EventGenerator,
187  // which is why we exclude those cases here.
188  det::Detector::GetInstance().Update(header.GetTime());
189  }
190 
191  // copy in the sd part of the raw event
192  if (event.HasRawEvent() && event.GetRawEvent().HasSd()) {
193  event << event.GetRawEvent().Sd();
194  ++RunController::GetInstance().GetRunData().GetNamedCounters()["EventFileReader/SdEvents"];
195  }
196 
197  if (event.HasRawEvent() && event.GetRawEvent().HasMd()) {
198  event << event.GetRawEvent().Md();
199  ++RunController::GetInstance().GetRunData().GetNamedCounters()["EventFileReader/MdEvents"];
200  }
201 
202  ostringstream info;
203  info << "Event id = '" << header.GetId() << '\'';
204  INFO(info);
205 
206  return eSuccess;
207 }
208 
209 
211 EventFileReader::Finish()
212 {
213  ostringstream info;
214  info << "Read " << fEventsRead << " events";
215 
216  gStopwatch.Stop();
217  const double realTime = gStopwatch.RealTime();
218  const double cpuTime = gStopwatch.CpuTime();
219 
220  info << " in " << realTime << " sec, " << (fEventsRead/realTime) << " ev/sec, with "
221  << (cpuTime/realTime*100) << "% cpu usage.";
222  INFO(info);
223 
224  delete fEventFiles;
225  fEventFiles = nullptr;
226 
227  return eSuccess;
228 }
229 
230 
231 const string&
232 EventFileReader::GetCurrentFilename()
233  const
234 {
235  return fEventFiles->GetCurrentFilename();
236 }
Branch GetTopBranch() const
Definition: Branch.cc:63
conex file, with random access (NOT sequencial, NO EOF)
Definition: IoCodes.h:42
IoAuger file format.
Definition: IoCodes.h:40
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
const utl::TimeStamp & GetTime() const
Definition: Event/Header.h:33
air shower radio simulations generated with EVA
Definition: IoCodes.h:49
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
Class representing a document branch.
Definition: Branch.h:107
Status
Return code for seek operation.
Definition: IoCodes.h:24
const Data result[]
const string file
const std::string & GetId() const
Get the event identifier.
Definition: Event/Header.h:31
A collection of EventFile.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
air shower radio simulations generated with ZHAireS
Definition: IoCodes.h:45
Detector description interface for SDetector-related data.
Definition: SDetector.h:42
bool HasRawEvent() const
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
Type
The type of file that we are acutally opening.
Definition: IoCodes.h:33
data-format of AERA
Definition: IoCodes.h:50
CDas file format.
Definition: IoCodes.h:37
root-format of AERA
Definition: IoCodes.h:51
Global event header.
Definition: Event/Header.h:27
air shower radio simulations generated with REAS
Definition: IoCodes.h:48

, generated on Tue Sep 26 2023.