CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/L1Trigger/DTTrackFinder/src/L1MuDTAddressArray.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: L1MuDTAddressArray
00004 //
00005 //   Description: Array of relative Addresses
00006 //
00007 //
00008 //   $Date: 2008/10/13 07:44:43 $
00009 //   $Revision: 1.3 $
00010 //
00011 //   Author :
00012 //   N. Neumeister            CERN EP
00013 //
00014 //--------------------------------------------------
00015 
00016 //-----------------------
00017 // This Class's Header --
00018 //-----------------------
00019 
00020 #include "L1Trigger/DTTrackFinder/src/L1MuDTAddressArray.h"
00021 
00022 //---------------
00023 // C++ Headers --
00024 //---------------
00025 
00026 #include <iostream>
00027 #include <iomanip>
00028 #include <vector>
00029 #include <cassert>
00030 
00031 //-------------------------------
00032 // Collaborating Class Headers --
00033 //-------------------------------
00034 
00035 using namespace std;
00036 
00037 // --------------------------------
00038 //       class L1MuDTAddressArray
00039 //---------------------------------
00040 
00041 //----------------
00042 // Constructors --
00043 //----------------
00044 
00045 L1MuDTAddressArray::L1MuDTAddressArray() {
00046 
00047   reset();
00048 
00049 }
00050 
00051 
00052 L1MuDTAddressArray::L1MuDTAddressArray(const L1MuDTAddressArray& addarray) {
00053   
00054   for ( int stat = 1; stat <= 4; stat++ ) {
00055     m_station[stat-1] = addarray.m_station[stat-1];
00056   }
00057 
00058 }
00059 
00060 
00061 //--------------
00062 // Destructor --
00063 //--------------
00064 
00065 L1MuDTAddressArray::~L1MuDTAddressArray() {}
00066 
00067 
00068 //--------------
00069 // Operations --
00070 //--------------
00071 
00072 //
00073 // assignment operator
00074 //
00075 L1MuDTAddressArray& L1MuDTAddressArray::operator=(const L1MuDTAddressArray& addarray) {
00076 
00077   if ( this != &addarray ) {
00078     for ( int stat = 1; stat <= 4; stat++ ) {
00079       m_station[stat-1] = addarray.m_station[stat-1];
00080     }
00081   }
00082   return *this;
00083 
00084 }
00085 
00086 
00087 //
00088 //
00089 //
00090 bool L1MuDTAddressArray::operator==(const L1MuDTAddressArray& addarray) const {
00091 
00092   for ( int stat = 1; stat <= 4; stat++ ) {
00093     if ( m_station[stat-1] != addarray.m_station[stat-1] ) return false;
00094   }
00095 
00096   return true;
00097 
00098 }
00099 
00100 
00101 //
00102 //
00103 //
00104 bool L1MuDTAddressArray::operator!=(const L1MuDTAddressArray& addarray) const {
00105 
00106   for ( int stat = 1; stat <= 4; stat++ ) {
00107     if ( m_station[stat-1] != addarray.m_station[stat-1] ) return true;
00108   }
00109 
00110   return false;
00111 
00112 }
00113 
00114 
00115 //
00116 // reset AddressArray
00117 //
00118 void L1MuDTAddressArray::reset() {
00119 
00120   for ( int stat = 1; stat <= 4; stat++ ) {
00121     m_station[stat-1] = 15; 
00122   }
00123 
00124 }
00125 
00126 
00127 //
00128 // set Address of a given station
00129 //
00130 void L1MuDTAddressArray::setStation(int stat, int adr) {
00131 
00132   //  assert( stat >  0 && stat <= 4 );
00133   //  assert( adr  >= 0 && adr  <= 15       );  
00134   m_station[stat-1] = adr;
00135 
00136 }
00137 
00138 
00139 //
00140 // set Addresses of all four stations
00141 //
00142 void L1MuDTAddressArray::setStations(int adr1, int adr2, int adr3, int adr4) {
00143 
00144   setStation(1,adr1);
00145   setStation(2,adr2);
00146   setStation(3,adr3);
00147   setStation(4,adr4);
00148 
00149 }
00150 
00151 
00152 //
00153 // get track address code (for eta track finder)
00154 //
00155 int L1MuDTAddressArray::trackAddressCode() const {
00156 
00157   int code = -1;
00158   
00159   int s1 = m_station[0];
00160   s1 = ( s1 == 15 ) ? 0 : ((s1/2)%2)+1;
00161   int s2 = m_station[1];
00162   s2 = ( s2 == 15 ) ? 0 : ((s2/2)%2)+1;
00163   int s3 = m_station[2];
00164   s3 = ( s3 == 15 ) ? 0 : ((s3/2)%2)+1;
00165   int s4 = m_station[3];
00166   s4 = ( s4 == 15 ) ? 0 : ((s4/2)%2)+1;
00167 
00168   //  0 ... empty track segment
00169   //  1 ... same wheel 
00170   //  2 ... next wheel 
00171   
00172   if ( s1 == 0 && s2 == 0 && s3 == 0 && s4 == 0 ) code =  0;
00173   if ( s1 == 0 && s2 == 0 && s3 == 2 && s4 == 1 ) code =  0;
00174   if ( s1 == 0 && s2 == 0 && s3 == 2 && s4 == 2 ) code =  0;
00175   if ( s1 == 0 && s2 == 2 && s3 == 0 && s4 == 1 ) code =  0;
00176   if ( s1 == 0 && s2 == 2 && s3 == 0 && s4 == 2 ) code =  0;
00177   if ( s1 == 0 && s2 == 2 && s3 == 1 && s4 == 0 ) code =  0;
00178   if ( s1 == 0 && s2 == 2 && s3 == 2 && s4 == 0 ) code =  0;   
00179   if ( s1 == 0 && s2 == 1 && s3 == 2 && s4 == 1 ) code =  0; 
00180   if ( s1 == 0 && s2 == 2 && s3 == 1 && s4 == 1 ) code =  0;
00181   if ( s1 == 0 && s2 == 2 && s3 == 1 && s4 == 2 ) code =  0;
00182   if ( s1 == 0 && s2 == 2 && s3 == 2 && s4 == 1 ) code =  0;
00183   if ( s1 == 0 && s2 == 2 && s3 == 2 && s4 == 2 ) code =  0;  
00184   if ( s1 == 1 && s2 == 0 && s3 == 2 && s4 == 1 ) code =  0; 
00185   if ( s1 == 1 && s2 == 2 && s3 == 0 && s4 == 1 ) code =  0;
00186   if ( s1 == 1 && s2 == 2 && s3 == 1 && s4 == 0 ) code =  0; 
00187   if ( s1 == 1 && s2 == 1 && s3 == 2 && s4 == 1 ) code =  0; 
00188   if ( s1 == 1 && s2 == 2 && s3 == 1 && s4 == 1 ) code =  0;
00189   if ( s1 == 1 && s2 == 2 && s3 == 1 && s4 == 2 ) code =  0;
00190   if ( s1 == 1 && s2 == 2 && s3 == 2 && s4 == 1 ) code =  0;    
00191   if ( s1 == 0 && s2 == 0 && s3 == 1 && s4 == 1 ) code =  1;
00192   if ( s1 == 0 && s2 == 0 && s3 == 1 && s4 == 2 ) code =  2;
00193   if ( s1 == 0 && s2 == 1 && s3 == 0 && s4 == 1 ) code =  3;
00194   if ( s1 == 0 && s2 == 1 && s3 == 0 && s4 == 2 ) code =  4;
00195   if ( s1 == 0 && s2 == 1 && s3 == 1 && s4 == 0 ) code =  5;
00196   if ( s1 == 0 && s2 == 1 && s3 == 1 && s4 == 1 ) code =  6;
00197   if ( s1 == 0 && s2 == 1 && s3 == 1 && s4 == 2 ) code =  7;
00198   if ( s1 == 0 && s2 == 1 && s3 == 2 && s4 == 0 ) code =  8;
00199   if ( s1 == 0 && s2 == 1 && s3 == 2 && s4 == 2 ) code =  8;
00200   if ( s1 == 1 && s2 == 0 && s3 == 0 && s4 == 1 ) code =  9;
00201   if ( s1 == 1 && s2 == 0 && s3 == 0 && s4 == 2 ) code = 10;
00202   if ( s1 == 1 && s2 == 0 && s3 == 1 && s4 == 0 ) code = 11;
00203   if ( s1 == 1 && s2 == 0 && s3 == 1 && s4 == 1 ) code = 12;
00204   if ( s1 == 1 && s2 == 0 && s3 == 1 && s4 == 2 ) code = 13;
00205   if ( s1 == 1 && s2 == 0 && s3 == 2 && s4 == 0 ) code = 14;
00206   if ( s1 == 1 && s2 == 0 && s3 == 2 && s4 == 2 ) code = 14;
00207   if ( s1 == 1 && s2 == 1 && s3 == 0 && s4 == 0 ) code = 15;
00208   if ( s1 == 1 && s2 == 1 && s3 == 0 && s4 == 1 ) code = 16;
00209   if ( s1 == 1 && s2 == 1 && s3 == 0 && s4 == 2 ) code = 17;
00210   if ( s1 == 1 && s2 == 1 && s3 == 1 && s4 == 0 ) code = 18;
00211   if ( s1 == 1 && s2 == 1 && s3 == 1 && s4 == 1 ) code = 19;
00212   if ( s1 == 1 && s2 == 1 && s3 == 1 && s4 == 2 ) code = 20;
00213   if ( s1 == 1 && s2 == 1 && s3 == 2 && s4 == 0 ) code = 21;
00214   if ( s1 == 1 && s2 == 1 && s3 == 2 && s4 == 2 ) code = 21;
00215   if ( s1 == 1 && s2 == 2 && s3 == 0 && s4 == 0 ) code = 22;
00216   if ( s1 == 1 && s2 == 2 && s3 == 0 && s4 == 2 ) code = 22;
00217   if ( s1 == 1 && s2 == 2 && s3 == 2 && s4 == 0 ) code = 22;
00218   if ( s1 == 1 && s2 == 2 && s3 == 2 && s4 == 2 ) code = 22;
00219 
00220   return code;
00221 
00222 }
00223 
00224 
00225 //
00226 // get converted Addresses
00227 //
00228 L1MuDTAddressArray L1MuDTAddressArray::converted() const {
00229 
00230   unsigned short int adr1 = L1MuDTAddressArray::convert(m_station[0]); 
00231   unsigned short int adr2 = L1MuDTAddressArray::convert(m_station[1]);
00232   unsigned short int adr3 = L1MuDTAddressArray::convert(m_station[2]);
00233   unsigned short int adr4 = L1MuDTAddressArray::convert(m_station[3]);
00234 
00235   L1MuDTAddressArray newaddressarray; 
00236   newaddressarray.setStations(adr1,adr2,adr3,adr4);
00237 
00238   return newaddressarray;
00239 
00240 }
00241 
00242 
00243 //
00244 //
00245 //
00246 ostream& operator<<(ostream& s, const L1MuDTAddressArray& adrarr ) {
00247 
00248   s.setf(ios::right,ios::adjustfield);
00249   for ( int stat = 1; stat <= 4; stat++ ) { 
00250     s << "stat " << stat << ": " << setw(2) << adrarr.station(stat) << "  ";
00251   }
00252 
00253   return s;
00254 
00255 }
00256 
00257 
00258 //
00259 // convert address to corresponding VHDL address
00260 //
00261 unsigned short int L1MuDTAddressArray::convert(unsigned short int adr) {
00262 
00263   unsigned short int newaddress = 15;
00264 
00265   switch ( adr ) {
00266     case  0 : { newaddress =  8; break; }
00267     case  1 : { newaddress =  9; break; }
00268     case  2 : { newaddress =  0; break; }
00269     case  3 : { newaddress =  1; break; }
00270     case  4 : { newaddress = 10; break; }
00271     case  5 : { newaddress = 11; break; }
00272     case  6 : { newaddress =  2; break; }
00273     case  7 : { newaddress =  3; break; }
00274     case  8 : { newaddress = 12; break; }
00275     case  9 : { newaddress = 13; break; }
00276     case 10 : { newaddress =  4; break; }
00277     case 11 : { newaddress =  5; break; }
00278     case 15 : { newaddress = 15; break; }
00279     default:  { newaddress = 15; break; }
00280 
00281   }
00282 
00283    return newaddress;
00284 
00285 }
00286 
00287 
00288 // 
00289 // is it a same wheel address?
00290 //
00291 bool L1MuDTAddressArray::sameWheel(unsigned short int adr) {
00292 
00293   //  if ( adr > 15 ) cerr << "L1MuDTAddressArray : Error wrong address " << adr << endl;
00294   return ( (adr/2)%2 == 0 );
00295 
00296 }
00297 
00298     
00299 //
00300 // is it a next wheel address?
00301 //
00302 bool L1MuDTAddressArray::nextWheel(unsigned short int adr) {
00303 
00304   //  if ( adr > 15 ) cerr << "L1MuDTAddressArray : Error wrong address " << adr << endl;
00305   return ( (adr/2)%2 == 1 );
00306 
00307 }