CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/L1Trigger/RPCTechnicalTrigger/src/RPCWheel.cc

Go to the documentation of this file.
00001 // $Id: RPCWheel.cc,v 1.12 2009/08/19 15:04:01 aosorio Exp $
00002 // Include files
00003 
00004 
00005 
00006 // local
00007 #include "L1Trigger/RPCTechnicalTrigger/interface/RPCWheel.h"
00008 
00009 //-----------------------------------------------------------------------------
00010 // Implementation file for class : RPCWheel
00011 //
00012 // 2008-10-15 : Andres Osorio
00013 //-----------------------------------------------------------------------------
00014 
00015 //=============================================================================
00016 // Standard constructor, initializes variables
00017 //=============================================================================
00018 RPCWheel::RPCWheel() {
00019   
00020   m_id = 0; 
00021   
00022   m_maxrbc     = 6;
00023   m_maxlayers  = 6;
00024   m_maxsectors = 12;
00025   
00026   m_debug = false;
00027 
00028   m_sec1id.push_back(12);
00029   m_sec2id.push_back(1);
00030   m_sec1id.push_back(2);
00031   m_sec2id.push_back(3);
00032   m_sec1id.push_back(4);
00033   m_sec2id.push_back(5);
00034   m_sec1id.push_back(6);
00035   m_sec2id.push_back(7);
00036   m_sec1id.push_back(8);
00037   m_sec2id.push_back(9);
00038   m_sec1id.push_back(10);
00039   m_sec2id.push_back(11);
00040 
00041   m_wheelmap = new std::bitset<6>[12];
00042     
00043 }
00044 
00045 void RPCWheel::setProperties( int wid ) {
00046   
00047   m_id = wid;
00048   
00049   int bisector[2];
00050   
00051   for( int k=0; k < m_maxrbc; ++k )
00052   {
00053     bisector[0]= m_sec1id[k];
00054     bisector[1]= m_sec2id[k];
00055     m_RBCE.push_back( new RBCEmulator( ) ); 
00056     m_RBCE[k]->setid( wid, bisector );
00057   }
00058 
00059   for( int k=0; k < m_maxsectors; ++k)
00060     m_wheelmap[k].reset();
00061   
00062 }
00063 
00064 
00065 void RPCWheel::setProperties( int wid, const char * logic_type) {
00066   
00067   m_id = wid;
00068   
00069   int bisector[2];
00070   
00071   for( int k=0; k < m_maxrbc; ++k )
00072   {
00073     bisector[0]= m_sec1id[k];
00074     bisector[1]= m_sec2id[k];
00075     m_RBCE.push_back( new RBCEmulator( logic_type ) ); 
00076     m_RBCE[k]->setid( wid, bisector );
00077   }
00078 
00079   for( int k=0; k < m_maxsectors; ++k)
00080     m_wheelmap[k].reset();
00081   
00082 }
00083 
00084 void RPCWheel::setProperties( int wid, const char * f_name, const char * logic_type) {
00085   
00086   m_id = wid; 
00087   
00088   int bisector[2];
00089   
00090   for( int k=0; k < m_maxrbc; ++k )
00091   {
00092     bisector[0]= (k*2)+1;
00093     bisector[1]= (k*2)+2;
00094     m_RBCE.push_back( new RBCEmulator( f_name, logic_type ) ); 
00095     m_RBCE[k]->setid( wid, bisector );
00096   }
00097   
00098   for( int k=0; k < m_maxsectors; ++k)
00099     m_wheelmap[k].reset();
00100   
00101 }
00102 
00103 //=============================================================================
00104 // Destructor
00105 //=============================================================================
00106 RPCWheel::~RPCWheel() {
00107   
00108   //destroy all rbc objects associated
00109   std::vector<RBCEmulator*>::iterator itr;
00110   for( itr = m_RBCE.begin(); itr != m_RBCE.end(); ++itr)
00111     if ( (*itr) ) delete (*itr);
00112   
00113   m_RBCE.clear();
00114   m_sec1id.clear();
00115   m_sec2id.clear();
00116 
00117   if ( m_wheelmap ) delete[] m_wheelmap;
00118     
00119 } 
00120 
00121 //=============================================================================
00122 void RPCWheel::setSpecifications( const RBCBoardSpecs * rbcspecs )
00123 {
00124   
00125   for( int k=0; k < m_maxrbc; ++k )
00126     m_RBCE[k]->setSpecifications( rbcspecs ); 
00127   
00128 }
00129 
00130 bool RPCWheel::initialise()
00131 {
00132 
00133   bool status(false);
00134   for( int k=0; k < m_maxrbc; ++k )
00135     status = m_RBCE[k]->initialise();
00136   return status;
00137   
00138 }
00139 
00140 void RPCWheel::emulate() 
00141 {
00142   //This is a test emulation
00143   for( int k=0; k < m_maxrbc; ++k )
00144   {
00145     m_RBCE[k]->emulate();
00146   }
00147   
00148 }
00149 
00150 bool RPCWheel::process( int bx, const std::map<int,RBCInput*> & data )
00151 {
00152   
00153   int bxsign(1);
00154   bool status(false);
00155   
00156   std::map<int,RBCInput*>::const_iterator itr;
00157   
00158   if ( bx != 0 ) bxsign = ( bx / abs(bx) );
00159   else bxsign = 1;
00160   
00161   for(int k=0; k < m_maxrbc; ++k) {
00162     
00163     m_RBCE[k]->reset();
00164     
00165     int key = bxsign*( 1000000 * abs(bx)
00166                        + m_RBCE[k]->m_rbcinfo->wheelIdx()*10000 
00167                        + m_RBCE[k]->m_rbcinfo->sector(0)*100
00168                        + m_RBCE[k]->m_rbcinfo->sector(1) );
00169     
00170     itr = data.find( key );
00171     
00172     if ( itr != data.end() )  {
00173       
00174       if ( ! (*itr).second->hasData )  { 
00175         status |= false;
00176         continue;
00177       } else {
00178         if( m_debug ) std::cout << "RPCWheel::process> found data at: " 
00179                                 <<  key << '\t' 
00180                                 << ( itr->second ) << std::endl;
00181         m_RBCE[k]->emulate( ( itr->second ) );
00182         status |= true;
00183       }
00184       
00185     } else {
00186       //if( m_debug ) std::cout << "RPCWheel::process> position not found: " <<  key << std::endl;
00187       status |= false;
00188     }
00189     
00190   }
00191   
00192   return status;
00193   
00194 }
00195 
00196 bool RPCWheel::process( int bx, const std::map<int,TTUInput*> & data )
00197 {
00198   
00199   int bxsign(1);
00200   bool status(false);
00201   
00202   std::map<int,TTUInput*>::const_iterator itr;
00203   
00204   if ( bx != 0 ) bxsign = ( bx / abs(bx) );
00205   else bxsign = 1;
00206   
00207   int key = bxsign*( 1000000 * abs(bx) + (m_id+2)*10000 );
00208   
00209   itr = data.find( key );
00210   
00211   if ( itr != data.end() )  {
00212     if( m_debug ) std::cout << "RPCWheel::process> found data at: " <<  key << '\t' 
00213                             << ( itr->second ) << std::endl;
00214 
00215     if ( ! (*itr).second->m_hasHits ) return false;
00216     
00217     for( int k=0; k < m_maxsectors; ++k ) {
00218       m_wheelmap[k]     = (*itr).second->input_sec[k];
00219       status = true;
00220     }
00221 
00222   } else {
00223     //if( m_debug ) std::cout << "RPCWheel::process> position not found: " <<  key << std::endl;
00224     status = false;
00225   }
00226   
00227   return status;
00228   
00229 }
00230 
00231 
00232 //.............................................................................
00233 
00234 void RPCWheel::createWheelMap()
00235 {
00236   
00237   m_rbcDecision.reset();
00238   
00239   std::bitset<6> layersignal;
00240   
00241   layersignal       = * m_RBCE[0]->getlayersignal( 0 );
00242   m_wheelmap[11]     = layersignal;
00243   
00244   m_rbcDecision.set( 11 , m_RBCE[0]->getdecision( 0 ) );
00245   
00246   for( int k=0; k < (m_maxrbc-1); ++k )
00247   {
00248     layersignal             = * m_RBCE[k+1]->getlayersignal( 0 );
00249     m_wheelmap[(k*2)+1]     = layersignal;
00250     layersignal             = * m_RBCE[k+1]->getlayersignal( 1 );
00251     m_wheelmap[(k*2)+2]     = layersignal;
00252     
00253     m_rbcDecision.set( (k*2)+1  , m_RBCE[k+1]->getdecision( 0 ) );
00254     m_rbcDecision.set( (k*2)+2  , m_RBCE[k+1]->getdecision( 1 ) );
00255     
00256   }
00257   
00258   layersignal       = * m_RBCE[0]->getlayersignal( 1 );
00259   m_wheelmap[0]     = layersignal;
00260   
00261   m_rbcDecision.set( 0 , m_RBCE[0]->getdecision( 1 ) );
00262   
00263   if( m_debug ) std::cout << "RPCWheel::createWheelMap done" << std::endl;
00264   
00265 }
00266 
00267 void RPCWheel::retrieveWheelMap( TTUInput & output ) 
00268 {
00269   
00270   if( m_debug ) std::cout << "RPCWheel::retrieveWheelMap starts" << std::endl;
00271   output.reset();
00272   
00273   for(int i=0; i < m_maxsectors; ++i ) {
00274     for( int j=0; j < m_maxlayers; ++j ) 
00275     {
00276       output.input_sec[i].set(j, m_wheelmap[i][j]);
00277     }
00278   }
00279   
00280   output.m_wheelId = m_id;
00281   
00282   output.m_rbcDecision = m_rbcDecision;
00283     
00284   if( m_debug ) print_wheel( output );
00285   if( m_debug ) std::cout << "RPCWheel::retrieveWheelMap done" << std::endl;
00286   
00287 }
00288 
00289 //=============================================================================
00290 
00291 
00292 void RPCWheel::printinfo() 
00293 {
00294   
00295   std::cout << "Wheel -> " << m_id << '\n';
00296   for( int k=0; k < m_maxrbc; ++k )
00297     m_RBCE[k]->printinfo();
00298   
00299 }
00300 
00301 void RPCWheel::print_wheel(const TTUInput & wmap )
00302 {
00303 
00304   std::cout << "RPCWheel::print_wheel> " << wmap.m_wheelId << '\t' << wmap.m_bx << std::endl;
00305   
00306   for( int i=0; i < m_maxsectors; ++i) std::cout << '\t' << (i+1);
00307   std::cout << std::endl;
00308   
00309   for( int k=0; k < m_maxlayers; ++k )
00310   {
00311     std::cout << (k+1) << '\t';
00312     for( int j=0; j < m_maxsectors; ++j)
00313       std::cout << wmap.input_sec[j][k] << '\t';
00314     std::cout << std::endl;
00315   }
00316   
00317 }
00318 
00319 //=============================================================================