FDasToOfflineEventConverter.cc
Go to the documentation of this file.
1 
9 #include <AugerEvent.h>
10 #include <EyeEvent.hh>
11 #include <EyeEventHeader.hh>
12 #include <FadcData.hh>
13 #include <FdNumbering.hh>
14 #include <FDEventLibVersion.hh>
15 
16 #include <io/FDasToOfflineEventConverter.h>
17 
18 #include <evt/Event.h>
19 #include <evt/Header.h>
20 
21 #include <fevt/FEvent.h>
22 #include <fevt/Header.h>
23 #include <fevt/Eye.h>
24 #include <fevt/EyeHeader.h>
25 #include <fevt/Telescope.h>
26 #include <fevt/Channel.h>
27 #include <fevt/Pixel.h>
28 
29 #include <utl/Trace.h>
30 #include <utl/TimeStamp.h>
31 #include <utl/TabulatedFunction.h>
32 #include <utl/AugerUnits.h>
33 
34 #include <utl/ErrorLogger.h>
35 #include <algorithm>
36 #include <sstream>
37 
38 using namespace fevt;
39 using namespace std;
40 
41 namespace io {
42 
43  void
44  operator<<(evt::Event& theEvent, const TEyeEvent& theData)
45  {
46  if (!theEvent.HasFEvent())
47  theEvent.MakeFEvent();
48 
49  fevt::FEvent& fevent = theEvent.GetFEvent();
50 
51  TEyeEventHeader* const eyeheader =
52  const_cast<TEyeEvent&>(theData).GetEventHeader();
53 
54  const unsigned int sec = eyeheader->GetTimeStamp()->GetGPSSec();
55  const unsigned int nsec = eyeheader->GetTimeStamp()->GetNanoSec();
56 
57  const utl::TimeStamp tstamp(sec, nsec);
58 
59  const int eyeid = eyeheader->GetEyeNo();
60 
61 #if FDEVENTLIB_VERSION_CODE < ModuleVersionCode(4, 0, 0)
62  if (eyeid > 4) {
63  ostringstream msg;
64  msg << "Trying to read data with eye ids > 4 (HEAT) using an "
65  << "FDEventLib older than v4r0. Old FDEventLibs do not support "
66  << "HEAT data. I will skip this eye (id=" << eyeid << ").";
67  WARNING(msg.str());
68  return;
69  }
70 #endif
71 
72  if (fevent.HasEye(eyeid)) {
73 
74  ostringstream err;
75  err << "\n\n\n\n"
76  " *************************************************************\n"
77  " *************************************************************\n"
78  " * FDAS raw-eye with Id=" << eyeid << " added twice!"
79  " * Report corrupt data, or check your input files!\n"
80  " *************************************************************\n"
81  " *************************************************************"
82  "\n\n\n";
83  ERROR(err.str());
84  }
85  fevent.MakeEye(eyeid);
86 
87  // ----------- do the EyeHeader ---------------
88 
89  if (!fevent.GetEye(eyeid).HasHeader())
90  fevent.GetEye(eyeid).MakeHeader();
91 
92  EyeHeader& headerEye = fevent.GetEye(eyeid).GetHeader();
93  Header& headerFEvent = fevent.GetHeader();
94 
95  // Fill offline header
96 
97  const unsigned int runno = eyeheader->GetRunNo();
98  const unsigned int evno = eyeheader->GetEventNo();
99  const int eclass = eyeheader->GetEventClass();
100  const int etype = eyeheader->GetEventType();
101 
102  // fill evt::Header of Event
103  evt::Header& evtHeader = theEvent.GetHeader();
104  const utl::TimeStamp& previous_time = evtHeader.GetTime();
105  const std::string& previous_str = evtHeader.GetId();
106 
107  if (!previous_time.GetGPSSecond() ||
108  previous_time > tstamp)
109  theEvent.GetHeader().SetTime(tstamp);
110 
111  ostringstream id_str;
112  if (!previous_str.empty())
113  id_str << previous_str << "__";
114  id_str << "eye" << eyeid
115  << "_run" << runno
116  << "_event" << evno;
117  theEvent.GetHeader().SetId(id_str.str());
118 
119  // Fill header of FEvent
120  headerFEvent.SetId(eyeid); // to be set
121  headerFEvent.SetNEyes(headerFEvent.GetNEyes() + 1);
122  headerFEvent.SetTime(tstamp);
123  // Fill header of eye
124  headerEye.SetTimeStamp(tstamp);
125  headerEye.SetEventNumber(evno);
126  headerEye.SetRunNumber(runno);
127  headerEye.SetEventType(static_cast<fevt::EyeHeader::EventType>(etype));
128  headerEye.SetEventClass(static_cast<fevt::EyeHeader::EventClass>(eclass));
129 
130  // copy the telescope time offset into the Offline data structure
131  for (unsigned int i = FdUtil::Fd::kEYE_FIRST_MIRROR;
132  i <= FdUtil::Fd::kEYE_LAST_MIRROR; ++i)
133 
134  if (eyeheader->IsMirrorDataPresent(i)) {
135 
136  if (!fevent.GetEye(eyeid).HasTelescope(i))
137  fevent.GetEye(eyeid).MakeTelescope(i);
138 
139  fevt::Telescope& telescope = fevent.GetEye(eyeid).GetTelescope(i);
140  telescope.SetTimeOffset(eyeheader->GetMirrorTimeOffset(i));
141 
142  ostringstream pointing;
143  pointing << "data: ";
144 #if FDEVENTLIB_VERSION_CODE >= ModuleVersionCode(4, 0, 4)
145  TEyeGeometryData * const eyeGeometry =
146  const_cast<TEyeEvent&>(theData).GetGeometryData();
147  if (!eyeGeometry) {
148  pointing << "unknown";
149  }
150  else {
151  float pointingElev, pointingPhi;
152  eyeGeometry->GetAxisDirection(i, pointingPhi, pointingElev);
153  pointing << pointingElev;
154  }
155 #else
156  pointing << "unknown";
157 #endif
158  telescope.SetRawTelPointing(pointing.str());
159  }
160  }
161 
162 
163  // RETHINK + REDO
164  void
165  operator>>(const fevt::Eye& /*eyeEvent*/, TEyeEvent& /*data*/)
166  {
167  /*
168  if (!theData) {
169 
170  ERROR("NULL TEyeEvent object passed to PushEvent().");
171  return;
172  }
173  */
174 
175  /*
176  if (!theEyeEvent.HasRawEvent()) {
177 
178  ERROR("Non-existent evt::Event::GetRawEvent() class object.");
179  return;
180  }
181  */
182 
183  /*
184  // this is because AugerEvent lacks a const EyesBegin
185  AugerEvent& non_const_event
186  = const_cast<AugerEvent&>(theEvent.GetRawEvent());
187 
188  AugerEvent::EyeIterator eyeiter = non_const_event.EyesBegin();
189 
190  // do nothing if the raw eye has not been filled
191  if (eyeiter != non_const_event.EyesEnd()) {
192 
193  *theData = *eyeiter;
194 
195  }
196  */
197  }
198 
199 }
200 
201 
202 // Configure (x)emacs for this file ...
203 // Local Variables:
204 // mode: c++
205 // End:
void operator>>(const Event &theEvent, IoSdEvent &rawSEvent)
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
Definition: FEvent/Eye.cc:57
bool HasHeader() const
Definition: FEvent/Eye.h:104
Header & GetHeader()
Definition: FEvent.h:92
fevt::EyeHeader & GetHeader()
Header for this Eye Event.
Definition: FEvent/Eye.cc:180
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
evt::Header & GetHeader()
bool HasFEvent() const
void SetTime(const utl::TimeStamp &t)
Definition: Event/Header.h:38
Header of Eye-level event.
Definition: EyeHeader.h:32
void SetTimeOffset(const unsigned int toffset)
void MakeEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Definition: FEvent.cc:115
void SetTimeStamp(const utl::TimeStamp ts)
Definition: EyeHeader.h:137
ostream & operator<<(ostream &os, const StationTriggerInfo &info)
void MakeTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Make Telescope telescopeId.
Definition: FEvent/Eye.cc:102
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
const utl::TimeStamp & GetTime() const
Definition: Event/Header.h:33
void SetId(const std::string &id)
Set the event identifier.
Definition: Event/Header.h:36
void SetTime(const utl::TimeStamp &time)
Definition: FEvent/Header.h:29
void SetEventType(const EventType et)
Definition: EyeHeader.h:140
void SetRawTelPointing(const std::string &pointing)
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void MakeHeader()
Definition: FEvent/Eye.cc:195
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
Eye & GetEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
return Eye by id
Definition: FEvent.cc:70
fevt::FEvent & GetFEvent()
bool HasEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Definition: FEvent.cc:57
const std::string & GetId() const
Get the event identifier.
Definition: Event/Header.h:31
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
void SetNEyes(const int n)
Definition: FEvent/Header.h:28
bool HasTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Check if the telescope is in the event.
Definition: FEvent/Eye.cc:117
void SetId(const int id)
Definition: FEvent/Header.h:27
int GetNEyes() const
Number of eyes in the event.
Definition: FEvent/Header.h:23
Fluorescence Detector Telescope Event.
void SetRunNumber(const unsigned int runno)
Definition: EyeHeader.h:138
void SetEventClass(const EventClass ec)
Definition: EyeHeader.h:141
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
Header for an fevt::FEvent.
Definition: FEvent/Header.h:16
void SetEventNumber(const unsigned int evno)
Definition: EyeHeader.h:139
Global event header.
Definition: Event/Header.h:27

, generated on Tue Sep 26 2023.