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