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 
8 #include <iostream>
9 #include <algorithm>
10 #include <iterator>
11 
12 using namespace std;
13 
14 // Constructors
15 CSCComparatorDigi::CSCComparatorDigi( int strip, int comparator, int timeBinWord )
16  : strip_( strip ), comparator_( comparator ), timeBinWord_( timeBinWord ) {
17 }
18 
19 
21  : strip_( 0 ), comparator_( 0 ), timeBinWord_( 0 ) {
22 }
23 
24 
25 // Comparison
26 
27 bool
29  if ( getStrip() != digi.getStrip() ) return false;
30  if ( getComparator() != digi.getComparator() ) return false;
31  if ( getTimeBinWord() != digi.getTimeBinWord() ) return false;
32  return true;
33 }
34 
35 
36 //@@ If one wanted to order comparator digis how would one want op< to behave?
37 // I don't know...
38 // I think LHS < RHS only makes sense if
39 // i) time(LHS) .eq. time(RHS)
40 // AND
41 // ii) strip(LHS) .lt. strip(RHS)
42 // But I don't see how this can be useful.
43 
44 bool
46  bool result = false;
47  if(getTimeBin() == digi.getTimeBin()) {
48  result = (getStrip() < digi.getStrip());
49  }
50  return result;
51 }
52 
53 
54 // Getters
55 
57  // Find first bin which fired, counting from 0
58  uint16_t tbit=1;
59  int tbin=-1;
60  for(int i=0;i<16;++i) {
61  if(tbit & timeBinWord_) {
62  tbin=i;
63  break;
64  }
65  tbit=tbit<<1;
66  }
67  return tbin;
68 }
69 
70 std::vector<int> CSCComparatorDigi::getTimeBinsOn() const {
71  std::vector<int> tbins;
72  uint16_t tbit = timeBinWord_;
73  const uint16_t one=1;
74  for(int i=0;i<16;++i) {
75  if(tbit & one) tbins.push_back(i);
76  tbit=tbit>>1;
77  if(tbit==0) break; // end already if no more bits set
78  }
79  return tbins;
80 }
81 
82 // Setters
83 //@@ No way to set time word?
84 
85 void CSCComparatorDigi::setStrip(int strip) {
86  strip_ = strip;
87 }
88 void CSCComparatorDigi::setComparator(int comparator) {
89  comparator_ = comparator;
90 }
91 
92 // Output
93 
94 void
96  std::ostringstream ost;
97  ost << "CSCComparatorDigi | strip " << getStrip()
98  << " | comparator " << getComparator()
99  << " | first time bin " << getTimeBin() << " | time bins on ";
100  std::vector<int> tbins=getTimeBinsOn();
101  for(unsigned int i=0; i<tbins.size();i++) {ost << tbins[i] << " ";}
102  edm::LogVerbatim("CSCDigi") << ost.str();
103 }
104 
105 //@@ Doesn't print all time bins
106 std::ostream & operator<<(std::ostream & o, const CSCComparatorDigi& digi) {
107  return o << " " << digi.getStrip()
108  << " " << digi.getComparator()
109  << " " << digi.getTimeBin();
110 }
111 
112 
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.
tuple result
Definition: mps_fire.py:83
bool operator<(const CSCComparatorDigi &digi) const
sort by time first, then by strip
std::vector< int > getTimeBinsOn() const
int getTimeBinWord() const
Return the word with each bit corresponding to a time bin.