SDetector.cc
Go to the documentation of this file.
1 #include <boost/format.hpp>
3 #include <boost/lexical_cast.hpp>
4 
5 #include <det/Detector.h>
6 #include <sdet/SDetector.h>
7 #include <sdet/Station.h>
8 #include <det/VManager.h>
9 #include <utl/ErrorLogger.h>
10 #include <utl/AugerException.h>
11 #include <utl/TimeStamp.h>
12 
13 #include <sevt/Station.h>
14 
15 using boost::format;
16 using namespace std;
17 using namespace sdet;
18 using namespace det;
19 using namespace utl;
20 
21 
22 SDetector::~SDetector()
23 {
24  for (const auto& idp : fFullStationMap)
25  delete idp.second;
26 }
27 
28 
29 void
30 SDetector::UpdateDense()
31 {
32  Update();
33 
34  const auto& sDet = Detector::GetInstance().GetSDetector();
35  for (const auto id : fDenseStationSubList)
36  sDet.GetStation(id).Update();
37 }
38 
39 
40 void
42 {
43  // Set the full station map and pairs first time the detector is updated.
44 
45  if (!fFullStationList.IsValid()) {
46 
47  const auto& sl = GetFullStationList();
48  for (const auto id : sl) {
49  const auto station = new Station(id);
50 
51  /*
52  * The hardware (electronics, small PMT, scintillator)
53  * of stations is updated upon creation, never
54  * again to be updated in the case of simulations.
55  */
56  int isUUB = 0;
57  station->GetStationData(isUUB, "isUUB", "stationList", "is uub");
58  station->UpdateElectronics(isUUB);
59 
60  int hasSmallPMT = 0;
61  station->GetStationData(hasSmallPMT, "hasSmallPMT", "stationList", "has small pmt");
62  if (hasSmallPMT)
63  station->MakeSmallPMT();
64 
65  int hasScintillator = 0;
66  station->GetStationData(hasScintillator, "hasScintillator", "stationList", "has scintillator");
67  if (hasScintillator)
68  station->MakeScintillator();
69 
70  // flag dense stations (if any)
71  const auto denseIt = find(fDenseStationSubList.begin(), fDenseStationSubList.end(), id);
72  if (denseIt != fDenseStationSubList.end()) {
73  station->fDense = true;
74  station->fInGrid = 0;
75  }
76  fFullStationMap[id] = station;
77  }
78 
79  FetchStationGroups();
80 
81  }
82 
83  const auto dTime = Detector::GetInstance().GetTime();
84 
85  fCommissionedStationList.clear();
86 
87  // add the stations into the commissioned station list depending on the time
88  // and update them
89  for (const auto& is : fFullStationMap) {
90  const Station* const station = is.second;
91  if (station->GetCommissionTimeRange() == dTime) {
92  station->Update();
93  fCommissionedStationList[is.first] = station;
94  }
95  }
96 }
97 
98 
109 const vector<int>&
110 SDetector::GetFullStationList()
111  const
112 {
113  if (!fFullStationList.IsValid()) {
114 
115  const auto& manager = Detector::GetInstance().GetSManagerRegister();
116 
117  fFullStationList.Get().clear();
118 
119  VManager::IndexMap indexMap;
120  auto status = manager.GetData(fFullStationList.Get(), "fullStationList", "stationList", indexMap);
121 
122  if (status == VManager::eNotFound) {
123  ostringstream err;
124  err << "Could not find a list of SD Station ID's. "
125  "No station information will be available!";
126  DEBUGLOG(err);
127  }
128 
129  fFullStationList.SetValid();
130 
131  // check for dense stations
132  // (this is done separately, as there is a different convention for
133  // specifying their positions.)
134  fDenseStationSubList.clear();
135  indexMap["reportErrors"] = "0";
136  status = manager.GetData(fDenseStationSubList, "denseStationList", "stationList", indexMap);
137 
138  if (status == VManager::eFound && !fDenseStationSubList.empty()) {
139  INFO("Using dense stations.");
140  fFullStationList.Get().insert(fFullStationList.Get().end(),
141  fDenseStationSubList.begin(),
142  fDenseStationSubList.end());
143  }
144 
145  }
146 
147  return fFullStationList.Get();
148 }
149 
150 
151 void
152 SDetector::FetchStationGroups()
153  const
154 {
155  const auto& manager = Detector::GetInstance().GetSManagerRegister();
156 
157  VManager::IndexMap indexMap;
158  vector<int> stationGroupIds;
159  const auto status = manager.GetData(stationGroupIds, "groupIds", "stationList", indexMap);
160 
161  if (status == VManager::eNotFound) {
162  WARNING("Could not find a list of SD Station groups ids.");
163  return;
164  }
165 
166  fStationGroups.clear();
167 
168  vector<int> groupVec;
169  set<int> groupSet;
170  for (const auto gid : stationGroupIds) {
171  groupVec.clear();
172  indexMap["groupId"] = boost::lexical_cast<string>(gid);
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(gid, groupSet));
179  }
180 }
181 
182 
183 const Station&
184 SDetector::GetStation(const sevt::Station& station)
185  const
186 {
187  return GetStation(station.GetId());
188 }
189 
190 
191 const Station&
192 SDetector::GetStation(const int id)
193  const
194 {
195  {
196  const auto it = fCommissionedStationList.find(id);
197  if (it != fCommissionedStationList.end())
198  return *it->second;
199  }
200 
201  // Handle special cases.
202  // 1) Dense stations. These stations are not in the commissioned station list.
203  // 2) Stations which come from some other station list manager and are
204  // hence not in the commissioned station list.
205 
206  // Special case of dense stations
207  {
208  const auto it = fFullStationMap.find(id);
209  if (it != fFullStationMap.end()) {
210  const Station* const station = it->second;
211  if (station->IsDense())
212  return *station;
213  }
214  }
215 
216  if (!fFullStationList.IsValid())
217  GetFullStationList();
218 
219  const auto it = find(fFullStationList.Get().begin(), fFullStationList.Get().end(), id);
220 
221  // Other special managers
222  if (it == fFullStationList.Get().end()) {
223 
224  const auto& detector = Detector::GetInstance();
225  const auto& manager = detector.GetSManagerRegister();
226 
227  const VManager::IndexMap indexMap({{ "stationId", boost::lexical_cast<string>(id) }});
228 
229  string stationName;
230  const bool hasName = manager.GetData(stationName, "name", "stationList", indexMap) == VManager::eFound;
231  double dummy;
232  const bool hasNorthing = manager.GetData(dummy, "northing", "stationList", indexMap) == VManager::eFound;
233  const bool hasEasting = manager.GetData(dummy, "easting", "stationList", indexMap) == VManager::eFound;
234  const bool hasAltitude = manager.GetData(dummy, "altitude", "stationList", indexMap) == VManager::eFound;
235 
236  if (hasName && hasNorthing && hasEasting && hasAltitude) {
237 
238  const auto station = new Station(id);
239  fFullStationList.Get().push_back(id);
240  const pair<int, const Station*> idStation(id, station);
241  fFullStationMap.insert(idStation);
242 
243  ostringstream warn;
244  warn << "Station " << format("%4d") % id << " was not in the station list. "
245  "It is being added individually.";
246  WARNING(warn);
247 
248  // now that we are at it, check if it's commissioned
249  const auto dTime = detector.GetTime();
250  if (station->GetCommissionTimeRange() == dTime) {
251  station->Update();
252  fCommissionedStationList.insert(idStation);
253  return *station;
254  }
255 
256  } else {
257 
258  ostringstream err;
259  err << "No station with Id = " << id << " was found. At least the following information is missing:"
260  << (hasName ? "" : " name")
261  << (hasNorthing ? "" : " northing")
262  << (hasEasting ? "" : " easting")
263  << (hasAltitude ? "" : " altitude")
264  << ". Do you have some station position manager registered in SManagerRegister?";
265  throw NonExistentComponentException(err.str());
266 
267  }
268 
269  }
270 
271  // individual addition ends here
272 
273  ostringstream err;
274  err << "Station with Id = " << id << " is not commissioned at "
275  "detector time = " << Detector::GetInstance().GetTime()
276  << " or else detector description was not properly configured";
277  throw NonExistentComponentException(err.str());
278 }
279 
280 
281 const Station&
282 SDetector::GetAllStation(const int id)
283  const
284 {
285  const auto it = fFullStationMap.find(id);
286  if (it != fFullStationMap.end())
287  return *it->second;
288 
289  ostringstream err;
290  err << "Station with Id = " << id << " is not fund in the list of all stations.";
291  throw NonExistentComponentException(err.str());
292 }
293 
294 
295 const PMT&
296 SDetector::GetPMT(const sevt::PMT& pmt)
297  const
298 {
299  return GetStation(pmt.GetStationId()).GetPMT(pmt.GetId());
300 }
const utl::TimeRange & GetCommissionTimeRange() const
Station commission time range.
int GetId() const
Get the station Id.
class to hold data at PMT level
Definition: SEvent/PMT.h:28
Detector description interface for Station-related data.
Detector description interface for PMT-related data.
Definition: SDetector/PMT.h:26
bool is(const double a, const double b)
Definition: testlib.cc:113
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.
unsigned int GetId() const
Return Id of the PMT.
Definition: SEvent/PMT.h:32
class to hold data at Station level
int GetStationId() const
Definition: SEvent/PMT.h:37
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
void Update() const
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
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.

, generated on Tue Sep 26 2023.