CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/CaloOnlineTools/HcalOnlineDb/src/XMLRBXPedestalsLoader.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     XMLTools
00004 // Class  :     XMLRBXPedestalsLoader
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: XMLRBXPedestalsLoader.cc,v 1.8 2010/08/06 20:24:13 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "CaloOnlineTools/HcalOnlineDb/interface/XMLRBXPedestalsLoader.h"
00018 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h"
00019 #include "CaloOnlineTools/HcalOnlineDb/interface/LMap.h"
00020 
00021 
00022 //
00023 // constants, enums and typedefs
00024 //
00025 
00026 //
00027 // static data member definitions
00028 //
00029 
00030 //
00031 // constructors and destructor
00032 //
00033 XMLRBXPedestalsLoader::loaderBaseConfig::_loaderBaseConfig()
00034 {
00035   extention_table_name = "HCAL_RBX_CONFIGURATION_TYPE01";
00036   name = "HCAL RBX configuration [PEDESTAL]";
00037   run_mode = "auto";
00038   data_set_id = "-1";
00039   iov_id = "1";
00040   iov_begin = 1;
00041   iov_end = -1;
00042   tag_id = "2";
00043   tag_mode = "auto";
00044   tag_name = "test_kukartsev_v1";
00045   detector_name = "HCAL";
00046   elements_comment_description = "RBX pedestals";
00047 }
00048 
00049 XMLRBXPedestalsLoader::datasetDBConfig::_datasetDBConfig() : XMLProcessor::DBConfig()
00050 {
00051   comment_description = "RBX pedestals for an RBX slot";
00052   name_label = "HEM10";
00053   kind_of_part = "HCAL RBX Slot";
00054 }
00055 
00056 XMLRBXPedestalsLoader::XMLRBXPedestalsLoader( loaderBaseConfig * config, std::string templateBase ) : XMLDOMBlock( templateBase )
00057 {
00058 
00059   init();
00060 
00061   setTagValue( "EXTENSION_TABLE_NAME", config -> extention_table_name );
00062   setTagValue( "NAME", config -> name );
00063   setTagAttribute( "RUN", "mode", config -> run_mode );
00064   setTagAttribute( "DATA_SET", "id", config -> data_set_id );
00065   setTagAttribute( "IOV", "id", config -> iov_id );
00066   setTagValue( "INTERVAL_OF_VALIDITY_BEGIN", config -> iov_begin );
00067   setTagValue( "INTERVAL_OF_VALIDITY_END", config -> iov_end );
00068   setTagAttribute( "TAG", "id", config -> tag_id );
00069   setTagAttribute( "TAG", "mode", config -> tag_mode );
00070   setTagValue( "TAG_NAME", config -> tag_name );
00071   setTagValue( "DETECTOR_NAME", config -> detector_name );
00072   setTagValue( "COMMENT_DESCRIPTION", config -> elements_comment_description );
00073   setTagAttribute( "TAG", "idref", config -> tag_id, 1 );
00074   setTagAttribute( "IOV", "idref", config -> iov_id, 1 );
00075   setTagAttribute( "DATA_SET", "idref", config -> data_set_id, 1 );
00076 }
00077 
00078 
00079 XMLRBXPedestalsLoader::~XMLRBXPedestalsLoader()
00080 {
00081   if( _data_ped_delay ) delete _data_ped_delay;
00082   if( _data_gol ) delete _data_gol;
00083   if( _data_led ) delete _data_led;
00084 }
00085 
00086 
00087 int XMLRBXPedestalsLoader::addRBXSlot( datasetDBConfig * config, std::string brickFileName, std::string rbx_config_type, std::string templateFileName )
00088 {
00089   DOMElement * root = document -> getDocumentElement();
00090 
00091   XMLDOMBlock dataSetDoc( templateFileName );
00092   DOMDocument * dataSet = dataSetDoc . getDocument();
00093 
00094   char timebuf[50];
00095   strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &(config -> create_timestamp) ) );
00096   setTagValue( "CREATE_TIMESTAMP", timebuf , 0, dataSet );
00097   setTagValue( "CREATED_BY_USER", config -> created_by_user, 0, dataSet );
00098   setTagValue( "VERSION", config -> version, 0, dataSet );
00099   setTagValue( "SUBVERSION", config -> subversion, 0, dataSet );
00100   setTagValue( "COMMENT_DESCRIPTION", config -> comment_description, 0, dataSet );
00101   setTagValue( "NAME_LABEL", config -> name_label, 0, dataSet );
00102   setTagValue( "KIND_OF_PART", config -> kind_of_part, 0, dataSet );
00103 
00104   // <DATA/>
00105   //XMLDOMBlock rbxBrickDoc( "rbx_HBM01_PEDESTAL.xml" );
00106   XMLDOMBlock rbxBrickDoc( brickFileName );
00107   DOMDocument * rbxBrick = rbxBrickDoc . getDocument();
00108   if ( rbx_config_type == "pedestals" || rbx_config_type == "delays" || rbx_config_type == "gols" ){
00109     for ( unsigned int _item = 0; _item < rbxBrick -> getElementsByTagName( XMLProcessor::_toXMLCh( "Data" ) ) -> getLength(); _item++ ){
00110       DOMElement * dataset_root = dataSet -> getDocumentElement();
00111       
00112       std::string _rm;
00113       std::string _qie;
00114       std::string _adc;
00115       //string _led_item;
00116       
00117       MemBufInputSource * _data; // a container for the XML template for a data block
00118       if ( rbx_config_type == "pedestals" || rbx_config_type == "delays" ){
00119         _rm = rbxBrickDoc . getTagAttribute( "Data", "rm", _item );
00120         _qie = rbxBrickDoc . getTagAttribute( "Data", "card", _item );
00121         _adc = rbxBrickDoc . getTagAttribute( "Data", "qie", _item );
00122         _data = _data_ped_delay;
00123       }
00124       else if ( rbx_config_type == "gols" ){
00125         _rm = rbxBrickDoc . getTagAttribute( "Data", "rm", _item );
00126         _qie = rbxBrickDoc . getTagAttribute( "Data", "card", _item );
00127         _adc = rbxBrickDoc . getTagAttribute( "Data", "gol", _item );
00128         _data = _data_gol;
00129       }
00130       //else if ( rbx_config_type == "leds" ){
00131       //_led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
00132       //_data = _data_led;
00133       //}
00134       else{
00135         std::cout << "XMLRBXPedestalsLoader::addRBXSlot(): Unknown config type... exiting" << std::endl;
00136         exit(1);
00137       }
00138       XMLDOMBlock dataDoc( *_data );
00139       DOMDocument * data = dataDoc . getDocument();
00140       std::string _value = rbxBrickDoc . getTagValue( "Data", _item );
00141       if ( rbx_config_type == "pedestals" || rbx_config_type == "delays" ){
00142         setTagValue( "MODULE_POSITION", _rm, 0, data );
00143         setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
00144         setTagValue( "QIE_ADC_NUMBER", _adc, 0, data );
00145       }
00146       else if ( rbx_config_type == "gols" ){
00147         setTagValue( "MODULE_POSITION", _rm, 0, data );
00148         setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
00149         setTagValue( "FIBER_NUMBER", _adc, 0, data );
00150       }
00151       else if ( rbx_config_type == "gols" ){
00152         setTagValue( "MODULE_POSITION", _rm, 0, data );
00153         setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
00154         setTagValue( "FIBER_NUMBER", _adc, 0, data );
00155       }
00156       else if ( rbx_config_type == "leds" ){
00157         setTagValue( "MODULE_POSITION", _rm, 0, data );
00158         setTagValue( "QIE_CARD_POSITION", _qie, 0, data );
00159         setTagValue( "FIBER_NUMBER", _adc, 0, data );
00160       }
00161       else{
00162         std::cout << "XMLRBXPedestalsLoader::addRBXSlot(): Unknown config type... exiting" << std::endl;
00163         exit(1);
00164       }
00165       setTagValue( "INTEGER_VALUE", _value, 0, data );
00166       DOMNode * cloneData = dataSet -> importNode( data -> getDocumentElement(), true );
00167       dataset_root -> appendChild( cloneData );
00168     }
00169   }
00170   else if ( rbx_config_type == "leds" ){
00171     DOMElement * dataset_root = dataSet -> getDocumentElement();
00172     
00173     std::string _led_item;
00174     
00175     MemBufInputSource * _data; // a container for the XML template for a data block
00176     _data = _data_led;
00177     std::string _value;
00178 
00179     XMLDOMBlock dataDoc( *_data );
00180     DOMDocument * data = dataDoc . getDocument();
00181 
00182     int _item = 0;
00183     _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
00184     // FIXME: need to check that the right data tag (_led_item) from the original brick is being processed
00185     _value = rbxBrickDoc . getTagValue( "Data", _item );
00186     setTagValue( "LED1_ON_IS_CHECKED", _value, 0, data );
00187     setTagValue( "SET_LEDS_IS_CHECKED", _value, 0, data );
00188     _item = 1;
00189     _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
00190     _value = rbxBrickDoc . getTagValue( "Data", _item );
00191     setTagValue( "LED2_ON_IS_CHECKED", _value, 0, data );
00192     if (_value.find("0")==std::string::npos){
00193       setTagValue( "SET_LEDS_IS_CHECKED", _value, 0, data );
00194     }
00195     _item = 2;
00196     _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
00197     _value = rbxBrickDoc . getTagValue( "Data", _item );
00198     setTagValue( "LED_AMPLITUDE", _value, 0, data );
00199     _item = 3;
00200     _led_item = rbxBrickDoc . getTagAttribute( "Data", "item", _item );
00201     _value = rbxBrickDoc . getTagValue( "Data", _item );
00202     setTagValue( "BUNCH_NUMBER", _value, 0, data );
00203     
00204     DOMNode * cloneData = dataSet -> importNode( data -> getDocumentElement(), true );
00205     dataset_root -> appendChild( cloneData );
00206   }
00207 
00208   // copy the <data_set> node into the final XML
00209   DOMNode * cloneDataSet = document -> importNode( dataSet -> getDocumentElement(), true );
00210   root -> appendChild( cloneDataSet );
00211 
00212   // update header from the brick
00213   std::string _name;
00214   int parameter_iter = -1;
00215   do
00216     {
00217       parameter_iter++;
00218       _name = rbxBrickDoc . getTagAttribute( "Parameter", "name", parameter_iter );
00219       //std::cout << _name << std::endl;
00220     } while( _name != "CREATIONTAG" ); 
00221   std::string _creationtag = rbxBrickDoc . getTagValue( "Parameter", parameter_iter );
00222   //std::cout << _creationtag << std::endl;
00223   //setTagValue( "TAG_NAME", _creationtag );    // uncomment if want to pick up tag name from the brick set
00224 
00225   parameter_iter = -1;
00226   do
00227     {
00228       parameter_iter++;
00229       _name = rbxBrickDoc . getTagAttribute( "Parameter", "name", parameter_iter );
00230       //std::cout << _name << std::endl;
00231     } while( _name != "RBX" ); 
00232   std::string _rbx = rbxBrickDoc . getTagValue( "Parameter", parameter_iter );
00233 
00234   // name_label fix - should be temporary
00235   //fixRbxName( _rbx );
00236   std::cout << _rbx << std::endl;
00237   setTagValue( "NAME_LABEL", _rbx );  
00238 
00239   // change kind of part name if this is ZDC (there is only one - ZDC01)
00240   if (_rbx.find("ZDC01")!=std::string::npos){
00241     setTagValue( "KIND_OF_PART", "HCAL ZDC RBX" );
00242     std::cout << " --> ZDC RBX!" << std::endl;
00243   }
00244 
00245   return 0;
00246 }
00247 
00248 int XMLRBXPedestalsLoader::fixRbxName( std::string & rbx )
00249 {
00250   std::string _fourth = rbx . substr(0,4);
00251   if ( _fourth == "HBM0" || _fourth == "HBP0" || _fourth == "HEP0" || _fourth == "HFP0" || _fourth == "HOP0" || _fourth == "HOM0" ) rbx . erase( 3, 1 );
00252 
00253   if ( rbx == "HO0M02" ) rbx = "HO0M2";
00254   if ( rbx == "HO0M04" ) rbx = "HO0M4";
00255   if ( rbx == "HO0M06" ) rbx = "HO0M6";
00256   if ( rbx == "HO0M08" ) rbx = "HO0M8";
00257   if ( rbx == "HO0M10" ) rbx = "HO0M10";
00258   if ( rbx == "HO0M12" ) rbx = "HO0M12";
00259   if ( rbx == "HO0P02" ) rbx = "HO0P2";
00260   if ( rbx == "HO0P04" ) rbx = "HO0P4";
00261   if ( rbx == "HO0P06" ) rbx = "HO0P6";
00262   if ( rbx == "HO0P08" ) rbx = "HO0P8";
00263   if ( rbx == "HO0P10" ) rbx = "HO0P10";
00264   if ( rbx == "HO0P12" ) rbx = "HO0P12";
00265 
00266   return 0;
00267 }
00268 
00269 int XMLRBXPedestalsLoader::init( void )
00270 {
00271   // define the <DATA/> template for pedestals and zero delays
00272   static const char * _str =  "\
00273   <DATA>\n\
00274    <MODULE_POSITION>2</MODULE_POSITION>\n\
00275    <QIE_CARD_POSITION>1</QIE_CARD_POSITION>\n\
00276    <QIE_ADC_NUMBER>0</QIE_ADC_NUMBER>\n\
00277    <INTEGER_VALUE>4</INTEGER_VALUE>\n\
00278   </DATA>\n\
00279   ";
00280   const XMLByte * _template = (const XMLByte *)_str;
00281   _data_ped_delay = new MemBufInputSource( _template, strlen( (const char *)_template ), "_data_ped_delay", false );
00282 
00283   // define the <DATA/> template for gol currents
00284   static const char * _str2 =  "\
00285   <DATA>\n\
00286    <MODULE_POSITION>2</MODULE_POSITION>\n\
00287    <QIE_CARD_POSITION>1</QIE_CARD_POSITION>\n\
00288    <FIBER_NUMBER>0</FIBER_NUMBER>\n\
00289    <INTEGER_VALUE>4</INTEGER_VALUE>\n\
00290   </DATA>\n\
00291   ";
00292   const XMLByte * _template2 = (const XMLByte *)_str2;
00293   _data_gol = new MemBufInputSource( _template2, strlen( (const char *)_template2 ), "_data_gol", false );
00294 
00295   // define the <DATA/> template for LED data
00296   static const char * _str3 =  "\
00297   <DATA>\n\
00298    <RM1_IS_CHECKED>1</RM1_IS_CHECKED>\n\
00299    <RM2_IS_CHECKED>1</RM2_IS_CHECKED>\n\
00300    <RM3_IS_CHECKED>1</RM3_IS_CHECKED>\n\
00301    <RM4_IS_CHECKED>1</RM4_IS_CHECKED>\n\
00302    <CALIB_IS_CHECKED>1</CALIB_IS_CHECKED>\n\
00303    <RESET1_IS_CHECKED>1</RESET1_IS_CHECKED>\n\
00304    <RESET1_VALUE>40</RESET1_VALUE>\n\
00305    <RESET1_WAIT_CYCLES>3</RESET1_WAIT_CYCLES>\n\
00306    <RESET2_IS_CHECKED>1</RESET2_IS_CHECKED>\n\
00307    <RESET2_VALUE>40</RESET2_VALUE>\n\
00308    <RESET2_WAIT_CYCLES>3</RESET2_WAIT_CYCLES>\n\
00309    <SET_LEDS_IS_CHECKED>0</SET_LEDS_IS_CHECKED>\n\
00310    <LED1_ON_IS_CHECKED>0</LED1_ON_IS_CHECKED>\n\
00311    <LED2_ON_IS_CHECKED>0</LED2_ON_IS_CHECKED>\n\
00312    <LED_AMPLITUDE>128</LED_AMPLITUDE>\n\
00313    <LED_DELAY>1000</LED_DELAY>\n\
00314    <TTCRX_PHASE>100</TTCRX_PHASE>\n\
00315    <BROADCAST_SETTINGS>1</BROADCAST_SETTINGS>\n\
00316    <QIE_RESET_DELAY>5</QIE_RESET_DELAY>\n\
00317    <BUNCH_NUMBER>2000</BUNCH_NUMBER>\n\
00318   </DATA>\n\
00319   ";
00320   const XMLByte * _template3 = (const XMLByte *)_str3;
00321   _data_led = new MemBufInputSource( _template3, strlen( (const char *)_template3 ), "_data_led", false );
00322 
00323   return 0;
00324 }
00325 
00326 //
00327 // const member functions
00328 //
00329 
00330 //
00331 // static member functions
00332 //