diff --git a/Event/EventContainers/EventContainers/I_InternalIDC.h b/Event/EventContainers/EventContainers/I_InternalIDC.h index c336d4b964b0e4e5b47e9862b9aff113f065b705..71d7a0f2550d103ec661fa52e21ebe7174ca1398 100644 --- a/Event/EventContainers/EventContainers/I_InternalIDC.h +++ b/Event/EventContainers/EventContainers/I_InternalIDC.h @@ -8,7 +8,6 @@ #include "Identifier/IdentifierHash.h" #include "GaudiKernel/StatusCode.h" #include <vector> -#include <utility> namespace EventContainers{ class IDC_WriteHandleBase; @@ -22,9 +21,19 @@ virtualised. A standard iterator is provided for fast iteration in a sequential order. */ +template<typename T> +struct hashPair{ + IdentifierHash::value_type first; + const T* second; + constexpr hashPair(IdentifierHash::value_type f, const T* s) : first(f), second(s) { } + bool operator <(const hashPair &b) const noexcept{ + return first < b.first; + } +}; + class I_InternalIDC{ public: - typedef std::pair < IdentifierHash::value_type, const void* > hashPair; + typedef EventContainers::hashPair<void> hashPair; typedef std::vector < hashPair >::const_iterator InternalConstItr; #include "EventContainers/deleter.h" virtual InternalConstItr cbegin() const=0; diff --git a/Event/EventContainers/EventContainers/IdentifiableContainerMT.h b/Event/EventContainers/EventContainers/IdentifiableContainerMT.h index b2fbf7afa34b74fb226159338f4f9fe8a6cbc0e3..35174e751c92bd268998a66c3cc52a03b3bb99a1 100644 --- a/Event/EventContainers/EventContainers/IdentifiableContainerMT.h +++ b/Event/EventContainers/EventContainers/IdentifiableContainerMT.h @@ -215,9 +215,10 @@ public: return IdentifiableContainerBase::numberOfCollections(); } - const std::vector < std::pair<IdentifierHash::value_type, const T*> >& GetAllHashPtrPair() const{ + const std::vector < EventContainers::hashPair<T> >& GetAllHashPtrPair() const{ static_assert(sizeof(const T*) == sizeof(const void*) && std::is_pointer<const T*>::value); - return reinterpret_cast<const std::vector < std::pair<IdentifierHash::value_type, const T*> >&> + static_assert(sizeof(EventContainers::hashPair<T>) == sizeof(EventContainers::hashPair<void>)); + return reinterpret_cast<const std::vector < EventContainers::hashPair<T> >&> (m_link->getAllHashPtrPair()); } diff --git a/Event/EventContainers/EventContainers/InternalOffline.h b/Event/EventContainers/EventContainers/InternalOffline.h index ed8e2d9d28c3dae0a9d0a7adebce2333a4d4e3a5..e9ee8e106d8ab71512f7f901b83ed67e5d8c31a1 100644 --- a/Event/EventContainers/EventContainers/InternalOffline.h +++ b/Event/EventContainers/EventContainers/InternalOffline.h @@ -38,7 +38,7 @@ public: virtual void* removeCollection( IdentifierHash hashId ) override; virtual void destructor(deleter_f*) noexcept override; private: - std::vector<std::pair<IdentifierHash::value_type, const void*>> m_map; + std::vector<I_InternalIDC::hashPair> m_map; size_t m_maximumSize; }; diff --git a/Event/EventContainers/EventContainers/InternalOfflineFast.h b/Event/EventContainers/EventContainers/InternalOfflineFast.h index a78aae631afce51190e2c474bf67bbc1ff7db85c..16cf509c7300bc9e1ddb5b9425b9f7666b74796e 100644 --- a/Event/EventContainers/EventContainers/InternalOfflineFast.h +++ b/Event/EventContainers/EventContainers/InternalOfflineFast.h @@ -39,7 +39,7 @@ public: virtual void* removeCollection( IdentifierHash hashId ) override; virtual void destructor(deleter_f*) noexcept override; private: - mutable std::vector<std::pair<IdentifierHash::value_type, const void*>> m_map; + mutable std::vector<I_InternalIDC::hashPair> m_map; std::vector<const void*> m_fullMap; mutable std::mutex m_waitMutex ATLAS_THREAD_SAFE; mutable std::atomic<bool> m_needsupdate ATLAS_THREAD_SAFE; //These mutables are carefully thought out, do not change diff --git a/Event/EventContainers/EventContainers/InternalOfflineMap.h b/Event/EventContainers/EventContainers/InternalOfflineMap.h index d101cef3f561931d93290193bd5472553472e249..dbd9b57180f08f80783eb6b7a168cd1fb6bb7edc 100644 --- a/Event/EventContainers/EventContainers/InternalOfflineMap.h +++ b/Event/EventContainers/EventContainers/InternalOfflineMap.h @@ -40,7 +40,7 @@ public: virtual void* removeCollection( IdentifierHash hashId ) override; virtual void destructor(deleter_f*) noexcept override; private: - mutable std::vector<std::pair<IdentifierHash::value_type, const void*>> m_map; + mutable std::vector<I_InternalIDC::hashPair> m_map; std::unordered_map<IdentifierHash::value_type, const void*> m_fullMap; mutable std::mutex m_waitMutex ATLAS_THREAD_SAFE; mutable std::atomic<bool> m_needsupdate ATLAS_THREAD_SAFE; //These mutables are carefully thought out, do not change diff --git a/Event/EventContainers/EventContainers/InternalOnline.h b/Event/EventContainers/EventContainers/InternalOnline.h index aa90b41816b3bac1d250e42651792e9f91043731..219b902295291b3a52de58d023f5450c2016a3fe 100644 --- a/Event/EventContainers/EventContainers/InternalOnline.h +++ b/Event/EventContainers/EventContainers/InternalOnline.h @@ -49,7 +49,7 @@ public: private: EventContainers::IdentifiableCacheBase *m_cacheLink; mutable std::vector< IdentifierHash > m_waitlist ATLAS_THREAD_SAFE; - mutable std::vector<std::pair<IdentifierHash::value_type, const void*>> m_map ATLAS_THREAD_SAFE; + mutable std::vector<I_InternalIDC::hashPair> m_map ATLAS_THREAD_SAFE; mutable std::mutex m_waitMutex ATLAS_THREAD_SAFE; mutable std::vector<bool> m_mask ATLAS_THREAD_SAFE; mutable std::atomic<bool> m_waitNeeded ATLAS_THREAD_SAFE; //These mutables are carefully thought out, do not change diff --git a/Event/EventContainers/src/InternalOffline.cxx b/Event/EventContainers/src/InternalOffline.cxx index 85165e6ff305e3ad6bb196244d85335970d82b25..c3acec4f8764dccf82729716d3069a502347e925 100644 --- a/Event/EventContainers/src/InternalOffline.cxx +++ b/Event/EventContainers/src/InternalOffline.cxx @@ -9,7 +9,13 @@ using namespace EventContainers; typedef I_InternalIDC::InternalConstItr InternalConstItr; -InternalOffline::InternalOffline(size_t max) : m_maximumSize(max) {} +InternalOffline::InternalOffline(size_t max) : m_maximumSize(max) { + //Check optimization assumptions + static_assert(std::is_trivially_copyable<hashPair>::value); + static_assert(std::is_trivially_destructible<hashPair>::value); + static_assert(std::is_trivially_copyable<IdentifierHash>::value); + static_assert(std::is_trivially_destructible<IdentifierHash>::value); +} bool InternalOffline::tryAddFromCache(IdentifierHash hash, EventContainers::IDC_WriteHandleBase&) {