CMS 3D CMS Logo

CaloID.cc

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

Generated on Tue Jun 9 17:27:14 2009 for CMSSW by  doxygen 1.5.4