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 CaloRecHit::~CaloRecHit() {
00012 }
00013
00014 static const uint32_t masks[] = {
00015 0x00000000u,0x00000001u,0x00000003u,0x00000007u,0x0000000fu,0x0000001fu,
00016 0x0000003fu,0x0000007fu,0x000000ffu,0x000001ffu,0x000003ffu,0x000007ffu,
00017 0x00000fffu,0x00001fffu,0x00003fffu,0x00007fffu,0x0000ffffu,0x0001ffffu,
00018 0x0003ffffu,0x0007ffffu,0x000fffffu,0x001fffffu,0x003fffffu,0x007fffffu,
00019 0x00ffffffu,0x01ffffffu,0x03ffffffu,0x07ffffffu,0x0fffffffu,0x1fffffffu,
00020 0x3fffffffu,0x7fffffffu,0xffffffffu};
00021
00022 void CaloRecHit::setFlagField(uint32_t value, int base, int width) {
00023 value&=masks[std::max(std::min(width,32),0)];
00024 value<<=std::max(std::min(base,31),0);
00025
00026 uint32_t clear=masks[std::max(std::min(width,32),0)];
00027 clear=clear<<std::max(std::min(base,31),0);
00028 clear^=0xFFFFFFFFu;
00029 flags_&=clear;
00030 flags_|=value;
00031 }
00032
00033 uint32_t CaloRecHit::flagField(int base, int width) const {
00034 return (flags_>>std::max(std::min(base,31),0))&masks[std::max(std::min(width,32),0)];
00035 }
00036
00037
00038 std::ostream& operator<<(std::ostream& s, const CaloRecHit& hit) {
00039 s << hit.detid().rawId() << ", " << hit.energy() << " GeV, " << hit.time() << " ns ";
00040 s << " flags=0x" << std::hex << hit.flags() << std::dec << " ";
00041 s << " aux=0x" << std::hex << hit.aux() << std::dec << " ";
00042 return s;
00043 }
00044