RDetector.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <limits>
4 
5 #include <det/VManager.h>
6 #include <det/Detector.h>
7 
8 #include <rdet/RDetector.h>
9 // #include <rdet/Station.h>
10 
11 #include <revt/Station.h>
12 
13 #include <utl/ErrorLogger.h>
14 #include <utl/TimeStamp.h>
15 #include <utl/UTCDateTime.h>
16 #include <utl/UTMPoint.h>
17 
18 #include <TMath.h>
19 
20 
21 using namespace rdet;
22 using namespace std;
23 using namespace det;
24 using namespace utl;
25 using TMath::Na;
26 
27 
29 {
30  for (const auto& is : fFullStationMap)
31  delete is.second;
32  for (const auto& nr : fHardwareResponseProfileMap)
33  delete nr.second;
34 }
35 
36 
37 void
39 {
40  // This would be smart but does not work:
41  //const TimeStamp dTime = Detector::GetInstance().GetTime();
42  /*
43  if (! fFullStationList.IsValid()) {
44  for (vector<int>::const_iterator it = GetFullStationList().begin();
45  it != GetFullStationList().end() ; ++it) {
46  const int id = *it;
47  Station* const station = new Station(id);
48  fFullStationMap[id] = station;
49  }
50  } else {
51  fFullStationMap.begin()->second->Update();
52  }
53  */
54 
55  // This is not smart but does work!
56 
57  // fFullStationList contains station ids
58  // fFullStationMap contains stations
59 
60  if (fFullStationList.IsValid()) {
61  for (const auto& is : fFullStationMap)
62  delete is.second;
63  fFullStationList.SetValid(false);
64  }
65 
66  fFullStationMap.clear();
67  for (const auto id : GetFullStationList()) {
68  fFullStationMap[id] = new Station(id);
69  }
70 }
71 
72 
83 const vector<int>&
85  const
86 {
87  if (!fFullStationList.IsValid()) {
88  fFullStationList.Get().clear();
89  VManager::IndexMap indexMap;
90 
91  const VManager& manager = Detector::GetInstance().GetRManagerRegister();
92  VManager::Status status =
93  manager.GetData(fFullStationList.Get(), "fullStationList", "stationList", indexMap);
94 
95  // Release a Error only if no station ids are added from the SManagers.
96  if (!AddStationListFromSManager()) {
97  if (status == VManager::eNotFound) {
98  ostringstream err;
99  err << "Could not get a list of station ID's from RManagers. "
100  "No AERA station information will be available!";
101  ERROR(err);
102  }
103  }
104 
105  if (AddStationListFromSManager()) {
106  std::vector<int> additionalRDStationIdsFromSManager;
107  additionalRDStationIdsFromSManager.clear();
108 
109  const VManager& smanager = Detector::GetInstance().GetSManagerRegister();
110  status = smanager.GetData(additionalRDStationIdsFromSManager, "fullStationList", "stationList", indexMap);
111 
112  if (status == VManager::eNotFound) {
113  ostringstream err;
114  err << "Could not get a list of station ID's from SManagers. "
115  "No RD station information will be available!";
116  ERROR(err);
117  }
118 
119  if (!additionalRDStationIdsFromSManager.empty()) {
120  for (const auto id : additionalRDStationIdsFromSManager)
121  fFullStationList.Get().push_back(id + fRdSdStationIdLink); // here linking SD to RD stations
122  }
123  }
124 
125  fFullStationList.SetValid();
126  }
127 
128  return fFullStationList.Get();
129 }
130 
131 
132 const Station&
134  const
135 {
136  return GetStation(station.GetId());
137 }
138 
139 
140 const Station&
142  const
143 {
144  const InternalStationIterator it = fFullStationMap.find(id);
145 
146  if (it != fFullStationMap.end() &&
147  it->second->GetCommissionTimeRange() == Detector::GetInstance().GetTime())
148  return *it->second;
149 
150  ostringstream err;
151  err << "Station with Id = " << id << " is not available at "
152  "detector time = " << Detector::GetInstance().GetTime()
153  << " or detector description was not properly configured. "
154  << "If station ID is larger than " << fRdSdStationIdLink << ", "
155  << "check if RModelsXMLManager and RHardwareProfileXMLManager are "
156  << "and configured.";
157  ERROR(err);
158  throw utl::NonExistentComponentException(err.str());
159 }
160 
161 
164 RDetector::GetHardwareResponseProfile(const std::string& responseId)
165  const
166 {
167  const HardwareResponseProfileMap::const_iterator it =
168  fHardwareResponseProfileMap.find(responseId);
169 
170  if (it != fHardwareResponseProfileMap.end())
171  return *it->second;
172 
174  GetDetectorData(rResponse, "Response", responseId, "Response");
175  fHardwareResponseProfileMap[responseId] = rResponse;
176 
177  return *rResponse;
178 }
179 
180 
182 const std::vector<double>&
184  const
185 {
186  if (fBeaconFreq) {
187  delete fBeaconFreq;
188  fBeaconFreq = nullptr;
189  }
190  GetDetectorData(fBeaconFreq, "BeaconFreq", "BeaconFreq", "BeaconFrequencies");
191  return *fBeaconFreq;
192 }
193 
194 
196 double
197 RDetector::GetBeaconReferencePhase(const int stationId, const double beaconFreq)
198  const
199 {
200  if (fBeaconReferencePhase) {
201  delete fBeaconReferencePhase;
202  fBeaconReferencePhase = nullptr;
203  }
204  VManager::IndexMap indexMap;
205  indexMap["RStationId"] = boost::lexical_cast<string>(stationId);
206  //boost::lexical_cast<string>(double) returns full double presentation of value, i.e. not rounded
207  //e.g. 0.061523000000000001 instead of 0.061523
208  //lexical_cast is supposed to be faster than the explicit stringstream
209  //string to_string(double) is only C++11
210  indexMap["BeaconFreq"] = boost::lexical_cast<string>(beaconFreq);
211  GetDetectorData(fBeaconReferencePhase, "BeaconRefPhase", "BeaconRefPhase", "BeaconFrequenciesReferencePhases", indexMap);
212  return *fBeaconReferencePhase;
213 }
214 
215 
216 unsigned long long int
217 RDetector::GetBadStationReason(const int stationId)
218  const
219 {
220  unsigned long long int res = 0;
221  const det::ManagerRegister& m = det::Detector::GetInstance().GetRManagerRegister();
222  m.GetDataOrThrow(res, "BadStation", boost::lexical_cast<string>(stationId));
223  return res << 15;
224 
225  /*union I2LL {
226  int fI[2];
227  unsigned long long int fLL;
228  };
229  static vector<int>* iiReason;
230  if (iiReason) {
231  delete iiReason;
232  iiReason = nullptr;
233  }
234  GetDetectorData(iiReason, "BadStation", boost::lexical_cast<string>(stationId) , "");
235  I2LL reason;
236  for (unsigned int i = 0; i < 2; ++i)
237  reason.fI[i] = iiReason->at(i);
238  return reason.fLL << 32;*/
239  /*static unsigned long long int* reason;
240  if (reason) {
241  delete reason;
242  reason = nullptr;
243  }
244  GetDetectorData(reason, "BadStation", boost::lexical_cast<string>(stationId) , "");
245  return *reason << 32; // in Offline the reasons from the database start at bit 32*/
246 }
247 
248 
249 double
250 RDetector::GetTemperature(const std::string& site)
251  const
252 {
253  static double* temperature;
254  if (temperature) {
255  delete temperature;
256  temperature = nullptr;
257  }
258  const VManager::IndexMap indexMap({{ "site", site }});
259  GetDetectorData(temperature, "monitoring", "temperature", "", indexMap);
260  return *temperature + 273.15; // conversion to Kelvin as temperature is stored in degree celsius in DB
261 }
262 
263 
264 bool
266  const
267 {
268  if (!fAddStationListFromSManager.IsValid()) {
269  const det::ManagerRegister& managerRRegister = det::Detector::GetInstance().GetRManagerRegister();
270 
271  // if no radio manager is registered return 0 anyway.
272  if (managerRRegister.ManagersBegin() == managerRRegister.ManagersEnd()) {
273  fAddStationListFromSManager = false;
274  }
275  else {
276  int addStations;
277  det::VManager::IndexMap indexMap;
278 
279  const det::VManager::Status foundFlag =
280  managerRRegister.GetData(addStations, "addSStationList", "", indexMap);
281 
282  if (foundFlag == det::VManager::eNotFound) {
283  ERROR("Did not find requested component: addSStationList (Flag to add station Ids from SManager to RDetector.)");
284  throw utl::NonExistentComponentException("Did not find requested component:"
285  "addSStationList (Flag to add station Ids from SManager to RDetector.)");
286  }
287  if (addStations == 1)
288  fAddStationListFromSManager = true;
289  else
290  fAddStationListFromSManager = false;
291  }
292 
293  fAddStationListFromSManager.SetValid();
294  }
295  return fAddStationListFromSManager.Get();
296 }
double GetTemperature(const std::string &site) const
Definition: RDetector.cc:250
double GetBeaconReferencePhase(const int stationId, const double beaconFreq) const
Get beacon reference phases for one station.
Definition: RDetector.cc:197
Detector description interface for Station-related data.
Status GetDataOrThrow(T &returnData, const std::string &component, const std::string &property, const IndexMap &index=IndexMap()) const
bool is(const double a, const double b)
Definition: testlib.cc:113
const std::vector< int > & GetFullStationList() const
Get list of ID&#39;s for all stations available in the database or configuration file.
Definition: RDetector.cc:84
ManagerIterator ManagersBegin() const
Iterator pointing to first available manager.
Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const
Base class for exceptions trying to access non-existing components.
InternalStationMap::const_iterator InternalStationIterator
Definition: RDetector.h:50
Interface for detector managers.
Definition: VManager.h:115
unsigned long long int GetBadStationReason(const int stationId) const
Definition: RDetector.cc:217
const std::vector< double > & GetBeaconFrequencies() const
Get vector of Beacon Frequencies for given detector-time from Manager.
Definition: RDetector.cc:183
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
class to hold data at the radio Station level.
const utl::TabulatedFunctionComplexLgAmpPhase & GetHardwareResponseProfile(const std::string &identifier) const
Get the response (TabulatedFunctionComplexLgAmpPhase) which corresponds to a hardware profile identif...
Definition: RDetector.cc:164
Class to hold collection (x,y) points and provide interpolation between them, where y are complex num...
int GetId() const
Get the station Id.
bool AddStationListFromSManager() const
Definition: RDetector.cc:265
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
Register for detector description managers.
ManagerIterator ManagersEnd() const
Iterator pointing one past the last available manager.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
constexpr double m
Definition: AugerUnits.h:121
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.