CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CaloOnlineTools/HcalOnlineDb/src/HcalTriggerKey.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     XMLTools
00004 // Class  :     HcalTriggerKey
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Gena Kukartsev, kukarzev@fnal.gov
00010 //         Created:  August 27, 2008
00011 //
00012 
00013 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalTriggerKey.h"
00014 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h"
00015 #include "CaloOnlineTools/HcalOnlineDb/interface/LMap.h"
00016 
00017 HcalTriggerKey::HcalTriggerKey( void )
00018 {
00019   _root = 0;
00020   _data = 0;
00021   init();
00022   parse(*_root);
00023 }
00024 
00025 
00026 HcalTriggerKey::~HcalTriggerKey()
00027 {
00028   if( _root ) delete _root;
00029   if( _data ) delete _data;
00030 }
00031 
00032 
00033 int HcalTriggerKey::init( void )
00034 {
00035   static const char * _str =  "\
00036   <ROOT>\n\
00037     <HEADER>\n\
00038       <TYPE>\n\
00039         <EXTENSION_TABLE_NAME>HCAL_TRIGGER_KEY</EXTENSION_TABLE_NAME>\n\
00040         <NAME>HCAL trigger key</NAME>\n\
00041       </TYPE>\n\
00042        <RUN mode='no-run' />\n\
00043     </HEADER>\n\
00044    <DATA_SET>\n\
00045       <VERSION>test_version</VERSION>\n\
00046       <SUBVERSION>1</SUBVERSION>\n\
00047      <CREATE_TIMESTAMP>2000-01-01 00:00:00.0</CREATE_TIMESTAMP>\n\
00048      <CREATED_BY_USER>kukarzev</CREATED_BY_USER>\n\
00049      <COMMENT_DESCRIPTION>test trigger key</COMMENT_DESCRIPTION>\n\
00050       <PART>\n\
00051          <NAME_LABEL>CMS-HCAL-ROOT</NAME_LABEL>\n\
00052       </PART>\n\
00053    </DATA_SET>\n\
00054   <!-- Tags secton -->\n\
00055       <ELEMENTS>\n\
00056           <DATA_SET id='-1'/>\n\
00057           <IOV id='1'>\n\
00058               <INTERVAL_OF_VALIDITY_BEGIN>0</INTERVAL_OF_VALIDITY_BEGIN>\n\
00059               <INTERVAL_OF_VALIDITY_END>1</INTERVAL_OF_VALIDITY_END>\n\
00060           </IOV>\n\
00061           <TAG id='2' mode='auto'>\n\
00062               <TAG_NAME>trigger_key_tag</TAG_NAME>\n\
00063               <DETECTOR_NAME>HCAL</DETECTOR_NAME>\n\
00064               <COMMENT_DESCRIPTION>trigger_key_tag</COMMENT_DESCRIPTION>\n\
00065           </TAG>\n\
00066       </ELEMENTS>\n\
00067       <MAPS>\n\
00068           <TAG idref='2'>\n\
00069               <IOV idref='1'>\n\
00070                   <DATA_SET idref='-1' />\n\
00071               </IOV>\n\
00072           </TAG>\n\
00073       </MAPS>\n\
00074   </ROOT>\n\
00075   ";
00076   const XMLByte * _template = (const XMLByte *)_str;
00077   _root = new MemBufInputSource( _template, strlen( (const char *)_template ), "_root", false );
00078 
00079   static const char * _str2 =  "\
00080       <DATA>\n\
00081          <TRIGGER_KEY_ID>TEST_trigger_key</TRIGGER_KEY_ID>\n\
00082          <TRIGGER_KEY_CONFIG_TYPE>LUT_tag</TRIGGER_KEY_CONFIG_TYPE>\n\
00083          <TRIGGER_KEY_CONFIG_VALUE>CRUZET_part4_physics_v3</TRIGGER_KEY_CONFIG_VALUE>\n\
00084       </DATA>\n\
00085   ";
00086   const XMLByte * _template2 = (const XMLByte *)_str2;
00087   _data = new MemBufInputSource( _template2, strlen( (const char *)_template2 ), "_data", false );
00088 
00089   return 0;
00090 }
00091 
00092 
00093 int HcalTriggerKey::add_data( std::string id, std::string type, std::string value){
00094   XMLDOMBlock data_block( *_data );
00095   data_block.setTagValue("TRIGGER_KEY_ID",id);
00096   data_block.setTagValue("TRIGGER_KEY_CONFIG_TYPE",type);
00097   data_block.setTagValue("TRIGGER_KEY_CONFIG_VALUE",value);
00098 
00099   DOMDocument * data_doc = data_block . getDocument();
00100 
00101   DOMElement * data_set_elem = (DOMElement *)(document -> getElementsByTagName( XMLProcessor::_toXMLCh( "DATA_SET" ) ) -> item(0));
00102 
00103   DOMNode * clone_data = document -> importNode( data_doc -> getDocumentElement(), true );
00104   data_set_elem -> appendChild( clone_data );
00105 
00106   //write("stdout");
00107 
00108   return 0;
00109 }
00110 
00111 
00112 int HcalTriggerKey::fill_key( std::string key_id, std::map<std::string, std::string> & key){
00113   int _c=0;
00114   for(std::map<std::string,std::string>::const_iterator key_pair=key.begin(); key_pair!=key.end(); key_pair++){
00115     add_data(key_id, key_pair->first, key_pair->second);
00116     _c++;
00117   }
00118   
00119   return _c;
00120 }
00121 
00122 int HcalTriggerKey::compose_key_dialogue( void ){
00123   std::map<std::string, std::string> _key;
00124   std::string _id, _type, _value;
00125 
00126   std::cout << std::endl << "Creating the trigger key..." << std::endl;
00127   std::cout << std::endl << "Enter the key ID (or tag if you would): " << std::endl;
00128   std::getline(std::cin, _id);
00129   while(1){
00130     std::cout << "Enter the next config type (or type exit if the trigger key is complete): " << std::endl;
00131     std::getline(std::cin, _type);
00132     if (_type.find("exit") != std::string::npos) break;
00133     std::cout << "Enter the config value: " << std::endl;
00134     std::getline(std::cin, _value);
00135     _key.insert(std::pair<std::string, std::string>(_type, _value));
00136   }
00137 
00138   fill_key(_id, _key);
00139 
00140   std::cout << std::endl << "Creating the trigger key... done" << std::endl;
00141   return 0;
00142 }