ATLAS Offline Software
Loading...
Searching...
No Matches
XMLHandler.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <memory>
10#include <vector>
11
12using namespace xercesc;
13
14
15XMLHandler::XMLHandler(const std::string& n, AGDDController& c)
16 : m_name(n)
17{
18// std::cout<< " creating new handler "<<n<<std::endl;
19 m_stopLoop=false;
21}
22
24{
25 c.GetHandlerStore().RegisterHandler(this);
26}
27
29{
30 m_stopLoop=v;
31}
33{
34 return m_stopLoop;
35}
36bool XMLHandler::isAttribute(const xercesc::DOMNode* t,
37 const std::string& name) const
38{
39 bool res;
40 std::string temp=getAttribute(t, name,res);
41 return res;
42}
43std::string XMLHandler::getAttribute(const xercesc::DOMNode* t,
44 const std::string& name, bool& isPresent) const
45{
46 std::string retValue="";
47 isPresent=false;
48 if (t->hasAttributes()) {
49 DOMNamedNodeMap *pAttributes = t->getAttributes();
50 auto deleter = [&](XMLCh buf[]) { XMLString::release(&buf); };
51 std::unique_ptr<XMLCh[], decltype(deleter)> ptr(XMLString::transcode(name.c_str()), deleter);
52 DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->getNamedItem(ptr.get());
53 if (pAttributeNode) {
54
55 char* val=XMLString::transcode(pAttributeNode->getValue());
56 if (val) {
57
58 isPresent=true;
59 retValue=val;
60 XMLString::release(&val);
61 return retValue;
62 }
63 }
64 else return retValue;
65
66 }
67 return retValue;
68}
70 const xercesc::DOMNode* t,
71 const std::string& name) const
72{
73 bool isPresent;
74 std::string temp=getAttribute(t, name,isPresent);
75 if (!isPresent) std::abort();
76 return temp;
77}
79 const xercesc::DOMNode* t,
80 const std::string& name) const
81{
82 double res=0.;
83 bool isPresent;
84 std::string temp=getAttribute(t, name,isPresent);
85 if (!isPresent) std::abort();
86 res=c.Evaluator().Eval(temp.c_str());
87 return res;
88}
90 const xercesc::DOMNode* t,
91 const std::string& name) const
92{
93 int res=0;
94 bool isPresent;
95 std::string temp=getAttribute(t, name,isPresent);
96 if (!isPresent) std::abort();
97 res=c.Evaluator().Eval(temp.c_str());
98 return res;
99}
101 const xercesc::DOMNode* t,
102 const std::string& name) const
103{
104 bool isPresent;
105 std::vector<double> vect;
106 std::string temp=getAttribute(t, name,isPresent);
107 if (!isPresent) std::abort();
108 std::vector<std::string> v=c.Evaluator().tokenize(";",temp);
109 for (unsigned int i=0;i<v.size();i++)
110 {
111 vect.push_back(c.Evaluator().Eval(v[i].c_str()));
112 }
113 return vect;
114}
115
117 const xercesc::DOMNode* t,
118 const std::string& name) const
119{
120 bool isPresent;
121 std::vector<int> vect;
122 std::string temp=getAttribute(t, name,isPresent);
123 if (!isPresent) std::abort();
124 std::vector<std::string> v=c.Evaluator().tokenize(";",temp);
125 for (unsigned int i=0;i<v.size();i++)
126 {
127 vect.push_back(c.Evaluator().Eval(v[i].c_str()));
128 }
129 return vect;
130}
131
133 const xercesc::DOMNode* t,
134 const std::string& name, bool& isPresent) const
135{
136 std::string temp=getAttribute(t, name,isPresent);
137 return temp;
138}
140 const xercesc::DOMNode* t,
141 const std::string& name, bool& isPresent) const
142{
143 double res=0.;
144 std::string temp=getAttribute(t, name,isPresent);
145 if (isPresent)
146 {
147 res=c.Evaluator().Eval(temp.c_str());
148 }
149 return res;
150}
152 const xercesc::DOMNode* t,
153 const std::string& name, bool& isPresent) const
154{
155 int res=0;
156 std::string temp=getAttribute(t, name,isPresent);
157 if (isPresent)
158 {
159 res=c.Evaluator().Eval(temp.c_str());
160 }
161 return res;
162}
164 const xercesc::DOMNode* t,
165 const std::string& name, bool& isPresent) const
166{
167 std::vector<double> vect;
168 std::string temp=getAttribute(t, name,isPresent);
169 if (isPresent)
170 {
171 std::vector<std::string> v=c.Evaluator().tokenize(";",temp);
172 for (unsigned int i=0;i<v.size();i++)
173 {
174 vect.push_back(c.Evaluator().Eval(v[i].c_str()));
175 }
176 }
177 return vect;
178}
179
181 const xercesc::DOMNode* t,
182 const std::string& name, bool& isPresent) const
183{
184 std::vector<int> vect;
185 std::string temp=getAttribute(t, name,isPresent);
186 if (isPresent)
187 {
188 std::vector<std::string> v=c.Evaluator().tokenize(";",temp);
189 for (unsigned int i=0;i<v.size();i++)
190 {
191 vect.push_back(c.Evaluator().Eval(v[i].c_str()));
192 }
193 }
194 return vect;
195}
196
198 const xercesc::DOMNode* t,
199 const std::string& name, const std::string& def) const
200{
201 bool isPresent;
202 std::string temp=getAttribute(t, name,isPresent);
203 if (isPresent) return temp;
204 else return def;
205}
207 const xercesc::DOMNode* t,
208 const std::string& name, const double def) const
209{
210 bool isPresent;
211 double res=0.;
212 std::string temp=getAttribute(t, name,isPresent);
213 if (isPresent)
214 {
215 res=c.Evaluator().Eval(temp.c_str());
216 return res;
217 }
218 return def;
219}
221 const xercesc::DOMNode* t,
222 const std::string& name, const int def) const
223{
224 bool isPresent;
225 int res=0;
226 std::string temp=getAttribute(t, name,isPresent);
227 if (isPresent)
228 {
229 res=c.Evaluator().Eval(temp.c_str());
230 return res;
231 }
232 return def;
233}
235 const xercesc::DOMNode* t,
236 const std::string& name, const std::vector<double>& def) const
237{
238 bool isPresent;
239 std::vector<double> vect;
240 std::string temp=getAttribute(t, name,isPresent);
241 if (isPresent)
242 {
243 std::vector<std::string> v=c.Evaluator().tokenize(";",temp);
244 for (unsigned int i=0;i<v.size();i++)
245 {
246 vect.push_back(c.Evaluator().Eval(v[i].c_str()));
247 }
248 return vect;
249 }
250 return def;
251}
252
254 const xercesc::DOMNode* t,
255 const std::string& name, const std::vector<int>& def) const
256{
257 bool isPresent;
258 std::vector<int> vect;
259 std::string temp=getAttribute(t, name,isPresent);
260 if (isPresent)
261 {
262 std::vector<std::string> v=c.Evaluator().tokenize(";",temp);
263 for (unsigned int i=0;i<v.size();i++)
264 {
265 vect.push_back(c.Evaluator().Eval(v[i].c_str()));
266 }
267 return vect;
268 }
269 return def;
270}
std::pair< std::vector< unsigned int >, bool > res
void StopLoop(bool)
void RegisterToStore(AGDDController &c)
int getAttributeAsInt(AGDDController &c, const xercesc::DOMNode *t, const std::string &) const
bool isAttribute(const xercesc::DOMNode *t, const std::string &) const
std::vector< double > getAttributeAsVector(AGDDController &c, const xercesc::DOMNode *t, const std::string &) const
std::string m_name
Definition XMLHandler.h:30
bool m_stopLoop
Definition XMLHandler.h:31
std::vector< int > getAttributeAsIntVector(AGDDController &c, const xercesc::DOMNode *t, const std::string &) const
std::string getAttribute(const xercesc::DOMNode *t, const std::string &, bool &) const
double getAttributeAsDouble(AGDDController &c, const xercesc::DOMNode *t, const std::string &) const
bool IsLoopToBeStopped() const
XMLHandler(const std::string &n, AGDDController &c)
std::string getAttributeAsString(AGDDController &c, const xercesc::DOMNode *t, const std::string &) const