AGOESSQLManager.cc
Go to the documentation of this file.
1 #include <atm/AGOESSQLManager.h>
2 
3 #include <det/Detector.h>
4 
5 #include <utl/TimeStamp.h>
6 #include <utl/StringCompare.h>
7 #include <utl/MoonCycle.h>
8 
9 using namespace std;
10 using namespace atm;
11 using namespace det;
12 using namespace utl;
13 
14 
15 REGISTER_A_MANAGER("AGOESSQLManager", AGOESSQLManager);
16 
17 
19 AGOESSQLManager::GetData(map<unsigned int, int>& returnData,
20  const string& tableName,
21  const string& componentName,
22  const IndexMap& /*componentIndex*/)
23  const
24 {
25  if (tableName != "cloud_pixel" || componentName != "cloud_probability") {
26  return eNotFound;
27  }
28 
29  ostringstream query;
30  query << "SELECT pixel_id, cloud_probability ";
31 
32  // Check for a software version specification...
33  if (!utl::StringEquivalent(fDatabaseSoftwareVersion, "default"))
34  query << "FROM cloud_pixel, software "
35  "WHERE cloud_pixel.software_id = software.software_id "
36  "AND software.software_version = \"" << fDatabaseSoftwareVersion
37  << "\" "
38  "AND ";
39  // ...or don't
40  else
41  query << "FROM cloud_pixel WHERE ";
42 
43  const utl::TimeStamp detTime = Detector::GetInstance().GetTime();
44 
45  query << "moon_cycle = "
46  << utl::MoonCycle(detTime).GetFullMoonCycle() << " "
47  "AND start_time <= " << detTime.GetGPSSecond() << " "
48  "AND end_time > " << detTime.GetGPSSecond() << " "
49  "ORDER BY last_modified ASC, start_time ASC";
50 
51  if (Query(query, "what") == eNotFound)
52  return eNotFound;
53 
54  boost::tuple<unsigned int, int> pixelId_prob;
55  returnData.clear();
56 
57  while (FetchRowMany(pixelId_prob, false) == eFound)
58  returnData[pixelId_prob.get<0>()] = pixelId_prob.get<1>();
59 
60  FreeResult();
61 
62  if (returnData.empty())
63  return eNotFound;
64 
65  return eFound;
66 }
67 
68 
70 AGOESSQLManager::GetDBResFundamental(const string& tableName,
71  const string& columnName,
72  const IndexMap& index)
73  const
74 {
75  if (tableName != "cloud_pixel") {
76  return eNotFound;
77  }
78 
79  const utl::TimeStamp detTime = Detector::GetInstance().GetTime();
80 
81  ostringstream query;
82  if (StringEquivalent(fDatabaseSoftwareVersion, "default")) {
83 
84  query << "SELECT " << columnName
85  << " FROM cloud_pixel WHERE"
86  " moon_cycle = "
87  << utl::MoonCycle(detTime).GetFullMoonCycle()
88  << " AND pixel_id = " << index.find("pixel_id")->second
89  << " AND start_time <= " << detTime.GetGPSSecond()
90  << " AND end_time > " << detTime.GetGPSSecond()
91  << " ORDER BY last_modified DESC, start_time DESC LIMIT 1";
92 
93  } else {
94 
95  query << "SELECT " << columnName
96  << " FROM cloud_pixel, software WHERE"
97  " moon_cycle = "
98  << utl::MoonCycle(detTime).GetFullMoonCycle()
99  << " AND pixel_id = " << index.find("pixel_id")->second
100  << " AND start_time <= " << detTime.GetGPSSecond()
101  << " AND end_time > " << detTime.GetGPSSecond()
102  << " and cloud_pixel.software_id = software.software_id"
103  " ORDER BY cloud_pixel.last_modified DESC, cloud_pixel.start_time DESC LIMIT 1";
104  }
105 
106  return Query(query, QueryInfoMessage(tableName, columnName));
107 }
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
#define REGISTER_A_MANAGER(_name_, _Type_)
long GetFullMoonCycle(const LunationEpoch epoch=eJan2004) const
Integer number of full moons since a start date (default = Jan 2004).
Definition: MoonCycle.h:40
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.