CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

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

Definition at line 111 of file EcalLinearCorrectionsXMLTranslator.cc.

References visDQMUpload::buf, remoteMonitoring_LASER_era2018_cfg::dump, EcalTimeDependentCorrections::getTimeMap(), EcalTimeDependentCorrections::getValueMap(), mps_fire::i, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, xuti::Laser_p1_tag(), xuti::Laser_p2_tag(), xuti::Laser_p3_tag(), xuti::Laser_tag(), EBDetId::MIN_HASH, fireworks::p1, fireworks::p2, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), and xuti::WriteNodeWithValue().

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 
124  xuti::writeHeader(root, header);
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 EcalTimeMap & getTimeMap() const
const TString p2
Definition: fwPaths.cc:13
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 TString p1
Definition: fwPaths.cc:12
const EcalValueMap & getValueMap() const
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
< trclass="colgroup">< tdclass="colgroup"colspan=5 > DT local reconstruction</td ></tr >< tr >< td >< ahref="classDTRecHit1DPair.html"> DTRecHit1DPair</a ></td >< td >< ahref="DataFormats_DTRecHit.html"> edm::RangeMap & lt
const std::string Laser_p2_tag("p2")
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
tuple dump
OutputFilePath = cms.string(&#39;/tmp/zhokin/&#39;), OutputFileExt = cms.string(&#39;&#39;),.
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, xuti::getChildNode(), xuti::GetNodeData(), xuti::Laser_p1_tag(), xuti::Laser_p2_tag(), xuti::Laser_p3_tag(), fireworks::p1, EcalTimeDependentCorrections::Values::p1, fireworks::p2, EcalTimeDependentCorrections::Values::p2, EcalTimeDependentCorrections::Values::p3, writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), EcalTimeDependentCorrections::setValue(), 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 setValue(uint32_t rawId, const Values &value)
const TString p2
Definition: fwPaths.cc:13
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 TString p1
Definition: fwPaths.cc:12
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
tuple filename
Definition: lut2db_cfg.py:20
const std::string Laser_p2_tag("p2")
tuple cout
Definition: gather_cfg.py:144
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
int EcalLinearCorrectionsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalLinearCorrections record 
)
static

Definition at line 98 of file EcalLinearCorrectionsXMLTranslator.cc.

References EcalCondTools::dumpXML(), compareTotals::fs, submitPVResolutionJobs::out, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

100  {
102 
103  std::fstream fs(filename.c_str(), ios::out);
104  fs << dumpXML(header, record);
105 
107 
108  return 0;
109 }
void xercesTerminate()
Definition: Xerces.cc:23
static std::string dumpXML(const EcalCondHeader &header, const EcalLinearCorrections &record)
void xercesInitialize()
Definition: Xerces.cc:18
tuple filename
Definition: lut2db_cfg.py:20