CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/L1Trigger/RPCTechnicalTrigger/src/RBCEmulator.cc

Go to the documentation of this file.
00001 // $Id: RBCEmulator.cc,v 1.11 2009/07/04 20:07:40 aosorio Exp $
00002 // Include files 
00003 
00004 // local
00005 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCEmulator.h"
00006 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCBasicConfig.h"
00007 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCProcessTestSignal.h"
00008 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCLinkBoardSignal.h"
00009 
00010 //-----------------------------------------------------------------------------
00011 // Implementation file for class : RBCEmulator
00012 //
00013 // 2008-10-10 : Andres Osorio
00014 //-----------------------------------------------------------------------------
00015 
00016 //=============================================================================
00017 // Standard constructor, initializes variables
00018 //=============================================================================
00019 RBCEmulator::RBCEmulator( ) {
00020   
00021   m_signal  = NULL;
00022   m_logtype = std::string("TestLogic");
00023   m_rbcinfo = new RBCId();
00024   m_input   = new RBCInput();
00025     
00026   m_layersignal[0] = new std::bitset<6>();
00027   m_layersignal[1] = new std::bitset<6>();
00028   m_layersignalVec.push_back( m_layersignal[0] );
00029   m_layersignalVec.push_back( m_layersignal[1] );
00030 
00031   m_debug   = false;
00032   
00033 }
00034 
00035 RBCEmulator::RBCEmulator( const char * logic_type ) {
00036   
00037   m_signal  = NULL;
00038   m_logtype = std::string( logic_type );
00039   m_rbcinfo = new RBCId();
00040   m_input   = new RBCInput();
00041   m_rbcconf = dynamic_cast<RBCConfiguration*> (new RBCBasicConfig(logic_type));
00042   
00043   m_layersignal[0] = new std::bitset<6>();
00044   m_layersignal[1] = new std::bitset<6>();
00045   m_layersignalVec.push_back( m_layersignal[0] );
00046   m_layersignalVec.push_back( m_layersignal[1] );
00047   
00048   m_debug   = false;
00049   
00050 }
00051 
00052 RBCEmulator::RBCEmulator( const char * f_name  , const char * logic_type ) {
00053   
00054   m_signal  = dynamic_cast<ProcessInputSignal*>(new RBCProcessTestSignal( f_name ));
00055   m_logtype = std::string( logic_type );
00056   m_rbcinfo = new RBCId();
00057   m_input   = new RBCInput();
00058   m_rbcconf = dynamic_cast<RBCConfiguration*> (new RBCBasicConfig(logic_type));
00059 
00060   m_layersignal[0] = new std::bitset<6>();
00061   m_layersignal[1] = new std::bitset<6>();
00062   m_layersignalVec.push_back( m_layersignal[0] );
00063   m_layersignalVec.push_back( m_layersignal[1] );
00064   
00065   m_debug   = false;
00066   
00067 }
00068 
00069 //=============================================================================
00070 // Destructor
00071 //=============================================================================
00072 RBCEmulator::~RBCEmulator() {
00073   
00074   if (m_signal)  delete m_signal;
00075   if (m_rbcconf) delete m_rbcconf;
00076   if (m_rbcinfo) delete m_rbcinfo;
00077   if (m_input)   delete m_input;
00078 
00079   std::vector<std::bitset<6>*>::iterator itr;
00080   for(itr =  m_layersignalVec.begin(); itr != m_layersignalVec.end(); ++itr)
00081     delete (*itr);
00082   
00083 } 
00084 
00085 //=============================================================================
00086 void RBCEmulator::setSpecifications( const RBCBoardSpecs * rbcspecs) 
00087 {
00088 
00089   m_rbcconf = dynamic_cast<RBCConfiguration*> (new RBCBasicConfig(rbcspecs, m_rbcinfo));
00090 
00091 }
00092 
00093 bool RBCEmulator::initialise() 
00094 {
00095   
00096   bool status(true);
00097   
00098   status = m_rbcconf->initialise();
00099   
00100   if ( !status ) { 
00101     if( m_debug ) std::cout << "RBCEmulator> Problem initialising the Configuration \n"; 
00102     return 0; };
00103   
00104   return 1;
00105   
00106 }
00107 
00108 void RBCEmulator::setid( int wh, int * sec)
00109 {
00110   m_rbcinfo->setid ( wh, sec);
00111 }
00112 
00113 void RBCEmulator::emulate() 
00114 {
00115   
00116   if( m_debug ) std::cout << "RBCEmulator> starting test emulation" << std::endl;
00117   
00118   std::bitset<2> decision;
00119   
00120   while ( m_signal->next() ) 
00121   {
00122     
00123     RPCInputSignal * data = m_signal->retrievedata();
00124     (*m_input) = * dynamic_cast<RBCLinkBoardSignal*>( data )->m_linkboardin ;
00125     
00126     m_rbcconf->m_rbclogic->run( (*m_input) , decision );
00127     
00128     m_layersignal[0] = m_rbcconf->m_rbclogic->getlayersignal( 0 );
00129     m_layersignal[1] = m_rbcconf->m_rbclogic->getlayersignal( 1 );
00130     
00131     printlayerinfo();
00132     
00133     if ( m_debug ) std::cout << decision[0] << " " << decision[1] << std::endl;
00134     
00135   }
00136   
00137   if( m_debug ) std::cout << "RBCEmulator> end test emulation" << std::endl;
00138   
00139 }
00140 
00141 void RBCEmulator::emulate( RBCInput * in )
00142 {
00143   
00144   if( m_debug ) std::cout << "RBCEmulator> starting emulation" << std::endl;
00145   
00146   std::bitset<2> decision;
00147   
00148   in->setWheelId( m_rbcinfo->wheel() );
00149   
00150   (*m_input) =  (*in);
00151   
00152   if( m_debug ) std::cout << "RBCEmulator> copied data" << std::endl;
00153 
00154   //.. mask and force as specified in hardware configuration
00155   m_rbcconf->preprocess( (*m_input) );
00156 
00157   if( m_debug ) std::cout << "RBCEmulator> preprocessing done" << std::endl;
00158     
00159   m_rbcconf->m_rbclogic->run( (*m_input) , decision );
00160 
00161   if( m_debug ) std::cout << "RBCEmulator> applying logic" << std::endl;
00162   
00163   m_layersignal[0] = m_rbcconf->m_rbclogic->getlayersignal( 0 );
00164   m_layersignal[1] = m_rbcconf->m_rbclogic->getlayersignal( 1 );
00165 
00166   m_decision.set(0, decision[0] );
00167   m_decision.set(1, decision[1] );
00168     
00169   if( m_debug ) {
00170     printlayerinfo();
00171     std::cout << decision[0] << " " << decision[1] << std::endl;
00172     std::cout << "RBCEmulator> end emulation" << std::endl;
00173   }
00174   
00175   decision.reset();  
00176   
00177 }
00178 
00179 void RBCEmulator::reset()
00180 {
00181 
00182   m_decision.reset();
00183   m_layersignal[0]->reset();
00184   m_layersignal[1]->reset();
00185   
00186 }
00187 
00188 void RBCEmulator::printinfo()
00189 {
00190   
00191   if( m_debug ) {
00192     std::cout << "RBC --> \n";
00193     m_rbcinfo->printinfo();
00194   }
00195   
00196 }
00197 
00198 void RBCEmulator::printlayerinfo()
00199 {
00200 
00201   std::cout << "Sector summary by layer: \n";
00202   for(int i=0; i < 6; ++i)
00203     std::cout << (*m_layersignal[0])[i] << '\t' 
00204               << (*m_layersignal[1])[i] << '\n';  
00205   
00206 }