Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:55

0001 #include "CondTools/Ecal/interface/EcalClusterLocalContCorrXMLTranslator.h"
0002 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
0003 #include "Utilities/Xerces/interface/Xerces.h"
0004 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0005 #include <xercesc/dom/DOMNode.hpp>
0006 #include <xercesc/dom/DOM.hpp>
0007 #include <xercesc/parsers/XercesDOMParser.hpp>
0008 #include <xercesc/util/XMLString.hpp>
0009 #include <xercesc/sax/SAXException.hpp>
0010 #include <xercesc/framework/LocalFileFormatTarget.hpp>
0011 
0012 #include <iostream>
0013 #include <sstream>
0014 #include <fstream>
0015 
0016 using namespace XERCES_CPP_NAMESPACE;
0017 using namespace xuti;
0018 using namespace std;
0019 
0020 int EcalClusterLocalContCorrXMLTranslator::readXML(const string& filename,
0021                                                    EcalCondHeader& header,
0022                                                    EcalFunParams& record) {
0023   cms::concurrency::xercesInitialize();
0024 
0025   XercesDOMParser* parser = new XercesDOMParser;
0026   parser->setValidationScheme(XercesDOMParser::Val_Never);
0027   parser->setDoNamespaces(false);
0028   parser->setDoSchema(false);
0029 
0030   parser->parse(filename.c_str());
0031 
0032   DOMDocument* xmlDoc = parser->getDocument();
0033 
0034   if (!xmlDoc) {
0035     std::cout << "EcalClusterLocalContCorrXMLTranslator::Error parsing document" << std::endl;
0036     return -1;
0037   }
0038 
0039   DOMElement* elementRoot = xmlDoc->getDocumentElement();
0040 
0041   xuti::readHeader(elementRoot, header);
0042 
0043   // need some extra code here
0044 
0045   delete parser;
0046   cms::concurrency::xercesTerminate();
0047   return 0;
0048 }
0049 
0050 std::string EcalClusterLocalContCorrXMLTranslator::dumpXML(const EcalCondHeader& header, const EcalFunParams& record) {
0051   unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0052 
0053   DOMLSSerializer* writer = impl->createLSSerializer();
0054   if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0055     writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0056 
0057   DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0058 
0059   DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr("EcalClusterLocalContCorr").ptr(), doctype);
0060 
0061   DOMElement* root = doc->getDocumentElement();
0062   xuti::writeHeader(root, header);
0063 
0064   for (auto it : record.params()) {
0065     DOMElement* ECEC = root->getOwnerDocument()->createElement(cms::xerces::uStr("ClusterLocal").ptr());
0066     root->appendChild(ECEC);
0067 
0068     WriteNodeWithValue(ECEC, Value_tag, it);
0069   }
0070 
0071   std::string dump = cms::xerces::toString(writer->writeToString(root));
0072   doc->release();
0073   doctype->release();
0074   writer->release();
0075 
0076   return dump;
0077 }
0078 
0079 int EcalClusterLocalContCorrXMLTranslator::writeXML(const std::string& filename,
0080                                                     const EcalCondHeader& header,
0081                                                     const EcalFunParams& record) {
0082   cms::concurrency::xercesInitialize();
0083 
0084   std::fstream fs(filename.c_str(), ios::out);
0085   fs << dumpXML(header, record);
0086 
0087   cms::concurrency::xercesTerminate();
0088 
0089   return 0;
0090 }