RDetector/Station.cc
Go to the documentation of this file.
1 #include <sstream>
2 #include <boost/lexical_cast.hpp>
3 
4 #include <det/Detector.h>
5 
6 #include <rdet/RDetector.h>
7 #include <rdet/Channel.h>
8 #include <rdet/Station.h>
9 
10 #include <revt/Channel.h>
11 
12 #include <fwk/LocalCoordinateSystem.h>
13 
14 #include <utl/ErrorLogger.h>
15 #include <utl/Point.h>
16 #include <utl/UTMPoint.h>
17 #include <utl/TimeStamp.h>
18 #include <utl/UTCDateTime.h>
19 #include <utl/TimeInterval.h>
20 #include <utl/Reader.h>
21 #include <utl/AugerUnits.h>
22 #include <utl/CoordinateSystem.h>
23 #include <utl/AugerCoordinateSystem.h>
24 #include <utl/ReferenceEllipsoid.h>
25 
26 using namespace det;
27 using namespace rdet;
28 using namespace std;
29 using namespace utl;
30 
31 
32 Station::Station(const int id) :
33  fId(id),
34  fStationIdString(boost::lexical_cast<string>(id))
35 {
37  for (unsigned int i = 0; i < fListOfChannelIds.size(); ++i) {
38  Channel* const channel = new Channel(id, fListOfChannelIds[i]);
39  fChannelVector.push_back(channel);
40  }
41 }
42 
43 
45 {
46  for (InternalChannelIterator it = fChannelVector.begin();
47  it != fChannelVector.end(); ++it)
48  delete *it;
49 }
50 
51 
52 const Channel&
53 Station::GetChannel(const int id)
54  const
55 {
58  } else {
59  ostringstream err;
60  err << "Invalid Channel Id requested : " << id
61  << ", available channel Id's are";
62  for(unsigned int i = 0; i < fListOfChannelIds.size(); ++i) {
63  err << fListOfChannelIds[i] << " ";
64  }
65  ERROR(err);
66  throw NonExistentComponentException(err.str());
67  }
68 }
69 
70 
71 const Channel&
73  const
74 {
75  return GetChannel(channel.GetId());
76 }
77 
78 
79 string
81  const
82 {
83  if (!fName.IsValid()) {
84  GetStationData(fName.Get(), "name", "stationList", "station name");
85  fName.SetValid();
86  }
87  return fName.Get();
88 }
89 
90 bool
92  const
93 {
94  int isvirtual;
95  GetStationData(isvirtual, "virtual", "stationList", "station is virtual");
96  return isvirtual;
97 }
98 
99 
100 bool
102  const
103 {
104  int IsInAcquisition;
105  GetStationData(IsInAcquisition, "station_in_acquisition", "is_in_acquisition", "station in acquisition flag");
106  return IsInAcquisition;
107 }
108 
109 
110 const TimeRange&
112  const
113 {
114  if (!fCommissionTimeRange.IsValid()) {
115  string timeString;
116  GetStationData(timeString, "commission", "stationList", "commission time");
117  const TimeStamp start = boost::lexical_cast<UTCDateTime>(timeString).GetTimeStamp();
118  GetStationData(timeString, "decommission", "stationList", "commission time");
119  const TimeStamp stop = boost::lexical_cast<UTCDateTime>(timeString).GetTimeStamp();
120  fCommissionTimeRange = TimeRange(start, stop);
121  }
122  return fCommissionTimeRange.Get();
123 }
124 
125 
126 Point
128  const
129 {
130  if (!fPosition.IsValid()) {
131 
132  double northing, easting, altitude;
133  GetStationData(northing, "northing", "stationList", "northing");
134  GetStationData(easting, "easting", "stationList", "easting");
135  GetStationData(altitude, "altitude", "stationList", "altitude");
136 
137  string ellipsoid;
138  GetStationData(ellipsoid, "ellipsoid", "stationList", "ellipsoid for UTM conversion");
139  fEllipsoid = ReferenceEllipsoid::GetEllipsoidIDFromString(ellipsoid);
140 
141  string band;
142  GetStationData(band, "band", "stationList", "band for UTM conversion");
143 
144  int zone;
145  GetStationData(zone, "zone", "stationList", "zone for UTM conversion");
146 
147  const CoordinateSystemPtr cs = Detector::GetInstance().GetSiteCoordinateSystem();
148  const UTMPoint utmposition(northing, easting, altitude, zone, band[0], fEllipsoid);
149 
150  fPosition = utmposition.GetPoint(cs);
151 
152  }
153  return fPosition.Get();
154 }
155 
156 
157 bool
159  const
160 {
161 
162  if (!fInGrid.IsValid()) {
163  if (fId > det::Detector::GetInstance().GetRDetector().GetRdSdStationIdLink()) // temporary solution until SStationList is expanded
164  fInGrid.Get() = 1;
165  else
166  GetStationData(fInGrid.Get(), "inGrid", "stationList", "get is-in-grid");
167  fInGrid.SetValid();
168  }
169  return fInGrid.Get();
170 }
171 
172 
173 void
174 Station::NotFoundAndThrow(const string& msg)
175  const
176 {
177  ostringstream err;
178  err << "Did not find requested component: '" << msg
179  << "' for station = " << fStationIdString;
180  ERROR(err);
181  throw NonExistentComponentException(err.str());
182 }
183 
184 
187  const
188 {
189  if (!fReferenceSystem)
192 
193  return fReferenceSystem;
194 }
195 
196 
197 void
199  const
200 {
201  /*
202  * In this method we clean all the variables that might change with time and deleted whatever was allocated in the get*'s
203 
204  fName.SetValid(false);
205  fInGrid.SetValid(false);
206  fPosition.SetValid(false);
207  fCommissionTimeRange.SetValid(false);
208 
209  delete fWaterAbsLength;
210  fWaterAbsLength = 0;
211 
212  delete fWaterRefractionIndex;
213  fWaterRefractionIndex = 0;
214 
215  delete fLinerReflectivity;
216  fLinerReflectivity = 0;
217 
218  delete fLinerSpecularLobe;
219  fLinerSpecularLobe = 0;
220 
221  delete fLinerSpecularSpike;
222  fLinerSpecularSpike = 0;
223 
224  delete fLinerSigmaAlpha;
225  fLinerSigmaAlpha = 0;
226  */
227 
228  fIsInAcquisition.SetValid(false);
229  fIsInAcquisition = 0;
230 
231  /*
232  delete fLiveTime;
233  fLiveTime = 0;
234  */
235 
236  for(InternalChannelIterator channelIt = fChannelVector.begin();
237  channelIt != fChannelVector.end(); ++channelIt)
238  (*channelIt)->Update();
239 }
240 
241 
243  det::VManager::IndexMap indexMap;
244  indexMap["station"] = fStationIdString;
245  indexMap["stationId"] = fStationIdString;
246  std::vector<int> requestedData;
247 
248  if (fId > det::Detector::GetInstance().GetRDetector().GetRdSdStationIdLink()) { // temporary solution until SStationList is expanded
249  std::vector<int> defaultChannelIds{0, 1};
250  requestedData = defaultChannelIds;
251  }
252  else {
253  const det::VManager& manager = det::Detector::GetInstance().GetRManagerRegister();
254  const det::VManager::Status status = manager.GetData(requestedData, "listOfChannelIds", "RChannel", indexMap);
255 
256  if (status == det::VManager::eNotFound)
257  NotFoundAndThrow("List of channels Ids not found.");
258  }
259 
260  fListOfChannelIds = requestedData;
261 
262  for(unsigned int i = 0; i< fListOfChannelIds.size(); ++i) {
263  fChannelIdToInternalChannelId.insert(std::pair<int, int> (fListOfChannelIds[i], i));
264  }
265 
266 }
267 
268 
269 template <typename T>
271 Station::GetStationData(T& requestedData,
272  const std::string& property,
273  const std::string& component,
274  const std::string& errorMsg,
275  const bool throwOnFailure)
276  const
277 {
278  det::VManager::Status status;
279  det::VManager::IndexMap indexMap;
280 
281  // If station Id is equal or below RDetector::fRdSdStationIdLink ask radio manager (AERA stations),
282  // if station Id is above ask SD manager (RD stations)
283  int rdsdLink = det::Detector::GetInstance().GetRDetector().GetRdSdStationIdLink();
284  if (fId <= rdsdLink) {
285  indexMap["stationId"] = fStationIdString;
286  const det::VManager& manager = det::Detector::GetInstance().GetRManagerRegister();
287  status = manager.GetData(requestedData, property, component, indexMap);
288  }
289  else {
290  indexMap["stationId"] = boost::lexical_cast<std::string>(fId - rdsdLink);
291  const det::VManager& manager = det::Detector::GetInstance().GetSManagerRegister();
292  status = manager.GetData(requestedData, property, component, indexMap);
293  }
294 
295  if (throwOnFailure && status == det::VManager::eNotFound)
296  NotFoundAndThrow(errorMsg);
297 
298  return status;
299 }
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger reference system centered on the station.
Point object.
Definition: Point.h:32
bool IsInAcquisition() const
Station in data acquisition.
int GetId() const
Return Id of the Channel.
Time interval defined by two TimeStamps.
Definition: TimeRange.h:23
void NotFoundAndThrow(const std::string &msg) const
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
det::VManager::Status GetStationData(T &requestedData, const std::string &property, const std::string &component, const std::string &errorMsg, const bool throwOnFailure=true) const
Base class for exceptions trying to access non-existing components.
Detector description interface for Channel-related data.
Interface for detector managers.
Definition: VManager.h:115
InternalChannelVector fChannelVector
bool IsVirtual() const
std::vector< int > fListOfChannelIds
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
std::string fStationIdString
utl::CoordinateSystemPtr fReferenceSystem
utl::Validated< utl::Point > fPosition
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
InternalChannelVector::const_iterator InternalChannelIterator
utl::Validated< std::string > fName
bool IsValid() const
Definition: Validated.h:64
utl::Validated< int > fIsInAcquisition
void Update() const
const Channel & GetChannel(const int id) const
Get specified Channel by id.
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
utl::Validated< utl::TimeRange > fCommissionTimeRange
void SetListOfChannelIds()
set list of channel ids of the station
Class that holds the data associated to an individual radio channel.
void SetValid(const bool valid=true)
Definition: Validated.h:66
std::map< int, int > fChannelIdToInternalChannelId
utl::Validated< int > fInGrid
utl::ReferenceEllipsoid::EllipsoidID fEllipsoid
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
Point GetPoint(const CoordinateSystemPtr &theCS=CoordinateSystemPtr()) const
Get a cartesian point from an UTMPoint.
Definition: UTMPoint.cc:45
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
bool IsInGrid(const int level=0) const
Tells whether the station is in the regular triangular grid.
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127
const utl::TimeRange & GetCommissionTimeRange() const
Station commission time range.
std::string GetName() const
Station name.

, generated on Tue Sep 26 2023.