test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions
EcalLaserAPDPNRatiosXMLTranslator Class Reference

#include <EcalLaserAPDPNRatiosXMLTranslator.h>

Static Public Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
 
static int readXML (const std::string &filename, EcalCondHeader &header, EcalLaserAPDPNRatios &record)
 
static int writeXML (const std::string &filename, 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 26 of file EcalLaserAPDPNRatiosXMLTranslator.h.

Member Function Documentation

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

Definition at line 123 of file EcalLaserAPDPNRatiosXMLTranslator.cc.

References hcal_timing_source_file_cfg::dump, xuti::fromNative(), EcalLaserAPDPNRatios::getLaserMap(), EcalLaserAPDPNRatios::getTimeMap(), i, 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, pyrootRender::root, AlCaHLTBitMon_QueryRunRegistry::string, lumiQTWidget::t, reco::t2, xuti::toNative(), EBDetId::unhashIndex(), EEDetId::unhashIndex(), EEDetId::validHashIndex(), xuti::writeCell(), xuti::writeHeader(), xuti::WriteNodeWithValue(), and cms::concurrency::xercesInitialize().

125  {
126 
127 
129 
130  DOMImplementation* impl =
131  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
132 
133  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
134  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
135 
136  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
137  DOMDocument * doc =
138  impl->createDocument( 0, fromNative(Laser_tag).c_str(), doctype );
139 
140 
141  doc->setEncoding(fromNative("UTF-8").c_str() );
142  doc->setStandalone(true);
143  doc->setVersion(fromNative("1.0").c_str() );
144 
145 
146  DOMElement* root = doc->getDocumentElement();
147 
148  xuti::writeHeader(root,header);
149 
150  string Lasertag = "Laser", LMtag = "LM";
151  for(int cellid = 0; cellid < (int)record.getTimeMap().size(); cellid++) {
152 
153  DOMElement* cellnode = doc->createElement( fromNative(Lasertag).c_str());
154  root->appendChild(cellnode);
155  stringstream value_s;
156  value_s << cellid;
157  cellnode->setAttribute(fromNative(LMtag).c_str(),
158  fromNative(value_s.str()).c_str());
159 
160  long int t123[3];
161  t123[0]=(record.getTimeMap())[cellid].t1.value();
162  t123[1]=(record.getTimeMap())[cellid].t2.value();
163  t123[2]=(record.getTimeMap())[cellid].t3.value();
164  string Laser_t_tag[3] = {"t1","t2","t3"};
165  for(int i = 0; i < 3; i++) {
166  time_t t = t123[i] >> 32;
167  char buf[256];
168  struct tm lt;
169  localtime_r(&t, &lt);
170  strftime(buf, sizeof(buf), "%F %R:%S", &lt);
171  buf[sizeof(buf)-1] = 0;
172  DOMDocument* subdoc = cellnode->getOwnerDocument();
173  DOMElement* new_node = subdoc->createElement(fromNative(Laser_t_tag[i]).c_str());
174  cellnode->appendChild(new_node);
175  std::stringstream value_ss;
176  value_ss << t123[i];
177  string newstr = value_ss.str() + " [" + string(buf) +"]";
178  DOMText* tvalue =
179  subdoc->createTextNode(fromNative(newstr).c_str());
180  new_node->appendChild(tvalue);
181  }
182  }
183 
184  for(int cellid = EBDetId::MIN_HASH;
186  ++cellid)
187  {
188 
189  uint32_t rawid = EBDetId::unhashIndex(cellid);
190 
191  DOMElement* cellnode= writeCell(root,rawid);
192 
193  float p1=(record.getLaserMap())[rawid].p1;
194  float p2=(record.getLaserMap())[rawid].p2;
195  float p3=(record.getLaserMap())[rawid].p3;
196 
197  WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
198  WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
199  WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
200 
201  }
202 
203 
204 
205 
206  for(int cellid = 0;
208  ++cellid)
209  {
210 
211  if(!EEDetId::validHashIndex(cellid)) continue;
212 
213  uint32_t rawid = EEDetId::unhashIndex(cellid);
214 
215 
216  DOMElement* cellnode=writeCell(root,rawid);
217 
218  float p1=(record.getLaserMap())[rawid].p1;
219  float p2=(record.getLaserMap())[rawid].p2;
220  float p3=(record.getLaserMap())[rawid].p3;
221 
222  WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
223  WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
224  WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
225  }
226 
227 
228  std::string dump= toNative(writer->writeToString(*root));
229  doc->release();
230  // cms::concurrency::xercesTerminate();
231 
232  return dump;
233 
234 }
int i
Definition: DBlmapReader.cc:9
const std::string Laser_p3_tag("p3")
void xercesInitialize()
Definition: Xerces.cc:17
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
const EcalLaserAPDPNRatiosMap & getLaserMap() const
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 std::string Laser_p1_tag("p1")
double p2[4]
Definition: TauolaWrapper.h:90
const std::string Laser_tag("EcalLaserAPDPNRatios")
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
< 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")
XercesString fromNative(const char *str)
Definition: XercesString.h:31
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
double p3[4]
Definition: TauolaWrapper.h:91
int EcalLaserAPDPNRatiosXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalLaserAPDPNRatios record 
)
static

Definition at line 30 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, mps_alisetup::parser, xuti::readCellId(), xuti::readHeader(), EcalLaserAPDPNRatios::setValue(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

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

References EcalCondTools::dumpXML(), and GenerateHcalLaserBadRunList::out.

116  {
117  std::fstream fs(filename.c_str(),ios::out);
118  fs<< dumpXML(header,record);
119  return 0;
120  }
static std::string dumpXML(const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
tuple filename
Definition: lut2db_cfg.py:20