11 #include <atm/ACloudSQLManager.h>
12 #include <det/Detector.h>
13 #include <utl/ErrorLogger.h>
14 #include <utl/TimeStamp.h>
15 #include <utl/StringCompare.h>
16 #include <utl/MoonCycle.h>
26 ACloudSQLManager::ACloudSQLManager() :
29 const char*
const tables[] = {
30 "authors",
"building_camera",
"cloud_pixel",
31 "db_header",
"software"
33 const int n =
sizeof(tables) /
sizeof(tables[0]);
39 const string& tableName,
40 const string& componentName,
41 const IndexMap& componentIndex)
44 if (tableName !=
"cloud_pixel") {
45 ERROR(
string(
"Cannot handle call for ") +
51 query <<
"SELECT pixel_id, cloud_coverage, start_time, end_time ";
55 query <<
"FROM cloud_pixel, building_camera, software "
56 <<
"WHERE cloud_pixel.building_camera_id = building_camera.building_camera_id "
57 <<
"AND cloud_pixel.software_id = software.software_id "
62 query <<
"FROM cloud_pixel, building_camera "
63 <<
"WHERE cloud_pixel.building_camera_id = building_camera.building_camera_id ";
67 query <<
"AND building_camera.building_number = "
68 << componentIndex.find(
"eyeId")->second <<
" "
69 <<
"AND building_camera.camera_number = "
70 << componentIndex.find(
"telescopeId")->second <<
" "
71 <<
"AND moon_cycle = "
75 <<
"OR end_time IS NULL) "
76 <<
"ORDER BY pixel_id";
81 boost::tuple<int, int, int, int> pixelId_coverage_gpsStart_gpsEnd;
88 rowData.push_back(pixelId_coverage_gpsStart_gpsEnd.get<0>());
89 rowData.push_back(pixelId_coverage_gpsStart_gpsEnd.get<1>());
90 rowData.push_back(pixelId_coverage_gpsStart_gpsEnd.get<2>());
91 rowData.push_back(pixelId_coverage_gpsStart_gpsEnd.get<3>());
92 returnData.push_back(rowData);
102 const std::string& columnName,
111 if (tableName ==
"cloud_pixel") {
113 query <<
"SELECT " << columnName <<
" "
114 <<
"FROM cloud_pixel, building_camera "
115 <<
"WHERE cloud_pixel.building_camera_id = building_camera.building_camera_id ";
119 query <<
"AND software.software_version = \""
120 << fDatabaseSoftwareVersion <<
"\" ";
122 query <<
"AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\" "
123 <<
"AND (end_time > \"" << detTime.
GetGPSSecond() <<
"\" "
124 <<
"OR end_time IS NULL) "
126 <<
"AND building_camera.building_number = "
127 << componentIndex.find(
"eyeId")->second <<
" "
128 <<
"AND building_camera.camera_number = "
129 << componentIndex.find(
"telescopeId")->second <<
" "
130 <<
"AND cloud_pixel.pixel_id = "
131 << componentIndex.find(
"pixelId")->second <<
" "
132 <<
"ORDER BY cloud_pixel.start_time, cloud_pixel.last_modified "
146 query <<
"SELECT " << columnName <<
" "
147 "FROM " << tableName <<
" "
Status FetchRowMany(boost::tuples::cons< TH, TT > &tuple, const bool freeResult=true) const
Get a tuple of values from the first row of an SQLite query result.
virtual Status GetDBResFundamental(const std::string &tableName, const std::string &columnName, const IndexMap &componentIndex) const
overload this in all derived managers that need it
std::string fDatabaseSoftwareVersion
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.
std::set< std::string > fAvailableComponents
Interface for detector managers that use MySQL.
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
#define REGISTER_A_MANAGER(_name_, _Type_)
static std::string QueryInfoMessage(const Handle &returnData, const std::string &component)
long GetFullMoonCycle(const LunationEpoch epoch=eJan2004) const
Integer number of full moons since a start date (default = Jan 2004).
unsigned long GetGPSSecond() const
GPS second.
Manager for cloudy portion of atmospheric monitoring database.
std::map< std::string, std::string > IndexMap
Status Query(const std::ostringstream &os, const std::string &what="") const
query MySQL
static std::string MergeIndexMap(const IndexMap &componentIndex)
Status
Specifies success or (eventually) various possible failure modes.