CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalADCToGeVXMLTranslator.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>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
11 
12 
16 
17 using namespace XERCES_CPP_NAMESPACE;
18 using namespace xuti;
19 using namespace std;
20 
21 
22 
24  EcalCondHeader& header,
26 
27 
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  if (!xmlDoc) {
39  std::cout << "EcalADCToGeVXMLTranslator::Error parsing document" << std::endl;
40  return -1;
41  }
42 
43  // Get the top-level element
44  DOMElement* elementRoot = xmlDoc->getDocumentElement();
45 
46  xuti::readHeader(elementRoot, header);
47 
48 
49  DOMNode * barrelnode = xuti::getChildNode(elementRoot,Barrel_tag);
50  DOMNode * endcapnode = xuti::getChildNode(elementRoot,Endcap_tag);
51 
52  double barrelvalue=0;
53  double endcapvalue=0;
54 
55  xuti::GetNodeData(barrelnode,barrelvalue);
56  xuti::GetNodeData(endcapnode,endcapvalue);
57 
58  record.setEBValue(barrelvalue);
59  record.setEEValue(endcapvalue);
60 
61 
62  delete parser;
64  return 0;
65 
66 }
67 
68 
69 
70 
71 
73  const EcalCondHeader& header,
75  std::fstream fs(filename.c_str(),ios::out);
76  fs<< dumpXML(header,record);
77  return 0;
78 
79 }
80 
83 
85 
86  DOMImplementation* impl =
87  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
88 
89  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
90  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
91 
92  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
93  DOMDocument * doc =
94  impl->createDocument( 0, fromNative(ADCToGeVConstant_tag).c_str(), doctype );
95 
96 
97  doc->setEncoding(fromNative("UTF-8").c_str() );
98  doc->setStandalone(true);
99  doc->setVersion(fromNative("1.0").c_str() );
100 
101  DOMElement* root = doc->getDocumentElement();
102 
103  xuti::writeHeader(root,header);
104 
107 
108  std::string dump= toNative(writer->writeToString(*root));
109  doc->release();
110 
111  // cms::concurrency::xercesTerminate();
112 
113  return dump;
114 }
115 
void xercesTerminate()
Definition: Xerces.cc:22
static std::string dumpXML(const EcalCondHeader &header, const EcalADCToGeVConstant &record)
static int readXML(const std::string &filename, EcalCondHeader &header, EcalADCToGeVConstant &record)
void xercesInitialize()
Definition: Xerces.cc:17
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
void setEEValue(const float &value)
const std::string ADCToGeVConstant_tag("EcalADCToGeVConstant")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
tuple doc
Definition: asciidump.py:381
tuple out
Definition: dbtoconf.py:99
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalADCToGeVConstant &record)
void setEBValue(const float &value)
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
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
const std::string Endcap_tag("EndcapValue")
tuple cout
Definition: gather_cfg.py:121
const std::string Barrel_tag("BarrelValue")
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70