FDetector/Eye.cc
Go to the documentation of this file.
1 #include <sstream>
2 
3 #include <boost/lexical_cast.hpp>
4 
5 #include <fdet/Telescope.h>
6 #include <fdet/Eye.h>
7 
8 #include <det/VManager.h>
9 #include <det/Detector.h>
10 
11 #include <utl/UTMPoint.h>
12 #include <utl/Point.h>
13 #include <utl/ReferenceEllipsoid.h>
14 #include <utl/Transformation.h>
15 #include <utl/Vector.h>
16 #include <utl/ErrorLogger.h>
17 #include <utl/Deprecator.h>
18 
19 #include <fwk/CoordinateSystemRegistry.h>
20 #include <fwk/LocalCoordinateSystem.h>
21 
22 using namespace std;
23 using namespace utl;
24 using namespace fdet;
25 using namespace det;
26 using namespace fwk;
27 
28 
29 bool
30 TelIsCommissioned::operator()(const fdet::Telescope& tel)
31  const
32 {
33  const TimeStamp& dTime = det::Detector::GetInstance().GetTime();
34  return tel.GetCommissionTime() < dTime && dTime < tel.GetDecommissionTime();
35 }
36 
37 
38 //=============================================================================
39 
40 
41 Eye::Eye(unsigned int eyeId) :
42  fEyeId(eyeId),
43  //fEyeIdString(),
44  fIdOfParentPhysicalEye(-1),
45  fFullTelescopeIdList(0),
46  fPosition(0),
47  fName(0),
48  fNameAbbr(0),
49  fCoordinateSystem(),
50  fBackwallAngle(0),
51  fTimeCorrectionFactors(0),
52  fSDTimeOffset(0),
53  fUpTimeFraction(0),
54  fStatus(0)
55 {
56  fEyeIdString = boost::lexical_cast<string>(eyeId);
57 }
58 
59 
61 {
62  delete fName;
63  delete fNameAbbr;
64  delete fBackwallAngle;
65  delete fPosition;
66  delete fFullTelescopeIdList;
68 
69  for (FullTelescopeIterator it = fFullTelescopeList.begin();
70  it != fFullTelescopeList.end(); ++it)
71  delete *it;
72 
73  delete fSDTimeOffset;
74 }
75 
76 
77 unsigned int
79  const
80 {
82  return 0;
83  return *std::min_element(fFullTelescopeIdList->begin(), fFullTelescopeIdList->end());
84 }
85 
86 
87 unsigned int
89  const
90 {
92  return 0;
93  return *std::max_element(fFullTelescopeIdList->begin(), fFullTelescopeIdList->end());
94 }
95 
96 
97 double
99  const
100 {
101  UpdateFdUpTime();
102  return fUpTimeFraction;
103 }
104 
105 double
107  const
108 {
109  UpdateFdUpTime();
110  return fFDASVetoFraction;
111 }
112 
113 double
115  const
116 {
117  UpdateFdUpTime();
118  return fCDASVetoFraction;
119 }
120 bool
122  const
123 {
124  UpdateFdUpTime();
125  return fUpTimeFraction > 0;
126 }
127 
128 
129 int
131  const
132 {
133  UpdateFdUpTime();
134  return fStatus;
135 }
136 
137 
138 void
140  const
141 {
143  return;
144 
145  int startTime;
146  GetEyeData(startTime, "uptime_gpsStart", "eye", "start validity eye up time");
147  int endTime;
148  GetEyeData(endTime, "uptime_gpsStop", "eye", "end validity eye up time");
149  GetEyeData(fUpTimeFraction, "uptime_fraction", "eye", "eye up time fraction");
150  GetEyeData(fFDASVetoFraction, "veto_fraction", "eye", "eye veto fraction");
151  GetEyeData(fCDASVetoFraction, "veto_fraction", "CDAS", "CDAS per eye veto fraction");
152  GetEyeData(fStatus, "status", "eye", "eye DAQ status");
153  fUpTimeValidityStamp.SetValidityInterval(startTime, endTime);
154 }
155 
156 
157 void
159 {
160  // Get all telescopes indicated in the XML file
161  // and construct telescopes (uses lazy evaluation).
163 
164  if (fIdOfParentPhysicalEye < 0) {
165  fIdOfParentPhysicalEye = 0; // default to being a physical eye
166  GetEyeData(fIdOfParentPhysicalEye, "parentEye", "virtualEye",
167  "parent eye id of virtual eye");
168 
170  = boost::lexical_cast<string>(fIdOfParentPhysicalEye);
171  }
172 
173  // typedef FullTelescopeList::iterator fullIt;
175  it->Update();
176 }
177 
178 
180 const Telescope&
181 Eye::GetTelescope(unsigned int telescopeId)
182  const
183 {
184  for (TelescopeIterator it = TelescopesBegin(); it != TelescopesEnd(); ++it)
185  if (telescopeId == it->GetId())
186  return *it;
187 
188  ostringstream err;
189  err << "Telescope with Id = " << telescopeId << " "
190  "for Eye " << fEyeIdString << " "
191  "is not commissioned at detector time = "
192  << Detector::GetInstance().GetTime();
193  ERROR(err);
194  throw utl::NonExistentComponentException(err.str());
195 }
196 
197 
198 Point
200  const
201 {
202  if (!fPosition) {
203  // WARNING("Consider using Telescope::GetPosition. It is in general more accurate. ");
204  double northing;
205  GetEyeData(northing, "northing", "eye", "eye position northing");
206  double easting;
207  GetEyeData(easting, "easting", "eye", "eye position easting");
208  double altitude;
209  GetEyeData(altitude, "altitude", "eye", "eye position altitude");
210  int zone;
211  GetEyeData(zone, "zone", "eye", "eye position zone");
212  string band;
213  GetEyeData(band, "band", "eye", "eye position band");
214 
215  const CoordinateSystemPtr cs = Detector::GetInstance().GetSiteCoordinateSystem();
216  const ReferenceEllipsoid& e = ReferenceEllipsoid::GetWGS84();
217  const UTMPoint utmp(northing, easting, altitude, zone, band.c_str()[0], e);
218  fPosition = new Point(utmp.GetPoint(cs));
219  }
220 
221  return *fPosition;
222 }
223 
224 
225 const string&
227  const
228 {
229  return GetEyeData(fName, "name", "eye", "eye name string");
230 }
231 
232 const string&
234  const
235 {
236  return GetEyeData(fNameAbbr, "nameAbbr", "eye", "eye name abbreviation string");
237 }
238 
244 void
246  const
247 {
248  // Lazy evaluation of FullTelescopeList
249  //
250  if (!fFullTelescopeIdList) {
251 
252  GetEyeData(fFullTelescopeIdList, "telescopeList", "", "telescope id list");
253 
254  // Construct all telescopes
255  for (FullTelescopeIdList::const_iterator it = fFullTelescopeIdList->begin();
256  it != fFullTelescopeIdList->end(); ++it) {
257  Telescope* const telescope = new Telescope(fEyeId, *it);
258  fFullTelescopeList.push_back(telescope);
259  }
260  }
261 }
262 
263 
264 double
266  const
267 {
268  return GetEyeData(fBackwallAngle, "backwallAngle", "eye", "eye backwall angle");
269 }
270 
271 
274  const
275 {
276  if (!fCoordinateSystem) {
277 
278 
279  const Point pos = GetPosition();
280  const CoordinateSystemPtr stdLocalCS = LocalCoordinateSystem::Create(pos);
281  fCoordinateSystem = CoordinateSystem::RotationZ(GetBackwallAngle(), stdLocalCS);
282  }
283 
284  return fCoordinateSystem;
285 }
286 
287 
290  const
291 {
292  const Point pos = GetPosition();
293  return LocalCoordinateSystem::Create(pos);
294 }
295 
296 
299  const
300 {
301  return GetEyeData(fTimeCorrectionFactors, "MHzTimeCorrection", "eye", "eye time correction factors");
302 }
303 
304 
305 const utl::TimeInterval&
307  const
308 {
309  if (!fSDTimeOffset) {
310 
311  double timeoffset = 0;
312  GetEyeData(timeoffset, "sdTimeOffset", "eye", "eye sd time offset");
313  fSDTimeOffset = new TimeInterval(timeoffset);
314  }
315 
316  return *fSDTimeOffset;
317 }
318 
319 
321  double minWavelength = 0;
322  bool first = true;
324  if (first) {
325  first = false;
326  minWavelength = it->GetModelMinWavelength();
327  }
328  else {
329  minWavelength = max(minWavelength, it->GetModelMinWavelength());
330  }
331  }
332  return minWavelength;
333 }
334 
336  double maxWavelength = 0;
337  bool first = true;
339  if (first) {
340  first = false;
341  maxWavelength = it->GetModelMaxWavelength();
342  }
343  else {
344  maxWavelength = min(maxWavelength, it->GetModelMaxWavelength());
345  }
346  }
347  return maxWavelength;
348 }
349 
350 
351 std::set<unsigned int>
353  const
354 {
355  set<unsigned int> ids;
356 
357  if (!IsVirtual()) {
358  ids.insert(fEyeId);
359  return ids;
360  }
361 
363  it != FullTelescopesEnd(); ++it)
364  ids.insert(it->GetParentPhysicalEyeId());
365 
366  return ids;
367 }
368 
369 template<typename T>
370 inline
371 const T&
372 Eye::GetEyeData(T*& requestedData,
373  const string& property,
374  const string& component,
375  const string& errorMsg)
376  const
377 {
378  if (!requestedData) {
379  requestedData = new T;
380  GetEyeData(*requestedData, property, component, errorMsg);
381  }
382  return *requestedData;
383 }
384 
385 
386 template<typename T>
387 inline
388 void
389 Eye::GetEyeData(T& requestedData,
390  const string& property,
391  const string& component,
392  const string& errorMsg)
393  const
394 {
395  const VManager& manager = Detector::GetInstance().GetFManagerRegister();
396 
397  VManager::IndexMap indexMap;
398 
399  // If this is a virtual eye, fetch the information from the
400  // real eye that this virtual eye resembles
401  if (IsVirtual()
402  && component != "virtualEye"
403  && property != "telescopeList"
404  && property != "name")
405  indexMap["eyeId"] = fIdOfParentPhysicalEyeString;
406  else
407  indexMap["eyeId"] = fEyeIdString;
408 
409  const VManager::Status status =
410  manager.GetData(requestedData, property, component, indexMap);
411 
412  // ERROR
413  if (status == VManager::eNotFound) {
414  ostringstream err;
415  err << "Did not find requested component for " << errorMsg << "; "
416  << VManager::QueryInfoMessage(property, component, indexMap);
417  ERROR(err);
418  throw NonExistentComponentException(err.str());
419  }
420 }
421 
422 
423 // Configure (x)emacs for this file ...
424 // Local Variables:
425 // mode: c++
426 // compile-command: "make -C .. FDetector/Eye.o -k"
427 // End:
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
The Auger coordinate system (x to east, z local verical) for this eye.
std::string * fName
utl::CoordinateSystemPtr fCoordinateSystem
void Update()
void UpdateFdUpTime() const
const T & GetEyeData(T *&requestedData, const std::string &property, const std::string &component, const std::string &errorMsg) const
Point object.
Definition: Point.h:32
double GetCDASVetoFraction() const
const utl::TabulatedFunction & GetTimeCorrectionFactors() const
int fIdOfParentPhysicalEye
void GetFullTelescopeList() const
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
double fCDASVetoFraction
FullTelescopeIdList * fFullTelescopeIdList
Class to hold collection (x,y) points and provide interpolation between them.
FullTelescopeList::iterator FullTelescopeIterator
Definition: FDetector/Eye.h:50
double fUpTimeFraction
Base class for exceptions trying to access non-existing components.
Interface for detector managers.
Definition: VManager.h:115
double * fBackwallAngle
unsigned int GetFirstTelescopeId() const
First telescope id in the eye.
InternalTelescopeIterator FullTelescopesBegin()
Definition: FDetector/Eye.h:58
det::ValidityStamp fUpTimeValidityStamp
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
double GetUpTimeFraction() const
boost::indirect_iterator< FullTelescopeIterator, Telescope & > InternalTelescopeIterator
Definition: FDetector/Eye.h:54
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
boost::indirect_iterator< FullTelescopeConstIterator, const Telescope & > InternalConstTelescopeIterator
Definition: FDetector/Eye.h:56
#define max(a, b)
utl::Point * fPosition
double fFDASVetoFraction
Reference ellipsoids for UTM transformations.
void SetValidityInterval(const utl::TimeStamp &start, const utl::TimeStamp &stop)
Set the start and end validity times.
Definition: ValidityStamp.h:40
std::string fIdOfParentPhysicalEyeString
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
double GetFDASVetoFraction() const
TelescopeIterator TelescopesBegin() const
Beginning of the collection of telescopes.
Definition: FDetector/Eye.h:79
unsigned int fEyeId
const utl::TimeStamp & GetDecommissionTime() const
Telescope decommission time.
const Telescope & GetTelescope(const unsigned int telescopeId) const
Find Telescope by numerical Id.
bool IsValid() const
True if detector time is between start and end validity times.
const std::string & GetNameAbbr() const
double GetModelMinWavelength() const
boost::filter_iterator< TelIsCommissioned, InternalConstTelescopeIterator > TelescopeIterator
An iterator over telescopes.
Definition: FDetector/Eye.h:76
const utl::TimeInterval & GetSDTimeOffset() const
Time Offset of this eye with respect to SD.
Detector description interface for Telescope-related data.
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
double GetBackwallAngle() const
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
int GetDAQStatus() const
0 == not in DAQ
unsigned int GetLastTelescopeId() const
Last telescope id in the eye.
std::string fEyeIdString
TelescopeIterator TelescopesEnd() const
End of the collection of telescopes.
Definition: FDetector/Eye.h:83
FullTelescopeList fFullTelescopeList
std::set< unsigned int > GetParticipatingEyeIds() const
Returns a list of eye id&#39;s that participate in this (virtual) eye.
utl::TimeInterval * fSDTimeOffset
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
bool IsInAquisition() const
utl::Point GetPosition() const
Eye position.
const utl::TimeStamp & GetCommissionTime() const
Telescope commission time.
utl::TabulatedFunction * fTimeCorrectionFactors
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127
double GetModelMaxWavelength() const
const std::string & GetName() const
Eye name.
bool IsVirtual() const
Returns whether this eye is a virtual eye.
std::string * fNameAbbr
InternalTelescopeIterator FullTelescopesEnd()
Definition: FDetector/Eye.h:62

, generated on Tue Sep 26 2023.