Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:48

0001 #include "DataFormats/CaloRecHit/interface/CaloID.h"
0002 #include <iostream>
0003 
0004 using namespace reco;
0005 using namespace std;
0006 
0007 void CaloID::setDetector(Detectors theDetector, bool value) {
0008   //  cout<<"CaloID::setDetector "<<theDetector<<" "<<(1<<theDetector)<<endl;
0009   if (value)
0010     detectors_ = detectors_ | (1 << theDetector);
0011   else
0012     detectors_ = detectors_ ^ (1 << theDetector);
0013 
0014   // cout<<detectors_<<endl;
0015 }
0016 
0017 bool CaloID::detector(Detectors theDetector) const { return (detectors_ >> theDetector) & 1; }
0018 
0019 CaloID::Detectors CaloID::detector() const {
0020   if (!isSingleDetector())
0021     return DET_NONE;
0022 
0023   int pos = leastSignificantBitPosition(detectors_);
0024 
0025   CaloID::Detectors det = static_cast<CaloID::Detectors>(pos);
0026 
0027   return det;
0028 }
0029 
0030 int CaloID::leastSignificantBitPosition(unsigned n) const {
0031   if (n == 0)
0032     return -1;
0033 
0034   int pos = 31;
0035 
0036   if (n & 0x000000000000FFFFLL) {
0037     pos -= 16;
0038   } else {
0039     n >>= 16;
0040   }
0041   if (n & 0x00000000000000FFLL) {
0042     pos -= 8;
0043   } else {
0044     n >>= 8;
0045   }
0046   if (n & 0x000000000000000FLL) {
0047     pos -= 4;
0048   } else {
0049     n >>= 4;
0050   }
0051   if (n & 0x0000000000000003LL) {
0052     pos -= 2;
0053   } else {
0054     n >>= 2;
0055   }
0056   if (n & 0x0000000000000001LL) {
0057     pos -= 1;
0058   }
0059   return pos;
0060 }
0061 
0062 std::ostream& reco::operator<<(std::ostream& out, const CaloID& id) {
0063   if (!out)
0064     return out;
0065 
0066   out << "CaloID: " << id.detectors();
0067   return out;
0068 }