CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCComparatorDigi.cc
Go to the documentation of this file.
1 
9 #include <iostream>
10 #include <algorithm>
11 #include <iterator>
12 
13 using namespace std;
14 
15 // Constructors
16 CSCComparatorDigi::CSCComparatorDigi( int strip, int comparator, int timeBinWord )
17  : strip_( strip ), comparator_( comparator ), timeBinWord_( timeBinWord ) {
18 }
19 
20 
22  : strip_( 0 ), comparator_( 0 ), timeBinWord_( 0 ) {
23 }
24 
25 
26 // Comparison
27 
28 bool
30  if ( getStrip() != digi.getStrip() ) return false;
31  if ( getComparator() != digi.getComparator() ) return false;
32  if ( getTimeBinWord() != digi.getTimeBinWord() ) return false;
33  return true;
34 }
35 
36 
37 //@@ If one wanted to order comparator digis how would one want op< to behave?
38 // I don't know...
39 // I think LHS < RHS only makes sense if
40 // i) time(LHS) .eq. time(RHS)
41 // AND
42 // ii) strip(LHS) .lt. strip(RHS)
43 // But I don't see how this can be useful.
44 
45 bool
47  bool result = false;
48  if(getTimeBin() == digi.getTimeBin()) {
49  result = (getStrip() < digi.getStrip());
50  }
51  return result;
52 }
53 
54 
55 // Getters
56 
58  // Find first bin which fired, counting from 0
59  uint16_t tbit=1;
60  int tbin=-1;
61  for(int i=0;i<16;++i) {
62  if(tbit & timeBinWord_) {
63  tbin=i;
64  break;
65  }
66  tbit=tbit<<1;
67  }
68  return tbin;
69 }
70 
71 std::vector<int> CSCComparatorDigi::getTimeBinsOn() const {
72  std::vector<int> tbins;
73  uint16_t tbit = timeBinWord_;
74  const uint16_t one=1;
75  for(int i=0;i<16;++i) {
76  if(tbit & one) tbins.push_back(i);
77  tbit=tbit>>1;
78  if(tbit==0) break; // end already if no more bits set
79  }
80  return tbins;
81 }
82 
83 // Setters
84 //@@ No way to set time word?
85 
86 void CSCComparatorDigi::setStrip(int strip) {
87  strip_ = strip;
88 }
89 void CSCComparatorDigi::setComparator(int comparator) {
90  comparator_ = comparator;
91 }
92 
93 // Output
94 
95 void
97  std::cout << "CSCComparatorDigi strip: " << getStrip()
98  << " comparator: " << getComparator()
99  << " first time bin: "<< getTimeBin()
100  << " time bins on: ";
101  std::vector<int> tbins=getTimeBinsOn();
102  std::copy( tbins.begin(), tbins.end(),
103  std::ostream_iterator<int>( std::cout, " "));
104  std::cout << std::endl;
105 }
106 
107 //@@ Doesn't print all time bins
108 std::ostream & operator<<(std::ostream & o, const CSCComparatorDigi& digi) {
109  return o << " " << digi.getStrip()
110  << " " << digi.getComparator()
111  << " " << digi.getTimeBin();
112 }
113 
114 
int i
Definition: DBlmapReader.cc:9
int getStrip() const
Get the strip number.
void setComparator(int comparator)
Set Comparator data.
void print() const
Print content of digi.
void setStrip(int strip)
Set the strip number.
CSCComparatorDigi()
comparator here can be either 0 or 1 for left or right halfstrip of given strip
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
int getComparator() const
Get Comparator readings.
bool operator==(const CSCComparatorDigi &digi) const
Digis are equal if they are on the same strip and have same Comparator data.
int getTimeBin() const
Return bin number of first time bin which is ON. Counts from 0.
bool operator<(const CSCComparatorDigi &digi) const
sort by time first, then by strip
tuple result
Definition: query.py:137
std::vector< int > getTimeBinsOn() const
int getTimeBinWord() const
Return the word with each bit corresponding to a time bin.
tuple cout
Definition: gather_cfg.py:121