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 std::string
109  const EcalCondHeader& header,
111 
112 
113 
114 
115  XMLPlatformUtils::Initialize();
116 
117  DOMImplementation* impl =
118  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
119 
120  DOMWriter* writer =
121  static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
122  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
123 
124  DOMDocumentType* doctype =
125  impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
126  DOMDocument * doc =
127  impl->createDocument( 0, fromNative(EcalFloatCondObjectContainer_tag).c_str(), doctype );
128 
129 
130  doc->setEncoding(fromNative("UTF-8").c_str() );
131  doc->setStandalone(true);
132  doc->setVersion(fromNative("1.0").c_str() );
133 
134 
135  DOMElement* root = doc->getDocumentElement();
136  xuti::writeHeader(root, header);
137 
138  for (int cellid = EBDetId::MIN_HASH;
140  ++cellid){// loop on EB cells
141 
142  uint32_t rawid= EBDetId::unhashIndex(cellid);
143 
144  if (!record[rawid]) continue; // cell absent from original record
145 
146  DOMElement* cellnode=writeCell(root,rawid);
147 
148  WriteNodeWithValue(cellnode,Value_tag,record[rawid]);
149 
150 
151  } // loop on EB cells
152 
153 
154 
155  for (int cellid = 0;
157  ++cellid){// loop on EE cells
158 
159  if (!EEDetId::validHashIndex(cellid)) continue;
160 
161  uint32_t rawid= EEDetId::unhashIndex(cellid);
162  if (!record[rawid]) continue; // cell absent from original record
163 
164  DOMElement* cellnode= writeCell(root,rawid);
165  WriteNodeWithValue(cellnode,Value_tag,record[rawid]);
166 
167 
168  } // loop on EE cells
169 
170 
171  std::string dump= toNative(writer->writeToString(*root));
172  doc->release();
173  return dump;
174 }
175 
176 
177 
178 int
180  const EcalCondHeader& header,
182 
183  std::fstream fs(filename.c_str(),ios::out);
184  fs<< dumpXML(header,record);
185  return 0;
186 }
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:11
const std::string EcalFloatCondObjectContainer_tag("EcalFloatCondObjectContainer")
const Items & barrelItems() const
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:115
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:234
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:135
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
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.cc:12
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:41
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