CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CaloOnlineTools/HcalOnlineDb/src/XMLHTRPatternLoader.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     XMLTools
00004 // Class  :     XMLHTRPatternLoader
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: XMLHTRPatternLoader.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/XMLHTRPatternLoader.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 XMLHTRPatternLoader::loaderBaseConfig::_loaderBaseConfig() : XMLProcessor::loaderBaseConfig()
00033 {
00034   extention_table_name = "HCAL_HTR_DATA_PATTERNS";
00035   name = "HCAL HRT data patterns";
00036   run_mode = "no-run";
00037   data_set_id = "-1";
00038   iov_id = "1";
00039   iov_begin = "0";
00040   iov_end = "1";
00041   tag_id = "2";
00042   tag_mode = "auto";
00043   tag_name = "HTR data pattern test";
00044   detector_name = "HCAL";
00045   comment_description = "empty comment, by kukarzev";
00046 }
00047 
00048 XMLHTRPatternLoader::datasetDBConfig::_datasetDBConfig() : XMLProcessor::DBConfig()
00049 {
00050   kind_of_part = "HCAL HTR Crate";
00051   name_label = "CRATE17";
00052   htr_data_patterns_data_file = "testHTRPatterns_17.xml";
00053   crate = 17;
00054 }
00055 
00056 XMLHTRPatternLoader::checksumsDBConfig::_checksumsDBConfig() : XMLProcessor::DBConfig()
00057 {
00058   comment_description = "checksum for all crates version test:2";
00059   name_label = "CMS-HCAL-ROOT";
00060   htr_data_patterns_data_file = "./testHTRPattern_checksums.xml";
00061   crate = -1;
00062 }
00063 
00064 XMLHTRPatternLoader::XMLHTRPatternLoader()
00065 {
00066 }
00067 
00068 XMLHTRPatternLoader::XMLHTRPatternLoader( XMLProcessor::loaderBaseConfig * config, std::string templateBase ) : XMLDOMBlock( templateBase )
00069 {
00070   setTagValue( "EXTENSION_TABLE_NAME", config -> extention_table_name );
00071   setTagValue( "NAME", config -> name );
00072   setTagAttribute( "RUN", "mode", config -> run_mode );
00073   setTagAttribute( "DATA_SET", "id", config -> data_set_id );
00074   setTagAttribute( "IOV", "id", config -> iov_id );
00075   setTagValue( "INTERVAL_OF_VALIDITY_BEGIN", config -> iov_begin );
00076   setTagValue( "INTERVAL_OF_VALIDITY_END", config -> iov_end );
00077   setTagAttribute( "TAG", "id", config -> tag_id );
00078   setTagAttribute( "TAG", "mode", config -> tag_mode );
00079   setTagValue( "TAG_NAME", config -> tag_name );
00080   setTagValue( "DETECTOR_NAME", config -> detector_name );
00081   setTagValue( "COMMENT_DESCRIPTION", config -> comment_description );
00082 
00083   setTagAttribute( "TAG", "idref", config -> tag_id, 1 );
00084   setTagAttribute( "IOV", "idref", config -> iov_id, 1 );
00085   setTagAttribute( "DATA_SET", "idref", config -> data_set_id, 1 );
00086 }
00087 
00088 // XMLHTRPatternLoader::XMLHTRPatternLoader(const XMLHTRPatternLoader& rhs)
00089 // {
00090 //    // do actual copying here;
00091 // }
00092 
00093 XMLHTRPatternLoader::~XMLHTRPatternLoader()
00094 {
00095 }
00096 
00097 //
00098 // assignment operators
00099 //
00100 // const XMLHTRPatternLoader& XMLHTRPatternLoader::operator=(const XMLHTRPatternLoader& rhs)
00101 // {
00102 //   //An exception safe implementation is
00103 //   XMLHTRPatternLoader temp(rhs);
00104 //   swap(rhs);
00105 //
00106 //   return *this;
00107 // }
00108 
00109 //
00110 // member functions
00111 //
00112 int XMLHTRPatternLoader::addPattern( datasetDBConfig * config, std::string templateFileName )
00113 {
00114   DOMElement * root = document -> getDocumentElement();
00115 
00116   XMLDOMBlock dataSetDoc( templateFileName );
00117   DOMDocument * dataSet = dataSetDoc . getDocument();
00118 
00119   // changes to the HTRPATTERN <data_set> node
00120   setTagValue( "VERSION", config -> version, 0, dataSet );
00121   setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
00122   char timebuf[50];
00123   //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
00124   strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
00125   setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
00126   setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
00127   setTagValue( "KIND_OF_PART", config -> kind_of_part, 0, dataSet );
00128   setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
00129   setTagValue( "HTR_DATA_PATTERNS_DATA_FILE", config -> htr_data_patterns_data_file, 0, dataSet );
00130   setTagValue( "CRATE", config -> crate, 0, dataSet );
00131   
00132   // copy the <data_set> node into the final XML
00133   DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
00134   root -> appendChild( cloneDataSet );
00135 
00136   return 0;
00137 }
00138 
00139 int XMLHTRPatternLoader::addChecksums( checksumsDBConfig * config, std::string templateFileName )
00140 {
00141   DOMElement * root = document -> getDocumentElement();
00142 
00143   XMLDOMBlock dataSetDoc( templateFileName );
00144   DOMDocument * dataSet = dataSetDoc . getDocument();
00145 
00146   // changes to the Checksums <data_set> node
00147   setTagValue( "VERSION", config -> version, 0, dataSet );
00148   setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
00149   char timebuf[50];
00150   //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
00151   strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
00152   setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
00153   setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
00154   setTagValue( "COMMENT_DESCRIPTION", config -> comment_description, 0, dataSet );
00155   setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
00156   setTagValue( "HTR_DATA_PATTERNS_DATA_FILE", config -> htr_data_patterns_data_file, 0, dataSet );
00157   setTagValue( "CRATE", config -> crate, 0, dataSet );
00158 
00159   // copy the <data_set> node into the final XML
00160   DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
00161   root -> appendChild( cloneDataSet );
00162 
00163   return 0;
00164 }
00165 
00166 int XMLHTRPatternLoader::createLoader( std::vector<int> crate_number, std::vector<std::string> file_name )
00167 {
00168   XMLHTRPatternLoader::datasetDBConfig conf;
00169 
00170   for ( std::vector<std::string>::const_iterator _file = file_name . begin(); _file != file_name . end(); _file++ )
00171     {
00172       conf . htr_data_patterns_data_file = *_file;
00173       conf . htr_data_patterns_data_file += ".dat";
00174       conf . crate = crate_number[ _file - file_name . begin() ];
00175 
00176       char _buf[128];
00177       sprintf( _buf, "CRATE%.2d", conf . crate );
00178       std::string _namelabel;
00179       _namelabel . append( _buf );
00180       conf . name_label = _namelabel;
00181       addPattern( &conf );
00182     }
00183   
00184   write( "HTRPatternLoader.xml" );
00185 
00186   return 0;
00187 }
00188 
00189 //
00190 // const member functions
00191 //
00192 
00193 //
00194 // static member functions
00195 //