diff --git a/Database/TPTools/TPTools/ATLAS_CHECK_THREAD_SAFETY b/Database/TPTools/TPTools/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 0000000000000000000000000000000000000000..e355845a305bb1cb9fcc3d082520bd7ad5724861 --- /dev/null +++ b/Database/TPTools/TPTools/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +Database/TPTools diff --git a/Database/TPTools/TPTools/ITPConverter.h b/Database/TPTools/TPTools/ITPConverter.h index 6c9f60d7ffb9d66a5bd446c32ee6b96d41cad8c0..780244d387eba4ad309479ce027637085b06bbe9 100644 --- a/Database/TPTools/TPTools/ITPConverter.h +++ b/Database/TPTools/TPTools/ITPConverter.h @@ -1,7 +1,7 @@ // -*- c++ -*- /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef ATHENAPOOLCNVSVC_ITPConverter_H @@ -54,7 +54,8 @@ public: /** return the top-level converter for this elemental TP converter @return TopLevelTPCnvBas */ - virtual TopLevelTPCnvBase* topConverter() const { return 0; } + virtual TopLevelTPCnvBase* topConverter() { return 0; } + virtual const TopLevelTPCnvBase* topConverter() const { return 0; } /** Return TP typeID for persistent objects produced by this converter @return TPObjRef::typeID_t& diff --git a/Database/TPTools/TPTools/TPConverter.h b/Database/TPTools/TPTools/TPConverter.h index ff437dd31f8d2d70268fde49a8d788f7bf47e8a2..c1acb8fc69454f71e343a08567e265546902a256 100644 --- a/Database/TPTools/TPTools/TPConverter.h +++ b/Database/TPTools/TPTools/TPConverter.h @@ -1,7 +1,7 @@ // dear emacs, this is -*- c++ -*- /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef TPCONVERTER_H @@ -188,7 +188,12 @@ public: /// @copydoc ITPConverter::topConverter() - virtual TopLevelTPCnvBase* topConverter() const { + virtual TopLevelTPCnvBase* topConverter() { + return m_topConverter; + } + + /// @copydoc ITPConverter::topConverter() + virtual const TopLevelTPCnvBase* topConverter() const { return m_topConverter; } diff --git a/Database/TPTools/TPTools/TopLevelTPCnvBase.h b/Database/TPTools/TPTools/TopLevelTPCnvBase.h index d26e43eebcf39e49262d37234573aec7e712a288..d4a03e027bb9d5922e2c2ced5d48d492550cc578 100644 --- a/Database/TPTools/TPTools/TopLevelTPCnvBase.h +++ b/Database/TPTools/TPTools/TopLevelTPCnvBase.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 TPTOPLEVELTPCNVBASE_H @@ -100,7 +100,10 @@ public: virtual bool hasTLPersObject() const = 0; /// @return pointer to the persistent object owned by this converter as @c void* - virtual void* getTLPersObjectAsVoid() const = 0; + virtual void* getTLPersObjectAsVoid() = 0; + + /// @return pointer to the persistent object owned by this converter as @c void* + virtual const void* getTLPersObjectAsVoid() const = 0; /// Create persistent object - the converter keeps it virtual void createTLPersObject() = 0; diff --git a/Database/TPTools/TPTools/TopLevelTPCnvBaseP.h b/Database/TPTools/TPTools/TopLevelTPCnvBaseP.h index 0eb00c251f54733d7d4b3ce6605aed5239d93321..1be59a57d79ee8519d3e2ce25f3b4e15fdfd0503 100644 --- a/Database/TPTools/TPTools/TopLevelTPCnvBaseP.h +++ b/Database/TPTools/TPTools/TopLevelTPCnvBaseP.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef TopLevelTPCnvBaseP_H @@ -49,19 +49,19 @@ public: // --------------- internals - "non-public" use /// @copydoc TopLevelTPCnvBase::hasTLPersObject() - virtual bool hasTLPersObject() const { + virtual bool hasTLPersObject() const override { return m_tlPersObject; } /// @copydoc TopLevelTPCnvBase::createTLPersObject() - virtual void createTLPersObject() { + virtual void createTLPersObject() override { m_tlPersObject = new TL_PERS(); setPStorage( m_tlPersObject ); } /// @copydoc TopLevelTPCnvBase::deleteTLPersObject() // cppcheck-suppress virtualCallInConstructor - virtual void deleteTLPersObject() { + virtual void deleteTLPersObject() override { if( m_tlPersObject ) { delete m_tlPersObject; clearTLPersObject(); @@ -69,7 +69,12 @@ public: } /// @return pointer to the persistent object owned by this converter - TL_PERS* getTLPersObject() const { + TL_PERS* getTLPersObject() { + return m_tlPersObject; + } + + /// @return pointer to the persistent object owned by this converter + const TL_PERS* getTLPersObject() const { return m_tlPersObject; } @@ -81,17 +86,22 @@ public: } /// @copydoc TopLevelTPCnvBase::getTLPersObjectAsVoid() - virtual void* getTLPersObjectAsVoid() const { + virtual void* getTLPersObjectAsVoid() override { + return getTLPersObject(); + } + + /// @copydoc TopLevelTPCnvBase::getTLPersObjectAsVoid() + virtual const void* getTLPersObjectAsVoid() const override { return getTLPersObject(); } /// @copydoc TopLevelTPCnvBase::clearTLPersObject() - virtual void clearTLPersObject() { + virtual void clearTLPersObject() override { m_tlPersObject = 0; } /// @copydoc TopLevelTPCnvBase::setTLPersObject() - virtual void setTLPersObject( void *persObj ) { + virtual void setTLPersObject( void *persObj ) override { if( m_tlPersObject ) delete m_tlPersObject; m_tlPersObject = reinterpret_cast<TL_PERS*>( persObj ); setPStorage( m_tlPersObject ); @@ -99,10 +109,10 @@ public: /// @copydoc TopLevelTPCnvBase::getTokenListVar() - virtual TPCnvTokenList_p1* getTokenListVar() { return 0; } + virtual TPCnvTokenList_p1* getTokenListVar() override { return 0; } /// @copydoc TopLevelTPCnvBase::getTokenListVarFrom() - virtual TPCnvTokenList_p1* getTokenListVarFrom( void *persObj ) { + virtual TPCnvTokenList_p1* getTokenListVarFrom( void *persObj ) override { // avoid setting up the pointer to persistent object // (can lead to deleting it twice, if the user deletes too) TL_PERS *tmp = m_tlPersObject; diff --git a/Database/TPTools/TPTools/TopLevelTPConverter.h b/Database/TPTools/TPTools/TopLevelTPConverter.h index fcca61c78ef878b0e76616cf36f21b40bae2f458..65573313ffc5b424b2821bd3ff46581aaf95a8c1 100644 --- a/Database/TPTools/TPTools/TopLevelTPConverter.h +++ b/Database/TPTools/TPTools/TopLevelTPConverter.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef TOPLEVELTPCONVERTER_H @@ -12,6 +12,7 @@ #include "TopLevelTPCnvBaseP.h" #include "TPConverter.h" +#include "CxxUtils/checker_macros.h" /** @class TopLevelTPConverter @@ -93,7 +94,11 @@ public: @return TRANS* transient object passed by a pointer */ virtual TRANS* createTransient(const TL_PERS* persObj, MsgStream &log) { - setPStorage( const_cast<TL_PERS*>(persObj) ); + // FIXME: TPConverter uses the same non-const member m_pStorage + // for both reading and writing, but we want it to be const + // in the former case. + TL_PERS* pers_nc ATLAS_THREAD_SAFE = const_cast<TL_PERS*>(persObj); + setPStorage( pers_nc ); return createTransient( log ); } @@ -194,7 +199,11 @@ public: // ---------------------- methods used by T_TPCnv<> converters virtual void persToTrans (const PERS* pers, TRANS* trans, MsgStream& msg) { - setPStorage (const_cast<TL_PERS*> (pers)); + // FIXME: TPConverter uses the same non-const member m_pStorage + // for both reading and writing, but we want it to be const + // in the former case. + TL_PERS* pers_nc ATLAS_THREAD_SAFE = const_cast<TL_PERS*>(pers); + setPStorage( pers_nc ); m_mainConverter.pstoreToTrans (0, trans, msg); } diff --git a/Database/TPTools/src/ITPConverter.cxx b/Database/TPTools/src/ITPConverter.cxx index fe361f969750cc7846ee98f136c2052ab8031125..474f73529228f51a1cc28fc014e7294753e3fb84 100644 --- a/Database/TPTools/src/ITPConverter.cxx +++ b/Database/TPTools/src/ITPConverter.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ @@ -10,9 +10,9 @@ static void errorHandler() { - static const char *ignore_error = getenv("ATHENA_TP_IGNORE_NOT_FOUND"); + static const char *const ignore_error = getenv("ATHENA_TP_IGNORE_NOT_FOUND"); if( ignore_error ) return; - static const char *do_abort = getenv("ATHENA_TP_DIE_ON_NOT_FOUND"); + static const char * const do_abort = getenv("ATHENA_TP_DIE_ON_NOT_FOUND"); if( do_abort ) abort(); throw std::runtime_error( "TP converter not found" ); }