CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/L1Trigger/RPCTechnicalTrigger/src/TTUEmulator.cc

Go to the documentation of this file.
00001 // $Id: TTUEmulator.cc,v 1.16 2009/10/27 09:01:48 aosorio Exp $
00002 // Include files 
00003 
00004 
00005 #include <cmath>
00006 #include <algorithm>
00007 // local
00008 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUEmulator.h"
00009 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUBasicConfig.h"
00010 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCLinkBoardGLSignal.h"
00011 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUGlobalSignal.h"
00012 
00013 //-----------------------------------------------------------------------------
00014 // Implementation file for class : TTUEmulator
00015 //
00016 // 2008-10-15 : Andres Osorio
00017 //-----------------------------------------------------------------------------
00018 
00019 //=============================================================================
00020 // Standard constructor, initializes variables
00021 //=============================================================================
00022 TTUEmulator::TTUEmulator( int id, int mxw  ) 
00023 {
00024   
00025   m_id        = id;
00026   m_maxWheels = mxw;
00027   
00028   int tmp[6]  = {1,  2, 0, 0, -1, -2};
00029   m_wheelIds = new int[6];
00030   for( int k=0; k < 6; ++k) m_wheelIds[k]=tmp[k];
00031   
00032   m_Wheels = new RPCWheel[2];
00033   for( int k=0; k < m_maxWheels; ++k ) 
00034     m_Wheels[k].setProperties( m_wheelIds[(id*2)+(k-2)] );
00035   
00036   m_ttuin = new TTUInput[2];
00037   
00038   m_trigger.reset();
00039   
00040   m_mode = 1;
00041   
00042   m_debug = false;
00043   
00044   m_line = 1;
00045   
00046 }
00047 
00048 
00049 TTUEmulator::TTUEmulator( int id, const char * rbclogic_type, const char * ttulogic_type, int mxw  ) 
00050 {
00051   
00052   m_id        = id;
00053   m_maxWheels = mxw;
00054 
00055   int tmp[6]  = {1,  2, 0, 0, -1, -2};
00056   m_wheelIds = new int[6];
00057   for( int k=0; k < 6; ++k) m_wheelIds[k]=tmp[k];
00058   
00059   m_Wheels = new RPCWheel[2];
00060   for( int k=0; k < m_maxWheels; ++k ) 
00061     m_Wheels[k].setProperties( m_wheelIds[(id*2)+(k-2)], rbclogic_type );
00062   
00063   m_ttuin = new TTUInput[2];
00064   
00065   m_ttuconf   = dynamic_cast<TTUConfiguration*> (new TTUBasicConfig (ttulogic_type));
00066   
00067   m_trigger.reset();
00068   
00069   m_mode = 1;
00070 
00071   m_debug = false;
00072 
00073   m_line = 1;
00074   
00075 }
00076 
00077 TTUEmulator::TTUEmulator( int id, const char * f_name, const char * rbclogic_type, 
00078                           const char * ttulogic_type, int mxw  ) 
00079 {
00080   
00081   m_id        = id;
00082   m_maxWheels = mxw;
00083 
00084   int tmp[6]  = {1,  2, 0, 0, -1, -2};
00085   m_wheelIds = new int[6];
00086   for( int k=0; k < 6; ++k) m_wheelIds[k]=tmp[k];
00087   
00088   m_Wheels = new RPCWheel[2];
00089   for( int k=0; k < m_maxWheels; ++k ) 
00090     m_Wheels[k].setProperties( m_wheelIds[(id*2)+(k-2)], f_name, rbclogic_type );
00091   
00092   m_ttuin = new TTUInput[2];
00093   
00094   m_ttuconf   = dynamic_cast<TTUConfiguration*> (new TTUBasicConfig (ttulogic_type));
00095   
00096   m_trigger.reset();
00097   
00098   m_mode = 1;
00099   
00100   m_debug = false;
00101 
00102   m_line = 1;
00103   
00104 }
00105 
00106 //=============================================================================
00107 // Destructor
00108 //=============================================================================
00109 TTUEmulator::~TTUEmulator() {
00110 
00111   if ( m_wheelIds ) delete[] m_wheelIds;
00112   if ( m_Wheels   ) delete[] m_Wheels;
00113   if ( m_ttuin    ) delete[] m_ttuin;
00114   if ( m_ttuconf  ) delete m_ttuconf;
00115   
00116 } 
00117 
00118 //=============================================================================
00119 void TTUEmulator::setSpecifications( const TTUBoardSpecs * ttuspecs, const RBCBoardSpecs * rbcspecs) 
00120 {
00121   
00122   m_ttuconf   = dynamic_cast<TTUConfiguration*> (new TTUBasicConfig (ttuspecs));
00123   
00124   for( int k=0; k < m_maxWheels; ++k)
00125     m_Wheels[k].setSpecifications( rbcspecs );
00126 
00127   std::vector<TTUBoardSpecs::TTUBoardConfig>::const_iterator itr;
00128   itr = m_ttuconf->m_ttuboardspecs->m_boardspecs.begin();
00129   
00130   m_mode = (*itr).m_triggerMode;
00131   
00132 }
00133 
00134 bool TTUEmulator::initialise()
00135 {
00136   bool status(false);
00137   for( int k=0; k < m_maxWheels; ++k)
00138     status = m_Wheels[k].initialise( );
00139   
00140   status = m_ttuconf->initialise( m_line , m_id );
00141   
00142   if ( !status ) { 
00143     if( m_debug ) std::cout << "TTUEmulator> Problem initialising the Configuration \n"; 
00144     return 0; };
00145   
00146   return status;
00147   
00148 }
00149 
00150 void TTUEmulator::SetLineId( int line )
00151 {
00152   m_line = line;
00153 }
00154 
00155 void TTUEmulator::emulate() 
00156 {
00157   //... only for testing
00158   for( int k=0; k < m_maxWheels; ++k ) 
00159     m_Wheels[k].emulate();
00160   
00161 }
00162 
00163 void TTUEmulator::processTtu( RPCInputSignal * signal ) 
00164 {
00165   
00166   //. 
00167   int bx(0);
00168   bool trg(false); 
00169 
00170   if( m_debug ) std::cout << "TTUEmulator::processTtu starts" << '\n';
00171   
00172   m_trigger.reset();
00173   m_triggerBx.clear();
00174   
00175   std::vector<int> bxVec;
00176   std::vector<int>::iterator bxItr;
00177   std::map<int,RBCInput*> * linkboardin;
00178   std::map<int,RBCInput*>::iterator inItr;
00179   
00180   linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>( signal )->m_linkboardin;
00181   
00182   for( inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr) 
00183   {
00184     
00185     if ( (*inItr).first < 0 ) bx = (int) ceil( (*inItr).first / 1000000.0 );
00186     else bx = (int) floor( (*inItr).first / 1000000.0 );
00187     bxVec.push_back(bx);
00188     
00189   }
00190   
00191   bxItr = unique (bxVec.begin(), bxVec.end());
00192   bxVec.resize(bxItr - bxVec.begin());
00193   
00194   for ( bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
00195     
00196     TriggerResponse * triggerResponse = new TriggerResponse();
00197     
00198     for( int k=0; k < m_maxWheels; ++k )
00199     {
00200       
00201       if ( m_Wheels[k].process( (*bxItr) , (*linkboardin) ) ) {
00202         
00203         m_Wheels[k].createWheelMap();
00204         
00205         m_Wheels[k].retrieveWheelMap( (m_ttuin[k]) );
00206         
00207         //.. execute selected logic at Ttu level
00208         m_ttuconf->m_ttulogic->run( (m_ttuin[k]) );
00209         
00210         //... and produce a Wheel level trigger
00211         trg = m_ttuconf->m_ttulogic->isTriggered();
00212         
00213         m_trigger.set(k,trg);
00214         
00215         if( m_debug ) std::cout << "TTUEmulator::processTtu ttuid: " << m_id 
00216                                 << " bx: "          << (*bxItr)
00217                                 << " wheel: "       << m_Wheels[k].getid()
00218                                 << " response: "    << trg << std::endl;
00219         
00220       }
00221 
00222       
00223     }
00224 
00225     
00226     triggerResponse->setTriggerBits( (*bxItr) , m_trigger );
00227     m_triggerBxVec.push_back( triggerResponse );
00228     m_triggerBx[ (*bxItr) ] = m_trigger;
00229     
00230   }
00231   
00232   
00233   if( m_debug ) std::cout << "TTUEmulator::processTtu> size of trigger map " 
00234                           << m_triggerBx.size() << std::endl;
00235   
00236   
00237   if( m_debug ) std::cout << "TTUEmulator::processTtu> done with this TTU: " << m_id << std::endl;
00238 
00239   bxVec.clear();
00240 
00241   if( m_debug ) std::cout << "TTUEmulator::processTtu ends" << '\n';
00242     
00243 }
00244 
00245 void TTUEmulator::processTtu( RPCInputSignal * signal , int wedgeId ) 
00246 {
00247   
00248   //. 
00249   int bx(0);
00250   bool trg(false); 
00251   
00252   if( m_debug ) std::cout << "TTUEmulator::processTtu( Pointing ) starts " << '\n';
00253   
00254   m_trigger.reset();
00255   m_triggerBx.clear();
00256   
00257   std::vector<int> bxVec;
00258   std::vector<int>::iterator bxItr;
00259   std::map<int,RBCInput*> * linkboardin;
00260   std::map<int,RBCInput*>::iterator inItr;
00261   
00262   linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>( signal )->m_linkboardin;
00263   
00264   for( inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr) 
00265   {
00266     
00267     if ( (*inItr).first < 0 ) bx = (int) ceil( (*inItr).first / 1000000.0 );
00268     else bx = (int) floor( (*inItr).first / 1000000.0 );
00269     bxVec.push_back(bx);
00270     
00271   }
00272   
00273   bxItr = unique (bxVec.begin(), bxVec.end());
00274   bxVec.resize(bxItr - bxVec.begin());
00275   
00276   for ( bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
00277     
00278     TriggerResponse * triggerResponse = new TriggerResponse();
00279     
00280     for( int k=0; k < m_maxWheels; ++k )
00281     {
00282       
00283       if ( m_Wheels[k].process( (*bxItr) , (*linkboardin) ) ) { // <- this process uses the default RBC emulation but need a different logic
00284         
00285         m_Wheels[k].createWheelMap();
00286         
00287         m_Wheels[k].retrieveWheelMap( (m_ttuin[k]) );
00288         
00289         //.. execute selected logic at Ttu level
00290         m_ttuconf->m_ttulogic->run( (m_ttuin[k]) , wedgeId );
00291         
00292         //... and produce a Wheel-Wedge level trigger
00293         trg = m_ttuconf->m_ttulogic->isTriggered();
00294         
00295         m_trigger.set(k,trg);
00296         
00297         if( m_debug ) std::cout << "TTUEmulator::processTtu( Pointing ) ttuid: " << m_id 
00298                                 << " bx: "          << (*bxItr)
00299                                 << " wheel: "       << m_Wheels[k].getid()
00300                                 << " response: "    << trg << std::endl;
00301         
00302       }
00303       
00304       
00305     }
00306     
00307     triggerResponse->setTriggerBits( (*bxItr) , wedgeId, m_trigger );
00308     m_triggerBxVec.push_back( triggerResponse );
00309     m_triggerBx[ (*bxItr) ] = m_trigger;
00310     
00311   }
00312   
00313   if( m_debug ) std::cout << "TTUEmulator::processTtu (Pointing) > size of trigger map " 
00314                           << m_triggerBx.size() << std::endl;
00315   
00316   if( m_debug ) std::cout << "TTUEmulator::processTtu (Pointing) > done with this TTU: " << m_id << std::endl;
00317   
00318   bxVec.clear();
00319 
00320   if( m_debug ) std::cout << "TTUEmulator::processTtu( Pointing ) end" << '\n';
00321   
00322 }
00323 
00324 
00325 void TTUEmulator::clearTriggerResponse()
00326 {
00327   
00328   std::vector<TriggerResponse*>::iterator itr;
00329   for ( itr = m_triggerBxVec.begin(); itr != m_triggerBxVec.end(); ++itr)
00330     if ( (*itr) ) delete (*itr);
00331   m_triggerBxVec.clear();
00332   
00333 }
00334 
00335 //.................................................................
00336 
00337 void TTUEmulator::printinfo() 
00338 {
00339   
00340   std::cout << "TTUEmulator: " << m_id << '\n';
00341   for( int k=0; k < m_maxWheels; ++k ) 
00342     m_Wheels[k].printinfo();
00343   
00344 }
00345