CMS 3D CMS Logo

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

#include <EcalLaserAPDPNRatiosXMLTranslator.h>

Static Public Member Functions

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

Static Private Member Functions

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

Detailed Description

Translates a EcalLaserAPDPNRatios record to XML and vice versa

Author
Stefano Argiro'
Version
Id
EcalLaserAPDPNRatiosXMLTranslator.h,v 1.1 2009/10/20 13:48:05 argiro Exp
Date
29 Jul 2008

Definition at line 16 of file EcalLaserAPDPNRatiosXMLTranslator.h.

Member Function Documentation

◆ dumpXML()

std::string EcalLaserAPDPNRatiosXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalLaserAPDPNRatios record 
)
staticprivate

Definition at line 109 of file EcalLaserAPDPNRatiosXMLTranslator.cc.

References visDQMUpload::buf, hcalRecHitTable_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(), 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::WeightGroups_tag(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and convertToRaw::writer.

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

Definition at line 26 of file EcalLaserAPDPNRatiosXMLTranslator.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(), EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p1, LaserDQM_cfg::p1, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p2, SiStripOfflineCRack_cfg::p2, chargedHadronTrackResolutionFilter_cfi::p3, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p3, writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), AlCaHarvesting_cff::record, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

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