CMS 3D CMS Logo

DEutils.h
Go to the documentation of this file.
1 #ifndef DEUTILS_H
2 #define DEUTILS_H
3 
4 /*\class template DEutils
5  *\description data|emulation auxiliary template
6  collection operations struct
7  *\author Nuno Leonardo (CERN)
8  *\date 07.04
9  */
10 
11 #include <iomanip>
12 
15 
16 template <typename T>
17 struct DEutils {
18 
19  typedef typename T::size_type col_sz;
20  typedef typename T::const_iterator col_cit;
21  typedef typename T::iterator col_it;
23  typedef typename de_trait::cand_type cand_type;
24  typedef typename de_trait::coll_type coll_type;
25 
26  public:
27 
28  DEutils() {
29  if(de_type()>51)
30  edm::LogError("L1ComparatorDeutilsCollType") //throw cms::Exception("ERROR")
31  << "DEutils::DEutils() :: "
32  << "specialization is still missing for collection of type:"
33  << de_type() << std::endl;
34  }
36 
37  inline int de_type() const {return de_trait::de_type();}
38  bool de_equal (const cand_type&, const cand_type&);
39  bool de_equal_loc (const cand_type&, const cand_type&);
40  bool de_nequal (const cand_type&, const cand_type&);
41  bool de_nequal_loc(const cand_type&, const cand_type&);
42  col_it de_find ( col_it, col_it, const cand_type&);
43  //col_it de_find_loc ( col_it, col_it, const cand_type&);
44 
45  std::string print(col_cit) const;
46  bool is_empty(col_cit) const;
47  std::string GetName(int i = 0) const;
48 
49  L1DataEmulDigi DEDigi(col_cit itd, col_cit itm, int ctype);
50 
51 };
52 
53 
55 
56 template <typename T>
59  return L1DataEmulDigi();
60 }
61 
62 template<> inline L1DataEmulDigi
64  int cid = de_type();
65  int errt = aflag;
66  //fill data if flagged, otherwise emulator
67  double x1 = (aflag!=4) ? itd->id().iphi() : itm->id().iphi();
68  double x2 = (aflag!=4) ? itd->id().ieta() : itm->id().ieta();
69  L1DataEmulDigi digi(dedefs::ETP,cid, x1,x2,0, errt);
70  unsigned int dwS = (aflag==4)?0:itd->sample(itd->sampleOfInterest()).raw();
71  unsigned int ewS = (aflag==3)?0:itm->sample(itm->sampleOfInterest()).raw();
72  //dw1 &= 0x01ff; ew1 &= 0x01ff; //9-bit: fg(8),energy(7:0)
73  unsigned int mask = 0x0eff; //fg bit temporary(!) mask
74  dwS &= mask; ewS &= mask;
75  unsigned int dwI = (aflag==4)?0:itd->id().rawId();
76  unsigned int ewI = (aflag==3)?0:itm->id().rawId();
77  //dw2 &= 0xfe00ffff; ew2 &= 0xfe00ffff; //32-bit, reset unused (24:16)
78  //merge id and sample words
79  unsigned int dw = (dwI & 0xfe00ffff ) | ( (dwS & 0x000001ff)<<16 );
80  unsigned int ew = (ewI & 0xfe00ffff ) | ( (ewS & 0x000001ff)<<16 );
81  digi.setData(dw,ew);
82  int de = (aflag==4)?0:itd->compressedEt() ;
83  int ee = (aflag==3)?0:itm->compressedEt() ;
84  digi.setRank((float)de,(float)ee);
85  L1MonitorDigi dedata(dedefs::ETP,cid, itd->id().iphi(),itd->id().ieta(),0,
86  itd->compressedEt(),itd->id().rawId());
87  L1MonitorDigi deemul(dedefs::ETP,cid, itm->id().iphi(),itm->id().ieta(),0,
88  itm->compressedEt(),itm->id().rawId());
89  digi.setDEpair(dedata,deemul);
90  return digi;
91 }
92 
93 template<> inline L1DataEmulDigi
95  int cid = de_type();
96  int errt = aflag;
97  double x1 = (aflag!=4) ? itd->id().iphi() : itm->id().iphi();
98  double x2 = (aflag!=4) ? itd->id().ieta() : itm->id().ieta();
99  L1DataEmulDigi digi(dedefs::HTP,cid, x1,x2,0, errt);
100  unsigned int dw = (aflag==4)?0:itd->t0().raw();
101  unsigned int ew = (aflag==3)?0:itm->t0().raw();
102  //16-bit; bits 10:9 not set(?);
103  // bits 15:11 not accessible in emulator (slb/channel ids)
104  unsigned int mask = 0x01ff;
105  dw &= mask; ew &= mask;
106  digi.setData(dw,ew);
107  int de = (aflag==4)?0:itd->SOI_compressedEt();
108  int ee = (aflag==3)?0:itm->SOI_compressedEt();
109  digi.setRank((float)de,(float)ee);
110  return digi;
111 }
112 
113 template<> inline L1DataEmulDigi
115  int cid = de_type();
116  int errt = aflag;
117  double x1, x2, x3(0.);
118  // global index ieta (0-21), iphi (0-17), card (0-6)
119  x1 = (aflag!=4) ? itd->regionId().iphi() : itm->regionId().iphi();
120  x2 = (aflag!=4) ? itd->regionId().ieta() : itm->regionId().ieta();
121  x3 = (aflag!=4) ? itd->regionId().rctCard() : itm->regionId().rctCard();
122  //alternative coordinates: rctCrate(), rctCard(), index()
123  L1DataEmulDigi digi(dedefs::RCT,cid, x1,x2,x3, errt);
124  unsigned int dw = itd->raw();
125  unsigned int ew = itm->raw();
126  dw &= 0x3ff;
127  dw += (((itd->rctCrate())&0x1f)<<10);
128  dw += (((itd->isolated()?1:0)&0x1)<<15);
129  dw += (((itd->index())&0x3)<<16);
130  ew &= 0x3ff;
131  ew += (((itm->rctCrate())&0x1f)<<10);
132  ew += (((itm->isolated()?1:0)&0x1)<<15);
133  ew += (((itm->index())&0x3)<<16);
134  dw = (aflag==4)?0:dw;
135  ew = (aflag==3)?0:ew;
139  digi.setData(dw,ew);
140  int de = (aflag==4)?0:itd->rank();
141  int ee = (aflag==3)?0:itm->rank();
142  digi.setRank((float)de,(float)ee);
143  return digi;
144 }
145 
146 template<> inline L1DataEmulDigi
148  int cid = de_type();
149  int errt = aflag;
150  double x1, x2, x3(0.);
151  x1 = (aflag!=4) ? itd->id().iphi() : itm->id().iphi();
152  x2 = (aflag!=4) ? itd->id().ieta() : itm->id().ieta();
153  x3 = (aflag!=4) ? itd->id().rctCard() : itm->id().rctCard();
154  L1DataEmulDigi digi(dedefs::RCT,cid, x1,x2,x3, errt);
155  unsigned int dw = itd->raw();
156  unsigned int ew = itm->raw();
157  unsigned int mask = 0x3fff;
158  //mask (temporary) mip(12), quiet (13)
159  mask = 0x0fff;
160  dw &= mask;
161  dw += (((itd->id().ieta())&0x1f)<<14);
162  dw += (((itd->id().iphi())&0x1f)<<19);
163  ew &= mask;
164  ew += (((itm->id().ieta())&0x1f)<<14);
165  ew += (((itm->id().iphi())&0x1f)<<19);
166  dw = (aflag==4)?0:dw;
167  ew = (aflag==3)?0:ew;
169  digi.setData(dw,ew);
170  int de = (aflag==4)?0:itd->et();
171  int ee = (aflag==3)?0:itm->et();
172  digi.setRank((float)de,(float)ee);
173  return digi;
174 }
175 
176 template<> inline L1DataEmulDigi
178  int cid = de_type();
179  int errt = aflag;
180  //phi: 0..17; eta: 0..21
181  // bring it to global coordinates
182  double x1 = (aflag!=4) ? itd->regionId().iphi() : itm->regionId().iphi();
183  double x2 = (aflag!=4) ? itd->regionId().ieta() : itm->regionId().ieta();
184  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
185  unsigned int dw = (aflag==4)?0:itd->raw();
186  unsigned int ew = (aflag==3)?0:itm->raw();
187  dw &= 0x7fff; ew &= 0x7fff; //15-bit
188  digi.setData(dw,ew);
189  int de = (aflag==4)?0:itd->rank();
190  int ee = (aflag==3)?0:itm->rank();
191  digi.setRank((float)de,(float)ee);
192  return digi;
193 }
194 
195 template<> inline L1DataEmulDigi
197  int cid = de_type();
198  int errt = aflag;
199  //phi: 0..17; eta: -6..-0,+0..+6; eta sign:1(z-),0(z+)
200  // bring it to global coordinates 0..21 below
201  double x1 = (aflag!=4) ? itd->phiIndex() : itm->phiIndex();
202  unsigned deta(0), eeta(0);
203  if (!itd->isForward()) deta=(itd->etaSign()==1?10-(itd->etaIndex()&0x7):(itd->etaIndex()&0x7)+11);
204  else deta=(itd->etaSign()==1? 3-(itd->etaIndex()&0x7):(itd->etaIndex()&0x7)+18 );
205  if (!itm->isForward()) eeta=(itm->etaSign()==1?10-(itm->etaIndex()&0x7):(itm->etaIndex()&0x7)+11);
206  else eeta=(itm->etaSign()==1? 3-(itm->etaIndex()&0x7):(itm->etaIndex()&0x7)+18 );
207  double x2 = (aflag!=4) ? deta : eeta;
208  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
209  unsigned int dw = (aflag==4)?0:itd->raw();
210  unsigned int ew = (aflag==3)?0:itm->raw();
211  dw &= 0x7fff; ew &= 0x7fff; //15-bit
212  digi.setData(dw,ew);
213  int de = (aflag==4)?0:itd->rank();
214  int ee = (aflag==3)?0:itm->rank();
215  digi.setRank((float)de,(float)ee);
216  return digi;
217 }
218 
219 template<> inline L1DataEmulDigi
221  int cid = de_type();
222  int errt = aflag;
223  double x1 = 0; double x2 = 0; //no 'location' associated with candidates...
224  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
225  unsigned int dw = (aflag==4)?0:itd->raw();
226  unsigned int ew = (aflag==3)?0:itm->raw();
227  dw &= 0x1fff; ew &= 0x1fff; //13-bit
228  digi.setData(dw,ew);
229  int de = (aflag==4)?0:itd->et();
230  int ee = (aflag==3)?0:itm->et();
231  digi.setRank((float)de,(float)ee);
232  return digi;
233 }
234 template<> inline L1DataEmulDigi
236  int cid = de_type();
237  int errt = aflag;
238  double x1 = (aflag!=4) ? itd->phi() : itm->phi();
239  double x2 = 0; //no 'eta' associated with candidates...
240  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
241  unsigned int dw = (aflag==4)?0:itd->raw();
242  unsigned int ew = (aflag==3)?0:itm->raw();
243  dw &= 0x8f1fff; ew &= 0x8f1fff; //22-bit (bits 13,14,15 not set)
244  digi.setData(dw,ew);
245  int de = (aflag==4)?0:itd->et();
246  int ee = (aflag==3)?0:itm->et();
247  digi.setRank((float)de,(float)ee);
248  return digi;
249 }
250 
251 template<> inline L1DataEmulDigi
253  int cid = de_type();
254  int errt = aflag;
255  double x1 = 0; double x2 = 0; //no 'location' associated with candidates...
256  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
257  unsigned int dw = (aflag==4)?0:itd->raw();
258  unsigned int ew = (aflag==3)?0:itm->raw();
259  dw &= 0x1fff; ew &= 0x1fff; //13-bit
260  digi.setData(dw,ew);
261  int de = (aflag==4)?0:itd->et();
262  int ee = (aflag==3)?0:itm->et();
263  digi.setRank((float)de,(float)ee);
264  return digi;
265 }
266 template<> inline L1DataEmulDigi
268  int cid = de_type();
269  int errt = aflag;
270  double x1 = 0; double x2 = 0; //no 'location' associated with candidates...
271  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
272  unsigned int dw = (aflag==4)?0:itd->raw();
273  unsigned int ew = (aflag==3)?0:itm->raw();
274  digi.setData(dw,ew);
275  int de = 0; int ee = 0; //no 'rank' associated with candidates...
276  digi.setRank((float)de,(float)ee);
277  return digi;
278 }
279 template<> inline L1DataEmulDigi
281  int cid = de_type();
282  int errt = aflag;
283  double x1 = 0; double x2 = 0; //no 'location' associated with candidates...
284  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
285  unsigned int dw = (aflag==4)?0:itd->raw();
286  unsigned int ew = (aflag==3)?0:itm->raw();
287  digi.setData(dw,ew);
288  int de = 0; int ee = 0; //no 'rank' associated with candidates...
289  digi.setRank((float)de,(float)ee);
290  return digi;
291 }
292 template<> inline L1DataEmulDigi
294  int cid = de_type();
295  int errt = aflag;
296  double x1 = (aflag!=4) ? itd->phi() : itm->phi();
297  double x2 = 0; //no 'eta' associated with candidates...
298  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
299  unsigned int dw = (aflag==4)?0:itd->raw();
300  unsigned int ew = (aflag==3)?0:itm->raw();
301  dw &= 0x8f1fff; ew &= 0x8f1fff; //22-bit (bits 13,14,15 not set)
302  digi.setData(dw,ew);
303  int de = (aflag==4)?0:itd->et();
304  int ee = (aflag==3)?0:itm->et();
305  digi.setRank((float)de,(float)ee);
306  return digi;
307 }
308 
309 template<> inline L1DataEmulDigi
311  int cid = de_type();
312  int errt = aflag;
313  double x1 = 0; double x2 = 0; //no 'location' associated with candidates...
314  L1DataEmulDigi digi(dedefs::GCT,cid, x1,x2,0., errt);
315  unsigned int dw = (aflag==4)?0:itd->raw0();//raw0, raw1...
316  unsigned int ew = (aflag==3)?0:itm->raw0();//raw0, raw1...
317  digi.setData(dw,ew);
318  int de = 0; int ee = 0; //no 'rank' associated with candidates...
319  digi.setRank((float)de,(float)ee);
320  return digi;
321 }
322 
323 template<> inline L1DataEmulDigi
325  int sid;
326  switch(itd->type_idx()) { // 0 DT, 1 bRPC, 2 CSC, 3 fRPC
327  case 0: sid=dedefs::DTF; break;
328  case 1: sid=dedefs::RPC; break;
329  case 2: sid=dedefs::CTF; break;
330  case 3: sid=dedefs::RPC; break;
331  default: sid=-1;
332  }
333  int cid = de_type();
334  int errt = aflag;
335  //double x1 = (aflag!=4) ? itd->phiValue() : itm->phiValue();
336  //double x2 = (aflag!=4) ? itd->etaValue() : itm->etaValue();
337  double x1 = (aflag!=4) ? itd->phi_packed() : itm->phi_packed();
338  double x2 = (aflag!=4) ? itd->eta_packed() : itm->eta_packed();
339  L1DataEmulDigi digi(sid,cid, x1,x2,0, errt);
340  unsigned int dw = (aflag==4)?0 : itd->getDataWord();
341  unsigned int ew = (aflag==3)?0 : itm->getDataWord();
342  unsigned int mask = 0xffffffff; //32-bit
343  //RPC: mask bits 25-29 (including synch bits)
344  // emulator doesn't set these bits (permanent masking)
345  if(sid==dedefs::RPC)
346  mask &= 0xc1ffffff;
347  dw &= mask; ew &= mask;
348  digi.setData(dw,ew);
349  int de = (aflag==4)?0:itd->pt_packed();//ptValue();
350  int ee = (aflag==3)?0:itm->pt_packed();//ptValue();
351  digi.setRank((float)de,(float)ee);
352  //note: phi,eta,pt 'values' not always set for all muon tf systems
353  //(under discussion) need universal mechanism for setting up physical units
354  if(false) //check print
355  std::cout << "L1DataEmulDigi DEutils<L1MuRegionalCandCollection>] dedigi info"
356  //<< " phivalue:" << itd->phiValue() << "," << itm->phiValue()
357  //<< " etavalue:" << itd->etaValue() << "," << itm->etaValue()
358  << " phipackd:" << itd->phi_packed() << "," << itm->phi_packed()
359  << " etapackd:" << itd->eta_packed() << "," << itm->eta_packed()
360  << std::endl;
361  return digi;
362 }
363 
364 template<> inline L1DataEmulDigi
366  int cid = de_type();
367  int errt = aflag;
368  //double x1 = (aflag!=4) ? itd->phiValue() : itm->phiValue();
369  //double x2 = (aflag!=4) ? itd->etaValue() : itm->etaValue();
370  double x1 = (aflag!=4) ? itd->phiIndex() : itm->phiIndex();
371  double x2 = (aflag!=4) ? itd->etaIndex() : itm->etaIndex();
372  L1DataEmulDigi digi(dedefs::GMT,cid, x1,x2,0, errt);
373  unsigned int dw = (aflag==4)?0 : itd->getDataWord();
374  unsigned int ew = (aflag==3)?0 : itm->getDataWord();
375  unsigned int mask = 0x3ffffff; //26-bit
376  //mask bits 22 (isolation), 23 (mip) [not permanent!]
377  mask &= (~(0x0c00000));
378  dw &= mask; ew &= mask;
379  digi.setData(dw,ew);
380  int de = (aflag==4)?0:itd->ptIndex();//ptValue();
381  int ee = (aflag==3)?0:itm->ptIndex();//ptValue();
382  digi.setRank((float)de,(float)ee);
383  if(false) //check print
384  std::cout << "l1dataemuldigi l1mugmtcandcoll type:" << cid
385  //<< " eta:" << itd->etaValue() << ", " << itm->etaValue()
386  //<< " phi:" << itd->phiValue() << ", " << itm->phiValue()
387  << std::hex << " word d:" << dw << "e:" << ew << std::dec
388  << std::endl;
389  return digi;
390 }
391 
392 template<>
394  int cid = de_type();
395  int errt = aflag;
396  double x1 = (aflag!=4) ? itd->scNum() : itm->scNum();
397  double x2 = (aflag!=4) ? itd->whNum() : itm->whNum();
398  double x3 = (aflag!=4) ? itd->stNum() : itm->stNum();
399  L1DataEmulDigi digi(dedefs::DTP,cid, x1,x2,x3, errt);
400  //other coordinate methods phi(), phiB()
401  //note: no data word defined for candidate
402  int dr = (aflag==4)?0:itd->code();
403  int er = (aflag==3)?0:itm->code();
404  digi.setRank((float)dr,(float)er);
405  return digi;
406 }
407 
408 template<> inline L1DataEmulDigi
410  int cid = de_type();
411  int errt = aflag;
412  double x1 = (aflag!=4) ? itd->scNum() : itm->scNum();
413  double x2 = (aflag!=4) ? itd->whNum() : itm->whNum();
414  double x3 = (aflag!=4) ? itd->stNum() : itm->stNum();
415  L1DataEmulDigi digi(dedefs::DTP,cid, x1,x2,x3, errt);
416  //note: no data word defined for candidate
417  int dr(0), er(0);
418  for(int i=0; i<7;i++){
419  if(itd->code(i)>=dr) dr=itd->quality(i);
420  if(itm->code(i)>=er) er=itm->quality(i);
421  }
422  //alternatives: code() = quality() + positions()
423  dr = (aflag==4)?0:dr;
424  er = (aflag==3)?0:er;
425  digi.setRank((float)dr,(float)er);
426  return digi;
427 }
428 
429 
430 template<> inline L1DataEmulDigi
432  int cid = de_type();
433  int errt = aflag;
434  double x1 = (aflag!=4) ? itd->getStrip() : itm->getStrip();
435  double x2 = (aflag!=4) ? itd->getKeyWG() : itm->getKeyWG();
436  double x3 = (aflag!=4) ? itd->getTrknmb(): itm->getTrknmb();
437  //multiple subsystem ctp,ctf
438  L1DataEmulDigi digi(-1,cid, x1,x2,x3, errt);
439  int dq = (aflag==4)?0:itd->getQuality();
440  int eq = (aflag==3)?0:itm->getQuality();
441  digi.setRank((float)dq,(float)eq);
442  // Pack LCT digi members into 32-bit data words.
443  static const int kValidBitWidth = 1; // Reverse the order of the 1st
444  static const int kQualityBitWidth = 4; // frame to keep the valid bit
445  static const int kPatternBitWidth = 4; // first and quality second, as
446  static const int kWireGroupBitWidth = 7; // is done in ALCT and CLCT.
447  static const int kHalfstripBitWidth = 8;
448  static const int kBendBitWidth = 1;
449  static const int kBxBitWidth = 1;
450  // Use sync_err and bx0_local bits to store MPC link.
451  static const int kMPCLinkBitWidth = 2;
452  static const int kCSCIdBitWidth = 4;
453  // While packing, check that the right number of bits is retained.
454  unsigned shift = 0, dw = 0, ew = 0;
455  dw = itd->isValid() & ((1<<kValidBitWidth)-1);
456  dw += (itd->getQuality() & ((1<<kQualityBitWidth)-1)) <<
457  (shift += kValidBitWidth);
458  dw += (itd->getPattern() & ((1<<kPatternBitWidth)-1)) <<
459  (shift += kQualityBitWidth);
460  dw += (itd->getKeyWG() & ((1<<kWireGroupBitWidth)-1)) <<
461  (shift += kPatternBitWidth);
462  dw += (itd->getStrip() & ((1<<kHalfstripBitWidth)-1)) <<
463  (shift += kWireGroupBitWidth);
464  dw += (itd->getBend() & ((1<<kBendBitWidth)-1)) <<
465  (shift += kHalfstripBitWidth);
466  dw += (itd->getBX() & ((1<<kBxBitWidth)-1)) <<
467  (shift += kBendBitWidth);
468  dw += (itd->getMPCLink() & ((1<<kMPCLinkBitWidth)-1)) <<
469  (shift += kBxBitWidth);
470  dw += (itd->getCSCID() & ((1<<kCSCIdBitWidth)-1)) <<
471  (shift += kMPCLinkBitWidth);
472  shift = 0;
473  ew = itm->isValid() & ((1<<kValidBitWidth)-1);
474  ew += (itm->getQuality() & ((1<<kQualityBitWidth)-1)) <<
475  (shift += kValidBitWidth);
476  ew += (itm->getPattern() & ((1<<kPatternBitWidth)-1)) <<
477  (shift += kQualityBitWidth);
478  ew += (itm->getKeyWG() & ((1<<kWireGroupBitWidth)-1)) <<
479  (shift += kPatternBitWidth);
480  ew += (itm->getStrip() & ((1<<kHalfstripBitWidth)-1)) <<
481  (shift += kWireGroupBitWidth);
482  ew += (itm->getBend() & ((1<<kBendBitWidth)-1)) <<
483  (shift += kHalfstripBitWidth);
484  ew += (itm->getBX() & ((1<<kBxBitWidth)-1)) <<
485  (shift += kBendBitWidth);
486  ew += (itm->getMPCLink() & ((1<<kMPCLinkBitWidth)-1)) <<
487  (shift += kBxBitWidth);
488  ew += (itm->getCSCID() & ((1<<kCSCIdBitWidth)-1)) <<
489  (shift += kMPCLinkBitWidth);
490  digi.setData(dw, ew);
491  return digi;
492 }
493 
494 template<> inline L1DataEmulDigi
496  int cid = de_type();
497  int errt = aflag;
498  double x2 = (aflag!=4) ? itd->getKeyWG () : itm->getKeyWG ();
499  double x3 = (aflag!=4) ? itd->getTrknmb() : itm->getTrknmb();
500  L1DataEmulDigi digi(dedefs::CTP,cid, 0,x2,x3, errt);
501  int dq = (aflag==4)?0:itd->getQuality();
502  int eq = (aflag==3)?0:itm->getQuality();
503  digi.setRank((float)dq,(float)eq);
504  // Pack anode digi members into 17-bit data words.
505  static const int kValidBitWidth = 1;
506  static const int kQualityBitWidth = 2;
507  static const int kAccelBitWidth = 1;
508  static const int kPatternBBitWidth = 1;
509  static const int kWireGroupBitWidth = 7;
510  static const int kBxBitWidth = 5;
511  // While packing, check that the right number of bits is retained.
512  unsigned shift = 0, dw = 0, ew = 0;
513  dw = itd->isValid() & ((1<<kValidBitWidth)-1);
514  dw += (itd->getQuality() & ((1<<kQualityBitWidth)-1)) <<
515  (shift += kValidBitWidth);
516  dw += (itd->getAccelerator() & ((1<<kAccelBitWidth)-1)) <<
517  (shift += kQualityBitWidth);
518  dw += (itd->getCollisionB() & ((1<<kPatternBBitWidth)-1)) <<
519  (shift += kAccelBitWidth);
520  dw += (itd->getKeyWG() & ((1<<kWireGroupBitWidth)-1)) <<
521  (shift += kPatternBBitWidth);
522  dw += (itd->getBX() & ((1<<kBxBitWidth)-1)) <<
523  (shift += kWireGroupBitWidth);
524  shift = 0;
525  ew = itm->isValid() & ((1<<kValidBitWidth)-1);
526  ew += (itm->getQuality() & ((1<<kQualityBitWidth)-1)) <<
527  (shift += kValidBitWidth);
528  ew += (itm->getAccelerator() & ((1<<kAccelBitWidth)-1)) <<
529  (shift += kQualityBitWidth);
530  ew += (itm->getCollisionB() & ((1<<kPatternBBitWidth)-1)) <<
531  (shift += kAccelBitWidth);
532  ew += (itm->getKeyWG() & ((1<<kWireGroupBitWidth)-1)) <<
533  (shift += kPatternBBitWidth);
534  ew += (itm->getBX() & ((1<<kBxBitWidth)-1)) <<
535  (shift += kWireGroupBitWidth);
536  digi.setData(dw, ew);
537  return digi;
538 }
539 template<> inline L1DataEmulDigi
541  int cid = de_type();
542  int errt = aflag;
543  double x1 = (aflag!=4) ? itd->getKeyStrip() : itm->getKeyStrip();
544  double x3 = (aflag!=4) ? itd->getTrknmb() : itm->getTrknmb();
545  L1DataEmulDigi digi(dedefs::CTP,cid, x1,0,x3, errt);
546  int dq = (aflag==4)?0:itd->getQuality();
547  int eq = (aflag==3)?0:itm->getQuality();
548  digi.setRank((float)dq,(float)eq);
549  // Pack cathode digi members into 19-bit data words.
550  static const int kValidBitWidth = 1;
551  static const int kQualityBitWidth = 3;
552  static const int kPatternBitWidth = 4;
553  static const int kBendBitWidth = 1;
554  static const int kHalfstripBitWidth = 5;
555  static const int kCFEBBitWidth = 3;
556  static const int kBxBitWidth = 2;
557  // While packing, check that the right number of bits is retained.
558  unsigned shift = 0, dw = 0, ew = 0;
559  dw = itd->isValid() & ((1<<kValidBitWidth)-1);
560  dw += (itd->getQuality() & ((1<<kQualityBitWidth)-1)) <<
561  (shift += kValidBitWidth);
562  dw += (itd->getPattern() & ((1<<kPatternBitWidth)-1)) <<
563  (shift += kQualityBitWidth);
564  dw += (itd->getBend() & ((1<<kBendBitWidth)-1)) <<
565  (shift += kPatternBitWidth);
566  dw += (itd->getStrip() & ((1<<kHalfstripBitWidth)-1)) <<
567  (shift += kBendBitWidth);
568  dw += (itd->getCFEB() & ((1<<kCFEBBitWidth)-1)) <<
569  (shift += kHalfstripBitWidth);
570  dw += (itd->getBX() & ((1<<kBxBitWidth)-1)) <<
571  (shift += kCFEBBitWidth);
572  shift = 0;
573  ew = itm->isValid() & ((1<<kValidBitWidth)-1);
574  ew += (itm->getQuality() & ((1<<kQualityBitWidth)-1)) <<
575  (shift += kValidBitWidth);
576  ew += (itm->getPattern() & ((1<<kPatternBitWidth)-1)) <<
577  (shift += kQualityBitWidth);
578  ew += (itm->getBend() & ((1<<kBendBitWidth)-1)) <<
579  (shift += kPatternBitWidth);
580  ew += (itm->getStrip() & ((1<<kHalfstripBitWidth)-1)) <<
581  (shift += kBendBitWidth);
582  ew += (itm->getCFEB() & ((1<<kCFEBBitWidth)-1)) <<
583  (shift += kHalfstripBitWidth);
584  ew += (itm->getBX() & ((1<<kBxBitWidth)-1)) <<
585  (shift += kCFEBBitWidth);
586  digi.setData(dw, ew);
587  return digi;
588 }
589 
590 template<> inline L1DataEmulDigi
592  int cid = de_type();
593  int errt = aflag;
594  double x1; //sector/slot
595  x1 = (aflag!=4) ? itd->slot() : itm->slot();
596  //sector-slot map to be in principle to be provided from event setup
597  //int de_cscstatus_slot2sector[22] =
598  // {0,0,0,0,0, 0,1,2,3,4, 5,6,0,0,0, 0,7,8,9,10, 11,12};
599  //x1 = (aflag!=4) ? slot2sector[itd->slot()] : slot2sector[itm->slot()];
600  L1DataEmulDigi digi(dedefs::CTF,cid, x1,0,0, errt);
601  //note: no data word and rank defined for candidate
602  return digi;
603 }
604 
606 
607 template <typename T> typename
609  for ( ;first!=last; first++)
610  if ( de_equal(*first,value) ) break;
611  return first;
612 }
613 
614 /*
615 template <typename T> typename
616 DEutils<T>::col_it DEutils<T>::de_find_loc( col_it first, col_it last, const cand_type& value ) {
617  for ( ;first!=last; first++)
618  if ( de_equal_loc(*first,value) ) break;
619  return first;
620 }
621 */
622 
624 
625 template <typename T>
626 bool DEutils<T>::de_equal(const cand_type& lhs, const cand_type& rhs) {
627  //declare candidate matching by default
628  return true;
629 }
630 template <typename T>
631 bool DEutils<T>::de_nequal(const cand_type& lhs, const cand_type& rhs) {
632  return !de_equal(lhs,rhs);
633 }
634 
635 template <> inline bool
637  bool val = true;
638  unsigned int mask = 0x0fff; //keep only ttf[11:9], fg [8], Et [7:0]
639  mask &= 0x0eff; //fg bit temporary(!) mask
640  val &= ((lhs[lhs.sampleOfInterest()].raw()&mask) == (rhs[rhs.sampleOfInterest()].raw()&mask));
641  val &= (lhs.id().rawId() == rhs.id().rawId());
642  return val;
643 }
644 
645 template <> inline bool
647  bool val = true;
648  unsigned int mask = 0x01ff;
649  val &= ((lhs.t0().raw()&mask) == (rhs.t0().raw()&mask));
650  val &= (lhs.id().rawId() == rhs.id().rawId());
651  return val;
652 }
653 
654 template <> inline bool
656  bool val = true;
657  val &= (lhs.raw() == rhs.raw() );
658  val &= (lhs.rctCrate() == rhs.rctCrate());
659  val &= (lhs.isolated() == rhs.isolated());
660  val &= (lhs.index() == rhs.index() );
661  //val &= (lhs.bx() == rhs.bx() );
662  return val;
663 }
664 
665 template <> inline bool
667  bool val = true;
668  val &= (lhs.et() == rhs.et() );
669  val &= (lhs.rctCrate() == rhs.rctCrate() );
670  val &= (lhs.rctRegionIndex() == rhs.rctRegionIndex());
671  val &= (lhs.id().isHf() == rhs.id().isHf());
672  if (!lhs.id().isHf()){
673  val &= (lhs.overFlow() == rhs.overFlow() );
674  val &= (lhs.tauVeto() == rhs.tauVeto() );
675  //mask temporarily (!) mip and quiet bits
676  //val &= (lhs.mip() == rhs.mip() );
677  //val &= (lhs.quiet() == rhs.quiet() );
678  val &= (lhs.rctCard() == rhs.rctCard() );
679  } else {
680  val &= (lhs.fineGrain() == rhs.fineGrain());
681  }
682  return val;
683 }
684 
685 template <> inline bool
686 DEutils<L1GctEmCandCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
687 
688 template <> inline bool DEutils<L1GctJetCandCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
689 
690 template <> inline bool DEutils<L1GctEtHadCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
691 template <> inline bool DEutils<L1GctEtMissCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
692 template <> inline bool DEutils<L1GctEtTotalCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
693 template <> inline bool DEutils<L1GctHtMissCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
694 template <> inline bool DEutils<L1GctHFRingEtSumsCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
695 template <> inline bool DEutils<L1GctHFBitCountsCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
696 template <> inline bool DEutils<L1GctJetCountsCollection>::de_equal(const cand_type& lhs, const cand_type& rhs) {return lhs==rhs;}
697 
698 
699 template <> inline bool
701  bool val = true;
702  val &= (lhs.whNum() ==rhs.whNum() );
703  val &= (lhs.scNum() ==rhs.scNum() );
704  val &= (lhs.stNum() ==rhs.stNum() );
705  //val &= (lhs.phi() ==rhs.phi() );
706  //val &= (lhs.phiB() ==rhs.phiB() );
707  val &= (lhs.code() ==rhs.code() );
708  val &= (lhs.Ts2Tag()==rhs.Ts2Tag());
709  //val &= (lhs.BxCnt() ==rhs.BxCnt() );
710  //val &= (lhs.bxNum() ==rhs.bxNum() );
711  return val;
712 }
713 
714 template <> inline bool
716  bool val = true;
717  val &= (lhs.whNum() ==rhs.whNum() );
718  val &= (lhs.scNum() ==rhs.scNum() );
719  val &= (lhs.stNum() ==rhs.stNum() );
720  //for(int i=0; i<7; i++) {
721  // val &= (lhs.code(i) ==rhs.code(i) );
722  // val &= (lhs.position(i)==rhs.position(i));
723  // val &= (lhs.quality(i) ==rhs.quality(i) );
724  //}
725  //val &= (lhs.bxNum() ==rhs.bxNum() );
726  return val;
727 }
728 
729 template <> inline bool
731  bool val = true;
732  val &= (lhs.type_idx() == rhs.type_idx());
733  val &= (lhs.bx() == rhs.bx());
734  if(!val) return val;
735  unsigned int dw = lhs.getDataWord();
736  unsigned int ew = rhs.getDataWord();
737  unsigned int mask = 0xffffffff; //32-bit
738  //RPC: mask bits 25-29 (including synch bits)
739  // emulator doesn't set these bits (permanent masking)
740  // 0 DT, 1 bRPC, 2 CSC, 3 fRPC
741  if(rhs.type_idx()==1 || rhs.type_idx()==3)
742  mask &= 0xc1ffffff;
743  dw &= mask; ew &= mask;
744  val &= (dw==ew);
745  //val &= (lhs.getDataWord() == rhs.getDataWord() );
746  //check whether collections being compared refer to same system and bx!
747  return val;
748 }
749 
750 template <> inline bool
752  //return (lhs.getDataWord() == rhs.getDataWord() );
753  //return lhs==rhs; //(dataword,bx..)
754  bool val = true;
755  unsigned int dw = rhs.getDataWord();
756  unsigned int ew = lhs.getDataWord();
757  unsigned int mask = 0x3ffffff; //26-bit
758  //mask bits 22 (isolation), 23 (mip) [not permanent!]
759  mask &= (~(0x0c00000));
760  dw &= mask; ew &= mask;
761  val &= (dw==ew);
762  return val;
763  }
764 
765 template <> inline bool
767  // Exclude track number from comparison since it is only meaningful for
768  // LCTs upstream of the MPC but not downstream (the latter ones are
769  // unpacked by the CSC TF unpacker).
770  bool val = true;
771  val &= (lhs.isValid() == rhs.isValid() );
772  val &= (lhs.getQuality() == rhs.getQuality());
773  val &= (lhs.getKeyWG() == rhs.getKeyWG() );
774  val &= (lhs.getStrip() == rhs.getStrip() );
775  val &= (lhs.getPattern() == rhs.getPattern());
776  val &= (lhs.getBend() == rhs.getBend() );
777  val &= (lhs.getBX() == rhs.getBX() );
778  val &= (lhs.getMPCLink() == rhs.getMPCLink());
779  val &= (lhs.getCSCID() == rhs.getCSCID() );
780  return val;
781  //return lhs==rhs;
782 }
783 template <> inline bool
785  return lhs==rhs;
786 }
787 template <> inline bool
789  return lhs==rhs;
790 }
791 template <> inline bool
793  bool val = true;
794  val &= (lhs.slot() == rhs.slot());
795  val &= (lhs.BXN () == rhs.BXN ());
796  val &= (lhs.FMM () == rhs.FMM ());
797  val &= (lhs.SEs () == rhs.SEs ());
798  val &= (lhs.SMs () == rhs.SMs ());
799  val &= (lhs.BXs () == rhs.BXs ());
800  val &= (lhs.AFs () == rhs.AFs ());
801  val &= (lhs.VPs () == rhs.VPs ());
802  return val;
803 }
804 
806 
807 template <typename T>
808 bool DEutils<T>::de_equal_loc(const cand_type& lhs, const cand_type& rhs) {
809  //declare candidate matching by default
810  return true;
811 }
812 template <typename T>
813 bool DEutils<T>::de_nequal_loc(const cand_type& lhs, const cand_type& rhs) {
814  return !de_equal_loc(lhs,rhs);
815 }
816 
817 
818 template <> inline bool
820  bool val = true;
821  val &= (lhs.id().zside() == rhs.id().zside() );
822  val &= (lhs.id().ietaAbs() == rhs.id().ietaAbs());
823  val &= (lhs.id().iphi() == rhs.id().iphi() );
824  return val;
825 }
826 
827 template <> inline bool
829  bool val = true;
830  val &= (lhs.id().zside() == rhs.id().zside() );
831  val &= (lhs.id().ietaAbs() == rhs.id().ietaAbs());
832  val &= (lhs.id().iphi() == rhs.id().iphi() );
833  return val;
834 }
835 
836 template <> inline bool
838  bool val = true;
839  val &= (lhs.rctCrate() == rhs.rctCrate());
840  val &= (lhs.rctCard() == rhs.rctCard());
841  val &= (lhs.rctRegion() == rhs.rctRegion());
842  return val;
843 }
844 
845 template <> inline bool
847  bool val = true;
848  val &= (lhs.rctCrate() == rhs.rctCrate() );
849  val &= (lhs.id().isHf() == rhs.id().isHf());
850  if (!lhs.id().isHf())
851  val &= (lhs.rctCard() == rhs.rctCard() );
852  val &= (lhs.rctRegionIndex() == rhs.rctRegionIndex());
853  return val;
854 }
855 
856 template <> inline bool
858  bool val = true;
859  val &= (lhs.etaIndex() == rhs.etaIndex());
860  val &= (lhs.phiIndex() == rhs.phiIndex());
861  return val;
862 }
863 template <> inline bool
865  bool val = true;
866  val &= (lhs.etaIndex() == rhs.etaIndex());
867  val &= (lhs.phiIndex() == rhs.phiIndex());
868  return val;
869 }
870 
871 template <> inline bool
873  return true; // no associated location defined
874 }
875 template <> inline bool
877  bool val = true;
878  val &= (lhs.phi() == rhs.phi());
879  return val;
880 }
881 template <> inline bool
883  return true; // no associated location defined
884 }
885 template <> inline bool
887  bool val = true;
888  val &= (lhs.phi() == rhs.phi());
889  return val;
890 }
891 template <> inline bool
893  return true; // no associated location defined
894 }
895 template <> inline bool
897  return true; // no associated location defined
898 }
899 template <> inline bool
901  return true; // no associated location defined
902 }
903 
904 
905 template <> inline bool
907  bool val = true;
908  val &= (lhs.phi_packed() ==rhs.phi_packed() );
909  val &= (lhs.eta_packed() ==rhs.eta_packed() );
910  //val &= (lhs.type_idx() == rhs.type_idx());
911  //val &= (lhs.bx() == rhs.bx());
912  return val;
913 }
914 
915 template <> inline bool
917  bool val = true;
918  val &= (lhs.phiIndex() ==rhs.phiIndex() );
919  val &= (lhs.etaIndex() ==rhs.etaIndex() );
920  return val;
921 }
922 
923 template <> inline bool
925  bool val = true;
926  val &= (lhs.whNum() ==rhs.whNum() );
927  val &= (lhs.scNum() ==rhs.scNum() );
928  val &= (lhs.stNum() ==rhs.stNum() );
929  //val &= (lhs.phi() ==rhs.phi() );
930  //val &= (lhs.phiB() ==rhs.phiB() );
931  //val &= (lhs.bxNum() ==rhs.bxNum() );
932  return val;
933 }
934 
935 template <> inline bool
937  bool val = true;
938  val &= (lhs.whNum() ==rhs.whNum() );
939  val &= (lhs.scNum() ==rhs.scNum() );
940  val &= (lhs.stNum() ==rhs.stNum() );
941  //val &= (lhs.bxNum() ==rhs.bxNum() );
942  return val;
943 }
944 
945 template <> inline bool
947  bool val = true;
948  val &= (lhs.getCSCID() == rhs.getCSCID() );
949  val &= (lhs.getStrip() == rhs.getStrip() );
950  val &= (lhs.getKeyWG() == rhs.getKeyWG() );
951  return val;
952 }
953 
954 template <> inline bool
956  bool val = true;
957  val &= (lhs.getTrknmb() == rhs.getTrknmb() );
958  val &= (lhs.getKeyWG() == rhs.getKeyWG() );
959  return val;
960 }
961 template <> inline bool
963  bool val = true;
964  val &= (lhs.getTrknmb() == rhs.getTrknmb() );
965  val &= (lhs.getKeyStrip() == rhs.getKeyStrip() );
966  return val;
967 }
968 template <> inline bool
970  bool val = true;
971  val &= (lhs.slot() == rhs.slot());
972  return val;
973 }
974 
976 
977 template <typename T>
978 bool DEutils<T>::is_empty(col_cit it) const {
979  //declare candidate non-empty by default
980  return false;
981 }
982 
983 template<>
985  bool val = false;
986  unsigned int raw = it->sample(it->sampleOfInterest()).raw();
987  unsigned int mask = 0x0fff;
988  mask = 0x0eff; //fg bit temporary(!) mask
989  raw &= mask;
990  val |= (raw==0);
991  if(val) return val;
992  unsigned int ttf = it->ttFlag();
993  val |= ((ttf!=0x1) && (ttf!=0x3)); //compare only if ttf is 1 or 3
994  return val;
995  // return ( it->size()==0 || it->sample(it->sampleOfInterest()).raw()==0);
996 }
997 
998 template<>
1000  unsigned int mask = 0x01ff;
1001  return ( it->size()==0 || ((it->t0().raw()&mask)==0) || it->SOI_compressedEt()==0 );
1002 }
1003 
1004 template<>
1006  return ((it->rank())==0);
1007  //return it->empty();
1008 }
1009 
1010 template<>
1012  return ((it->et())==0);
1013  //return it->empty();
1014 }
1015 
1016 template<>
1018  return (it->empty());
1019 }
1020 
1021 template<>
1023  return (it->empty());
1024 }
1025 
1026 template <> inline bool DEutils<L1GctEtHadCollection>::is_empty(col_cit it) const {return(it->empty());}
1027 template <> inline bool DEutils<L1GctEtMissCollection>::is_empty(col_cit it) const {return(it->empty());}
1028 template <> inline bool DEutils<L1GctEtTotalCollection>::is_empty(col_cit it) const {return(it->empty());}
1029 template <> inline bool DEutils<L1GctHtMissCollection>::is_empty(col_cit it) const {return(it->empty());}
1030 template <> inline bool DEutils<L1GctHFRingEtSumsCollection>::is_empty(col_cit it) const {return(it->empty());}
1031 template <> inline bool DEutils<L1GctHFBitCountsCollection>::is_empty(col_cit it) const {return(it->empty());}
1032 template <> inline bool DEutils<L1GctJetCountsCollection>::is_empty(col_cit it) const {return(it->empty());}
1033 
1034 
1035 template<>
1037  return (it->bxNum() != 0 || it->code() == 7);
1038  //return (it->qualityCode() == 7);
1039  //return false;
1040 }
1041 template<>
1043  return (it->whNum()==0 && it->scNum()==0 && it->stNum()==0);//tmp!
1044  //return false;
1045 }
1046 
1047 template<>
1049  //note: following call used to give trouble sometimes
1050 
1051  //restrict further processing to bx==0 for RPC
1052  if(it->type_idx()==1 || it->type_idx()==3) //rpc
1053  if (it->bx()!=0)
1054  return true;
1055 
1056  return (it->empty());
1057  //virtual bool empty() const { return readDataField( PT_START, PT_LENGTH) == 0; }
1058  //return (it->getDataWord()==0);
1059  //return (it->pt_packed()==0);
1060 }
1061 
1062 template<>
1064  return (it->empty());
1065  //return (it->ptIndex()==0);
1066  //return (it->getDataWord()==0);
1067 }
1068 
1069 template<>
1071  return !(it->isValid());
1072 }
1073 template<>
1075  return !(it->isValid());
1076 }
1077 template<>
1079  return !(it->isValid());
1080 }
1081 
1082 template<>
1084  unsigned data =
1085  it->slot() | it->BXN () | it->FMM () | it->SEs () |
1086  it->SMs () | it->BXs () | it->AFs () | it->VPs ();
1087  return data==0;
1088 }
1089 
1091 
1092 template <typename T>
1094  std::stringstream ss;
1095  ss << "[DEutils<T>::print()] specialization still missing for collection!";
1096  //ss << *it; // default
1097  ss << std::endl;
1098  return ss.str();
1099 }
1100 
1101 template <>
1103  std::stringstream ss;
1104  ss << "0x" << std::setw(4) << std::setfill('0') << std::hex
1105  << it->sample(it->sampleOfInterest()).raw()
1106  << std::setfill(' ') << std::dec
1107  << ", et:" << std::setw(3) << it->compressedEt()
1108  << ", fg:" << std::setw(1) << it->fineGrain()
1109  << ", ttf:" << std::setw(2) << it->ttFlag()
1110  << ", sdet:" << ((it->id().subDet()==EcalBarrel)?("Barrel"):("Endcap"))
1111  << ", iz:" << ((it->id().zside()>0)?("+"):("-"))
1112  << ", ieta:" << std::setw(2) << it->id().ietaAbs()
1113  << ", iphi:" << std::setw(2) << it->id().iphi()
1114  //<< "\n\t: " << *it
1115  << std::endl;
1116  return ss.str();
1117 }
1118 
1119 template <>
1121  std::stringstream ss;
1122  ss << "0x" << std::setw(4) << std::setfill('0') << std::hex
1123  << it->t0().raw()
1124  << std::setfill(' ') << std::dec
1125  << ", et:" << std::setw(3) << it->SOI_compressedEt()
1126  << ", fg:" << std::setw(1) << it->SOI_fineGrain()
1127  << ", sdet:" << it->id().subdet()
1128  << ", iz:" << ((it->id().zside()>0)?("+"):("-"))
1129  << ", ieta:" << std::setw(2) << it->id().ietaAbs()
1130  << ", iphi:" << std::setw(2) << it->id().iphi()
1131  << std::endl;
1132  //ss << *it << std::endl;
1133  return ss.str();
1134 }
1135 
1136 template <>
1138  std::stringstream ss;
1139  ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->raw()
1140  << ", rank=0x"<< std::setw(2) << std::hex << it->rank()
1141  << std::setfill(' ') << std::dec
1142  << ", region:"<< std::setw(1) << it->rctRegion()
1143  << ", card:" << std::setw(1) << it->rctCard()
1144  << ", crate:" << std::setw(2) << it->rctCrate()
1145  << ", ieta:" << std::setw(2) << it->regionId().ieta() //0..21
1146  << ", iphi:" << std::setw(2) << it->regionId().iphi() //0..17
1147  //<< ", eta:" << std::setw(2) << it->regionId().rctEta() //0..10
1148  //<< ", phi:" << std::setw(2) << it->regionId().rctPhi() //0..1
1149  << ", iso:" << std::setw(1) << it->isolated()
1150  << ", index:" << std::setw(1) << it->index()
1151  << ", bx:" << it->bx()
1152  << std::endl;
1153  //ss << *it;
1154  return ss.str();
1155 }
1156 
1157 template <>
1159  std::stringstream ss;
1160  ss << "L1CaloRegion:"
1161  << " et=" << it->et()
1162  << " o/f=" << it->overFlow()
1163  << " f/g=" << it->fineGrain()
1164  << " tau=" << it->tauVeto()
1165  << " rct(crate=" << it->rctCrate()
1166  << " card=" << it->rctCard()
1167  << " rgn=" << it->rctRegionIndex()
1168  << " eta=" << it->rctEta()
1169  << " phi=" << it->rctPhi()
1170  << ")\n\t\t"
1171  << "gct(eta=" << it->gctEta()
1172  << " phi=" << it->gctPhi()
1173  << ")"
1174  << std::hex << " cap_block=" << it->capBlock()
1175  << std::dec << " index=" << it->capIndex()
1176  << " bx=" << it->bx()
1177  << std::endl;
1178  //ss << *it; ///replace due to too long unformatted verbose
1179  //note: raw() data accessor missing in dataformats
1180  return ss.str();
1181 }
1182 
1183 template <>
1185  std::stringstream ss;
1186  //get rct index
1187  //int ieta = (it->etaIndex()&0x7); ieta = it->etaSign() ? 10-ieta:11+ieta;
1188  ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->raw()
1189  << ", rank=0x"<< std::setw(2) << std::hex << it->rank()
1190  << std::setfill(' ') << std::dec
1191  << ", etaSign:" << it->etaSign()
1192  << ", eta:" << (it->etaIndex()&0x7) //0..6
1193  << ", phi:" << std::setw(2) << it->phiIndex() //0..17
1194  << " (ieta:" << std::setw(2) << it->regionId().ieta() //0..21
1195  << ",iphi:" << std::setw(2) << it->regionId().iphi() << ")" //0..17
1196  << ", iso:" << it->isolated()
1197  << ", cap block:" << std::setw(3) << it->capBlock()
1198  << ", index:" << it->capIndex()
1199  << ", bx:" << it->bx()
1200  << std::endl;
1201  //<< " " << *it << std::dec << std::endl;
1202  return ss.str();
1203 }
1204 
1205 /*notes on rct/gct indices
1206  ieta: 0 .. 11 .. 21 -> rctEta: 10 .. 0 .. 10 ie: ieta<11?10-ieta:ieta-11
1207  gct from rct eta: rctEta&0x7 (7..0..7) | etaSign(==ieta<11)
1208  rct from gct eta: +-(0..7) -> 3..18 ie: sign?10-eta:eta+11
1209  rct iphi = gct phi
1210 */
1211 
1212 template <>
1214  std::stringstream ss;
1215  ss << "0x" << std::setw(4) << std::setfill('0') << std::hex << it->raw()
1216  << " " << *it << std::dec << std::endl;
1217  return ss.str();
1218 }
1219 template <> inline std::string DEutils<L1GctEtHadCollection >::print(col_cit it) const {std::stringstream ss; ss<<*it; return ss.str();}
1220 template <> inline std::string DEutils<L1GctEtMissCollection >::print(col_cit it) const {std::stringstream ss; ss<<*it; return ss.str();}
1221 template <> inline std::string DEutils<L1GctEtTotalCollection >::print(col_cit it) const {std::stringstream ss; ss<<*it; return ss.str();}
1222 template <> inline std::string DEutils<L1GctHtMissCollection >::print(col_cit it) const {std::stringstream ss; ss<<*it; return ss.str();}
1223 template <> inline std::string DEutils<L1GctHFRingEtSumsCollection>::print(col_cit it) const {std::stringstream ss; ss<<*it; return ss.str();}
1224 template <> inline std::string DEutils<L1GctHFBitCountsCollection >::print(col_cit it) const {std::stringstream ss; ss<<*it; return ss.str();}
1225 template <> inline std::string DEutils<L1GctJetCountsCollection >::print(col_cit it) const {std::stringstream ss; ss<<*it; return ss.str();}
1226 
1227 template <>
1229  std::stringstream ss;
1230  ss << ""
1231  << " bxNum:" << it->bxNum()
1232  << " whNum:" << it->whNum()
1233  << " scNum:" << it->scNum()
1234  << " stNum:" << it->stNum()
1235  << " phi:" << it->phi()
1236  << " phiB:" << it->phiB()
1237  << " code:" << it->code()
1238  << " Ts2Tag:" << it->Ts2Tag()
1239  << " BxCnt:" << it->BxCnt()
1240  << std::endl;
1241  //nb: operator << not implemented in base class L1MuDTChambPhDigi
1242  return ss.str();
1243 }
1244 
1245 template <>
1247  std::stringstream ss;
1248  ss << ""
1249  << " bxNum:" << it->bxNum()
1250  << " whNum:" << it->whNum()
1251  << " scNum:" << it->scNum()
1252  << " stNum:" << it->stNum()
1253  << std::endl;
1254  //nb: operator << not implemented in base class L1MuDTChambThDigi
1255  return ss.str();
1256 }
1257 
1258 template <>
1260  std::stringstream ss;
1261  //const float noval = -10; //L1MuRegionalCand::m_invalidValue;
1262  ss << std::setiosflags(std::ios::showpoint | std::ios::fixed | std::ios::right | std::ios::adjustfield);
1263  ss << std::hex << std::setfill('0')
1264  << " 0x" << std::setw(8) << it->getDataWord();
1265  //if(it->phiValue()==noval || it->etaValue()==noval || it->ptValue()==noval )
1266  ss << std::hex << std::setfill('0')
1267  << " pt:0x" << std::setw(2) << it->pt_packed()
1268  << " phi:0x"<< std::setw(2) << it->phi_packed()
1269  << " eta:0x"<< std::setw(2) << it->eta_packed();
1270  //else
1271  // ss << std::dec << std::setfill(' ')
1272  // << " pt:" << std::setw(5) << std::setprecision(1) << it->ptValue() <<"[GeV]"
1273  // << " phi:" << std::setw(5) << std::setprecision(3) << it->phiValue()<<"[rad]"
1274  // << " eta:" << std::setw(6) << std::setprecision(3) << it->etaValue();
1275  ss << std::dec << std::setfill(' ')
1276  << " qua:" << std::setw(1) << it->quality()
1277  << " cha:" << std::setw(2) << it->chargeValue()
1278  << " chav:" << std::setw(1) << it->chargeValid()
1279  << " fh:" << std::setw(1) << it->isFineHalo()
1280  << " bx:" << std::setw(4) << it->bx()
1281  << " [id:" << std::setw(1) << it->type_idx() << "]" // 0 DT, 1 bRPC, 2 CSC, 3 fRPC
1282  << std::endl;
1283  //ss << it->print()
1284  return ss.str();
1285 }
1286 
1287 template <>
1289  std::stringstream ss;
1290  ss << std::setiosflags(std::ios::showpoint | std::ios::fixed | std::ios::right | std::ios::adjustfield);
1291  //const float noval = -10; //L1MuGMTCand::m_invalidValue;
1292  ss << std::hex << std::setfill('0')
1293  << " 0x" << std::setw(7) << it->getDataWord();
1294  //if(it->phiValue()==noval || it->etaValue()==noval || it->ptValue()==noval)
1295  ss << std::hex << std::setfill('0')
1296  << " pt:0x" << std::setw(2) << it->ptIndex()
1297  << " eta:0x"<< std::setw(2) << it->etaIndex()
1298  << " phi:0x"<< std::setw(3) << it->phiIndex();
1299  //else
1300  // ss << std::dec << std::setfill(' ')
1301  // << " pt:" << std::setw(5) << std::setprecision(1) << it->ptValue() <<"[GeV]"
1302  // << " phi:" << std::setw(5) << std::setprecision(3) << it->phiValue()<<"[rad]"
1303  // << " eta:" << std::setw(6) << std::setprecision(2) << it->etaValue();
1304  ss << std::dec << std::setfill(' ')
1305  << " cha:" << std::setw(2) << it->charge()
1306  << " qua:" << std::setw(3) << it->quality()
1307  << " iso:" << std::setw(1) << it->isol()
1308  << " mip:" << std::setw(1) << it->mip()
1309  << " bx:" << it->bx()
1310  << std::endl;
1311  //ss << it->print()
1312  return ss.str();
1313 }
1314 
1315 template <>
1317  std::stringstream ss;
1318  ss
1319  //<< " lct#:" << it->getTrknmb()
1320  //<< " val:" << it->isValid()
1321  //<< " qua:" << it->getQuality()
1322  //<< " strip:" << it->getStrip()
1323  //<< " bend:" << ((it->getBend() == 0) ? 'L' : 'R')
1324  //<< " patt:" << it->getPattern()
1325  //<<" key wire:" << it->getKeyWG()
1326  //<< " bx:" << it->getBX()
1327  //<< " mpc-link:" << it->getMPCLink()
1328  //<< " csc id:" << it->getCSCID()
1329  //<< std::endl;
1330  << *it;
1331  return ss.str();
1332 }
1333 
1334 template <>
1336  std::stringstream ss;
1337  ss
1338  << *it
1339  << std::endl;
1340  return ss.str();
1341 }
1342 
1343 template <>
1345  std::stringstream ss;
1346  ss
1347  << *it
1348  << std::endl;
1349  return ss.str();
1350 }
1351 
1352 template <>
1354  std::stringstream ss;
1355  ss
1356  << " slot:"<< it->slot()
1357  << " bxn:" << it->BXN ()
1358  << " fmm:" << it->FMM ()
1359  << " ses:" << it->SEs ()
1360  << " sms:" << it->SMs ()
1361  << " bxs:" << it->BXs ()
1362  << " afs:" << it->AFs ()
1363  << " vps:" << it->VPs ()
1364  << std::endl;
1365  return ss.str();
1366 }
1367 
1369 
1370 template <typename T>
1372 
1373  const int nlabel = 17;
1374  if(!(i<nlabel))
1375  return "un-defined" ;
1376  std::string str[nlabel]= {"un-registered"};
1377 
1378  switch(de_type()) {
1379  case dedefs::ECALtp:
1380  str[0] = "ECAL tp";
1381  str[1] = "EcalTrigPrimDigiCollection";
1382  str[2] = "EcalTriggerPrimitiveDigi";
1383  break;
1384  case dedefs::HCALtp:
1385  str[0] = "HCAL tp";
1386  str[1] = "HcalTrigPrimDigiCollection";
1387  str[2] = "HcalTriggerPrimitiveDigi";
1388  break;
1389  case dedefs::RCTem:
1390  str[0] = "RCT em";
1391  str[1] = "L1CaloEmCollection";
1392  str[2] = "L1CaloEmCand";
1393  break;
1394  case dedefs::RCTrgn:
1395  str[0] = "RCT region";
1396  str[1] = "L1CaloRegionCollection";
1397  str[2] = "L1CaloRegion";
1398  break;
1399  case dedefs::GCTisolaem:
1400  str[0] = "GCT em isolated";
1401  str[1] = "L1GctEmCandCollection";
1402  str[2] = "L1GctEmCand";
1403  break;
1404  case dedefs::GCTnoisoem:
1405  str[0] = "GCT em non-isolated";
1406  str[1] = "L1GctEmCandCollection";
1407  str[2] = "L1GctEmCand";
1408  break;
1409  case dedefs::GCTcenjets:
1410  str[0] = "GCT central jet";
1411  str[1] = "L1GctJetCandCollection";
1412  str[2] = "L1GctJetCand";
1413  break;
1414  case dedefs::GCTforjets:
1415  str[0] = "GCT forward jet";
1416  str[1] = "L1GctJetCandCollection";
1417  str[2] = "L1GctJetCand";
1418  break;
1419  case dedefs::GCTtaujets:
1420  str[0] = "GCT tau jet";
1421  str[1] = "L1GctJetCandCollection";
1422  str[2] = "L1GctJetCand";
1423  break;
1424  case dedefs::GCTisotaujets:
1425  str[0] = "Stage1Layer2 iso-tau jet";
1426  str[1] = "L1GctJetCandCollection";
1427  str[2] = "L1GctJetCand";
1428  break;
1429  case dedefs::GCTethad:
1430  str[0] = "GCT ht";
1431  str[1] = "L1GctEtHadCollection";
1432  str[2] = "L1GctEtHad";
1433  break;
1434  case dedefs::GCTetmiss:
1435  str[0] = "GCT et miss";
1436  str[1] = "L1GctEtMissCollection";
1437  str[2] = "L1GctEtMiss";
1438  break;
1439  case dedefs::GCTettot:
1440  str[0] = "GCT et total";
1441  str[1] = "L1GctEtTotalCollection";
1442  str[2] = "L1GctEtTotal";
1443  break;
1444  case dedefs::GCThtmiss:
1445  str[0] = "GCT ht miss";
1446  str[1] = "L1GctHtMissCollection";
1447  str[2] = "L1GctHtMiss";
1448  break;
1449  case dedefs::GCThfring:
1450  str[0] = "GCT hf ring";
1451  str[1] = "L1GctHFRingEtSumsCollection";
1452  str[2] = "L1GctHFRingEtSums";
1453  break;
1454  case dedefs::GCThfbit:
1455  str[0] = "GCT hf bit counts";
1456  str[1] = "L1GctHFBitCountsCollection";
1457  str[2] = "L1GctHFBitCounts";
1458  break;
1459 
1460  case dedefs::DTtpPh:
1461  str[0] = "DT tp phi";
1462  str[1] = "L1MuDTChambPhDigiCollection";
1463  str[2] = "L1MuDTChambPhDigi";
1464  break;
1465  case dedefs::DTtpTh:
1466  str[0] = "DT tp theta";
1467  str[1] = "L1MuDTChambThDigiCollection";
1468  str[2] = "L1MuDTChambThDigi";
1469  break;
1470  case dedefs::CSCtpa:
1471  str[0] = "CSC tpa";
1472  str[1] = "CSCALCTDigiCollection";
1473  str[2] = "CSCALCTDigi";
1474  break;
1475  case dedefs::CSCtpc:
1476  str[0] = "CSC tpc";
1477  str[1] = "CSCCLCTDigiCollection";
1478  str[2] = "CSCCLCTDigi";
1479  break;
1480  case dedefs::CSCtpl:
1481  str[0] = "CSC tp";
1482  str[1] = "CSCCorrelatedLCTDigiCollection";
1483  str[2] = "CSCCorrelatedLCTDigi";
1484  break;
1485  case dedefs::CSCsta:
1486  str[0] = "CSC tf status";
1487  str[1] = "L1CSCSPStatusDigiCollection_";
1488  str[2] = "L1CSCSPStatusDigi";
1489  break;
1490  case dedefs::MUrtf:
1491  str[0] = "Mu reg tf";
1492  str[1] = "L1MuRegionalCandCollection";
1493  str[2] = "L1MuRegionalCand";
1494  break;
1495  case dedefs::LTCi:
1496  str[0] = "LTC";
1497  str[1] = "LTCDigiCollection";
1498  str[2] = "LTCDigi";
1499  break;
1500  case dedefs::GMTcnd:
1501  str[0] = "GMT cand";
1502  str[1] = "L1MuGMTCandCollection";
1503  str[2] = "L1MuGMTCand";
1504  break;
1505  case dedefs::GMTrdt:
1506  str[0] = "GMT record";
1507  str[1] = "L1MuGMTReadoutRecordCollection";
1508  str[2] = "L1MuGMTReadoutRecord";
1509  break;
1510  case dedefs::GTdword:
1511  str[0] = "";
1512  str[1] = "";
1513  str[2] = "";
1514  break;
1515  //default:
1516  }
1517  return str[i];
1518 }
1519 
1521 
1522 template <typename T>
1523 struct de_rank : public DEutils<T> {
1525  typedef typename de_trait::cand_type cand_type;
1526  bool operator()(const cand_type& x, const cand_type& y) const {
1527  return false; //default
1528  }
1529 };
1530 
1531 template <> inline bool de_rank<EcalTrigPrimDigiCollection>::operator()(const cand_type& x, const cand_type& y) const { return x.compressedEt() > y.compressedEt(); }
1532 template <> inline bool de_rank<HcalTrigPrimDigiCollection>::operator()(const cand_type& x, const cand_type& y) const { return x.SOI_compressedEt() > y.SOI_compressedEt(); }
1533 
1534 template <>
1536  (const cand_type& x, const cand_type& y) const {
1537  if (x.rank() != y.rank()) {
1538  return (x.rank() < y.rank()) ;
1539  } else if(x.isolated() != y.isolated()) {
1540  return (x.isolated())?true:false;
1541  } else if(x.rctRegion() != y.rctRegion()){
1542  return (x.rctRegion() < y.rctRegion());
1543  } else if(x.rctCrate() != y.rctCrate()) {
1544  return (x.rctCrate() < y.rctCrate()) ;
1545  } else if(x.rctCard() != y.rctCard()) {
1546  return (x.rctCard() < y.rctCard()) ;
1547  } else {
1548  return x.raw() < y.raw();
1549  }
1550 }
1551 
1552 template <> inline bool de_rank<L1CaloRegionCollection>::operator()(const cand_type& x, const cand_type& y) const { return x.et() < y.et(); }
1553 
1554 template <> inline bool de_rank<L1GctEmCandCollection>::operator()(const cand_type& x, const cand_type& y)const { if(x.rank()!=y.rank()){return x.rank() < y.rank();} else{if(x.etaIndex()!=y.etaIndex()){return y.etaIndex() < x.etaIndex();}else{ return x.phiIndex() < y.phiIndex();}}}
1555 template <> inline bool de_rank<L1GctJetCandCollection>::operator()(const cand_type& x, const cand_type& y)const { if(x.rank()!=y.rank()){return x.rank() < y.rank();} else{if(x.etaIndex()!=y.etaIndex()){return y.etaIndex() < x.etaIndex();}else{ return x.phiIndex() < y.phiIndex();}}}
1556 //template <> inline bool de_rank<L1GctEtHadCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1557 //template <> inline bool de_rank<L1GctEtMissCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1558 //template <> inline bool de_rank<L1GctEtTotalCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1559 //template <> inline bool de_rank<L1GctHtMissCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1560 //template <> inline bool de_rank<L1GctHFRingEtSumsCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1561 //template <> inline bool de_rank<L1GctHFBitCountsCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1562 //template <> inline bool de_rank<L1GctJetCountsCollection>::operator()(const cand_type& x, const cand_type& y)const { }
1563 
1564 template <> inline bool de_rank<L1MuDTChambPhDigiCollection>::operator()(const cand_type& x, const cand_type& y)const { if(x.whNum()!=y.whNum()){return x.whNum() < y.whNum();} else{if(x.scNum()!=y.scNum()){return y.scNum() < x.scNum();}else{ return x.stNum() < y.stNum();}}}
1565 template <> inline bool de_rank<L1MuDTChambThDigiCollection>::operator()(const cand_type& x, const cand_type& y)const { if(x.whNum()!=y.whNum()){return x.whNum() < y.whNum();} else{if(x.scNum()!=y.scNum()){return y.scNum() < x.scNum();}else{ return x.stNum() < y.stNum();}}}
1566 
1567 template <> inline bool de_rank<L1MuRegionalCandCollection>::operator()(const cand_type& x, const cand_type& y)const {if(x.phi_packed()!=y.phi_packed()){return x.phi_packed() < y.phi_packed();} else{if(x.eta_packed()!=y.eta_packed()){return y.eta_packed() < x.eta_packed();}else{ return x.quality_packed() < y.quality_packed();}}}
1568 
1569 template <> inline bool de_rank<L1MuGMTCandCollection>::operator()(const cand_type& x, const cand_type& y)const {
1570  if(x.bx()!=y.bx()){return x.bx() < y.bx();}
1571  else if(x.ptIndex()!=y.ptIndex()){return x.ptIndex() < y.ptIndex();}
1572  else{ return x.quality() < y.quality();}
1573 }
1574 
1575 template <> inline bool de_rank<CSCCorrelatedLCTDigiCollection_>::operator()(const cand_type& x, const cand_type& y)const {if(x.getTrknmb()!=y.getTrknmb()){return x.getTrknmb() < y.getTrknmb();} else{if(x.getKeyWG()!=y.getKeyWG()){return y.getKeyWG() < x.getKeyWG();} else{ return x.getQuality() < y.getQuality();}}}
1576 
1577 #endif
T::const_iterator col_cit
Definition: DEutils.h:20
de_trait::cand_type cand_type
Definition: DEutils.h:23
L1DataEmulDigi DEDigi(col_cit itd, col_cit itm, int ctype)
— form de-digi —
Definition: DEutils.h:57
void setRank(float d, float e)
DEtrait< T > de_trait
Definition: DEutils.h:22
— order candidates —
Definition: DEcompare.h:17
de_trait::coll_type coll_type
Definition: DEutils.h:24
void setData(unsigned int d, unsigned int e)
int de_type() const
Definition: DEutils.h:37
uint16_t size_type
bool de_nequal(const cand_type &, const cand_type &)
Definition: DEutils.h:631
bool de_nequal_loc(const cand_type &, const cand_type &)
Definition: DEutils.h:813
DEtrait< T > de_trait
Definition: DEutils.h:1524
bool is_empty(col_cit) const
— candidate emptiness definition —
Definition: DEutils.h:978
void setDEpair(const L1MonitorDigi &d, const L1MonitorDigi &e)
std::string print(col_cit) const
— print candidate —
Definition: DEutils.h:1093
~DEutils()
Definition: DEutils.h:35
Definition: value.py:1
T::size_type col_sz
Definition: DEutils.h:19
bool de_equal_loc(const cand_type &, const cand_type &)
— candidate location-match definition —
Definition: DEutils.h:808
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
col_it de_find(col_it, col_it, const cand_type &)
— find candidate —
Definition: DEutils.h:608
DEutils()
Definition: DEutils.h:28
static unsigned int const shift
de_trait::cand_type cand_type
Definition: DEutils.h:1525
std::string GetName(int i=0) const
— name candidate —
Definition: DEutils.h:1371
bool operator()(const cand_type &x, const cand_type &y) const
Definition: DEutils.h:1526
#define str(s)
T::iterator col_it
Definition: DEutils.h:21
bool de_equal(const cand_type &, const cand_type &)
— candidate match definition —
Definition: DEutils.h:626