COverrideXMLManager.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <boost/lambda/lambda.hpp>
4 
5 #include <cdet/COverrideXMLManager.h>
6 #include <fwk/CentralConfig.h>
7 #include <det/VManager.h>
8 #include <utl/ErrorLogger.h>
9 #include <utl/Reader.h>
10 #include <cdet/CManagerRegister.h> // needed for registration macro
11 
12 using namespace std;
13 using namespace cdet;
14 using namespace fwk;
15 using namespace std;
16 using namespace utl;
17 using namespace det;
18 using namespace boost::lambda;
19 
20 
21 REGISTER_C_MANAGER("COverrideXMLManager", COverrideXMLManager)
22 
23 
24 template<typename T>
26 COverrideXMLManager::GetOverrideData(T& returnData,
27  const string& componentProperty,
28  const string& componentName,
29  const IndexMap& componentIndex)
30  const
31 {
32  Branch dataB =
33  FindBranch(componentProperty, componentName, componentIndex);
34 
35  if (!dataB)
36  return eNotFound;
37 
38  dataB.GetData(returnData);
39  return eFound;
40 }
41 
42 
44 COverrideXMLManager::GetData(TabulatedFunction& returnData,
45  const string& componentProperty,
46  const string& componentName,
47  const IndexMap& componentIndex)
48  const
49 {
50  Branch dataB =
51  FindBranch(componentProperty, componentName, componentIndex);
52  if (!dataB)
53  return eNotFound;
54 
55  // Since this is tabulated data, retrieve the ordinate and abscissa
56  // It is assumed that the abscissa is labeled 'x' and the ordinate is labeled 'y'
57  Branch xB = dataB.GetChild("x");
58  if (!xB)
59  return eNotFound;
60  vector<double> x;
61  xB.GetData(x);
62 
63  Branch yB = dataB.GetChild("y");
64  if (!yB)
65  return eNotFound;
66  vector<double> y;
67  yB.GetData(y);
68 
69  // As a convenience, scale all ordinate values if a scale factor is given
70  double scaleY;
71  Branch scaleYB = dataB.GetChild("scaleY");
72  if (scaleYB) {
73  scaleYB.GetData(scaleY);
74  for_each(y.begin(), y.end(), _1 *= scaleY);
75  }
76 
77  const unsigned int n = x.size();
78  for (unsigned int i = 0; i < n; ++i)
79  returnData.PushBack(x[i], y[i]);
80 
81  return eFound;
82 }
83 
84 
85 Branch
86 COverrideXMLManager::FindBranch(const string& componentProperty,
87  const string& componentName,
88  const IndexMap& componentIndex)
89  const
90 {
91  if (!fBranch)
92  return fBranch;
93 
94  // Act on the Branch request based on the number of indices specified
95  // Number of indices can be 1 (just the station id), 2 (station and RPC id's)
96 
97  const int nIndices = componentIndex.size();
98 
99  switch (nIndices) {
100  case 1:
101  {
102  // If just 1 index, it had better be the station Id !
103  const IndexMap::const_iterator it = componentIndex.begin();
104  if (it->first != "stationId") {
105  if (IsReportingErrors())
106  INFO(string("If data request is made using one index, "
107  "that index must specify the stationId; ") +
108  QueryInfoMessage(componentProperty, componentName, componentIndex));
109  return Branch();
110  }
111 
112  IndexMap atts;
113  atts["id"] = it->second;
114  Branch stationB = fBranch.GetChild("station", atts);
115  if (!stationB)
116  return Branch();
117 
118  Branch stationComponentB = stationB.GetChild(componentName);
119  if (!stationComponentB)
120  return Branch();
121 
122  Branch stationComponentPropertyB = stationComponentB.GetChild(componentProperty);
123  return stationComponentPropertyB;
124  }
125  case 2:
126  {
127  // Station Id
128  const IndexMap::const_iterator sIt = componentIndex.find("stationId");
129  if (sIt == componentIndex.end()) {
130  if (IsReportingErrors())
131  INFO(string("Request for data using two indices, "
132  "neither of which specifies stationId; ") +
133  QueryInfoMessage(componentProperty, componentName, componentIndex));
134  return Branch();
135  }
136  const string& stationId = sIt->second;
137 
138  // RPC Id
139  const IndexMap::const_iterator pIt = componentIndex.find("RPCId");
140  if (pIt == componentIndex.end()) {
141  if (IsReportingErrors())
142  INFO(string("Request for data using two indices, "
143  "neither of which specifies RPCId; ") +
144  QueryInfoMessage(componentProperty, componentName, componentIndex));
145  return Branch();
146  }
147 
148  IndexMap atts;
149  atts["id"] = stationId;
150  Branch stationB = fBranch.GetChild("station", atts);
151  if (!stationB)
152  return Branch();
153 
154  Branch stationComponentB = stationB.GetChild(componentName);
155  if (!stationComponentB)
156  return Branch();
157 
158  const string& rpcId = pIt->second;
159  IndexMap atts2;
160  atts2["RPCId"] = rpcId;
161 
162  Branch stationComponentPropertyB = stationComponentB.GetChild(componentProperty,atts2);
163  if (!stationComponentPropertyB)
164  return Branch();
165 
166  return stationComponentPropertyB;
167  }
168  case 3:
169  if (IsReportingErrors())
170  INFO(string("Three indices in query: not yet supported; ") +
171  QueryInfoMessage(componentProperty, componentName, componentIndex));
172  return Branch();
173  default:
174  if (IsReportingErrors())
175  INFO(string("Invalid number of parameters specified in component index map; ") +
176  QueryInfoMessage(componentProperty, componentName, componentIndex));
177  return Branch();
178  }
179 }
180 
181 
182 // Configure (x)emacs for this file ...
183 // Local Variables:
184 // mode: c++
185 // End:
Class to hold collection (x,y) points and provide interpolation between them.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Interface for detector managers.
Definition: VManager.h:115
void PushBack(const double x, const double y)
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
Class representing a document branch.
Definition: Branch.h:107
Status
Return code for seek operation.
Definition: IoCodes.h:24
REGISTER_C_MANAGER("CStationListXMLManager", CStationListXMLManager)
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
Manager for SD description in XML &quot;override&quot; files.
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.