5#include "GaudiKernel/IIncidentSvc.h"
14#include "Gaudi/Interfaces/IOptionsSvc.h"
15#include "GaudiKernel/IAppMgrUI.h"
45 currentHiveEventSlot=pSlot;
46 if ( 0 != currentHiveEventSlot) {
47 currentHiveEventSlot->pEvtStore->makeCurrent();
54 ISvcLocator *svcLocator = Gaudi::svcLocator();
55 SmartIF<StoreGateSvc> sg{svcLocator->service(
"StoreGateSvc/StoreGateSvc")};
56 if ( !sg.isValid() ) {
58 "Could not get \"StoreGateSvc\" to initialize currentStoreGate",
59 "StoreGateSvc", StatusCode::FAILURE);
64 return ::currentStoreGate;
69 return currentHiveEventSlot;
84 bool clearAddressFlag,
85 const std::vector<CLID>& bases)
87 _SGXCALL(
recordAddress, (skey, std::move(pAddress), clearAddressFlag, bases), StatusCode::FAILURE);
92 bool clearAddressFlag,
93 const std::vector<CLID>& bases)
95 _SGXCALL(
recordAddress, (std::move(pAddress), clearAddressFlag, bases), StatusCode::FAILURE);
101 _SGXCALL(
setConst, (pObject), StatusCode::FAILURE);
110 CHECK( Service::initialize() );
114 SmartIF<Gaudi::Interfaces::IOptionsSvc> pJOSvc{serviceLocator()->service(
"JobOptionsSvc")};
115 if ( !pJOSvc.isValid() ) {
116 error() <<
"Failed to retrieve JobOptionsSvc" <<
endmsg;
119 const std::string implStoreName = name() +
"_Impl";
120 for (
const Gaudi::Details::PropertyBase* p : getProperties()) {
121 pJOSvc->set( implStoreName +
"." + p->name(), p->toString() );
128 std::string implStoreFullName =
"SGImplSvc/" + implStoreName;
129 debug() <<
"trying to create store " << implStoreFullName <<
endmsg;
131 m_defaultStore = serviceLocator().as<ISvcManager>()->createService(implStoreFullName);
134 error() <<
"Could not create store " << implStoreFullName <<
endmsg;
135 return StatusCode::FAILURE;
141 if (name() ==
"StoreGateSvc") {
145 error() <<
"Could not initialize default store " << implStoreFullName
147 return StatusCode::FAILURE;
149 if ( !
m_incSvc.retrieve().isSuccess() ) {
150 error() <<
"Could not locate IncidentSvc" <<
endmsg;
151 return StatusCode::FAILURE;
158 const int PRIORITY=100;
159 m_incSvc->addListener(
this,
"EndEvent",PRIORITY);
162 return StatusCode::SUCCESS;
172 auto pISM = serviceLocator().as<ISvcManager>();
173 pISM->setPriority(name(), pISM->getPriority(name())+1).ignore();
174 verbose() <<
"stop: setting service priority to " << pISM->getPriority(name())
175 <<
" so that event stores get finalized and cleared before other stores" <<
endmsg;
177 return StatusCode::SUCCESS;
188 CHECK( Service::finalize() );
197 return StatusCode::SUCCESS;
204 _SGXCALL(
proxy, (pTransient), 0);
210 _SGXCALL(
proxy, (
id), 0);
216 _SGXCALL(
proxy, (
id, key), 0);
224 _SGXCALL(
proxy, (
id, checkValid), 0);
231 _SGXCALL(
proxy, (
id, key, checkValid), 0);
268 const std::string& key,
272 _SGXCALL(
recordObject, (std::move(obj), key, allowMods, returnExisting),
nullptr);
277vector<const SG::DataProxy*>
279 vector<const SG::DataProxy*> nullV;
288 _SGXCALL(
clids, (), nullV);
313 const std::string& keyA,
const std::string& keyB ) {
321 const void*
const raw_ptr,
322 bool allowMods,
bool resetOnly,
324 _SGXCALL(
typeless_record, (obj, key, raw_ptr, allowMods, resetOnly, noHist), StatusCode::FAILURE);
329 DataObject* obj,
const std::string& key,
330 const void*
const raw_ptr,
333 const std::type_info* tinfo) {
334 _SGXCALL(
typeless_overwrite, (
id, obj, key, raw_ptr, allowMods, noHist, tinfo), StatusCode::FAILURE);
348 bool includeAlias,
bool onlyValid)
const
350 _SGVOIDCALL(
keys,(
id, vkeys, includeAlias, onlyValid));
357 std::string nullS =
"\n>>>>>>>NO CURRENT STORE<<<<<<<\n";
358 _SGXCALL(
dump, (), nullS);
385 const std::string&
str,
392 off_t index_offset) {
393 _SGVOIDCALL(
remap_impl, (source, target, index_offset) );
398 sgkey_t& sgkey_out,
size_t& index_out) {
399 _SGXCALL(
tryELRemap, (sgkey_in, index_in, sgkey_out, index_out),
false );
406 _SGXCALL(
proxyRange, (
id, beg, end), StatusCode::FAILURE );
440 std::vector<IIncidentListener*> l;
441 m_incSvc->getListeners (l,
"StoreCleared");
450 if (
sc.isSuccess()) {
487 IOpaqueAddress* addr,
488 DataObject*& refpObject)
490 _SGXCALL(
createObj, (cvt, addr, refpObject), StatusCode::FAILURE );
501 CLID clid,
const std::string& key)
const
508 if (alg->type() ==
"AthenaOutputStream")
return;
509 if (alg->type() ==
"AthIncFirerAlg")
return;
510 algo = alg->type() +
"/" + alg->name();
524 const std::string& what)
const
526 if (
bad.empty())
return;
527 std::vector<std::string> lines;
529 lines.push_back (
id.fullKey() +
" [" +
id.m_algo +
"]");
532 warning() <<
"Called " << what <<
" on these objects in a MT store" <<
endmsg;
533 for (
const std::string& s : lines) {
541 std::cout << sg->
dump() <<
"\n";
546 std::ofstream f (fname);
547 f << sg->
dump() <<
"\n";
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
uint32_t CLID
The Class ID type.
Incident sent after a store is cleared.
void SG_dump(StoreGateSvc *sg)
These are intended to be easy to call from the debugger.
Simple smart pointer for Gaudi-style refcounted objects.
The Athena Transient Store API.
virtual void handle(const Incident &) override final
triggered by Incident service
virtual StatusCode clearStore(bool forceRemove=false) override final
clear DataStore contents: called by the event loop mgrs
Incident sent after a store is cleared.
The Athena Transient Store API.
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override final
Record an object in the store.
virtual StatusCode finalize() override
static SG::HiveEventSlot * currentSlot()
std::string dump() const
dump objects in store.
virtual StatusCode createObj(IConverter *cvt, IOpaqueAddress *addr, DataObject *&refpObject) override
Call converter to create an object, with locking.
virtual void handle(const Incident &) override final
virtual void registerKey(sgkey_t key, const std::string &str, CLID clidid) override final
Remember an additional mapping from key to string/CLID.
DataObject * accessData(const CLID &id) const
find proxy and access its data. Returns 0 to flag failure
StoreGateSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
SmartIF< SGImplSvc > m_defaultStore
StatusCode loadEventProxies()
load proxies at begin event
Gaudi::Property< bool > m_pruneIncidents
StatusCode proxyRange(const CLID &id, SG::ConstProxyIterator &beg, SG::ConstProxyIterator &end) const
return a range to all proxies of a given CLID
void remap_impl(sgkey_t source, sgkey_t target, off_t index_offset)
Declare a remapping.
void rememberBad(BadItemList &bad, CLID clid, const std::string &key) const
Remember that retrieve or record was called for a MT store.
static StoreGateSvc * currentStoreGate()
get current StoreGate
std::lock_guard< mutex_t > lock_t
virtual ~StoreGateSvc() override
Standard Destructor.
SG::DataProxy * transientProxy(const CLID &id, const std::string &key) const
get proxy with given id and key.
void clearProxyPayload(SG::DataProxy *)
use to reset a proxy (clearing the data object it contains) Unlike DataProxy::reset this method corre...
Gaudi::Property< bool > m_DumpStore
void setStoreID(StoreID::type id)
set store ID. request forwarded to DataStore:
std::unordered_set< BadListItem, DataObjID_Hasher > BadItemList
IStringPool::sgkey_t sgkey_t
int typeCount() const
Return the number of instances of an object of type T int i = p_store->typeCount<T>(); Note that th...
virtual StatusCode addToStore(CLID id, SG::DataProxy *proxy) override final
Raw addition of a proxy to the store.
CLID clid(const TKEY &key) const
Retrieve the main CLID of the object recorded in StoreGate with the given "key" WARNING: slow!
virtual bool tryELRemap(sgkey_t sgkey_in, size_t index_in, sgkey_t &sgkey_out, size_t &index_out) override final
Test to see if the target of an ElementLink has moved.
StoreID::type m_storeID
Cache store type in the facade class.
virtual void commitNewDataObjects() override final
Reset handles added since the last call to commit.
void makeCurrent()
The current store is becoming the active store.
SGImplSvc * currentStore() const
returns pointer to the current SGImplSvc
void emptyTrash()
throw away bad objects
virtual StatusCode initialize() override
Service initialization.
std::vector< CLID > clids(const TKEY &key) const
Retrieve all the CLID s (including symlinks) of the object recorded in StoreGate with the given "key"...
virtual StatusCode clearStore(bool forceRemove=false) override final
clear DataStore contents: called by the event loop mgrs
void printBadList(const BadItemList &bad, const std::string &what) const
Print out a list of bad calls during finalization.
StatusCode typeless_record(DataObject *obj, const std::string &key, const void *const raw_ptr, bool allowMods, bool resetOnly=true, bool noHist=false)
type-less recording of an object with a key, allow possibility of specifying const-access and history...
ServiceHandle< IAlgContextSvc > m_algContextSvc
StatusCode recordAddress(const std::string &skey, CxxUtils::RefCountedPtr< IOpaqueAddress > pAddress, bool clearAddressFlag=true, const std::vector< CLID > &bases={})
Create a proxy object using an IOpaqueAddress and a transient key.
virtual const std::string * keyToString(sgkey_t key) const override final
Find the string corresponding to a given key.
std::atomic< ListenerState > m_listenerState
bool transientSwap(const CLID &id, const std::string &keyA, const std::string &keyB)
swap the content of 2 keys payload A indexed by keyA will now be accessed via keyB and vice versa Not...
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override final
Find the key for a string/CLID pair.
virtual StatusCode stop() override
Service start.
std::vector< CLID > clids() const
Return all CLIDs in the store.
virtual std::vector< const SG::DataProxy * > proxies() const override final
return the list of all current proxies in store
virtual SG::DataProxy * proxy(const void *const pTransient) const override final
get proxy for a given data object address in memory
StatusCode setConst(const void *pointer)
prevent downstream clients from modifying the pointed-at dobj
void keys(std::vector< std::string > &vkeys, bool includeAlias=false, bool onlyValid=true) const
provide list of all StoreGate keys associated with an object.
StatusCode typeless_overwrite(const CLID &id, DataObject *obj, const std::string &key, const void *const raw_ptr, bool allowMods, bool noHist=false, const std::type_info *tinfo=0)
same as typeless_record, allows to overwrite an object in memory or on disk
void releaseObject(const CLID &id, const std::string &key)
release object held by proxy, if any.
ServiceHandle< IIncidentSvc > m_incSvc
StatusCode removeProxy(SG::DataProxy *proxy, const void *pTrans, bool forceRemove=false)
remove proxy from store, unless it is reset only.
static void setSlot(SG::HiveEventSlot *pSlot)
set the hive event slot pointer: used by the event loop mgrs
void setDefaultStore(SGImplSvc *pStore)
set pointer to default event store: used by ActiveStoreSvc
defines an enum used by address providers to decide what kind of StoreGateSvc they are providing addr...
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
ProxyMap::const_iterator ConstProxyIterator
virtual void lock() override
Lock the container.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.