CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalFloatCondObjectContainerXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 
5 #include <xercesc/dom/DOMNode.hpp>
6 #include <xercesc/dom/DOM.hpp>
7 #include <xercesc/parsers/XercesDOMParser.hpp>
8 #include <xercesc/util/PlatformUtils.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 
13 
14 
17 
18 using namespace XERCES_CPP_NAMESPACE;
19 using namespace xuti;
20 using namespace std;
21 
22 
23 int
25  EcalCondHeader& header,
27 
28  XMLPlatformUtils::Initialize();
29 
30  XercesDOMParser* parser = new XercesDOMParser;
31  parser->setValidationScheme( XercesDOMParser::Val_Never );
32  parser->setDoNamespaces( false );
33  parser->setDoSchema( false );
34 
35  parser->parse(filename.c_str());
36 
37  DOMDocument* xmlDoc = parser->getDocument();
38 
39 
40  if (!xmlDoc) {
41  std::cout << "EcalFloatCondObjectContainerXMLTranslator::Error parsing document" << std::endl;
42  return -1;
43  }
44 
45  DOMElement* elementRoot = xmlDoc->getDocumentElement();
46 
47  xuti::readHeader(elementRoot, header);
48 
49  // get the first cell node
50  DOMNode * cellnode=getChildNode(elementRoot,Cell_tag);
51 
52  // loop on cell nodes
53  while (cellnode){
54 
55  float val=0;
56 
57  // read id
58  DetId detid= readCellId(dynamic_cast<DOMElement*>(cellnode));
59 
60  // read value
61  DOMNode * c_node = getChildNode(cellnode,Value_tag);
62  GetNodeData(c_node,val);
63 
64  // fill record
65  record[detid]=val;
66 
67  // get next cell
68  cellnode= cellnode->getNextSibling();
69 
70  while (cellnode&& cellnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
71  cellnode= cellnode->getNextSibling();
72 
73 
74  }
75 
76 
77  delete parser;
78  XMLPlatformUtils::Terminate();
79  return 0;
80 
81 }
82 
83 
84 
85 std::vector<float>
87  EcalCondHeader header;
89  readXML(filename,header,record);
90 
91  return record.barrelItems();
92 
93 }
94 
95 
96 std::vector<float>
98  EcalCondHeader header;
100  readXML(filename,header,record);
101 
102  return record.endcapItems();
103 
104 }
105 
106 
107 
110  const EcalCondHeader& header,
111  const std::vector<float>& eb,
112  const std::vector<float>& ee){
113 
114 
115  if (eb.size() != EBDetId::kSizeForDenseIndexing){
116  std::cerr<<"Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Barrel array size: "
117  <<eb.size() << " should be "<< EBDetId::kSizeForDenseIndexing<< std::endl;
118  return std::string("");
119  }
120 
121  if (ee.size() != EEDetId::kSizeForDenseIndexing){
122  std::cerr<<"Error in EcalFloatCondObjectContainerXMLTranslator::dumpXML, invalid Endcap array size: "
123  <<ee.size() << " should be "<< EEDetId::kSizeForDenseIndexing<< std::endl;
124  return std::string("");
125  }
126 
128 
129  for (int cellid = 0;
131  ++cellid){// loop on EB cells
132 
133  uint32_t rawid = EBDetId::unhashIndex(cellid);
134  record[rawid] = eb[cellid];
135  }
136 
137  for (int cellid = 0;
139  ++cellid){// loop on EE cells
140 
141 
142 
143  if (EEDetId::validHashIndex(cellid)){
144  uint32_t rawid = EEDetId::unhashIndex(cellid);
145 
146  record[rawid]=ee[cellid];
147  } // if
148  }
149 
150  return dumpXML(header,record);
151 
152 
153 }
154 
157  const EcalCondHeader& header,
159 
160 
161 
162 
163  XMLPlatformUtils::Initialize();
164 
165  DOMImplementation* impl =
166  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
167 
168  DOMWriter* writer =
169  static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
170  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
171 
172  DOMDocumentType* doctype =
173  impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
174  DOMDocument * doc =
175  impl->createDocument( 0, fromNative(EcalFloatCondObjectContainer_tag).c_str(), doctype );
176 
177 
178  doc->setEncoding(fromNative("UTF-8").c_str() );
179  doc->setStandalone(true);
180  doc->setVersion(fromNative("1.0").c_str() );
181 
182 
183  DOMElement* root = doc->getDocumentElement();
184  xuti::writeHeader(root, header);
185 
186  for (int cellid = EBDetId::MIN_HASH;
188  ++cellid){// loop on EB cells
189 
190  uint32_t rawid= EBDetId::unhashIndex(cellid);
192  record.find(rawid);
193  if (value_ptr==record.end()) continue; // cell absent from original record
194 
195  DOMElement* cellnode=writeCell(root,rawid);
196 
197  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
198 
199 
200  } // loop on EB cells
201 
202 
203 
204  for (int cellid = 0;
206  ++cellid){// loop on EE cells
207 
208  if (!EEDetId::validHashIndex(cellid)) continue;
209 
210  uint32_t rawid= EEDetId::unhashIndex(cellid);
212  record.find(rawid);
213  if (value_ptr==record.end()) continue; // cell absent from original record
214 
215 
216  DOMElement* cellnode= writeCell(root,rawid);
217  WriteNodeWithValue(cellnode,Value_tag,*value_ptr);
218 
219 
220  } // loop on EE cells
221 
222 
223  std::string dump= toNative(writer->writeToString(*root));
224  doc->release();
225  return dump;
226 }
227 
228 
229 
230 int
232  const EcalCondHeader& header,
234 
235  std::fstream fs(filename.c_str(),ios::out);
236  fs<< dumpXML(header,record);
237  return 0;
238 }
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
static std::vector< float > barrelfromXML(const std::string &filename)
JetCorrectorParameters::Record record
Definition: classes.h:13
const std::string EcalFloatCondObjectContainer_tag("EcalFloatCondObjectContainer")
const Items & barrelItems() const
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
const std::string Value_tag("Value")
static bool validHashIndex(int i)
Definition: EEDetId.h:240
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
static std::string dumpXML(const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
static const int MIN_HASH
Definition: EBDetId.h:157
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
tuple doc
Definition: asciidump.py:381
tuple out
Definition: dbtoconf.py:99
static std::vector< float > endcapfromXML(const std::string &filename)
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
std::vector< Item >::const_iterator const_iterator
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:115
tuple filename
Definition: lut2db_cfg.py:20
const_iterator find(uint32_t rawId) const
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:121
const_iterator end() const
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const Items & endcapItems() const
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70