EventFileExporter.cc
Go to the documentation of this file.
1 #include "EventFileExporter.h"
2 
3 
4 #include <io/EventFile.h>
5 
6 #include <fwk/CentralConfig.h>
7 #include <fwk/RunController.h>
8 
9 #include <evt/Event.h>
10 
11 #include <det/Detector.h>
12 
13 #include <sevt/SEvent.h>
14 #include <sevt/Header.h>
15 #include <sevt/EventTrigger.h>
16 
17 #include <fevt/FEvent.h>
18 #include <fevt/Eye.h>
19 #include <fevt/EyeHeader.h>
20 
21 #include <utl/config.h>
22 #include <utl/ErrorLogger.h>
23 #include <utl/Reader.h>
24 #include <utl/TimeStamp.h>
25 
26 #include <EyeEvent.hh>
27 
28 #include <boost/filesystem/operations.hpp>
29 #include <boost/filesystem/path.hpp>
30 
31 #include <cstddef>
32 #include <sstream>
33 
34 namespace fs = boost::filesystem;
35 using namespace EventFileExporterOG;
36 using namespace fwk;
37 using namespace io;
38 using namespace evt;
39 using namespace utl;
40 using namespace std;
41 
42 
45 {
46 
47  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("EventFileExporter");
48 
49  const string fileType = topBranch.GetChild("OutputFileType").Get<string>();
50 
51  if(fileType == "Offline")
52  fFileType = eOffline;
53  else if(fileType == "FDAS")
54  fFileType = eFDas;
55  else if(fileType == "CDAS")
56  fFileType = eCDas;
57  else if(fileType == "CORSIKA")
58  fFileType = eCorsika;
59  else if(fileType == "AIRES")
60  fFileType = eAires;
61  else if(fileType == "IoAuger")
62  fFileType = eIoAuger;
63  else if(fileType == "RadioAERAroot")
64  fFileType = eRadioAERAroot;
65  else{
66  ostringstream err;
67  err << "Unknown file type " << fileType << " in EventFileExporter::Init()";
68  ERROR(err);
69  }
70 
71  topBranch.GetChild("OutputFilename").GetData(fEventFilename);
72 
73  if (fFileType == io::eCorsika || fFileType == io::eAires) {
74  ERROR("Output to strictly input only file types not allowed.");
75  return eFailure;
76  }
77 
78  // Read in streamer switch settings from XML and set the StreamerSwitch accordingly
79  Branch sB = topBranch.GetChild("StreamerSwitches");
80 
81  if (sB) {
82  //ostringstream msg;
83  string sSwitch;
84 
85  if (sB.GetChild("FDRaw")) {
86  sB.GetChild("FDRaw").GetData(sSwitch);
87  if (sSwitch == string("off")) {
88  //msg << "\n\tFDRaw data";
89  //fStreamerSwitch.SetFDRaw(false);
90  WARNING("Streamer switching is currently not supported ");
91  }
92  }
93 
94  if (sB.GetChild("FDSimTraces")) {
95  sB.GetChild("FDSimTraces").GetData(sSwitch);
96  if (sSwitch == string("off")) {
97  //msg << "\n\tFDSim photon traces";
98  //fStreamerSwitch.SetFDSimPhotonTraces(false);
99  WARNING("Streamer switching is currently not supported ");
100  }
101  }
102 
103  if (sB.GetChild("FDSimTelescope")) {
104  sB.GetChild("FDSimTelescope").GetData(sSwitch);
105  if (sSwitch == string("off")) {
106  //msg << "\n\tFDSim photon telescopes";
107  //fStreamerSwitch.SetFDSimTelescope(false);
108  WARNING("Streamer switching is currently not supported ");
109  }
110  }
111 
112  if (sB.GetChild("SDSimPEHisto")) {
113  sB.GetChild("SDSimPEHisto").GetData(sSwitch);
114  if (sSwitch == string("off")) {
115  //msg << "\n\tSD PMT simulated photoelectron time distributions";
116  //fStreamerSwitch.SetSDSimPETimeDistribution(false);
117  WARNING("Streamer switching is currently not supported ");
118  }
119  }
120 
121  if (sB.GetChild("SDSimPMTBaseHisto")) {
122  sB.GetChild("SDSimPMTBaseHisto").GetData(sSwitch);
123  if (sSwitch == string("off")) {
124  //msg << "\n\tSD PMT base time distributions";
125  //fStreamerSwitch.SetSDSimPMTBaseTimeDistribution(false);
126  WARNING("Streamer switching is currently not supported ");
127  }
128  }
129 
130  if (sB.GetChild("SDSimPMTFilterHisto")) {
131  sB.GetChild("SDSimPMTFilterHisto").GetData(sSwitch);
132  if (sSwitch == string("off")) {
133  //msg << "\n\tSD PMT filter time distributions";
134  //fStreamerSwitch.SetSDSimPMTFilterTimeDistribution(false);
135  WARNING("Streamer switching is currently not supported ");
136  }
137  }
138 
139  if (sB.GetChild("SDSimTankParticles")) {
140  sB.GetChild("SDSimTankParticles").GetData(sSwitch);
141  if (sSwitch == string("on")) {
142  //INFO("Switching on SD sim particle streamers.");
143  //fStreamerSwitch.SetSDSimTankParticles(true);
144  } else
145  WARNING("Streamer switching is currently not supported ");
146  }
147 
148  if (sB.GetChild("CDSimRPCParticles")) {
149  sB.GetChild("CDSimRPCParticles").GetData(sSwitch);
150  if (sSwitch == string("on")) {
151  //INFO("Switching on MARTA sim streamer for particles in RPC.");
152  //fStreamerSwitch.SetMARTASimRPCParticles(true);
153  } else
154  WARNING("Streamer switching is currently not supported ");
155  }
156 
157  /*ostringstream info;
158  info << "StreamerSwitch data found. ";
159  if (msg.str().length())
160  info << "Switching off the following streamers:"
161  << msg.str();*/
162 
163  } else
164 
165  INFO("StreamerSwitch data not found.");
166 
167 #warning INFO: the streamer-switches can also go entirely into the new Branch interface
168  fEventFile = new EventFile(fEventFilename, io::eNew, fFileType, 0, fStreamerSwitch);
169  return eSuccess;
170 }
171 
172 
175 {
176  fEventFile->Write(event);
177  ++fEventsWritten;
178 
179  ++RunController::GetInstance().GetRunData().GetNamedCounters()["EventFileExporter/Events"];
180 
181  return eSuccess;
182 }
183 
184 
187 {
188  std::ostringstream info;
189  info << "Wrote " << fEventsWritten << " events.";
190  INFO(info);
191 
192  fEventFile->Close();
193 
194  return eSuccess;
195 }
Branch GetTopBranch() const
Definition: Branch.cc:63
fwk::VModule::ResultFlag Run(evt::Event &event) override
Run: invoked once per event.
FDas file format.
Definition: IoCodes.h:36
Open file for write, fail if exists.
Definition: IoCodes.h:19
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
fwk::VModule::ResultFlag Init() override
Initialize: invoked at beginning of run (NOT beginning of event)
Offline native file format.
Definition: IoCodes.h:35
T Get() const
Definition: Branch.h:271
Class representing a document branch.
Definition: Branch.h:107
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
Interface to file I/O objects.
Definition: EventFile.h:34
fwk::VModule::ResultFlag Finish() override
Finish: invoked at end of the run (NOT end of the event)
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
data-format of AERA
Definition: IoCodes.h:50
CDas file format.
Definition: IoCodes.h:37

, generated on Tue Sep 26 2023.