CDetector.cc
Go to the documentation of this file.
1 
3 #include <boost/format.hpp>
4 #include <boost/lexical_cast.hpp>
5 
6 #include <det/Detector.h>
7 #include <cdet/CDetector.h>
8 #include <cdet/Station.h>
9 #include <det/VManager.h>
10 #include <utl/ErrorLogger.h>
11 #include <utl/AugerException.h>
12 #include <utl/TimeStamp.h>
13 
14 #include <cevt/Station.h>
15 
16 using boost::format;
17 using namespace std;
18 using namespace cdet;
19 using namespace det;
20 using namespace utl;
21 
22 
23 CDetector::~CDetector()
24 {
25  for (InternalStationIterator it = fFullStationMap.begin();
26  it != fFullStationMap.end(); ++it)
27  delete it->second;
28 }
29 
30 
31 void
32 CDetector::UpdateDense()
33 {
34  Update();
35 
36  for (vector<int>::iterator it = fDenseStationSubList.begin(), end = fDenseStationSubList.end();
37  it != end; ++it)
38  Detector::GetInstance().GetCDetector().GetStation(*it).Update();
39 }
40 
41 
42 void
44 {
45  // Set the full station map and pairs first time the detector is updated.
46 
47  if (!fFullStationList.IsValid()) {
48 
49  const vector<int>& sl = GetFullStationList();
50 
51  for (vector<int>::const_iterator it = sl.begin(), end = sl.end();
52  it != end; ++it) {
53  const int id = *it;
54  Station* const station = new Station(id);
55 
56  // flag dense stations (if any)
57  const vector<int>::const_iterator denseIt =
58  find(fDenseStationSubList.begin(), fDenseStationSubList.end(), id);
59  if (denseIt != fDenseStationSubList.end()) {
60  station->fDense = true;
61  station->fInGrid = 0;
62  }
63 
64  fFullStationMap[id] = station;
65  }
66 
67  FetchStationGroups();
68 
69  }
70 
71  const TimeStamp dTime = Detector::GetInstance().GetTime();
72 
73  fCommissionedStationList.clear();
74 
75  // add the stations into the commissioned station list depending on the time
76  // and update them
77  for (InternalStationIterator it = fFullStationMap.begin(), end = fFullStationMap.end();
78  it != end; ++it) {
79 
80  const Station* const station = it->second;
81 
82  if (station->GetCommissionTimeRange() == dTime) {
83  station->Update();
84  fCommissionedStationList[it->first] = station;
85  }
86  }
87 }
88 
89 
100 const vector<int>&
101 CDetector::GetFullStationList()
102  const
103 {
104  if (!fFullStationList.IsValid()) {
105 
106  const VManager& manager = Detector::GetInstance().GetCManagerRegister();
107 
108  fFullStationList.Get().clear();
109 
110  VManager::IndexMap indexMap;
111  VManager::Status status =
112  manager.GetData(fFullStationList.Get(), "fullStationList", "stationList", indexMap);
113 
114  if (status == VManager::eNotFound) {
115  ostringstream err;
116  err << "Could not find a list of SD Station ID's. "
117  "No station information will be available!";
118  DEBUGLOG(err);
119  }
120 
121  fFullStationList.SetValid();
122 
123  // check for dense stations
124  // (this is done separately, as there is a different convention for
125  // specifying their positions.)
126 
127  // Use SManager for dense station list
128  const VManager& smanager = Detector::GetInstance().GetSManagerRegister();
129 
130  fDenseStationSubList.clear();
131  indexMap["reportErrors"] = "0";
132  status =
133  smanager.GetData(fDenseStationSubList, "denseStationList", "stationList", indexMap);
134 
135 
136  if (status == VManager::eFound && !fDenseStationSubList.empty()) {
137  INFO("Using dense stations.");
138  fFullStationList.Get().insert(fFullStationList.Get().end(),
139  fDenseStationSubList.begin(),
140  fDenseStationSubList.end());
141  }
142 
143  }
144 
145  return fFullStationList.Get();
146 }
147 
148 
149 void
150 CDetector::FetchStationGroups()
151  const
152 {
153  const VManager& manager = Detector::GetInstance().GetCManagerRegister();
154 
155  VManager::IndexMap indexMap;
156  vector<int> stationGroupIds;
157  const VManager::Status status =
158  manager.GetData(stationGroupIds, "groupIds", "stationList", indexMap);
159 
160  if (status == VManager::eNotFound) {
161  WARNING("Could not find a list of SD Station groups ids.");
162  return;
163  }
164 
165  fStationGroups.clear();
166 
167  vector<int> groupVec;
168  set<int> groupSet;
169  for (vector<int>::const_iterator gIt = stationGroupIds.begin(), end = stationGroupIds.end();
170  gIt != end; ++gIt) {
171  groupVec.clear();
172  indexMap["groupId"] = boost::lexical_cast<string>(*gIt);
173  manager.GetData(groupVec, "group", "stationList", indexMap);
174  if (groupVec.empty())
175  continue;
176  groupSet.clear();
177  groupSet.insert(groupVec.begin(), groupVec.end());
178  fStationGroups.insert(make_pair(*gIt, groupSet));
179  }
180 }
181 
182 
183 const Station&
184 CDetector::GetStation(const cevt::Station& station)
185  const
186 {
187  return GetStation(station.GetId());
188 }
189 
190 
191 const Station&
192 CDetector::GetStation(const int id)
193  const
194 {
195  {
196  const InternalStationIterator it = fCommissionedStationList.find(id);
197 
198  if (it != fCommissionedStationList.end())
199  return *it->second;
200  }
201 
202  // Handle special cases.
203  // 1) Dense stations. These stations are not in the commissioned station list.
204  // 2) Stations which come from some other station list manager and are
205  // hence not in the commissioned station list.
206 
207  // Special case of dense stations
208  {
209  const InternalStationIterator it = fFullStationMap.find(id);
210  if (it != fFullStationMap.end()) {
211  const Station* const station = it->second;
212  if (station->IsDense())
213  return *station;
214  }
215  }
216 
217  if (!fFullStationList.IsValid())
218  GetFullStationList();
219 
220  const vector<int>::const_iterator it =
221  find(fFullStationList.Get().begin(), fFullStationList.Get().end(), id);
222 
223  // Other special managers
224  if (it == fFullStationList.Get().end()) {
225 
226  const Detector& detector = Detector::GetInstance();
227  const VManager& manager = detector.GetCManagerRegister();
228 
229  VManager::IndexMap indexMap;
230  indexMap["stationId"] = boost::lexical_cast<string>(id);
231 
232  string stationName;
233  const bool hasName =
234  manager.GetData(stationName, "name", "stationList", indexMap) == VManager::eFound;
235  double dummy;
236  const bool hasNorthing =
237  manager.GetData(dummy, "northing", "stationList", indexMap) == VManager::eFound;
238  const bool hasEasting =
239  manager.GetData(dummy, "easting", "stationList", indexMap) == VManager::eFound;
240  const bool hasAltitude =
241  manager.GetData(dummy, "altitude", "stationList", indexMap) == VManager::eFound;
242 
243  if (hasName && hasNorthing && hasEasting && hasAltitude) {
244 
245  Station* const station = new Station(id);
246  fFullStationList.Get().push_back(id);
247  const pair<int, const Station*> idStation(id, station);
248  fFullStationMap.insert(idStation);
249 
250  ostringstream warn;
251  warn << "Station " << format("%4d") % id << " was not in the station list. "
252  "It is being added individually.";
253  WARNING(warn);
254 
255  // now that we are at it, check if it's commissioned
256  const TimeStamp dTime = detector.GetTime();
257  if (station->GetCommissionTimeRange() == dTime) {
258  station->Update();
259  fCommissionedStationList.insert(idStation);
260  return *station;
261  }
262 
263  } else {
264 
265  ostringstream err;
266  err << "No station with Id = " << id << " was found. At least the following information is missing:"
267  << (hasName ? "" : " name")
268  << (hasNorthing ? "" : " northing")
269  << (hasEasting ? "" : " easting")
270  << (hasAltitude ? "" : " altitude")
271  << ". Do you have some station position manager registered in CManagerRegister?";
272  throw NonExistentComponentException(err.str());
273  }
274 
275  }
276 
277  // individual addition ends here
278 
279  ostringstream err;
280  err << "Station with Id = " << id << " is not commissioned at "
281  "detector time = " << Detector::GetInstance().GetTime()
282  << " or else detector description was not properly configured";
283  throw NonExistentComponentException(err.str());
284 }
285 
286 
287 const Station&
288 CDetector::GetAllStation(const int id)
289  const
290 {
291  const InternalStationIterator it = fFullStationMap.find(id);
292  if (it != fFullStationMap.end())
293  return *it->second;
294 
295  ostringstream err;
296  err << "Station with Id = " << id << " is not fund in the list of all stations.";
297  throw NonExistentComponentException(err.str());
298 }
299 
300 
301 // Configure (x)emacs for this file ...
302 // Local Variables:
303 // mode: c++
304 // End:
InternalStationMap::const_iterator InternalStationIterator
Definition: CDetector.h:44
const utl::TimeRange & GetCommissionTimeRange() const
Station commission time range.
utl::TimeStamp GetTime() const
Get time pertaining to the detector description.
Definition: Detector.h:134
void Update() const
void Update(std::vector< double > &init, const std::vector< double > &res)
Definition: Util.h:100
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Base class for exceptions trying to access non-existing components.
Interface for detector managers.
Definition: VManager.h:115
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
Detector description interface for MARTA Station-related data.
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
int GetId() const
Get the station Id.
utl::Validated< InGridType > fInGrid
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
class to hold data at Station level
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
bool IsDense() const
Tells whether the station belongs to set of hypothetical &quot;dense&quot; stations.
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127
ManagerRegister & GetCManagerRegister() const
Definition: Detector.h:109

, generated on Tue Sep 26 2023.