CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/CondTools/Ecal/src/EcalLaserAPDPNRatiosXMLTranslator.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/EcalObjects/interface/EcalLaserAPDPNRatios.h"
00014 #include "CondTools/Ecal/interface/EcalLaserAPDPNRatiosXMLTranslator.h"
00015 
00016 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
00017 #include "CondTools/Ecal/interface/XMLTags.h"
00018 
00019 using namespace XERCES_CPP_NAMESPACE;
00020 using namespace xuti;
00021 using namespace std;
00022 
00023 
00024 //
00025 // TODO: write and read time map
00026 //
00027 //
00028 
00029 
00030 
00031 int  EcalLaserAPDPNRatiosXMLTranslator::readXML(const std::string& filename, 
00032                                              EcalCondHeader& header,
00033                                              EcalLaserAPDPNRatios& record){
00034 
00035 
00036 
00037   XMLPlatformUtils::Initialize();
00038 
00039   XercesDOMParser* parser = new XercesDOMParser;
00040   parser->setValidationScheme( XercesDOMParser::Val_Never );
00041   parser->setDoNamespaces( false );
00042   parser->setDoSchema( false );
00043   
00044   parser->parse(filename.c_str());
00045 
00046   DOMDocument* xmlDoc = parser->getDocument();
00047   if (!xmlDoc) {
00048     std::cout << "EcalLaserAPDPNRatiosXMLTranslator::Error parsing document" << std::endl;
00049     return -1;
00050   }
00051 
00052   DOMElement* elementRoot = xmlDoc->getDocumentElement();
00053 
00054   xuti::readHeader(elementRoot,header);
00055 
00056   DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
00057 
00058   while(cellnode)
00059     {
00060       float p1 = 0;
00061       float p2 = 0;
00062       float p3 = 0;
00063 //       edm::TimeStamp t1=0;
00064 //       edm::TimeStamp t2=0;
00065 //       edm::TimeStamp t3=0;
00066 
00067 
00068       DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
00069 
00070       DOMNode* p1_node = getChildNode(cellnode,Laser_p1_tag);
00071       GetNodeData(p1_node,p1);
00072 
00073       DOMNode* p2_node = getChildNode(cellnode,Laser_p2_tag);
00074       GetNodeData(p2_node,p2);
00075 
00076       DOMNode* p3_node = getChildNode(cellnode,Laser_p3_tag);
00077       GetNodeData(p3_node,p3);
00078 
00079 //       DOMNode* t1_node = getChildNode(cellnode,Laser_t1_tag);
00080 //       GetNodeData(t1_node,t1);
00081 
00082 //       DOMNode* t2_node = getChildNode(cellnode,Laser_t2_tag);
00083 //       GetNodeData(t3_node,t2);
00084 
00085 //       DOMNode* p1_node = getChildNode(cellnode,Laser_t3_tag);
00086 //       GetNodeData(t3_node,t3);
00087 
00088  
00089       EcalLaserAPDPNRatios::EcalLaserAPDPNpair pair;
00090       pair.p1 =p1;
00091       pair.p2 =p2;
00092       pair.p3 =p3;
00093 
00094       record.setValue(detid,pair);
00095    
00096       cellnode = cellnode->getNextSibling();
00097 
00098       while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
00099         cellnode = cellnode->getNextSibling();
00100 
00101  
00102     }  
00103 
00104   delete parser;
00105   XMLPlatformUtils::Terminate();
00106   return 0;
00107   
00108   
00109 }
00110   
00111 
00112 
00113 
00114 
00115   int EcalLaserAPDPNRatiosXMLTranslator::writeXML(const std::string& filename, 
00116                                                const EcalCondHeader& header,
00117                                                const EcalLaserAPDPNRatios& record){
00118     std::fstream fs(filename.c_str(),ios::out);
00119     fs<< dumpXML(header,record);
00120     return 0;
00121   }
00122 
00123 
00124 std::string EcalLaserAPDPNRatiosXMLTranslator::dumpXML(
00125                                              const EcalCondHeader& header,
00126                                              const EcalLaserAPDPNRatios& record){
00127  
00128 
00129    XMLPlatformUtils::Initialize();
00130 
00131     DOMImplementation*  impl =
00132       DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
00133 
00134     DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
00135     writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00136 
00137     DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
00138     DOMDocument *    doc = 
00139          impl->createDocument( 0, fromNative(Laser_tag).c_str(), doctype );
00140 
00141 
00142     doc->setEncoding(fromNative("UTF-8").c_str() );
00143     doc->setStandalone(true);
00144     doc->setVersion(fromNative("1.0").c_str() );
00145 
00146     
00147     DOMElement* root = doc->getDocumentElement();
00148  
00149     xuti::writeHeader(root,header);
00150 
00151     for(int cellid = EBDetId::MIN_HASH;
00152         cellid < EBDetId::kSizeForDenseIndexing;
00153         ++cellid)
00154       {
00155 
00156         uint32_t rawid = EBDetId::unhashIndex(cellid);
00157 
00158         DOMElement* cellnode= writeCell(root,rawid);      
00159 
00160         float p1=(record.getLaserMap())[rawid].p1;
00161         float p2=(record.getLaserMap())[rawid].p2;
00162         float p3=(record.getLaserMap())[rawid].p3;
00163          
00164 //      edm::TimeStamp t1=(record.getTimeMap())[rawid].t1;
00165 //      edm::TimeStamp t2=(record.getTimeMap())[rawid].t2;
00166 //      edm::TimeStamp t3=(record.getTimeMap())[rawid].t3;
00167  
00168         WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
00169         WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
00170         WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
00171 //      WriteNodeWithValue(cellnode,Laser_t1_tag,t1);
00172 //      WriteNodeWithValue(cellnode,Laser_t2_tag,t2);
00173 //      WriteNodeWithValue(cellnode,Laser_t3_tag,t3);
00174                           
00175       }
00176 
00177 
00178 
00179    
00180     for(int cellid = 0;
00181         cellid < EEDetId::kSizeForDenseIndexing;
00182         ++cellid)
00183       {
00184           
00185         if(!EEDetId::validHashIndex(cellid)) continue;
00186           
00187         uint32_t rawid = EEDetId::unhashIndex(cellid); 
00188 
00189 
00190         DOMElement* cellnode=writeCell(root,rawid);
00191           
00192         float p1=(record.getLaserMap())[rawid].p1;
00193         float p2=(record.getLaserMap())[rawid].p2;
00194         float p3=(record.getLaserMap())[rawid].p3;
00195          
00196 //      edm::TimeStamp t1=(record.getTimeMap())[rawid].t1;
00197 //      edm::TimeStamp t2=(record.getTimeMap())[rawid].t2;
00198 //      edm::TimeStamp t3=(record.getTimeMap())[rawid].t3;
00199  
00200         WriteNodeWithValue(cellnode,Laser_p1_tag,p1);
00201         WriteNodeWithValue(cellnode,Laser_p2_tag,p2);
00202         WriteNodeWithValue(cellnode,Laser_p3_tag,p3);
00203 //      WriteNodeWithValue(cellnode,Laser_t1_tag,t1);
00204 //      WriteNodeWithValue(cellnode,Laser_t2_tag,t2);
00205 //      WriteNodeWithValue(cellnode,Laser_t3_tag,t3);
00206                 
00207           
00208           
00209       }
00210     
00211 
00212     std::string dump= toNative(writer->writeToString(*root)); 
00213     doc->release();
00214     //   XMLPlatformUtils::Terminate();
00215 
00216     return dump;
00217 
00218 }