CMS 3D CMS Logo

List of all members | Static Public Member Functions | Static Private Member Functions
EcalPulseShapesXMLTranslator Class Reference

#include <EcalPulseShapesXMLTranslator.h>

Static Public Member Functions

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

Static Private Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalPulseShapes &record)
 

Detailed Description

Translates a EcalGainRatio record to XML and vice versa

Author
Francesco RUBBO
Version
Id
EcalPulseShapesXMLTranslator.h,v 0 2010/04/26 fay Exp
Date
26 Apr 2010

Definition at line 15 of file EcalPulseShapesXMLTranslator.h.

Member Function Documentation

◆ dumpXML()

std::string EcalPulseShapesXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalPulseShapes record 
)
staticprivate

Definition at line 131 of file EcalPulseShapesXMLTranslator.cc.

References hcalRecHitTable_cff::doc, GCP_Ntuples_cfg::dump, RecoTauValidation_cfi::header, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, EBDetId::MIN_HASH, xuti::PulseShapes_tag(), AlCaHarvesting_cff::record, xuti::sample0_tag(), xuti::sample10_tag(), xuti::sample11_tag(), xuti::sample1_tag(), xuti::sample2_tag(), xuti::sample3_tag(), xuti::sample4_tag(), xuti::sample5_tag(), xuti::sample6_tag(), xuti::sample7_tag(), xuti::sample8_tag(), xuti::sample9_tag(), AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and convertToRaw::writer.

131  {
132  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
133 
134  DOMLSSerializer* writer = impl->createLSSerializer();
135  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
136  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
137 
138  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
139  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(PulseShapes_tag.c_str()).ptr(), doctype);
140 
141  DOMElement* root = doc->getDocumentElement();
142 
144  if (record.barrelItems().empty())
145  return std::string();
146  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
147  uint32_t rawid = EBDetId::unhashIndex(cellid);
148 
149  if (record.find(rawid) == record.end())
150  continue;
151  if (!record[rawid].pdfval[5])
152  continue;
153 
154  DOMElement* cellnode = writeCell(root, rawid);
155 
156  WriteNodeWithValue(cellnode, sample0_tag, record[rawid].pdfval[0]);
157  WriteNodeWithValue(cellnode, sample1_tag, record[rawid].pdfval[1]);
158  WriteNodeWithValue(cellnode, sample2_tag, record[rawid].pdfval[2]);
159  WriteNodeWithValue(cellnode, sample3_tag, record[rawid].pdfval[3]);
160  WriteNodeWithValue(cellnode, sample4_tag, record[rawid].pdfval[4]);
161  WriteNodeWithValue(cellnode, sample5_tag, record[rawid].pdfval[5]);
162  WriteNodeWithValue(cellnode, sample6_tag, record[rawid].pdfval[6]);
163  WriteNodeWithValue(cellnode, sample7_tag, record[rawid].pdfval[7]);
164  WriteNodeWithValue(cellnode, sample8_tag, record[rawid].pdfval[8]);
165  WriteNodeWithValue(cellnode, sample9_tag, record[rawid].pdfval[9]);
166  WriteNodeWithValue(cellnode, sample10_tag, record[rawid].pdfval[10]);
167  WriteNodeWithValue(cellnode, sample11_tag, record[rawid].pdfval[11]);
168  }
169 
170  if (record.endcapItems().empty())
171  return std::string();
172  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
173  if (!EEDetId::validHashIndex(cellid))
174  continue;
175 
176  uint32_t rawid = EEDetId::unhashIndex(cellid);
177 
178  if (record.find(rawid) == record.end())
179  continue;
180  if (!record[rawid].pdfval[5])
181  continue;
182 
183  DOMElement* cellnode = writeCell(root, rawid);
184 
185  WriteNodeWithValue(cellnode, sample0_tag, record[rawid].pdfval[0]);
186  WriteNodeWithValue(cellnode, sample1_tag, record[rawid].pdfval[1]);
187  WriteNodeWithValue(cellnode, sample2_tag, record[rawid].pdfval[2]);
188  WriteNodeWithValue(cellnode, sample3_tag, record[rawid].pdfval[3]);
189  WriteNodeWithValue(cellnode, sample4_tag, record[rawid].pdfval[4]);
190  WriteNodeWithValue(cellnode, sample5_tag, record[rawid].pdfval[5]);
191  WriteNodeWithValue(cellnode, sample6_tag, record[rawid].pdfval[6]);
192  WriteNodeWithValue(cellnode, sample7_tag, record[rawid].pdfval[7]);
193  WriteNodeWithValue(cellnode, sample8_tag, record[rawid].pdfval[8]);
194  WriteNodeWithValue(cellnode, sample9_tag, record[rawid].pdfval[9]);
195  WriteNodeWithValue(cellnode, sample10_tag, record[rawid].pdfval[10]);
196  WriteNodeWithValue(cellnode, sample11_tag, record[rawid].pdfval[11]);
197  }
198 
199  std::string dump = cms::xerces::toString(writer->writeToString(root));
200  doc->release();
201  doctype->release();
202  writer->release();
203 
204  return dump;
205 }
const std::string sample9_tag("sample_9")
const std::string sample10_tag("sample_10")
const std::string sample0_tag("sample_0")
const std::string PulseShapes_tag("EcalPulseShapes")
const std::string sample2_tag("sample_2")
const std::string sample11_tag("sample_11")
const std::string sample5_tag("sample_5")
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
const std::string sample7_tag("sample_7")
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
std::string toString(XMLCh const *toTranscode)
const std::string sample3_tag("sample_3")
static const int MIN_HASH
Definition: EBDetId.h:149
const std::string sample8_tag("sample_8")
const std::string sample1_tag("sample_1")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const std::string sample6_tag("sample_6")
const std::string sample4_tag("sample_4")

