1 #include <boost/lambda/lambda.hpp>
3 #include <det/VManager.h>
5 #include <rdet/RChannelSQLManager.h>
6 #include <rdet/RDetector.h>
7 #include <rdet/RManagerRegister.h>
8 #include <rdet/RSimulationStationListManager.h>
10 #include <utl/ErrorLogger.h>
11 #include <utl/UTCDateTime.h>
12 #include <utl/TimeStamp.h>
13 #include <utl/TabulatedFunctionComplexLgAmpPhase.h>
14 #include <utl/MathConstants.h>
15 #include <utl/LeapSeconds.h>
39 const TimeStamp& curTime = Detector::GetInstance().GetTime();
42 query <<
"select MaxVoltage, MinVoltage, SamplingFrequency, BitDepth, ChannelType, PositionX, PositionY, PositionZ, "
43 "DesignUpperFreq, DesignLowerFreq, AntennaType, OrientationAzimuth, OrientationZenith, OrientationZeta, RADCId "
44 "from RHardWareAssociation left join RADC using (RADCId) left join RChannel using (RChannelId) "
45 "where RStationId=" << componentIndex.find(
"station")->second <<
" "
46 "and ChannelId=" << componentIndex.find(
"channel")->second <<
" "
50 if (Query(query.str(), QueryInfoMessage(
"Channel",
"Channel")) == eNotFound) {
51 const string err =
"No station_list SQL data found! Query: " + query.str();
56 fComponentMap.clear();
61 vector<string> sqlResult;
62 while (FetchRow(sqlResult,
false) == eFound) {
63 fComponentMap.insert(pair<string, string>(
"MaxVoltage", sqlResult[0]));
64 fComponentMap.insert(pair<string, string>(
"MinVoltage", sqlResult[1]));
65 fComponentMap.insert(pair<string, string>(
"SamplingFrequency", sqlResult[2]));
66 fComponentMap.insert(pair<string, string>(
"BitDepth", sqlResult[3]));
67 fComponentMap.insert(pair<string, string>(
"ChannelType", sqlResult[4]));
68 fComponentMap.insert(pair<string, string>(
"PositionX", sqlResult[5]));
69 fComponentMap.insert(pair<string, string>(
"PositionY", sqlResult[6]));
70 fComponentMap.insert(pair<string, string>(
"PositionZ", sqlResult[7]));
71 fComponentMap.insert(pair<string, string>(
"DesignUpperFreq", sqlResult[8]));
72 fComponentMap.insert(pair<string, string>(
"DesignLowerFreq", sqlResult[9]));
73 fComponentMap.insert(pair<string, string>(
"AntennaType", sqlResult[10]));
74 fComponentMap.insert(pair<string, string>(
"OrientationAzimuth", sqlResult[11]));
75 fComponentMap.insert(pair<string, string>(
"OrientationZenith", sqlResult[12]));
76 fComponentMap.insert(pair<string, string>(
"OrientationZeta", sqlResult[13]));
77 fComponentMap.insert(pair<string, string>(
"ADCType", sqlResult[14]));
79 fIndexMap = componentIndex;
88 const TimeStamp& curTime = Detector::GetInstance().GetTime();
90 info <<
"Request RChannel component SQL Data for time: " << curTime;
94 query <<
"select MaxVoltage, MinVoltage, SamplingFrequency, BitDepth, ChannelType, PositionX, PositionY, PositionZ, "
95 "DesignUpperFreq, DesignLowerFreq, AntennaType, OrientationAzimuth, OrientationZenith, OrientationZeta, RADCId, "
96 "RStationId, ChannelId, UNIX_TIMESTAMP(Commission), UNIX_TIMESTAMP(Decommission) "
97 "from RHardWareAssociation left join RADC using (RADCId) left join RChannel using (RChannelId) "
101 if (Query(query.str(), QueryInfoMessage(
"Channel",
"Channel")) == eNotFound) {
102 const string err =
"No station_list SQL data found! Query: " + query.str();
108 vector<string> sqlResult;
109 while (FetchRow(sqlResult,
false) == eFound) {
110 fComponentMap.clear();
111 fComponentMap.insert(pair<string, string>(
"MaxVoltage", sqlResult[0]));
112 fComponentMap.insert(pair<string, string>(
"MinVoltage", sqlResult[1]));
113 fComponentMap.insert(pair<string, string>(
"SamplingFrequency", sqlResult[2]));
114 fComponentMap.insert(pair<string, string>(
"BitDepth", sqlResult[3]));
115 fComponentMap.insert(pair<string, string>(
"ChannelType", sqlResult[4]));
116 fComponentMap.insert(pair<string, string>(
"PositionX", sqlResult[5]));
117 fComponentMap.insert(pair<string, string>(
"PositionY", sqlResult[6]));
118 fComponentMap.insert(pair<string, string>(
"PositionZ", sqlResult[7]));
119 fComponentMap.insert(pair<string, string>(
"DesignUpperFreq", sqlResult[8]));
120 fComponentMap.insert(pair<string, string>(
"DesignLowerFreq", sqlResult[9]));
121 fComponentMap.insert(pair<string, string>(
"AntennaType", sqlResult[10]));
122 fComponentMap.insert(pair<string, string>(
"OrientationAzimuth", sqlResult[11]));
123 fComponentMap.insert(pair<string, string>(
"OrientationZenith", sqlResult[12]));
124 fComponentMap.insert(pair<string, string>(
"OrientationZeta", sqlResult[13]));
125 fComponentMap.insert(pair<string, string>(
"ADCType", sqlResult[14]));
127 fComponentMap.insert(pair<string, string>(
"Commission", sqlResult[17]));
128 fComponentMap.insert(pair<string, string>(
"Decommission", sqlResult[18]));
130 Index componentIndex (sqlResult[15], sqlResult[16]);
131 fBuffer.insert(std::pair<Index, ComponentMap>(componentIndex, fComponentMap));
138 const Index& currentComponent,
139 const std::string& componentProperty)
143 std::map<Index, ComponentMap>::const_iterator it = fBuffer.find(currentComponent);
144 if (it == fBuffer.end()) {
146 out <<
"Channel " <<currentComponent.second <<
" of station " << currentComponent.first
147 <<
" not contained in buffer -> buffering ...";
149 BufferComponentMap();
150 it = fBuffer.find(currentComponent);
153 if (it != fBuffer.end()) {
154 const utl::TimeStamp& curTime = det::Detector::GetInstance().GetTime();
158 unsigned long gpsSecondsComission = 0;
159 unsigned long gpsSecondsDecomission = 0;
161 long(boost::lexical_cast<double>(componentMapofCurrentChannel.find(
"Commission")->second)),
165 long(boost::lexical_cast<double>(componentMapofCurrentChannel.find(
"Decommission")->second)),
166 gpsSecondsDecomission
172 out <<
"time of channel " <<currentComponent.second <<
" of station " << currentComponent.first
173 <<
" not valid anymore -> rebuffer" << std::endl;
175 BufferComponentMap();
178 it = fBuffer.find(currentComponent);
179 if (it != fBuffer.end()) {
180 componentMapofCurrentChannel = it->second;
181 ComponentMap::const_iterator itProperty = componentMapofCurrentChannel.find(componentProperty);
182 if (itProperty != componentMapofCurrentChannel.end()) {
183 returnData = itProperty->second;
189 out <<
"time of channel " <<currentComponent.second <<
" of station " << currentComponent.first
190 <<
"no " << componentProperty <<
" found";
200 const TimeStamp& curTime = Detector::GetInstance().GetTime();
202 info <<
"Request RChannel SQL Data for time: " << curTime;
206 query <<
"select RStationId, ChannelId, UNIX_TIMESTAMP(Commission), UNIX_TIMESTAMP(Decommission) "
207 "from RHardWareAssociation left join RChannel using (RChannelId) "
210 "ORDER BY RStationId asc, ChannelId asc;";
212 if (Query(query.str(), QueryInfoMessage(
"Channel",
"Channel")) == eNotFound) {
213 const string err =
"No RChannel SQL data found! Query: " + query.str();
218 fBufferChannelIdLists.clear();
220 vector<string> sqlResult;
221 while (FetchRow(sqlResult,
false) == eFound) {
222 const int stationId = boost::lexical_cast<
int>(sqlResult[0]);
223 const int channelId = boost::lexical_cast<
int>(sqlResult[1]);
225 unsigned long gpsSecondsComission = 0;
226 unsigned long gpsSecondsDecomission = 0;
227 leapSeconds.
ConvertUnixToGPS(boost::lexical_cast<unsigned long>(sqlResult[2]), gpsSecondsComission);
228 leapSeconds.ConvertUnixToGPS(boost::lexical_cast<unsigned long>(sqlResult[3]), gpsSecondsDecomission);
240 const std::string& componentProperty,
241 const std::string& componentName,
245 if (!(componentName ==
"RChannel" && componentProperty ==
"listOfChannelIds"))
252 const int stationId = boost::lexical_cast<
int>(componentIndex.find(
"station")->second);
253 map<int, ChannelIdList>::const_iterator it = fBufferChannelIdLists.find(stationId);
254 if (it == fBufferChannelIdLists.end()) {
256 it = fBufferChannelIdLists.find(stationId);
258 if (it != fBufferChannelIdLists.end()) {
259 const TimeStamp& curTime = Detector::GetInstance().GetTime();
261 if (!(it->second.fGpsSecondComission <= curTime.
GetGPSSecond() &&
262 it->second.fGpsSecondDecomission > curTime.
GetGPSSecond())) {
263 INFO(
"Time of station list not valid -> rebuffering");
265 it = fBufferChannelIdLists.find(stationId);
267 if (it != fBufferChannelIdLists.end()) {
268 returnData = it->second.fChannelIds;
279 out <<
"Station " << stationId <<
" not found";
294 return VManager::eNotFound;
296 const TimeStamp& curTime = Detector::GetInstance().GetTime();
302 query <<
"select RResponseMapListId from RHardWareAssociation "
303 "where RStationId=" << componentIndex.find(
"station")->second <<
" "
304 "and ChannelId=" << componentIndex.find(
"channel")->second <<
" "
308 if (Query(query.str(), QueryInfoMessage(
"RResponseMapListId",
"ResponseMap")) == eNotFound) {
309 const string err =
"No station_list SQL data found! Query: " + query.str();
313 vector<string> sqlResult;
314 FetchRow(sqlResult,
false);
318 query <<
"select ResponseId, ResponseWeight from ResponseMapList "
319 "where RResponseMapListId=" <<
"\"" << sqlResult[0] <<
"\";";
320 if (Query(query.str(), QueryInfoMessage(
"ResponseId, ResponseWeight",
"ResponseMap")) == eNotFound) {
321 const string err =
"No station_list SQL data found! Query: " + query.str();
326 while (FetchRow(sqlResult,
false) == eFound) {
327 returnData.insert(pair<string, double>(sqlResult[0], boost::lexical_cast<double>(sqlResult[1])));
330 if (returnData.empty())
331 return VManager::eNotFound;
333 return VManager::eFound;
339 const std::string& componentProperty,
340 const std::string& componentName,
345 if (componentProperty !=
"Response")
350 query <<
"select x, dB, Phase from RResponse "
351 "where ResponseId=\"" << componentName <<
"\" "
353 if (Query(query.str(), QueryInfoMessage(
"RResponse",
"RResponse")) == eNotFound) {
354 const string err =
"No station_list SQL data found! Query: " + query.str();
357 vector<string> sqlResult;
358 while (FetchRow(sqlResult,
false) == eFound) {
360 returnData.
PushBack(boost::lexical_cast<float>(sqlResult[0]),
362 boost::lexical_cast<float>(sqlResult[2])));
365 return VManager::eFound;
367 return VManager::eNotFound;
std::pair< std::string, std::string > Index
#define INFO(message)
Macro for logging informational messages.
Status GetDataMap(std::map< std::string, double > &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const
std::string GetInMySQLFormat() const
void Init()
Initialise the registry.
vector< t2list > out
output of the algorithm: a list of clusters
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.
void BufferComponentMap() const
VManager::Status GetComponentFromBuffer(std::string &returnData, const Index &componentIndex, const std::string &componentProperty) const
Class to hold collection (x,y) points and provide interpolation between them, where y are complex num...
void Init(const std::string &configLink)
Manager Initialization. configLink is the CentralConfig hook for the configuration file...
Status GetTFCLAPData(utl::TabulatedFunctionComplexLgAmpPhase &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const
std::map< std::string, std::string > ComponentMap
std::vector< int > fChannelIds
A class to store complex numbers which are internally represented by log10(amplitude) and phase (and ...
void FillComponentMap(const IndexMap &componentIndex) const
unsigned int GetNPoints() const
unsigned long GetGPSSecond() const
GPS second.
void PushBack(const double x, const utl::ComplexLgAmpPhase &y)
unsigned long int fGpsSecondComission
std::map< std::string, std::string > IndexMap
void BufferChannelList() const
Status GetChannelListFromBuffer(std::vector< int > &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const
Manager for RD description of Station-Channels in SQL DB.
#define ERROR(message)
Macro for logging error messages.
Status
Specifies success or (eventually) various possible failure modes.
unsigned long int fGpsSecondDecomission
void ConvertUnixToGPS(const time_t unixSecond, unsigned long &gpsSecond) const
static std::string GetSourceType(const std::string stationIdstring)