ATLAS Offline Software
Loading...
Searching...
No Matches
IOVSvcTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef IOVSVC_IOVSVCTOOL_H
6#define IOVSVC_IOVSVCTOOL_H 1
7
8
9/*****************************************************************************
10 *
11 * IOVSvcTool.h
12 * IOVSvc
13 *
14 * Author: Charles Leggett
15 *
16 * Provides automatic updating and callbacks for time dependent data
17 * This AlgTool does the real work.
18 *
19 *****************************************************************************/
20
21
23#include "GaudiKernel/StatusCode.h"
24#include "GaudiKernel/ClassID.h"
25#include "GaudiKernel/IIncidentListener.h"
26#include "GaudiKernel/ServiceHandle.h"
27
30#include "SGTools/DataProxy.h"
31#include "SGTools/CallBackID.h"
32#include "IOVSvc/IIOVSvcTool.h"
33#include "IOVEntry.h"
34
35#include <string>
36#include <set>
37#include <map>
38#include <list>
39#include <utility>
40
41
42class StoreGateSvc;
43class IIncidentSvc;
44class Incident;
46class IClassIDSvc;
47class IProxyDict;
48class IToolSvc;
49class CallBackID;
50class CBTree;
51
52namespace SG {
53 class TransientAddress;
54 class DataProxy;
55}
56
58public:
60 const SG::TransientAddress* ) const;
61};
62
63class SortDPptr {
64public:
65 bool operator() ( const SG::DataProxy*,
66 const SG::DataProxy* ) const;
67};
68
69
70class IOVSvcTool: public extends<AthAlgTool, IIOVSvcTool, IIncidentListener> {
71
72public:
73
74 IOVSvcTool(const std::string& type, const std::string& name,
75 const IInterface* parent);
76
77
78 virtual StatusCode initialize() override;
79 virtual StatusCode reinitialize() override;
80
81
83
84 // Incident handler
85 virtual void handle(const Incident&) override;
86
87 virtual
88 void setStoreName(const std::string& storeName) override {
89 m_storeName = storeName;
90 }
91 virtual const std::string& getStoreName() const override { return m_storeName; }
92
93 // register callback functions
94 virtual StatusCode regFcn(SG::DataProxy *dp, const CallBackID& c,
95 const IOVSvcCallBackFcn& fcn, bool trigger = false) override;
96
97 virtual StatusCode regFcn(const CallBackID& c1,
98 const CallBackID& c2, const IOVSvcCallBackFcn& fcn2,
99 bool trigger = false) override;
100
101 virtual StatusCode regFcn(const IAlgTool* ia,
102 const CallBackID& c2, const IOVSvcCallBackFcn& fcn2,
103 bool trigger = false) override;
104
105 // Update Range from dB
106 virtual StatusCode setRange(const CLID& clid, const std::string& key,
107 IOVRange&) override;
108
109 virtual StatusCode getRange(const CLID& clid, const std::string& key,
110 IOVRange& iov) const override;
111
112 // Subscribe method for DataProxy. key StoreGate key
113 virtual StatusCode regProxy( SG::DataProxy *proxy,
114 const std::string& key ) override;
115 // Another way to subscribe
116 virtual StatusCode regProxy( const CLID& clid, const std::string& key ) override;
117
118 virtual StatusCode deregProxy( SG::DataProxy *proxy ) override;
119 virtual StatusCode deregProxy( const CLID& clid, const std::string& key ) override;
120
121 // replace method for DataProxy, to be used when an update is necessary
122 virtual StatusCode replaceProxy( SG::DataProxy *pOld,
123 SG::DataProxy *pNew) override;
124
125 // Get IOVRange from db for current event
126 virtual StatusCode getRangeFromDB(const CLID& clid, const std::string& key,
127 IOVRange& range, std::string &tag,
128 std::unique_ptr<IOpaqueAddress>& ioa,
129 const IOVTime& curTime) const override;
130
131 // Get IOVRange from db for a particular event
132 virtual StatusCode getRangeFromDB(const CLID& clid, const std::string& key,
133 const IOVTime& time,
134 IOVRange& range, std::string &tag,
135 std::unique_ptr<IOpaqueAddress>& ioa) const override;
136
137 // Set a particular IOVRange in db (and memory)
138 virtual StatusCode setRangeInDB(const CLID& clid, const std::string& key,
139 const IOVRange& range,
140 const std::string &tag) override;
141
142 // supply a list of TADs whose proxies will be preloaded
143 virtual StatusCode preLoadTAD( const SG::TransientAddress * ) override;
144
145 // supply a list of TADs whose data will be preloaded
146 virtual StatusCode preLoadDataTAD( const SG::TransientAddress * ) override;
147
148 // return list of tools (or functions) that have been triggered by key
149 // will return FAILURE if no tools found, or no key found
150 virtual StatusCode getTriggeredTools(const std::string& key,
151 std::set<std::string>& tools) override;
152
153 virtual bool holdsProxy( SG::DataProxy* proxy ) const override;
154 virtual bool holdsProxy( const CLID& clid, const std::string& key ) const override;
155 virtual bool holdsCallback( const CallBackID& ) const override;
156 virtual bool holdsAlgTool( const IAlgTool* ia ) const override;
157
158 virtual void resetAllProxies() override;
159
160 virtual
161 void ignoreProxy( const CLID& clid, const std::string& key ) override{
162 m_ignoredProxyNames.insert( std::make_pair(clid,key) );
163 }
164 virtual
165 void ignoreProxy(SG::DataProxy* proxy) override {
166 m_ignoredProxies.insert(proxy);
167 }
168
169 // Destructor.
170 virtual ~IOVSvcTool();
171
172private:
173
174 StatusCode preLoadProxies(const EventContext& ctx);
175 StatusCode preLoadData();
176 StatusCode triggerCallback( IOVSvcCallBackFcn*, const std::string& key );
177 StatusCode triggerCallback( const SG::DataProxy*, const std::string& key );
178 std::string fullProxyName( const SG::TransientAddress* ) const;
179 std::string fullProxyName( const SG::DataProxy* ) const;
180 std::string fullProxyName( const CLID&, const std::string& ) const;
181 void setRange_impl (SG::DataProxy* proxy, IOVRange& iovr);
182
183 std::string m_storeName;
184
190
191 //IOVTime m_curTime{0};
192
194 typedef std::multimap<const SG::DataProxy*, BFCN*>::iterator pmITR;
195 typedef std::multimap<BFCN*, const SG::DataProxy*>::iterator fnITR;
196 typedef std::multiset<IOVEntry*, IOVEntry::IOVEntryStartCritereon> startSet;
197 typedef std::multiset<IOVEntry*, IOVEntry::IOVEntryStopCritereon> stopSet;
198 typedef startSet::iterator startITR;
199 typedef stopSet::iterator stopITR;
200
201 std::map< const SG::DataProxy*, std::string> m_names;
202
203 mutable std::recursive_mutex m_handleMutex ATLAS_THREAD_SAFE;
204 // meant to protect: m_first, m_entries,
205 // m_startSet..., m_stopSet... .
206 // Locked by "handle" and "setRange", where setRange
207 // is called also via preLoadProxies which calls
208 // SG::DataProxy::updateAddress which then calls
209 // setRange. So, without refactoring a recursive
210 // mutex is needed.
211
212 std::set< SG::DataProxy*, SortDPptr > m_proxies;
213 std::multimap< const SG::DataProxy*, BFCN* > m_proxyMap;
214 std::multimap< BFCN*, const SG::DataProxy* > m_bfcnMap;
215
216 std::set<SG::DataProxy*> m_ignoredProxies;
217 std::set< std::pair<CLID, std::string> > m_ignoredProxyNames;
218
219 std::map<BFCN*, CallBackID> m_fcnMap;
220 std::map<CallBackID, BFCN*> m_cbidMap;
221
222 typedef std::map<const void*, std::set<CallBackID>* > ObjMap;
224
225 std::map< const SG::DataProxy*, IOVEntry*> m_entries;
226
229
232
234
235 std::set< const SG::TransientAddress*, SortTADptr > m_preLoad;
236
237 typedef std::tuple <CLID, std::string> TADkey_t;
239 { return TADkey_t (p.clID(), p.name()); }
241 { return TADkey_t (t.clID(), t.name()); }
242 std::set< TADkey_t > m_partPreLoad;
243
244 std::atomic<bool> m_first{true};
245 bool m_checkOnce{false};
246 bool m_triggered{false};
247 bool m_firstEventOfRun{false};
249 std::string m_checkTrigger;
250
251 Gaudi::Property<bool> m_preLoadRanges{this, "preLoadRanges", false};
252 Gaudi::Property<bool> m_preLoadData{this, "preLoadData", false};
253 Gaudi::Property<bool> m_partialPreLoadData{this, "partialPreLoadData", true};
254 Gaudi::Property<bool> m_preLoadExtensibleFolders{this, "preLoadExtensibleFolders", true};
255 Gaudi::Property<bool> m_sortKeys{this, "sortKeys", true};
256 Gaudi::Property<bool> m_forceReset{this, "forceResetAtBeginRun", false};
257 Gaudi::Property<std::string> m_updateInterval{this, "updateInterval", "Event"};
258
259
260 void scanStartSet(startSet &pSet, const std::string &type,
261 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
262 const IOVTime& curTime) const;
263 void scanStopSet(stopSet &pSet, const std::string &type,
264 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
265 const IOVTime& curTime) const;
266
267 void PrintStartSet() const;
268 void PrintStopSet() const;
269 void PrintProxyMap() const;
270 void PrintProxyMap(const SG::DataProxy*) const;
271
272};
273
274#endif
uint32_t CLID
The Class ID type.
defines and typedefs for IOVSvc
boost::function< StatusCode(IOVSVC_CALLBACK_ARGS) > IOVSvcCallBackFcn
the type of an IOVSvc call back: it wraps both the method and the object the method is called on
Definition IOVSvcDefs.h:58
Basic time unit for IOVSvc.
Validity Range object.
Definition IOVRange.h:30
bool m_checkOnce
Definition IOVSvcTool.h:245
virtual bool holdsAlgTool(const IAlgTool *ia) const override
virtual StatusCode regProxy(SG::DataProxy *proxy, const std::string &key) override
Register a DataProxy with the service.
virtual StatusCode getTriggeredTools(const std::string &key, std::set< std::string > &tools) override
std::multimap< constSG::DataProxy *, BFCN * >::iterator pmITR
Definition IOVSvcTool.h:194
virtual const std::string & getStoreName() const override
Definition IOVSvcTool.h:91
void setRange_impl(SG::DataProxy *proxy, IOVRange &iovr)
Gaudi::Property< bool > m_forceReset
Definition IOVSvcTool.h:256
std::string fullProxyName(const SG::TransientAddress *) const
std::multiset< IOVEntry *, IOVEntry::IOVEntryStartCritereon > startSet
Definition IOVSvcTool.h:196
ObjMap m_objMap
Definition IOVSvcTool.h:223
Gaudi::Property< bool > m_preLoadRanges
Definition IOVSvcTool.h:251
std::set< std::pair< CLID, std::string > > m_ignoredProxyNames
Definition IOVSvcTool.h:217
ServiceHandle< IClassIDSvc > p_CLIDSvc
Definition IOVSvcTool.h:188
virtual void ignoreProxy(SG::DataProxy *proxy) override
Definition IOVSvcTool.h:165
std::multimap< BFCN *, constSG::DataProxy * >::iterator fnITR
Definition IOVSvcTool.h:195
void PrintStopSet() const
virtual StatusCode replaceProxy(SG::DataProxy *pOld, SG::DataProxy *pNew) override
replace a registered DataProxy with a new version
Gaudi::Property< bool > m_partialPreLoadData
Definition IOVSvcTool.h:253
stopSet::iterator stopITR
Definition IOVSvcTool.h:199
Gaudi::Property< bool > m_sortKeys
Definition IOVSvcTool.h:255
std::map< CallBackID, BFCN * > m_cbidMap
Definition IOVSvcTool.h:220
startSet::iterator startITR
Definition IOVSvcTool.h:198
StatusCode preLoadProxies(const EventContext &ctx)
std::recursive_mutex m_handleMutex ATLAS_THREAD_SAFE
Definition IOVSvcTool.h:203
std::string m_storeName
Definition IOVSvcTool.h:183
virtual StatusCode setRangeInDB(const CLID &clid, const std::string &key, const IOVRange &range, const std::string &tag) override
bool m_triggered
Definition IOVSvcTool.h:246
virtual void resetAllProxies() override
std::set< TADkey_t > m_partPreLoad
Definition IOVSvcTool.h:242
startSet * p_startSet
Definition IOVSvcTool.h:227
stopSet m_stopSet_Clock
Definition IOVSvcTool.h:231
std::map< BFCN *, CallBackID > m_fcnMap
Definition IOVSvcTool.h:219
std::set< const SG::TransientAddress *, SortTADptr > m_preLoad
Definition IOVSvcTool.h:235
virtual StatusCode preLoadTAD(const SG::TransientAddress *) override
add to a set of TADs that will be registered at start of first event
IOVSvcTool(const std::string &type, const std::string &name, const IInterface *parent)
std::set< SG::DataProxy * > m_ignoredProxies
Definition IOVSvcTool.h:216
void scanStopSet(stopSet &pSet, const std::string &type, std::set< SG::DataProxy *, SortDPptr > &proxiesToReset, const IOVTime &curTime) const
virtual StatusCode reinitialize() override
ServiceHandle< IProxyProviderSvc > p_PPSvc
Definition IOVSvcTool.h:187
void PrintStartSet() const
std::map< const SG::DataProxy *, IOVEntry * > m_entries
Definition IOVSvcTool.h:225
std::atomic< bool > m_first
Definition IOVSvcTool.h:244
stopSet m_stopSet_RE
Definition IOVSvcTool.h:231
Gaudi::Property< std::string > m_updateInterval
Definition IOVSvcTool.h:257
Gaudi::Property< bool > m_preLoadData
Definition IOVSvcTool.h:252
StatusCode triggerCallback(IOVSvcCallBackFcn *, const std::string &key)
virtual void ignoreProxy(const CLID &clid, const std::string &key) override
Definition IOVSvcTool.h:161
stopSet * p_stopSet
Definition IOVSvcTool.h:228
void scanStartSet(startSet &pSet, const std::string &type, std::set< SG::DataProxy *, SortDPptr > &proxiesToReset, const IOVTime &curTime) const
std::tuple< CLID, std::string > TADkey_t
Definition IOVSvcTool.h:237
virtual bool holdsCallback(const CallBackID &) const override
std::string m_checkTrigger
Definition IOVSvcTool.h:249
std::map< const SG::DataProxy *, std::string > m_names
Definition IOVSvcTool.h:201
virtual StatusCode initialize() override
TADkey_t TADkey(const SG::DataProxy &p)
Definition IOVSvcTool.h:238
std::multimap< const SG::DataProxy *, BFCN * > m_proxyMap
Definition IOVSvcTool.h:213
void PrintProxyMap() const
virtual StatusCode regFcn(SG::DataProxy *dp, const CallBackID &c, const IOVSvcCallBackFcn &fcn, bool trigger=false) override
StatusCode preLoadData()
CBTree * m_trigTree
Definition IOVSvcTool.h:233
virtual StatusCode deregProxy(SG::DataProxy *proxy) override
Deregister a DataProxy with the service.
IOVSvcCallBackFcn BFCN
Definition IOVSvcTool.h:193
startSet m_startSet_Clock
Definition IOVSvcTool.h:230
bool m_firstEventOfRun
Definition IOVSvcTool.h:247
Gaudi::Property< bool > m_preLoadExtensibleFolders
Definition IOVSvcTool.h:254
std::multimap< BFCN *, const SG::DataProxy * > m_bfcnMap
Definition IOVSvcTool.h:214
virtual StatusCode getRange(const CLID &clid, const std::string &key, IOVRange &iov) const override
virtual bool holdsProxy(SG::DataProxy *proxy) const override
ServiceHandle< IToolSvc > p_toolSvc
Definition IOVSvcTool.h:189
TADkey_t TADkey(const SG::TransientAddress &t)
Definition IOVSvcTool.h:240
virtual StatusCode getRangeFromDB(const CLID &clid, const std::string &key, IOVRange &range, std::string &tag, std::unique_ptr< IOpaqueAddress > &ioa, const IOVTime &curTime) const override
virtual StatusCode preLoadDataTAD(const SG::TransientAddress *) override
add to a set of TADs that who's data will be preLoaded
std::map< const void *, std::set< CallBackID > * > ObjMap
Definition IOVSvcTool.h:222
std::multiset< IOVEntry *, IOVEntry::IOVEntryStopCritereon > stopSet
Definition IOVSvcTool.h:197
ServiceHandle< StoreGateSvc > p_cndSvc
Definition IOVSvcTool.h:185
virtual void handle(const Incident &) override
bool m_resetAllCallbacks
Definition IOVSvcTool.h:248
ServiceHandle< IIncidentSvc > p_incSvc
Definition IOVSvcTool.h:186
std::set< SG::DataProxy *, SortDPptr > m_proxies
Definition IOVSvcTool.h:212
virtual StatusCode setRange(const CLID &clid, const std::string &key, IOVRange &) override
startSet m_startSet_RE
Definition IOVSvcTool.h:230
virtual ~IOVSvcTool()
virtual void setStoreName(const std::string &storeName) override
Definition IOVSvcTool.h:88
Basic time unit for IOVSvc.
Definition IOVTime.h:33
bool operator()(const SG::DataProxy *, const SG::DataProxy *) const
bool operator()(const SG::TransientAddress *, const SG::TransientAddress *) const
The Athena Transient Store API.
Forward declaration.