ATLAS Offline Software
Loading...
Searching...
No Matches
StoreGateSvc.icc
Go to the documentation of this file.
1/* -*- C++ -*- */
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7/** @file StoreGateSvc.icc
8 */
9
10#ifndef STOREGATE_STOREGATESVC_ICC
11#define STOREGATE_STOREGATESVC_ICC
12#include "StoreGate/constraints/KeyConcept.h"
13#include "AthContainersInterfaces/AuxStore_traits.h"
14#include "AthenaKernel/ClassName.h"
15#include "CxxUtils/checker_macros.h"
16#include <vector>
17
18/// macro to help writing the function calls.
19/// first looks if there is a hive slot defined, otherwise forwards to the "serial" implementation
20#define _SGXCALL(FUN,ARGS,ONERR) \
21 SGImplSvc* impl = this->currentStore(); \
22 if (impl) { \
23 return impl->FUN ARGS; \
24 } \
25 return ONERR;
26
27
28/// macro to help writing the function calls
29#define _SGVOIDCALL(FUN,ARGS) \
30 SGImplSvc* impl = this->currentStore(); \
31 if (impl) { \
32 impl->FUN ARGS; \
33 }
34
35
36inline
37StoreID::type
38StoreGateSvc::storeID() const
39{
40 return m_storeID;
41}
42
43
44inline
45SGImplSvc*
46StoreGateSvc::currentStore() const {
47 if (m_storeID == StoreID::EVENT_STORE) {
48 SG::HiveEventSlot* slot = currentSlot();
49 if (slot) return slot->pEvtStore;
50 }
51 return m_defaultStore;
52}
53
54
55inline
56SG::DataProxy*
57StoreGateSvc::proxy(const CLID& id, const char* key) const {
58 _SGXCALL( proxy, (id, key), 0 );
59}
60
61inline
62SG::DataProxy*
63StoreGateSvc::proxy_exact (SG::sgkey_t sgkey) const {
64 _SGXCALL( proxy_exact, (sgkey), 0 );
65}
66
67template <typename H, typename TKEY>
68StatusCode
69StoreGateSvc::regHandle ATLAS_NOT_THREAD_SAFE ( const DataHandle<H>& handle, const TKEY& key )
70{
71 CLID clid = ClassID_traits<H>::ID();
72 IResetable *ir = const_cast<IResetable*> (static_cast<const IResetable*> (&handle));
73 SG::DataProxy *dp = 0;
74
75 bool ret = this->currentStore()->bindHandleToProxyAndRegister (clid, key, ir, dp);
76 if (!ret) {
77 return StatusCode::FAILURE;
78 }
79
80 return handle.setState(dp); // FIXME - should be retrieve?
81}
82
83/// non-const method - will return an error
84template <typename H, typename TKEY>
85StatusCode
86StoreGateSvc::regHandle( DataHandle<H>& /*handle*/, const TKEY& key)
87{
88 error() << "regHandle(): DataHandle must be const: "
89 << ClassName<H>::name() << "[" + key + "]"
90 << endmsg;
91
92 return StatusCode::FAILURE;
93}
94
95///////////////////////////////////////////////////////////////////
96// create an object and record it with key
97//////////////////////////////////////////////////////////////////
98template <typename T, typename TKEY, typename... ARGS>
99SG::WPtr<T>
100StoreGateSvc::create(const TKEY& key, ARGS... constructorArgs) {
101 T* pT = new T(constructorArgs...);
102 if(!(this->record(pT, key).isSuccess())) {
103 error() << "create: problem recording created object @"
104 << pT << " using key " << key << endmsg;
105 pT=0; //record will take care of deleting pT even if it fails
106 }
107 return pT;
108}
109///////////////////////////////////////////////////////////////////
110// record an object with key
111//////////////////////////////////////////////////////////////////
112template <typename T, typename TKEY>
113StatusCode StoreGateSvc::record(T* pObject, const TKEY& key)
114{
115 const bool ALLOWMODS(true);
116 return record(pObject, key, ALLOWMODS); //allow mods by default
117}
118//-------------------------------------------------------------------
119template <typename T, typename TKEY>
120StatusCode StoreGateSvc::record(const T* pObject, const TKEY& key)
121{
122 const bool NOMODS(false);
123 // Ok --- we hold objects as non-const pointers internally, but mark
124 // them as const, so they can only be retrieved as const.
125 T* pObject_nc ATLAS_THREAD_SAFE = const_cast<T*> (pObject);
126 return record(pObject_nc, key, NOMODS); // do not allow mods
127}
128
129//-------------------------------------------------------------------
130template <typename T, typename TKEY>
131StatusCode StoreGateSvc::record(T* pObject, const TKEY& key,
132 bool allowMods, bool resetOnly, bool noHist)
133{
134 return record1 (SG::asStorable<T>(pObject), pObject, key,
135 allowMods, resetOnly, noHist);
136}
137
138
139//-------------------------------------------------------------------
140
141
142template <typename T, typename TKEY>
143StatusCode StoreGateSvc::record1(DataObject* obj,
144 T* pObject, const TKEY& key,
145 bool allowMods, bool resetOnly, bool noHist)
146requires KeyConcept<TKEY>
147{
148 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
149 rememberBadRecord (ClassID_traits<T>::ID(), key);
150 }
151
152 // make sure the BaseInfo(Base) structure is initialized
153 SG::BaseInfo<T>::baseinfo();
154
155 // If s_isConst is set for this type, then we want to automatically
156 // make it const when recorded.
157 if (ClassID_traits<T>::s_isConst)
158 allowMods = false;
159
160 StatusCode sc = this->currentStore()->typeless_record( obj, key, pObject,
161 allowMods, resetOnly, noHist,
162 &typeid(T));
163#ifndef NDEBUG
164 if (sc.isSuccess()) {
165 SG_MSG_DEBUG(
166 "Recorded object @" << pObject
167 << " with key " << (std::string)key
168 << " of type " << ClassID_traits<T>::typeName()
169 << "(CLID " << ClassID_traits<T>::ID()
170 << ")\n in DataObject @" << obj
171 << "\n object " << (allowMods ? "" : "not ")
172 << "modifiable when retrieved");
173 }
174#endif
175
176 return sc;
177}
178
179
180//-------------------------------------------------------------------
181
182
183template <typename T, typename TKEY>
184StatusCode StoreGateSvc::overwrite1(DataObject* obj, T* pObject,
185 const TKEY& key,
186 bool allowMods, bool noHist)
187requires KeyConcept<TKEY>
188{
189 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
190 rememberBadRecord (ClassID_traits<T>::ID(), key);
191 }
192
193 // make sure the BaseInfo(Base) structure is initialized
194 SG::BaseInfo<T>::baseinfo();
195
196 // If s_isConst is set for this type, then we want to automatically
197 // make it const when recorded.
198 if (ClassID_traits<T>::s_isConst) allowMods = false;
199
200 StatusCode sc = this->currentStore()->typeless_overwrite(ClassID_traits<T>::ID(),
201 obj, key,
202 pObject, allowMods, noHist,
203 &typeid(T));
204#ifndef NDEBUG
205 if (sc.isSuccess()) {
206 SG_MSG_DEBUG(
207 "overwrite: Recorded object @" << pObject
208 << " with key " << (std::string)key
209 << " of type " << ClassID_traits<T>::typeName()
210 << "(CLID " << ClassID_traits<T>::ID()
211 << ")\n in DataObject @" << obj
212 << "\n object " << (allowMods ? "" : "not ")
213 << "modifiable when retrieved");
214 }
215#endif
216 return sc;
217}
218
219//////////////////////////////////////////////////////////////////
220// Retrieve the default object (with no key) as a const pointer
221//////////////////////////////////////////////////////////////////
222template <typename T>
223StatusCode StoreGateSvc::retrieve(const T*& ptr) const
224{
225 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
226 rememberBadRetrieve (ClassID_traits<T>::ID(), "");
227 }
228
229 SG::DataProxy* dp =proxy(ClassID_traits<T>::ID());
230 if (!dp || !dp->isValid()) {
231 warning()
232 << "retrieve(default): No valid proxy for default object \n"
233 << " of type " << ClassID_traits<T>::typeName() << "(CLID "
234 << ClassID_traits<T>::ID() << ')' << endmsg;
235 return StatusCode::FAILURE;
236 }
237 ptr = SG::DataProxy_cast<T> (dp);
238 if (!ptr) {
239 return StatusCode::FAILURE;
240 }
241
242 //for types with an associated store, try to retrieve it and associate it
243 this->associateAux (ptr, SG::DEFAULTKEY);
244#ifndef NDEBUG
245 SG_MSG_DEBUG("retrieve(default): Retrieved const pointer to default object \n"
246 << " of type " << ClassID_traits<T>::typeName()
247 << "(CLID " << ClassID_traits<T>::ID() << ')');
248#endif
249
250 return StatusCode::SUCCESS;
251}
252
253//////////////////////////////////////////////////////////////////
254// Retrieve the default object (with no key) as a pointer (non-const)
255//////////////////////////////////////////////////////////////////
256template <typename T>
257StatusCode StoreGateSvc::retrieve(T*& ptr) const
258{
259 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
260 rememberBadRetrieve (ClassID_traits<T>::ID(), "");
261 }
262
263 SG::DataProxy* dp =proxy(ClassID_traits<T>::ID());
264 if (!dp || !dp->isValid() || dp->isConst()) {
265 warning()
266 << "retrieve(default): No valid proxy for default object "
267 << " of type " << ClassID_traits<T>::typeName() << "(CLID "
268 << ClassID_traits<T>::ID() << ")\n Try to use a const retrieve "
269 << endmsg;
270 return StatusCode::FAILURE;
271 }
272 ptr = SG::DataProxy_cast<T> (dp);
273 if (!ptr) {
274 return StatusCode::FAILURE;
275 }
276
277 //for types with an associated store, try to retrieve it and associate it
278 this->associateAux (ptr, SG::DEFAULTKEY);
279#ifndef NDEBUG
280 SG_MSG_DEBUG("retrieve(default): Retrieved non-const pointer to default object \n"
281 << " of type " << ClassID_traits<T>::typeName()
282 << "(CLID " << ClassID_traits<T>::ID() << ')');
283#endif
284
285 return StatusCode::SUCCESS;
286}
287
288//////////////////////////////////////////////////////////////////
289// Retrieve the keyed object as a const pointer
290// Overload for std::string key type
291//////////////////////////////////////////////////////////////////
292template <typename T>
293StatusCode StoreGateSvc::retrieve(const T*& ptr, const std::string& key) const
294{
295 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
296 rememberBadRetrieve (ClassID_traits<T>::ID(), key);
297 }
298
299 SG::DataProxy* dp =proxy (ClassID_traits<T>::ID(),
300 key,
301 false);
302 if (!dp || !dp->isValid()) {
303 warning()
304 << "retrieve(const): No valid proxy for object " << key << ' '
305 << " of type " << ClassID_traits<T>::typeName() << "(CLID "
306 << ClassID_traits<T>::ID() << ')' << endmsg;
307 return StatusCode::FAILURE;
308 }
309 ptr = SG::DataProxy_cast<T> (dp);
310 if (!ptr) {
311 return StatusCode::FAILURE;
312 }
313
314 //for types with an associated store, try to retrieve it and associate it
315 this->associateAux (ptr, key);
316#ifndef NDEBUG
317 SG_MSG_DEBUG( "Retrieved const pointer to object " << key << ' '
318 << " of type " << ClassID_traits<T>::typeName()
319 << "(CLID " << ClassID_traits<T>::ID() << ')');
320#endif
321
322 return StatusCode::SUCCESS;
323}
324
325//////////////////////////////////////////////////////////////////
326// Retrieve the keyed object as a const pointer
327//////////////////////////////////////////////////////////////////
328template <typename T, typename TKEY>
329StatusCode StoreGateSvc::retrieve(const T*& ptr, const TKEY& key) const
330requires KeyConcept<TKEY>
331{
332 return this->retrieve(ptr, static_cast<std::string>(key));
333}
334
335//////////////////////////////////////////////////////////////////
336// Retrieve the keyed object as a non-const pointer
337// Overload for std::string key type
338//////////////////////////////////////////////////////////////////
339template <typename T>
340StatusCode StoreGateSvc::retrieve(T*& ptr, const std::string& key) const
341{
342 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
343 rememberBadRetrieve (ClassID_traits<T>::ID(), key);
344 }
345
346 SG::DataProxy* dp =proxy (ClassID_traits<T>::ID(),
347 key,
348 false);
349 if (!dp || !dp->isValid() || dp->isConst()) {
350 SG_MSG_WARNING("retrieve(non-const): No valid proxy for object "
351 << key << ' '
352 << " of type " << ClassID_traits<T>::typeName() << "(CLID "
353 << ClassID_traits<T>::ID()
354 << ") \n Try to use a const retrieve" );
355 return StatusCode::FAILURE;
356 }
357 ptr = SG::DataProxy_cast<T> (dp);
358 if (!ptr) {
359 return StatusCode::FAILURE;
360 }
361
362 //for types with an associated store, try to retrieve it and associate it
363 this->associateAux (ptr, key);
364#ifndef NDEBUG
365 SG_MSG_DEBUG("Retrieved non-const pointer to object " << (std::string)key
366 << ' ' << " of type " << ClassID_traits<T>::typeName()
367 << "(CLID " << ClassID_traits<T>::ID() << ')');
368#endif
369
370 return StatusCode::SUCCESS;
371}
372
373//////////////////////////////////////////////////////////////////
374// Retrieve the keyed object as a non-const pointer
375//////////////////////////////////////////////////////////////////
376template <typename T, typename TKEY>
377StatusCode StoreGateSvc::retrieve(T*& ptr, const TKEY& key) const
378requires KeyConcept<TKEY>
379{
380 return this->retrieve(ptr, static_cast<std::string>(key));
381}
382
383/// Retrieve all objects of type T: returns an SG::ConstIterator range
384template <typename T>
385StatusCode
386StoreGateSvc::retrieve(SG::ConstIterator<T>& begin,
387 SG::ConstIterator<T>& end) const {
388 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
389 rememberBadRetrieve (ClassID_traits<T>::ID(), "(iterator)");
390 }
391 _SGXCALL(retrieve, (ClassID_traits<T>::ID(), begin, end), StatusCode::FAILURE);
392}
393
394
395/**
396 * @brief Retrieve an object of type @c T from StoreGate.
397 * Return 0 if not found.
398 **/
399
400template <typename T>
401T* StoreGateSvc::retrieve () const
402{
403 T* p = 0;
404 retrieve (p).ignore();
405 return p;
406}
407
408/**`<
409 * @brief Retrieve an object of type @c T from StoreGate.
410 * Return 0 if not found.
411 * @param key The key to use for the lookup.
412 **/
413template <typename T, class TKEY>
414T* StoreGateSvc::retrieve (const TKEY& key) const
415{
416 T* p = 0;
417 retrieve (p, key).ignore();
418 return p;
419}
420
421/**
422 * @brief Retrieve an object of type @c T from StoreGate.
423 * Return 0 if not found.
424 **/
425template <typename T>
426T* StoreGateSvc::tryRetrieve () const
427{
428 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
429 rememberBadRetrieve (ClassID_traits<T>::ID(), "");
430 }
431
432 SG::DataProxy* dp = proxy (ClassID_traits<T>::ID());
433 if (dp && dp->isValid() && !dp->isConst()) {
434 T* ptr = SG::DataProxy_cast<T> (dp);
435 if (ptr) {
436 this->associateAux (ptr, SG::DEFAULTKEY);
437 return ptr;
438 }
439 }
440 return nullptr;
441}
442
443template <typename T>
444const T* StoreGateSvc::tryConstRetrieve() const
445{
446 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
447 rememberBadRetrieve (ClassID_traits<T>::ID(), "");
448 }
449
450 SG::DataProxy* dp = proxy (ClassID_traits<T>::ID());
451 if (dp && dp->isValid()) {
452 const T* ptr = SG::DataProxy_cast<T> (dp);
453 if (ptr) {
454 this->associateAux (ptr, SG::DEFAULTKEY);
455 return ptr;
456 }
457 }
458 return nullptr;
459}
460
461/**
462 * @brief Retrieve an object of type @c T from StoreGate.
463 * Return 0 if not found. Don't print any WARNINGs
464 * @param key The key to use for the lookup.
465 **/
466template <typename T, class TKEY>
467T* StoreGateSvc::tryRetrieve (const TKEY& key) const
468requires KeyConcept<TKEY>
469{
470 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
471 rememberBadRetrieve (ClassID_traits<T>::ID(), key);
472 }
473 SG::DataProxy* dp = proxy (ClassID_traits<T>::ID(),
474 static_cast<std::string> (key),
475 false);
476 if (dp && dp->isValid() && !dp->isConst()) {
477 T* ptr = SG::DataProxy_cast<T> (dp);
478 if (ptr) {
479 this->associateAux (ptr, key);
480 return ptr;
481 }
482 }
483 return nullptr;
484}
485
486template <typename T, class TKEY>
487const T* StoreGateSvc::tryConstRetrieve (const TKEY& key) const
488requires KeyConcept<TKEY>
489{
490 if (m_storeID == StoreID::EVENT_STORE && currentSlot() != nullptr) {
491 rememberBadRetrieve (ClassID_traits<T>::ID(), key);
492 }
493
494 SG::DataProxy* dp = proxy (ClassID_traits<T>::ID(),
495 static_cast<std::string> (key),
496 false);
497 if (dp && dp->isValid()) {
498 const T* ptr = SG::DataProxy_cast<T> (dp);
499 if (ptr) {
500 this->associateAux (ptr, key);
501 return ptr;
502 }
503 }
504 return nullptr;
505}
506
507template <typename T>
508int StoreGateSvc::typeCount() const
509{
510 return typeCount(ClassID_traits<T>::ID());
511}
512
513
514template <typename T, typename TKEY>
515bool
516StoreGateSvc::contains(const TKEY& key) const
517{
518 return this->contains(ClassID_traits<T>::ID(), key);
519}
520
521template <typename TKEY>
522bool
523StoreGateSvc::contains(const CLID& clid, const TKEY& key) const
524{
525 _SGXCALL( contains, (clid,key), false );
526}
527
528template <typename T, typename TKEY>
529bool
530StoreGateSvc::transientContains(const TKEY& key) const
531{
532 return transientContains(ClassID_traits<T>::ID(), key);
533}
534
535
536
537template <typename TKEY>
538bool
539StoreGateSvc::transientContains(const CLID& id, const TKEY& key) const
540{
541 _SGXCALL(transientContains, (id, key), false);
542}
543
544//-------------------------end of contains methods--------------------
545template <typename T>
546void
547StoreGateSvc::keys(std::vector<std::string>& vkeys,
548 bool includeAlias, bool onlyValid) const {
549 return this->keys(ClassID_traits<T>::ID(), vkeys, includeAlias, onlyValid);
550}
551
552
553template <typename T, typename TKEY>
554StatusCode
555StoreGateSvc::bind ATLAS_NOT_THREAD_SAFE (const DataHandle<T>& handle, const TKEY& key) {
556 CLID clid = ClassID_traits<T>::ID();
557 IResetable *ir = const_cast<IResetable*> (static_cast<const IResetable*> (&handle));
558 SG::DataProxy *dp = 0;
559 bool ret = this->currentStore()->bindHandleToProxy (clid, key, ir, dp);
560 if (!ret) {
561 return StatusCode::FAILURE;
562 }
563
564 return handle.setState(dp); // FIXME - should be retrieve?
565}
566
567//-------------------------------------------------------------------
568template <typename T, typename TKEY>
569StatusCode StoreGateSvc::record(std::unique_ptr<T> pUnique, const TKEY& key)
570{
571 const bool ALLOWMODS(true);
572 return record(std::move(pUnique), key, ALLOWMODS); //allow mods by default
573}
574//-------------------------------------------------------------------
575template <typename T, typename TKEY>
576StatusCode StoreGateSvc::record(std::unique_ptr<const T> pUnique,
577 const TKEY& key)
578{
579 const bool NOMODS(false);
580 // Ok --- we hold objects as non-const pointers internally, but mark
581 // them as const, so they can only be retrieved as const.
582 T* ptr ATLAS_THREAD_SAFE = const_cast<T*> (pUnique.release());
583 return record1(SG::asStorable (ptr), ptr,
584 key, NOMODS); // do not allow mods
585}
586
587//-------------------------------------------------------------------
588template <typename T, typename TKEY>
589StatusCode StoreGateSvc::record(std::unique_ptr<T> pUnique, const TKEY& key,
590 bool allowMods, bool resetOnly, bool noHist)
591{
592 T* ptr = pUnique.get();
593 return record1 (SG::asStorable<T>(std::move(pUnique)), ptr, key,
594 allowMods, resetOnly, noHist);
595}
596
597template <typename T, typename TKEY>
598StatusCode StoreGateSvc::overwrite(T* p2BRegistered, const TKEY& key)
599{
600 const bool ALLOWMODS(true);
601 return overwrite(p2BRegistered, key, ALLOWMODS); //SG takes ownership
602}
603
604template <typename T, typename TKEY>
605StatusCode
606StoreGateSvc::overwrite(T* pObject, const TKEY& key,
607 bool allowMods, bool noHist)
608{
609 return overwrite1 (SG::asStorable<T>(pObject), pObject, key,
610 allowMods, noHist);
611}
612
613template <typename T, typename TKEY>
614StatusCode StoreGateSvc::overwrite(std::unique_ptr<T> pUnique, const TKEY& key)
615{
616 const bool ALLOWMODS(true);
617 return overwrite(std::move(pUnique), key, ALLOWMODS); //allow mods by default
618}
619
620template <typename T, typename TKEY>
621StatusCode StoreGateSvc::overwrite(std::unique_ptr<T> pUnique, const TKEY& key,
622 bool allowMods, bool noHist)
623{
624 T* ptr = pUnique.get();
625 return overwrite1 (SG::asStorable<T>(std::move(pUnique)), ptr, key,
626 allowMods, noHist);
627}
628
629template <typename T, typename AKEY>
630StatusCode StoreGateSvc::setAlias(const T* pObject, const AKEY& aKey)
631requires KeyConcept<AKEY>
632{
633 _SGXCALL(setAlias, (pObject, aKey), StatusCode::FAILURE);
634}
635//-------------------------------------------------------------------
636template <typename T, typename TKEY, typename AKEY>
637StatusCode
638StoreGateSvc::setAlias(const T* /*dummy*/,
639 const TKEY& key, const AKEY& aKey)
640requires KeyConcept<TKEY> && KeyConcept<AKEY>
641{
642 _SGXCALL(setAlias, (ClassID_traits<T>::ID(), key, aKey), StatusCode::FAILURE);
643}
644
645inline
646StatusCode
647StoreGateSvc::setAlias(SG::DataProxy* proxy, const std::string& aliasKey)
648{
649 _SGXCALL(setAlias, (proxy, aliasKey), StatusCode::FAILURE);
650}
651
652//////////////////////////////////////////////////////////////////
653// Make a soft link to the object with key: return non_const link
654//////////////////////////////////////////////////////////////////
655template <typename T, typename TLINK>
656StatusCode
657StoreGateSvc::symLink(const T* pObject, TLINK* /*dummy*/)
658{
659 _SGXCALL(symLink, (pObject, ClassID_traits<TLINK>::ID()), StatusCode::FAILURE);
660}
661
662//////////////////////////////////////////////////////////////////
663// Make a soft link to the object with key: set const link
664//////////////////////////////////////////////////////////////////
665template <typename T, typename TLINK>
666StatusCode
667StoreGateSvc::symLink(const T* pObject, const TLINK* /*dummy*/)
668{
669 _SGXCALL(symLink, (pObject, ClassID_traits<TLINK>::ID()), StatusCode::FAILURE);
670}
671
672template <KeyConcept TKEY>
673StatusCode
674StoreGateSvc::symLink(const CLID id, const TKEY& key, const CLID linkid)
675{
676 _SGXCALL(symLink, (id, key, linkid), StatusCode::FAILURE);
677}
678
679
680/// Remove pObject, will remove its proxy if not reset only.
681template <typename T>
682StatusCode
683StoreGateSvc::remove(const T* pObject) {
684 _SGXCALL(remove, (pObject), StatusCode::FAILURE);
685}
686
687/// Remove pObject and its proxy no matter what.
688template <typename T>
689StatusCode
690StoreGateSvc::removeDataAndProxy(const T* pObject) {
691 _SGXCALL(removeDataAndProxy, (pObject), StatusCode::FAILURE);
692}
693
694template <typename T, class TKEY>
695StatusCode
696StoreGateSvc::retrieveHighestVersion(SG::ObjectWithVersion<T>& dobjWithVersion,
697 const TKEY& requestedKey) const
698{
699 std::list< SG::ObjectWithVersion<T> > allVersions;
700 StatusCode sc(this->retrieveAllVersions(allVersions,requestedKey));
701 if (sc.isSuccess()) {
702 allVersions.sort(); // on highest version number
703 dobjWithVersion.versionedKey.copyVK(allVersions.back().versionedKey.rawVersionKey());
704 }
705 return sc;
706}
707
708template <typename T, class TKEY>
709StatusCode
710StoreGateSvc::retrieveAllVersions(std::list< SG::ObjectWithVersion<T> >& allVersions,
711 const TKEY& requestedKey) const
712{
713 StatusCode sc(StatusCode::FAILURE);
714 SG::ConstIterator<T> i,e;
715 if ((this->retrieve<T>(i,e)).isSuccess()){
716 SG::VersionedKey reqVK(requestedKey);
717 while (i != e) {
718 SG::VersionedKey vk(i.key());
719 if (reqVK.sameKey(vk)) {
720 sc = StatusCode::SUCCESS;
721 SG::ObjectWithVersion<T> okOWV(vk, i.proxy());
722 allVersions.push_back(okOWV);
723 }
724 ++i;
725 }
726 }
727 return sc;
728}
729
730
731template <typename T>
732std::unique_ptr<T>
733StoreGateSvc::retrieveUniquePrivateCopy (const std::string& key)
734{
735 CLID clid = ClassID_traits<T>::ID();
736 DataObject* obj = this->currentStore()->typeless_retrievePrivateCopy(clid, key);
737 std::unique_ptr<T> ret (SG::Storable_cast<T>(obj));
738 if (DataBucketBase* dbb = dynamic_cast<DataBucketBase*> (obj))
739 {
740 dbb->relinquish();
741 }
742 obj->release();
743 return ret;
744}
745
746//////////////////////////////////////////////////////////////////
747// Retrieve the @c CLID of a given "key"
748// WARNING: slow!
749//////////////////////////////////////////////////////////////////
750template<typename TKEY>
751CLID
752StoreGateSvc::clid( const TKEY& key ) const
753{
754 _SGXCALL(clid, (key), CLID_NULL);
755}
756
757//////////////////////////////////////////////////////////////////
758// Retrieve the @c CLID s of a given "key"
759// WARNING: slow!
760//////////////////////////////////////////////////////////////////
761template<typename TKEY>
762std::vector<CLID>
763StoreGateSvc::clids( const TKEY& key ) const
764{
765 std::vector<CLID> nullV;
766 _SGXCALL(clids, (key), nullV);
767}
768
769///////////////////////////////////////////////////////////////////////////
770
771inline
772void
773StoreGateSvc::setProxyProviderSvc(IProxyProviderSvc* pPPSvc) {
774 _SGVOIDCALL(setProxyProviderSvc, (pPPSvc));
775}
776
777
778inline
779IProxyProviderSvc*
780StoreGateSvc::proxyProviderSvc() {
781 _SGXCALL(proxyProviderSvc, (), nullptr);
782}
783
784
785/**
786 * @brief Return the metadata source ID for the current event slot.
787 * @param key SG key of the DataHeader to query.
788 * Returns an empty string if no source has been set.
789 *
790 * The default version always returns an empty string.
791 */
792inline
793SG::SourceID
794StoreGateSvc::sourceID (const std::string& key /*= "EventSelector"*/) const {
795 _SGXCALL(sourceID, (key), "");
796}
797
798
799template <class TKEY>
800void
801StoreGateSvc::remap (CLID clid,
802 const TKEY& source,
803 const TKEY& target,
804 off_t index_offset) {
805 _SGVOIDCALL(remap_impl, (this->stringToKey (source, clid),
806 this->stringToKey (target, clid),
807 index_offset));
808}
809
810
811/**
812 * @brief Remember that retrieve() was called for a MT store.
813 * @param clid CLID of the operation.
814 * @param key Key of the operation.
815 */
816inline
817void StoreGateSvc::rememberBadRetrieve (CLID clid, const std::string& key) const
818{
819 rememberBad (m_badRetrieves, clid, key);
820}
821
822
823/**
824 * @brief Remember that retrieve() was called for a MT store.
825 * @param clid CLID of the operation.
826 * @param key Key of the operation.
827 */
828inline
829void StoreGateSvc::rememberBadRecord (CLID clid, const std::string& key) const
830{
831 rememberBad (m_badRecords, clid, key);
832}
833
834
835template <class DOBJ, class AUXSTORE>
836bool StoreGateSvc::associateAux_impl (DOBJ* ptr,
837 const std::string& key,
838 const AUXSTORE*) const
839{
840 CLID auxclid = ClassID_traits<AUXSTORE>::ID();
841 _SGXCALL( associateAux_impl, (ptr, key, auxclid), false);
842}
843
844
845template <class DOBJ>
846bool StoreGateSvc::associateAux_impl (DOBJ* /*ptr*/,
847 const std::string& /*key*/,
848 const SG::NoAuxStore*) const
849{
850 return true;
851}
852
853
854/**
855 * @brief associate a data object to its auxiliary store
856 * Return false if the aux store is not found.
857 * @param key The key to use for the lookup.
858 **/
859template <class DOBJ>
860bool StoreGateSvc::associateAux (DOBJ* ptr,
861 const std::string& key,
862 bool ignoreMissing) const
863{
864 typename SG::AuxStore_traits<DOBJ>::type* pDummy(0); //used to pass down auxstore type
865 bool hasAux=associateAux_impl(ptr, key, pDummy) || ignoreMissing;
866 if (!hasAux) SG_MSG_WARNING("associateAux const: Could not associate AuxStore of type "
867 << SG::AuxStore_traits<DOBJ>::const_typeName()
868 << "\n to object of type " << ClassID_traits<DOBJ>::typeName() << "(CLID "
869 << ClassID_traits<DOBJ>::ID() << ") with key " << key << endmsg);
870 return hasAux;
871}
872
873
874template <class DOBJ>
875bool StoreGateSvc::associateAux (const DOBJ* ptr,
876 const std::string& key,
877 bool ignoreMissing) const
878{
879 typename SG::AuxStore_traits<DOBJ>::const_type* pDummy(0); //used to pass down auxstore type
880 // Should generally be ok, since any actual modification is done
881 // inside the store lock. Still kind of a wart that we still do this, though.
882 DOBJ* ptr_nc ATLAS_THREAD_SAFE = const_cast<DOBJ*> (ptr);
883 bool hasAux=associateAux_impl(ptr_nc, key, pDummy) || ignoreMissing;
884 if (!hasAux) SG_MSG_WARNING("associateAux const: Could not associate AuxStore of type "
885 << SG::AuxStore_traits<DOBJ>::const_typeName()
886 << "\n to object of type " << ClassID_traits<DOBJ>::typeName() << "(CLID "
887 << ClassID_traits<DOBJ>::ID() << ") with key " << key << endmsg);
888 return hasAux;
889}
890
891
892#endif //STOREGATE_STOREGATESVC_ICC