CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DataFormats/CaloRecHit/src/CaloID.cc

Go to the documentation of this file.
00001 #include "DataFormats/CaloRecHit/interface/CaloID.h"
00002 #include <iostream>
00003 
00004 using namespace reco;
00005 using namespace std;
00006 
00007 
00008 void CaloID::setDetector(Detectors theDetector, bool value) {
00009   
00010   //  cout<<"CaloID::setDetector "<<theDetector<<" "<<(1<<theDetector)<<endl;
00011   if(value)
00012     detectors_ = detectors_ | (1<<theDetector);
00013   else 
00014     detectors_ = detectors_ ^ (1<<theDetector);
00015 
00016   // cout<<detectors_<<endl;
00017 }
00018 
00019 
00020 
00021 bool CaloID::detector(Detectors theDetector) const {
00022 
00023   return (detectors_>>theDetector) & 1;
00024 }
00025 
00026 
00027 CaloID::Detectors  CaloID::detector() const {
00028   if( ! isSingleDetector() ) return DET_NONE;
00029   
00030   int pos =  leastSignificantBitPosition( detectors_ );
00031   
00032   CaloID::Detectors det = static_cast<CaloID::Detectors>(pos);
00033                                                                
00034   return det;
00035 }
00036 
00037 
00038 
00039 int CaloID::leastSignificantBitPosition(unsigned n) const {
00040     if (n == 0)
00041       return -1;
00042  
00043     int pos = 31;
00044 
00045     if (n & 0x000000000000FFFFLL) { pos -= 16; } else { n >>= 16; }
00046     if (n & 0x00000000000000FFLL) { pos -=  8; } else { n >>=  8; }
00047     if (n & 0x000000000000000FLL) { pos -=  4; } else { n >>=  4; }
00048     if (n & 0x0000000000000003LL) { pos -=  2; } else { n >>=  2; }
00049     if (n & 0x0000000000000001LL) { pos -=  1; }
00050     return pos;
00051 }
00052 
00053 
00054 std::ostream& reco::operator<<(std::ostream& out,
00055                                const CaloID& id) {
00056   if(!out) return out;
00057 
00058   out<<"CaloID: "<<id.detectors();
00059   return out;
00060 }