From a47a862cd68ffb8cfeb651bc212646294eb1629c Mon Sep 17 00:00:00 2001 From: abarton Date: Wed, 30 Oct 2019 18:22:25 +0000 Subject: [PATCH 1/4] First Version of IdentifiableValueContainers --- .../EventContainers/IdentifiableCache.h | 4 +- .../EventContainers/IdentifiableValueCache.h | 56 +++++++++++++ .../IdentifiableValueContainer.h | 79 +++++++++++++++++++ 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 Event/EventContainers/EventContainers/IdentifiableValueCache.h create mode 100644 Event/EventContainers/EventContainers/IdentifiableValueContainer.h diff --git a/Event/EventContainers/EventContainers/IdentifiableCache.h b/Event/EventContainers/EventContainers/IdentifiableCache.h index e1c805941ef..dafdac5c87f 100644 --- a/Event/EventContainers/EventContainers/IdentifiableCache.h +++ b/Event/EventContainers/EventContainers/IdentifiableCache.h @@ -45,8 +45,8 @@ public: { } - IdentifiableCache (IdentifierHash maxHash, const Maker* maker, size_t /*lockBucketSize*/) - : IdentifiableCacheBase (maxHash, maker) + IdentifiableCache (IdentifierHash maxHash, const Maker* maker, size_t lockBucketSize) + : IdentifiableCacheBase (maxHash, maker, lockBucketSize) { } diff --git a/Event/EventContainers/EventContainers/IdentifiableValueCache.h b/Event/EventContainers/EventContainers/IdentifiableValueCache.h new file mode 100644 index 00000000000..c764683e0ee --- /dev/null +++ b/Event/EventContainers/EventContainers/IdentifiableValueCache.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTCONTAINERS_IDENTIFIABLEVALUECACHE_H +#define EVENTCONTAINERS_IDENTIFIABLEVALUECACHE_H + +#include +#include + + + +template +class IdentifiableValueCache{ + +public: + static constexpr T emptyValue() { + return EMPTYVALUE; + } + + IdentifiableValueCache(const IdentifiableValueCache&) = delete; + IdentifiableValueCache(size_t maxSize) + : m_vec(maxSize) + { + for(auto &x : m_vec) x.store(emptyValue(), std::memory_order_relaxed); + } + + void forceReset(){ + for(auto &x : m_vec) x.store(emptyValue(), std::memory_order_relaxed); + } + + size_t maxSize() const { return m_vec.size(); } + + ~IdentifiableValueCache() = default; + + T retrieve(size_t i){ + return m_vec.at(i).load(); + } + + bool present(size_t i){ + return m_vec.at(i).load() != emptyValue(); + } + + bool setOrDrop(size_t i, const T &value){ + T val = emptyValue(); + return m_vec.at(i).compare_exchange_strong(val, value); + } + + const std::vector>& rawReadAccess() const { return m_vec; } + +private: + std::vector> m_vec; + +}; + +#endif diff --git a/Event/EventContainers/EventContainers/IdentifiableValueContainer.h b/Event/EventContainers/EventContainers/IdentifiableValueContainer.h new file mode 100644 index 00000000000..4d8b1a000c5 --- /dev/null +++ b/Event/EventContainers/EventContainers/IdentifiableValueContainer.h @@ -0,0 +1,79 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTCONTAINERS_IDENTIFIABLECVALUEONTAINER_H +#define EVENTCONTAINERS_IDENTIFIABLEVALUECONTAINER_H + +#include "EventContainers/IdentifiableValueCache.h" + +template +class IdentifiableValueContainer{ + +public: + + static constexpr T emptyValue() { + return EMPTYVALUE; + } + + IdentifiableValueContainer(const IdentifiableValueContainer&) = delete; + + ~IdentifiableValueContainer() { if(m_own) delete m_cache; } + IdentifiableValueContainer(size_t maxSize) : m_mask(maxSize, false), m_own(true) + { + m_cache = new IdentifiableValueCache(maxSize); + } + + IdentifiableValueContainer(IdentifiableValueCache *ptr) : m_mask(ptr->maxSize()), + m_cache(ptr), m_own(false) + {} + + bool present(size_t i) const + { + return m_mask.at(i); + } + + bool setOrDrop(size_t i, const T &value){ + bool b = m_cache->setOrDrop(i, value); + m_mask[i] = true; + return b; + } + + size_t maxSize() const { return m_mask.size(); } + + size_t numberSet() const{ + size_t count = 0; + for(bool b : m_mask) count += b; + return count; + } + + bool tryAddFromCache(size_t i){ + if(i >= m_mask.size()) return false; + bool b = m_cache->present(i); + m_mask[i] = b; + return b; + } + + T retrieve(size_t i) const{ + if(m_mask[i]) return m_cache->retrieve(i); + else return emptyValue(); + } + + std::vector> getAll() const{ + std::vector> list; + const auto& raw = m_cache->rawReadAccess(); + for(size_t i =0; i>& wholeEventReadAccess() const { return m_cache->rawReadAccess(); } + +private: + std::vector m_mask; + IdentifiableValueCache *m_cache; + bool m_own; +}; + +#endif \ No newline at end of file -- GitLab From e17f5e33b531ea12d3f53d43520eac0c6654dfb2 Mon Sep 17 00:00:00 2001 From: abarton Date: Thu, 31 Oct 2019 11:32:14 +0000 Subject: [PATCH 2/4] Add test program for IDCValue --- Event/EventContainers/CMakeLists.txt | 5 +++ Event/EventContainers/share/IDCValueTest.ref | 2 + Event/EventContainers/test/IDCValueTest.cxx | 44 ++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 Event/EventContainers/share/IDCValueTest.ref create mode 100644 Event/EventContainers/test/IDCValueTest.cxx diff --git a/Event/EventContainers/CMakeLists.txt b/Event/EventContainers/CMakeLists.txt index c65a935b9a0..a78bf3a7d82 100644 --- a/Event/EventContainers/CMakeLists.txt +++ b/Event/EventContainers/CMakeLists.txt @@ -34,3 +34,8 @@ atlas_add_test( IDStressTest SOURCES test/IDC_Realistic_Test.cxx LINK_LIBRARIES Identifier AthenaKernel GaudiKernel EventContainers EXTRA_PATTERNS "elapsed|^no lock time|^deleted|^countHit|^lock time" ) +atlas_add_test( IDCValueTest SOURCES test/IDCValueTest.cxx + INCLUDE_DIRS src test EventContainers + LINK_LIBRARIES Identifier AthenaKernel GaudiKernel EventContainers + EXTRA_PATTERNS "" + ) \ No newline at end of file diff --git a/Event/EventContainers/share/IDCValueTest.ref b/Event/EventContainers/share/IDCValueTest.ref new file mode 100644 index 00000000000..1a2c5e2c1a5 --- /dev/null +++ b/Event/EventContainers/share/IDCValueTest.ref @@ -0,0 +1,2 @@ +Threw exception correctly +Completed - no errors diff --git a/Event/EventContainers/test/IDCValueTest.cxx b/Event/EventContainers/test/IDCValueTest.cxx new file mode 100644 index 00000000000..c7b908d8f0c --- /dev/null +++ b/Event/EventContainers/test/IDCValueTest.cxx @@ -0,0 +1,44 @@ + +#include "EventContainers/IdentifiableValueContainer.h" + +#include +#include +#include + +typedef IdentifiableValueCache::min()> int100cache; +typedef IdentifiableValueContainer::min()> int100container; + +int main(){ + auto *cache = new int100cache(100); + auto *container = new int100container(cache); + auto *container2 = new int100container(cache); + static_assert(cache->emptyValue() == std::numeric_limits::min()); + if(container->maxSize()!= 100) std::abort(); + if(!container->setOrDrop(50, 29)) std::abort(); + if(!container->setOrDrop(51, -29)) std::abort(); + if(!container->setOrDrop(52, -9)) std::abort(); + if(container->setOrDrop(52, 10) == true) std::abort(); //check if repeated setting passes + if(container->retrieve(52) != -9) std::abort(); + + if(container->present(50)==false || container->present(51)==false || container->present(52)==false) std::abort(); + if(container2->tryAddFromCache(50) == false) std::abort(); + if(container2->getAll().size()!= 1) std::abort(); + if(container->getAll().size()!= 3) std::abort(); + if(container2->retrieve(50) != 29) std::abort(); + if(container2->present(51) == true) std::abort(); + if(container2->retrieve(51) != container2->emptyValue()) std::abort(); + bool except =false; + try{ + container->setOrDrop(150, -29); + }catch(const std::out_of_range& ex) + { + except = true; + std::cout << "Threw exception correctly" << std::endl; + } + if(except == false) std::abort(); + delete container2; + delete container; + delete cache; + std::cout << "Completed - no errors" << std::endl; + return 0; +} \ No newline at end of file -- GitLab From c59048a48d60b15c1384c372ff6133941c1b2ee4 Mon Sep 17 00:00:00 2001 From: abarton Date: Thu, 31 Oct 2019 11:32:54 +0000 Subject: [PATCH 3/4] Remove unnecessary virtual --- Event/EventContainers/EventContainers/IdentifiableContainerMT.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Event/EventContainers/EventContainers/IdentifiableContainerMT.h b/Event/EventContainers/EventContainers/IdentifiableContainerMT.h index ad26ea3c007..1fd416dd8eb 100644 --- a/Event/EventContainers/EventContainers/IdentifiableContainerMT.h +++ b/Event/EventContainers/EventContainers/IdentifiableContainerMT.h @@ -252,7 +252,7 @@ public: virtual StatusCode addOrDelete(std::unique_ptr, IdentifierHash hashId) override final; ///identical to previous excepts allows counting of deletions - virtual StatusCode addOrDelete(std::unique_ptr, IdentifierHash hashId, bool &deleted); + StatusCode addOrDelete(std::unique_ptr, IdentifierHash hashId, bool &deleted); ///Like the other add methods but optimized for changing from the inprogress state StatusCode addLock(std::unique_ptr ptr, IdentifierHash hashId); -- GitLab From 7b626799213c173dad73c296763fcb6b6fc1cd7b Mon Sep 17 00:00:00 2001 From: Adam Edward Barton Date: Fri, 1 Nov 2019 13:15:25 +0000 Subject: [PATCH 4/4] Update copyright statements --- Event/EventContainers/EventContainers/IdentifiableCache.h | 2 +- Event/EventContainers/test/IDCValueTest.cxx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Event/EventContainers/EventContainers/IdentifiableCache.h b/Event/EventContainers/EventContainers/IdentifiableCache.h index dafdac5c87f..0c0d3aa7d22 100644 --- a/Event/EventContainers/EventContainers/IdentifiableCache.h +++ b/Event/EventContainers/EventContainers/IdentifiableCache.h @@ -1,7 +1,7 @@ // This file's extension implies that it's C, but it's really -*- C++ -*-. /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ // $Id: IdentifiableCache.h 791541 2017-01-09 10:43:53Z smh $ diff --git a/Event/EventContainers/test/IDCValueTest.cxx b/Event/EventContainers/test/IDCValueTest.cxx index c7b908d8f0c..0c223f35b28 100644 --- a/Event/EventContainers/test/IDCValueTest.cxx +++ b/Event/EventContainers/test/IDCValueTest.cxx @@ -1,7 +1,9 @@ - +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ #include "EventContainers/IdentifiableValueContainer.h" -#include +#include #include #include -- GitLab