VZoneSlice.h
Go to the documentation of this file.
1 #ifndef _atm_VZoneSlice_h_
2 #define _atm_VZoneSlice_h_
3 
4 #include <det/VManager.h>
5 #include <det/Detector.h>
6 #include <utl/AugerException.h>
7 
8 #include <string>
9 #include <map>
10 
11 
12 namespace atm {
13 
28  class VZoneSlice {
29 
30  public:
32  double GetMinHeight() const { return fMinHeight; }
33 
35  double GetMaxHeight() const { return fMaxHeight; }
36 
37  protected:
38  VZoneSlice(const std::string& headerDBName,
39  const std::string& zoneSliceId,
40  const std::string& headerZoneIdString,
41  const double minHeight, const double maxHeight) :
42  fHeaderDBName(headerDBName),
43  fZoneSliceIdString(zoneSliceId),
44  fHeaderZoneIdString(headerZoneIdString),
45  fMinHeight(minHeight),
46  fMaxHeight(maxHeight)
47  { }
48 
49  virtual ~VZoneSlice() { }
50 
51  std::string fHeaderDBName; // name of the header table (ie. "aerosol", "molecular", "lidar")
52  std::string fZoneSliceIdString; // identifies slice in the zone
53  std::string fHeaderZoneIdString; // identifies record in aerosol_zone table
54  double fMinHeight;
55  double fMaxHeight;
56 
57  // Helper method to do the redundant work of preparing requests for data contained
58  // an a zone slice, sending it to the manager and reporting any errors.
59  // The errorMsg argument is used to construct some hopefully meaningful error message if the
60  // requested component is not found. It should have a description in some human language
61  // of what was not located.
62 
63  template<typename T>
64  void
65  GetSliceData(T*& requestedData,
66  const std::string& property,
67  const std::string& component,
68  const std::string& errorMsg)
69  const
70  {
71  if (requestedData)
72  return;
73  requestedData = new T;
74 
75  const det::VManager::IndexMap indexMap({
76  { fHeaderDBName + "_zone_id", fHeaderZoneIdString },
77  { "zone_slices_id", fZoneSliceIdString }
78  });
79 
80  try {
81  const det::VManager& manager =
82  det::Detector::GetInstance().GetAManagerRegister();
83 
84  const det::VManager::Status foundFlag =
85  manager.GetData(*requestedData, property, component, indexMap);
86 
87  if (foundFlag == det::VManager::eFound)
88  return;
89  } catch (...) {
90  delete requestedData;
91  requestedData = nullptr;
92  throw;
93  }
94 
95  throw utl::DataNotFoundInDBException(errorMsg);
96  }
97 
98  // Similar to GetSliceData, except that this method is intended for
99  // data stored in attenuation_lambda and phase_func_lambda tables.
100  // Fetching data from these tables requires first retrieving the
101  // appropriate foreign key from the attenuation or phase_func table,
102  // then using this in the query of the attenuation_lambda or
103  // phase_func_lambda table.
104 
105  template<typename T>
106  void
107  GetLambdaSliceData(T*& requestedData,
108  const std::string& zoneTable, // type of zone (eg. attenuation of phase_func)
109  const std::string& foreignKey, // name of foreign key to lambda table (eg. attenuation_lambda_id, phase_func_lambda_id)
110  const std::string& lambdaTable, // name of lambda table (eg. attenuation_lambda, phase_func_lambda)
111  const std::string& column, // column in lambda table (eg att_lambda, f_lambda, ....)
112  const std::string& errorMsg)
113  const
114  {
115  if (requestedData)
116  return;
117  requestedData = new T;
118 
119  const det::VManager::IndexMap indexMap1({
120  { "aerosol_zone_id", fHeaderZoneIdString },
121  { "zone_slices_id", fZoneSliceIdString }
122  });
123 
124  try {
125  const det::VManager& manager =
126  det::Detector::GetInstance().GetAManagerRegister();
127 
128  std::string lambdaIdString;
129  const det::VManager::Status found1 =
130  manager.GetData(lambdaIdString, zoneTable, foreignKey, indexMap1);
131 
132  const det::VManager::IndexMap indexMap2({
133  { lambdaTable + "_id", lambdaIdString }
134  });
135 
136  const det::VManager::Status found2 =
137  manager.GetData(*requestedData, lambdaTable, column, indexMap2);
138 
139  if (found1 == det::VManager::eFound && found2 == det::VManager::eFound)
140  return;
141  } catch (...) {
142  delete requestedData;
143  requestedData = nullptr;
144  throw;
145  }
146 
147  throw utl::DataNotFoundInDBException(errorMsg);
148  }
149 
150  };
151 
152 }
153 
154 
155 #endif
void GetSliceData(T *&requestedData, const std::string &property, const std::string &component, const std::string &errorMsg) const
Definition: VZoneSlice.h:65
std::string fZoneSliceIdString
Definition: VZoneSlice.h:52
void GetLambdaSliceData(T *&requestedData, const std::string &zoneTable, const std::string &foreignKey, const std::string &lambdaTable, const std::string &column, const std::string &errorMsg) const
Definition: VZoneSlice.h:107
double fMaxHeight
Definition: VZoneSlice.h:55
double GetMinHeight() const
Height of the bottom of the slice.
Definition: VZoneSlice.h:32
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
double fMinHeight
Definition: VZoneSlice.h:54
Exception to use in case requested data not found in the database with detailed printout.
double GetMaxHeight() const
Height of the top of the slice.
Definition: VZoneSlice.h:35
Base class for AttSlice and PFSlice.
Definition: VZoneSlice.h:28
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
VZoneSlice(const std::string &headerDBName, const std::string &zoneSliceId, const std::string &headerZoneIdString, const double minHeight, const double maxHeight)
Definition: VZoneSlice.h:38
virtual ~VZoneSlice()
Definition: VZoneSlice.h:49
std::string fHeaderZoneIdString
Definition: VZoneSlice.h:53
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127
std::string fHeaderDBName
Definition: VZoneSlice.h:51

, generated on Tue Sep 26 2023.