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

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

Definition at line 121 of file EcalLaserAPDPNRatiosXMLTranslator.cc.

References common_cff::doc, FrontierConditions_GlobalTag_cff::dump, EcalLaserAPDPNRatios::getLaserMap(), EcalLaserAPDPNRatios::getTimeMap(), mps_fire::i, createfilelist::int, EBDetId::kSizeForDenseIndexing, EEDetId::kSizeForDenseIndexing, xuti::Laser_p1_tag(), xuti::Laser_p2_tag(), xuti::Laser_p3_tag(), EBDetId::MIN_HASH, p1, p2, p3, AlCaHLTBitMon_QueryRunRegistry::string, lumiQTWidget::t, cms::xerces::toString(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), cms::xerces::uStr(), EEDetId::validHashIndex(), xuti::WeightGroups_tag(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cscNeutronWriter_cfi::writer.

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

Definition at line 29 of file EcalLaserAPDPNRatiosXMLTranslator.cc.

References xuti::Cell_tag(), gather_cfg::cout, xuti::getChildNode(), xuti::GetNodeData(), xuti::Laser_p1_tag(), xuti::Laser_p2_tag(), xuti::Laser_p3_tag(), EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p1, p1, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p2, p2, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p3, p3, createfilelist::parser, xuti::readCellId(), xuti::readHeader(), EcalLaserAPDPNRatios::setValue(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

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

Definition at line 107 of file EcalLaserAPDPNRatiosXMLTranslator.cc.

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

109  {
110 
112 
113  std::fstream fs(filename.c_str(),ios::out);
114  fs<< dumpXML(header,record);
115 
117 
118  return 0;
119 }
void xercesTerminate()
Definition: Xerces.cc:23
static std::string dumpXML(const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
void xercesInitialize()
Definition: Xerces.cc:18