CMS 3D CMS Logo

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

#include <EcalPedestalsXMLTranslator.h>

Static Public Member Functions

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

Static Private Member Functions

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

Detailed Description

Translates a EcalGainRatio record to XML and vice versa

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

Definition at line 15 of file EcalPedestalsXMLTranslator.h.

Member Function Documentation

◆ dumpXML()

std::string EcalPedestalsXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalPedestals record 
)
staticprivate

Definition at line 114 of file EcalPedestalsXMLTranslator.cc.

References boostedTaus_cff::doc, submitPVValidationJobs::dump, RecoTauValidation_cfi::header, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, xuti::mean12_tag(), xuti::mean1_tag(), xuti::mean6_tag(), EBDetId::MIN_HASH, xuti::Pedestals_tag(), AlCaHarvesting_cff::record, xuti::rms12_tag(), xuti::rms1_tag(), xuti::rms6_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.

114  {
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 
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 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
std::string toString(XMLCh const *toTranscode)
static const int MIN_HASH
Definition: EBDetId.h:149
const std::string Pedestals_tag("EcalPedestals")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
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
const std::string rms12_tag("rms_x12")
const std::string rms6_tag("rms_x6")
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const std::string rms1_tag("rms_x1")

◆ readXML()

int EcalPedestalsXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalPedestals record 
)
static

Definition at line 22 of file EcalPedestalsXMLTranslator.cc.

References xuti::Cell_tag(), officialStyle::chan, gather_cfg::cout, corrVsCorr::filename, xuti::getChildNode(), xuti::GetNodeData(), RecoTauValidation_cfi::header, xuti::mean12_tag(), xuti::mean1_tag(), xuti::mean6_tag(), writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), AlCaHarvesting_cff::record, xuti::rms12_tag(), xuti::rms1_tag(), xuti::rms6_tag(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

22  {
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 }
const std::string mean12_tag("mean_x12")
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
const std::string mean1_tag("mean_x1")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string Cell_tag("cell")
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")
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
const std::string rms12_tag("rms_x12")
const std::string rms6_tag("rms_x6")
const std::string rms1_tag("rms_x1")
const DetId readCellId(xercesc::DOMElement *node)
Assuming.

◆ writeXML()

int EcalPedestalsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalPedestals record 
)
static