CMS 3D CMS Logo

EcalWeightGroupXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 #include <xercesc/dom/DOMNode.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/parsers/XercesDOMParser.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 
16 
17 using namespace XERCES_CPP_NAMESPACE;
18 using namespace xuti;
19 using namespace std;
20 
24 
26 
27  XercesDOMParser* parser = new XercesDOMParser;
28  parser->setValidationScheme( XercesDOMParser::Val_Never );
29  parser->setDoNamespaces( false );
30  parser->setDoSchema( false );
31 
32  parser->parse(filename.c_str());
33 
34  DOMDocument* xmlDoc = parser->getDocument();
35  if (!xmlDoc) {
36  std::cout << "EcalWeightGroupXMLTranslator::Error parsing document" << std::endl;
37  return -1;
38  }
39 
40  DOMElement* elementRoot = xmlDoc->getDocumentElement();
41 
42  xuti::readHeader(elementRoot,header);
43  // get the first cell node
44  DOMNode * cellnode=getChildNode(elementRoot,Cell_tag);
45 
46  // loop on cell nodes
47  while (cellnode){
48 
49  unsigned int group=0;
50 
51  // read id
52  DetId detid= readCellId(dynamic_cast<DOMElement*> (cellnode));
53 
54  // read constant
55  DOMNode * c_node = getChildNode(cellnode,WeightGroup_tag);
56  GetNodeData(c_node,group);
57 
58  // fill record
59  record[detid]=EcalXtalGroupId(group);
60 
61  // get next cell
62  cellnode= cellnode->getNextSibling();
63 
64  while (cellnode&& cellnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
65  cellnode= cellnode->getNextSibling();
66 
67  }
68 
69  delete parser;
71  return 0;
72 
73 }
74 
76  const EcalCondHeader& header,
79 
80  std::fstream fs(filename.c_str(),ios::out);
81  fs<< dumpXML(header,record);
82 
84 
85  return 0;
86 }
87 
91 
92  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
93 
94  DOMLSSerializer* writer = impl->createLSSerializer();
95  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
96  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
97 
98  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
99  DOMDocument* doc = impl->createDocument( nullptr, cms::xerces::uStr(WeightGroups_tag.c_str()).ptr(), doctype );
100  DOMElement* root = doc->getDocumentElement();
101 
102  xuti::writeHeader(root,header);
103 
104  for (int cellid = EBDetId::MIN_HASH;
106  ++cellid){// loop on EB cells
107 
108  uint32_t rawid= EBDetId::unhashIndex(cellid);
109 
110  //if (!record[rawid]) continue; // cell absent from original record
111 
112  DOMElement* cellnode=writeCell(root,rawid);
113 
114  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
115 
116 
117  } // loop on EB cells
118 
119 
120 
121  for (int cellid = 0;
123  ++cellid){// loop on EE cells
124 
125  if (!EEDetId::validHashIndex(cellid)) continue;
126 
127  uint32_t rawid= EEDetId::unhashIndex(cellid);
128  //xif (!record[rawid]) continue; // cell absent from original record
129 
130 
131  DOMElement* cellnode=writeCell(root,rawid);
132  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
133 
134  } // loop on EE cells
135 
136  std::string dump = cms::xerces::toString( writer->writeToString( root ));
137  doc->release();
138  doctype->release();
139  writer->release();
140 
141  return dump;
142 }
def dumpXML(db, tag, since, filename='dump.xml')
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalWeightXtalGroups &record)
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static bool validHashIndex(int i)
Definition: EEDetId.h:239
const std::string WeightGroup_tag("EcalWeightGroup")
std::string toString(XMLCh const *toTranscode)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
static int readXML(const std::string &filename, EcalCondHeader &header, EcalWeightXtalGroups &record)
static const int MIN_HASH
Definition: EBDetId.h:156
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
const std::string WeightGroups_tag("EcalWeightGroups")
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightXtalGroups &record)
Definition: DetId.h:18
Definition: dump.py:1
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
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const DetId readCellId(xercesc::DOMElement *node)
Assuming.