ATLAS Offline Software
Loading...
Searching...
No Matches
DelayedConditionsCleanerSvc.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4*/
11
12
13#ifndef ATHENASERVICES_DELAYEDCONDITIONSCLEANERTOOLSVC_H
14#define ATHENASERVICES_DELAYEDCONDITIONSCLEANERTOOLSVC_H
15
16
19#include "CxxUtils/Ring.h"
20#include <queue>
21#include <mutex>
22#include <cstdint>
23#include <atomic>
24#include <unordered_map>
25
26
27namespace Athena {
28
29
30class DelayedConditionsCleanerTask;
32
33
58 : public extends<AthService, IConditionsCleanerSvc>
59{
60public:
63
64
70 DelayedConditionsCleanerSvc (const std::string& name, ISvcLocator* svc);
71
76
77
81 virtual StatusCode initialize() override;
82
83
87 virtual StatusCode finalize() override;
88
89
96 virtual StatusCode event (const EventContext& ctx, bool allowAsync) override;
97
98
104 virtual StatusCode condObjAdded (const EventContext& ctx,
105 CondContBase& cc) override;
106
107
113 virtual StatusCode printStats() const override;
114
115
120 virtual StatusCode reset() override;
121
122
123
124private:
126
127
130
131
134
135 typedef std::array<std::vector<key_type>,2> twoKeys_t;
136
137
140 {
141 public:
143
147
149 size_t m_nClean = 0;
150
152 size_t m_nRemoved = 0;
153
155 size_t m_removed0 = 0;
156
158 size_t m_removed1 = 0;
159
161 size_t m_removed2plus = 0;
162 };
163
164
165 twoKeys_t getKeys(const Ring& runLBRing, const Ring& TSRing) const;
166
176 void scheduleClean (std::vector<CondContInfo*>&& cis,
177 twoKeys_t&& twoKeys,
178 bool allowAsync);
179
180
186 void cleanContainers (std::vector<CondContInfo*>&& cis,
187 twoKeys_t&& twoKeys);
188
189
198 const twoKeys_t& keys) const;
199
200
201
207
209 std::vector<key_type> m_slotLBN;
210 std::vector<key_type> m_slotTimestamp;
211
212
214 typedef std::unordered_map<CondContBase*, CondContInfo> CCInfoMap_t;
216
217
221 {
222 QueueItem (EventContext::ContextEvt_t evt, CondContInfo& ci)
223 : m_evt (evt), m_ci (&ci)
224 {}
225
226 EventContext::ContextEvt_t m_evt;
228
229 bool operator< (const QueueItem& other) const
230 {
231 // Reversed, since we want the lowest to come first.
232 return m_evt > other.m_evt;
233 }
234 };
235
237 std::priority_queue<QueueItem> m_work;
238
240 typedef std::mutex mutex_t;
241 typedef std::lock_guard<mutex_t> lock_t;
243
244
246 size_t m_nEvents = 0; // Number of times queue was examined.
247 size_t m_queueSum = 0; // Running sum of queue size.
248 size_t m_workRemoved = 0; // Count of items removed from the queue.
249 size_t m_maxQueue = 0; // Maximum queue size.
250
251
253 std::atomic<int> m_cleanTasks {0};
254
256 std::unique_ptr<DelayedConditionsCleanerSvcProps> m_props;
257};
258
259
260} // namespace Athena
261
262
263#endif // not ATHENASERVICES_DELAYEDCONDITIONSCLEANERTOOLSVC_H
Interface for doing garbage collection of conditions objects.
A simple ring buffer.
Information that we maintain about each conditions container.
size_t m_removed2plus
Number of times two or more objects were removed.
size_t m_removed1
Number of times exactly 1 object was removed.
size_t m_removed0
Number of times exactly 0 objects were removed.
size_t m_nClean
Number of times cleaning was attempted.
size_t m_nRemoved
Total number of objects removed by cleaning.
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.
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.
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::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.
CondContBase::KeyType KeyType
Run+LBN or timestamp key?
bool cleanContainer(CondContInfo *ci, const twoKeys_t &keys) const
Clean a single container.
std::mutex mutex_t
Serialize access to m_ccinfo and m_work.
std::vector< key_type > m_slotLBN
IOV keys currently in use for each slot.
virtual StatusCode finalize() override
Standard Gaudi finalize method.
virtual StatusCode printStats() const override
Print some statistics about the garbage collection.
std::unordered_map< CondContBase *, CondContInfo > CCInfoMap_t
Map of information, indexed by the conditions container.
Base class for all conditions containers.
Definition CondCont.h:140
KeyType
Type of key used for this container.
Definition CondCont.h:180
uint64_t key_type
Type used to store an IOV time internally.
Definition CondCont.h:204
A very simple ring buffer.
Definition Ring.h:40
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
QueueItem(EventContext::ContextEvt_t evt, CondContInfo &ci)