ATLAS Offline Software
Loading...
Searching...
No Matches
SGImplSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#undef DEBUG_SGIMPL
6
7#include <algorithm>
8#include <cassert>
9#include <cstdio>
10#include <iostream>
11#include <functional>
12#include <format>
13#include <string>
14#include <unordered_map>
15
16#include <sstream>
17#include <fstream>
18#include <iomanip>
19
28#include "GaudiKernel/IClassIDSvc.h"
29#include "GaudiKernel/IHistorySvc.h"
30#include "GaudiKernel/ISvcLocator.h"
31#include "GaudiKernel/IConversionSvc.h"
32#include "GaudiKernel/Incident.h"
33#include "GaudiKernel/IOpaqueAddress.h"
34#include "GaudiKernel/MsgStream.h"
35#include "GaudiKernel/StatusCode.h"
36#include "GaudiKernel/DataHistory.h"
39#include "SGTools/DataProxy.h"
40#include "SGTools/DataStore.h"
41#include "SGTools/StringPool.h"
48
49// StoreGateSvc. must come before SGImplSvc.h
52#include "SGTools/DataStore.h"
53
54using std::setw;
55using std::hex;
56using std::dec;
57using std::endl;
58using std::ends;
59using std::pair;
60using std::string;
61using std::vector;
62
63using SG::DataProxy;
64using SG::DataStore;
66
67// Helpers for debug formatting
68// std::print implementation to be replaced when C++ 23 is available
69namespace dbg {
70template <class... Args> void print(std::FILE* stream, std::format_string<Args...> fmt, Args&&... args) {
71 std::fputs(std::format(fmt, std::forward<Args>(args)...), stream);
72}
73
74template <class T> void* ptr(T* p) { return static_cast<void*>(p); }
75}
76
78// Remapping implementation.
79
80
81namespace SG {
82
83
95
96
97} // namespace SG
98
99
102SGImplSvc::SGImplSvc(const string& name,ISvcLocator* svc)
103 : base_class(name, svc),
104 m_pCLIDSvc("ClassIDSvc", name),
105 m_pDataLoader("EventPersistencySvc", name),
106 m_pPPSHandle("ProxyProviderSvc", name),
107 m_pPPS(nullptr),
108 m_pHistorySvc("HistorySvc", name),
109 m_pStore(new DataStore(*this)),
110 m_pIncSvc("IncidentSvc", name),
111 m_DumpStore(false),
112 m_ActivateHistory(false),
113 m_DumpArena(false),
114 m_pIOVSvc("IOVSvc", name),
115 m_storeLoaded(false),
116 m_remap_impl (new SG::RemapImpl),
117 m_arena (name),
118 m_slotNumber(-1),
119 m_numSlots(1)
120{
121 //our properties
122 declareProperty("ProxyProviderSvc", m_pPPSHandle);
123 declareProperty("Dump", m_DumpStore);
124 declareProperty("ActivateHistory", m_ActivateHistory);
125 declareProperty("DumpArena", m_DumpArena);
126 //StoreGateSvc properties
127 declareProperty("IncidentSvc", m_pIncSvc);
128 //add handler for Service base class property
129 m_outputLevel.declareUpdateHandler(&SGImplSvc::msg_update_handler, this);
130
132 header->addArena (&m_arena);
133}
134
135
139 header->delArena (&m_arena);
140
141 delete m_pStore;
142 delete m_remap_impl;
143}
144
148
149 verbose() << "Initializing " << name() << endmsg;
150
151 CHECK( Service::initialize() );
152
153 if (!m_pStore)
154 m_pStore = new DataStore (*this);
155 if (!m_remap_impl)
157
158 //properties accessible from now on
159
161 // If this is the default event store (StoreGateSvc), then declare
162 // our arena as the default for memory allocations.
163 if (this->storeID() == StoreID::EVENT_STORE) {
164 m_arena.makeCurrent();
165 SG::CurrentEventStore::setStore (this);
166 }
167 // set up the incident service:
168 if (!(m_pIncSvc.retrieve()).isSuccess()) {
169 error() << "Could not locate IncidentSvc "
170 << endmsg;
171 return StatusCode::FAILURE;
172 }
173
174 // We explicitly do not retrieve m_pIOVSvc and rely on retrieval
175 // on first use to avoid an initialization loop here.
176
177 CHECK( m_pDataLoader.retrieve() );
178 CHECK( m_pCLIDSvc.retrieve() );
179
180 if (!m_pPPSHandle.empty()) {
181 CHECK( m_pPPSHandle.retrieve() );
183 }
184
185 if ( m_pPPS && (m_pPPS->preLoadProxies(*m_pStore)).isFailure() )
186 {
187 SG_MSG_DEBUG(" Failed to preLoad proxies");
188 return StatusCode::FAILURE;
189 }
190
191 // Get hold of History Service
192 if (m_ActivateHistory) {
193 CHECK( m_pHistorySvc.retrieve() );
194 }
195
196 return StatusCode::SUCCESS;
197}
198
199StatusCode SGImplSvc::start() {
200
201 verbose() << "Start " << name() << endmsg;
202 /*
203 // This will need regFcn clients to be updated first.
204 if ( 0 == m_pPPS || (m_pPPS->preLoadProxies(*m_pStore)).isFailure() ) {
205 debug() << " Failed to preLoad proxies"
206 << endmsg;
207 return StatusCode::FAILURE;
208 }
209 */
210
211 return StatusCode::SUCCESS;
212}
213
214StatusCode SGImplSvc::stop() {
215
216 verbose() << "Stop " << name() << endmsg;
217 //HACK ALERT: ID event store objects refer to det store objects
218 //by setting an ad-hoc priority for event store(s) we make sure they are finalized and hence cleared first
219 // see e.g. https://savannah.cern.ch/bugs/index.php?99993
220 if (store()->storeID() == StoreID::EVENT_STORE) {
221 ISvcManager* pISM(dynamic_cast<ISvcManager*>(serviceLocator().get()));
222 if (!pISM)
223 return StatusCode::FAILURE;
224 pISM->setPriority(name(), pISM->getPriority(name())+1).ignore();
225 verbose() << "stop: setting service priority to " << pISM->getPriority(name())
226 << " so that event stores get finalized and cleared before other stores" <<endmsg;
227 }
228 return StatusCode::SUCCESS;
229}
230
232void SGImplSvc::handle(const Incident &inc) {
233
234 if (inc.type() == "EndEvent") {
235 if (m_DumpStore) {
236 SG_MSG_DEBUG("Dumping StoreGate Contents");
237 info() << '\n' << dump() << endl
238 << endmsg;
239 }
240 }
241}
242
245 StatusCode sc(StatusCode::SUCCESS);
246 //FIXME this should probably be dealt with by the providers
247 if (0 != m_pPPS && !m_storeLoaded) {
248 m_storeLoaded = true;
249 sc=m_pPPS->loadProxies(*m_pStore);
250#ifdef DEBUG_SGIMPL
251 dbg::print(stderr, "SGImplSvc::loadEventProxies() LOADED PROXIES on {}\n", name());
252 }
253 else {
254 dbg::print(stderr, "SGImplSvc::loadEventProxies() PROXIES ALREADY LOADED on {}\n", name());
255#endif
256 }
257 return sc;
258}
259
261// Create a key for a type (used if the client has not specified a key)
262string SGImplSvc::createKey(const CLID& id)
263{
264 return std::to_string(m_pStore->typeCount(id) + 1);
265}
266
267// clear store
268StatusCode SGImplSvc::clearStore(bool forceRemove)
269{
270#ifdef DEBUG_SGIMPL
271 dbg::print(stderr, "SGImplSvc::clearStore(forceRemove={}) on {}\n", forceRemove, name());
272#endif
273 {
274 if (m_DumpArena) {
275 std::ostringstream s;
276 m_arena.report(s);
277 info() << "Report for Arena: " << m_arena.name() << '\n'
278 << s.str() << endmsg;
279 }
280 }
281 {
283 emptyTrash();
284 for (auto& p : m_newBoundHandles)
285 p.second.clear();
286 assert(m_pStore);
287 debug() << "Clearing store with forceRemove="
288 << forceRemove << endmsg;
289 bool hard_reset = (m_numSlots > 1);
290 m_pStore->clearStore(forceRemove, hard_reset, &msgStream(MSG::DEBUG));
291 m_storeLoaded=false; //FIXME hack needed by loadEventProxies
292 }
293 {
294 lock_t remap_lock (m_remapMutex);
295 m_remap_impl->m_remaps.clear();
296 m_arena.reset();
297 }
298
299 return StatusCode::SUCCESS;
300}
301
304 verbose() << "Finalizing " << name() << endmsg ;
305
306 // Incident service may not work in finalize.
307 // Clear this, so that we won't try to send an incident from clearStore.
308 (m_pIncSvc.release()).ignore();
309
310 const bool FORCEREMOVE(true);
311 clearStore(FORCEREMOVE).ignore();
312
313 m_stringpool.clear();
314 delete m_pStore;
315 m_pStore = nullptr;
316 delete m_remap_impl;
317 m_remap_impl = 0;
318 m_arena.erase();
319
320 return Service::finalize();
321}
322
325 verbose() << "Reinitializing " << name() << endmsg ;
326 const bool FORCEREMOVE(true);
327 clearStore(FORCEREMOVE).ignore();
328 //not in v20r2p2! return Service::reinitialize();
329 return StatusCode::SUCCESS;
330}
331
334// add proxy (with IOpaqueAddress that will later be retrieved from P)
336StatusCode SGImplSvc::recordAddress(const std::string& skey,
338 bool clearAddressFlag,
339 const std::vector<CLID>& bases)
340{
342 assert(0 != pAddress);
343 CLID dataID = pAddress->clID();
344
345 if (dataID == 0)
346 {
347 warning() << "recordAddress: Invalid Class ID found in IOpaqueAddress @"
348 << pAddress.get() << ". IOA will not be recorded"
349 << endmsg;
350 return StatusCode::FAILURE;
351 }
352
353 //do not overwrite a persistent object
354 if (m_pPPS) {
355 DataProxy* dp = m_pStore->proxy (dataID, skey);
356 if (!dp) {
357 dp = m_pPPS->retrieveProxy(dataID, skey, *m_pStore);
358 }
359 if (dp && dp->provider()) {
360 std::string clidTypeName;
361 m_pCLIDSvc->getTypeNameOfID(dataID, clidTypeName).ignore();
362 warning() << "recordAddress: failed for key="<< skey << ", type "
363 << clidTypeName
364 << " (CLID " << dataID << ')'
365 << "\n there is already a persistent version of this object. Will not record a duplicate! "
366 << endmsg;
367 return StatusCode::FAILURE;
368 }
369 }
370
371 // Check if a key already exists
372 DataProxy* dp = m_pStore->proxy_exact(dataID, skey);
373 if (0 == dp && 0 != m_pPPS) {
374 dp = m_pPPS->retrieveProxy(dataID, skey, *m_pStore);
375 }
376
377 // Now treat the various cases:
378 if (0 == dp)
379 {
380 // create the proxy object and register it
381 dp = new DataProxy (TransientAddress (dataID, skey,
382 std::move(pAddress),
383 clearAddressFlag),
384 m_pDataLoader.get(), true, true);
385 m_pStore->addToStore(dataID, dp).ignore();
386
387 addAutoSymLinks (skey, dataID, dp, 0, false);
388
389 // Add extra bases.
390 for (CLID b : bases) {
391 if (addSymLink (b, dp).isFailure()) {
392 warning() << std::format ("Can't add extra base {} for object {}/{}",
393 b, dataID, skey) << endmsg;
394 }
395 }
396 }
397 else if ((0 != dp) && (0 == dp->address()))
398 // Note: intentionally not checking dp->isValidAddress()
399 {
400 // Update proxy with IOpaqueAddress
401 dp->setAddress(std::move(pAddress));
402 }
403 else
404 {
405 string errType;
406 m_pCLIDSvc->getTypeNameOfID(dataID, errType).ignore();
407 warning() << "recordAddress: preexisting proxy @" << dp
408 << " with non-NULL IOA found for key "
409 << skey << " type " << errType << " (" << dataID << "). \n"
410 << "Cannot record IOpaqueAddress @" << pAddress.get()
411 << endmsg;
412 return StatusCode::FAILURE;
413 }
414
415 return StatusCode::SUCCESS;
416
417}
418
421// add proxy (with IOpaqueAddress that will later be retrieved from P)
424 bool clearAddressFlag,
425 const std::vector<CLID>& bases)
426{
428 assert(0 != pAddress);
429
430 CLID dataID = pAddress->clID();
431
432 string gK = (pAddress->par())[1]; // transient name by convention
433 if (gK.empty()) gK = (pAddress->par())[0]; // FIXME backward compatibility
434 if (gK.empty()) gK = createKey(dataID);
435
436 return this->recordAddress(gK, std::move(pAddress), clearAddressFlag, bases);
437}
438
440 const string& gK,
441 DataObject* pDObj,
442 bool allowMods,
443 bool resetOnly) {
444 // locate the proxy
445 DataProxy* dp = m_pStore->proxy_exact(dataID, gK);
446
447 if (0 != dp) { //proxy found
448 if (0 != dp->object())
449 {
450 // Case 0: duplicated proxy
451 warning() << " setupProxy:: error setting up proxy for key "
452 << gK << " and clid " << dataID
453 << "\n Pre-existing valid DataProxy @"<< dp
454 << " found in Store for key " << dp->object()->name()
455 << " with clid " << dp->object()->clID()
456 << endmsg;
457 recycle(pDObj); // commit this object to trash
458 dp = 0;
459 } else {
460 // Case 1: Proxy found... if not valid, update it:
461 dp->setObject(pDObj);
462 if (!allowMods) dp->setConst();
463 }
464 } else {
465 // Case 2: No Proxy found:
466 dp = new DataProxy(pDObj,
467 TransientAddress(dataID, gK),
468 !allowMods, resetOnly);
469 if (!(m_pStore->addToStore(dataID, dp).isSuccess())) {
470 warning() << " setupProxy:: could not addToStore proxy @" << dp
471 << endmsg;
472 recycle(pDObj); // commit this object to trash
473 delete dp;
474 dp = 0;
475 }
476 }
477 return dp;
478}
479
486
488{
490 return store()->storeID();
491}
492
493
494void
495SGImplSvc::keys(const CLID& id, std::vector<std::string>& vkeys,
496 bool includeAlias, bool onlyValid)
497
498{
500 return store()->keys(id, vkeys, includeAlias, onlyValid);
501}
502
503
504bool SGImplSvc::isSymLinked(const CLID& linkID, DataProxy* dp)
505{
506 return (0 != dp) ? dp->transientID(linkID) : false;
507}
508
510// Dump Contents in store:
511string SGImplSvc::dump() const
512{
514 auto out_buffer = std::string{};
515 auto out = std::back_inserter(out_buffer);
516 const std::string me = name();
517 std::format_to(out, "{}: <<<<<<<<<<<<<<<<< Data Store Dump >>>>>>>>>>>>>>> \n", me);
518 std::format_to(out, "{}: SGImplSvc()::dump() which is {} \n", me, m_storeLoaded ? "LOADED" : "NOT LOADED");
519
520 DataStore::ConstStoreIterator s_iter, s_end;
521 store()->tRange(s_iter, s_end).ignore();
522
523 for (; s_iter != s_end; ++s_iter)
524 {
525
526 CLID id = s_iter->first;
527 int nProxy = store()->typeCount(id);
528 std::string tname;
529 m_pCLIDSvc->getTypeNameOfID(id, tname).ignore();
530 std::format_to(out, "{}: Found {} {} for ClassID {} ({}): \n", me, nProxy, ((nProxy == 1) ? "proxy" : "proxies"), id, tname);
531
532 // loop over each type:
533 SG::ConstProxyIterator p_iter = (s_iter->second).begin();
534 SG::ConstProxyIterator p_end = (s_iter->second).end();
535
536 while (p_iter != p_end) {
537 const DataProxy& dp(*p_iter->second);
538 std::format_to(out, "{}: flags: ({:7s}, {:8s}, {:6s}) --- data: {:10p} --- key: {}\n", me,
539 (dp.isValid() ? "valid" : "INVALID"),
540 (dp.isConst() ? "locked" : "UNLOCKED"),
541 (dp.isResetOnly() ? "reset" : "DELETE"),
542 dbg::ptr(dp.object()), p_iter->first);
543 ++p_iter;
544 }
545 }
546 std::format_to(out, "{}: <<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>> \n", me);
547 return out_buffer;
548}
549
550DataStore*
552{
553 return m_pStore;
554}
555
556const DataStore*
558{
559 return m_pStore;
560}
561
562
564// Make a soft link to the object with key
566StatusCode SGImplSvc::symLink(const void* pObject, CLID linkID)
567{
569 SG::DataProxy* dp(proxy(pObject));
570
571 // if symLink already exists, just return success
572 return isSymLinked(linkID,dp) ?
573 StatusCode::SUCCESS :
574 addSymLink(linkID,dp);
575}
576
577StatusCode SGImplSvc::symLink(const CLID id, const std::string& key, const CLID linkID)
578{
580 SG::DataProxy* dp(proxy(id, key, false));
581 // if symLink already exists, just return success
582 return isSymLinked(linkID,dp) ?
583 StatusCode::SUCCESS :
584 addSymLink(linkID,dp);
585}
586
587
588StatusCode
590{
591 if (0 == dp) {
592 warning() << "addSymLink: no target DataProxy found. Sorry, can't link to a non-existing data object"
593 << endmsg;
594 return StatusCode::FAILURE;
595 }
596 StatusCode sc = m_pStore->addSymLink(linkid, dp);
597
598 // If the symlink is a derived->base conversion, then we may have
599 // a different transient pointer for the symlink.
600 if (sc.isSuccess() && dp->object()) {
601 void* baseptr = SG::DataProxy_cast (dp, linkid);
602 if (baseptr)
603 this->t2pRegister (baseptr, dp).ignore();
604 }
605 return sc;
606}
607
608
609StatusCode SGImplSvc::setAlias(const void* pObject, const std::string& aliasKey)
610{
612
613 SG::DataProxy* dp(0);
614 dp = proxy(pObject);
615 if (0 == dp) {
616 error() << "setAlias: problem setting alias "
617 << aliasKey << '\n'
618 << "DataObject does not exist, record before setting alias."
619 << endmsg;
620 return StatusCode::FAILURE;
621 }
622
623 StatusCode sc = addAlias(aliasKey, dp);
624 if (sc.isFailure()) {
625 error() << "setAlias: problem setting alias "
626 << aliasKey << '\n'
627 << "DataObject does not exist, record before setting alias."
628 << endmsg;
629 return StatusCode::FAILURE;
630 }
631
632 return StatusCode::SUCCESS;
633}
634
635
637 const std::string& key, const std::string& aKey)
638{
640
641 SG::DataProxy* dp(0);
642 dp = proxy(clid, key);
643 if (0 == dp) {
644 error() << "setAlias: problem setting alias "
645 << std::string(aKey) << '\n'
646 << "DataObject does not exist, record before setting alias."
647 << endmsg;
648 return StatusCode::FAILURE;
649 }
650
651 StatusCode sc = addAlias(aKey, dp);
652 if (sc.isFailure()) {
653 error() << "setAlias: problem setting alias "
654 << (std::string)aKey << '\n'
655 << "DataObject does not exist, record before setting alias."
656 << endmsg;
657 return StatusCode::FAILURE;
658 }
659
660 return StatusCode::SUCCESS;
661}
662
663StatusCode SGImplSvc::setAlias(SG::DataProxy* proxy, const std::string& aliasKey)
664{
665 return addAlias( aliasKey, proxy );
666}
667
668StatusCode
669SGImplSvc::addAlias(const std::string& aliasKey, DataProxy* proxy)
670{
671 if (0 == proxy) {
672 warning() << "addAlias: no target DataProxy given, Cannot alias to a non-existing object"
673 << endmsg;
674 return StatusCode::FAILURE;
675 }
676
677 // add key to proxy and to ProxyStore
678 return m_pStore->addAlias(aliasKey, proxy);
679}
680
681int SGImplSvc::typeCount(const CLID& id) const
682{
684 return m_pStore->typeCount(id);
685}
686
687
688bool
689SGImplSvc::contains(const CLID id, const std::string& key) const
690{
691 try {
692 return (0 != proxy(id, key, true));
693 } catch(...) { return false; }
694}
695
696
697bool
698SGImplSvc::transientContains(const CLID id, const std::string& key) const
699{
700 try {
701 return (0 != transientProxy(id, key));
702 } catch(...) { return false; }
703}
704
705
706DataProxy*
707SGImplSvc::proxy(const void* const pTransient) const
708{
709 // No lock needed here --- the T2pmap held by DataStore has its own locking
710 // (and we were seeing contention here).
711 //lock_t lock (m_mutex);
712 return m_pStore->locatePersistent(pTransient);
713}
714
715DataProxy*
716SGImplSvc::proxy(const CLID& id) const
717{
718 return proxy(id, false);
719}
720
721DataProxy*
722SGImplSvc::proxy(const CLID& id, bool checkValid) const
723{
724 DataProxy* dp = nullptr;
725 {
727 dp = m_pStore->proxy(id);
728 if (0 == dp && 0 != m_pPPS) {
730 dp = m_pPPS->retrieveProxy(id, string("DEFAULT"), *pStore);
731 }
732 }
734 // Be sure to release the lock before this.
735 // isValid() may call back to the store, so we could otherwise deadlock..
736 if (checkValid && 0 != dp) {
737 // FIXME: For keyless retrieve, this checks only the first instance
738 // of the CLID in store. If that happens to be invalid, but the second
739 // is valid - this does not work (when checkValid is requested).
740 return dp->isValid() ? dp : 0;
741 }
742 return dp;
743}
744
745DataProxy*
746SGImplSvc::proxy(const CLID& id, const string& key) const
747{
748 return proxy(id, key, false);
749}
750
752SGImplSvc::proxy(const CLID& id, const string& key, bool checkValid) const
753{
754 DataProxy* dp = nullptr;
755 {
757 dp = m_pStore->proxy(id, key);
758#ifdef DEBUG_SGIMPL
759 if (!dp) dbg::print(stderr, "::SGImplSvc::proxy(name={}, key={}): data proxy is null, m_pPPS is {}\n", this->name(), key, m_pPPS == 0 ? "NULL" : "NOT NULL");
760#endif
761 if (0 == dp && 0 != m_pPPS) {
763 dp = m_pPPS->retrieveProxy(id, key, *pStore);
764#ifdef DEBUG_SGIMPL
765 if (!dp) dbg::print(stderr, "::SGImplSvc::proxy(name={}, key={}): data proxy is still null\n", this->name(), key);
766#endif
767 }
768 }
769 // Be sure to release the lock before this.
770 // isValid() may call back to the store, so we could otherwise deadlock..
771 if (checkValid && 0 != dp && !(dp->isValid())) {
772 dp = 0;
773 }
774 return dp;
775}
776
777
784{
786 return m_pStore->addToStore (id, proxy);
787}
788
789
811 const std::string& key,
812 bool allowMods,
813 bool returnExisting)
814{
816 const void* raw_ptr = obj.get();
817 const std::type_info* tinfo = nullptr;
818
819 if (DataBucketBase* bucket = dynamic_cast<DataBucketBase*> (obj.get())) {
820 raw_ptr = bucket->object();
821 tinfo = &bucket->tinfo();
822 }
823
824 if (returnExisting) {
825 SG::DataProxy* proxy = this->proxy (obj->clID(), key);
826 if (proxy && proxy->isValid()) return proxy;
827
828 // Look for the same object recorded under a different key/clid.
829 proxy = this->proxy (raw_ptr);
830 if (proxy && proxy->isValid()) {
831 if (proxy->transientID (obj->clID())) {
832 // CLID matches. Make an alias.
833 if (addAlias (key, proxy).isFailure()) {
834 CLID clid = proxy->clID();
835 std::string clidTypeName;
836 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
837 warning() << "SGImplSvc::recordObject: addAlias fails for object "
838 << clid << "[" << clidTypeName << "] " << proxy->name()
839 << " and new key " << key
840 << endmsg;
841
842 proxy = nullptr;
843 }
844 }
845
846 else if (key == proxy->name() || proxy->hasAlias(key) > 0)
847 {
848 // key matches. Make a symlink.
849 if (addSymLink (obj->clID(), proxy).isFailure()) {
850 CLID clid = proxy->clID();
851 std::string clidTypeName;
852 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
853 CLID newclid = obj->clID();
854 std::string newclidTypeName;
855 m_pCLIDSvc->getTypeNameOfID(newclid, newclidTypeName).ignore();
856 error() << "SGImplSvc::recordObject: addSymLink fails for object "
857 << clid << "[" << clidTypeName << "] " << proxy->name()
858 << " and new clid " << newclid << "[" << newclidTypeName << "]"
859 << endmsg;
860 proxy = nullptr;
861 }
862 }
863
864 else {
865 CLID clid = proxy->clID();
866 std::string clidTypeName;
867 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
868 CLID newclid = obj->clID();
869 std::string newclidTypeName;
870 m_pCLIDSvc->getTypeNameOfID(newclid, newclidTypeName).ignore();
871 error() << "SGImplSvc::recordObject: existing object found with "
872 << clid << "[" << clidTypeName << "] " << proxy->name()
873 << " but neither clid " << newclid << "[" << newclidTypeName << "]"
874 << " nor key " << key << " match."
875 << endmsg;
876 proxy = nullptr;
877 }
878
879 return proxy;
880 }
881 }
882
883 const bool resetOnly = true;
884 const bool noHist = false;
885 SG::DataProxy* proxy = nullptr;
886 if (this->typeless_record (obj.get(), key, raw_ptr,
887 allowMods, resetOnly, noHist, tinfo,
888 &proxy, true).isFailure())
889 {
890 return nullptr;
891 }
892 return proxy;
893}
894
895
900{
901 return m_pStore->proxy_exact_unlocked (sgkey, m_mutex);
902}
903
904
911void SGImplSvc::setSlotNumber (int slot, int numSlots)
912{
913 m_slotNumber = slot;
914 m_numSlots = numSlots;
915
917 header->setArenaForSlot (slot, &m_arena);
918}
919
920
921std::vector<const SG::DataProxy*>
923{
925 const std::vector<SG::DataProxy*>& proxies = store()->proxies();
926 std::vector<const SG::DataProxy*> ret (proxies.begin(), proxies.end());
927 return ret;
928}
929
930
931std::vector<CLID>
933{
935
936 using std::distance;
937 DataStore::ConstStoreIterator s_iter, s_end;
938 store()->tRange(s_iter, s_end).ignore();
939
940 std::vector<CLID> clids;
941 clids.reserve( distance( s_iter, s_end ) );
942
943 for (; s_iter != s_end; ++s_iter ) {
944 const CLID id = s_iter->first;
945 clids.push_back (id);
946 }
947
948 return clids;
949}
950
951
953SGImplSvc::transientProxy(const CLID& id, const string& key) const
954{
956 DataProxy* dp(m_pStore->proxy(id, key));
957 return ( (0 != dp && dp->isValidObject()) ? dp : 0 );
958}
959
960DataObject*
962{
964 DataProxy* theProxy(proxy(id, true));
965 return (0 == theProxy) ? 0 : theProxy->accessData();
966}
967
968DataObject*
969SGImplSvc::accessData(const CLID& id, const string& key) const
970{
972 DataProxy* theProxy(proxy(id, key, true));
973 return (0 == theProxy) ? 0 : theProxy->accessData();
974}
975
976bool
978 const std::string& keyA, const std::string& keyB )
979{
981 const bool checkValid = true;
982 DataProxy* a = proxy( id, keyA, checkValid );
983 DataProxy* b = proxy( id, keyB, checkValid );
984 if ( 0 == a || 0 == b ) { return false; }
985 DataObject* objA = a->accessData();
986 DataObject* objB = b->accessData();
987
988 if ( 0 == objA || 0 == objB ) { return false; }
989 // prevent 'accidental' release of DataObjects...
990 const unsigned int refCntA = objA->addRef();
991 const unsigned int refCntB = objB->addRef();
992 // in case swap is being specialized for DataObjects
993 using std::swap;
994 swap( objA, objB );
995 a->setObject( objA );
996 b->setObject( objB );
997 // and then restore old ref-count;
998 return ( (refCntA-1) == objA->release() &&
999 (refCntB-1) == objB->release() );
1000}
1001
1002StatusCode
1003SGImplSvc::typeless_record( DataObject* obj, const std::string& key,
1004 const void* const raw_ptr,
1005 bool allowMods, bool resetOnly, bool noHist)
1006{
1007 return typeless_record (obj, key, raw_ptr, allowMods, resetOnly, noHist, 0,
1008 nullptr, true);
1009}
1010
1011
1012StatusCode
1013SGImplSvc::typeless_record( DataObject* obj, const std::string& key,
1014 const void* const raw_ptr,
1015 bool allowMods, bool resetOnly, bool noHist,
1016 const std::type_info* tinfo)
1017{
1018 return typeless_record (obj, key, raw_ptr, allowMods, resetOnly, noHist,tinfo,
1019 nullptr, true);
1020}
1021
1022
1023StatusCode
1024SGImplSvc::typeless_record( DataObject* obj, const std::string& key,
1025 const void* const raw_ptr,
1026 bool allowMods, bool resetOnly, bool noHist,
1027 const std::type_info* tinfo,
1028 SG::DataProxy** proxy_ret,
1029 bool noOverwrite)
1030{
1033 record_impl( obj, key, raw_ptr, allowMods, resetOnly, !noOverwrite, tinfo);
1034 if ( proxy == nullptr )
1035 return StatusCode::FAILURE;
1036 if (proxy_ret)
1037 *proxy_ret = proxy;
1038
1039 if ( !m_ActivateHistory || noHist ) {
1040 return StatusCode::SUCCESS;
1041 }
1042
1043 if ( store()->storeID() != StoreID::EVENT_STORE ) {
1044 return StatusCode::SUCCESS;
1045 } else {
1046 return record_HistObj( obj->clID(), key, name(), allowMods, resetOnly );
1047 }
1048}
1049
1050StatusCode
1052 DataObject* obj,
1053 const std::string& key,
1054 const void* const raw_ptr,
1055 bool allowMods,
1056 bool noHist,
1057 const std::type_info* tinfo)
1058{
1060 StatusCode sc(StatusCode::SUCCESS);
1061 SG::DataProxy* toRemove(proxy(clid, key, false));
1062 if (0 != toRemove) {
1063 toRemove->addRef();
1064 const bool FORCEREMOVE(true);
1065 sc =removeProxy(toRemove, (void*)0, FORCEREMOVE);
1066 }
1067 if (sc.isSuccess()) {
1068 const bool ALLOWOVERWRITE(true);
1069 const bool NORESET(false);
1070 if (record_impl( obj, key, raw_ptr, allowMods, NORESET, ALLOWOVERWRITE, tinfo) == nullptr)
1071 sc = StatusCode::FAILURE;
1072 else if ( m_ActivateHistory && noHist && store()->storeID() == StoreID::EVENT_STORE ) {
1073 sc = record_HistObj( obj->clID(), key, name(), allowMods, NORESET );
1074 }
1075 }
1076 //for detector store objects managed by IIOVSvc, replace the old proxy with the new one (#104311)
1077 if (toRemove && sc.isSuccess() && store()->storeID() == StoreID::DETECTOR_STORE) {
1078 sc = m_pIOVSvc->replaceProxy(toRemove, proxy(clid, key));
1079 }
1080 if (toRemove)
1081 toRemove->release();
1082 return sc;
1083}
1084
1086SGImplSvc::record_impl( DataObject* pDObj, const std::string& key,
1087 const void* const raw_ptr,
1088 bool allowMods, bool resetOnly, bool allowOverwrite,
1089 const std::type_info* tinfo)
1090{
1091 CLID clid = pDObj->clID();
1092 std::string rawKey(key);
1093 bool isVKey(SG::VersionedKey::isVersionedKey(key));
1094 if (isVKey) {
1095 //FIXME VersionedKeys will need to be handled more efficiently
1096 SG::VersionedKey vk(rawKey);
1097 DataProxy *dp(proxy(clid, vk.key()));
1098 if (dp) {
1099 //proxies primary key
1100 const std::string& pTAName(dp->name());
1101 //original key as versioned
1102 SG::VersionedKey primaryVK(pTAName);
1103
1104 //if the existing matching object has no version
1105 //create a versioned alias for the original unversioned key
1106 //so it will remain accessible
1107 if (!SG::VersionedKey::isVersionedKey(pTAName)) {
1108 if (!(this->addAlias(primaryVK.rawVersionKey(), dp)).isSuccess()) {
1109 warning() << "record_impl: Could not setup alias key "
1110 << primaryVK.rawVersionKey()
1111 << " for unversioned object " << pTAName
1112 << endmsg;
1113 return nullptr;
1114 }
1115 }
1116 if (vk.isAuto()) {
1117 //make a new versioned key incrementing the existing version
1118 SG::VersionedKey newVK(primaryVK.key(), primaryVK.version()+1);
1119 //FIXME this will fail in a confusing way if version+1 is in use
1120 //FIXME need a better error message below, probably looking at all
1121 //FIXME aliases
1122 rawKey = newVK.rawVersionKey();
1123 }
1124 }
1125 }
1126 if (!allowOverwrite && m_pPPS) {
1127 //do not overwrite a persistent object
1128 DataProxy* dp = m_pStore->proxy (clid, rawKey);
1129 if (!dp) {
1130 dp = m_pPPS->retrieveProxy(clid, rawKey, *m_pStore);
1131 }
1132 if (dp && dp->provider()) {
1133 std::string clidTypeName;
1134 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1135 warning() << "record_impl: you are recording an object with key "
1136 << rawKey << ", type " << clidTypeName
1137 << " (CLID " << clid << ')'
1138 << "\n There is already a persistent version of this object. Recording a duplicate may lead to unreproducible results and it is deprecated."
1139 << endmsg;
1140 }
1141 }
1142 //now check whether raw_ptr has already been recorded
1143 //We need to do this before we create the bucket, the proxy etc
1144 SG::DataProxy* dp(proxy(raw_ptr));
1145 if (0 != dp) {
1146 std::string clidTypeName;
1147 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1148 warning() << "record_impl: failed for key="<< rawKey << ", type "
1149 << clidTypeName
1150 << " (CLID " << clid << ')'
1151 << "\n object @" << raw_ptr
1152 << " already in store with key="<< dp->name()
1153 << ". Will not record a duplicate! "
1154 << endmsg;
1155 if (pDObj != dp->object()) {
1156 DataBucketBase* pDBB(dynamic_cast<DataBucketBase*>(pDObj));
1157 if (!pDBB) std::abort();
1158 pDBB->relinquish(); //don't own the data obj already recorded!
1159 }
1160 this->recycle(pDObj);
1161 return nullptr;
1162 }
1163
1164
1165 // setup the proxy
1166 dp = setupProxy( clid, rawKey, pDObj, allowMods, resetOnly );
1167 if ( 0 == dp ) {
1168 std::string clidTypeName;
1169 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1170 warning() << "record_impl: Problem setting up the proxy for object @"
1171 << raw_ptr
1172 << "\n recorded with key " << rawKey
1173 << " of type " << clidTypeName
1174 << " (CLID " << clid << ") in DataObject @" << pDObj
1175 << endmsg;
1176
1177 return nullptr;
1178 }
1179
1180 // record in t2p:
1181 if ( !(this->t2pRegister( raw_ptr, dp )).isSuccess() ) {
1182 std::string clidTypeName;
1183 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1184 warning() << "record_impl: can not add to t2p map object @" <<raw_ptr
1185 << "\n with key " << rawKey
1186 << " of type " << clidTypeName
1187 << " (CLID " << clid << ')'
1188 << endmsg;
1189 return nullptr;
1190 }
1191
1192 addAutoSymLinks (rawKey, clid, dp, tinfo);
1193
1194 //handle versionedKeys: we register an alias with the "true" key
1195 //unless an object as already been recorded with that key.
1196 //Notice that addAlias overwrites any existing alias, so a generic
1197 //retrieve will always return the last version added
1198 //FIXME not the one with the highest version
1199 if (isVKey) {
1200 SG::VersionedKey vk(rawKey);
1201 if (!(this->addAlias(vk.key(), dp)).isSuccess()) {
1202 warning() << "record_impl: Could not setup alias key " << vk.key()
1203 << " for VersionedKey " << rawKey
1204 << ". Generic access to this object with clid" << clid
1205 << " will not work"
1206 << endmsg;
1207 }
1208 }
1209
1210 return dp;
1211}
1212
1213DataProxy*
1215 bool checkValid) const
1216{
1217 DataProxy* dp = m_pStore->proxy(tAddr);
1218
1219 if (checkValid && 0 != dp) {
1220 return dp->isValid() ? dp : 0;
1221 } else {
1222 return dp;
1223 }
1224}
1225
1226StatusCode
1228 bool forceRemove)
1229{
1231 // check if valid proxy
1232 if (0 == proxy) return StatusCode::FAILURE;
1233
1234 if (0 == pTrans) {
1235 DataBucketBase* bucket = dynamic_cast<DataBucketBase*>(proxy->object());
1236 if (bucket) pTrans = bucket->object();
1237 }
1238
1239 // remove all entries from t2p map
1240 // --- only if the proxy actually has an object!
1241 // otherwise, we can trigger I/O.
1242 // besides being useless here, we can get deadlocks if we
1243 // call into the I/O code while holding the SG lock.
1244 if (proxy->isValidObject()) {
1245 this->t2pRemove(pTrans);
1246 SG::DataProxy::CLIDCont_t clids = proxy->transientID();
1247 for (SG::DataProxy::CLIDCont_t::const_iterator i = clids.begin();
1248 i != clids.end();
1249 ++i)
1250 {
1251 void* ptr = SG::DataProxy_cast (proxy, *i);
1252 this->t2pRemove(ptr);
1253 }
1254 }
1255
1256 // remove from store
1257 return m_pStore->removeProxy(proxy, forceRemove, true);
1258}
1259
1260StatusCode
1261SGImplSvc::t2pRegister(const void* const pTrans, DataProxy* const pPers)
1262{
1263 return m_pStore->t2pRegister(pTrans, pPers);
1264}
1265
1266
1267void
1268SGImplSvc::t2pRemove(const void* const pTrans)
1269{
1270 m_pStore->t2pRemove(pTrans);
1271}
1272
1273void
1274SGImplSvc::msg_update_handler(Gaudi::Details::PropertyBase& /*outputLevel*/)
1275{
1276 setUpMessaging();
1277 updateMsgStreamOutputLevel( outputLevel() );
1278 msgSvc()->setOutputLevel(name(), outputLevel());
1279}
1280
1281StatusCode
1284 SG::ConstProxyIterator& end) const {
1286 return m_pStore->pRange(id,begin,end);
1287}
1288
1289StatusCode SGImplSvc::setConst(const void* pObject)
1290{
1292 // Check if DataProxy does not exist
1293 DataProxy * dp = proxy(pObject);
1294
1295 if (0 == dp)
1296 {
1297 warning() << "setConst: NO Proxy for the dobj you want to set const"
1298 << endmsg;
1299 return StatusCode::FAILURE;
1300 }
1301
1302 dp->setConst();
1303 return StatusCode::SUCCESS;
1304}
1305
1306
1307// remove an object from Store, will remove its proxy if not reset only
1308StatusCode
1309SGImplSvc::remove(const void* pObject)
1310{
1312 return removeProxy(proxy(pObject), pObject);
1313}
1314
1315
1316// remove an object and its proxy from Store
1317StatusCode
1319{
1321 const bool FORCEREMOVE(true);
1322 return removeProxy(proxy(pObject), pObject, FORCEREMOVE);
1323}
1324
1325//put a bad (unrecordable) dobj away
1326void SGImplSvc::recycle(DataObject* pBadDObj) {
1327 assert(pBadDObj);
1328 pBadDObj->addRef();
1329 m_trash.push_back(pBadDObj);
1330}
1331
1332//throw away bad objects
1335 while (!m_trash.empty()) {
1336 m_trash.front()->release(); //delete the bad data object
1337 m_trash.pop_front(); //remove pointer from list
1338 }
1339}
1340
1341
1342/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1343
1344StatusCode
1345SGImplSvc::record_HistObj(const CLID& id, const std::string& key,
1346 const std::string& store,
1347 bool allowMods, bool resetOnly) {
1348
1349 DataHistory *dho;
1350 dho = m_pHistorySvc->createDataHistoryObj( id, key, store );
1351
1352 std::string idname;
1353 StatusCode sc = m_pCLIDSvc->getTypeNameOfID(id, idname);
1354 if (sc.isFailure() || idname.empty() ) {
1355 idname = std::to_string(id);
1356 }
1357 idname += '/';
1358 idname += key;
1359
1360 DataObject* obj = SG::asStorable(dho);
1361
1362 const bool ALLOWOVERWRITE(false);
1363 if (record_impl(obj, idname, dho, allowMods, resetOnly, ALLOWOVERWRITE,
1364 &typeid(DataHistory)) == nullptr)
1365 return StatusCode::FAILURE;
1366 return StatusCode::SUCCESS;
1367}
1368
1369
1380{
1382 return m_stringpool.stringToKey (str, clid);
1383}
1384
1385
1393const std::string* SGImplSvc::keyToString (sgkey_t key) const
1394{
1396 return m_stringpool.keyToString (key);
1397}
1398
1399
1408const std::string*
1410{
1412 return m_stringpool.keyToString (key, clid);
1413}
1414
1415
1429 const std::string& str,
1430 CLID clid)
1431{
1433 if (!m_stringpool.registerKey (key, str, clid)) {
1434 CLID clid2;
1435 const std::string* str2 = m_stringpool.keyToString (key, clid2);
1436 REPORT_MESSAGE (MSG::WARNING) << "The numeric key " << key
1437 << " maps to multiple string key/CLID pairs: "
1438 << *str2 << "/" << clid2 << " and "
1439 << str << "/" << clid;
1440 }
1441}
1442
1443
1452{
1453 // We should hold m_stringPoolMutex before touching the pool.
1454 // But if we acquire the locks for both this and the other store,
1455 // we risk a deadlock. So first copy the other pool, so that we
1456 // don't need to hold both locks at the same time.
1457 SG::StringPool tmp;
1458 {
1459 lock_t lock (other.m_stringPoolMutex);
1460 tmp = other.m_stringpool;
1461 }
1463 return m_stringpool.merge (tmp);
1464}
1465
1466
1467void
1468SGImplSvc::releaseObject(const CLID& id, const std::string& key) {
1470 DataProxy *pP(0);
1471 if (0 != (pP = proxy(id, key))) {
1472 // remove all entries from t2p map
1474 SG::DataProxy::CLIDCont_t::const_iterator i(clids.begin()), e(clids.end());
1475 while (i != e) t2pRemove(SG::DataProxy_cast (pP, *i++));
1476 DataBucketBase *pDBB(dynamic_cast<DataBucketBase*>(pP->object()));
1477 //tell the bucket to let go of the data object
1478 if (0 != pDBB) pDBB->relinquish(); //somebody else better took ownership
1479 bool hard_reset = (m_numSlots > 1);
1480 pP->reset (hard_reset);
1481 }
1482}
1483
1484void
1487
1488 // Remove transient pointer entries for this proxy.
1489 // But do that only if the proxy has a valid object.
1490 // Otherwise, we could trigger I/O --- which we don't want since it's useless
1491 // (we'd just destroy the object immediately). In some cases it can also
1492 // lead to a deadlock (see ATR-24482).
1493 if (dp->isValidObject()) {
1494 SG::DataProxy::CLIDCont_t clids = dp->transientID();
1495 SG::DataProxy::CLIDCont_t::const_iterator i(clids.begin()), e(clids.end());
1496 while (i != e) {
1497 t2pRemove(SG::DataProxy_cast (dp, *i++));
1498 }
1499 }
1500
1501 bool hard_reset = (m_numSlots > 1);
1502 dp->reset (hard_reset);
1503}
1504
1505
1514 sgkey_t target,
1515 off_t index_offset)
1516{
1518 SG::RemapImpl::remap_t payload;
1519 payload.target = target;
1520 payload.index_offset = index_offset;
1521 m_remap_impl->m_remaps[source] = payload;
1522}
1523
1524
1533bool SGImplSvc::tryELRemap (sgkey_t sgkey_in, size_t index_in,
1534 sgkey_t& sgkey_out, size_t& index_out)
1535{
1537 SG::RemapImpl::remap_map_t::iterator i =
1538 m_remap_impl->m_remaps.find (sgkey_in);
1539 if (i == m_remap_impl->m_remaps.end())
1540 return false;
1541 const SG::RemapImpl::remap_t& payload = i->second;
1542 sgkey_out = payload.target;
1543 index_out = index_in + payload.index_offset;
1544 return true;
1545}
1546
1547
1549 const std::string& key)
1550{
1552 DataObject* obj = nullptr;
1553 SG::DataProxy* dp = proxy (clid, key);
1554 //we do not want anyone to mess up with our copy hence we release it immediately.
1555 if (dp && dp->isValid()) {
1556 obj = dp->object();
1557 obj->addRef();
1558 clearProxyPayload (dp);
1559 }
1560 return obj;
1561}
1562
1563
1564CLID SGImplSvc::clid( const std::string& key ) const
1565{
1568 store()->tRange(s_iter, s_end).ignore();
1569
1570 for ( ; s_iter != s_end; ++s_iter ) {
1571 if ( s_iter->second.find( key ) != s_iter->second.end() ) {
1572 return s_iter->first;
1573 }
1574 }
1575
1576 return CLID_NULL;
1577}
1578
1579
1580std::vector<CLID> SGImplSvc::clids( const std::string& key ) const
1581{
1583 std::vector<CLID> clids;
1585 store()->tRange(s_iter, s_end).ignore();
1586
1587 for ( ; s_iter != s_end; ++s_iter ) {
1588 if ( s_iter->second.find( key ) != s_iter->second.end() ) {
1589 clids.push_back(s_iter->first);
1590 }
1591 }
1592
1593 return clids;
1594}
1595
1596
1598void SGImplSvc::addAutoSymLinks (const std::string& key,
1599 CLID clid,
1600 DataProxy* dp,
1601 const std::type_info* tinfo,
1602 bool warn_nobib /*= true*/)
1603{
1604 // Automatically make all legal base class symlinks
1605 if (!tinfo) {
1607 }
1608 const SG::BaseInfoBase* bib = nullptr;
1609 if (tinfo) {
1610 bib = SG::BaseInfoBase::find (*tinfo);
1611 }
1612 if (!bib) {
1613 // Could succeed where the previous fails if clid for DataVector<T>
1614 // but tinfo is for ConstDataVector<DataVector<T> >.
1616 }
1617 if ( bib ) {
1618 const std::vector<CLID>& bases = bib->get_bases();
1619 for ( std::size_t i = 0, iMax = bases.size(); i < iMax; ++i ) {
1620 if ( bases[i] != clid ) {
1621 if ( addSymLink( bases[i], dp ).isSuccess() ) {
1622 // register with t2p
1623 if (dp->object())
1624 this->t2pRegister( SG::DataProxy_cast( dp, bases[i] ), dp ).ignore();
1625 }
1626 else {
1627 warning() << "record_impl: Doing auto-symlinks for object with CLID "
1628 << clid
1629 << " and SG key " << key
1630 << ": Proxy already set for base CLID " << bases[i]
1631 << "; not making auto-symlink." << endmsg;
1632 }
1633 }
1634 }
1635
1636 // Handle copy conversions.
1637 {
1638 for (CLID copy_clid : bib->get_copy_conversions()) {
1639 if (m_pStore->addSymLink (copy_clid, dp).isFailure()) {
1640 warning() << "record_impl: Doing auto-symlinks for object with CLID "
1641 << clid
1642 << " and SG key " << key
1643 << ": Proxy already set for copy-conversion CLID "
1644 << copy_clid
1645 << "; not making auto-symlink." << endmsg;
1646 }
1647 }
1648 }
1649 }
1650 else {
1651 if (warn_nobib) {
1652 warning() << "record_impl: Could not find suitable SG::BaseInfoBase for CLID ["
1653 << clid << "] (" << key << ") !\t"
1654 << "No auto-symlink established !"
1655 << endmsg;
1656 }
1657 }
1658}
1659
1660void
1663
1664 // Reset handles added since the last call to commit.
1665 bool hard_reset = (m_numSlots > 1);
1666 std::vector<IResetable*> handles;
1667 m_newBoundHandles[std::this_thread::get_id()].swap (handles);
1668 for (IResetable* h : handles)
1669 h->reset (hard_reset);
1670}
1671
1672
1678void
1680{
1681 m_newBoundHandles[std::this_thread::get_id()].push_back (handle);
1682}
1683
1684
1690void
1692{
1693 std::vector<IResetable*>& v = m_newBoundHandles[std::this_thread::get_id()];
1694 std::vector<IResetable*>::iterator it =
1695 std::find (v.begin(), v.end(), handle);
1696 if (it != v.end())
1697 v.erase (it);
1698}
1699
1700
1704{
1706 m_arena.makeCurrent();
1707 SG::CurrentEventStore::setStore (this);
1708}
1709
1710
1721StatusCode
1722SGImplSvc::createObj (IConverter* cvt,
1723 IOpaqueAddress* addr,
1724 DataObject*& refpObject)
1725{
1726 // This lock was here originally, but is probably not really needed ---
1727 // both DataProxy and the I/O components have their own locks.
1728 // Further, this was observed to cause deadlocks for the detector store,
1729 // and would in general be expected to be a contention issue.
1730 //lock_t lock (m_mutex);
1731 return cvt->createObj (addr, refpObject);
1732}
1733
1734
1735// This is intended to be called from the debugger.
1737{
1738 std::cout << sg->dump() << "\n";
1739}
1740void SG_dump (SGImplSvc* sg, const char* fname)
1741{
1742 std::ofstream f (fname);
1743 f << sg->dump() << "\n";
1744 f.close();
1745}
1746
1747
1754SG::SourceID SGImplSvc::sourceID (const std::string& key /*= "EventSelector"*/) const
1755{
1758 if (dp) {
1760 if (dh) {
1761 return dh->begin()->getToken()->dbID().toString();
1762 }
1763 }
1764 return "";
1765}
1766
1767
1769// Retrieve a list of collections from Transient Store with no Key.
1770// const version
1773 SG::detail::IteratorBase& cibegin,
1774 SG::detail::IteratorBase& ciend) const
1775{
1779
1780 if (!(proxyRange(clid,first,end)).isSuccess()) {
1781 std::string typnam;
1782 m_pCLIDSvc->getTypeNameOfID(clid, typnam).ignore();
1783 SG_MSG_DEBUG("retrieve(range): no object found "
1784 << " of type " << typnam
1785 << "(CLID " << clid << ')');
1786 }
1787
1788 (ciend.setState(end, end, true)).ignore();
1789
1790 if (!(cibegin.setState(first, end, true)).isSuccess()) {
1791 std::string typnam;
1792 m_pCLIDSvc->getTypeNameOfID(clid, typnam).ignore();
1793 SG_MSG_DEBUG("retrieve(range): Can't initialize iterator for object range "
1794 << " of type " << typnam
1795 << "(CLID " << clid << ')');
1796 return StatusCode::FAILURE;
1797 }
1798
1799 return StatusCode::SUCCESS;
1800}
1801
1802
1804 const std::string& key,
1805 CLID auxclid) const
1806{
1807 // If we already have the aux store (as should usually be the case), return
1808 // without taking out the SG lock. Otherwise, we can deadlock
1809 // if another thread is also trying to dereference a link to the aux store.
1810 // (Should _not_ be holding the SG lock when dereferencing the link!)
1811 if (ptr->hasStore()) return true;
1812
1814 SG_MSG_VERBOSE("called associateAux_impl for key " + key);
1815 // no Aux store set yet
1816 if (!ptr->hasStore()) {
1817 SG::DataProxy* dp = proxy (auxclid, key + "Aux.", true);
1818 if (dp) {
1819 if (!dp->isConst()) {
1821 if (pAux) {
1822 ptr->setStore (pAux);
1823 return true;
1824 }
1825 }
1826
1827 const SG::IConstAuxStore* pAux = SG::DataProxy_cast<SG::IConstAuxStore> (dp);
1828 if (pAux) {
1829 ptr->setStore (pAux);
1830 return true;
1831 }
1832 }
1833 }
1834 return false;
1835}
1836
1837
1839 const std::string& key,
1840 CLID auxclid) const
1841{
1843 SG_MSG_VERBOSE("called associateAux_impl for key " + key);
1844 // no Aux store set yet
1845 if (!ptr->hasStore()) {
1846 SG::DataProxy* dp = proxy (auxclid, key + "Aux.", true);
1847 if (dp) {
1848 if (!dp->isConst()) {
1850 if (pAux) {
1851 ptr->setStore (pAux);
1852 return true;
1853 }
1854 }
1855
1856 const SG::IConstAuxStore* pAux = SG::DataProxy_cast<SG::IConstAuxStore> (dp);
1857 if (pAux) {
1858 ptr->setStore (pAux);
1859 return true;
1860 }
1861 }
1862 }
1863 return false;
1864}
#define endmsg
Proxy for a group of Arenas. See Arena.h for an overview of the arena-based memory allocators.
Manage index tracking and synchronization of auxiliary data.
a static registry of CLID->typeName entries.
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
This file contains the class definition for the DataHeader and DataHeaderElement classes.
void swap(DataVector< T > &a, DataVector< T > &b)
See DataVector<T, BASE>::swap().
uint32_t CLID
The Class ID type.
Interface for non-const operations on an auxiliary store.
Interface for const operations on an auxiliary store.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
static Double_t a
static Double_t sc
const bool debug
void SG_dump(SGImplSvc *sg)
These are intended to be easy to call from the debugger.
Hold a pointer to the current event store.
defines a StoreGateSvc key with a version number
Incident sent after a store is cleared.
Maintain a mapping of strings to 64-bit ints.
const char *const fmt
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
Header file for AthHistogramAlgorithm.
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
Simple smart pointer for Gaudi-style refcounted objects.
T * get()
Get the pointer.
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
virtual void * object()=0
virtual void relinquish()=0
Give up ownership of the DataBucket contents.
This class provides the layout for summary information stored for data written to POOL.
Definition DataHeader.h:123
std::vector< DataHeaderElement >::const_iterator begin() const
a resetable object (e.g.
Definition IResetable.h:15
SG::sgkey_t sgkey_t
Type of the keys.
Definition IStringPool.h:34
The Athena Transient Store API.
Definition SGImplSvc.h:109
virtual SG::DataProxy * proxy(const void *const pTransient) const override final
get proxy for a given data object address in memory
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.
void addAutoSymLinks(const std::string &key, CLID clid, SG::DataProxy *dp, const std::type_info *tinfo, bool warn_nobib=true)
Add automatically-made symlinks for DP.
void setStoreID(StoreID::type id)
set store ID. request forwarded to DataStore:
StatusCode t2pRegister(const void *const pTrans, SG::DataProxy *const pPers)
forwarded to DataStore
virtual ~SGImplSvc() override final
Standard Destructor.
StatusCode symLink(const void *p2BRegistered, CLID linkID)
make a soft link to the object T* already registered
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...
virtual void boundHandle(IResetable *handle) override final
Tell the store that a proxy has been bound to a handle.
DataObject * typeless_retrievePrivateCopy(const CLID clid, const std::string &key)
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override final
Find the key for a string/CLID pair.
StatusCode remove(const void *pObject)
Remove pObject, will remove its proxy if not reset only.
virtual void handle(const Incident &) override final
triggered by Incident service
SG::DataProxy * locatePersistent(const SG::TransientAddress *tAddr, bool checkValid=false) const
virtual std::vector< const SG::DataProxy * > proxies() const override final
return the list of all current proxies in store
StatusCode setAlias(CLID clid, const std::string &key, const std::string &aliasKey)
make an alias to a DataObject (provide data type and old key)
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override final
Record an object in the store.
StatusCode loadEventProxies()
load proxies at begin event
void keys(const CLID &id, std::vector< std::string > &vkeys, bool includeAlias=false, bool onlyValid=true)
provide list of all StoreGate keys associated with an object.
SG::DataStore * store()
SG::RemapImpl * m_remap_impl
Definition SGImplSvc.h:677
int m_slotNumber
The Hive slot number for this store, or -1 if this isn't a Hive store.
Definition SGImplSvc.h:683
ServiceHandle< IProxyProviderSvc > m_pPPSHandle
Definition SGImplSvc.h:652
virtual StatusCode finalize() override final
Service finalization.
std::map< std::thread::id, std::vector< IResetable * > > m_newBoundHandles
Keep track of proxies bound since the last call to commitNewDataObjects or clearStore.
Definition SGImplSvc.h:692
virtual SG::SourceID sourceID(const std::string &key="EventSelector") const override
Return the metadata source ID for the current event slot.
StatusCode setConst(const void *pointer)
prevent downstream clients from modifying the pointed-at dobj
virtual StatusCode createObj(IConverter *cvt, IOpaqueAddress *addr, DataObject *&refpObject) override
Call converter to create an object, with locking.
std::vector< CLID > clids(const std::string &key) const
Retrieve all the CLID s (including symlinks) of the object recorded in StoreGate with the given "key"...
bool m_DumpStore
Dump Property flag: triggers dump() at EndEvent.
Definition SGImplSvc.h:663
bool m_ActivateHistory
Activate the history service.
Definition SGImplSvc.h:664
CLID clid(const std::string &key) const
Retrieve the main CLID of the object recorded in StoreGate with the given "key" WARNING: slow!
void msg_update_handler(Gaudi::Details::PropertyBase &outputLevel)
callback for output level property
SG::StringPool m_stringpool
Definition SGImplSvc.h:675
virtual StatusCode start() override final
Service start.
mutex_t m_mutex
Definition SGImplSvc.h:696
std::string createKey(const CLID &dataID)
creates a key internally if none specified by client
bool m_DumpArena
DumpArena Property flag : trigger m_arena->report() at clearStore.
Definition SGImplSvc.h:665
StatusCode removeProxy(SG::DataProxy *proxy, const void *pTrans, bool forceRemove=false)
remove proxy from store, unless it is reset only.
StoreID::type storeID() const
get store ID. request forwarded to DataStore:
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.
virtual void registerKey(sgkey_t key, const std::string &str, CLID clidid) override final
Remember an additional mapping from key to string/CLID.
StatusCode addSymLink(const CLID &linkid, SG::DataProxy *dp)
SG::Arena m_arena
Allocation arena to associate with this store.
Definition SGImplSvc.h:680
virtual StatusCode clearStore(bool forceRemove=false) override final
clear DataStore contents: called by the event loop mgrs
bool isSymLinked(const CLID &linkID, SG::DataProxy *dp)
std::lock_guard< mutex_t > lock_t
Definition SGImplSvc.h:695
IProxyProviderSvc * m_pPPS
Definition SGImplSvc.h:655
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 void commitNewDataObjects() override final
Reset handles added since the last call to commit.
int typeCount(const CLID &id) const
Return the number of instances of type T (input CLID).
virtual StatusCode stop() override final
Service stop.
void t2pRemove(const void *const pTrans)
forwarded to DataStore
virtual StatusCode addToStore(CLID id, SG::DataProxy *proxy) override final
Raw addition of a proxy to the store.
SG::DataStore * m_pStore
Definition SGImplSvc.h:659
StatusCode record_HistObj(const CLID &id, const std::string &key, const std::string &store, bool allowMods, bool resetOnly=true)
virtual const std::string * keyToString(sgkey_t key) const override final
Find the string corresponding to a given key.
void clearProxyPayload(SG::DataProxy *)
use to reset a proxy (clearing the data object it contains) Unlike DataProxy::reset this method corre...
StatusCode removeDataAndProxy(const void *pObject)
Remove pObject and its proxy no matter what.
mutex_t m_stringPoolMutex
Definition SGImplSvc.h:698
SG::DataProxy * setupProxy(const CLID &dataID, const std::string &gK, DataObject *pDObj, bool allowMods, bool resetOnly)
try to locate a proxy or create it if needed
std::vector< CLID > clids() const
Return all CLIDs in the store.
std::list< DataObject * > m_trash
The Recycle Bin.
Definition SGImplSvc.h:660
ServiceHandle< IHistorySvc > m_pHistorySvc
Definition SGImplSvc.h:657
void releaseObject(const CLID &id, const std::string &key)
release object held by proxy, if any.
IStringPool::sgkey_t sgkey_t
Definition SGImplSvc.h:338
ServiceHandle< IIOVSvc > m_pIOVSvc
get the IOVSvc "just in time" (breaks recursion at initialize)
Definition SGImplSvc.h:671
void makeCurrent()
The current store is becoming the active store.
SGImplSvc(const SGImplSvc &)=delete
int m_numSlots
The total number of slots. 1 if this isn't a Hive store.
Definition SGImplSvc.h:686
bool mergeStringPool(const SGImplSvc &other)
Merge the string pool from another store into this one.
DataObject * accessData(const CLID &id) const
find proxy and access its data. Returns 0 to flag failure
void recycle(DataObject *pBadDObj)
put a bad (unrecordable) dobj away
virtual StatusCode reinitialize() override final
Service reinitialization.
bool m_storeLoaded
FIXME hack needed by loadEventProxies.
Definition SGImplSvc.h:673
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override final
Get proxy given a hashed key+clid.
ServiceHandle< IClassIDSvc > m_pCLIDSvc
Definition SGImplSvc.h:649
bool transientContains(const CLID id, const std::string &key) const
Look up a transient data object in TDS only by CLID.
ServiceHandle< IIncidentSvc > m_pIncSvc
property
Definition SGImplSvc.h:662
std::string dump() const
dump objects in store.
StatusCode addAlias(const std::string &aliasKey, SG::DataProxy *dp)
bool contains(const CLID id, const std::string &key) const
Look up a keyed object in TDS by CLID.
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...
mutex_t m_remapMutex
Definition SGImplSvc.h:697
void setSlotNumber(int slot, int numSlots)
Set the Hive slot number for this store.
StatusCode retrieve(CLID clid, SG::detail::IteratorBase &cibegin, SG::detail::IteratorBase &ciend) const
Retrieve all objects of type T: returns an SG::ConstIterator range.
virtual void unboundHandle(IResetable *handle) override final
Tell the store that a handle has been unbound from a proxy.
SG::DataProxy * transientProxy(const CLID &id, const std::string &key) const
get proxy with given id and key.
bool associateAux_impl(SG::AuxVectorBase *ptr, const std::string &key, CLID auxclid) const
virtual StatusCode initialize() override final
Service initialization.
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
SG::DataProxy * record_impl(DataObject *obj, const std::string &key, const void *const raw_ptr, bool allowMods, bool resetOnly, bool allowOverwrite, const std::type_info *tinfo)
real recording of an object with a key, allow possibility of specifying const-access
void emptyTrash()
throw away bad objects
ServiceHandle< IConversionSvc > m_pDataLoader
Definition SGImplSvc.h:650
Proxy for a group of Arenas.
Definition ArenaHeader.h:54
static ArenaHeader * defaultHeader()
Return the global default Header instance.
Manage index tracking and synchronization of auxiliary data.
The non-template portion of the BaseInfo implementation.
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
Definition BaseInfo.cxx:570
const std::vector< CLID > & get_bases() const
Return the class IDs of all known bases of T (that have class IDs).
Definition BaseInfo.cxx:304
std::vector< CLID > get_copy_conversions() const
Return known copy conversions.
Definition BaseInfo.cxx:455
bool transientID(CLID id) const
return the list of transient IDs (primary or symLinked):
void reset(bool hard=false)
Other methods of DataProxy (not in Interface IRegistry):
DataObject * accessData()
Access DataObject on-demand using conversion service.
TransientAddress::TransientClidSet CLIDCont_t
Definition DataProxy.h:54
Hold DataProxy instances associated with a store.
int typeCount(const CLID &id) const
Count number of object of a given type in store.
virtual StoreID::type storeID() const override
void keys(const CLID &id, std::vector< std::string > &vkeys, bool includeAlias, bool onlyValid)
StoreMap::const_iterator ConstStoreIterator
void setStoreID(StoreID::type id)
const std::vector< DataProxy * > & proxies() const
All proxies managed by this store.
StatusCode tRange(ConstStoreIterator &f, ConstStoreIterator &e) const
Return an iterator over the StoreMap:
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:51
a StoreGateSvc key with a version number.
unsigned char version() const
static bool isVersionedKey(const char *)
quickly determine whether a string has the right format to be a VK
const std::string & rawVersionKey() const
static bool isAuto(const std::string &)
quickly determine whether a string has the right format to be a VK with auto-generated version #
const std::string & key() const
Implementation class, not to be used directly Iterates over valid proxies it the range.
Definition SGIterator.h:37
StatusCode setState(SG::ConstProxyIterator itr, SG::ConstProxyIterator itrEnd, bool isConst)
Reset state of the iterator.
@ EVENT_STORE
Definition StoreID.h:26
@ DETECTOR_STORE
Definition StoreID.h:27
static StoreID::type findStoreID(const std::string &storeName)
Definition StoreID.cxx:21
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
bool verbose
Definition hcg.cxx:75
Forward declaration.
DATA * DataProxy_cast(DataProxy *proxy)
cast the proxy into the concrete data object it proxies
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
ProxyMap::const_iterator ConstProxyIterator
Definition ProxyMap.h:24
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
Definition sgkey_t.h:93
void * ptr(T *p)
Definition SGImplSvc.cxx:74
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition SGImplSvc.cxx:70
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
SGKeyMap< remap_t > remap_map_t
Definition SGImplSvc.cxx:92
remap_map_t m_remaps
Definition SGImplSvc.cxx:93
IStringPool::sgkey_t sgkey_t
Definition SGImplSvc.cxx:86