◆ readXML()

int EcalPulseShapesXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalPulseShapes record 
)
static

Definition at line 22 of file EcalPulseShapesXMLTranslator.cc.

References xuti::Cell_tag(), officialStyle::chan, gather_cfg::cout, corrVsCorr::filename, xuti::getChildNode(), xuti::GetNodeData(), RecoTauValidation_cfi::header, writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), AlCaHarvesting_cff::record, alignCSCRings::s, xuti::sample0_tag(), xuti::sample10_tag(), xuti::sample11_tag(), xuti::sample1_tag(), xuti::sample2_tag(), xuti::sample3_tag(), xuti::sample4_tag(), xuti::sample5_tag(), xuti::sample6_tag(), xuti::sample7_tag(), xuti::sample8_tag(), xuti::sample9_tag(), EgammaValidation_cff::samples, EcalPulseShape::TEMPLATESAMPLES, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

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 << "EcalPulseShapesXMLTranslator::Error parsing document" << std::endl;
37  return -1;
38  }
39 
40  DOMElement* elementRoot = xmlDoc->getDocumentElement();
41 
42  xuti::readHeader(elementRoot, header);
43 
44  DOMNode* cellnode = getChildNode(elementRoot, Cell_tag);
45 
46  int chan = 0;
47  while (cellnode) {
48  // std::cout << " Channel " << chan << std::endl;
50 
51  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
52  // std::cout << " readCell Id Channel " << chan << " tag " << mean12_tag << std::endl;
53 
54  DOMNode* sample0_node = getChildNode(cellnode, sample0_tag);
55  GetNodeData(sample0_node, samples[0]);
56  // std::cout << " tag " << sample0_tag << " sample0 " << sample0 << std::endl;
57 
58  DOMNode* sample1_node = getChildNode(cellnode, sample1_tag);
59  GetNodeData(sample1_node, samples[1]);
60  // std::cout << " tag " << sample1_tag << " sample1 " << sample1 << std::endl;
61 
62  DOMNode* sample2_node = getChildNode(cellnode, sample2_tag);
63  GetNodeData(sample2_node, samples[2]);
64  // std::cout << " tag " << sample2_tag << " sample2 " << sample2 << std::endl;
65 
66  DOMNode* sample3_node = getChildNode(cellnode, sample3_tag);
67  GetNodeData(sample3_node, samples[3]);
68  // std::cout << " tag " << sample3_tag << " sample3 " << sample3 << std::endl;
69 
70  DOMNode* sample4_node = getChildNode(cellnode, sample4_tag);
71  GetNodeData(sample4_node, samples[4]);
72  // std::cout << " tag " << sample4_tag << " sample4 " << sample4 << std::endl;
73 
74  DOMNode* sample5_node = getChildNode(cellnode, sample5_tag);
75  GetNodeData(sample5_node, samples[5]);
76  // std::cout << " tag " << sample5_tag << " sample5 " << sample5 << std::endl;
77 
78  DOMNode* sample6_node = getChildNode(cellnode, sample6_tag);
79  GetNodeData(sample6_node, samples[6]);
80  // std::cout << " tag " << sample6_tag << " sample6 " << sample6 << std::endl;
81 
82  DOMNode* sample7_node = getChildNode(cellnode, sample7_tag);
83  GetNodeData(sample7_node, samples[7]);
84  // std::cout << " tag " << sample7_tag << " sample7 " << sample7 << std::endl;
85 
86  DOMNode* sample8_node = getChildNode(cellnode, sample8_tag);
87  GetNodeData(sample8_node, samples[8]);
88  // std::cout << " tag " << sample8_tag << " sample8 " << sample8 << std::endl;
89 
90  DOMNode* sample9_node = getChildNode(cellnode, sample9_tag);
91  GetNodeData(sample9_node, samples[9]);
92  // std::cout << " tag " << sample9_tag << " sample9 " << sample9 << std::endl;
93 
94  DOMNode* sample10_node = getChildNode(cellnode, sample10_tag);
95  GetNodeData(sample10_node, samples[10]);
96  // std::cout << " tag " << sample10_tag << " sample10 " << sample10 << std::endl;
97 
98  DOMNode* sample11_node = getChildNode(cellnode, sample11_tag);
99  GetNodeData(sample11_node, samples[11]);
100  // std::cout << " tag " << sample11_tag << " sample11 " << sample11 << std::endl;
101 
102  for (int s = 0; s < EcalPulseShape::TEMPLATESAMPLES; ++s)
103  record[detid].pdfval[s] = samples[s];
104 
105  cellnode = cellnode->getNextSibling();
106 
107  while (cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
108  cellnode = cellnode->getNextSibling();
109  chan++;
110  }
111 
112  delete parser;
114  std::cout << " nb of channels found in xml file " << chan << std::endl;
115  return 0;
116 }
const std::string sample9_tag("sample_9")
const std::string sample10_tag("sample_10")
const std::string sample0_tag("sample_0")
const std::string sample2_tag("sample_2")
void xercesTerminate()
Definition: Xerces.cc:23
static const int TEMPLATESAMPLES
const std::string sample11_tag("sample_11")
const std::string sample5_tag("sample_5")
void xercesInitialize()
Definition: Xerces.cc:18
const std::string sample7_tag("sample_7")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string sample3_tag("sample_3")
const std::string Cell_tag("cell")
const std::string sample8_tag("sample_8")
const std::string sample1_tag("sample_1")
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
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
const std::string sample6_tag("sample_6")
const std::string sample4_tag("sample_4")
const DetId readCellId(xercesc::DOMElement *node)
Assuming.

◆ writeXML()

int EcalPulseShapesXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalPulseShapes record 
)
static