CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions | Static Private Member Functions
EcalTBWeightsXMLTranslator Class Reference

#include <EcalTBWeightsXMLTranslator.h>

Static Public Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalTBWeights &record)
 
static int readXML (const std::string &filename, EcalCondHeader &header, EcalTBWeights &record)
 
static int writeXML (const std::string &filename, const EcalCondHeader &header, const EcalTBWeights &record)
 

Static Private Member Functions

static void readWeightSet (xercesc::DOMNode *parentNode, EcalWeightSet &ws)
 
static void writeChi2WeightMatrix (xercesc::DOMNode *node, const EcalWeightSet::EcalChi2WeightMatrix &matrix)
 
static void writeWeightMatrix (xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
 
static void writeWeightSet (xercesc::DOMNode *parentNode, const EcalWeightSet &ws)
 

Detailed Description

Translates a EcalTBWeights record to XML and vice versa

Author
Stefano ARGIRO
Version
Id:
EcalTBWeightsXMLTranslator.h,v 1.2 2009/06/30 14:40:11 argiro Exp
Date
21 Aug 2008

Definition at line 22 of file EcalTBWeightsXMLTranslator.h.

Member Function Documentation

std::string EcalTBWeightsXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalTBWeights record 
)
static

Definition at line 353 of file EcalTBWeightsXMLTranslator.cc.

References asciidump::doc, hcal_timing_source_file_cfg::dump, xuti::EcalTBWeight_tag(), xuti::EcalTBWeights_tag(), xuti::EcalTDCId_tag(), xuti::EcalXtalGroupId_tag(), xuti::fromNative(), EcalTBWeights::getMap(), dbtoconf::root, AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), xuti::writeHeader(), and xuti::WriteNodeWithValue().

Referenced by cond::PayLoadInspector< DataT >::dump(), and cond::PayLoadInspector< DataT >::summary().

354  {
355 
356 
357  XMLPlatformUtils::Initialize();
358 
359  DOMImplementation* impl =
360  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
361 
362  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
363  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
364 
365  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
366  DOMDocument * doc =
367  impl->createDocument( 0, fromNative(EcalTBWeights_tag).c_str(), doctype );
368 
369 
370  doc->setEncoding(fromNative("UTF-8").c_str() );
371  doc->setStandalone(true);
372  doc->setVersion(fromNative("1.0").c_str() );
373 
374 
375  DOMElement* root = doc->getDocumentElement();
376  xuti::writeHeader(root, header);
377 
378 
379  const EcalTBWeights::EcalTBWeightMap wmap= record.getMap();
380 
381  EcalTBWeights::EcalTBWeightMap::const_iterator it ;
382  for (it =wmap.begin(); it!=wmap.end(); ++it){
383 
384  DOMElement * tbweight= doc->createElement(fromNative(EcalTBWeight_tag).c_str());
385  root->appendChild(tbweight);
386 
387  EcalXtalGroupId gid = it->first.first;
388  EcalTBWeights::EcalTDCId tid = it->first.second;
389  EcalWeightSet ws = it->second;
390 
392  WriteNodeWithValue(tbweight,EcalTDCId_tag, tid);
393  writeWeightSet(tbweight,ws);
394 
395 
396  } //
397 
398  std::string dump= toNative(writer->writeToString(*root));
399  doc->release();
400 
401  // XMLPlatformUtils::Terminate();
402 
403  return dump;
404 }
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
Definition: EcalTBWeights.h:19
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
const std::string EcalTBWeights_tag("EcalTBWeights")
const std::string EcalTBWeight_tag("EcalTBWeight")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
tuple doc
Definition: asciidump.py:381
static void writeWeightSet(xercesc::DOMNode *parentNode, const EcalWeightSet &ws)
const std::string EcalXtalGroupId_tag("EcalXtalGroupId")
const EcalTBWeightMap & getMap() const
Definition: EcalTBWeights.h:29
XercesString fromNative(const char *str)
Definition: XercesString.h:31
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
const std::string EcalTDCId_tag("EcalTDCId")
string root
initialization
Definition: dbtoconf.py:70
void EcalTBWeightsXMLTranslator::readWeightSet ( xercesc::DOMNode *  parentNode,
EcalWeightSet ws 
)
staticprivate

Definition at line 95 of file EcalTBWeightsXMLTranslator.cc.

