4 #include <boost/lexical_cast.hpp>
6 #include <fdet/FCalibSQLManager.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>
17 #include <utl/StringCompare.h>
19 #include <fdet/FManagerRegister.h>
20 #include <fdet/FDetector.h>
22 #include <fdet/Telescope.h>
38 fEyesToIgnore.clear();
40 if (fBranch.GetChild(
"eyesToIgnore"))
41 fBranch.GetChild(
"eyesToIgnore").GetData(fEyesToIgnore);
45 FCalibSQLManager::GetData(
double& returnData,
46 const string& componentProperty,
47 const string& componentName,
48 const IndexMap& componentIndex)
53 if (componentProperty ==
"pixel_t_offset") {
55 const int pixeltoffsetid = GetPixelTOffsetId(componentIndex);
56 if (!pixeltoffsetid) {
57 ERROR(
"Could not retrieve pixel_t_offset_id");
62 query <<
"SELECT pixel_t_offset FROM pixel_t_offset "
63 "WHERE pixel_t_offset_id = " << pixeltoffsetid;
65 return (Query(query, QueryInfoMessage(componentProperty, componentName)) == eNotFound) ?
66 eNotFound : FetchRow(returnData);
68 }
else if (componentProperty ==
"elecgain" || componentProperty ==
"status") {
70 const IndexMap::const_iterator pIt = componentIndex.find(
"pixelId");
71 if (pIt == componentIndex.end()) {
72 if (IsReportingErrors())
73 ERROR(
"'pixelId' not found for " + QueryInfoMessage(componentProperty, componentName));
77 const string& pixelId = pIt->second;
81 if (componentName ==
"fd_calib") {
83 query <<
"SELECT " << componentProperty <<
" FROM pixel_calib "
84 "WHERE working_calib_id = " << GetWorkingCalibId(componentIndex) <<
" "
85 "AND pixel_number = " << pixelId;
87 }
else if (componentName ==
"low_gain_calib") {
89 const int pixel = boost::lexical_cast<
int>(pixelId);
91 const unsigned int telId = boost::lexical_cast<
unsigned int>(componentIndex.find(
"telescopeId")->second);
93 det::Detector::GetInstance().GetFDetector().GetEye(componentIndex.find(
"eyeId")->second);
96 query <<
"SELECT elec_gain FROM low_gain_channel "
97 "WHERE working_calib_id = " << GetWorkingCalibId(componentIndex) <<
" "
102 ERROR(
string(
"Can not handle call for ") + QueryInfoMessage(componentProperty, componentName));
106 return (Query(query, QueryInfoMessage(componentProperty, componentName)) == eNotFound) ?
107 eNotFound : FetchRow(returnData);
115 FCalibSQLManager::GetData(map<int, utl::TabulatedFunction>& returnData,
116 const string& componentProperty,
117 const string& componentName,
118 const IndexMap& componentIndex)
123 if (componentProperty !=
"pixel_calibs") {
124 ERROR(
string(
"Can not handle call for ") + QueryInfoMessage(componentProperty, componentName));
128 if (fEyesToIgnore.size() > 0) {
130 istringstream eyeIds(componentIndex.find(
"eyeId")->second);
133 for (vector<unsigned int>::const_iterator it = fEyesToIgnore.begin(); it != fEyesToIgnore.end(); it++) {
139 const int workingCalibId = GetWorkingCalibId(componentIndex);
141 if (workingCalibId < 0) {
142 ERROR(
"Could not retrieve working_calib_id");
148 query <<
"SELECT pixel_number, wavelength, cal_const FROM pixel_wavelength_calib, pixel_calib "
149 "WHERE pixel_calib.working_calib_id = " << workingCalibId <<
" "
150 "AND pixel_wavelength_calib.pixel_calib_id = pixel_calib.pixel_calib_id";
152 if (Query(query, QueryInfoMessage(componentProperty, componentName)) == eNotFound)
155 const unsigned int numCols = NumFields();
158 ERROR(
"Found wrong number of rows in the pixel calibration query!");
167 boost::tuple<int, double, double> pixelNumber_wavelength_calConst;
169 while (FetchNextRowMany(pixelNumber_wavelength_calConst) == eFound) {
171 const int& pixelNumber = pixelNumber_wavelength_calConst.get<0>();
173 if (pixelNumber != curPix) {
175 returnData.insert(make_pair(curPix, *calVsWavelength));
178 curPix = pixelNumber;
181 const double& wavelength = pixelNumber_wavelength_calConst.get<1>();
182 const double& calConst = pixelNumber_wavelength_calConst.get<2>();
188 returnData.insert(make_pair(curPix, *calVsWavelength));
195 FCalibSQLManager::GetData(
int& returnData,
196 const string& componentProperty,
197 const string& componentName,
198 const IndexMap& componentIndex)
202 if (componentProperty !=
"start_time" && componentProperty !=
"end_time") {
203 ERROR(
string(
"Can not handle call for ") + QueryInfoMessage(componentProperty, componentName));
208 query <<
"SELECT " << componentProperty <<
" FROM working_calib "
209 "WHERE working_calib_id = " << GetWorkingCalibId(componentIndex);
211 if (Query(query) == eNotFound)
214 if (FetchRow(returnData) == eFound)
218 query <<
"SELECT start_time "
219 "FROM working_calib, software, building_camera "
220 "WHERE working_calib.building_camera_id = building_camera.building_camera_id "
221 "AND building_camera.building_number = " << componentIndex.find(
"eyeId")->second <<
" "
222 "AND building_camera.camera_number = " << componentIndex.find(
"telescopeId")->second;
226 "AND working_calib.software_id = software.software_id "
227 "AND software.software_version = '" << fDatabaseSoftwareVersion <<
'\'';
229 const TimeStamp detTime = Detector::GetInstance().GetTime();
231 "AND working_calib.start_time > '"<< detTime.
GetGPSSecond()<<
"' "
232 "ORDER BY working_calib.start_time, working_calib.last_modified DESC "
235 if (Query(query, QueryInfoMessage(componentProperty, componentName)) == eNotFound)
238 if (FetchRow(returnData) == eNotFound)
247 FCalibSQLManager::GetData(vector<int>& returnData,
248 const string& componentProperty,
249 const string& componentName,
250 const IndexMap& componentIndex)
253 if (componentProperty !=
"status" || componentName !=
"fd_calib")
260 query <<
"SELECT pixel_number, status FROM pixel_calib "
261 "WHERE working_calib_id = " << GetWorkingCalibId(componentIndex)
262 <<
" ORDER BY pixel_number DESC";
264 if (Query(query) == eNotFound)
267 boost::tuple<int, int> pixelId_status;
268 if (FetchRowMany(pixelId_status,
false) != eFound)
271 const int maxPixelId = pixelId_status.get<0>();
274 returnData.resize(maxPixelId + 1, -1);
275 returnData[maxPixelId] = pixelId_status.get<1>();
277 while (FetchRowMany(pixelId_status,
false) == eFound)
278 returnData[pixelId_status.get<0>()] = pixelId_status.get<1>();
287 FCalibSQLManager::GetWorkingCalibId(
const IndexMap& componentIndex)
290 const TimeStamp detTime = Detector::GetInstance().GetTime();
294 const string& eyeId = componentIndex.find(
"eyeId")->second;
295 const string& telescopeId = componentIndex.find(
"telescopeId")->second;
300 query <<
"SELECT working_calib_id "
301 "FROM working_calib LEFT JOIN building_camera "
302 "ON working_calib.building_camera_id=building_camera.building_camera_id ";
305 query <<
" LEFT JOIN software "
306 "ON working_calib.software_id = software.software_id ";
308 query <<
"WHERE building_camera.building_number = " << eyeId <<
" "
309 "AND building_camera.camera_number = " << telescopeId <<
" "
310 "AND working_calib.start_time <= \""<< detTime.
GetGPSSecond() <<
"\" "
311 "AND (working_calib.end_time > \"" << detTime.
GetGPSSecond() <<
"\" "
312 "OR working_calib.end_time IS NULL) ";
315 query <<
"AND software.software_version = \"" << fDatabaseSoftwareVersion <<
'"';
317 query <<
" ORDER BY working_calib.last_modified DESC, working_calib.start_time DESC, working_calib_id DESC "
329 if ( Query(query) != eNotFound )
339 FCalibSQLManager::GetPixelTOffsetId(
const IndexMap& componentIndex)
342 const int workingCalibId = GetWorkingCalibId(componentIndex);
343 const string& pixelId = componentIndex.find(
"pixelId")->second;
346 query <<
"SELECT pixel_t_offset_id FROM pixel_calib "
347 "WHERE working_calib_id = " << workingCalibId <<
" "
348 "AND pixel_number = " << pixelId;
351 if (Query(query, QueryInfoMessage(
"pixel_calib",
"pixel_t_offset_id")) == eFound)
359 FCalibSQLManager::FindAvailableWavelengths(
const int pixelCalibId)
363 query <<
"SELECT wavelength FROM pixel_wavelength_calib "
364 "WHERE pixel_calib_id = " << pixelCalibId;
366 vector<double> retWavelengths;
368 if (Query(query, QueryInfoMessage(
"pixel_wavelength_calib",
"wavelength")) == eFound)
369 FetchColumn(retWavelengths);
371 return retWavelengths;
pointer with built-in initialization, deletion, deep copying
Class to hold collection (x,y) points and provide interpolation between them.
void Init()
Initialise the registry.
Detector description interface for Eye-related data.
void PushBack(const double x, const double y)
bool StringEquivalent(const std::string &a, const std::string &b, Predicate p)
Utility to compare strings for equivalence. It takes a predicate to determine the equivalence of indi...
A TimeStamp holds GPS second and nanosecond for some event.
constexpr double nanometer
unsigned int GetLastPixelId() const
Detector description interface for Telescope-related data.
unsigned long GetGPSSecond() const
GPS second.
#define REGISTER_F_MANAGER(_name_, _Type_)
std::map< std::string, std::string > IndexMap
#define ERROR(message)
Macro for logging error messages.
TimeStamp GetTimeStamp() const
Status
Specifies success or (eventually) various possible failure modes.
Manager for FD calibration and monitoring data residing in MySQL database.