16#include "GaudiKernel/EventContext.h"
17#include "GaudiKernel/ServiceHandle.h"
19#include <unordered_set>
29#define USE_ASYNC_TASK 0
49 {
parent(),
"RingSize", 100,
50 "Number of previous events for which to remember IOV history." };
55 {
parent(),
"CleanDelay", 100,
56 "Number of events after adding a conditions object we try to clean its container." };
60 {
parent(),
"LookAhead", 10,
61 "Maximum number of events to consolodate together when cleaning." };
67 {
parent(),
"Async",
false,
68 "If true, run cleaning asynchronously in an MT job." };
75 {
parent(),
"RCUSvc",
"Athena::RCUSvc",
84class DelayedConditionsCleanerTask
95 DelayedConditionsCleanerTask (DelayedConditionsCleanerSvc& cleaner,
96 std::vector<DelayedConditionsCleanerSvc::CondContInfo*>&& cis,
97 DelayedConditionsCleanerSvc::twoKeys_t&& keys);
102 tbb::task* execute()
override;
107 DelayedConditionsCleanerSvc& m_cleaner;
110 std::vector<DelayedConditionsCleanerSvc::CondContInfo*> m_cis;
113 DelayedConditionsCleanerSvc::twoKeys_t m_keys;
123DelayedConditionsCleanerTask::DelayedConditionsCleanerTask
125 std::vector<DelayedConditionsCleanerSvc::CondContInfo*>&& cis,
127 : m_cleaner (cleaner),
137tbb::task* DelayedConditionsCleanerTask::execute()
140 m_cleaner.cleanContainers (std::move (m_cis), std::move (m_keys));
143 --m_cleaner.m_cleanTasks;
156 : base_class (name, svc),
172 size_t nslots =
m_props->m_rcu->getNumSlots();
176 return StatusCode::SUCCESS;
195 EventContext::ContextID_t slot = ctx.slot();
196 if (slot != EventContext::INVALID_CONTEXT_ID) {
205 return StatusCode::SUCCESS;
209 std::vector<CondContInfo*> ci_vec;
213 if (!
m_work.empty() &&
m_work.top().m_evt <= ctx.evt()) {
225 case KeyType::SINGLE:
227 case KeyType::RUNLBN:
229 case KeyType::TIMESTAMP:
230 ci_vec.push_back (ci);
242 if (!ci_vec.empty()) {
246 return StatusCode::SUCCESS;
260 CCInfoMap_t::iterator it =
m_ccinfo.find (&cc);
265 EventContext::ContextEvt_t evt = ctx.evt();
267 return StatusCode::SUCCESS;
280 return StatusCode::SUCCESS;
286 ATH_MSG_INFO(
" Avg size: {:.2f} / Avg removed: {:.2f}",
290 std::vector<const CondContInfo*> infos;
292 infos.push_back (&p.second);
296 { return a->m_cc.id().key() < b->m_cc.id().key(); });
300 ci->m_cc.id().key().c_str(),
302 ci->m_cc.maxSize() );
303 den = std::max (ci->m_nClean, 1lu);
304 ATH_MSG_INFO(
" nClean {} avgRemoved {:.2f} 0/1/2+ {}/{}/{}",
306 static_cast<float> (ci->m_nRemoved) / den,
309 ci->m_removed2plus );
312 return StatusCode::SUCCESS;
329 std::priority_queue<QueueItem> tmp;
338 return StatusCode::SUCCESS;
346 std::vector<key_type> runLBKeys=runLBRing.
getKeysDedup();
357 twoKeys_t result{std::move(runLBKeys), std::move(TSKeys)};
363 for (
auto& keys : result ) {
366 keys.resize (end - keys.begin());
391 cis.resize (pos - cis.begin());
393 if (allowAsync &&
m_props->m_async) {
401 tbb::task* t =
new (tbb::task::allocate_root())
403 std::move (twoKeys));
404 tbb::task::enqueue (*t);
433 std::vector<CondContInfo*> toclean = std::move (cis);
434 std::unordered_set<CondContInfo*> cleaned (toclean.begin(), toclean.end());
435 while (!toclean.empty()) {
436 std::vector<CondContInfo*> newclean;
440 for (CondContBase* dep : ci->m_cc.getDeps()) {
441 CCInfoMap_t::iterator
it =
m_ccinfo.find (dep);
445 if (cleaned.insert (ci_dep).second) {
446 newclean.push_back (ci_dep);
452 toclean = std::move (newclean);
467 const twoKeys_t& twoKeys)
const
469 size_t n = ci->m_cc.trim (twoKeys[0],twoKeys[1]);
481 ++ci->m_removed2plus;
499 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x,...)
pimpl-style holder for component properties.
Hold mappings of ranges to condition objects.
Clean conditions containers after a delay.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
read-copy-update (RCU) style synchronization for Athena.
DelayedConditionsCleanerSvc * parent()
AthProperties(DelayedConditionsCleanerSvc *parent)
bool m_async
Property: If true, run cleaning asynchronously in an MT job.
Gaudi::Property< size_t > m_cleanDelay
Property: Number of events after adding a conditions object we try to clean its container.
ServiceHandle< Athena::IRCUSvc > m_rcu
Property: RCU Service.
DelayedConditionsCleanerSvcProps(DelayedConditionsCleanerSvc *parent)
Gaudi::Property< size_t > m_ringSize
Property: Number of previous events for which to remember IOV history.
Gaudi::Property< size_t > m_lookAhead
Property: Maximum number of events to consolodate together when cleaning.
Information that we maintain about each conditions container.
CondContBase & m_cc
The conditions container.
Clean conditions containers after a delay.
DelayedConditionsCleanerSvc(const std::string &name, ISvcLocator *svc)
Standard Gaudi constructor.
std::priority_queue< QueueItem > m_work
Priority queue of pending cleaning requests.
size_t m_nEvents
Priority queue statistics.
virtual StatusCode finalize() override
Standard Gaudi finalize method.
friend class DelayedConditionsCleanerTask
twoKeys_t getKeys(const Ring &runLBRing, const Ring &TSRing) const
virtual StatusCode condObjAdded(const EventContext &ctx, CondContBase &cc) override
Called after a conditions object has been added.
virtual StatusCode initialize() override
Standard Gaudi initialize method.
Ring m_runlbn
Two ring buffers for recent IOV keys, one for run+LBN and one for timestamp.
std::vector< key_type > m_slotTimestamp
virtual StatusCode event(const EventContext &ctx, bool allowAsync) override
Called at the start of each event.
void scheduleClean(std::vector< CondContInfo * > &&cis, twoKeys_t &&twoKeys, bool allowAsync)
Do cleaning for a set of containers.
std::unique_ptr< DelayedConditionsCleanerSvcProps > m_props
Component properties.
CxxUtils::Ring< key_type > Ring
Ring buffer holding most recent IOV keys of a given type.
CondContBase::key_type key_type
Packed key type.
std::lock_guard< mutex_t > lock_t
std::atomic< int > m_cleanTasks
Number of active asynchronous cleaning tasks.
virtual StatusCode reset() override
Clear the internal state of the service.
std::array< std::vector< key_type >, 2 > twoKeys_t
void cleanContainers(std::vector< CondContInfo * > &&cis, twoKeys_t &&twoKeys)
Clean a set of containers.
bool cleanContainer(CondContInfo *ci, const twoKeys_t &keys) const
Clean a single container.
std::vector< key_type > m_slotLBN
IOV keys currently in use for each slot.
virtual StatusCode printStats() const override
Print some statistics about the garbage collection.
~DelayedConditionsCleanerSvc()
Standard destructor.
Base class for all conditions containers.
static key_type keyFromTimestamp(const EventIDBase &b)
Make a timestamp key from an EventIDBase.
static key_type keyFromRunLBN(const EventIDBase &b)
Make a run+lbn key from an EventIDBase.
KeyType keyType() const
Return the key type for this container.
std::vector< T > getKeysDedup() const
Return a copy of keys in the buffer.
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
::StatusCode StatusCode
StatusCode definition for legacy code.
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.