References xuti::fromNative(), EcalWeightSet::getChi2WeightsAfterGainSwitch(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), xuti::getChildNode(), EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), i, xuti::id_tag(), xuti::row_tag(), AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), histoStyle::weight, xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), and xuti::wgtChi2BeforeSwitch_tag().

96  {
97 
98 
99 
100  // get the first cell node
101  DOMNode * wgtBSnode=getChildNode(parentNode,wgtBeforeSwitch_tag);
102  DOMNode * wgtASnode=getChildNode(parentNode,wgtAfterSwitch_tag);
103  DOMNode * wgtChi2BSnode=getChildNode(parentNode,wgtChi2BeforeSwitch_tag);
104  DOMNode * wgtChi2ASnode=getChildNode(parentNode,wgtChi2AfterSwitch_tag);
105 
106 
107  DOMNode* rownode = getChildNode(wgtBSnode,row_tag);
108 
109  DOMElement* rowelement=0;
110 
111  // loop on row nodes
112  while (rownode){
113 
114  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
115 
116  std::string rowid_s = toNative(rowelement->getAttribute(fromNative(id_tag).c_str()));
117 
118  std::stringstream rowid_ss(rowid_s);
119  int rowid = 0;
120  rowid_ss >> rowid;
121 
122  std::string weightrow = toNative(rownode->getTextContent());
123 
124  std::stringstream weightrow_s(weightrow);
125  double weight = 0;
126  int i = 0;
127  while(weightrow_s >> weight){
128  ws.getWeightsBeforeGainSwitch()(rowid,i)= weight;
129  i++;
130 
131  }
132 
133 
134  // get next cell
135  rownode = rownode->getNextSibling();
136 
137  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
138  rownode = rownode->getNextSibling();
139 
140 
141  }
142 
143  rownode = getChildNode(wgtASnode,row_tag);
144 
145  // loop on row nodes
146  while (rownode){
147 
148  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
149 
150  std::string rowid_s = toNative(rowelement->getAttribute( fromNative(id_tag).c_str()));
151 
152  std::stringstream rowid_ss(rowid_s);
153  int rowid = 0;
154  rowid_ss >> rowid;
155 
156  std::string weightrow = toNative(rownode->getTextContent());
157 
158  std::stringstream weightrow_s(weightrow);
159  double weight = 0;
160  int i = 0;
161  while(weightrow_s >> weight){
162  ws.getWeightsAfterGainSwitch()(rowid,i)= weight;
163  i++;
164  }
165 
166 
167  // get next cell
168  rownode = rownode->getNextSibling();
169 
170  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
171  rownode = rownode->getNextSibling();
172 
173 
174  }
175 
176  rownode = getChildNode(wgtChi2BSnode,row_tag);
177 
178 
179  // loop on row nodes
180  while (rownode){
181 
182  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
183  std::string rowid_s = toNative(rowelement->getAttribute(fromNative(id_tag).c_str()));
184 
185  std::stringstream rowid_ss(rowid_s);
186  int rowid = 0;
187  rowid_ss >> rowid;
188 
189  std::string weightrow = toNative(rownode->getTextContent());
190 
191  std::stringstream weightrow_s(weightrow);
192  double weight = 0;
193  int i = 0;
194  while(weightrow_s >> weight)
195  {
196  ws.getChi2WeightsBeforeGainSwitch()(rowid,i)= weight;
197  i++;
198  }
199 
200 
201  // get next cell
202  rownode = rownode->getNextSibling();
203 
204  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
205  rownode = rownode->getNextSibling();
206 
207 
208  }
209 
210 
211  rownode = getChildNode(wgtChi2ASnode,row_tag);
212 
213 
214  // loop on row nodes
215  while (rownode){
216 
217  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
218  std::string rowid_s = toNative(rowelement->getAttribute(fromNative(id_tag).c_str()));
219 
220  std::stringstream rowid_ss(rowid_s);
221  int rowid = 0;
222  rowid_ss >> rowid;
223 
224  std::string weightrow = toNative(rownode->getTextContent());
225 
226  std::stringstream weightrow_s(weightrow);
227  double weight = 0;
228  int i = 0;
229  while(weightrow_s >> weight){
230  ws.getChi2WeightsAfterGainSwitch()(rowid,i)= weight;
231  i++;
232  }
233 
234 
235  // get next cell
236  rownode = rownode->getNextSibling();
237 
238  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
239  rownode = rownode->getNextSibling();
240 
241 
242  }
243 
244 
245 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:29
int i
Definition: DBlmapReader.cc:9
const std::string id_tag("id")
const std::string row_tag("row")
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:30
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:28
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:27
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
XercesString fromNative(const char *str)
Definition: XercesString.h:31
int weight
Definition: histoStyle.py:50
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
int EcalTBWeightsXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalTBWeights record 
)
static

