diff --git a/src/iguana/algorithms/clas12/ZVertexFilter/Algorithm.cc b/src/iguana/algorithms/clas12/ZVertexFilter/Algorithm.cc index d63dcc96..1ff9712f 100644 --- a/src/iguana/algorithms/clas12/ZVertexFilter/Algorithm.cc +++ b/src/iguana/algorithms/clas12/ZVertexFilter/Algorithm.cc @@ -46,6 +46,7 @@ namespace iguana::clas12 { } concurrent_key_t ZVertexFilter::PrepareEvent(int const runnum, concurrent_key_t key) const { + m_log->Trace("calling PrepareEvent({}, {})", runnum, key); if(o_runnum->NeedsHashing()) { std::hash hash_ftn; auto hash_key = hash_ftn(runnum); @@ -53,13 +54,14 @@ namespace iguana::clas12 { Reload(runnum, hash_key); return hash_key; } - if(o_runnum->Load(key) != runnum) + if(o_runnum->IsEmpty() || o_runnum->Load(key) != runnum) Reload(runnum, key); return key; } void ZVertexFilter::Reload(int const runnum, concurrent_key_t key) const { std::lock_guard const lock(m_mutex); // NOTE: be sure to lock successive `ConcurrentParam::Save` calls !!! + m_log->Trace("-> calling Reload({}, {})", runnum, key); o_runnum->Save(runnum, key); o_zcuts->Save(GetOptionVector("cuts", {GetConfig()->InRange("runs", runnum), "cuts"}), key); // FIXME: handle PIDs diff --git a/src/iguana/services/ConcurrentParam.cc b/src/iguana/services/ConcurrentParam.cc index 4674447b..de2349e2 100644 --- a/src/iguana/services/ConcurrentParam.cc +++ b/src/iguana/services/ConcurrentParam.cc @@ -64,6 +64,7 @@ namespace iguana { template void SingleThreadParam::Save(T const& value, concurrent_key_t const key) { + this->m_empty = false; m_value = value; } @@ -71,12 +72,14 @@ namespace iguana { void MemoizedParam::Save(T const& value, concurrent_key_t const key) { std::lock_guard const lock(this->m_mutex); + this->m_empty = false; m_container.insert({key, value}); } template void ThreadPoolParam::Save(T const& value, concurrent_key_t const key) { + this->m_empty = false; throw std::runtime_error("TODO: 'threadpool' model not yet implemented"); } @@ -102,4 +105,24 @@ namespace iguana { throw std::runtime_error("TODO: 'threadpool' model not yet implemented"); } + // ================================================================================== + // GetSize() methods + // ================================================================================== + template + std::size_t SingleThreadParam::GetSize() const + { + return 1; + } + + template + std::size_t MemoizedParam::GetSize() const + { + return m_container.size(); + } + + template + std::size_t ThreadPoolParam::GetSize() const + { + throw std::runtime_error("TODO: 'threadpool' model not yet implemented"); + } } diff --git a/src/iguana/services/ConcurrentParam.h b/src/iguana/services/ConcurrentParam.h index a1653be3..1185d818 100644 --- a/src/iguana/services/ConcurrentParam.h +++ b/src/iguana/services/ConcurrentParam.h @@ -40,6 +40,12 @@ namespace iguana { /// @returns true if hashing is needed bool NeedsHashing() const { return m_needs_hashing; } + /// @returns the size of the internal data storage container + virtual std::size_t GetSize() const = 0; + + /// @returns true if no value has been saved + bool IsEmpty() const { return m_empty; } + protected: /// whether this `ConcurrentParam` needs hashing for calling `::Load` or `::Save` @@ -48,6 +54,9 @@ namespace iguana { /// mutex std::mutex m_mutex; + /// whether this `ConcurrentParam` has something saved + bool m_empty{true}; + }; // ================================================================================== @@ -64,6 +73,7 @@ namespace iguana { T const Load(concurrent_key_t const key = 0) const override; void Save(T const& value, concurrent_key_t const key = 0) override; bool HasKey(concurrent_key_t const key) const override; + std::size_t GetSize() const override; private: T m_value; @@ -86,6 +96,7 @@ namespace iguana { T const Load(concurrent_key_t const key = 0) const override; void Save(T const& value, concurrent_key_t const key = 0) override; bool HasKey(concurrent_key_t const key) const override; + std::size_t GetSize() const override; private: container_t m_container; @@ -109,6 +120,7 @@ namespace iguana { T const Load(concurrent_key_t const key = 0) const override; void Save(T const& value, concurrent_key_t const key = 0) override; bool HasKey(concurrent_key_t const key) const override; + std::size_t GetSize() const override; private: container_t m_container;