RStationListManager.cc
Go to the documentation of this file.
1 #include <boost/format.hpp>
2 #include <boost/lexical_cast.hpp>
3 
4 #include <det/Detector.h>
5 
6 #include <rdet/RDetector.h>
7 #include <rdet/RStationListManager.h>
8 
9 #include <utl/UTCDateTime.h>
10 
11 using namespace rdet;
12 using namespace det;
13 using namespace std;
14 using namespace utl;
15 using namespace ::boost::multi_index;
16 
17 
18 namespace rdet {
19 
20 // specialization for "int"
21 template<>
24  const string& componentProperty,
25  const VManager::IndexMap& componentIndex)
26  const
27 {
28  const int id = GetStationId(componentIndex);
29  const StationIdIndex& idIndex = fStations.get<ByStationId>();
30  const StationIdIndex::const_iterator sIt = idIndex.find(id);
31 
32  if (sIt == idIndex.end())
33  return VManager::eNotFound;
34 
35  if (componentProperty == "inGrid")
36  returnData = sIt->fInGrid;
37  else if (componentProperty == "zone")
38  returnData = sIt->fZone;
39  else if (componentProperty == "nChannels")
40  returnData = sIt->fNChannels;
41  else if (componentProperty == "firstChannelId")
42  returnData = sIt->fFirstChannelId;
43  else if (componentProperty == "lastChannelId")
44  returnData = sIt->fLastChannelId;
45  else if (componentProperty == "virtual")
46  returnData = sIt->fIsVirtual;
47  else
48  return VManager::eNotFound;
49 
50  return VManager::eFound;
51 }
52 
53 
54 // specialization for "double"
55 template<>
57 RStationListManager::GetData(double& returnData,
58  const string& componentProperty,
59  const VManager::IndexMap& componentIndex)
60  const
61 {
62  const int id = GetStationId(componentIndex);
63  const StationIdIndex& idIndex = fStations.get<ByStationId>();
64  const StationIdIndex::const_iterator sIt = idIndex.find(id);
65 
66  if (sIt == idIndex.end())
67  return VManager::eNotFound;
68 
69  if (componentProperty == "northing")
70  returnData = sIt->fNorthing;
71  else if (componentProperty == "easting")
72  returnData = sIt->fEasting;
73  else if (componentProperty == "altitude")
74  returnData = sIt->fAltitude;
75  else
76  return VManager::eNotFound;
77 
78  return VManager::eFound;
79 }
80 
81 
82 // specialization for "string"
83 template<>
85 RStationListManager::GetData(string& returnData,
86  const string& componentProperty,
87  const VManager::IndexMap& componentIndex)
88  const
89 {
90  const int id = GetStationId(componentIndex);
91  const StationIdIndex& idIndex = fStations.get<ByStationId>();
92  const StationIdIndex::const_iterator sIt = idIndex.find(id);
93 
94  if (sIt == idIndex.end())
95  return VManager::eNotFound;
96 
97  if (componentProperty == "name")
98  returnData = sIt->fName;
99  else if (componentProperty == "commission")
100  returnData = sIt->fCommissionTime;
101  else if (componentProperty == "decommission")
102  returnData = sIt->fDecommissionTime;
103  else if (componentProperty == "band")
104  returnData = sIt->fBand;
105  else if (componentProperty == "ellipsoid")
106  returnData = sIt->fEllipsoid;
107  else if (componentProperty == "source")
108  returnData = sIt->fSource;
109  else
110  return VManager::eNotFound;
111 
112  return VManager::eFound;
113 }
114 
115 
116 // specialization for "vector<int>"
117 template<>
119 RStationListManager::GetData(vector<int>& returnData,
120  const string& componentProperty,
121  const VManager::IndexMap& /*componentIndex*/)
122  const
123 {
124  /* For the AugerPrime Radio Detector (RD), the station list is provided
125  by the SStationListManager (see RDetector.cc). Only if that is _not_
126  explicitly configured (i.e. !rDetector.AddStationListFromSManager())
127  return a eNotFound for an empty station list. */
128  if (fStations.empty() && !Detector::GetInstance().GetRDetector().AddStationListFromSManager())
129  return VManager::eNotFound;
130 
131  if (componentProperty == "fullStationList")
132  GetFullStationList(returnData);
133  else
134  return VManager::eNotFound;
135 
136  return VManager::eFound;
137 }
138 
139 
140 // specialization for "vector<vector<int> >"
141 template<>
143 RStationListManager::GetData(vector<vector<int> >& /*returnData*/,
144  const string& /*componentProperty*/,
145  const VManager::IndexMap&)
146  const
147 {
148  if (fStations.empty())
149  return VManager::eNotFound;
150 
151  return VManager::eFound;
152 }
153 
154 
155 bool
157 {
158  if (HasStationData(station.fId))
159  return false;
160 
161  const TimeStamp commission =
162  boost::lexical_cast<UTCDateTime>(station.fCommissionTime).GetTimeStamp();
163  const TimeStamp decommission =
164  boost::lexical_cast<UTCDateTime>(station.fDecommissionTime).GetTimeStamp();
165  station.fCommissionTimeRange = TimeRange(commission, decommission);
166  fStations.insert(station);
167  return true;
168 }
169 
170 
171 void
173 {
174  const TimeStamp commission =
175  boost::lexical_cast<UTCDateTime>(station.fCommissionTime).GetTimeStamp();
176  const TimeStamp decommission =
177  boost::lexical_cast<UTCDateTime>(station.fDecommissionTime).GetTimeStamp();
178  station.fCommissionTimeRange = TimeRange(commission, decommission);
179 
180  if (HasStationData(station.fId)) {
181  // if station already exists, find and replace
182  StationIdIndex& station_by_id = fStations.get<ByStationId>();
183  StationIdIndex::iterator station_to_be_replaced = station_by_id.find(station.fId);
184  station_by_id.replace(station_to_be_replaced, station);
185  } else {
186  fStations.insert(station);
187  }
188 }
189 
190 
191 void
192 RStationListManager::ClearStations(const std::string source_type)
193 {
194  std::vector<int> remove_station_ids;
195  for (auto& station : fStations) {
196  if (station.fSource == source_type)
197  remove_station_ids.push_back(station.fId);
198  }
199 
200  for (auto& id : remove_station_ids)
201  fStations.erase(id);
202 }
203 
204 
205 
206 bool
208 {
209  if (HasStationData(station.fId)) {
210  // if station already exists, find and replace
211  StationIdIndex& station_by_id = fStations.get<ByStationId>();
212  StationIdIndex::iterator station_to_be_removed = station_by_id.find(station.fId);
213  station_by_id.erase(station_to_be_removed);
214  return true;
215  } else {
216  return false;
217  }
218 }
219 
220 
221 bool
223  const
224 {
225  const StationIdIndex& idIndex = fStations.get<ByStationId>();
226  return idIndex.find(id) != idIndex.end();
227 }
228 
229 
230 void
232  const
233 {
234  returnList.clear();
235  const StationIdIndex& idIndex = fStations.get<ByStationId>();
236  for (StationIdIndex::const_iterator sIt = idIndex.begin(); sIt != idIndex.end(); ++sIt)
237  returnList.push_back(sIt->fId);
238 }
239 
240 
241 
242 string
243 StringToXMLString(const string& str)
244 {
245  ostringstream res;
246 
247  for (string::const_iterator it = str.begin(); it != str.end(); ++it)
248  switch (*it) {
249  // replace '&' with "&amp;"
250  case '&':
251  res << "and";
252  break;
253  default:
254  res << *it;
255  }
256 
257  return res.str();
258 }
259 
260 
261 bool
262 RStationListManager::DumpXML(ostream& output, const string& indent)
263  const
264 {
265  if (fStations.empty())
266  return false;
267 
268  boost::format stationFmt(
269  "%1%<station id=\"%2%\">\n"
270  "%1% <northing unit=\"meter\"> %|3$.2f| </northing>\n"
271  "%1% <easting unit=\"meter\"> %|4$.2f| </easting>\n"
272  "%1% <altitude unit=\"meter\"> %|5$.2f| </altitude>\n"
273  "%1% <name> %6% </name>\n"
274  "%1% <commission> %7% </commission>\n"
275  "%1% <decommission> %8% </decommission>\n"
276  "%1% <inGrid> %9% </inGrid>\n"
277  "%1% <ellipsoid> %13% </ellipsoid>\n"
278  "%1% <zone> %14% </zone>\n"
279  "%1% <band> %15% </band>\n"
280  "%1%</station>\n"
281  );
282 
283  const StationIdIndex& sIndex = fStations.get<ByStationId>();
284  for (StationIdIndex::const_iterator sIt = sIndex.begin();
285  sIt != sIndex.end(); ++sIt)
286  output
287  << stationFmt
288  % indent
289  % sIt->fId
290  % sIt->fNorthing
291  % sIt->fEasting
292  % sIt->fAltitude
293  % StringToXMLString(sIt->fName)
294  % sIt->fCommissionTime
295  % sIt->fDecommissionTime
296  % sIt->fInGrid
297  % sIt->fEllipsoid
298  % sIt->fZone
299  % sIt->fBand
300  << '\n';
301 
302  return true;
303 }
304 
305 }
string StringToXMLString(const string &str)
bool ConditionalAddStationData(StationData &station)
adds station record only if it does not already exist
bool RemoveStationData(StationData &station)
Removes station data if manager has station.
Time interval defined by two TimeStamps.
Definition: TimeRange.h:23
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
det::VManager::Status GetData(T &returnData, const std::string &componentProperty, const det::VManager::IndexMap &componentIndex) const
bool DumpXML(std::ostream &output, const std::string &indent="") const
void GetFullStationList(std::vector< int > &returnList) const
bool HasStationData(const int id) const
index< StationContainer, ByStationId >::type StationIdIndex
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
void ClearStations(const std::string source_type)
Removes all stations from fStations with fSource == source_type.
void AddOrReplaceStationData(StationData &station)
adds station record and might overright old entry
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.