Definition at line 35 of file EcalTBWeightsXMLTranslator.cc.

References gather_cfg::cout, xuti::EcalTBWeight_tag(), xuti::EcalTDCId_tag(), xuti::EcalWeightSet_tag(), xuti::EcalXtalGroupId_tag(), xuti::getChildNode(), xuti::GetNodeData(), geometryXMLtoCSV::parser, xuti::readHeader(), and EcalTBWeights::setValue().

37  {
38 
39  XMLPlatformUtils::Initialize();
40 
41  XercesDOMParser* parser = new XercesDOMParser;
42  parser->setValidationScheme( XercesDOMParser::Val_Never );
43  parser->setDoNamespaces( false );
44  parser->setDoSchema( false );
45 
46  parser->parse(filename.c_str());
47 
48  DOMDocument* xmlDoc = parser->getDocument();
49  if (!xmlDoc) {
50  std::cout << "EcalTBWeightsXMLTranslator::Error parsing document" << std::endl;
51  return -1;
52  }
53 
54  DOMElement* elementRoot = xmlDoc->getDocumentElement();
55  xuti::readHeader(elementRoot, header);
56 
57  DOMNode * wnode=getChildNode(elementRoot,EcalTBWeight_tag);
58 
59  while (wnode){
60 
61  DOMNode * gid_node = getChildNode(wnode,EcalXtalGroupId_tag);
62  DOMNode * tdc_node = getChildNode(wnode,EcalTDCId_tag);
63  DOMNode * ws_node = getChildNode(wnode,EcalWeightSet_tag);
64 
65  EcalXtalGroupId gid;
67  EcalWeightSet ws;
68 
69  GetNodeData(gid_node,gid);
70  GetNodeData(tdc_node,tid);
71 
72  readWeightSet(ws_node,ws);
73 
74  record.setValue(gid,tid,ws);
75 
76  wnode= wnode->getNextSibling();
77 
78  while (wnode&& wnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
79  wnode= wnode->getNextSibling();
80  }
81 
82  return 0;
83 }
const std::string EcalWeightSet_tag("EcalWeightSet")
void setValue(const EcalXtalGroupId &groupId, const EcalTDCId &tdcId, const EcalWeightSet &weight)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string EcalTBWeight_tag("EcalTBWeight")
static void readWeightSet(xercesc::DOMNode *parentNode, EcalWeightSet &ws)
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
const std::string EcalXtalGroupId_tag("EcalXtalGroupId")
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
const std::string EcalTDCId_tag("EcalTDCId")
void EcalTBWeightsXMLTranslator::writeChi2WeightMatrix ( xercesc::DOMNode *  node,
const EcalWeightSet::EcalChi2WeightMatrix matrix 
)
staticprivate

Definition at line 316 of file EcalTBWeightsXMLTranslator.cc.

References xuti::fromNative(), i, xuti::id_tag(), gen::k, makeMuonMisalignmentScenario::matrix, and xuti::row_tag().

317  {
318 
319  DOMElement* row=0;
320  DOMAttr* rowid=0;
321  DOMText* rowvalue=0;
322 
323  const int ncols =10;
324  const int nrows =10;
325 
326  for(int i=0;i<nrows;++i)
327  {
328 
329 
330  row= node->getOwnerDocument()->createElement( fromNative(row_tag).c_str());
331  node->appendChild(row);
332 
333  stringstream value_s;
334  value_s << i;
335 
336  rowid = node->getOwnerDocument()->createAttribute(fromNative(id_tag).c_str());
337  rowid ->setValue(fromNative(value_s.str()).c_str());
338  row ->setAttributeNode(rowid);
339 
340  stringstream row_s;
341 
342  for(int k=0;k<ncols;++k) row_s << " "<< matrix(i,k)<<" ";
343 
344  rowvalue =
345  node->getOwnerDocument()->createTextNode(fromNative(row_s.str()).c_str());
346  row->appendChild(rowvalue);
347  }//for loop on col
348 
349 
350 }
int i
Definition: DBlmapReader.cc:9
const std::string id_tag("id")
const std::string row_tag("row")
tuple node
Definition: Node.py:50
int k[5][pyjets_maxn]
XercesString fromNative(const char *str)
Definition: XercesString.h:31
void EcalTBWeightsXMLTranslator::writeWeightMatrix ( xercesc::DOMNode *  node,
const EcalWeightSet::EcalWeightMatrix matrix 
)
staticprivate

Definition at line 278 of file EcalTBWeightsXMLTranslator.cc.

References xuti::fromNative(), i, xuti::id_tag(), gen::k, makeMuonMisalignmentScenario::matrix, and xuti::row_tag().

279  {
280 
281  DOMElement* row=0;
282  DOMAttr* rowid=0;
283  DOMText* rowvalue=0;
284 
285  const int ncols =10;
286  const int nrows =3;
287 
288  for(int i=0;i<nrows;++i)
289  {
290 
291 
292  row= node->getOwnerDocument()->createElement( fromNative(row_tag).c_str());
293  node->appendChild(row);
294 
295  stringstream value_s;
296  value_s << i;
297 
298  rowid = node->getOwnerDocument()->createAttribute(fromNative(id_tag).c_str());
299  rowid ->setValue(fromNative(value_s.str()).c_str());
300  row ->setAttributeNode(rowid);
301 
302  stringstream row_s;
303 
304  for(int k=0;k<ncols;++k) row_s <<" " << matrix(i,k)<<" " ;
305 
306  rowvalue =
307  node->getOwnerDocument()->createTextNode(fromNative(row_s.str()).c_str());
308  row->appendChild(rowvalue);
309  }//for loop on col
310 
311 
312 }
int i
Definition: DBlmapReader.cc:9
const std::string id_tag("id")
const std::string row_tag("row")
tuple node
Definition: Node.py:50
int k[5][pyjets_maxn]
XercesString fromNative(const char *str)
Definition: XercesString.h:31
void EcalTBWeightsXMLTranslator::writeWeightSet ( xercesc::DOMNode *  parentNode,
const EcalWeightSet ws 
)
staticprivate

Definition at line 248 of file EcalTBWeightsXMLTranslator.cc.

References asciidump::doc, xuti::EcalWeightSet_tag(), xuti::fromNative(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), and xuti::wgtChi2BeforeSwitch_tag().

249  {
250 
251 
252  xercesc::DOMDocument* doc = parentNode->getOwnerDocument();
253 
254  DOMElement * weightsetel= doc->createElement( fromNative(EcalWeightSet_tag).c_str());
255  parentNode-> appendChild(weightsetel);
256 
257  DOMElement* wgtBS = doc->createElement( fromNative(wgtBeforeSwitch_tag).c_str());
258  weightsetel->appendChild(wgtBS);
259 
260  DOMElement* wgtAS = doc->createElement(fromNative(wgtAfterSwitch_tag).c_str());
261  weightsetel->appendChild(wgtAS);
262 
263  DOMElement* wgtChi2BS = doc->createElement( fromNative(wgtChi2BeforeSwitch_tag).c_str());
264  weightsetel->appendChild(wgtChi2BS);
265 
266  DOMElement* wgtChi2AS = doc->createElement(fromNative(wgtChi2AfterSwitch_tag).c_str());
267  weightsetel->appendChild(wgtChi2AS);
268 
271 
274 
275 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:29
const std::string EcalWeightSet_tag("EcalWeightSet")
static void writeWeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
tuple doc
Definition: asciidump.py:381
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:28
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:27
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
static void writeChi2WeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalChi2WeightMatrix &matrix)
XercesString fromNative(const char *str)
Definition: XercesString.h:31
int EcalTBWeightsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalTBWeights record 
)
static

Definition at line 85 of file EcalTBWeightsXMLTranslator.cc.

References EcalCondTools::dumpXML(), and dbtoconf::out.

87  {
88  std::fstream fs(filename.c_str(),ios::out);
89  fs<< dumpXML(header,record);
90  return 0;
91 }
static std::string dumpXML(const EcalCondHeader &header, const EcalTBWeights &record)
tuple out
Definition: dbtoconf.py:99
tuple filename
Definition: lut2db_cfg.py:20