FModelsXMLManager.cc
Go to the documentation of this file.
1 #include <boost/lambda/lambda.hpp>
2 
3 #include <fdet/FModelsXMLManager.h>
4 #include <fwk/CentralConfig.h>
5 #include <det/VManager.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/Reader.h>
8 #include <fdet/FManagerRegister.h> // needed for registration macro
9 
10 using namespace std;
11 using namespace fdet;
12 using namespace utl;
13 using namespace det;
14 using namespace boost::lambda;
15 
16 
17 REGISTER_F_MANAGER("FModelsXMLManager", FModelsXMLManager)
18 
19 
20 void
21 FModelsXMLManager::Init(const string& configLink)
22 {
23  VManager::Init(configLink);
24  FillMaps();
25 }
26 
27 
28 // Generic data getters
29 // --------------------
30 template<typename T>
32 FModelsXMLManager::GetModelData(T& returnData,
33  const string& componentProperty,
34  const string& componentName,
35  const IndexMap& componentIndex)
36  const
37 {
38  // Find where requested data resides in DOM
39  Branch dataBranch =
40  FindBranch(componentProperty, componentName, componentIndex);
41 
42  if (!dataBranch)
43  return VManager::eNotFound;
44 
45  // Extract data from the branch
46  dataBranch.GetData(returnData);
47 
48  // Found the data. To be returned as type T
49  return VManager::eFound;
50 }
51 
52 
54 FModelsXMLManager::GetTabulatedModelData(TabulatedFunction& tabulatedReturnData,
55  const string& componentProperty,
56  const string& componentName,
57  const IndexMap& componentIndex)
58  const
59 {
60  // Find where requested data resides in DOM
61  Branch dataBranch =
62  FindBranch(componentProperty, componentName, componentIndex);
63 
64  if (!dataBranch)
65  return VManager::eNotFound;
66 
67  // Since this is tabulated data, retrieve the ordinate and abscissa
68  // NOTE THAT IT IS ASSUMED THAT THE ABSCISSA IS LABELED "x" AND
69  // THE ORDINATE IS LABELED "y"
70  Branch abscissaBranch = dataBranch.GetChild("x");
71  if (!abscissaBranch)
72  return VManager::eNotFound;
73  vector<double> abscissaVector;
74  abscissaBranch.GetData(abscissaVector);
75 
76  Branch ordinateBranch = dataBranch.GetChild("y");
77  if (!ordinateBranch)
78  return VManager::eNotFound;
79  vector<double> ordinateVector;
80  ordinateBranch.GetData(ordinateVector);
81 
82  // As a convenience, scale all ordinate values if a scale factor is given
83  double scaleY;
84  Branch scaleYBranch = dataBranch.GetChild("scaleY");
85  if (scaleYBranch) {
86  scaleYBranch.GetData(scaleY);
87  for_each(ordinateVector.begin(), ordinateVector.end(), _1 *= scaleY);
88  }
89 
90  for (unsigned int i = 0; i < abscissaVector.size(); ++i)
91  tabulatedReturnData.PushBack(abscissaVector[i], ordinateVector[i]);
92 
93  return VManager::eFound;
94 }
95 
96 
102 Branch
103 FModelsXMLManager::FindBranch(const string& componentProperty,
104  const string& modelType,
105  const IndexMap& componentIndex)
106  const
107 {
108 
109  string telescopeId;
110  //string eyeId;
111  //string pmtId; // pixel or channel (NOT USED)
112 
113  // Act on the Branch request based on the number of indices specified
114  // Number of indices can be 1 (just the telescope id), 2 (telescope and
115  // mirror segment id's) or 3 (telescope, mirror segment, ... )
116  //
117  //int nIndices = componentIndex.size();
118 
119  // The component attribute map is currently used in cases where a mirror
120  // segment index is specified (that is we have differing data applying
121  // different to mirror segments in a telescope).
122  //
123  const IndexMap::const_iterator iterTel = componentIndex.find("telescopeId");
124  const IndexMap::const_iterator iterEye = componentIndex.find("eyeId");
125  // const IndexMap::const_iterator iterPixel = componentIndex.find("pixelId");
126 
127  if (iterTel == componentIndex.end() ||
128  iterEye == componentIndex.end()) {
129 
130  if (IsReportingErrors()) {
131  INFO(string("Request with two indices, "
132  "none of them specifies 'telescopeId' and 'eyeId'; ") +
133  QueryInfoMessage(componentProperty, modelType, componentIndex));
134  }
135 
136  } else {
137 
138  // condensed stupid index
139  telescopeId = iterEye->second + " " + iterTel->second;
140  }
141 
142  IndexMap componentAtts;
143 
144  const IndexMap::const_iterator iterMirrorSeg = componentIndex.find("mirrorSegmentId");
145  if (iterMirrorSeg != componentIndex.end())
146  componentAtts["mirrorSegmentId"] = iterMirrorSeg->second;
147 
148  const IndexMap::const_iterator iterCorrectorId = componentIndex.find("correctorId");
149  if (iterCorrectorId != componentIndex.end())
150  componentAtts["size"] = iterCorrectorId->second;
151 
152  IndexMap modelMap;
153  const map<string, IndexMap>::const_iterator iModelMap = fTelescopeModelMap.find(telescopeId);
154  if (iModelMap != fTelescopeModelMap.end())
155  modelMap = iModelMap->second;
156 
157  string modelId;
158  const IndexMap::const_iterator iModelId = modelMap.find(modelType);
159  if (iModelId != modelMap.end())
160  modelId = iModelId->second;
161 
162  // Get the requested data from the DOM
163  IndexMap atts;
164  atts["id"] = modelId;
165 
166  if (!fBranch)
167  return fBranch;
168 
169  Branch modelsB = fBranch.GetChild("telescopeModels");
170  if (!modelsB)
171  return modelsB;
172 
173  Branch modelB = modelsB.GetChild(modelType, atts);
174  if (!modelB)
175  return modelB;
176 
177  // First, attempt to find the dataB without providing componentAtts map
178  // to further specify a component. componentAtts is currently used to
179  // identify a particular mirror segment in a telescope or to
180  // distinguish between telescope with and without corrector lens.
181  Branch dataB = modelB.GetChild(componentProperty);
182 
183  // If no data found when no componentAtts specified, specify the
184  // componentAtts.
185  // This will find data unique to a PMT in the tank
186  if (!dataB)
187  dataB = modelB.GetChild(componentProperty, componentAtts);
188 
189  return dataB;
190 }
191 
192 
193 void
194 FModelsXMLManager::FillMaps()
195 {
196  // fill fTelescopeIdMap from DetectorConfig file
197  // Parse information between <telescopeConfig> tags and fill
198  // fTelescopeModelMap
199  Branch configB = fBranch.GetChild("telescopeConfig");
200 
201  // loop on prototypes
202  for (Branch protoB = configB.GetFirstChild();
203  protoB; protoB = protoB.GetNextSibling()) {
204 
205  Branch modelsB = protoB.GetChild("models");
206  // loop on models
207  IndexMap modelMap;
208  for (Branch modelB = modelsB.GetFirstChild();
209  modelB; modelB = modelB.GetNextSibling()) {
210 
211  IndexMap atts = modelB.GetAttributes();
212  modelMap[modelB.GetName()] = atts.find("id")->second;
213 
214  }
215 
216  // loop on eyes (to which this model applies)
217  Branch eyesB = protoB.GetChild("eyes");
218  for (Branch eyeB = eyesB.GetFirstChild();
219  eyeB; eyeB = eyeB.GetNextSibling()) {
220 
221  IndexMap atts = eyeB.GetAttributes();
222  const string eyeIdString = atts.find("id")->second;
223 
224  // loop on telescopes (to which this model applies)
225  Branch telescopesB = eyeB.GetChild("telescopes");
226  for (Branch telB = telescopesB.GetFirstChild();
227  telB; telB = telB.GetNextSibling()) {
228 
229  IndexMap atts2 = telB.GetAttributes();
230  const string telescopeIdString =
231  eyeIdString + " " + atts2.find("id")->second;
232 
233  // write an entry in map<Id, map<model type, model id> >
234  fTelescopeModelMap[telescopeIdString] = modelMap;
235  }
236  }
237  }
238 }
Class to hold collection (x,y) points and provide interpolation between them.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
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
AttributeMap GetAttributes() const
Get a map&lt;string, string&gt; containing all the attributes of this Branch.
Definition: Branch.cc:267
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
Class representing a document branch.
Definition: Branch.h:107
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
if(dataRoot)
Definition: XXMLManager.h:1003
#define REGISTER_F_MANAGER(_name_, _Type_)
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127
Manager for FD description in XML &quot;model&quot; files.

, generated on Tue Sep 26 2023.