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