CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalLaserAPDPNRatiosXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 #include <xercesc/dom/DOMNode.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/parsers/XercesDOMParser.hpp>
7 #include <xercesc/util/PlatformUtils.hpp>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
11 
12 
15 
18 
19 using namespace XERCES_CPP_NAMESPACE;
20 using namespace xuti;
21 using namespace std;
22 
23 
24 //
25 // TODO: write and read time map
26 //
27 //
28 
29 
30 
34 
35 
36 
37  XMLPlatformUtils::Initialize();
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 << "EcalLaserAPDPNRatiosXMLTranslator::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;
105  XMLPlatformUtils::Terminate();
106  return 0;
107 
108 
109 }
110 
111 
112 
113 
114 
116  const EcalCondHeader& header,
118  std::fstream fs(filename.c_str(),ios::out);
119  fs<< dumpXML(header,record);
120  return 0;
121  }
122 
123 
125  const EcalCondHeader& header,
127 
128 
129  XMLPlatformUtils::Initialize();
130 
131  DOMImplementation* impl =
132  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
133 
134  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
135  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
136 
137  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
138  DOMDocument * doc =
139  impl->createDocument( 0, fromNative(Laser_tag).c_str(), doctype );
140 
141 
142  doc->setEncoding(fromNative("UTF-8").c_str() );
143  doc->setStandalone(true);
144  doc->setVersion(fromNative("1.0").c_str() );
145 
146 
147  DOMElement* root = doc->getDocumentElement();
148 
149  xuti::writeHeader(root,header);
150 
151  for(int cellid = EBDetId::MIN_HASH;
153  ++cellid)
154  {
155 
156  uint32_t rawid = EBDetId::unhashIndex(cellid);
157 
158  DOMElement* cellnode= writeCell(root,rawid);
159 
160  float p1=(record.getLaserMap())[rawid].p1;
161  float p2=(record.getLaserMap())[rawid].p2;
162  float p3=(record.getLaserMap())[rawid].p3;
163 
164 // edm::TimeStamp t1=(record.getTimeMap())[rawid].t1;
165 // edm::TimeStamp t2=(record.getTimeMap())[rawid].t2;
166 // edm::TimeStamp t3=(record.getTimeMap())[rawid].t3;
167 
168  WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
169  WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
170  WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
171 // WriteNodeWithValue(cellnode,Laser_t1_tag,t1);
172 // WriteNodeWithValue(cellnode,Laser_t2_tag,t2);
173 // WriteNodeWithValue(cellnode,Laser_t3_tag,t3);
174 
175  }
176 
177 
178 
179 
180  for(int cellid = 0;
182  ++cellid)
183  {
184 
185  if(!EEDetId::validHashIndex(cellid)) continue;
186 
187  uint32_t rawid = EEDetId::unhashIndex(cellid);
188 
189 
190  DOMElement* cellnode=writeCell(root,rawid);
191 
192  float p1=(record.getLaserMap())[rawid].p1;
193  float p2=(record.getLaserMap())[rawid].p2;
194  float p3=(record.getLaserMap())[rawid].p3;
195 
196 // edm::TimeStamp t1=(record.getTimeMap())[rawid].t1;
197 // edm::TimeStamp t2=(record.getTimeMap())[rawid].t2;
198 // edm::TimeStamp t3=(record.getTimeMap())[rawid].t3;
199 
200  WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
201  WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
202  WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
203 // WriteNodeWithValue(cellnode,Laser_t1_tag,t1);
204 // WriteNodeWithValue(cellnode,Laser_t2_tag,t2);
205 // WriteNodeWithValue(cellnode,Laser_t3_tag,t3);
206 
207 
208 
209  }
210 
211 
212  std::string dump= toNative(writer->writeToString(*root));
213  doc->release();
214  // XMLPlatformUtils::Terminate();
215 
216  return dump;
217 
218 }
JetCorrectorParameters::Record record
Definition: classes.h:11
static int readXML(const std::string &filename, EcalCondHeader &header, EcalLaserAPDPNRatios &record)
static std::string dumpXML(const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
const std::string Laser_p3_tag("p3")
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:115
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static bool validHashIndex(int i)
Definition: EEDetId.h:234
const EcalLaserAPDPNRatiosMap & getLaserMap() const
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
static const int MIN_HASH
Definition: EBDetId.h:135
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const std::string Laser_p1_tag("p1")
tuple doc
Definition: asciidump.py:381
double p2[4]
Definition: TauolaWrapper.h:90
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
tuple out
Definition: dbtoconf.py:99
const std::string Laser_tag("EcalLaserAPDPNRatios")
Definition: DetId.h:20
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
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.cc:12
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")
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:121
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
double p3[4]
Definition: TauolaWrapper.h:91
string root
initialization
Definition: dbtoconf.py:70