FTelescopeListXMLManager.cc
Go to the documentation of this file.
1 #include <fdet/FTelescopeListXMLManager.h>
2 
3 #include <fwk/CentralConfig.h>
4 #include <utl/ErrorLogger.h>
5 #include <utl/Reader.h>
6 #include <fdet/FManagerRegister.h>
7 
8 using namespace std;
9 using namespace fdet;
10 using namespace fwk;
11 using namespace utl;
12 using namespace det;
13 
14 
15 REGISTER_F_MANAGER("FTelescopeListXMLManager", FTelescopeListXMLManager)
16 
17 
19 {
20 }
21 
22 /*********************************************************************/
23 // Generic data getters
24 //---------------------
25 template<typename T>
27 FTelescopeListXMLManager::GetTelescopeListData(T& returnData,
28  const string& componentProperty,
29  const string& componentName,
30  const IndexMap& componentIndex)
31  const
32 {
33  // For this manager, there are three cases to consider:
34  // 0) no index has been provided --> requests for overall properties
35  // 1) One index has been provided, specifying just the eye. In this case, we
36  // search for data unique to an eye (name, position, coordinate system)
37  // 2) Two indices have been provided, one for the eye and one for the telescope.
38  // In this case, we search for data unique to a telescope (orientation, position, commission time, etc)
39  // Note that any conversion of the telescope orientation into the frame of the eye
40  // will be done in the Eye interface class.
41 
42  if (componentIndex.empty()) {
43  Branch propertyB = fBranch.GetChild(componentProperty);
44  if (!propertyB)
45  return eNotFound;
46 
47  propertyB.GetData(returnData);
48  return eFound;
49  }
50  else if (componentIndex.size() == 1) {
51  return GetEyeData(returnData, componentProperty,
52  componentName, componentIndex);
53  }
54  else if (componentIndex.size() == 2) {
55  return GetTelescopeData(returnData, componentProperty,
56  componentName, componentIndex);
57  }
58  else {
59  if (IsReportingErrors()) {
60  INFO(string("More than three indices found; ") +
61  QueryInfoMessage(componentProperty, componentName, componentIndex));
62  }
63  return eNotFound;
64  }
65 
66  return eNotFound; // never reached.
67 }
68 
69 
70 /*********************************************************************/
71 // Getter for eye-level data
72 template<typename T>
74 FTelescopeListXMLManager::GetEyeData(T& returnData,
75  const string& componentProperty,
76  const string& componentName,
77  const IndexMap& componentIndex)
78  const
79 {
80  const IndexMap::const_iterator it = componentIndex.find("eyeId");
81  if (it == componentIndex.end()) {
82  INFO(string("Only one index found and it is not 'eyeId'; ") +
83  QueryInfoMessage(componentProperty, componentName, componentIndex));
84  return eNotFound;
85  }
86 
87  if (componentName != "eye"
88  && componentName != "virtualEye") {
89  return eNotFound;
90  }
91  const bool isVirtual = componentName == "virtualEye";
92 
93  IndexMap atts;
94  atts["id"] = it->second;
95 
96  Branch eyeB = fBranch.GetChild(componentName, atts);
97  if (!eyeB) {
98  // If we're looking for the parent eye for a virtual eye,
99  // we short circuit the manager loop by claiming that we found the
100  // information.
101  if (isVirtual && componentProperty == "parentEye")
102  return eFound;
103 
104  // The name is available from virtual eyes as well!
105  if (componentProperty == "name")
106  eyeB = fBranch.GetChild("virtualEye", atts);
107 
108  if (!eyeB)
109  return eNotFound;
110  }
111 
112  Branch propertyB = eyeB.GetChild(componentProperty);
113  if (!propertyB)
114  return eNotFound;
115 
116  propertyB.GetData(returnData);
117 
118  return eFound;
119 }
120 
121 
122 /*********************************************************************/
123 // Getter for telescope-level data
124 template<typename T>
126 FTelescopeListXMLManager::GetTelescopeData(T& returnData,
127  const string& componentProperty,
128  const string& componentName,
129  const IndexMap& componentIndex)
130  const
131 {
132  // First validate the componentIndex
133  const IndexMap::const_iterator eIt = componentIndex.find("eyeId");
134  if (eIt == componentIndex.end()) {
135  INFO(string("Two indices found, neither of them is 'eyeId'; ") +
136  QueryInfoMessage(componentProperty, componentName, componentIndex));
137  return eNotFound;
138  }
139 
140  const IndexMap::const_iterator tIt = componentIndex.find("telescopeId");
141  if (tIt == componentIndex.end()) {
142  INFO(string("Two indices found, neither of them is 'telescopeId'; ") +
143  QueryInfoMessage(componentProperty, componentName, componentIndex));
144  return eNotFound;
145  }
146 
147  // validate componentName
148  const bool isVirtual = componentName == "virtualTelescope";
149  if (componentName != "telescope" && !isVirtual) {
150  return eNotFound;
151  }
152 
153  // the "pointing" property is just a fallback solution,
154  // we have to redirect it to "defaultPointing"
155  const string componentPropertyReal = (componentProperty == "pointing")
156  ? "defaultPointing"
157  : componentProperty;
158 
159  IndexMap atts;
160  atts["id"] = eIt->second;
161  Branch eyeB = fBranch.GetChild((isVirtual ? "virtualEye" : "eye"), atts);
162  if (!eyeB) {
163  // If we're looking for the from* info for a virtual tel,
164  // we short circuit the manager loop by claiming that we found the
165  // information.
166  if (isVirtual
167  && (componentProperty == "fromEye"
168  || componentProperty == "fromTelescope")) {
169  return eFound;
170  }
171 
172  return eNotFound;
173  }
174 
175  atts["id"] = tIt->second;
176  Branch telescopeB = eyeB.GetChild("telescopes").GetChild("telescope", atts);
177  if (!telescopeB)
178  return eNotFound;
179 
180  Branch propertyB = telescopeB.GetChild(componentPropertyReal);
181  if (!propertyB)
182  return eNotFound;
183 
184  propertyB.GetData(returnData);
185 
186  return eFound;
187 }
188 
189 
190 /*********************************************************************/
191 // Special Getter for list of all Eye Id's and Telescope Id's present
192 // in the XML file.
194 FTelescopeListXMLManager::GetFullEyeTelescopeList(list<int>& returnList,
195  const string& componentProperty,
196  const string& componentName,
197  const IndexMap& componentIndex)
198  const
199 {
200  // There are two possible requests indicated by the componentProperty:
201  // 1) eyeList : request for all eyes present in the XML file
202  // 2) telescopeList : request for all telescopes present in the XML file
203 
204  if (componentProperty == "eyeList") {
205 
206  Branch topB = fBranch;
207  for (Branch cb = topB.GetFirstChild(); cb; cb = cb.GetNextSibling()) {
208  if (cb.GetName() == "eye"
209  || cb.GetName() == "virtualEye") {
210  istringstream is(cb.GetAttributes().find("id")->second);
211  int id;
212  is >> id;
213  returnList.push_back(id);
214  }
215  }
216 
217  }
218  else if (componentProperty == "telescopeList") {
219 
220  // There must be an index indicating which eye we are interested in
221  if (componentIndex.size() != 1) {
222  INFO(string("Invalid number of indices specified "
223  "in request for 'telescopeList'; ") +
224  QueryInfoMessage(componentProperty, componentName, componentIndex));
225  return eNotFound;
226  }
227 
228  // The supplied index element must be 'eyeId'
229  const IndexMap::const_iterator eIt = componentIndex.find("eyeId");
230  if (eIt == componentIndex.end()) {
231  INFO(string("Invalid indices for retrieving 'telescopeList'; ") +
232  QueryInfoMessage(componentProperty, componentName, componentIndex));
233  return eNotFound;
234  }
235 
236  Branch topB = fBranch;
237 
238  IndexMap eyeAtts;
239  eyeAtts["id"] = eIt->second;
240  Branch eyeB = topB.GetChild("eye", eyeAtts);
241  // If this fails, check for a virtual eye, too
242  if (!eyeB)
243  eyeB = topB.GetChild("virtualEye", eyeAtts);
244 
245  if (!eyeB) {
246  ostringstream info;
247  info << "Could not find requested eye in XML file: " << eIt->second;
248  INFO(info);
249  return eNotFound;
250  }
251 
252  // Loop on all telescopes and put them in the list
253  for (Branch telescopeB = eyeB.GetChild("telescopes").GetFirstChild();
254  telescopeB; telescopeB = telescopeB.GetNextSibling())
255  {
256  const IndexMap telescopeAtts = telescopeB.GetAttributes();
257  istringstream is(telescopeAtts.find("id")->second);
258  int telescopeId;
259  is >> telescopeId;
260  returnList.push_back(telescopeId);
261 
262  }
263 
264  } // end if componentProperty == telescopeList
265  else {
266  INFO(string("Could not interpret the request with ") +
267  QueryInfoMessage(componentProperty, componentName, componentIndex));
268  return eNotFound;
269  }
270 
271  return eFound;
272 }
273 
274 
275 /*********************************************************************/
277 FTelescopeListXMLManager::GetTelescopePointingData(std::map<std::string, double>& returnData,
278  const string& componentProperty,
279  const string& componentName,
280  const IndexMap& componentIndex)
281  const
282 {
283  if (componentIndex.size() != 2)
284  return eNotFound;
285 
286  if (componentProperty != string("opticalAxisPhi")
287  && componentProperty != string("opticalAxisElevation")) {
288  return eNotFound;
289  }
290 
291  // First find the requested eye
292  const IndexMap::const_iterator eIt = componentIndex.find("eyeId");
293 
294  if (eIt == componentIndex.end()) {
295  INFO(string("No 'eyeId' in componentIndex; ") +
296  QueryInfoMessage(componentProperty, componentName, componentIndex));
297  return eNotFound;
298  }
299 
300  IndexMap atts;
301  atts["id"] = eIt->second;
302  Branch eyeB = fBranch.GetChild("eye", atts);
303  if (!eyeB)
304  return eNotFound;
305 
306  // Next, find the requested telescope for the given eye
307  const IndexMap::const_iterator tIt = componentIndex.find("telescopeId");
308 
309  if (tIt == componentIndex.end()) {
310  INFO(string("Two indices found, neither of them is 'telescopeId'; ") +
311  QueryInfoMessage(componentProperty, componentName, componentIndex));
312  return eNotFound;
313  }
314 
315  atts["id"] = tIt->second;
316  Branch telescopeB = eyeB.GetChild("telescopes").GetChild("telescope", atts);
317  if (!telescopeB)
318  return eNotFound;
319 
320  Branch pointingsB = telescopeB.GetChild(string("pointings"));
321 
322  Branch pointingB = pointingsB.GetFirstChild();
323  while (pointingB) {
324  AttributeMap attrs = pointingB.GetAttributes();
325  const std::string pointingId = attrs.find(string("id"))->second;
326  double angle;
327  pointingB.GetChild(componentProperty).GetData(angle);
328  returnData[pointingId] = angle;
329  pointingB = pointingB.GetNextSibling();
330  }
331 
332  return eFound;
333 }
334 
335 
336 /*********************************************************************/
338 FTelescopeListXMLManager::GetData(utl::TabulatedFunction& returnData,
339  const std::string& componentProperty,
340  const std::string& componentName,
341  const IndexMap& componentIndex)
342  const
343 {
344  if (componentProperty == "relativeResponse") {
345 
346  vector<double> wavelength;
347  Status s =
348  GetTelescopeListData(wavelength, "relativeResponseLambda",
349  componentName, componentIndex);
350 
351  if (s != eFound)
352  return s;
353 
354  vector<double> value;
355  s = GetTelescopeListData(value, "relativeResponseValue",
356  componentName, componentIndex);
357 
358  if (s != eFound)
359  return s;
360 
361  returnData = TabulatedFunction(wavelength, value);
362 
363  return VManager::eFound;
364 
365  } else if (componentProperty == "MHzTimeCorrection") {
366 
367  vector<double> correctionFactors;
368  Status s =
369  GetTelescopeListData(correctionFactors, "MHzCorrectionFactors",
370  componentName, componentIndex);
371  if (s != eFound)
372  return s;
373 
374  vector<double> months;
375  s = GetTelescopeListData(months, "MHzCorrectionTimes",
376  componentName, componentIndex);
377  if (s != eFound)
378  return s;
379 
380  returnData = TabulatedFunction(months, correctionFactors);
381  return eFound;
382 
383  } else
384  return eNotFound;
385 }
Class to hold collection (x,y) points and provide interpolation between them.
bool is(const double a, const double b)
Definition: testlib.cc:113
std::map< std::string, std::string > AttributeMap
Definition: Branch.h:24
#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
AttributeMap GetAttributes() const
Get a map&lt;string, string&gt; containing all the attributes of this Branch.
Definition: Branch.cc:267
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
Class representing a document branch.
Definition: Branch.h:107
constexpr double s
Definition: AugerUnits.h:163
Reads data from XML file(s) containing data unique to telescopes and eyes (eg. positions, orientations, commission times, and so forth).
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
#define REGISTER_F_MANAGER(_name_, _Type_)
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.