MolecularDB.cc
Go to the documentation of this file.
1 #include <sstream>
2 #include <iostream>
3 #include <boost/lexical_cast.hpp>
4 
5 #include <det/Detector.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/AugerException.h>
8 #include <atm/Atmosphere.h>
9 #include <atm/MolecularZone.h>
10 #include <atm/MolecularDB.h>
11 
12 using namespace det;
13 using namespace std;
14 using namespace atm;
15 using namespace utl;
16 
17 
18 const string MolecularDB::fgProfileNameLookup[MolecularIds::eUSStdA+1] = {
19  "weather station",
20  "radiosonde data",
21  "Malargue January model",
22  "Malargue February model",
23  "Malargue March model",
24  "Malargue April model",
25  "Malargue May model",
26  "Malargue June model",
27  "Malargue July model",
28  "Malargue August model",
29  "Malargue September model",
30  "Malargue October model",
31  "Malargue November model",
32  "Malargue December model",
33  "Malargue GDAS data",
34  "US-StdA"
35 };
36 
37 
38 MolecularDB::MolecularDB(const MolecularIds::ProfileId id) :
39  fZoneMap(),
40  fProfileId(id)
41 {
42  //Detector::GetInstance().GetTime();
43  const VManager& manager =
44  Detector::GetInstance().GetAManagerRegister().GetManager("AMolecularSQLManager");
45 
46  // find the profile_type_id
47  VManager::IndexMap profileIndexMap;
48  profileIndexMap["profile_type_name"] = string("'") + fgProfileNameLookup[id] + string("'");
49  string profileTypeIdString;
50  const VManager::Status stat1 =
51  manager.GetData(profileTypeIdString, "profile_type", "profile_type_id", profileIndexMap);
52  if (stat1 == VManager::eNotFound) {
53  ostringstream msg;
54  msg << "Request for table 'profile_type' with profile_type_name '"
55  << profileIndexMap["profile_type_name"] << "' not found.";
56  WARNING(msg);
57  return; // return MolecularDB with 0 zones
58  }
59 
60  VManager::IndexMap molecularIndexMap;
61  molecularIndexMap["profile_type_id"] = profileTypeIdString;
62  // molecularIndexMap["profile_type_name"] = fgProfileNameLookup[id];
63 
64 
65  const VManager::Status stat2 =
66  manager.GetData(fMolecularIdStrings, "molecular", "molecular_id", molecularIndexMap);
67  if (stat2 == VManager::eNotFound) {
68  ostringstream msg;
69  msg << "Request for table 'molecular' with profile_type_id '"
70  << molecularIndexMap["profile_type_id"] << "' turned up with no data "
71  "for time: " << Detector::GetInstance().GetTime() << ". "
72  "Returning 0 zones.";
73  WARNING(msg);
74  return; // return MolecularDB with 0 zones
75  }
76 
77  // for (vector<string>::iterator sIt = fMolecularIdStrings.begin() ;
78  // sIt != fMolecularIdStrings.end(); ++sIt) {
79  // cout << " " << *sIt << endl;
80  // }
81 
82  CacheZones();
83 }
84 
85 
86 void
88 {
89  // CacheZones should only be invoked when fZoneMap is 0
90  //
91  if (!fZoneMap.empty())
92  ERROR("Call to CacheZones with non-empty fZoneMap. This is a bug .. please report it.");
93 
94  //fZoneMap = new InternalZoneMap;
95 
96  const VManager& manager =
97  Detector::GetInstance().GetAManagerRegister().GetManager("AMolecularSQLManager");
98 
99  // Make an MolecularZone object for each zone valid at the current
100  // detector time (and for specified software version, etc.)
101  //
102 
103  for (unsigned int i = 0; i < fMolecularIdStrings.size(); ++i) {
104  string zoneIdString;
105  VManager::IndexMap indexMap;
106  indexMap["molecular_id"] = fMolecularIdStrings[i];
107 
108  const VManager::Status stat =
109  manager.GetData(zoneIdString, "zone", "zone_id", indexMap);
110  if (stat == VManager::eNotFound)
111  throw DataNotFoundInDBException("zone", "zone_id", indexMap,
112  boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
113 
114  VManager::IndexMap zoneNameIndexMap;
115  zoneNameIndexMap["zone_id"] = zoneIdString;
116 
117  string zoneName;
118  manager.GetData(zoneName, "zone", "name", zoneNameIndexMap);
119 
120  double zoneNorthing;
121  manager.GetData(zoneNorthing, "zone", "northing", zoneNameIndexMap);
122 
123  double zoneEasting;
124  manager.GetData(zoneEasting, "zone", "easting", zoneNameIndexMap);
125 
126  const MolecularZone* const aZone =
127  new MolecularZone(zoneIdString, fMolecularIdStrings[i],
128  zoneName, zoneNorthing, zoneEasting);
129 
130  fZoneMap[zoneName] = aZone;
131  }
132 }
133 
134 
136 {
137  for (InternalZoneIterator it = fZoneMap.begin();
138  it != fZoneMap.end(); ++it)
139  delete it->second;
140 }
std::vector< std::string > fMolecularIdStrings
Definition: MolecularDB.h:71
static const std::string fgProfileNameLookup[MolecularIds::eLast+1]
Definition: MolecularDB.h:75
InternalZoneMap::const_iterator InternalZoneIterator
Definition: MolecularDB.h:35
Interface for detector managers.
Definition: VManager.h:115
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
Exception to use in case requested data not found in the database with detailed printout.
ProfileId
Monitoring profiles:
Definition: MolecularIds.h:8
class describing a molecular zone.
Definition: MolecularZone.h:33
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
US standard atmosphere.
Definition: MolecularIds.h:41
InternalZoneMap fZoneMap
Definition: MolecularDB.h:37
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.