AerosolDB.cc
Go to the documentation of this file.
1 #include <sstream>
2 #include <iostream>
3 
4 #include <det/Detector.h>
5 #include <utl/ErrorLogger.h>
6 #include <atm/Atmosphere.h>
7 #include <atm/AerosolZone.h>
8 #include <atm/AerosolDB.h>
9 
10 #include <utl/AugerException.h>
11 
12 using namespace det;
13 using namespace std;
14 using namespace atm;
15 using namespace utl;
16 
17 
18 AerosolDB::AerosolDB()
19 {
20  // Find the id for this AerosolDB
21  // (this is just the primary key in the aerosol table for the given
22  // time, database version, etc.
23  //
24  det::VManager::IndexMap emptyIndexMap;
25 
26  const VManager& manager =
27  Detector::GetInstance().GetAManagerRegister().GetManager("AAerosolSQLManager");
28 
29  const VManager::Status stat =
30  manager.GetData(fAerosolIdString, "aerosol", "aerosol_id", emptyIndexMap);
31 
32  if (stat == VManager::eNotFound) {
33  /*ostringstream msg;
34  msg << "Request for AerosolDB, but no aerosol data available for current time: ";
35  << Detector::GetInstance().GetTime() << ". Returning 0 zones.";
36  WARNING(msg.str());*/
37  return; // return AerosolDB with 0 zones
38  }
39 
40  CacheZones();
41 }
42 
43 
44 void
45 AerosolDB::CacheZones()
46 {
47  // CacheZones should only be invoked when fZoneMap is 0
48  //
49  if (!fZoneMap.empty())
50  ERROR("Call to CacheZones with non-empty fZoneMap. This is a bug .. please report it");
51 
52  //fZoneMap = new InternalZoneMap;
53 
54  const VManager& manager =
55  Detector::GetInstance().GetAManagerRegister().GetManager("AAerosolSQLManager");
56 
57  // Make an AerosolZone object for each zone valid at the current
58  // detector time (and for specified software version, etc.)
59  //
60  vector<string> zoneIdStrings;
61  det::VManager::IndexMap indexMap;
62  indexMap["aerosol_id"] = fAerosolIdString;
63  const VManager::Status stat =
64  manager.GetData(zoneIdStrings, "zone", "zone_id", indexMap);
65  if (stat == VManager::eNotFound) {
66  throw DataNotFoundInDBException("zone", "zone_id", indexMap,
67  boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
68  }
69 
70  for (vector<string>::iterator it = zoneIdStrings.begin();
71  it != zoneIdStrings.end(); ++it) {
72 
73  det::VManager::IndexMap zoneNameIndexMap;
74  zoneNameIndexMap["zone_id"] = *it;
75 
76  string zoneName;
77  manager.GetData(zoneName, "zone", "name", zoneNameIndexMap);
78 
79  double zoneNorthing;
80  manager.GetData(zoneNorthing, "zone", "northing", zoneNameIndexMap);
81 
82  double zoneEasting;
83  manager.GetData(zoneEasting, "zone", "easting", zoneNameIndexMap);
84 
85  const AerosolZone* const aZone =
86  new AerosolZone(*it, fAerosolIdString, zoneName, zoneNorthing, zoneEasting);
87 
88  fZoneMap[zoneName] = aZone;
89  }
90 }
91 
92 AerosolDB::~AerosolDB()
93 {
94  for (InternalZoneIterator it = fZoneMap.begin();
95  it != fZoneMap.end(); ++it)
96  delete it->second;
97 }
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.
InternalZoneMap::const_iterator InternalZoneIterator
Definition: AerosolDB.h:20
Class for storing an hour&#39;s worth of aerosol data.
Definition: AerosolZone.h:27
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
#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.