CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/CaloOnlineTools/HcalOnlineDb/src/XMLLUTLoader.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     XMLTools
00004 // Class  :     XMLLUTLoader
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Gena Kukartsev, kukarzev@fnal.gov
00010 //         Created:  Tue Oct 23 14:30:20 CDT 2007
00011 // $Id: XMLLUTLoader.cc,v 1.4 2010/08/06 20:24:13 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "CaloOnlineTools/HcalOnlineDb/interface/XMLLUTLoader.h"
00018 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h"
00019 #include <cstdio>
00020 
00021 //
00022 // constants, enums and typedefs
00023 //
00024 
00025 //
00026 // static data member definitions
00027 //
00028 
00029 //
00030 // constructors and destructor
00031 //
00032 XMLLUTLoader::lutDBConfig::_lutDBConfig() : XMLProcessor::DBConfig()
00033 {
00034   kind_of_part = "HCAL HTR Crate";
00035   name_label = "CRATE17";
00036   trig_prim_lookuptbl_data_file = "testLUT_17.xml";
00037   crate = 17;
00038 }
00039 
00040 XMLLUTLoader::checksumsDBConfig::_checksumsDBConfig() : XMLProcessor::DBConfig()
00041 {
00042   comment_description = "checksum for all crates version test:2";
00043   name_label = "CMS-HCAL-ROOT";
00044   trig_prim_lookuptbl_data_file = "./testLUT_checksums.xml";
00045   crate = -1;
00046 }
00047 
00048 XMLLUTLoader::XMLLUTLoader()
00049 {
00050 }
00051 
00052 XMLLUTLoader::XMLLUTLoader( XMLProcessor::loaderBaseConfig * config, std::string templateBase ) : XMLDOMBlock( templateBase )
00053 {
00054   setTagValue( "EXTENSION_TABLE_NAME", config -> extention_table_name );
00055   setTagValue( "NAME", config -> name );
00056   setTagAttribute( "RUN", "mode", config -> run_mode );
00057   setTagAttribute( "DATA_SET", "id", config -> data_set_id );
00058   setTagAttribute( "IOV", "id", config -> iov_id );
00059   setTagValue( "INTERVAL_OF_VALIDITY_BEGIN", config -> iov_begin );
00060   setTagValue( "INTERVAL_OF_VALIDITY_END", config -> iov_end );
00061   setTagAttribute( "TAG", "id", config -> tag_id );
00062   setTagAttribute( "TAG", "mode", config -> tag_mode );
00063   setTagValue( "TAG_NAME", config -> tag_name );
00064   setTagValue( "DETECTOR_NAME", config -> detector_name );
00065   setTagValue( "COMMENT_DESCRIPTION", config -> comment_description );
00066 
00067   setTagAttribute( "TAG", "idref", config -> tag_id, 1 );
00068   setTagAttribute( "IOV", "idref", config -> iov_id, 1 );
00069   setTagAttribute( "DATA_SET", "idref", config -> data_set_id, 1 );
00070 }
00071 
00072 // XMLLUTLoader::XMLLUTLoader(const XMLLUTLoader& rhs)
00073 // {
00074 //    // do actual copying here;
00075 // }
00076 
00077 XMLLUTLoader::~XMLLUTLoader()
00078 {
00079 }
00080 
00081 //
00082 // assignment operators
00083 //
00084 // const XMLLUTLoader& XMLLUTLoader::operator=(const XMLLUTLoader& rhs)
00085 // {
00086 //   //An exception safe implementation is
00087 //   XMLLUTLoader temp(rhs);
00088 //   swap(rhs);
00089 //
00090 //   return *this;
00091 // }
00092 
00093 //
00094 // member functions
00095 //
00096 int XMLLUTLoader::addLUT( lutDBConfig * config, std::string templateFileName )
00097 {
00098   DOMElement * root = document -> getDocumentElement();
00099 
00100   XMLDOMBlock dataSetDoc( templateFileName );
00101   DOMDocument * dataSet = dataSetDoc . getDocument();
00102 
00103   // changes to the LUT <data_set> node
00104   setTagValue( "VERSION", config -> version, 0, dataSet );
00105   setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
00106   char timebuf[50];
00107   //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
00108   strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
00109   setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
00110   setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
00111   setTagValue( "KIND_OF_PART", config -> kind_of_part, 0, dataSet );
00112   setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
00113   setTagValue( "TRIG_PRIM_LOOKUPTBL_DATA_FILE", config -> trig_prim_lookuptbl_data_file, 0, dataSet );
00114   setTagValue( "CRATE", config -> crate, 0, dataSet );
00115   
00116   // copy the <data_set> node into the final XML
00117   DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
00118   root -> appendChild( cloneDataSet );
00119 
00120   return 0;
00121 }
00122 
00123 int XMLLUTLoader::addChecksums( checksumsDBConfig * config, std::string templateFileName )
00124 {
00125   DOMElement * root = document -> getDocumentElement();
00126 
00127   XMLDOMBlock dataSetDoc( templateFileName );
00128   DOMDocument * dataSet = dataSetDoc . getDocument();
00129 
00130   // changes to the Checksums <data_set> node
00131   setTagValue( "VERSION", config -> version, 0, dataSet );
00132   setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
00133   char timebuf[50];
00134   //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
00135   strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
00136   setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
00137   setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
00138   setTagValue( "COMMENT_DESCRIPTION", config -> comment_description, 0, dataSet );
00139   setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
00140   setTagValue( "TRIG_PRIM_LOOKUPTBL_DATA_FILE", config -> trig_prim_lookuptbl_data_file, 0, dataSet );
00141   setTagValue( "CRATE", config -> crate, 0, dataSet );
00142 
00143   // copy the <data_set> node into the final XML
00144   DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
00145   root -> appendChild( cloneDataSet );
00146 
00147   return 0;
00148 }
00149 
00150 int XMLLUTLoader::createLoader( std::vector<int> crate_number, std::vector<std::string> file_name )
00151 {
00152   XMLLUTLoader::lutDBConfig conf;
00153   XMLLUTLoader::checksumsDBConfig CSconf;
00154 
00155   for ( std::vector<std::string>::const_iterator _file = file_name . begin(); _file != file_name . end(); _file++ )
00156     {
00157       conf . trig_prim_lookuptbl_data_file = *_file;
00158       conf . trig_prim_lookuptbl_data_file += ".dat";
00159       conf . crate = crate_number[ _file - file_name . begin() ];
00160 
00161       char _buf[128];
00162       sprintf( _buf, "CRATE%.2d", conf . crate );
00163       std::string _namelabel;
00164       _namelabel . append( _buf );
00165       conf . name_label = _namelabel;
00166       addLUT( &conf );
00167     }
00168   
00169   CSconf . trig_prim_lookuptbl_data_file += ".dat";
00170   addChecksums( &CSconf );
00171   write( "LUTLoader.xml" );
00172 
00173   return 0;
00174 }
00175 
00176 //
00177 // const member functions
00178 //
00179 
00180 //
00181 // static member functions
00182 //