4 #include <boost/lexical_cast.hpp>
6 #include <fdet/FOpticalEfficiencyLossSQLManager.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>
38 FOpticalEfficiencyLossSQLManager::GetData(
double& ,
49 FOpticalEfficiencyLossSQLManager::GetData(map<int, utl::TabulatedFunction>& returnData,
50 const string& componentProperty,
51 const string& componentName,
52 const IndexMap& componentIndex)
56 if (componentName !=
"fd_optical_efficiency")
61 if (componentProperty ==
"pixel_optical_efficiency_corrections") {
62 const fdet::FDetector& fdet = det::Detector::GetInstance().GetFDetector();
65 const string& eyeIdString = componentIndex.find(
"eyeId")->second;
66 const string& telescopeIdString = componentIndex.find(
"telescopeId")->second;
67 const unsigned int eyeId = boost::lexical_cast<
unsigned int>(eyeIdString);
68 const unsigned int telId = boost::lexical_cast<
unsigned int>(telescopeIdString);
70 double opticalEff = 0;
71 if (GetOpticalEfficiencyCorrectionForTelescope(eyeId, telId, opticalEff)) {
73 for (
int iPix = 1; iPix <= 440; ++iPix) {
75 effVsWavelength.
PushBack(wavelength, opticalEff);
76 returnData.insert(make_pair(iPix, effVsWavelength));
88 FOpticalEfficiencyLossSQLManager::GetOpticalEfficiencyCorrectionForTelescope(
const unsigned int eyeId,
89 const unsigned int telId,
93 const TimeStamp detTime = Detector::GetInstance().GetTime();
95 const string tel = ConvertEyeTelToTelId(eyeId, telId);
97 ostringstream queryBefore;
98 ostringstream queryAfter;
100 boost::tuple<double, int> before;
101 boost::tuple<double, int> after;
103 queryBefore <<
"SELECT " << tel <<
", GPSsecond FROM constants, software WHERE constants.GPSsecond <= \"" << gpsSecond
104 <<
"\" AND constants.software_id = software.software_id AND software.software_version = \"" << fDatabaseSoftwareVersion
105 <<
"\" AND constants." << tel <<
" IS NOT NULL ORDER BY constants.GPSsecond DESC, constants.constants_id DESC LIMIT 1";
107 if ( Query(queryBefore) != eNotFound ) {
108 if ( FetchRowMany(before) == eNotFound ) {
115 queryAfter <<
"SELECT " << tel <<
", GPSsecond FROM constants, software WHERE constants.GPSsecond > \"" << gpsSecond
116 <<
"\" AND constants.software_id = software.software_id AND software.software_version = \"" << fDatabaseSoftwareVersion
117 <<
"\" AND constants." << tel <<
" IS NOT NULL ORDER BY constants.GPSsecond, constants.constants_id DESC LIMIT 1";
119 if ( Query(queryAfter) != eNotFound ) {
120 if ( FetchRowMany(after) == eNotFound ) {
127 if (before.get<1>() != 0 && after.get<1>() != 0) {
128 if ((gpsSecond - before.get<1>()) < (after.get<1>()-gpsSecond)) {
129 value = before.get<0>();
131 value = after.get<0>();
133 }
else if (before.get<1>() != 0) {
134 value = before.get<0>();
135 }
else if (after.get<1>() != 0) {
136 value = after.get<0>();
147 FOpticalEfficiencyLossSQLManager::GetData(vector<int>& returnData,
148 const string& componentProperty,
149 const string& componentName,
154 if (componentProperty !=
"status" || componentName !=
"fd_optical_efficiency")
157 returnData.resize(441, 0);
163 FOpticalEfficiencyLossSQLManager::GetData(
int& returnData,
164 const string& componentProperty,
165 const string& componentName,
166 const IndexMap& componentIndex)
170 if (componentName !=
"fd_optical_efficiency")
173 const TimeStamp detTime = Detector::GetInstance().GetTime();
176 const string& eyeIdString = componentIndex.find(
"eyeId")->second;
177 const string& telescopeIdString = componentIndex.find(
"telescopeId")->second;
178 const unsigned int eyeId = boost::lexical_cast<
unsigned int>(eyeIdString);
179 const unsigned int telId = boost::lexical_cast<
unsigned int>(telescopeIdString);
180 string tel = ConvertEyeTelToTelId(eyeId, telId);
182 ostringstream queryBefore;
183 ostringstream queryAfter;
185 vector<unsigned int> GPSbefore;
186 vector<unsigned int> GPSafter;
188 queryBefore <<
"SELECT GPSsecond FROM constants, software WHERE constants.GPSsecond <= \"" << gpsSecond
189 <<
"\" AND constants.software_id = software.software_id AND software.software_version = \"" << fDatabaseSoftwareVersion
190 <<
"\" AND constants." << tel <<
" IS NOT NULL ORDER BY constants.GPSsecond DESC, constants.constants_id DESC LIMIT 2";
192 if ( Query(queryBefore) != eNotFound ) {
193 FetchColumn(GPSbefore);
196 queryAfter <<
"SELECT GPSsecond FROM constants, software WHERE constants.GPSsecond > \"" << gpsSecond
197 <<
"\" AND constants.software_id = software.software_id AND software.software_version = \"" << fDatabaseSoftwareVersion
198 <<
"\" AND constants." << tel <<
" IS NOT NULL ORDER BY constants.GPSsecond, constants.constants_id DESC LIMIT 2";
200 if ( Query(queryAfter) != eNotFound ) {
201 FetchColumn(GPSafter);
217 GPSbefore.resize(2, veryEarly);
218 GPSafter.resize(2, veryLate);
222 if ( (gpsSecond - GPSbefore[0]) < (GPSafter[0] - gpsSecond) ) {
223 if (GPSbefore[1] == veryEarly) {
224 GPSstart = veryEarly;
226 GPSstart = (GPSbefore[1]+GPSbefore[0])/2;
229 GPSend = (GPSbefore[0]+GPSafter[0])/2;
231 GPSstart = (GPSbefore[0]+GPSafter[0])/2;
233 if (GPSafter[1] == veryLate) {
236 GPSend = (GPSafter[0]+GPSafter[1])/2;
240 if (GPSbefore[0] == veryEarly) {
241 GPSstart = veryEarly;
243 if (GPSafter[0] == veryLate) {
247 if (componentProperty ==
"start_time") {
248 returnData = GPSstart;
252 if (componentProperty ==
"end_time") {
261 FOpticalEfficiencyLossSQLManager::ConvertEyeTelToTelId(
const int eyeId,
266 tel <<
"Tel" << (eyeId-1)*6+telId;
Class to hold collection (x,y) points and provide interpolation between them.
void Init()
Initialise the registry.
void PushBack(const double x, const double y)
Detector description interface for FDetector-related data.
A TimeStamp holds GPS second and nanosecond for some event.
double GetReferenceLambda() const
unsigned long GetGPSSecond() const
GPS second.
#define REGISTER_F_MANAGER(_name_, _Type_)
TimeStamp GetTimeStamp() const
Status
Specifies success or (eventually) various possible failure modes.
Manager for FD optical efficiency correction constants read from SQL database.