3 #include <boost/lambda/lambda.hpp>
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>
27 AddAvailability<unsigned long long int>(
"BadStation");
32 RBadStationSQLManager::InternalGetData(std::vector<int>& returnData,
const std::string& componentProperty,
33 const std::string& componentName,
const IndexMap& )
36 if (componentProperty !=
"BadStation")
39 if (fBadPeriodList.empty()) {
40 std::cout <<
"Buffer BadStation Database" << std::endl;
41 BufferBadPeriodTable();
46 unsigned int long long fL;
50 llReturn.fL = GetBadPeriodFromBuffer(boost::lexical_cast<int>(componentName));
53 for (
unsigned int i = 0; i < 2; ++i)
54 returnData[i] = llReturn.fI[i];
60 RBadStationSQLManager::GenericGetData(
Handle& returnData,
61 const std::string& component,
62 const std::string& property,
66 if (!(returnData.
Is<
unsigned long long int>() && component ==
"BadStation"))
69 if (fBadPeriodList.empty()) {
70 std::cout <<
"Buffer BadStation Database" << std::endl;
71 BufferBadPeriodTable();
74 returnData.
Get<
unsigned long long int>() = GetBadPeriodFromBuffer(boost::lexical_cast<int>(property));
80 RBadStationSQLManager::GetBadPeriod(
const int stationId)
83 std::cout <<
"\nRBadStationSQLManager::GetBadPeriod()" << std::endl;
84 const utl::TimeStamp& currentTime = det::Detector::GetInstance().GetTime();
88 query <<
"select Reason from RBadStationList where" <<
" StartTime<\"" << mySQLTime <<
"\" "
89 <<
" and StopTime>\"" << mySQLTime <<
"\" and StationName = \"" << stationId <<
"\";";
90 std::cout << query.str() << endl;
92 const int queryResult =
93 Query(query.str(), QueryInfoMessage(
"Station", boost::lexical_cast<string>(stationId)));
94 cout <<
"Query Result = " << queryResult << endl;
95 if (queryResult == eNotFound) {
96 std::cout <<
"RdBadStationSQLManager: No bad period for station " << stationId <<
" at time "
102 vector<string> sqlResult;
103 while (FetchRow(sqlResult,
false) == eFound) {
104 cout <<
"while " << endl;
105 result = result | boost::lexical_cast<
int>(sqlResult[0]);
108 std::cout <<
"RdBadStationSQLManager: No bad period for station " << stationId <<
" at time "
112 std::cout <<
"RdBadStationSQLManager: Found bad period for station " << stationId <<
" at time "
113 <<
utl::UTCDateTime(currentTime) <<
" with reason = " << result << std::endl;
118 unsigned long long int
119 RBadStationSQLManager::GetBadPeriodFromBuffer(
const int stationId)
125 const utl::TimeStamp& currentTime = det::Detector::GetInstance().GetTime();
129 const std::vector<BadPeriod>& vBadPeriod = fBadPeriodList[stationId];
131 unsigned long long int reason = 0;
132 for (std::vector<BadPeriod>::const_iterator itBadPeriod = vBadPeriod.begin();
133 itBadPeriod != vBadPeriod.end(); ++itBadPeriod) {
135 if ((itBadPeriod->startGPSSecond <= currentGPSSecond) &&
136 (itBadPeriod->stopGPSSecond >= currentGPSSecond)) {
137 reason = reason | itBadPeriod->reason;
187 RBadStationSQLManager::BufferBadPeriodTable()
193 std::vector<BadPeriod> vBadPeriod;
198 query <<
"SELECT DISTINCT PartName, ReasonPattern, GPSStart, GPSStop FROM `BadPeriod` "
199 "LEFT JOIN PartsRel using (BadPeriod_id) "
200 "LEFT JOIN Parts on PartsRel.ComponentId = Parts.Parts_id "
201 "WHERE Status_id = 3 AND Projects_id = 3 AND SiteId = 140 "
202 "order by PartName asc, GPSStart asc";
208 if (Query(query.str(), error) == eNotFound) {
209 ostringstream error_msg;
210 error_msg <<
"BadPeriod has no entries. " << error << std::endl;
216 vector<string> sqlResult;
219 while (FetchRow(sqlResult,
false) == eFound) {
222 const int gotId = boost::lexical_cast<
int>(sqlResult[0]);
224 if (stationId != gotId) {
228 if (!vBadPeriod.empty()) {
229 info <<
"\n\tBuffer bad periods for station " << stationId <<
": " << vBadPeriod.size() <<
" bad periods in total";
230 fBadPeriodList.insert(std::pair<
int, std::vector<BadPeriod> >(stationId, vBadPeriod));
238 sBadPeriod.
reason = boost::lexical_cast<
unsigned long long int>(sqlResult[1]);
239 sBadPeriod.
startGPSSecond = boost::lexical_cast<
unsigned int>(sqlResult[2]);
240 sBadPeriod.
stopGPSSecond = boost::lexical_cast<
unsigned int>(sqlResult[3]);
250 vBadPeriod.push_back(sBadPeriod);
254 if (!vBadPeriod.empty()) {
255 info <<
"\n\tSaving bad periods for last station (station " << stationId <<
", " << vBadPeriod.size() <<
" bad periods)" << endl;
256 fBadPeriodList.insert(std::pair<
int, std::vector<BadPeriod> >(stationId, vBadPeriod));
#define INFO(message)
Macro for logging informational messages.
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_)
unsigned long long int reason
Manager for RD Bad Stations.
unsigned long startGPSSecond
unsigned long GetGPSSecond() const
GPS second.
std::map< std::string, std::string > IndexMap
boost::add_reference< typename boost::remove_const< T >::type >::type Get()
#define ERROR(message)
Macro for logging error messages.
TimeStamp GetTimeStamp() const
Status
Specifies success or (eventually) various possible failure modes.
unsigned long stopGPSSecond