Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:57

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/EcalClusterCrackCorrXMLTranslator.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 EcalClusterCrackCorrXMLTranslator::readXML(const string& filename, EcalCondHeader& header, EcalFunParams& record) {
0022   cms::concurrency::xercesInitialize();
0023 
0024   XercesDOMParser* parser = new XercesDOMParser;
0025   parser->setValidationScheme(XercesDOMParser::Val_Never);
0026   parser->setDoNamespaces(false);
0027   parser->setDoSchema(false);
0028 
0029   parser->parse(filename.c_str());
0030 
0031   DOMDocument* xmlDoc = parser->getDocument();
0032 
0033   if (!xmlDoc) {
0034     std::cout << "EcalClusterCrackCorrXMLTranslator::Error parsing document" << std::endl;
0035     return -1;
0036   }
0037 
0038   DOMElement* elementRoot = xmlDoc->getDocumentElement();
0039 
0040   xuti::readHeader(elementRoot, header);
0041 
0042   // need some extra code here
0043 
0044   delete parser;
0045   cms::concurrency::xercesTerminate();
0046   return 0;
0047 }
0048 
0049 std::string EcalClusterCrackCorrXMLTranslator::dumpXML(const EcalCondHeader& header, const EcalFunParams& record) {
0050   unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0051 
0052   DOMLSSerializer* writer = impl->createLSSerializer();
0053   if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0054     writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0055 
0056   DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0057   const std::string EcalClusterCrackCorr_tag("EcalClusterCrackCorr");
0058   DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(EcalClusterCrackCorr_tag.c_str()).ptr(), doctype);
0059 
0060   DOMElement* root = doc->getDocumentElement();
0061   xuti::writeHeader(root, header);
0062 
0063   const std::string ECCC_tag[4] = {"IPCloseEtaSide", "IPFarEtaSide", "IPClosePhiSide", "IPFarPhiSide"};
0064   ;
0065   int num = 0;
0066   for (EcalFunctionParameters::const_iterator it = record.params().begin(); it != record.params().end(); ++it) {
0067     int side = num / 5;
0068     int par = num % 5;
0069     std::string s;
0070     std::stringstream out;
0071     out << par;
0072     s = out.str();
0073     std::string sw = ECCC_tag[side] + "_" + s;
0074     DOMElement* ECCC = root->getOwnerDocument()->createElement(cms::xerces::uStr(sw.c_str()).ptr());
0075     root->appendChild(ECCC);
0076 
0077     WriteNodeWithValue(ECCC, Value_tag, *it);
0078     num++;
0079   }
0080 
0081   std::string dump = cms::xerces::toString(writer->writeToString(root));
0082   doc->release();
0083   doctype->release();
0084   writer->release();
0085 
0086   return dump;
0087 }
0088 
0089 int EcalClusterCrackCorrXMLTranslator::writeXML(const std::string& filename,
0090                                                 const EcalCondHeader& header,
0091                                                 const EcalFunParams& record) {
0092   cms::concurrency::xercesInitialize();
0093 
0094   std::fstream fs(filename.c_str(), ios::out);
0095   fs << dumpXML(header, record);
0096 
0097   cms::concurrency::xercesTerminate();
0098 
0099   return 0;
0100 }