diff --git a/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/CMakeLists.txt b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/CMakeLists.txt index e86580b4de7cbf8e5175d2d6b6b21185df2764ae..5c04aa542f3c53cf97dfc36711a997730bbcdebf 100644 --- a/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/CMakeLists.txt +++ b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/CMakeLists.txt @@ -12,6 +12,8 @@ atlas_depends_on_subdirs( PUBLIC Event/ByteStreamData InnerDetector/InDetRawEvent/InDetRawData PRIVATE + Control/AthenaKernel + Control/CxxUtils Control/StoreGate Database/AthenaPOOL/AthenaPoolUtilities Event/ByteStreamCnvSvcBase @@ -37,7 +39,7 @@ atlas_add_component( TRT_RawDataByteStreamCnv src/*.cxx src/components/*.cxx INCLUDE_DIRS ${CORAL_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} ${TDAQ-COMMON_INCLUDE_DIRS} - LINK_LIBRARIES ${CORAL_LIBRARIES} ${ROOT_LIBRARIES} ${COOL_LIBRARIES} ${TDAQ-COMMON_LIBRARIES} AthenaBaseComps Identifier ByteStreamData ByteStreamData_test InDetRawData StoreGateLib SGtests AthenaPoolUtilities ByteStreamCnvSvcBaseLib GaudiKernel TRT_ConditionsServicesLib InDetIdentifier InDetReadoutGeometry TRT_ReadoutGeometry PathResolver IRegionSelector TrigSteeringEvent TRT_CablingLib ) + LINK_LIBRARIES ${CORAL_LIBRARIES} ${ROOT_LIBRARIES} ${COOL_LIBRARIES} ${TDAQ-COMMON_LIBRARIES} AthenaBaseComps Identifier ByteStreamData ByteStreamData_test InDetRawData AthenaKernel CxxUtils StoreGateLib SGtests AthenaPoolUtilities ByteStreamCnvSvcBaseLib GaudiKernel TRT_ConditionsServicesLib InDetIdentifier InDetReadoutGeometry TRT_ReadoutGeometry PathResolver IRegionSelector TrigSteeringEvent TRT_CablingLib ) # Install files from the package: atlas_install_headers( TRT_RawDataByteStreamCnv ) diff --git a/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/TRT_RawDataByteStreamCnv/ATLAS_CHECK_THREAD_SAFETY b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/TRT_RawDataByteStreamCnv/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 0000000000000000000000000000000000000000..a0119e0dee67c295c992fd52f2956d5107540791 --- /dev/null +++ b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/TRT_RawDataByteStreamCnv/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv diff --git a/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.cxx b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.cxx index 8d98a5277484c1aef45af2d0185b963f51b70794..fdbfed9102d96b6550abbeb799d3ab4d85ec9be6 100644 --- a/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.cxx +++ b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.cxx @@ -248,10 +248,11 @@ StatusCode TRT_RodDecoder::finalize() { * ---------------------------------------------------------- */ StatusCode -TRT_RodDecoder::fillCollection ( const ROBFragment* robFrag, +TRT_RodDecoder::fillCollection ATLAS_NOT_THREAD_SAFE ( const ROBFragment* robFrag, TRT_RDO_Container* rdoIdc, TRT_BSErrContainer* bsErr, const std::vector<IdentifierHash>* vecHash ) +// Non-thread-safe function 'StatusCode TRT_RodDecoder::update()' called { std::lock_guard<std::mutex> lock(m_cacheMutex); @@ -271,8 +272,6 @@ TRT_RodDecoder::fillCollection ( const ROBFragment* robFrag, // << robid << " L1ID = " << robFrag->rod_lvl1_id() // << MSG::dec ); - static int err_count = 0; - /* * Save non-zero rob status to TRT BS Conditions Services */ @@ -292,14 +291,19 @@ TRT_RodDecoder::fillCollection ( const ROBFragment* robFrag, * This is a hack to only print once per event. It will work the * vast majority of the time, but it may miss an occasional event. */ - static uint32_t Last_print_L1ID = 0xffffffff; - static uint32_t Last_print_BCID = 0xffffffff; - if ( (Last_print_L1ID != robFrag->rod_lvl1_id()) || - (Last_print_BCID != robFrag->rod_bc_id()) ) + const EventContext& ctx{Gaudi::Hive::currentContext()}; + CacheEntry* ent{m_cache.get(ctx)}; + if (ent->m_evt!=ctx.evt()) { // New event in this slot + ent->reset(); + ent->m_evt = ctx.evt(); + } + + if ( (ent->Last_print_L1ID != robFrag->rod_lvl1_id()) || + (ent->Last_print_BCID != robFrag->rod_bc_id()) ) { - Last_print_L1ID = robFrag->rod_lvl1_id(); - Last_print_BCID = robFrag->rod_bc_id(); + ent->Last_print_L1ID = robFrag->rod_lvl1_id(); + ent->Last_print_BCID = robFrag->rod_bc_id(); ATH_MSG_INFO( "Non-Zero ROB status word for ROB " << MSG::hex @@ -324,18 +328,18 @@ TRT_RodDecoder::fillCollection ( const ROBFragment* robFrag, vecHash ); else { - if ( err_count < 100 ) + if ( m_err_count_fillCollection < 100 ) { ATH_MSG_WARNING( "Rod Version: " << RodBlockVersion \ << ", but Compression Table not loaded! ROD ID = " \ << MSG::hex << robid << MSG::dec ); - err_count++; + m_err_count_fillCollection++; } - else if ( 100 == err_count ) + else if ( 100 == m_err_count_fillCollection ) { ATH_MSG_WARNING( "Too many Rod Version messages. " \ << "Turning message off." ); - err_count++; + m_err_count_fillCollection++; } sc = StatusCode::FAILURE; @@ -707,8 +711,6 @@ TRT_RodDecoder::int_fillMinimalCompress( const ROBFragment *robFrag, TRT_RDO_Container* rdoIdc, const std::vector<IdentifierHash>* vecHash) { - static int err_count = 0; - uint32_t robid = robFrag->rod_source_id(); // get the ROD version. It could be used to decode the data in one @@ -775,14 +777,14 @@ TRT_RodDecoder::int_fillMinimalCompress( const ROBFragment *robFrag, // ATH_MSG_WARNING( "vint[" << in_ptr << "] = " << MSG::hex << vint[in_ptr] << MSG::dec ); } if ( v ) { - if ( err_count < 100 ) { + if ( m_err_count_int_fillMinimalCompress < 100 ) { ATH_MSG_WARNING( "Invalid ByteStream, ROD ID = " \ << MSG::hex << robid << MSG::dec ); - err_count++; - } else if ( 100 == err_count ) { + m_err_count_int_fillMinimalCompress++; + } else if ( 100 == m_err_count_int_fillMinimalCompress ) { ATH_MSG_WARNING( "Too many Invalid ByteStream messages " \ << "Turning message off." ); - err_count++; + m_err_count_int_fillMinimalCompress++; } return StatusCode::RECOVERABLE; } @@ -938,8 +940,6 @@ TRT_RodDecoder::int_fillFullCompress( const ROBFragment *robFrag, t_CompressTable* Ctable, const std::vector<IdentifierHash>* vecHash) { - static int err_count = 0; - int phase; for ( phase=0; phase<2; phase++ ) { @@ -1033,17 +1033,17 @@ TRT_RodDecoder::int_fillFullCompress( const ROBFragment *robFrag, word = Ctable->m_syms[idx]; else { - if ( err_count < 100 ) + if ( m_err_count_int_fillFullCompress < 100 ) { ATH_MSG_WARNING( "Invalid ByteStream, ROD ID = " \ << MSG::hex << robid << MSG::dec ); - err_count++; + m_err_count_int_fillFullCompress++; } - else if ( 100 == err_count ) + else if ( 100 == m_err_count_int_fillFullCompress ) { ATH_MSG_WARNING( "Too many Invalid ByteStream messages " \ << "Turning message off." ); - err_count++; + m_err_count_int_fillFullCompress++; } return StatusCode::RECOVERABLE; @@ -1700,7 +1700,8 @@ TableFilename * Read Compression Table from DB on IOV change */ StatusCode -TRT_RodDecoder::update() +TRT_RodDecoder::update ATLAS_NOT_THREAD_SAFE () +// Non-thread-safe function 'AthenaAttributeList::AthenaAttributeList(const coral::AttributeList&)' called { /* diff --git a/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.h b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.h index 9d7103b9527732130ed046b74fd677d6e7a89217..0a0d47657d6584da455bc365c9f182c2606f145c 100644 --- a/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.h +++ b/InnerDetector/InDetEventCnv/TRT_RawDataByteStreamCnv/src/TRT_RodDecoder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef TRT_RAWDATABYTESTREAM_TRT_RODDECODER_H @@ -61,12 +61,19 @@ */ #include "InDetIdentifier/TRT_ID.h" +/* + * For cache + */ +#include "AthenaKernel/SlotSpecificObj.h" +#include "CxxUtils/checker_macros.h" + /* * STL */ -#include <vector> +#include <atomic> #include <map> - +#include <mutex> +#include <vector> // the tool to decode a ROB frament @@ -155,6 +162,10 @@ public: uint32_t m_Nrdos; // Number of RDOs created + mutable std::atomic<int> m_err_count_fillCollection{0}; + mutable std::atomic<int> m_err_count_int_fillMinimalCompress{0}; + mutable std::atomic<int> m_err_count_int_fillFullCompress{0}; + // This replaces the IOVCALLBACK SG::ReadCondHandleKey<CondAttrListCollection> m_CompressKey{this,"keyName","/TRT/Onl/ROD/Compress","in-key"}; mutable std::mutex m_cacheMutex; @@ -178,7 +189,19 @@ private: StatusCode ReadCompressTableFile( std::string TableFilename ); StatusCode ReadCompressTableDB( std::string Tag ); - + + // Struct for event cache + struct CacheEntry { + EventContext::ContextEvt_t m_evt{EventContext::INVALID_CONTEXT_EVT}; + uint32_t Last_print_L1ID = 0xffffffff; + uint32_t Last_print_BCID = 0xffffffff; + void reset() { + Last_print_L1ID = 0xffffffff; + Last_print_BCID = 0xffffffff; + } + }; + mutable SG::SlotSpecificObj<CacheEntry> m_cache ATLAS_THREAD_SAFE; // Guarded by m_cacheMutex + }; #endif