AAerosolSQLManager.cc
Go to the documentation of this file.
1 #include <atm/AAerosolSQLManager.h>
2 #include <atm/AManagerRegister.h>
3 #include <det/Detector.h>
4 #include <utl/ErrorLogger.h>
5 #include <utl/TimeStamp.h>
6 #include <utl/AugerException.h>
7 #include <utl/StringCompare.h>
8 
9 #include <boost/lexical_cast.hpp>
10 #include <sstream>
11 
12 using namespace std;
13 using namespace atm;
14 using namespace det;
15 using namespace utl;
16 
17 
18 REGISTER_A_MANAGER("AAerosolSQLManager", AAerosolSQLManager);
19 
20 
21 AAerosolSQLManager::AAerosolSQLManager() :
22  VSQLManager()
23 {
24  fAvailableComponents.insert({
25  "aerosol", "aerosol_zone", "attenuation", "attenuation_lambda", "authors",
26  "db_header", "phase_func", "phase_func_lambda", "software",
27  "zone", "zone_slices"
28  });
29 }
30 
31 
34  const string& columnName,
35  const VManager::IndexMap& componentIndex)
36  const
37 {
38  const utl::TimeStamp detTime = Detector::GetInstance().GetTime();
39 
40  ostringstream query;
41 
42  // aerosol table is a special case, as it requires checking software version
43  if (tableName == "aerosol") {
44 
46 
47  query << "SELECT aerosol_id "
48  "FROM aerosol "
49  "WHERE start_time <= \"" << detTime.GetGPSSecond() << "\" "
50  "AND (end_time > \"" << detTime.GetGPSSecond() << "\" "
51  "OR end_time IS NULL) ORDER BY last_modified DESC, start_time DESC LIMIT 1";
52 
53  } else {
54 
55  query << "SELECT aerosol_id "
56  "FROM aerosol, software "
57  "WHERE start_time <= \"" << detTime.GetGPSSecond() << "\" "
58  "AND (end_time > \"" << detTime.GetGPSSecond() << "\" "
59  "OR end_time IS NULL) "
60  "AND aerosol.software_id = software.software_id "
61  "AND software.software_version = \"" << fDatabaseSoftwareVersion << "\" "
62  "ORDER BY aerosol.last_modified DESC, start_time DESC LIMIT 1";
63  }
64 
65  } else if (tableName == "zone") {
66 
67  if (componentIndex.find("zone_id") == componentIndex.end()) {
68  ERROR("request for zone data called with no zone_id");
69  throw DataNotFoundInDBException("zone", "zone_id", componentIndex,
70  boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
71  }
72  query << "SELECT " << columnName << " "
73  "FROM zone "
74  "WHERE zone_id = " << componentIndex.find("zone_id")->second;
75 
76  } else {
77 
78  if (fAvailableComponents.find(tableName) == fAvailableComponents.end())
79  return eNotFound;
80 
81  // issue queries in form :
82  // SELECT columnName FROM tableName WHERE
83  // componentIndex[0].first = componentIndex[0].second AND
84  // componentIndex[1].first = componentIndex[1].second ...
85 
86  query << "SELECT " << columnName << " "
87  "FROM " << tableName << " "
88  "WHERE " << MergeIndexMap(componentIndex);
89  }
90 
91  // Send the query
92  return Query(query, QueryInfoMessage(tableName, columnName));
93 }
94 
95 
97 AAerosolSQLManager::GetDBResVector(const string& tableName,
98  const string& columnName,
99  const VManager::IndexMap& componentIndex)
100  const
101 {
102  // special case (I think) : get all zones valid for a particular aerosol_id
103 
104  if (tableName == "zone") {
105 
106  // index map must specify the aerosol_id
107  if (componentIndex.find("aerosol_id") == componentIndex.end()) {
108  DEBUGLOG("no aerosol_id specified when looking up zone names");
109  return VManager::eNotFound;
110  }
111 
112  ostringstream query;
113  query << "SELECT zone." << columnName << " FROM zone,aerosol_zone "
114  "WHERE aerosol_id = " << componentIndex.find("aerosol_id")->second << " "
115  "AND aerosol_zone.zone_id = zone.zone_id;";
116 
117  return Query(query, string("vector for ") + QueryInfoMessage(tableName, columnName));
118 
119  } else {
120 
121  if (fAvailableComponents.find(tableName) == fAvailableComponents.end())
122  return eNotFound;
123 
124  ostringstream query;
125  query << "SELECT " << columnName << " "
126  "FROM " << tableName << " "
127  "WHERE " << MergeIndexMap(componentIndex);
128 
129  return Query(query, string("vector for ") + QueryInfoMessage(tableName, columnName));
130 
131  }
132 }
133 
134 
137  const string& /*component*/,
138  const string& /*property*/,
139  const VManager::IndexMap& /*indexMap*/)
140  const
141 {
142  return eNotFound;
143 }
Manager for aerosol portion of atmospheric monitoring database.
virtual Status GetDBResFundamental(const std::string &tableName, const std::string &columnName, const VManager::IndexMap &componentIndex) const
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...
Definition: StringCompare.h:38
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
std::set< std::string > fAvailableComponents
Definition: VManager.h:362
Interface for detector managers that use MySQL.
Exception to use in case requested data not found in the database with detailed printout.
virtual Status GenericGetData(VManager::Handle &returnData, const std::string &component, const std::string &property, const VManager::IndexMap &) const
#define REGISTER_A_MANAGER(_name_, _Type_)
static std::string QueryInfoMessage(const Handle &returnData, const std::string &component)
Definition: VManager.cc:108
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
Status Query(const std::ostringstream &os, const std::string &what="") const
query MySQL
static std::string MergeIndexMap(const IndexMap &componentIndex)
virtual Status GetDBResVector(const std::string &tableName, const std::string &columnName, const VManager::IndexMap &componentIndex) const
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.