CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuDTExtrapolationUnit.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTExtrapolationUnit
4 //
5 // Description: Extrapolation Unit
6 //
7 //
8 // $Date: 2008/11/28 10:30:51 $
9 // $Revision: 1.5 $
10 //
11 // Author :
12 // N. Neumeister CERN EP
13 //
14 //--------------------------------------------------
15 
16 //-----------------------
17 // This Class's Header --
18 //-----------------------
19 
21 
22 //---------------
23 // C++ Headers --
24 //---------------
25 
26 #include <iostream>
27 #include <bitset>
28 #include <cassert>
29 
30 //-------------------------------
31 // Collaborating Class Headers --
32 //-------------------------------
33 
45 
46 using namespace std;
47 
48 // --------------------------------
49 // class L1MuDTExtrapolationUnit
50 //---------------------------------
51 
52 //----------------
53 // Constructors --
54 //----------------
55 
57  m_sp(sp), m_SEUs() {
58 
59  for ( int ext_idx = 0; ext_idx < MAX_EXT; ext_idx++ ) {
60 
61  Extrapolation ext = static_cast<Extrapolation>(ext_idx);
62 
63  if ( ext == EX12 || ext == EX13 || ext == EX14 ||
64  ext == EX21 || ext == EX23 || ext == EX24 || ext == EX34 ) {
65 
66  unsigned int maxaddr = 4;
67 
68  if ( ext == EX12 || ext == EX13 || ext == EX14 ) maxaddr = 2;
69 
70  for ( unsigned int startAddress = 0; startAddress < maxaddr; startAddress++ ) {
71  SEUId id = make_pair(ext, startAddress);
72  m_SEUs[id] = new L1MuDTSEU(sp,ext,startAddress);
73  if ( L1MuDTTFConfig::Debug(6) ) cout << " creating SEU " << ext << " " << startAddress << endl;
74  }
75  }
76  }
77 
78 }
79 
80 
81 //--------------
82 // Destructor --
83 //--------------
84 
86 
87  for ( SEUmap::iterator iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
88  delete (*iter).second;
89  (*iter).second = 0;
90  }
91  m_SEUs.clear();
92 
93 }
94 
95 
96 //--------------
97 // Operations --
98 //--------------
99 
100 //
101 // run Extrapolation Unit
102 //
104 
105  c.get< L1MuDTTFParametersRcd >().get( pars );
106 
107  SEUmap::const_iterator iter;
108  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
109 
110  pair<int,int> ext_pair = which_ext(((*iter).second)->ext());
111  int start = ext_pair.first;
112 
113  const L1MuDTTrackSegPhi* ts = 0;
114 
115  //get start track segment
116  ts = m_sp.data()->getTSphi(start, ((*iter).second)->tsId() );
117 
118  if ( ts != 0 && !ts->empty() ) {
119  ((*iter).second)->load(ts);
120  ((*iter).second)->run(c);
121  }
122 
123  }
124 
125  //
126  // use EX21 to cross-check EX12
127  //
128  bool run_21 = pars->get_soc_run_21(m_sp.id().wheel(), m_sp.id().sector());
129  if ( L1MuDTTFConfig::getUseEX21() || run_21 ) {
130 
131  // search for EX12 + EX21 single extrapolation units
132  for ( unsigned int startAdr = 0; startAdr < 2; startAdr++ ) {
133 
134  bitset<12> extab12 = this->getEXTable( EX12, startAdr );
135  bitset<12> extab21 = this->getEXTable( EX21, startAdr );
136 
137  for ( int eux = 0; eux < 12; eux++ ) {
138  if ( extab12.test(eux) && !extab21.test(eux) ) {
139  reset(EX12,startAdr,eux);
140  if ( L1MuDTTFConfig::Debug(6) ) {
141  SEUId seuid = make_pair(EX12, startAdr);
142  L1MuDTSEU* SEU12 = m_SEUs[seuid];
143  cout << " EX12 - EX21 mismatch : "
144  << " EX12 : " << extab12 << " , "
145  << " EX21 : " << extab21 << endl
146  << " Cancel: " << SEU12->ext()
147  << " start addr = " << SEU12->tsId()
148  << " target addr = " << eux << endl;
149  }
150  }
151  }
152 
153  }
154  }
155 
156 }
157 
158 
159 //
160 // reset Extrapolation Unit
161 //
163 
164  SEUmap::const_iterator iter;
165  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
166  ((*iter).second)->reset();
167  }
168 
169 }
170 
171 
172 //
173 // reset a single extrapolation
174 //
175 void L1MuDTExtrapolationUnit::reset(Extrapolation ext, unsigned int startAdr, unsigned int relAdr) {
176 
177  // assert( startAdr >= 0 && startAdr <= 3 );
178  // assert( relAdr >= 0 && relAdr <= 12 );
179 
180  SEUId seuid = make_pair(ext, startAdr);
181  SEUmap::const_iterator iter = m_SEUs.find(seuid);
182  if ( iter != m_SEUs.end() ) ((*iter).second)->reset(relAdr);
183 
184 }
185 
186 
187 //
188 // get extrapolation address from ERS
189 //
190 unsigned short int L1MuDTExtrapolationUnit::getAddress(Extrapolation ext, unsigned int startAdr, int id) const {
191 
192  // get extrapolation address from ERS
193  // startAdr = 0, 1 : own wheel
194  // startAdr = 2, 3 : next wheel neighbour
195 
196  // assert( startAdr >= 0 && startAdr <= 3 );
197  // assert( id == 0 || id == 1 );
198 
199  unsigned short int address = 15;
200 
201  SEUId seuid = make_pair(ext, startAdr);
202  SEUmap::const_iterator iter = m_SEUs.find(seuid);
203  if ( iter != m_SEUs.end() ) address = ((*iter).second)->ers()->address(id);
204 
205  return address;
206 
207 }
208 
209 
210 //
211 // get extrapolation quality from ERS
212 //
213 unsigned short int L1MuDTExtrapolationUnit::getQuality(Extrapolation ext, unsigned int startAdr, int id) const {
214 
215  // get extrapolation quality from ERS
216  // startAdr = 0, 1 : own wheel
217  // startAdr = 2, 3 : next wheel neighbour
218 
219  // assert( startAdr >= 0 && startAdr <= 3 );
220  // assert( id == 0 || id == 1 );
221 
222  unsigned short int quality = 0;
223 
224  SEUId seuid = make_pair(ext, startAdr);
225  SEUmap::const_iterator iter = m_SEUs.find(seuid);
226  if ( iter != m_SEUs.end() ) quality = ((*iter).second)->ers()->quality(id);
227 
228  return quality;
229 
230 }
231 
232 
233 //
234 // get Extrapolator table for a given SEU
235 //
236 const bitset<12>& L1MuDTExtrapolationUnit::getEXTable(Extrapolation ext, unsigned int startAdr) const {
237 
238  // startAdr = 0, 1 : own wheel
239  // startAdr = 2, 3 : next wheel neighbour
240 
241  // assert( startAdr >= 0 && startAdr <= 3 );
242 
243  SEUId seuid = make_pair(ext, startAdr);
244  return m_SEUs[seuid]->exTable();
245 
246 }
247 
248 
249 //
250 // get Quality Sorter table for a given SEU
251 //
252 const bitset<12>& L1MuDTExtrapolationUnit::getQSTable(Extrapolation ext, unsigned int startAdr) const {
253 
254  // startAdr = 0, 1 : own wheel
255  // startAdr = 2, 3 : next wheel neighbour
256 
257  // assert( startAdr >= 0 && startAdr <= 3 );
258 
259  SEUId seuid = make_pair(ext, startAdr);
260  return m_SEUs[seuid]->qsTable();
261 
262 }
263 
264 
265 //
266 // get number of successful extrapolations
267 //
269 
270  int number = 0;
271  SEUmap::const_iterator iter;
272  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
273  number += ((*iter).second)->numberOfExt();
274  }
275 
276  return number;
277 
278 }
279 
280 
281 //
282 // print all successful extrapolations
283 //
285 
286  SEUmap::const_iterator iter_seu;
287 
288  if ( level == 0 ) {
289  for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
290  vector<L1MuDTEUX*> vec_eux = ((*iter_seu).second)->eux();
291  vector<L1MuDTEUX*>::const_iterator iter_eux;
292  for ( iter_eux = vec_eux.begin();
293  iter_eux != vec_eux.end(); iter_eux++ ) {
294  if ( (*iter_eux)->result() ) {
295  cout << ((*iter_seu).second)->ext() << " "
296  << ((*iter_seu).second)->tsId() << " "
297  << (*iter_eux)->id() << endl;
298  cout << "start : " << *(*iter_eux)->ts().first << endl;
299  cout << "target : " << *(*iter_eux)->ts().second << endl;
300  cout << "result : " << "quality = " << (*iter_eux)->quality() << '\t'
301  << "address = " << (*iter_eux)->address() << endl;
302  }
303  }
304  }
305  }
306 
307  //
308  // print all results from Extrapolator and Quality Sorter
309  //
310  if ( level == 1 ) {
311  cout << "Results from Extrapolator and Quality Sorter of " << m_sp.id()
312  << " : \n" << endl;
313 
314  cout << " EXT QSU " << endl;
315  cout << " S E U 11 11 " << endl;
316  cout << " 109876543210 109876543210 " << endl;
317  cout << "-------------------------------------" << endl;
318  for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
319 
320  cout << ((*iter_seu).second)->ext() << "_ "
321  << ((*iter_seu).second)->tsId() << ": "
322  << ((*iter_seu).second)->exTable() << " "
323  << ((*iter_seu).second)->qsTable() << endl;
324 
325  }
326 
327  cout << endl;
328  }
329 
330 }
331 
332 
333 // static
334 
335 //
336 // get station of start and target track segment for a given extrapolation
337 //
339 
340  int source = 0;
341  int target = 0;
342 
343  // assert( ext >= 0 && ext < MAX_EXT );
344 
345  switch ( ext ) {
346  case EX12 : { source = 1; target = 2; break; }
347  case EX13 : { source = 1; target = 3; break; }
348  case EX14 : { source = 1; target = 4; break; }
349  case EX21 : { source = 1; target = 2; break; }
350  case EX23 : { source = 2; target = 3; break; }
351  case EX24 : { source = 2; target = 4; break; }
352  case EX34 : { source = 3; target = 4; break; }
353  case EX15 : { source = 1; target = 3; break; }
354  case EX25 : { source = 2; target = 3; break; }
355  default : { source = 1; target = 2; break; }
356  }
357 
358  return pair<int,int>(source,target);
359 
360 }
char * address
Definition: mlp_lapack.h:14
Extrapolation ext() const
return extrapolation type
Definition: L1MuDTSEU.h:82
const std::bitset< 12 > & getEXTable(Extrapolation ext, unsigned int startAdr) const
get Extrapolator table for a given SEU
std::pair< Extrapolation, unsigned int > SEUId
virtual void reset()
reset Extrapolation Unit
unsigned short int getQuality(Extrapolation ext, unsigned int startAdr, int id) const
get extrapolation quality from a given ERS
void print(int level=0) const
print all successful extrapolations
int sector() const
return sector number
const L1MuDTDataBuffer * data() const
return pointer to Data Buffer
const std::bitset< 12 > & getQSTable(Extrapolation ext, unsigned int startAdr) const
get Quality Sorter table for a given SEU
const L1MuDTSectorProcessor & m_sp
L1MuDTExtrapolationUnit(const L1MuDTSectorProcessor &)
constructor
virtual void run()
run processor logic
const int MAX_EXT
def load
Definition: svgfig.py:546
unsigned short int getAddress(Extrapolation ext, unsigned int startAdr, int id) const
get extrapolation address from a given ERS
bool empty() const
is it an empty phi track segment?
static bool Debug()
const L1MuDTSecProcId & id() const
return Sector Processor identifier
Extrapolation
static std::pair< int, int > which_ext(Extrapolation ext)
return station of start and target track segment for a given extrapolation
const TSPhivector & getTSphi() const
get all track segments from the buffer
static bool getUseEX21()
const T & get() const
Definition: EventSetup.h:55
edm::ESHandle< L1MuDTTFParameters > pars
int numberOfExt() const
return number of successful extrapolations
int wheel() const
return wheel number
tuple cout
Definition: gather_cfg.py:121
virtual ~L1MuDTExtrapolationUnit()
destructor
tuple level
Definition: testEve_cfg.py:34
unsigned int tsId() const
return start track segment identifier (relative address)
Definition: L1MuDTSEU.h:85