#include #include #include #include "IChannelId.hxx" #include "IStrawTrkChannelId.hxx" #include "IECALChannelId.hxx" #include "ICTHChannelId.hxx" #include "ICDCChannelId.hxx" #include "ITOFChannelId.hxx" #include "ICOMETLog.hxx" ClassImp(COMET::IChannelId); namespace { }; //---------------------------------------------------------------------- COMET::IChannelId::IChannelId(UInt_t id): fChannelId(id) { //std::cout << "IChannelId id = " << id << std::endl; } //---------------------------------------------------------------------- COMET::IChannelId::IChannelId(const IChannelId& src): fChannelId(src.fChannelId) {} //---------------------------------------------------------------------- COMET::IChannelId::~IChannelId() {} //---------------------------------------------------------------------- unsigned int COMET::IChannelId::GetField(int msb, int lsb) const { if (lsb>msb || lsb<0 || 31> lsb; unsigned int mask = (1<<(msb-lsb+1))-1; return (field & mask); } //---------------------------------------------------------------------- std::string COMET::IChannelId::GetAsString( const char* detName, UInt_t channel) const { const char* det = IChannelId::SubDetAsString().c_str(); char buffer[50]; snprintf(buffer, 50, "%7s: %s:(CH=%024i)", det, detName, channel); return std::string(buffer); } //---------------------------------------------------------------------- void COMET::IChannelId::SetField(int val, int msb, int lsb) { // Make sure the bit range is valid. if (lsb>msb || lsb<0 || 31= maxValue) { COMETSevere("Channel id value out of range " << val << " Bits in field " << msb-lsb+1 << " Maximum value " << maxValue); return; } if (val < 0) { COMETSevere("Channel id value out of range " << val << " -- Negative values are not allowed"); return; } // Build a mask for this field long mask = ((1<<(msb-lsb+1))-1) << lsb; // Clear the bit field. fChannelId &= ~mask; // Shift the value and set the field. fChannelId |= ((val << lsb)&mask); } //---------------------------------------------------------------------- void COMET::IChannelId::SetGuardBit() { SetField(1,kGuardBitMSB, kGuardBitLSB); } //---------------------------------------------------------------------- const COMET::IChannelId::SubDetId COMET::IChannelId::GetSubDetector() const { return COMET::IChannelId::SubDetId(GetField(kSubDetMSB,kSubDetLSB)); } //---------------------------------------------------------------------- void COMET::IChannelId::SetSubDetector(int det) { if ( det < 1 || kMaxDetector <= det) { COMETSevere("Setting invalid sub-detector value: " << det); } SetField(det,kSubDetMSB,kSubDetLSB); } //---------------------------------------------------------------------- const Bool_t COMET::IChannelId::IsValid() const { if (!(fChannelId & kGuard_Mask)) { COMETSevere("Channel identifier has invalid guard bit"); return false; } int det = GetSubDetector(); if (det < 1 || kMaxDetector <= det) { COMETSevere("Channel identifier has invalid sub-detector: " << det); return false; } return true; } //---------------------------------------------------------------------- const Bool_t COMET::IChannelId::IsCDCChannel() const { return (kCDC == GetSubDetector()); } //---------------------------------------------------------------------- const Bool_t COMET::IChannelId::IsCTHChannel() const { return (kCTH == GetSubDetector()); } //---------------------------------------------------------------------- const Bool_t COMET::IChannelId::IsStrawTrkChannel() const { return (kStrawTrk == GetSubDetector()); } //---------------------------------------------------------------------- const Bool_t COMET::IChannelId::IsECALChannel() const { return (kECAL == GetSubDetector()); } //---------------------------------------------------------------------- const Bool_t COMET::IChannelId::IsTOFChannel() const { return (kTOF == GetSubDetector()); } //---------------------------------------------------------------------- const Bool_t COMET::IChannelId::IsECALTrigChannel() const { return (kECALTrig == GetSubDetector()); } //---------------------------------------------------------------------- std::string COMET::IChannelId::SubDetAsString() const { std::string det = "Unset"; switch (GetSubDetector()) { case kCDC: det = "CDC"; break; case kCTH: det = "CTH"; break; case kECAL: det = "ECAL"; break; case kStrawTrk: det = "StrawTrk"; break; case kTOF: det = "TOF"; break; case kECALTrig: det = "ECALTrig"; break; default: det = "-------"; break; } return det; } //---------------------------------------------------------------------- std::string COMET::IChannelId::AsString() const { if (IsCDCChannel()) { ICDCChannelId cdc(*this); return cdc.AsString(); } if (IsCTHChannel()) { ICTHChannelId cth(*this); return cth.AsString(); } if (IsStrawTrkChannel()) { IStrawTrkChannelId StrawTrk(*this); return StrawTrk.AsString(); } if (IsECALChannel()) { IECALChannelId ECAL(*this); return ECAL.AsString(); } if (IsTOFChannel()) { ITOFChannelId TOF(*this); return TOF.AsString(); } if (IsECALTrigChannel()) { IECALTrigChannelId ECALTrig(*this); return ECALTrig.AsString(); } std::ostringstream buffer; buffer << std::setw(7) << SubDetAsString() << std::setw(8) << std::hex << std::setfill('0') << "0x" << fChannelId; return buffer.str(); }