#include "IECALChannelMap.hxx" #include "COMETGeomId.hxx" #include "COMETGeomIdDef.hxx" #include "IECALGeomId.hxx" #include "ICOMETLog.hxx" #include #include COMET::IECALChannelMap* COMET::IECALChannelMap::fECALChannelMap = NULL; COMET::IECALChannelMap::IECALChannelMap() { //std::cout << " new channel map" << std::endl; if(fECALChannelMap){ COMETError("ECAL channel map instance already exists," << " cannot change after intialisation"); return; } } COMET::IECALChannelMap::~IECALChannelMap() { delete fECALChannelMap; } //---------------------------------------------------------------------- COMET::IECALChannelMap& COMET::IECALChannelMap::Get() { if(!fECALChannelMap) fECALChannelMap = new IECALChannelMap(); return *fECALChannelMap; } //---------------------------------------------------------------------- bool COMET::IECALChannelMap::GetGeometryId(COMET::IGeometryId& geomId, COMET::IECALChannelId channelId) { if(!channelId.IsECALChannel()){ COMETDebug(channelId << " (" << channelId.AsUInt() << ") doesn'nt belong to ECAL."); return false; } UInt_t block, crystal; if( channelId.GetComponentNumber(block, crystal) ){ // Only the module numbers are set. // "*Wrapper" and "Crystal" are always 1 but APD* are always 0 geomId = COMET::GeomId::ECAL::Module(block, 1, crystal, 1, 1, 1, 0, 0, 0); // Debugging COMETNamedVerbose("IECALChannelMap", std::endl << "\tChanId: " << std::bitset<32>(channelId.AsUInt()) << std::endl << "\tGeomId: " << std::bitset<32>(geomId.AsInt()) << std::endl ); return true; } return false; } //---------------------------------------------------------------------- bool COMET::IECALChannelMap::GetChannelId(COMET::IECALChannelId& channelId, COMET::IGeometryId geomId) { if(! COMET::GeomId::ECAL::IsECAL(geomId)){ COMETDebug(geomId << "(" << geomId.AsInt() << ") doesn't belong to ECAL."); return false; } //-------------------------------------------------------- // Translate geom Id into channel Id //-------------------------------------------------------- Int_t geom = geomId.AsInt(); using namespace COMET::GeomId::Def::ECAL; UInt_t crystal = (geom & kCrystalModuleMask) >> kCrystalModuleLSB; UInt_t block = (geom & kBlockModuleMask) >> kBlockModuleLSB; // Set channel channelId = IECALChannelId(COMET::IChannelId::kECAL, block, crystal); return true; } //---------------------------------------------------------------------- bool COMET::IECALChannelMap::GetChannelId(COMET::IECALTrigChannelId& channelId, COMET::IGeometryId geomId) { IECALChannelId ecalId; bool ret = GetChannelId(ecalId, geomId); if(ret) channelId = ecalId.GetTrigChannelId(); return ret; } //---------------------------------------------------------------------- inline const COMET::IGeometryId COMET::IECALChannelMap::BadGeomId() const { //Construct by hand as we are deliberately creating an invalid id //0x80000000 guard bit (Invalid => high) //0x7E000000 sub-det specifier range (FGD => normally 0x3) //so 0x86000000 == invalid-geomID in FGD range //0x01FFFFFF sub detector use range (25 bits) //Set all these high: 0x1FFFFFF return IGeometryId(0x87FFFFFF); // == 0x86000000 | 0x01FFFFFF; } //---------------------------------------------------------------------- inline const COMET::IECALChannelId COMET::IECALChannelMap::BadChanId() const { //Construct by hand as we are deliberately creating an invalid id //0x80000000 guard bit (Invalid => low) //0x7E000000 sub-det specifier range (FGD => normally 0x3) //so 0x06000000 == invalid-chanID in FGD range //0x01FFFFFF sub detector use range (25 bits) //Set all these high: 0x1FFFFFF return IECALChannelId(0x07FFFFFF); // == 0x06000000 | 0x01000000 }