ALidarSQLManager.cc
Go to the documentation of this file.
1 
9 #include <sstream>
10 #include <boost/lexical_cast.hpp>
11 
12 #include <atm/ALidarSQLManager.h>
13 #include <det/Detector.h>
14 #include <utl/ErrorLogger.h>
15 #include <utl/TimeStamp.h>
16 #include <utl/AugerException.h>
17 #include <utl/StringCompare.h>
18 
19 using namespace std;
20 using namespace atm;
21 using namespace det;
22 using namespace utl;
23 
24 REGISTER_A_MANAGER("ALidarSQLManager", ALidarSQLManager);
25 
26 
27 ALidarSQLManager::ALidarSQLManager() :
28  VSQLManager()
29 {
30  const char* const tables[] = {
31  "VAOD", "authors", "cloud", "lidar", "lidar_zone", "software",
32  "zone", "zone_slices"
33  };
34  const int n = sizeof(tables) / sizeof(tables[0]);
35  fAvailableComponents.insert(tables, tables + n);
36 }
37 
38 
40 ALidarSQLManager::GetDBResFundamental(const std::string& tableName,
41  const std::string& columnName,
42  const IndexMap& componentIndex)
43  const
44 {
45  const utl::TimeStamp detTime = Detector::GetInstance().GetTime();
46 
47  ostringstream query;
48 
49  // lidar table is a special case, as it requires checking software version
50  if (tableName == "lidar") {
51 
53  // do NOT check software version
54 
55  query << "SELECT lidar_id "
56  "FROM lidar "
57  "WHERE start_time <= \"" << detTime.GetGPSSecond() << "\" "
58  "AND (end_time > \"" << detTime.GetGPSSecond() << "\" "
59  "OR end_time IS NULL) ORDER BY last_modified DESC, start_time DESC LIMIT 1";
60 
61  } else { // DO check software version
62 
63  query << "SELECT lidar_id "
64  "FROM lidar, software "
65  "WHERE start_time <= \"" << detTime.GetGPSSecond() << "\" "
66  "AND (end_time > \"" << detTime.GetGPSSecond() << "\" "
67  "OR end_time IS NULL) "
68  "AND lidar.software_id = software.software_id "
69  "AND software.software_version = \"" << fDatabaseSoftwareVersion << "\" "
70  "ORDER BY lidar.last_modified DESC, start_time DESC LIMIT 1";
71  }
72 
73  } else if (tableName == "zone") {
74 
75  if (componentIndex.find("zone_id") == componentIndex.end()) {
76  ERROR("request for zone data called with no zone_id");
77  throw DataNotFoundInDBException("zone", "zone_id", componentIndex,
78  boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
79  }
80  query << "SELECT " << columnName << " "
81  "FROM zone "
82  "WHERE zone_id = " << componentIndex.find("zone_id")->second;
83 
84  } else {
85 
86  if (fAvailableComponents.find(tableName) == fAvailableComponents.end())
87  return eNotFound;
88 
89  // issue queries in form :
90  // SELECT columnName FROM tableName WHERE
91  // componentIndex[0].first = componentIndex[0].second AND
92  // componentIndex[1].first = componentIndex[1].second
93  // (etc)
94  //
95  query << "SELECT " << columnName << " "
96  "FROM " << tableName << " "
97  "WHERE " << MergeIndexMap(componentIndex);
98  }
99 
100  return Query(query);
101 }
102 
103 
105 ALidarSQLManager::GetDBResVector(const std::string& tableName,
106  const std::string& columnName,
107  const IndexMap& componentIndex)
108  const
109 {
110  if (tableName == "zone") {
111 
112  // index map must specify the lidar_id
113  if (componentIndex.find("lidar_id") == componentIndex.end()) {
114  DEBUGLOG("no lidar_id specified when looking up zone names");
115  return VManager::eNotFound;
116  }
117 
118  ostringstream query;
119  query << "SELECT zone." << columnName << " FROM zone,lidar_zone "
120  "WHERE lidar_id = " << componentIndex.find("lidar_id")->second << " "
121  "AND lidar_zone.zone_id = zone.zone_id;";
122 
123  return Query(query);
124 
125  } else {
126 
127  if (fAvailableComponents.find(tableName) == fAvailableComponents.end())
128  return eNotFound;
129 
130  ostringstream query;
131  query << "SELECT " << columnName << " "
132  "FROM " << tableName << " "
133  "WHERE " << MergeIndexMap(componentIndex);
134 
135  return Query(query);
136 
137  }
138 }
139 
140 
141 // Configure (x)emacs for this file ...
142 // Local Variables:
143 // mode: c++
144 // End:
std::string fDatabaseSoftwareVersion
virtual Status GetDBResFundamental(const std::string &tableName, const std::string &columnName, const IndexMap &componentIndex) const
overload this in all derived managers that need it
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.
#define REGISTER_A_MANAGER(_name_, _Type_)
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
virtual Status GetDBResVector(const std::string &tableName, const std::string &columnName, const IndexMap &componentIndex) const
overload this in all derived managers that need it
Manager for lidar portion of atmospheric monitoring database.
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)
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.