CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondTools/Ecal/src/ESGainXMLTranslator.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <fstream>
00004 #include <xercesc/dom/DOMNode.hpp>
00005 #include <xercesc/dom/DOM.hpp>
00006 #include <xercesc/parsers/XercesDOMParser.hpp>
00007 #include <xercesc/util/PlatformUtils.hpp>
00008 #include <xercesc/util/XMLString.hpp>
00009 #include <xercesc/sax/SAXException.hpp>
00010 #include <xercesc/framework/LocalFileFormatTarget.hpp>
00011 
00012 
00013 #include "CondFormats/ESObjects/interface/ESGain.h"
00014 #include "CondTools/Ecal/interface/ESGainXMLTranslator.h"
00015 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
00016 
00017 using namespace XERCES_CPP_NAMESPACE;
00018 using namespace xuti;
00019 using namespace std;
00020 
00021 int ESGainXMLTranslator::writeXML(const std::string& filename, 
00022                                         const EcalCondHeader& header,
00023                                         const ESGain& record){
00024   std::fstream fs(filename.c_str(),ios::out);
00025   fs<< dumpXML(header,record);
00026   return 0;  
00027  
00028 }
00029 
00030 std::string ESGainXMLTranslator::dumpXML(const EcalCondHeader& header,
00031                                           const ESGain& record){
00032 
00033   XMLPlatformUtils::Initialize();
00034   
00035   DOMImplementation*  impl =
00036     DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
00037   
00038   DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
00039   writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00040   
00041   DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
00042   DOMDocument *    doc = 
00043     impl->createDocument( 0, fromNative(ADCToGeVConstant_tag).c_str(), doctype );
00044 
00045 
00046   doc->setEncoding(fromNative("UTF-8").c_str() );
00047   doc->setStandalone(true);
00048   doc->setVersion(fromNative("1.0").c_str() );
00049     
00050   DOMElement* root = doc->getDocumentElement();
00051  
00052   xuti::writeHeader(root,header);
00053    
00054   xuti::WriteNodeWithValue(root,ESGain_tag,record.getESGain());
00055 
00056   std::string dump= toNative(writer->writeToString(*root)); 
00057   doc->release();
00058 
00059   //   XMLPlatformUtils::Terminate();
00060 
00061   return dump;
00062 }
00063