CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalClusterEnergyCorrectionXMLTranslator.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 
15 
16 using namespace XERCES_CPP_NAMESPACE;
17 using namespace xuti;
18 using namespace std;
19 
20 
21 int
23  const string& filename,
26 
27  XMLPlatformUtils::Initialize();
28 
29  XercesDOMParser* parser = new XercesDOMParser;
30  parser->setValidationScheme( XercesDOMParser::Val_Never );
31  parser->setDoNamespaces( false );
32  parser->setDoSchema( false );
33 
34  parser->parse(filename.c_str());
35 
36  DOMDocument* xmlDoc = parser->getDocument();
37 
38 
39  if (!xmlDoc) {
40  std::cout << "EcalClusterEnergyCorrectionXMLTranslator::Error parsing document" << std::endl;
41  return -1;
42  }
43 
44  DOMElement* elementRoot = xmlDoc->getDocumentElement();
45 
46  xuti::readHeader(elementRoot, header);
47 
48  // need some extra code here
49 
50  delete parser;
51  XMLPlatformUtils::Terminate();
52  return 0;
53 }
54 
55 std::string
57  const EcalCondHeader& header,
58  const EcalFunParams& record){
59 
60  XMLPlatformUtils::Initialize();
61 
62  DOMImplementation* impl =
63  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
64 
65  DOMWriter* writer =
66  static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
67  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
68 
69  DOMDocumentType* doctype =
70  impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
71  const std::string EcalClusterEnergyCorrection_tag("EcalClusterEnergyCorrection");
72  DOMDocument * doc =
73  impl->createDocument( 0, fromNative(EcalClusterEnergyCorrection_tag).c_str(), doctype );
74 
75 
76  doc->setEncoding(fromNative("UTF-8").c_str() );
77  doc->setStandalone(true);
78  doc->setVersion(fromNative("1.0").c_str() );
79 
80 
81  DOMElement* root = doc->getDocumentElement();
82  xuti::writeHeader(root, header);
83 
84  const std::string ECEC_tag("ClusterEnergy");
85  for ( EcalFunctionParameters::const_iterator it = record.params().begin(); it != record.params().end(); ++it ) {
86  DOMElement* ECEC =
87  root->getOwnerDocument()->createElement( fromNative(ECEC_tag).c_str());
88  root->appendChild(ECEC);
89 
90  WriteNodeWithValue(ECEC,Value_tag,*it);
91  }
92 
93  std::string dump= toNative(writer->writeToString(*root));
94  doc->release();
95  return dump;
96 }
97 
98 int
100  const std::string& filename,
101  const EcalCondHeader& header,
102  const EcalFunParams& record){
103 
104  std::fstream fs(filename.c_str(),ios::out);
105  fs<< dumpXML(header,record);
106  return 0;
107 }
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalFunParams &record)
static std::string dumpXML(const EcalCondHeader &header, const EcalFunParams &record)
JetCorrectorParameters::Record record
Definition: classes.h:11
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
const std::string Value_tag("Value")
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFunParams &record)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
EcalFunctionParameters & params()
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
tuple doc
Definition: asciidump.py:381
tuple out
Definition: dbtoconf.py:99
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:121
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70