File indexing completed on 2024-04-06 12:02:55
0001 #include <iostream>
0002 #include <sstream>
0003 #include <fstream>
0004
0005 #include <xercesc/dom/DOMNode.hpp>
0006 #include <xercesc/dom/DOM.hpp>
0007 #include <xercesc/parsers/XercesDOMParser.hpp>
0008 #include "Utilities/Xerces/interface/Xerces.h"
0009 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0010 #include <xercesc/util/XMLString.hpp>
0011 #include <xercesc/sax/SAXException.hpp>
0012 #include <xercesc/framework/LocalFileFormatTarget.hpp>
0013
0014 #include "CondTools/Ecal/interface/EcalClusterEnergyCorrectionObjectSpecificXMLTranslator.h"
0015 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
0016
0017 using namespace XERCES_CPP_NAMESPACE;
0018 using namespace xuti;
0019 using namespace std;
0020
0021 int EcalClusterEnergyCorrectionObjectSpecificXMLTranslator::readXML(const string& filename,
0022 EcalCondHeader& header,
0023 EcalFunParams& record) {
0024 cms::concurrency::xercesInitialize();
0025
0026 XercesDOMParser* parser = new XercesDOMParser;
0027 parser->setValidationScheme(XercesDOMParser::Val_Never);
0028 parser->setDoNamespaces(false);
0029 parser->setDoSchema(false);
0030
0031 parser->parse(filename.c_str());
0032
0033 DOMDocument* xmlDoc = parser->getDocument();
0034
0035 if (!xmlDoc) {
0036 std::cout << "EcalClusterEnergyCorrectionObjectSpecificXMLTranslator::Error parsing document" << std::endl;
0037 return -1;
0038 }
0039
0040 DOMElement* elementRoot = xmlDoc->getDocumentElement();
0041
0042 xuti::readHeader(elementRoot, header);
0043
0044
0045
0046 delete parser;
0047 cms::concurrency::xercesTerminate();
0048 return 0;
0049 }
0050
0051 std::string EcalClusterEnergyCorrectionObjectSpecificXMLTranslator::dumpXML(const EcalCondHeader& header,
0052 const EcalFunParams& record) {
0053 unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0054
0055 DOMLSSerializer* writer = impl->createLSSerializer();
0056 if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0057 writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0058
0059 DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0060 const std::string ECECOS_tag("EcalClusterEnergyCorrectionObjectSpecific");
0061 DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(ECECOS_tag.c_str()).ptr(), doctype);
0062
0063 DOMElement* root = doc->getDocumentElement();
0064 xuti::writeHeader(root, header);
0065
0066 const std::string ECEC_tag[9] = {"fEta",
0067 "fBremEtaElectrons",
0068 "fBremEtaPhotons",
0069 "fEtElectronsEB",
0070 "fEtElectronsEE",
0071 "fEtPhotonsEB",
0072 "fEtPhotonsEE",
0073 "fEnergyElectronsEE",
0074 "fEnergyPhotonsEE"};
0075 int tit = 0;
0076 int par = 0;
0077 for (EcalFunctionParameters::const_iterator it = record.params().begin(); it != record.params().end(); ++it) {
0078 if (par < 2)
0079 tit = 0;
0080 else if (par < 86)
0081 tit = 1;
0082 else if (par < 170)
0083 tit = 2;
0084 else if (par < 177)
0085 tit = 3;
0086 else if (par < 184)
0087 tit = 4;
0088 else if (par < 191)
0089 tit = 5;
0090 else if (par < 198)
0091 tit = 6;
0092 else if (par < 203)
0093 tit = 7;
0094 else
0095 tit = 8;
0096 DOMElement* ECEC = root->getOwnerDocument()->createElement(cms::xerces::uStr(ECEC_tag[tit].c_str()).ptr());
0097 root->appendChild(ECEC);
0098
0099 WriteNodeWithValue(ECEC, Value_tag, *it);
0100 par++;
0101 }
0102 std::cout << "\n";
0103
0104 std::string dump = cms::xerces::toString(writer->writeToString(root));
0105 doc->release();
0106 doctype->release();
0107 writer->release();
0108
0109 return dump;
0110 }
0111
0112 int EcalClusterEnergyCorrectionObjectSpecificXMLTranslator::writeXML(const std::string& filename,
0113 const EcalCondHeader& header,
0114 const EcalFunParams& record) {
0115 cms::concurrency::xercesInitialize();
0116
0117 std::fstream fs(filename.c_str(), ios::out);
0118 fs << dumpXML(header, record);
0119
0120 cms::concurrency::xercesTerminate();
0121
0122 return 0;
0123 }