10 #include <boost/lexical_cast.hpp>
12 #include <atm/AMolecularSQLManager.h>
13 #include <fwk/CentralConfig.h>
14 #include <det/Detector.h>
15 #include <utl/ErrorLogger.h>
16 #include <utl/TimeStamp.h>
17 #include <utl/Reader.h>
18 #include <utl/AugerException.h>
19 #include <utl/StringCompare.h>
31 AMolecularSQLManager::GetDBResFundamental(
const string& tableName,
32 const string& columnName,
41 if (tableName ==
"molecular") {
45 if (componentIndex.find(
"profile_type_id") == componentIndex.end()) {
46 ERROR(
"Request for data in molecular table does not specify the profile_type_id.");
48 boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
55 const string profileTypeName = componentIndex.find(
"profile_type_name")->second;
61 <<
"SELECT molecular_id "
64 "(SELECT MAX(start_time) FROM molecular "
65 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
66 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\") "
67 "AND profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
68 "ORDER BY last_modified DESC LIMIT 1";
72 <<
"SELECT molecular_id "
73 "FROM molecular, software "
75 "(SELECT MAX(start_time) FROM molecular "
76 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
77 "AND molecular.software_id = software.software_id "
78 "AND software.software_version = \"" << fDatabaseSoftwareVersion <<
"\" "
79 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\") "
80 "AND profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
81 "ORDER BY molecular.last_modified DESC LIMIT 1";
89 <<
"SELECT molecular_id "
92 "(SELECT MAX(start_time) FROM molecular "
93 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
94 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\" "
96 "AND profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
97 "ORDER BY last_modified DESC LIMIT 1";
101 <<
"SELECT molecular_id "
102 "FROM molecular, software "
103 "WHERE start_time = "
104 "(SELECT MAX(start_time) FROM molecular "
105 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
106 "AND molecular.software_id = software.software_id "
107 "AND software.software_version = \"" << fDatabaseSoftwareVersion <<
"\" "
108 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\" "
109 "AND end_time >= \"" << detTime.
GetGPSSecond() <<
"\") "
110 "AND profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
111 "ORDER BY molecular.last_modified DESC LIMIT 1";
119 <<
"SELECT molecular_id "
121 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
122 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\" "
123 "AND (end_time > \"" << detTime.
GetGPSSecond() <<
"\" OR end_time IS NULL) "
124 "ORDER BY last_modified DESC, start_time DESC LIMIT 1";
128 <<
"SELECT molecular_id "
129 "FROM molecular, software "
130 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
131 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\" "
132 "AND (end_time > \"" << detTime.
GetGPSSecond() <<
"\" OR end_time IS NULL) "
133 "AND molecular.software_id = software.software_id "
134 "AND software.software_version = \"" << fDatabaseSoftwareVersion <<
"\" "
135 "ORDER BY molecular.last_modified DESC, start_time DESC LIMIT 1";
140 }
else if (tableName ==
"zone") {
143 if (columnName ==
"zone_id") {
145 <<
"SELECT " << columnName <<
" "
146 "FROM molecular_zone "
147 "WHERE molecular_id = " << componentIndex.find(
"molecular_id")->second;
150 <<
"SELECT " << columnName <<
" "
152 "WHERE zone_id = " << componentIndex.find(
"zone_id")->second;
164 <<
"SELECT " << columnName <<
" "
165 "FROM " << tableName <<
" "
166 "WHERE " << MergeIndexMap(componentIndex);
170 return Query(query, QueryInfoMessage(tableName, columnName));
175 AMolecularSQLManager::GetDBResVector(
const string& tableName,
176 const string& columnName,
185 if (tableName ==
"zone") {
188 if (componentIndex.find(
"molecular_id") == componentIndex.end()) {
189 ERROR(
"no molecular_id specified when looking up zone names");
191 boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
196 <<
"SELECT zone." << columnName <<
" FROM zone, molecular_zone "
197 "WHERE " << MergeIndexMap(componentIndex) <<
" "
198 "AND molecular_zone.zone_id = zone.zone_id";
200 return Query(query,
string(
"vector from ") + QueryInfoMessage(tableName, columnName));
202 }
else if (tableName ==
"molecular") {
213 <<
"SELECT molecular_id "
215 "WHERE start_time = "
216 "(SELECT MAX(start_time) FROM molecular "
217 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
218 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\") "
219 "AND profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
'"';
223 <<
"SELECT molecular_id "
224 "FROM molecular, software "
225 "WHERE start_time = (SELECT MAX(start_time) FROM molecular "
226 "WHERE profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
"\" "
227 "AND molecular.software_id = software.software_id "
228 "AND software.software_version = \"" << fDatabaseSoftwareVersion <<
"\" "
229 "AND start_time <= \"" << detTime.
GetGPSSecond() <<
"\") "
230 "AND profile_type_id = \"" << componentIndex.find(
"profile_type_id")->second <<
'"';
233 return Query(query,
string(
"vector from ") + QueryInfoMessage(tableName, columnName));
239 <<
"SELECT " << columnName <<
" "
240 "FROM " << tableName <<
" "
241 "WHERE " << MergeIndexMap(componentIndex);
243 return Query(query,
string(
"vector from ") + QueryInfoMessage(tableName, columnName));
250 AMolecularSQLManager::GetDBDataCheckTranspose(vector<double>& returnData,
251 const string& tableName,
252 const string& columnName,
256 const unsigned int n = FindComponent<unsigned int>(
"transpose", 0, componentIndex);
258 return VSQLManager::GetDBData(returnData, tableName, columnName, componentIndex);
260 IndexMap newComponentIndex = componentIndex;
261 newComponentIndex.erase(
"transpose");
265 <<
"SELECT " << columnName <<
" "
266 "FROM " << tableName <<
" "
267 "WHERE " << MergeIndexMap(newComponentIndex);
269 if (Query(query,
string(
"transposed vector from ") + QueryInfoMessage(tableName, columnName)) != eFound)
272 return FetchRow(returnData);
Manager for molecular portion of atmospheric monitoring database.
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.
Exception to use in case requested data not found in the database with detailed printout.
#define REGISTER_A_MANAGER(_name_, _Type_)
unsigned long GetGPSSecond() const
GPS second.
std::map< std::string, std::string > IndexMap
#define ERROR(message)
Macro for logging error messages.
Status
Specifies success or (eventually) various possible failure modes.