CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DataFormats/CaloRecHit/src/CaloRecHit.cc

Go to the documentation of this file.
00001 #include "DataFormats/CaloRecHit/interface/CaloRecHit.h"
00002 
00003 
00004 CaloRecHit::CaloRecHit() : energy_(0), time_(0), flags_(0), aux_(0) {
00005 }
00006 
00007 CaloRecHit::CaloRecHit(const DetId& id, float energy, float time, uint32_t flags, uint32_t aux) : 
00008         id_(id),energy_(energy), time_(time), flags_(flags), aux_(aux) {
00009 }
00010 
00011 
00012 static const uint32_t masks[] = {
00013   0x00000000u,0x00000001u,0x00000003u,0x00000007u,0x0000000fu,0x0000001fu,
00014   0x0000003fu,0x0000007fu,0x000000ffu,0x000001ffu,0x000003ffu,0x000007ffu,
00015   0x00000fffu,0x00001fffu,0x00003fffu,0x00007fffu,0x0000ffffu,0x0001ffffu,
00016   0x0003ffffu,0x0007ffffu,0x000fffffu,0x001fffffu,0x003fffffu,0x007fffffu,
00017   0x00ffffffu,0x01ffffffu,0x03ffffffu,0x07ffffffu,0x0fffffffu,0x1fffffffu,
00018   0x3fffffffu,0x7fffffffu,0xffffffffu};
00019 
00020 void CaloRecHit::setFlagField(uint32_t value, int base, int width) {
00021   value&=masks[std::max(std::min(width,32),0)];
00022   value<<=std::max(std::min(base,31),0);
00023   // clear out the relevant bits
00024   uint32_t clear=masks[std::max(std::min(width,32),0)];
00025   clear=clear<<std::max(std::min(base,31),0);
00026   clear^=0xFFFFFFFFu;
00027   flags_&=clear;
00028   flags_|=value;
00029 }
00030 
00031 uint32_t CaloRecHit::flagField(int base, int width) const {
00032   return (flags_>>std::max(std::min(base,31),0))&masks[std::max(std::min(width,32),0)];
00033 }
00034 
00035 
00036 std::ostream& operator<<(std::ostream& s, const CaloRecHit& hit) {
00037   s << hit.detid().rawId() << ", " << hit.energy() << " GeV, " << hit.time() << " ns ";
00038   s << " flags=0x" << std::hex << hit.flags() << std::dec << " ";
00039   s << " aux=0x" << std::hex << hit.aux() << std::dec << " ";
00040   return s;
00041 }
00042