Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:05

0001 #include "CondFormats/ESObjects/interface/ESGain.h"
0002 #include "CondTools/Ecal/interface/ESGainXMLTranslator.h"
0003 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
0004 #include "Utilities/Xerces/interface/Xerces.h"
0005 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0006 #include <xercesc/dom/DOMNode.hpp>
0007 #include <xercesc/dom/DOM.hpp>
0008 #include <xercesc/parsers/XercesDOMParser.hpp>
0009 #include <xercesc/util/XMLString.hpp>
0010 #include <xercesc/sax/SAXException.hpp>
0011 #include <xercesc/framework/LocalFileFormatTarget.hpp>
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 ESGainXMLTranslator::writeXML(const std::string& filename, const EcalCondHeader& header, const ESGain& record) {
0021   cms::concurrency::xercesInitialize();
0022 
0023   std::fstream fs(filename.c_str(), ios::out);
0024   fs << dumpXML(header, record);
0025 
0026   cms::concurrency::xercesTerminate();
0027 
0028   return 0;
0029 }
0030 
0031 std::string ESGainXMLTranslator::dumpXML(const EcalCondHeader& header, const ESGain& record) {
0032   unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0033 
0034   DOMLSSerializer* writer = impl->createLSSerializer();
0035   if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0036     writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0037 
0038   DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0039   DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(ADCToGeVConstant_tag.c_str()).ptr(), doctype);
0040 
0041   DOMElement* root = doc->getDocumentElement();
0042 
0043   xuti::writeHeader(root, header);
0044 
0045   xuti::WriteNodeWithValue(root, ESGain_tag, record.getESGain());
0046 
0047   std::string dump = cms::xerces::toString(writer->writeToString(root));
0048   doc->release();
0049   doctype->release();
0050   writer->release();
0051 
0052   return dump;
0053 }