CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalPedestalsXMLTranslator.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 
17 
18 using namespace XERCES_CPP_NAMESPACE;
19 using namespace xuti;
20 using namespace std;
21 
24 
25  XercesDOMParser* parser = new XercesDOMParser;
26  parser->setValidationScheme(XercesDOMParser::Val_Never);
27  parser->setDoNamespaces(false);
28  parser->setDoSchema(false);
29 
30  parser->parse(filename.c_str());
31 
32  DOMDocument* xmlDoc = parser->getDocument();
33  if (!xmlDoc) {
34  std::cout << "EcalPedestalsXMLTranslator::Error parsing document" << std::endl;
35  return -1;
36  }
37 
38  DOMElement* elementRoot = xmlDoc->getDocumentElement();
39 
40  xuti::readHeader(elementRoot, header);
41 
42  DOMNode* cellnode = getChildNode(elementRoot, Cell_tag);
43 
44  int chan = 0;
45  while (cellnode) {
46  // std::cout << " Channel " << chan << std::endl;
47  float mean12 = 0;
48  float mean6 = 0;
49  float mean1 = 0;
50  float rms12 = 0;
51  float rms6 = 0;
52  float rms1 = 0;
53  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
54  // std::cout << " readCell Id Channel " << chan << " tag " << mean12_tag << std::endl;
55 
56  DOMNode* mean12_node = getChildNode(cellnode, mean12_tag);
57  GetNodeData(mean12_node, mean12);
58  // std::cout << " tag " << mean12_tag << " mean12 " << mean12 << std::endl;
59 
60  DOMNode* mean6_node = getChildNode(cellnode, mean6_tag);
61  GetNodeData(mean6_node, mean6);
62  // std::cout << " tag " << mean6_tag << " mean6 " << mean6 << std::endl;
63 
64  DOMNode* mean1_node = getChildNode(cellnode, mean1_tag);
65  GetNodeData(mean1_node, mean1);
66  // std::cout << " tag " << mean1_tag << " mean1 " << mean1 << std::endl;
67 
68  DOMNode* rms12_node = getChildNode(cellnode, rms12_tag);
69  GetNodeData(rms12_node, rms12);
70  // std::cout << " tag 12 " << rms12_tag << " rms 12 " << rms12 << std::endl;
71 
72  DOMNode* rms6_node = getChildNode(cellnode, rms6_tag);
73  GetNodeData(rms6_node, rms6);
74  // std::cout << " tag 6 " << rms6_tag << " rms 6 " << rms6 << std::endl;
75 
76  DOMNode* rms1_node = getChildNode(cellnode, rms1_tag);
77  // std::cout << " tag 1 " << rms1_tag << std::endl;
78 
79  GetNodeData(rms1_node, rms1);
80  // std::cout << " Channel " << chan << " mean12 " << mean12 << " rms 1 " << rms1 << std::endl;
81  record[detid].mean_x12 = mean12;
82  record[detid].mean_x6 = mean6;
83  record[detid].mean_x1 = mean1;
84  record[detid].rms_x12 = rms12;
85  record[detid].rms_x6 = rms6;
86  record[detid].rms_x1 = rms1;
87 
88  cellnode = cellnode->getNextSibling();
89 
90  while (cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
91  cellnode = cellnode->getNextSibling();
92  chan++;
93  }
94 
95  delete parser;
97  std::cout << " nb of channels found in xml file " << chan << std::endl;
98  return 0;
99 }
100 
102  const EcalCondHeader& header,
103  const EcalPedestals& record) {
105 
106  std::fstream fs(filename.c_str(), ios::out);
107  fs << dumpXML(header, record);
108 
110 
111  return 0;
112 }
113 
115  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
116 
117  DOMLSSerializer* writer = impl->createLSSerializer();
118  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
119  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
120 
121  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
122  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(Pedestals_tag.c_str()).ptr(), doctype);
123 
124  DOMElement* root = doc->getDocumentElement();
125 
126  xuti::writeHeader(root, header);
127  if (record.barrelItems().empty())
128  return std::string();
129  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
130  uint32_t rawid = EBDetId::unhashIndex(cellid);
131 
132  if (record.find(rawid) == record.end())
133  continue;
134  if (!record[rawid].mean_x12 && !record[rawid].rms_x12)
135  continue;
136 
137  DOMElement* cellnode = writeCell(root, rawid);
138 
139  WriteNodeWithValue(cellnode, mean12_tag, record[rawid].mean_x12);
140  WriteNodeWithValue(cellnode, mean6_tag, record[rawid].mean_x6);
141  WriteNodeWithValue(cellnode, mean1_tag, record[rawid].mean_x1);
142  WriteNodeWithValue(cellnode, rms12_tag, record[rawid].rms_x12);
143  WriteNodeWithValue(cellnode, rms6_tag, record[rawid].rms_x6);
144  WriteNodeWithValue(cellnode, rms1_tag, record[rawid].rms_x1);
145  }
146 
147  if (record.endcapItems().empty())
148  return std::string();
149  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
150  if (!EEDetId::validHashIndex(cellid))
151  continue;
152 
153  uint32_t rawid = EEDetId::unhashIndex(cellid);
154 
155  if (record.find(rawid) == record.end())
156  continue;
157  if (!record[rawid].mean_x12 && !record[rawid].rms_x12)
158  continue;
159 
160  DOMElement* cellnode = writeCell(root, rawid);
161 
162  WriteNodeWithValue(cellnode, mean12_tag, record[rawid].mean_x12);
163  WriteNodeWithValue(cellnode, mean6_tag, record[rawid].mean_x6);
164  WriteNodeWithValue(cellnode, mean1_tag, record[rawid].mean_x1);
165  WriteNodeWithValue(cellnode, rms12_tag, record[rawid].rms_x12);
166  WriteNodeWithValue(cellnode, rms6_tag, record[rawid].rms_x6);
167  WriteNodeWithValue(cellnode, rms1_tag, record[rawid].rms_x1);
168  }
169 
170  std::string dump = cms::xerces::toString(writer->writeToString(root));
171  doc->release();
172  doctype->release();
173  writer->release();
174 
175  return dump;
176 }
const std::string mean12_tag("mean_x12")
static int readXML(const std::string &filename, EcalCondHeader &header, EcalPedestals &record)
void xercesTerminate()
Definition: Xerces.cc:23
tuple chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, &quot;NDC&quot;) lumi.SetBorderSize( 0 ) lumi...
const Items & barrelItems() const
void xercesInitialize()
Definition: Xerces.cc:18
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
const std::string mean1_tag("mean_x1")
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
static std::string dumpXML(const EcalCondHeader &header, const EcalPedestals &record)
std::string toString(XMLCh const *toTranscode)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
static const int MIN_HASH
Definition: EBDetId.h:149
const std::string Cell_tag("cell")
const std::string Pedestals_tag("EcalPedestals")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
Definition: DetId.h:17
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 mean6_tag("mean_x6")
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
tuple filename
Definition: lut2db_cfg.py:20
const_iterator find(uint32_t rawId) const
const std::string rms12_tag("rms_x12")
const std::string rms6_tag("rms_x6")
tuple cout
Definition: gather_cfg.py:144
const_iterator end() const
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const Items & endcapItems() const
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalPedestals &record)
const std::string rms1_tag("rms_x1")
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
tuple dump
OutputFilePath = cms.string(&#39;/tmp/zhokin/&#39;), OutputFileExt = cms.string(&#39;&#39;),.