1 #include <io/REASIOException.h>
3 #include <rdet/RSimulationStationListManager.h>
4 #include <rdet/RManagerRegister.h>
6 #include <det/Detector.h>
9 #include <evt/ShowerSimData.h>
10 #include <evt/RadioSimulation.h>
12 #include <utl/UTCDateTime.h>
13 #include <utl/TimeStamp.h>
14 #include <utl/UTMPoint.h>
15 #include <utl/Point.h>
16 #include <utl/ReferenceEllipsoid.h>
17 #include <utl/ErrorLogger.h>
19 #include <fwk/CentralConfig.h>
20 #include <fwk/RunController.h>
21 #include <fwk/LocalCoordinateSystem.h>
23 #include <boost/algorithm/string/predicate.hpp>
24 #include <boost/lexical_cast.hpp>
36 using namespace boost;
50 for (string::const_iterator it = str.begin(); it != str.end(); ++it) {
51 const int i = (
unsigned char) (*it);
56 if (it != str.end() && int((
unsigned char) (*it)) == 177)
64 if (32 <= i && i < 127)
79 Branch topBranch = CentralConfig::GetInstance()->
GetTopBranch(
"RSimulationStationListManager");
81 topBranch.
GetChild(
"ReadInAdditionalStationViaXML").
GetData(fReadInAdditionalStationViaXML);
82 topBranch.
GetChild(
"ReadInAdditionalStationViaSQL").
GetData(fReadInAdditionalStationViaSQL);
87 if (fReadInAdditionalStationViaXML) {
90 int number_of_xml_stations = 0;
93 if (cB.GetName() ==
"station") {
98 station.
fId = FindComponent<int>(
"id", cB.GetAttributes());
99 cB.GetChild(
"northing").GetData(station.
fNorthing);
100 cB.GetChild(
"easting").GetData(station.
fEasting);
101 cB.GetChild(
"altitude").GetData(station.
fAltitude);
102 station.
fName = cB.GetChild(
"name").GetDataString();
105 cB.GetChild(
"inGrid").GetData(station.
fInGrid);
106 cB.GetChild(
"ellipsoid").GetData(station.
fEllipsoid);
107 cB.GetChild(
"zone").GetData(station.
fZone);
108 cB.GetChild(
"band").GetData(station.
fBand);
109 cB.GetChild(
"nChannels").GetData(station.
fNChannels);
114 fStationManager.ConditionalAddStationData(station);
118 error <<
"multiple instances of station id " << station.
fId
119 <<
" found in XML / SQL configuration";
124 number_of_xml_stations++;
128 out <<
"\n\tInitialized " << number_of_xml_stations <<
" radio stations via XML list.";
131 out <<
"\n\tInitialize stations from SQL DB: " << fReadInAdditionalStationViaSQL <<
"\n";
139 fStationManager.AddOrReplaceStationData(station);
143 RSimulationStationListManager::HasStationData(
const int id)
146 return fStationManager.HasStationData(
id);
151 RSimulationStationListManager::GetListOfChannelIds(std::vector<int>& resultData,
157 int firstChannelId = 0;
158 int lastChannelId = 0;
159 if (fStationManager.GetData(firstChannelId,
"firstChannelId", componentIndex) == eFound &&
160 fStationManager.GetData(lastChannelId,
"lastChannelId", componentIndex) == eFound) {
161 for (
int i = firstChannelId; i <= lastChannelId; ++i)
174 const TimeStamp& curTime = Detector::GetInstance().GetTime();
175 if (Commissioned.IsInRange(curTime))
179 fStationManager.ClearStations(
"SQL");
182 TimeStamp maxValidTime(2147483647
U, 999999999.9999999);
187 "ellipsoid, zone, band, "
188 "northing, easting, altitude, "
191 "nChannels, firstChannelId, lastChannelId, "
192 "max(Commission), min(Decommission) "
193 "FROM RStation left join RHardWareAssociation using (RStationId) "
194 "left join utm_data using (utm_data_id) "
195 "where Commission<\""
197 "and Decommission>\""
199 "GROUP BY RStationId ORDER BY RStationId ASC";
203 if (Query(query.str(), QueryInfoMessage(
"all station_list",
"station_list")) == eNotFound) {
204 const string err =
"No station_list SQL data found! Query: " + query.str();
214 vector<string> IdElZoBaNoEaAlNaIGNCFCLCCTDT;
215 while (FetchRow(IdElZoBaNoEaAlNaIGNCFCLCCTDT,
false) == eFound) {
220 station.
fId = lexical_cast<
int>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[0]);
221 station.
fEllipsoid = IdElZoBaNoEaAlNaIGNCFCLCCTDT[1];
222 station.
fZone = lexical_cast<
int>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[2]);
223 station.
fBand = IdElZoBaNoEaAlNaIGNCFCLCCTDT[3];
224 station.
fNorthing = lexical_cast<
double>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[4]);
225 station.
fEasting = lexical_cast<
double>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[5]);
226 station.
fAltitude = lexical_cast<
double>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[6]);
228 station.
fInGrid = lexical_cast<
int>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[8]);
229 station.
fNChannels = lexical_cast<
int>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[9]);
230 station.
fFirstChannelId = lexical_cast<
int>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[10]);
231 station.
fLastChannelId = lexical_cast<
int>(IdElZoBaNoEaAlNaIGNCFCLCCTDT[11]);
237 if (IdElZoBaNoEaAlNaIGNCFCLCCTDT[12].size() == 0) {
239 err <<
"No configuration for station-id " << station.
fId <<
" found -> station ignored";
243 if (IdElZoBaNoEaAlNaIGNCFCLCCTDT[12].size() < 19) {
246 warn <<
"Empty Comissioning-Time for station " << station.
fId <<
" now set to "
255 if (IdElZoBaNoEaAlNaIGNCFCLCCTDT[13].size() < 19) {
258 warn <<
"Empty Decomissioning-Time for station " << station.
fId <<
" now set to "
267 fStationManager.AddOrReplaceStationData(station);
279 if (tmpTime > minValidTime) {
280 minValidTime = tmpTime;
282 tmpTime = boost::lexical_cast<UTCDateTime>(station.
fDecommissionTime).GetTimeStamp();
283 if (tmpTime < maxValidTime) {
284 maxValidTime = tmpTime;
291 query <<
"SELECT max(Decommission) "
293 "left join RHardWareAssociation using (RStationId) left join utm_data using (utm_data_id)"
294 "where Decommission<\""
297 if (Query(query.str(), QueryInfoMessage(
"all station_list",
"station_list")) == eNotFound) {
298 const string err =
"No decommissioned stations found before current time! Query: " + query.str();
301 vector<string> sql_result;
302 if (FetchRow(sql_result,
false) == eFound) {
303 if (sql_result[0].size() >= 19) {
304 std::string temp = sql_result[0];
307 maxDecommission = boost::lexical_cast<
UTCDateTime>(temp).GetTimeStamp();
312 minValidTime =
max(maxDecommission, minValidTime);
313 TimeStamp minCommission = TimeStamp::Max();
317 query <<
"SELECT min(Commission) "
319 "left join RHardWareAssociation using (RStationId) left join utm_data using (utm_data_id)"
320 "where Commission>\""
322 if (Query(query.str(), QueryInfoMessage(
"all station_list",
"station_list")) == eNotFound) {
323 const string err =
"No now commissioned stations found after current time! Query: " + query.str();
326 vector<string> sql_result2;
327 if (FetchRow(sql_result2,
false) == eFound) {
328 if (sql_result2[0].size() >= 19) {
329 std::string temp = sql_result2[0];
332 minCommission = boost::lexical_cast<
UTCDateTime>(temp).GetTimeStamp();
337 maxValidTime = min(minCommission, maxValidTime);
338 Commissioned.SetTimeRange(minValidTime, maxValidTime);
Branch GetTopBranch() const
std::string fDecommissionTime
void Update(std::vector< double > &init, const std::vector< double > &res)
#define INFO(message)
Macro for logging informational messages.
std::string GetInMySQLFormat() const
void Init()
Initialise the registry.
vector< t2list > out
output of the algorithm: a list of clusters
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
string Utf8To7Bit(const string &str)
Exception for errors encountered when parsing XML.
A TimeStamp holds GPS second and nanosecond for some event.
Branch GetNextSibling() const
Get next sibling of this branch.
#define REGISTER_R_MANAGER(_name_, _Type_)
Class representing a document branch.
Exception to use in case requested data not found in the database with detailed printout.
void GetData(bool &b) const
Overloads of the GetData member template function.
Manager for RD description in SQL or XML station lists.
std::map< std::string, std::string > IndexMap
Branch GetFirstChild() const
Get first child of this Branch.
std::string fCommissionTime
#define ERROR(message)
Macro for logging error messages.
Status
Specifies success or (eventually) various possible failure modes.