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.

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 }

References visDQMUpload::buf, common_cff::doc, FrontierConditions_GlobalTag_cff::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, p1, p2, p3, GlobalPosition_Frontier_DevDB_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, OrderedSet::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 cscNeutronWriter_cfi::writer.

◆ readXML()

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

Definition at line 28 of file EcalLinearCorrectionsXMLTranslator.cc.

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 }

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, p1, EcalTimeDependentCorrections::Values::p2, p2, EcalTimeDependentCorrections::Values::p3, p3, writedatasetfile::parser, xuti::readCellId(), xuti::readHeader(), GlobalPosition_Frontier_DevDB_cff::record, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

◆ writeXML()

int EcalLinearCorrectionsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalLinearCorrections record 
)
static
xuti::getChildNode
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
EcalTimeDependentCorrections::Values
Definition: EcalTimeDependentCorrections.h:16
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
common_cff.doc
doc
Definition: common_cff.py:54
mps_fire.i
i
Definition: mps_fire.py:355
xuti::Laser_p3_tag
const std::string Laser_p3_tag("p3")
xuti::writeHeader
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
Definition: DOMHelperFunctions.cc:151
xuti::writeCell
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
Definition: DOMHelperFunctions.cc:71
EEDetId::unhashIndex
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
xuti::Laser_p2_tag
const std::string Laser_p2_tag("p2")
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EBDetId::unhashIndex
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
EcalLinearCorrectionsXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const EcalLinearCorrections &record)
Definition: EcalLinearCorrectionsXMLTranslator.cc:111
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
xuti::Laser_p1_tag
const std::string Laser_p1_tag("p1")
EcalTimeDependentCorrections::Values::p3
float p3
Definition: EcalTimeDependentCorrections.h:20
EcalTimeDependentCorrections::Values::p1
float p1
Definition: EcalTimeDependentCorrections.h:18
DetId
Definition: DetId.h:17
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:34
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
EEDetId::kSizeForDenseIndexing
Definition: EEDetId.h:329
xuti::WriteNodeWithValue
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
Definition: DOMHelperFunctions.h:46
p2
double p2[4]
Definition: TauolaWrapper.h:90
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
OrderedSet.t
t
Definition: OrderedSet.py:90
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalTimeDependentCorrections::Values::p2
float p2
Definition: EcalTimeDependentCorrections.h:19
xuti::Laser_tag
const std::string Laser_tag("EcalLaserAPDPNRatios")
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
createfilelist.int
int
Definition: createfilelist.py:10
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
root
Definition: RooFitFunction.h:10
EEDetId::validHashIndex
static bool validHashIndex(int i)
Definition: EEDetId.h:239
p1
double p1[4]
Definition: TauolaWrapper.h:89
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:30
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
impl
Definition: trackAlgoPriorityOrder.h:18
EBDetId::kSizeForDenseIndexing
Definition: EBDetId.h:155
p3
double p3[4]
Definition: TauolaWrapper.h:91
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
xuti::readCellId
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
Definition: DOMHelperFunctions.cc:24
EBDetId::MIN_HASH
static const int MIN_HASH
Definition: EBDetId.h:149
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
xuti::readHeader
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
Definition: DOMHelperFunctions.cc:164
xuti::Cell_tag
const std::string Cell_tag("cell")
xuti::GetNodeData
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
Definition: DOMHelperFunctions.h:38