CMS 3D CMS Logo

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

#include <EcalLinearCorrectionsXMLTranslator.h>

Static Public Member Functions

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

Static Private Member Functions

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

Detailed Description

Translates a EcalLinearCorrections record to XML and vice versa

Author
Stefano ARGIRO
Version
Id
EcalLinearCorrectionsXMLTranslator.h,v 1.1 2012/11/21 17:01:39 fra Exp
Date
20 Jun 2008

Definition at line 16 of file EcalLinearCorrectionsXMLTranslator.h.

Member Function Documentation

◆ dumpXML()

std::string EcalLinearCorrectionsXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalLinearCorrections record 
)
staticprivate

Definition at line 111 of file EcalLinearCorrectionsXMLTranslator.cc.

References visDQMUpload::buf, boostedTaus_cff::doc, GCP_Ntuples_cfg::dump, RecoTauValidation_cfi::header, mps_fire::i, createfilelist::int, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, xuti::Laser_p1_tag(), xuti::Laser_p2_tag(), xuti::Laser_p3_tag(), xuti::Laser_tag(), EBDetId::MIN_HASH, LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, chargedHadronTrackResolutionFilter_cfi::p3, AlCaHarvesting_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, RandomServiceHelper::t1, RandomServiceHelper::t2, RandomServiceHelper::t3, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and convertToRaw::writer.

112  {
113  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
114 
115  DOMLSSerializer* writer = impl->createLSSerializer();
116  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
117  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
118 
119  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
120  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(Laser_tag.c_str()).ptr(), doctype);
121 
122  DOMElement* root = doc->getDocumentElement();
123 
125 
126  string Lasertag = "Laser", LMtag = "LM";
127  for (int cellid = 0; cellid < (int)record.getTimeMap().size(); cellid++) {
128  DOMElement* cellnode = doc->createElement(cms::xerces::uStr(Lasertag.c_str()).ptr());
129  root->appendChild(cellnode);
130  stringstream value_s;
131  value_s << cellid;
132  cellnode->setAttribute(cms::xerces::uStr(LMtag.c_str()).ptr(), cms::xerces::uStr(value_s.str().c_str()).ptr());
133 
134  long int t123[3];
135  t123[0] = (record.getTimeMap())[cellid].t1.value();
136  t123[1] = (record.getTimeMap())[cellid].t2.value();
137  t123[2] = (record.getTimeMap())[cellid].t3.value();
138  string Laser_t_tag[3] = {"t1", "t2", "t3"};
139  for (int i = 0; i < 3; i++) {
140  time_t t = t123[i] >> 32;
141  char buf[256];
142  struct tm lt;
143  localtime_r(&t, &lt);
144  strftime(buf, sizeof(buf), "%F %R:%S", &lt);
145  buf[sizeof(buf) - 1] = 0;
146  DOMDocument* subdoc = cellnode->getOwnerDocument();
147  DOMElement* new_node = subdoc->createElement(cms::xerces::uStr(Laser_t_tag[i].c_str()).ptr());
148  cellnode->appendChild(new_node);
149  std::stringstream value_ss;
150  value_ss << t123[i];
151  string newstr = value_ss.str() + " [" + string(buf) + "]";
152  DOMText* tvalue = subdoc->createTextNode(cms::xerces::uStr(newstr.c_str()).ptr());
153  new_node->appendChild(tvalue);
154  }
155  }
156 
157  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
158  uint32_t rawid = EBDetId::unhashIndex(cellid);
159 
160  DOMElement* cellnode = writeCell(root, rawid);
161 
162  float p1 = (record.getValueMap())[rawid].p1;
163  float p2 = (record.getValueMap())[rawid].p2;
164  float p3 = (record.getValueMap())[rawid].p3;
165 
166  WriteNodeWithValue(cellnode, Laser_p1_tag, p1);
167  WriteNodeWithValue(cellnode, Laser_p2_tag, p2);
168  WriteNodeWithValue(cellnode, Laser_p3_tag, p3);
169  }
170 
171  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
172  if (!EEDetId::validHashIndex(cellid))
173  continue;
174 
175  uint32_t rawid = EEDetId::unhashIndex(cellid);
176 
177  DOMElement* cellnode = writeCell(root, rawid);
178 
179  float p1 = (record.getValueMap())[rawid].p1;
180  float p2 = (record.getValueMap())[rawid].p2;
181  float p3 = (record.getValueMap())[rawid].p3;
182 
183  WriteNodeWithValue(cellnode, Laser_p1_tag, p1);
184  WriteNodeWithValue(cellnode, Laser_p2_tag, p2);
185  WriteNodeWithValue(cellnode, Laser_p3_tag, p3);
186  }
187 
188  std::string dump = cms::xerces::toString(writer->writeToString(root));
189  doc->release();
190  doctype->release();
191  writer->release();
192 
193  return dump;
194 }
const std::string Laser_p3_tag("p3")
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
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
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const std::string Laser_p1_tag("p1")
ZStr< XMLCh > uStr(char const *str)
const std::string Laser_tag("EcalLaserAPDPNRatios")
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
const std::string Laser_p2_tag("p2")
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.

