4 #include <boost/lexical_cast.hpp>
6 #include <fdet/FdUpTimeSQLManager.h>
7 #include <fwk/CentralConfig.h>
8 #include <det/Detector.h>
10 #include <utl/ErrorLogger.h>
11 #include <utl/TimeStamp.h>
12 #include <utl/UTCDateTime.h>
13 #include <utl/Reader.h>
14 #include <utl/TabulatedFunction.h>
15 #include <utl/AugerException.h>
16 #include <utl/ShadowPtr.h>
18 #include <fdet/FManagerRegister.h>
19 #include <fdet/FDetector.h>
21 #include <fdet/Telescope.h>
40 if (fBranch.GetChild(
"verbosity")) {
41 fBranch.GetChild(
"verbosity").GetData(fVerbosity);
42 cout <<
" FdUpTimeSQLeManager verbosity level = " << fVerbosity << endl;
47 fAvailableComponents.insert(
"has_fduptime");
48 fAvailableComponents.insert(
"uptime_gpsStart");
49 fAvailableComponents.insert(
"uptime_gpsStop");
50 fAvailableComponents.insert(
"uptime_fraction");
51 fAvailableComponents.insert(
"status");
52 fAvailableComponents.insert(
"ADCVariance");
53 fAvailableComponents.insert(
"Threshold");
54 fAvailableComponents.insert(
"Baseline");
60 const std::string& componentProperty,
61 const std::string& componentName,
62 const IndexMap& componentIndex)
const {
66 if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
67 return VManager::eNotFound;
70 ERROR(
"******************************************");
71 ERROR(
"* Index not found (gps-second) *");
72 ERROR(
"******************************************");
73 return VManager::eNotFound;
78 info <<
"called GetData(double) for componentName=" << componentName
79 <<
" componentProperty=" << componentProperty <<
" and index map: \n" ;
80 for (IndexMap::const_iterator imap = componentIndex.begin();
81 imap!=componentIndex.end(); imap++) {
82 info <<
" index=\"" << imap->first <<
"\" -> \"" << imap->second <<
"\"\n";
87 if (componentProperty ==
"has_fduptime") {
89 return VManager::eFound;
91 if (componentName==
"channel") {
94 return GetChannelData(returnData, componentProperty, componentName, componentIndex);
96 }
else if(componentName==
"telescope" || componentName==
"eye" || componentName==
"CDAS") {
99 return GetOnTimeFraction(returnData, componentProperty, componentName, componentIndex);
103 return VManager::eNotFound;
108 const std::string& componentProperty,
109 const std::string& componentName,
110 const IndexMap& componentIndex)
const {
115 info <<
"called GetOnTimeFraction for componentName=" << componentName
116 <<
" componentProperty=" << componentProperty <<
" and index map: \n" ;
117 for (IndexMap::const_iterator imap = componentIndex.begin();
118 imap!=componentIndex.end(); imap++) {
119 info <<
" index=\"" << imap->first <<
"\" -> \"" << imap->second <<
"\"\n";
124 if (componentProperty==
"uptime_fraction") {
126 if (componentName==
"telescope") {
128 int dataId = GetTelIndex(componentIndex);
129 map<int, double>::const_iterator iData = fTelescopeOnTimeFraction.find(dataId);
130 if (iData == fTelescopeOnTimeFraction.end()) {
131 INFO_TERSE(
"Requested property of FdUpTimeSQLManager not available!");
132 return VManager::eNotFound;
135 returnData = iData->second;
136 return VManager::eFound;
140 if (componentName==
"eye") {
142 int eyeId = GetEyeIndex(componentIndex);
143 map<int, double>::const_iterator iData = fEyeOnTimeFraction.find(eyeId);
144 if (iData == fEyeOnTimeFraction.end()) {
145 INFO_TERSE(
"Requested property of FdUpTimeSQLManager not available!");
146 return VManager::eNotFound;
149 returnData = iData->second;
150 return VManager::eFound;
154 if (componentName==
"CDAS") {
156 returnData = fCDASOnTimeFraction;
157 return VManager::eFound;
161 return VManager::eNotFound;
166 int FdUpTimeSQLManager::GetEyeIndex(
const IndexMap& componentIndex)
const {
168 IndexMap::const_iterator iEyeId;
169 iEyeId = componentIndex.find(
"eyeId");
170 if (iEyeId == componentIndex.end()) {
172 INFO_TERSE(
"Called FdUpTimeSQLManager with wrong number of arguments!");
177 istringstream ssEyeId(iEyeId->second);
184 int FdUpTimeSQLManager::GetTelIndex(
const IndexMap& componentIndex)
const {
186 IndexMap::const_iterator iEyeId, iTelId;
187 iEyeId = componentIndex.find(
"eyeId");
188 iTelId = componentIndex.find(
"telescopeId");
189 if (iEyeId == componentIndex.end() ||
190 iTelId == componentIndex.end()) {
192 INFO_TERSE(
"Called FdUpTimeSQLManager with wrong number of arguments!");
197 istringstream ssEyeId(iEyeId->second);
199 istringstream ssTelId(iTelId->second);
201 int dataId = (eyeId-1) * 6 + telId;
206 int FdUpTimeSQLManager::GetChannelIndex(
const IndexMap& componentIndex)
const {
208 IndexMap::const_iterator iChannelId;
209 iChannelId = componentIndex.find(
"channelId");
210 if (iChannelId == componentIndex.end()) {
211 INFO_TERSE(
"Called FdUpTimeSQLManager with wrong number of arguments!");
216 istringstream ssChannelId(iChannelId->second);
217 ssChannelId >> channelId;
225 FdUpTimeSQLManager::GetChannelData(
double& returnData,
226 const std::string& componentProperty,
236 info <<
"called GetChannelData with componentProperty=" << componentProperty <<
" and index map: \n" ;
237 for (IndexMap::const_iterator imap = componentIndex.begin();
238 imap!=componentIndex.end(); imap++) {
239 info <<
" index=\"" << imap->first <<
"\" -> \"" << imap->second <<
"\"\n";
244 int dataId = GetTelIndex(componentIndex);
245 int channelId = GetChannelIndex(componentIndex);
249 info <<
" (eye/tel) dataId=" << dataId <<
" channelId=" << channelId
250 <<
" fChannelInfo.size()=" << fChannelInfo.size() <<
" # tels " << endl;
254 map<int, vector<ChannelInfo > >::const_iterator iData = fChannelInfo.find(dataId);
255 if (iData == fChannelInfo.end()) {
256 INFO_TERSE(
"Requested property of FdUpTimeSQLManager not available!");
257 return VManager::eNotFound;
260 const vector<ChannelInfo>& info = iData->second;
263 cout <<
" channel vector size=" << info.size() << endl;
268 if( (
unsigned int)channelId < info.size() ) {
270 if (componentProperty==
"ADCVariance") returnData = info[channelId].Variance;
271 else if (componentProperty==
"Threshold") returnData = info[channelId].Threshold;
272 else if (componentProperty==
"Baseline") returnData = info[channelId].Baseline;
273 else return VManager::eNotFound;
277 cout <<
" VAR=" << returnData << endl;
280 return VManager::eFound;
288 bool FdUpTimeSQLManager::ReadData()
const {
292 INFO(
"enter ReadData ");
295 if (fDataValidity.IsValid()) {
297 INFO(
"Data is still valid ");
302 unsigned int now = det::Detector::GetInstance().GetTime().GetGPSSecond();
305 fEyeOnTimeFraction.clear();
306 fTelescopeOnTimeFraction.clear();
308 fTelescopeStatus.clear();
310 fCDASOnTimeFraction=0.;
311 fChannelInfo.clear();
317 query <<
"SELECT * FROM UptimeTelescope as a, UptimeBin as b WHERE b.GPSStart >= " << now <<
" AND b.GPSStop < " << now;
#define INFO_TERSE(message)
Macro for logging informational messages.
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
#define REGISTER_F_MANAGER(_name_, _Type_)
std::map< std::string, std::string > IndexMap
#define ERROR(message)
Macro for logging error messages.
Status
Specifies success or (eventually) various possible failure modes.