2 #include <boost/lambda/lambda.hpp>
4 #include <rdet/RBeaconSQLManager.h>
5 #include <utl/ErrorLogger.h>
6 #include <rdet/RDetector.h>
7 #include <rdet/RManagerRegister.h>
8 #include <det/VManager.h>
9 #include <utl/UTCDateTime.h>
10 #include <utl/TimeStamp.h>
11 #include <utl/LeapSeconds.h>
12 #include <utl/TabulatedFunctionComplexLgAmpPhase.h>
13 #include <utl/MathConstants.h>
33 const std::string& componentName,
36 if (componentName==
"BeaconFreq") {
39 const TimeStamp& curTime = Detector::GetInstance().GetTime();
40 if ( (fBeaconFreqs.size()) &&
41 (fBeaconFreqsBufferedStartDate < curTime) &&
42 (fBeaconFreqsBufferedStopDate > curTime) ) {
43 returnData = fBeaconFreqs;
47 returnData = GetBeaconFrequencies();
48 fBeaconFreqs = returnData;
49 if (returnData.size()) {
63 const std::string& componentName,
66 if (componentName==
"BeaconRefPhase") {
67 const TimeStamp& curTime = Detector::GetInstance().GetTime();
68 const int stationId = boost::lexical_cast<
int>(componentIndex.find(
"RStationId")->second);
69 stringstream sBeaconFreq(componentIndex.find(
"BeaconFreq")->second);
70 double beaconFreq = 0;
71 sBeaconFreq >> beaconFreq;
74 if ( (fBufferBeaconRefPhases.size()) &&
75 (fBufferBeaconRefPhases.find(stationId) != fBufferBeaconRefPhases.end()) &&
76 (fBufferBeaconRefPhases[stationId].find(beaconFreq) != fBufferBeaconRefPhases[stationId].end()) &&
77 (fBufferBeaconRefPhases[stationId][beaconFreq].startDate < curTime) &&
78 (fBufferBeaconRefPhases[stationId][beaconFreq].stopDate > curTime) ) {
79 returnData = fBufferBeaconRefPhases[stationId][beaconFreq].refPhase;
82 returnData = GetBeaconRefPhase(stationId, beaconFreq);
97 const TimeStamp& curTime = Detector::GetInstance().GetTime();
99 query <<
"select BeaconFrequency, UNIX_TIMESTAMP(Commission), UNIX_TIMESTAMP(Decommission) from BeaconFreq where"
102 if (Query(query.str(), QueryInfoMessage(
"BeaconFrequency",
"BeaconFreq")) == eNotFound) {
103 const string err =
"No Beacon Frequency for given event-time in SQL data found! Query: " + query.str();
106 vector<double> Result;
107 vector<TimeStamp> Comission;
108 vector<TimeStamp> Decomission;
109 vector<string> sqlResult;
111 unsigned long gpsSeconds=0;
112 bool firstValue =
true;
113 while (FetchRow(sqlResult,
false) == eFound) {
114 Result.push_back(boost::lexical_cast<double>(sqlResult[0]));
117 leapSeconds.
ConvertUnixToGPS(boost::lexical_cast<unsigned long>(sqlResult[1]),gpsSeconds);
119 fBeaconFreqsBufferedStartDate =
TimeStamp(gpsSeconds);
121 if (fBeaconFreqsBufferedStartDate <
TimeStamp(gpsSeconds))
122 fBeaconFreqsBufferedStartDate =
TimeStamp(gpsSeconds);
124 leapSeconds.
ConvertUnixToGPS(boost::lexical_cast<unsigned long>(sqlResult[2]),gpsSeconds);
126 fBeaconFreqsBufferedStopDate =
TimeStamp(gpsSeconds);
128 if (fBeaconFreqsBufferedStopDate >
TimeStamp(gpsSeconds))
129 fBeaconFreqsBufferedStopDate =
TimeStamp(gpsSeconds);
139 const double& beaconFreq)
const
141 const TimeStamp& curTime = Detector::GetInstance().GetTime();
143 query <<
"select BeaconRefPhase.RefPhase, UNIX_TIMESTAMP(Start), UNIX_TIMESTAMP(Stop) from BeaconFreq , BeaconRefPhase"
144 <<
" where BeaconFreq.BeaconFreq_id=BeaconRefPhase.BeaconFreq_id"
145 <<
" and BeaconRefPhase.RStationId = " << stationId
146 <<
" and BeaconFreq.BeaconFrequency LIKE " << beaconFreq
149 const string err =
"No Beacon RefPhase for event-time in SQL data found! Query: " + query.str();
150 if (Query(query.str(), QueryInfoMessage(
"BeaconRefPhase",
"RefPhase")) == eNotFound) {
154 vector<string> sqlResult;
155 if (FetchRow(sqlResult,
false) != eFound) {
158 double Result = boost::lexical_cast<
double>(sqlResult[0]);
161 fBufferBeaconRefPhases[stationId][beaconFreq].refPhase = Result;
165 unsigned long gpsSeconds=0;
166 leapSeconds.
ConvertUnixToGPS(boost::lexical_cast<unsigned long>(sqlResult[1]),gpsSeconds);
167 fBufferBeaconRefPhases[stationId][beaconFreq].startDate =
TimeStamp(gpsSeconds);
168 leapSeconds.
ConvertUnixToGPS(boost::lexical_cast<unsigned long>(sqlResult[2]),gpsSeconds);
169 fBufferBeaconRefPhases[stationId][beaconFreq].stopDate =
TimeStamp(gpsSeconds);
void Init(const std::string &configLink)
Manager Initialization. configLink is the CentralConfig hook for the configuration file...
double GetBeaconRefPhase(const int &stationId, const double &beaconFreq) const
Status InternalGetDataDouble(double &returnData, const std::string &, const std::string &componentName, const IndexMap &componentIndex) const
Manager for RD description of Station-Channels in SQL DB.
std::string GetInMySQLFormat() const
void Init()
Initialise the registry.
A TimeStamp holds GPS second and nanosecond for some event.
#define REGISTER_R_MANAGER(_name_, _Type_)
Exception to use in case requested data not found in the database with detailed printout.
Status InternalGetDataVecDouble(std::vector< double > &returnData, const std::string &, const std::string &componentName, const IndexMap &) const
std::vector< double > GetBeaconFrequencies() const
std::map< std::string, std::string > IndexMap
Status
Specifies success or (eventually) various possible failure modes.
void ConvertUnixToGPS(const time_t unixSecond, unsigned long &gpsSecond) const