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

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

Definition at line 123 of file EcalLinearCorrectionsXMLTranslator.cc.

References FrontierConditions_GlobalTag_cff::dump, EcalTimeDependentCorrections::getTimeMap(), EcalTimeDependentCorrections::getValueMap(), 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, AlCaHLTBitMon_QueryRunRegistry::string, lumiQTWidget::t, reco::t2, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cscNeutronWriter_cfi::writer.

125  {
126 
127  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
128 
129  DOMLSSerializer* writer = impl->createLSSerializer();
130  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
131  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
132 
133  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), 0, 0 );
134  DOMDocument * doc =
135  impl->createDocument( 0, cms::xerces::uStr(Laser_tag.c_str()).ptr(), doctype );
136 
137  DOMElement* root = doc->getDocumentElement();
138 
139  xuti::writeHeader(root,header);
140 
141  string Lasertag = "Laser", LMtag = "LM";
142  for(int cellid = 0; cellid < (int)record.getTimeMap().size(); cellid++) {
143 
144  DOMElement* cellnode = doc->createElement( cms::xerces::uStr(Lasertag.c_str()).ptr());
145  root->appendChild(cellnode);
146  stringstream value_s;
147  value_s << cellid;
148  cellnode->setAttribute(cms::xerces::uStr(LMtag.c_str()).ptr(),
149  cms::xerces::uStr(value_s.str().c_str()).ptr());
150 
151  long int t123[3];
152  t123[0]=(record.getTimeMap())[cellid].t1.value();
153  t123[1]=(record.getTimeMap())[cellid].t2.value();
154  t123[2]=(record.getTimeMap())[cellid].t3.value();
155  string Laser_t_tag[3] = {"t1","t2","t3"};
156  for(int i = 0; i < 3; i++) {
157  time_t t = t123[i] >> 32;
158  char buf[256];
159  struct tm lt;
160  localtime_r(&t, &lt);
161  strftime(buf, sizeof(buf), "%F %R:%S", &lt);
162  buf[sizeof(buf)-1] = 0;
163  DOMDocument* subdoc = cellnode->getOwnerDocument();
164  DOMElement* new_node = subdoc->createElement(cms::xerces::uStr(Laser_t_tag[i].c_str()).ptr());
165  cellnode->appendChild(new_node);
166  std::stringstream value_ss;
167  value_ss << t123[i];
168  string newstr = value_ss.str() + " [" + string(buf) +"]";
169  DOMText* tvalue =
170  subdoc->createTextNode(cms::xerces::uStr(newstr.c_str()).ptr());
171  new_node->appendChild(tvalue);
172  }
173  }
174 
175  for(int cellid = EBDetId::MIN_HASH;
177  ++cellid)
178  {
179 
180  uint32_t rawid = EBDetId::unhashIndex(cellid);
181 
182  DOMElement* cellnode= writeCell(root,rawid);
183 
184  float p1=(record.getValueMap())[rawid].p1;
185  float p2=(record.getValueMap())[rawid].p2;
186  float p3=(record.getValueMap())[rawid].p3;
187 
188  WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
189  WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
190  WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
191 
192  }
193 
194 
195 
196 
197  for(int cellid = 0;
199  ++cellid)
200  {
201 
202  if(!EEDetId::validHashIndex(cellid)) continue;
203 
204  uint32_t rawid = EEDetId::unhashIndex(cellid);
205 
206 
207  DOMElement* cellnode=writeCell(root,rawid);
208 
209  float p1=(record.getValueMap())[rawid].p1;
210  float p2=(record.getValueMap())[rawid].p2;
211  float p3=(record.getValueMap())[rawid].p3;
212 
213  WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
214  WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
215  WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
216  }
217 
218 
219  std::string dump = cms::xerces::toString(writer->writeToString( root ));
220  doc->release();
221  doctype->release();
222  writer->release();
223 
224  return dump;
225 }
const EcalTimeMap & getTimeMap() const
const std::string Laser_p3_tag("p3")
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
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)
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
static const int MIN_HASH
Definition: EBDetId.h:156
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const EcalValueMap & getValueMap() const
const std::string Laser_p1_tag("p1")
ZStr< XMLCh > uStr(char const *str)
double p2[4]
Definition: TauolaWrapper.h:90
const std::string Laser_tag("EcalLaserAPDPNRatios")
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
double p1[4]
Definition: TauolaWrapper.h:89
const std::string Laser_p2_tag("p2")
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
double p3[4]
Definition: TauolaWrapper.h:91
int EcalLinearCorrectionsXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalLinearCorrections record 
)
static

Definition at line 31 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(), EcalTimeDependentCorrections::Values::p1, p1, EcalTimeDependentCorrections::Values::p2, p2, EcalTimeDependentCorrections::Values::p3, p3, createfilelist::parser, xuti::readCellId(), xuti::readHeader(), EcalTimeDependentCorrections::setValue(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

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

Definition at line 109 of file EcalLinearCorrectionsXMLTranslator.cc.

References EcalCondTools::dumpXML(), MillePedeFileConverter_cfg::out, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

111  {
112 
114 
115  std::fstream fs(filename.c_str(),ios::out);
116  fs<< dumpXML(header,record);
117 
119 
120  return 0;
121 }
void xercesTerminate()
Definition: Xerces.cc:23
static std::string dumpXML(const EcalCondHeader &header, const EcalLinearCorrections &record)
void xercesInitialize()
Definition: Xerces.cc:18