diff --git a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibDbCoolStrTool/src/MdtCalibDbCoolStrTool.cxx b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibDbCoolStrTool/src/MdtCalibDbCoolStrTool.cxx index b706960cc7ab8d82ada389fafd9154de1db7f715..6130ec417dae995140e62d9d329e2e6aaa3ad0b9 100644 --- a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibDbCoolStrTool/src/MdtCalibDbCoolStrTool.cxx +++ b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibDbCoolStrTool/src/MdtCalibDbCoolStrTool.cxx @@ -274,12 +274,8 @@ StatusCode MdtCalibDbCoolStrTool::loadTube(IOVSVC_CALLBACK_ARGS) { StatusCode sc = detStore()->retrieve( m_tubeData, m_tubeDataLocation ); if(sc.isSuccess()) { sc = detStore()->removeDataAndProxy( m_tubeData ); - if( msgLvl(MSG::DEBUG) ) { - ATH_MSG_DEBUG( "Tube Collection found " << m_tubeData ); - if(sc.isSuccess()) { - ATH_MSG_DEBUG( "Tube Collection at " << m_tubeData << " removed "); - } - } + ATH_MSG_DEBUG( "Tube Collection found " << m_tubeData ); + if(sc.isSuccess()) ATH_MSG_DEBUG( "Tube Collection at " << m_tubeData << " removed "); } // reinitialize the MdtTubeCalibContainerCollection @@ -353,14 +349,29 @@ StatusCode MdtCalibDbCoolStrTool::loadTube(IOVSVC_CALLBACK_ARGS) { delete [] parameters; // find chamber ID - Identifier chId = m_mdtIdHelper->elementID(name,ieta,iphi); - + bool isValid = true; // the elementID takes a bool pointer to check the validity of the Identifier + Identifier chId = m_mdtIdHelper->elementID(name,ieta,iphi,true,&isValid); + if (!isValid) { + ATH_MSG_WARNING("Element Identifier " << chId.get_compact() << " retrieved for station name " << name << " is not valid, skipping..."); + continue; + } + MuonCalib::MdtTubeCalibContainer *tubes = NULL; // get chamber hash IdentifierHash hash; IdContext idCont = m_mdtIdHelper->module_context(); - m_mdtIdHelper->get_hash( chId , hash, &idCont ); + if (m_mdtIdHelper->get_hash( chId , hash, &idCont )) ATH_MSG_WARNING("Retrieving module hash for Identifier " << chId.get_compact() << " failed"); + + // we have to check whether the retrieved Identifier is valid. The problem is that the is_valid() function of the Identifier class does only check + // for the size of the number, not for the physical validity. The get_detectorElement_hash function of the MuonIdHelper however returns + // an error in case the Identifier is not part of the vector of physically valid Identifiers (the check could also be done using the module hash) + // It is important that the methods from MuonIdHelper are called which are not overwritten by the MdtIdHelper + IdentifierHash detElHash; + if (m_mdtIdHelper->MuonIdHelper::get_detectorElement_hash(chId, detElHash )) { + ATH_MSG_WARNING("Retrieving detector element hash for Identifier " << chId.get_compact() << " failed, thus Identifier is not valid, skipping..."); + continue; + } if( msgLvl(MSG::VERBOSE) ) { ATH_MSG_VERBOSE( "name of chamber is " << pch << " station name is " << name ); @@ -391,7 +402,7 @@ StatusCode MdtCalibDbCoolStrTool::loadTube(IOVSVC_CALLBACK_ARGS) { int ntubesLay = tubes->numTubes(); int size = nml*nlayers*ntubesLay; if(size!=ntubes) { - ATH_MSG_ERROR( "Pre-existing MdtTubeCalibContainer for chamber ID " <<chId<< " size does not match the one found in DB "); + ATH_MSG_ERROR( "Pre-existing MdtTubeCalibContainer for chamber ID " <<chId.get_compact()<< " size (" << size << ") does not match the one found in DB (" << ntubes << ")"); return StatusCode::FAILURE; } diff --git a/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MdtIdHelper.h b/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MdtIdHelper.h index 80d90c2860d40b3e8edfd2a8b4e1dfd6f0fbc336..3c1fd5f5437049c419ae4f7c846daa21ce3d2905 100644 --- a/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MdtIdHelper.h +++ b/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MdtIdHelper.h @@ -212,9 +212,13 @@ CLASS_DEF(MdtIdHelper, 4170, 1) inline Identifier MdtIdHelper::elementID(int stationName, int stationEta, int stationPhi, bool check, bool* isValid) const { + bool val = false; + if (stationName<0) { + if (check && isValid) *isValid = val; + return (Identifier(-1)); + } // pack fields independently Identifier result((Identifier::value_type)0); - bool val = false; m_muon_impl.pack(muon_field_value(),result); m_sta_impl.pack (stationName,result); m_eta_impl.pack (stationEta,result); diff --git a/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MuonIdHelper.h b/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MuonIdHelper.h index 44d38e048e6878bd4f2cfa72e1bd4bae548ea035..3768752ea8f748f714e1e0fcd6d7302b3e7a30e5 100644 --- a/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MuonIdHelper.h +++ b/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/MuonIdHelper.h @@ -605,15 +605,10 @@ inline int MuonIdHelper::technologyIndex(const std::string& name) const /*******************************************************************************/ inline const std::string& MuonIdHelper::stationNameString(const int& index) const { + static std::string name = BAD_NAME; assert ( index >= 0 && index <= stationNameIndexMax() ); - static std::string name; if ( index >= 0 && index <= stationNameIndexMax() ) { - name = m_stationNameVector[index]; - if (name.empty()) { - name = BAD_NAME; - } - } else { - name = BAD_NAME; + if (!m_stationNameVector[index].empty()) name = m_stationNameVector[index]; } return name; } diff --git a/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelper.cxx b/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelper.cxx index 7ab63bc26896d5dd4e4120b44db925203d1212d2..8b3c77aa5cbf85f473fd88d5b969f8b1a6eaec7b 100644 --- a/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelper.cxx +++ b/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelper.cxx @@ -154,57 +154,44 @@ int MuonIdHelper::get_module_hash(const Identifier& id, // by binary search - overwritten in the derived classes IdContext context = module_context(); - int result = 1; - hash_id = 0; + hash_id = UINT_MAX; size_t begin = context.begin_index(); size_t end = context.end_index(); if (0 == begin) { // No hashes yet for ids with prefixes if (m_MODULE_INDEX == end) { - id_vec_it it = std::lower_bound(m_module_vec.begin(), - m_module_vec.end(), - id); - - if (it != m_module_vec.end()) { - hash_id = it - m_module_vec.begin(); - result = 0; - } - else - { - create_mlog(); - (*m_Log)<<MSG::WARNING<< "MuonIdHelper::get_hash(cid,hash,con):hash not OK for collection" << endmsg; - } + id_vec_it it = std::lower_bound(m_module_vec.begin(), m_module_vec.end(), id); + if ((it != m_module_vec.end())&&(*it==id)) { + hash_id = it - m_module_vec.begin(); + return 0; + } } - } - return result; + } + create_mlog(); + (*m_Log)<<MSG::WARNING<< "MuonIdHelper::get_module_hash(): Could not determine hash for identifier " << id.get_compact() << endmsg; + return 1; } int MuonIdHelper::get_detectorElement_hash(const Identifier& id, IdentifierHash& hash_id) const { // by binary search - overwritten in the derived classes - int result = 1; - hash_id = 0; + hash_id = UINT_MAX; IdContext context = detectorElement_context(); size_t begin = context.begin_index(); size_t end = context.end_index(); if ( 0 == begin ) { if (m_DETECTORELEMENT_INDEX == end) { - id_vec_it it = std::lower_bound(m_detectorElement_vec.begin(), - m_detectorElement_vec.end(), - id); - if (it != m_detectorElement_vec.end()) { - hash_id = it - m_detectorElement_vec.begin(); - result = 0; - } - else - { - create_mlog(); - (*m_Log) << MSG::WARNING << "MuonIdHelper::get_hash(cid,hash,con):hash not OK for detector element" << endmsg; - } + id_vec_it it = std::lower_bound(m_detectorElement_vec.begin(), m_detectorElement_vec.end(), id); + if ((it != m_detectorElement_vec.end())&&(*it==id)) { + hash_id = it - m_detectorElement_vec.begin(); + return 0; + } } } - return result; + create_mlog(); + (*m_Log) << MSG::WARNING << "MuonIdHelper::get_detectorElement_hash(): Could not determine hash for identifier " << id.get_compact() << endmsg; + return 1; } int MuonIdHelper::get_channel_hash(const Identifier& id, @@ -324,36 +311,29 @@ MuonIdHelper::get_hash_calc (const Identifier& compact_id, const IdContext* context) const { // Get the hash code from vec (for wafers only). - int result = 1; - hash_id = 0; + hash_id = UINT_MAX; size_t begin = (context) ? context->begin_index(): 0; size_t end = (context) ? context->end_index() : 0; if (0 == begin) { // No hashes yet for ids with prefixes if (m_MODULE_INDEX == end) { - result = get_module_hash(compact_id, hash_id); + return get_module_hash(compact_id, hash_id); } else if (m_DETECTORELEMENT_INDEX == end) { - result = get_detectorElement_hash(compact_id, hash_id); + return get_detectorElement_hash(compact_id, hash_id); } else if (m_CHANNEL_INDEX == end) { - id_vec_it it = std::lower_bound(m_channel_vec.begin(), - m_channel_vec.end(), - compact_id); - - if (it != m_channel_vec.end()) { - hash_id = it - m_channel_vec.begin(); - result = 0; - } - else - { - create_mlog(); - (*m_Log) << MSG::WARNING << "MuonIdHelper::get_hash(cid,hash,con):hash not OK for channel" << endmsg; - } + id_vec_it it = std::lower_bound(m_channel_vec.begin(), m_channel_vec.end(), compact_id); + if ((it != m_channel_vec.end())&&(*it==compact_id)) { + hash_id = it - m_channel_vec.begin(); + return 0; + } } } - return (result); + create_mlog(); + (*m_Log) << MSG::WARNING << "MuonIdHelper::get_hash_calc(): Could not determine hash for identifier " << compact_id.get_compact() << endmsg; + return 1; } int MuonIdHelper::initLevelsFromDict() {