CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h

Go to the documentation of this file.
00001 #ifndef HCALConfigDBTools_XMLTools_XMLProcessor_h
00002 #define HCALConfigDBTools_XMLTools_XMLProcessor_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     XMLTools
00006 // Class  :     XMLProcessor
00007 // 
00016 //
00017 // Original Author:  Gena Kukartsev
00018 //         Created:  Sun Sep 23 16:57:06 CEST 2007
00019 // $Id: XMLProcessor.h,v 1.6 2010/08/06 20:24:02 wmtan Exp $
00020 //
00021 
00022 // system include files
00023 #include <vector>
00024 #include <string>
00025 #include <time.h>
00026 #include <xercesc/dom/DOM.hpp>
00027 #include <xercesc/util/XMLString.hpp>
00028 #include <xercesc/util/PlatformUtils.hpp>
00029 #include <xercesc/dom/DOMNode.hpp>
00030 #include <xercesc/framework/MemBufInputSource.hpp>
00031 #include <cstdio>
00032 
00033 #if defined(XERCES_NEW_IOSTREAMS)
00034 #include <iostream>
00035 #else
00036 #include <iostream.h>
00037 #endif
00038 
00039 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLDOMBlock.h"
00040 
00041 
00042 XERCES_CPP_NAMESPACE_USE 
00043 
00044 class XMLProcessor
00045 {
00046   
00047  public:
00048   
00049   typedef struct _loaderBaseConfig
00050   {
00051     _loaderBaseConfig();
00052     std::string extention_table_name;
00053     std::string name;
00054     std::string run_mode;
00055     std::string data_set_id;
00056     std::string iov_id;
00057     std::string iov_begin;
00058     std::string iov_end;
00059     std::string tag_id;
00060     std::string tag_mode;
00061     std::string tag_name;
00062     std::string detector_name;
00063     std::string comment_description;
00064   } loaderBaseConfig;
00065 
00066   typedef struct _LMapRowHBEF
00067   {
00068     int    side;
00069     int    eta;
00070     int    phi;
00071     int    dphi;
00072     int    depth;
00073     std::string det;
00074     std::string rbx;
00075     int    wedge;
00076     int    rm;
00077     int    pixel;
00078     int    qie;
00079     int    adc;
00080     int    rm_fi;
00081     int    fi_ch;
00082     int    crate;
00083     int    htr;
00084     std::string fpga;
00085     int    htr_fi;
00086     int    dcc_sl;
00087     int    spigo;
00088     int    dcc;
00089     int    slb;
00090     std::string slbin;
00091     std::string slbin2;
00092     std::string slnam;
00093     int    rctcra;
00094     int    rctcar;
00095     int    rctcon;
00096     std::string rctnam;
00097     int    fedid;
00098   } LMapRowHBEF;
00099 
00100   typedef struct _LMapRowHO
00101   {
00102     int    sideO;
00103     int    etaO;
00104     int    phiO;
00105     int    dphiO;
00106     int    depthO;
00107     std::string detO;
00108     std::string rbxO;
00109     int    sectorO;
00110     int    rmO;
00111     int    pixelO;
00112     int    qieO;
00113     int    adcO;
00114     int    rm_fiO;
00115     int    fi_chO;
00116     std::string let_codeO;
00117     int    crateO;
00118     int    htrO;
00119     std::string fpgaO;
00120     int    htr_fiO;
00121     int    dcc_slO;
00122     int    spigoO;
00123     int    dccO;
00124     int    fedidO;
00125   } LMapRowHO;
00126 
00127   typedef struct _DBConfig
00128   {
00129     _DBConfig();
00130     std::string    version;
00131     std::string    subversion;
00132     time_t create_timestamp;
00133     std::string created_by_user;
00134   } DBConfig;
00135 
00136   typedef struct _lutDBConfig : public _DBConfig
00137   {
00138     int    crateNumber;
00139   } lutDBConfig;
00140   
00141   typedef struct _checksumsDBConfig : public _DBConfig
00142   {
00143     std::string comment;
00144   } checksumsDBConfig;
00145 
00146   // this class is a singleton
00147   static XMLProcessor * getInstance()
00148     {
00149       if (!instance) instance = new XMLProcessor();
00150       return instance;
00151     }
00152   
00153   // returns XML std::string if target == "string" otherwise NULL
00154   XMLCh * serializeDOM( DOMNode* node, std::string target = "stdout" );
00155 
00156   inline static XMLCh * _toXMLCh( std::string temp );
00157   inline static XMLCh * _toXMLCh( int temp );
00158   inline static XMLCh * _toXMLCh( double temp );
00159   inline static XMLCh * _toXMLCh( time_t temp );
00160   virtual ~XMLProcessor();
00161   
00162   int test( void );
00163   int init( void );
00164   int terminate( void );
00165   
00166   XMLDOMBlock * createLMapHBEFXMLBase( std::string templateFileName );
00167   XMLDOMBlock * createLMapHOXMLBase( std::string templateFileName );
00168 
00169   int addLMapHBEFDataset( XMLDOMBlock * doc, LMapRowHBEF * row, std::string templateFileName );
00170   int addLMapHODataset( XMLDOMBlock * doc, LMapRowHO * row, std::string templateFileName );
00171  
00172   int write( XMLDOMBlock * doc, std::string target = "stdout" );
00173   
00174  private:
00175   XMLProcessor();
00176 
00177   XMLProcessor(const XMLProcessor&); // stop default
00178   
00179   //const XMLProcessor& operator=(const XMLProcessor&); // stop default
00180   
00181   // ---------- member data --------------------------------
00182   static XMLProcessor * instance;
00183 };
00184 
00185 inline XMLCh* XMLProcessor::_toXMLCh( std::string temp )
00186 {
00187   XMLCh* buff = XMLString::transcode(temp.c_str());    
00188   return  buff;
00189 }
00190 
00191 inline XMLCh* XMLProcessor::_toXMLCh( int temp )
00192 {
00193   char buf[100];
00194   int status = snprintf( buf, 100, "%d", temp );
00195   if ( status >= 100 )
00196     {
00197       std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
00198     }
00199   else if ( status <0 )
00200     {
00201       std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
00202     }
00203   XMLCh* buff = XMLString::transcode( buf );    
00204   return  buff;
00205 }
00206 
00207 inline XMLCh* XMLProcessor::_toXMLCh( double temp )
00208 {
00209   char buf[100];
00210   int status = snprintf( buf, 100, "%.10e", temp );
00211   if ( status >= 100 )
00212     {
00213       std::cout << "XMLProcessor::_toXMLCh(int temp): buffer overflow, the std::string will be truncated!" << std::endl;
00214     }
00215   else if ( status <0 )
00216     {
00217       std::cout << "XMLProcessor::_toXMLCh(int temp): output error" << std::endl;
00218     }
00219   XMLCh* buff = XMLString::transcode( buf );    
00220   return  buff;
00221 }
00222 
00223 inline XMLCh* XMLProcessor::_toXMLCh( time_t temp )
00224 {
00225   char buf[100];
00226   int status = strftime( buf, 50, "%c", gmtime( &temp ) );
00227   if ( status == 0 )
00228     {
00229       std::cout << "XML  Processor::_toXMLCh(int temp): buffer overflow, the std::string is indeterminate!" << std::endl;
00230     }
00231   XMLCh* buff = XMLString::transcode( buf );    
00232   return  buff;
00233 }
00234 
00235 
00236 #endif
00237