◆ readXML()

int EcalLinearCorrectionsXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalLinearCorrections record 
)
static

Definition at line 28 of file EcalLinearCorrectionsXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, corrVsCorr::filename, xuti::getChildNode(), xuti::GetNodeData(), RecoTauValidation_cfi::header, xuti::Laser_p1_tag(), xuti::Laser_p2_tag(), xuti::Laser_p3_tag(), EcalTimeDependentCorrections::Values::p1, LaserDQM_cfg::p1, EcalTimeDependentCorrections::Values::p2, SiStripOfflineCRack_cfg::p2, chargedHadronTrackResolutionFilter_cfi::p3, EcalTimeDependentCorrections::Values::p3, writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), AlCaHarvesting_cff::record, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

30  {
32 
33  XercesDOMParser* parser = new XercesDOMParser;
34  parser->setValidationScheme(XercesDOMParser::Val_Never);
35  parser->setDoNamespaces(false);
36  parser->setDoSchema(false);
37 
38  parser->parse(filename.c_str());
39 
40  DOMDocument* xmlDoc = parser->getDocument();
41  if (!xmlDoc) {
42  std::cout << "EcalLinearCorrectionsXMLTranslator::Error parsing document" << std::endl;
43  return -1;
44  }
45 
46  DOMElement* elementRoot = xmlDoc->getDocumentElement();
47 
48  xuti::readHeader(elementRoot, header);
49 
50  DOMNode* cellnode = getChildNode(elementRoot, Cell_tag);
51 
52  while (cellnode) {
53  float p1 = 0;
54  float p2 = 0;
55  float p3 = 0;
56  // edm::TimeStamp t1=0;
57  // edm::TimeStamp t2=0;
58  // edm::TimeStamp t3=0;
59 
60  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
61 
62  DOMNode* p1_node = getChildNode(cellnode, Laser_p1_tag);
63  GetNodeData(p1_node, p1);
64 
65  DOMNode* p2_node = getChildNode(cellnode, Laser_p2_tag);
66  GetNodeData(p2_node, p2);
67 
68  DOMNode* p3_node = getChildNode(cellnode, Laser_p3_tag);
69  GetNodeData(p3_node, p3);
70 
71  // DOMNode* t1_node = getChildNode(cellnode,Laser_t1_tag);
72  // GetNodeData(t1_node,t1);
73 
74  // DOMNode* t2_node = getChildNode(cellnode,Laser_t2_tag);
75  // GetNodeData(t3_node,t2);
76 
77  // DOMNode* p1_node = getChildNode(cellnode,Laser_t3_tag);
78  // GetNodeData(t3_node,t3);
79 
81  pair.p1 = p1;
82  pair.p2 = p2;
83  pair.p3 = p3;
84 
85  record.setValue(detid, pair);
86 
87  cellnode = cellnode->getNextSibling();
88 
89  while (cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
90  cellnode = cellnode->getNextSibling();
91  }
92 
93  delete parser;
95  return 0;
96 }
void xercesTerminate()
Definition: Xerces.cc:23
const std::string Laser_p3_tag("p3")
void xercesInitialize()
Definition: Xerces.cc:18
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string Cell_tag("cell")
const std::string Laser_p1_tag("p1")
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 Laser_p2_tag("p2")
const DetId readCellId(xercesc::DOMElement *node)
Assuming.

◆ writeXML()

int EcalLinearCorrectionsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalLinearCorrections record 
)
static