CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DataFormats/CSCDigi/src/CSCComparatorDigi.cc

Go to the documentation of this file.
00001 
00008 #include <DataFormats/CSCDigi/interface/CSCComparatorDigi.h>
00009 #include <iostream>
00010 #include <algorithm>
00011 #include <iterator>
00012 
00013 using namespace std;
00014 
00015 // Constructors
00016 CSCComparatorDigi::CSCComparatorDigi( int strip, int comparator, int timeBinWord )
00017   : strip_( strip ), comparator_( comparator ), timeBinWord_( timeBinWord ) {
00018 }
00019 
00020 
00021 CSCComparatorDigi::CSCComparatorDigi() 
00022   : strip_( 0 ), comparator_( 0 ), timeBinWord_( 0 ) {
00023 }
00024 
00025 
00026 // Comparison
00027 
00028 bool
00029 CSCComparatorDigi::operator == (const CSCComparatorDigi& digi) const {
00030   if ( getStrip() != digi.getStrip() ) return false;
00031   if ( getComparator() != digi.getComparator() ) return false;
00032   if ( getTimeBinWord() != digi.getTimeBinWord() ) return false;
00033   return true;
00034 }
00035 
00036 
00037 //@@ If one wanted to order comparator digis how would one want op< to behave?
00038 // I don't know...
00039 // I think LHS < RHS only makes sense if
00040 // i) time(LHS) .eq. time(RHS)
00041 // AND
00042 // ii) strip(LHS) .lt. strip(RHS)
00043 // But I don't see how this can be useful.
00044 
00045 bool 
00046 CSCComparatorDigi::operator<(const CSCComparatorDigi& digi) const {
00047   bool result = false;
00048   if(getTimeBin() == digi.getTimeBin()) {
00049     result = (getStrip() < digi.getStrip());
00050   }
00051   return result;
00052 }
00053 
00054 
00055 // Getters
00056 
00057 int CSCComparatorDigi::getTimeBin() const {
00058   // Find first bin which fired, counting from 0
00059   uint16_t tbit=1;
00060   int tbin=-1;
00061   for(int i=0;i<16;++i) {
00062     if(tbit & timeBinWord_) {
00063       tbin=i;
00064       break;
00065     }
00066     tbit=tbit<<1;
00067   }
00068   return tbin;
00069 }
00070 
00071 std::vector<int> CSCComparatorDigi::getTimeBinsOn() const {
00072   std::vector<int> tbins;
00073   uint16_t tbit = timeBinWord_;
00074   const uint16_t one=1;
00075   for(int i=0;i<16;++i) {
00076     if(tbit & one) tbins.push_back(i);
00077     tbit=tbit>>1;
00078     if(tbit==0) break; // end already if no more bits set
00079   }
00080   return tbins;                                  
00081 }
00082 
00083 // Setters
00084 //@@ No way to set time word?
00085 
00086 void CSCComparatorDigi::setStrip(int strip) {
00087   strip_ = strip;
00088 }
00089 void CSCComparatorDigi::setComparator(int comparator) {
00090   comparator_ = comparator;
00091 }
00092 
00093 // Output
00094 
00095 void
00096 CSCComparatorDigi::print() const {
00097   std::cout << "CSCComparatorDigi strip: " << getStrip() 
00098        << " comparator: " << getComparator() 
00099             << " first time bin: "<< getTimeBin()
00100        << " time bins on: ";
00101   std::vector<int> tbins=getTimeBinsOn();
00102   std::copy( tbins.begin(), tbins.end(), 
00103      std::ostream_iterator<int>( std::cout, " "));
00104   std::cout << std::endl; 
00105 }
00106 
00107 //@@ Doesn't print all time bins
00108 std::ostream & operator<<(std::ostream & o, const CSCComparatorDigi& digi) {
00109   return o << " " << digi.getStrip()
00110            << " " << digi.getComparator()
00111            << " " << digi.getTimeBin();
00112 }  
00113 
00114