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();
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
244 lock_t lock (m_mutex);
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 {
282 lock_t lock (m_mutex);
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{
340 lock_t lock (m_mutex);
341 assert(0 != pAddress);
342 CLID dataID = pAddress->clID();
343
344 if (dataID == 0)
345 {
346 warning() << "recordAddress: Invalid Class ID found in IOpaqueAddress @"
347 << pAddress.get() << ". IOA will not be recorded"
348 << endmsg;
349 return StatusCode::FAILURE;
350 }
351
352 //do not overwrite a persistent object
353 if (m_pPPS) {
354 DataProxy* dp = m_pStore->proxy (dataID, skey);
355 if (!dp) {
356 dp = m_pPPS->retrieveProxy(dataID, skey, *m_pStore);
357 }
358 if (dp && dp->provider()) {
359 std::string clidTypeName;
360 m_pCLIDSvc->getTypeNameOfID(dataID, clidTypeName).ignore();
361 warning() << "recordAddress: failed for key="<< skey << ", type "
362 << clidTypeName
363 << " (CLID " << dataID << ')'
364 << "\n there is already a persistent version of this object. Will not record a duplicate! "
365 << endmsg;
366 return StatusCode::FAILURE;
367 }
368 }
369
370 // Check if a key already exists
371 DataProxy* dp = m_pStore->proxy_exact(dataID, skey);
372 if (0 == dp && 0 != m_pPPS) {
373 dp = m_pPPS->retrieveProxy(dataID, skey, *m_pStore);
374 }
375
376 // Now treat the various cases:
377 if (0 == dp)
378 {
379 // create the proxy object and register it
380 dp = new DataProxy (TransientAddress (dataID, skey,
381 std::move(pAddress),
382 clearAddressFlag),
383 m_pDataLoader.get(), true, true);
384 m_pStore->addToStore(dataID, dp).ignore();
385
386 addAutoSymLinks (skey, dataID, dp, 0, false);
387 }
388 else if ((0 != dp) && (0 == dp->address()))
389 // Note: intentionally not checking dp->isValidAddress()
390 {
391 // Update proxy with IOpaqueAddress
392 dp->setAddress(std::move(pAddress));
393 }
394 else
395 {
396 string errType;
397 m_pCLIDSvc->getTypeNameOfID(dataID, errType).ignore();
398 warning() << "recordAddress: preexisting proxy @" << dp
399 << " with non-NULL IOA found for key "
400 << skey << " type " << errType << " (" << dataID << "). \n"
401 << "Cannot record IOpaqueAddress @" << pAddress.get()
402 << endmsg;
403 return StatusCode::FAILURE;
404 }
405
406 return StatusCode::SUCCESS;
407
408}
409
412// add proxy (with IOpaqueAddress that will later be retrieved from P)
415 bool clearAddressFlag)
416{
417 lock_t lock (m_mutex);
418 assert(0 != pAddress);
419
420 CLID dataID = pAddress->clID();
421
422 string gK = (pAddress->par())[1]; // transient name by convention
423 if (gK.empty()) gK = (pAddress->par())[0]; // FIXME backward compatibility
424 if (gK.empty()) gK = createKey(dataID);
425
426 return this->recordAddress(gK, std::move(pAddress), clearAddressFlag);
427}
428
430 const string& gK,
431 DataObject* pDObj,
432 bool allowMods,
433 bool resetOnly) {
434 // locate the proxy
435 DataProxy* dp = m_pStore->proxy_exact(dataID, gK);
436
437 if (0 != dp) { //proxy found
438 if (0 != dp->object())
439 {
440 // Case 0: duplicated proxy
441 warning() << " setupProxy:: error setting up proxy for key "
442 << gK << " and clid " << dataID
443 << "\n Pre-existing valid DataProxy @"<< dp
444 << " found in Store for key " << dp->object()->name()
445 << " with clid " << dp->object()->clID()
446 << endmsg;
447 recycle(pDObj); // commit this object to trash
448 dp = 0;
449 } else {
450 // Case 1: Proxy found... if not valid, update it:
451 dp->setObject(pDObj);
452 if (!allowMods) dp->setConst();
453 }
454 } else {
455 // Case 2: No Proxy found:
456 dp = new DataProxy(pDObj,
457 TransientAddress(dataID, gK),
458 !allowMods, resetOnly);
459 if (!(m_pStore->addToStore(dataID, dp).isSuccess())) {
460 warning() << " setupProxy:: could not addToStore proxy @" << dp
461 << endmsg;
462 recycle(pDObj); // commit this object to trash
463 delete dp;
464 dp = 0;
465 }
466 }
467 return dp;
468}
469
472{
473 lock_t lock (m_mutex);
474 store()->setStoreID(id);
475}
476
478{
479 lock_t lock (m_mutex);
480 return store()->storeID();
481}
482
483
484void
485SGImplSvc::keys(const CLID& id, std::vector<std::string>& vkeys,
486 bool includeAlias, bool onlyValid)
487
488{
489 lock_t lock (m_mutex);
490 return store()->keys(id, vkeys, includeAlias, onlyValid);
491}
492
493
494bool SGImplSvc::isSymLinked(const CLID& linkID, DataProxy* dp)
495{
496 return (0 != dp) ? dp->transientID(linkID) : false;
497}
498
500// Dump Contents in store:
501string SGImplSvc::dump() const
502{
503 lock_t lock (m_mutex);
504 auto out_buffer = std::string{};
505 auto out = std::back_inserter(out_buffer);
506 const std::string me = name();
507 std::format_to(out, "{}: <<<<<<<<<<<<<<<<< Data Store Dump >>>>>>>>>>>>>>> \n", me);
508 std::format_to(out, "{}: SGImplSvc()::dump() which is {} \n", me, m_storeLoaded ? "LOADED" : "NOT LOADED");
509
510 DataStore::ConstStoreIterator s_iter, s_end;
511 store()->tRange(s_iter, s_end).ignore();
512
513 for (; s_iter != s_end; ++s_iter)
514 {
515
516 CLID id = s_iter->first;
517 int nProxy = store()->typeCount(id);
518 std::string tname;
519 m_pCLIDSvc->getTypeNameOfID(id, tname).ignore();
520 std::format_to(out, "{}: Found {} {} for ClassID {} ({}): \n", me, nProxy, ((nProxy == 1) ? "proxy" : "proxies"), id, tname);
521
522 // loop over each type:
523 SG::ConstProxyIterator p_iter = (s_iter->second).begin();
524 SG::ConstProxyIterator p_end = (s_iter->second).end();
525
526 while (p_iter != p_end) {
527 const DataProxy& dp(*p_iter->second);
528 std::format_to(out, "{}: flags: ({:7s}, {:8s}, {:6s}) --- data: {:10p} --- key: {}\n", me,
529 (dp.isValid() ? "valid" : "INVALID"),
530 (dp.isConst() ? "locked" : "UNLOCKED"),
531 (dp.isResetOnly() ? "reset" : "DELETE"),
532 dbg::ptr(dp.object()), p_iter->first);
533 ++p_iter;
534 }
535 }
536 std::format_to(out, "{}: <<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>> \n", me);
537 return out_buffer;
538}
539
540DataStore*
542{
543 return m_pStore;
544}
545
546const DataStore*
548{
549 return m_pStore;
550}
551
552
554// Make a soft link to the object with key
556StatusCode SGImplSvc::symLink(const void* pObject, CLID linkID)
557{
558 lock_t lock (m_mutex);
559 SG::DataProxy* dp(proxy(pObject));
560
561 // if symLink already exists, just return success
562 return isSymLinked(linkID,dp) ?
563 StatusCode::SUCCESS :
564 addSymLink(linkID,dp);
565}
566
567StatusCode SGImplSvc::symLink(const CLID id, const std::string& key, const CLID linkID)
568{
569 lock_t lock (m_mutex);
570 SG::DataProxy* dp(proxy(id, key, false));
571 // if symLink already exists, just return success
572 return isSymLinked(linkID,dp) ?
573 StatusCode::SUCCESS :
574 addSymLink(linkID,dp);
575}
576
577
578StatusCode
580{
581 if (0 == dp) {
582 warning() << "addSymLink: no target DataProxy found. Sorry, can't link to a non-existing data object"
583 << endmsg;
584 return StatusCode::FAILURE;
585 }
586 StatusCode sc = m_pStore->addSymLink(linkid, dp);
587
588 // If the symlink is a derived->base conversion, then we may have
589 // a different transient pointer for the symlink.
590 if (sc.isSuccess() && dp->object()) {
591 void* baseptr = SG::DataProxy_cast (dp, linkid);
592 if (baseptr)
593 this->t2pRegister (baseptr, dp).ignore();
594 }
595 return sc;
596}
597
598
599StatusCode SGImplSvc::setAlias(const void* pObject, const std::string& aliasKey)
600{
601 lock_t lock (m_mutex);
602
603 SG::DataProxy* dp(0);
604 dp = proxy(pObject);
605 if (0 == dp) {
606 error() << "setAlias: problem setting alias "
607 << aliasKey << '\n'
608 << "DataObject does not exist, record before setting alias."
609 << endmsg;
610 return StatusCode::FAILURE;
611 }
612
613 StatusCode sc = addAlias(aliasKey, dp);
614 if (sc.isFailure()) {
615 error() << "setAlias: problem setting alias "
616 << aliasKey << '\n'
617 << "DataObject does not exist, record before setting alias."
618 << endmsg;
619 return StatusCode::FAILURE;
620 }
621
622 return StatusCode::SUCCESS;
623}
624
625
627 const std::string& key, const std::string& aKey)
628{
629 lock_t lock (m_mutex);
630
631 SG::DataProxy* dp(0);
632 dp = proxy(clid, key);
633 if (0 == dp) {
634 error() << "setAlias: problem setting alias "
635 << std::string(aKey) << '\n'
636 << "DataObject does not exist, record before setting alias."
637 << endmsg;
638 return StatusCode::FAILURE;
639 }
640
641 StatusCode sc = addAlias(aKey, dp);
642 if (sc.isFailure()) {
643 error() << "setAlias: problem setting alias "
644 << (std::string)aKey << '\n'
645 << "DataObject does not exist, record before setting alias."
646 << endmsg;
647 return StatusCode::FAILURE;
648 }
649
650 return StatusCode::SUCCESS;
651}
652
653StatusCode SGImplSvc::setAlias(SG::DataProxy* proxy, const std::string& aliasKey)
654{
655 return addAlias( aliasKey, proxy );
656}
657
658StatusCode
659SGImplSvc::addAlias(const std::string& aliasKey, DataProxy* proxy)
660{
661 if (0 == proxy) {
662 warning() << "addAlias: no target DataProxy given, Cannot alias to a non-existing object"
663 << endmsg;
664 return StatusCode::FAILURE;
665 }
666
667 // add key to proxy and to ProxyStore
668 return m_pStore->addAlias(aliasKey, proxy);
669}
670
671int SGImplSvc::typeCount(const CLID& id) const
672{
673 lock_t lock (m_mutex);
674 return m_pStore->typeCount(id);
675}
676
677
678bool
679SGImplSvc::contains(const CLID id, const std::string& key) const
680{
681 try {
682 return (0 != proxy(id, key, true));
683 } catch(...) { return false; }
684}
685
686
687bool
688SGImplSvc::transientContains(const CLID id, const std::string& key) const
689{
690 try {
691 return (0 != transientProxy(id, key));
692 } catch(...) { return false; }
693}
694
695
696DataProxy*
697SGImplSvc::proxy(const void* const pTransient) const
698{
699 // No lock needed here --- the T2pmap held by DataStore has its own locking
700 // (and we were seeing contention here).
701 //lock_t lock (m_mutex);
702 return m_pStore->locatePersistent(pTransient);
703}
704
705DataProxy*
706SGImplSvc::proxy(const CLID& id) const
707{
708 return proxy(id, false);
709}
710
711DataProxy*
712SGImplSvc::proxy(const CLID& id, bool checkValid) const
713{
714 DataProxy* dp = nullptr;
715 {
716 lock_t lock (m_mutex);
717 dp = m_pStore->proxy(id);
718 if (0 == dp && 0 != m_pPPS) {
720 dp = m_pPPS->retrieveProxy(id, string("DEFAULT"), *pStore);
721 }
722 }
724 // Be sure to release the lock before this.
725 // isValid() may call back to the store, so we could otherwise deadlock..
726 if (checkValid && 0 != dp) {
727 // FIXME: For keyless retrieve, this checks only the first instance
728 // of the CLID in store. If that happens to be invalid, but the second
729 // is valid - this does not work (when checkValid is requested).
730 return dp->isValid() ? dp : 0;
731 }
732 return dp;
733}
734
735DataProxy*
736SGImplSvc::proxy(const CLID& id, const string& key) const
737{
738 return proxy(id, key, false);
739}
740
742SGImplSvc::proxy(const CLID& id, const string& key, bool checkValid) const
743{
744 DataProxy* dp = nullptr;
745 {
746 lock_t lock (m_mutex);
747 dp = m_pStore->proxy(id, key);
748#ifdef DEBUG_SGIMPL
749 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");
750#endif
751 if (0 == dp && 0 != m_pPPS) {
753 dp = m_pPPS->retrieveProxy(id, key, *pStore);
754#ifdef DEBUG_SGIMPL
755 if (!dp) dbg::print(stderr, "::SGImplSvc::proxy(name={}, key={}): data proxy is still null\n", this->name(), key);
756#endif
757 }
758 }
759 // Be sure to release the lock before this.
760 // isValid() may call back to the store, so we could otherwise deadlock..
761 if (checkValid && 0 != dp && !(dp->isValid())) {
762 dp = 0;
763 }
764 return dp;
765}
766
767
774{
775 lock_t lock (m_mutex);
776 return m_pStore->addToStore (id, proxy);
777}
778
779
801 const std::string& key,
802 bool allowMods,
803 bool returnExisting)
804{
805 lock_t lock (m_mutex);
806 const void* raw_ptr = obj.get();
807 const std::type_info* tinfo = nullptr;
808
809 if (DataBucketBase* bucket = dynamic_cast<DataBucketBase*> (obj.get())) {
810 raw_ptr = bucket->object();
811 tinfo = &bucket->tinfo();
812 }
813
814 if (returnExisting) {
815 SG::DataProxy* proxy = this->proxy (obj->clID(), key);
816 if (proxy && proxy->isValid()) return proxy;
817
818 // Look for the same object recorded under a different key/clid.
819 proxy = this->proxy (raw_ptr);
820 if (proxy && proxy->isValid()) {
821 if (proxy->transientID (obj->clID())) {
822 // CLID matches. Make an alias.
823 if (addAlias (key, proxy).isFailure()) {
824 CLID clid = proxy->clID();
825 std::string clidTypeName;
826 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
827 warning() << "SGImplSvc::recordObject: addAlias fails for object "
828 << clid << "[" << clidTypeName << "] " << proxy->name()
829 << " and new key " << key
830 << endmsg;
831
832 proxy = nullptr;
833 }
834 }
835
836 else if (key == proxy->name() || proxy->hasAlias(key) > 0)
837 {
838 // key matches. Make a symlink.
839 if (addSymLink (obj->clID(), proxy).isFailure()) {
840 CLID clid = proxy->clID();
841 std::string clidTypeName;
842 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
843 CLID newclid = obj->clID();
844 std::string newclidTypeName;
845 m_pCLIDSvc->getTypeNameOfID(newclid, newclidTypeName).ignore();
846 error() << "SGImplSvc::recordObject: addSymLink fails for object "
847 << clid << "[" << clidTypeName << "] " << proxy->name()
848 << " and new clid " << newclid << "[" << newclidTypeName << "]"
849 << endmsg;
850 proxy = nullptr;
851 }
852 }
853
854 else {
855 CLID clid = proxy->clID();
856 std::string clidTypeName;
857 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
858 CLID newclid = obj->clID();
859 std::string newclidTypeName;
860 m_pCLIDSvc->getTypeNameOfID(newclid, newclidTypeName).ignore();
861 error() << "SGImplSvc::recordObject: existing object found with "
862 << clid << "[" << clidTypeName << "] " << proxy->name()
863 << " but neither clid " << newclid << "[" << newclidTypeName << "]"
864 << " nor key " << key << " match."
865 << endmsg;
866 proxy = nullptr;
867 }
868
869 return proxy;
870 }
871 }
872
873 const bool resetOnly = true;
874 const bool noHist = false;
875 SG::DataProxy* proxy = nullptr;
876 if (this->typeless_record (obj.get(), key, raw_ptr,
877 allowMods, resetOnly, noHist, tinfo,
878 &proxy, true).isFailure())
879 {
880 return nullptr;
881 }
882 return proxy;
883}
884
885
890{
891 return m_pStore->proxy_exact_unlocked (sgkey, m_mutex);
892}
893
894
901void SGImplSvc::setSlotNumber (int slot, int numSlots)
902{
903 m_slotNumber = slot;
904 m_numSlots = numSlots;
905
907 header->setArenaForSlot (slot, &m_arena);
908}
909
910
911std::vector<const SG::DataProxy*>
913{
914 lock_t lock (m_mutex);
915 const std::vector<SG::DataProxy*>& proxies = store()->proxies();
916 std::vector<const SG::DataProxy*> ret (proxies.begin(), proxies.end());
917 return ret;
918}
919
920
921std::vector<CLID>
923{
924 lock_t lock (m_mutex);
925
926 using std::distance;
927 DataStore::ConstStoreIterator s_iter, s_end;
928 store()->tRange(s_iter, s_end).ignore();
929
930 std::vector<CLID> clids;
931 clids.reserve( distance( s_iter, s_end ) );
932
933 for (; s_iter != s_end; ++s_iter ) {
934 const CLID id = s_iter->first;
935 clids.push_back (id);
936 }
937
938 return clids;
939}
940
941
943SGImplSvc::transientProxy(const CLID& id, const string& key) const
944{
945 lock_t lock (m_mutex);
946 DataProxy* dp(m_pStore->proxy(id, key));
947 return ( (0 != dp && dp->isValidObject()) ? dp : 0 );
948}
949
950DataObject*
952{
953 lock_t lock (m_mutex);
954 DataProxy* theProxy(proxy(id, true));
955 return (0 == theProxy) ? 0 : theProxy->accessData();
956}
957
958DataObject*
959SGImplSvc::accessData(const CLID& id, const string& key) const
960{
961 lock_t lock (m_mutex);
962 DataProxy* theProxy(proxy(id, key, true));
963 return (0 == theProxy) ? 0 : theProxy->accessData();
964}
965
966bool
968 const std::string& keyA, const std::string& keyB )
969{
970 lock_t lock (m_mutex);
971 const bool checkValid = true;
972 DataProxy* a = proxy( id, keyA, checkValid );
973 DataProxy* b = proxy( id, keyB, checkValid );
974 if ( 0 == a || 0 == b ) { return false; }
975 DataObject* objA = a->accessData();
976 DataObject* objB = b->accessData();
977
978 if ( 0 == objA || 0 == objB ) { return false; }
979 // prevent 'accidental' release of DataObjects...
980 const unsigned int refCntA = objA->addRef();
981 const unsigned int refCntB = objB->addRef();
982 // in case swap is being specialized for DataObjects
983 using std::swap;
984 swap( objA, objB );
985 a->setObject( objA );
986 b->setObject( objB );
987 // and then restore old ref-count;
988 return ( (refCntA-1) == objA->release() &&
989 (refCntB-1) == objB->release() );
990}
991
992StatusCode
993SGImplSvc::typeless_record( DataObject* obj, const std::string& key,
994 const void* const raw_ptr,
995 bool allowMods, bool resetOnly, bool noHist)
996{
997 return typeless_record (obj, key, raw_ptr, allowMods, resetOnly, noHist, 0,
998 nullptr, true);
999}
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 const std::type_info* tinfo)
1007{
1008 return typeless_record (obj, key, raw_ptr, allowMods, resetOnly, noHist,tinfo,
1009 nullptr, true);
1010}
1011
1012
1013StatusCode
1014SGImplSvc::typeless_record( DataObject* obj, const std::string& key,
1015 const void* const raw_ptr,
1016 bool allowMods, bool resetOnly, bool noHist,
1017 const std::type_info* tinfo,
1018 SG::DataProxy** proxy_ret,
1019 bool noOverwrite)
1020{
1021 lock_t lock (m_mutex);
1023 record_impl( obj, key, raw_ptr, allowMods, resetOnly, !noOverwrite, tinfo);
1024 if ( proxy == nullptr )
1025 return StatusCode::FAILURE;
1026 if (proxy_ret)
1027 *proxy_ret = proxy;
1028
1029 if ( !m_ActivateHistory || noHist ) {
1030 return StatusCode::SUCCESS;
1031 }
1032
1033 if ( store()->storeID() != StoreID::EVENT_STORE ) {
1034 return StatusCode::SUCCESS;
1035 } else {
1036 return record_HistObj( obj->clID(), key, name(), allowMods, resetOnly );
1037 }
1038}
1039
1040StatusCode
1042 DataObject* obj,
1043 const std::string& key,
1044 const void* const raw_ptr,
1045 bool allowMods,
1046 bool noHist,
1047 const std::type_info* tinfo)
1048{
1049 lock_t lock (m_mutex);
1050 StatusCode sc(StatusCode::SUCCESS);
1051 SG::DataProxy* toRemove(proxy(clid, key, false));
1052 if (0 != toRemove) {
1053 toRemove->addRef();
1054 const bool FORCEREMOVE(true);
1055 sc =removeProxy(toRemove, (void*)0, FORCEREMOVE);
1056 }
1057 if (sc.isSuccess()) {
1058 const bool ALLOWOVERWRITE(true);
1059 const bool NORESET(false);
1060 if (record_impl( obj, key, raw_ptr, allowMods, NORESET, ALLOWOVERWRITE, tinfo) == nullptr)
1061 sc = StatusCode::FAILURE;
1062 else if ( m_ActivateHistory && noHist && store()->storeID() == StoreID::EVENT_STORE ) {
1063 sc = record_HistObj( obj->clID(), key, name(), allowMods, NORESET );
1064 }
1065 }
1066 //for detector store objects managed by IIOVSvc, replace the old proxy with the new one (#104311)
1067 if (toRemove && sc.isSuccess() && store()->storeID() == StoreID::DETECTOR_STORE) {
1068 sc = m_pIOVSvc->replaceProxy(toRemove, proxy(clid, key));
1069 }
1070 if (toRemove)
1071 toRemove->release();
1072 return sc;
1073}
1074
1076SGImplSvc::record_impl( DataObject* pDObj, const std::string& key,
1077 const void* const raw_ptr,
1078 bool allowMods, bool resetOnly, bool allowOverwrite,
1079 const std::type_info* tinfo)
1080{
1081 CLID clid = pDObj->clID();
1082 std::string rawKey(key);
1083 bool isVKey(SG::VersionedKey::isVersionedKey(key));
1084 if (isVKey) {
1085 //FIXME VersionedKeys will need to be handled more efficiently
1086 SG::VersionedKey vk(rawKey);
1087 DataProxy *dp(proxy(clid, vk.key()));
1088 if (dp) {
1089 //proxies primary key
1090 const std::string& pTAName(dp->name());
1091 //original key as versioned
1092 SG::VersionedKey primaryVK(pTAName);
1093
1094 //if the existing matching object has no version
1095 //create a versioned alias for the original unversioned key
1096 //so it will remain accessible
1097 if (!SG::VersionedKey::isVersionedKey(pTAName)) {
1098 if (!(this->addAlias(primaryVK.rawVersionKey(), dp)).isSuccess()) {
1099 warning() << "record_impl: Could not setup alias key "
1100 << primaryVK.rawVersionKey()
1101 << " for unversioned object " << pTAName
1102 << endmsg;
1103 return nullptr;
1104 }
1105 }
1106 if (vk.isAuto()) {
1107 //make a new versioned key incrementing the existing version
1108 SG::VersionedKey newVK(primaryVK.key(), primaryVK.version()+1);
1109 //FIXME this will fail in a confusing way if version+1 is in use
1110 //FIXME need a better error message below, probably looking at all
1111 //FIXME aliases
1112 rawKey = newVK.rawVersionKey();
1113 }
1114 }
1115 }
1116 if (!allowOverwrite && m_pPPS) {
1117 //do not overwrite a persistent object
1118 DataProxy* dp = m_pStore->proxy (clid, rawKey);
1119 if (!dp) {
1120 dp = m_pPPS->retrieveProxy(clid, rawKey, *m_pStore);
1121 }
1122 if (dp && dp->provider()) {
1123 std::string clidTypeName;
1124 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1125 warning() << "record_impl: you are recording an object with key "
1126 << rawKey << ", type " << clidTypeName
1127 << " (CLID " << clid << ')'
1128 << "\n There is already a persistent version of this object. Recording a duplicate may lead to unreproducible results and it is deprecated."
1129 << endmsg;
1130 }
1131 }
1132 //now check whether raw_ptr has already been recorded
1133 //We need to do this before we create the bucket, the proxy etc
1134 SG::DataProxy* dp(proxy(raw_ptr));
1135 if (0 != dp) {
1136 std::string clidTypeName;
1137 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1138 warning() << "record_impl: failed for key="<< rawKey << ", type "
1139 << clidTypeName
1140 << " (CLID " << clid << ')'
1141 << "\n object @" << raw_ptr
1142 << " already in store with key="<< dp->name()
1143 << ". Will not record a duplicate! "
1144 << endmsg;
1145 if (pDObj != dp->object()) {
1146 DataBucketBase* pDBB(dynamic_cast<DataBucketBase*>(pDObj));
1147 if (!pDBB) std::abort();
1148 pDBB->relinquish(); //don't own the data obj already recorded!
1149 }
1150 this->recycle(pDObj);
1151 return nullptr;
1152 }
1153
1154
1155 // setup the proxy
1156 dp = setupProxy( clid, rawKey, pDObj, allowMods, resetOnly );
1157 if ( 0 == dp ) {
1158 std::string clidTypeName;
1159 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1160 warning() << "record_impl: Problem setting up the proxy for object @"
1161 << raw_ptr
1162 << "\n recorded with key " << rawKey
1163 << " of type " << clidTypeName
1164 << " (CLID " << clid << ") in DataObject @" << pDObj
1165 << endmsg;
1166
1167 return nullptr;
1168 }
1169
1170 // record in t2p:
1171 if ( !(this->t2pRegister( raw_ptr, dp )).isSuccess() ) {
1172 std::string clidTypeName;
1173 m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
1174 warning() << "record_impl: can not add to t2p map object @" <<raw_ptr
1175 << "\n with key " << rawKey
1176 << " of type " << clidTypeName
1177 << " (CLID " << clid << ')'
1178 << endmsg;
1179 return nullptr;
1180 }
1181
1182 addAutoSymLinks (rawKey, clid, dp, tinfo);
1183
1184 //handle versionedKeys: we register an alias with the "true" key
1185 //unless an object as already been recorded with that key.
1186 //Notice that addAlias overwrites any existing alias, so a generic
1187 //retrieve will always return the last version added
1188 //FIXME not the one with the highest version
1189 if (isVKey) {
1190 SG::VersionedKey vk(rawKey);
1191 if (!(this->addAlias(vk.key(), dp)).isSuccess()) {
1192 warning() << "record_impl: Could not setup alias key " << vk.key()
1193 << " for VersionedKey " << rawKey
1194 << ". Generic access to this object with clid" << clid
1195 << " will not work"
1196 << endmsg;
1197 }
1198 }
1199
1200 return dp;
1201}
1202
1203DataProxy*
1205 bool checkValid) const
1206{
1207 DataProxy* dp = m_pStore->proxy(tAddr);
1208
1209 if (checkValid && 0 != dp) {
1210 return dp->isValid() ? dp : 0;
1211 } else {
1212 return dp;
1213 }
1214}
1215
1216StatusCode
1218 bool forceRemove)
1219{
1220 lock_t lock (m_mutex);
1221 // check if valid proxy
1222 if (0 == proxy) return StatusCode::FAILURE;
1223
1224 if (0 == pTrans) {
1225 DataBucketBase* bucket = dynamic_cast<DataBucketBase*>(proxy->object());
1226 if (bucket) pTrans = bucket->object();
1227 }
1228
1229 // remove all entries from t2p map
1230 // --- only if the proxy actually has an object!
1231 // otherwise, we can trigger I/O.
1232 // besides being useless here, we can get deadlocks if we
1233 // call into the I/O code while holding the SG lock.
1234 if (proxy->isValidObject()) {
1235 this->t2pRemove(pTrans);
1236 SG::DataProxy::CLIDCont_t clids = proxy->transientID();
1237 for (SG::DataProxy::CLIDCont_t::const_iterator i = clids.begin();
1238 i != clids.end();
1239 ++i)
1240 {
1241 void* ptr = SG::DataProxy_cast (proxy, *i);
1242 this->t2pRemove(ptr);
1243 }
1244 }
1245
1246 // remove from store
1247 return m_pStore->removeProxy(proxy, forceRemove, true);
1248}
1249
1250StatusCode
1251SGImplSvc::t2pRegister(const void* const pTrans, DataProxy* const pPers)
1252{
1253 return m_pStore->t2pRegister(pTrans, pPers);
1254}
1255
1256
1257void
1258SGImplSvc::t2pRemove(const void* const pTrans)
1259{
1260 m_pStore->t2pRemove(pTrans);
1261}
1262
1263void
1264SGImplSvc::msg_update_handler(Gaudi::Details::PropertyBase& /*outputLevel*/)
1265{
1266 setUpMessaging();
1267 updateMsgStreamOutputLevel( outputLevel() );
1268 msgSvc()->setOutputLevel(name(), outputLevel());
1269}
1270
1271StatusCode
1274 SG::ConstProxyIterator& end) const {
1275 lock_t lock (m_mutex);
1276 return m_pStore->pRange(id,begin,end);
1277}
1278
1279StatusCode SGImplSvc::setConst(const void* pObject)
1280{
1281 lock_t lock (m_mutex);
1282 // Check if DataProxy does not exist
1283 DataProxy * dp = proxy(pObject);
1284
1285 if (0 == dp)
1286 {
1287 warning() << "setConst: NO Proxy for the dobj you want to set const"
1288 << endmsg;
1289 return StatusCode::FAILURE;
1290 }
1291
1292 dp->setConst();
1293 return StatusCode::SUCCESS;
1294}
1295
1296
1297// remove an object from Store, will remove its proxy if not reset only
1298StatusCode
1299SGImplSvc::remove(const void* pObject)
1300{
1301 lock_t lock (m_mutex);
1302 return removeProxy(proxy(pObject), pObject);
1303}
1304
1305
1306// remove an object and its proxy from Store
1307StatusCode
1309{
1310 lock_t lock (m_mutex);
1311 const bool FORCEREMOVE(true);
1312 return removeProxy(proxy(pObject), pObject, FORCEREMOVE);
1313}
1314
1315//put a bad (unrecordable) dobj away
1316void SGImplSvc::recycle(DataObject* pBadDObj) {
1317 assert(pBadDObj);
1318 pBadDObj->addRef();
1319 m_trash.push_back(pBadDObj);
1320}
1321
1322//throw away bad objects
1324 lock_t lock (m_mutex);
1325 while (!m_trash.empty()) {
1326 m_trash.front()->release(); //delete the bad data object
1327 m_trash.pop_front(); //remove pointer from list
1328 }
1329}
1330
1331
1332/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1333
1334StatusCode
1335SGImplSvc::record_HistObj(const CLID& id, const std::string& key,
1336 const std::string& store,
1337 bool allowMods, bool resetOnly) {
1338
1339 DataHistory *dho;
1340 dho = m_pHistorySvc->createDataHistoryObj( id, key, store );
1341
1342 std::string idname;
1343 StatusCode sc = m_pCLIDSvc->getTypeNameOfID(id, idname);
1344 if (sc.isFailure() || idname.empty() ) {
1345 idname = std::to_string(id);
1346 }
1347 idname += '/';
1348 idname += key;
1349
1350 DataObject* obj = SG::asStorable(dho);
1351
1352 const bool ALLOWOVERWRITE(false);
1353 if (record_impl(obj, idname, dho, allowMods, resetOnly, ALLOWOVERWRITE,
1354 &typeid(DataHistory)) == nullptr)
1355 return StatusCode::FAILURE;
1356 return StatusCode::SUCCESS;
1357}
1358
1359
1370{
1372 return m_stringpool.stringToKey (str, clid);
1373}
1374
1375
1383const std::string* SGImplSvc::keyToString (sgkey_t key) const
1384{
1386 return m_stringpool.keyToString (key);
1387}
1388
1389
1398const std::string*
1400{
1402 return m_stringpool.keyToString (key, clid);
1403}
1404
1405
1419 const std::string& str,
1420 CLID clid)
1421{
1423 if (!m_stringpool.registerKey (key, str, clid)) {
1424 CLID clid2;
1425 const std::string* str2 = m_stringpool.keyToString (key, clid2);
1426 REPORT_MESSAGE (MSG::WARNING) << "The numeric key " << key
1427 << " maps to multiple string key/CLID pairs: "
1428 << *str2 << "/" << clid2 << " and "
1429 << str << "/" << clid;
1430 }
1431}
1432
1433
1442{
1443 // We should hold m_stringPoolMutex before touching the pool.
1444 // But if we acquire the locks for both this and the other store,
1445 // we risk a deadlock. So first copy the other pool, so that we
1446 // don't need to hold both locks at the same time.
1447 SG::StringPool tmp;
1448 {
1449 lock_t lock (other.m_stringPoolMutex);
1450 tmp = other.m_stringpool;
1451 }
1453 return m_stringpool.merge (tmp);
1454}
1455
1456
1457void
1458SGImplSvc::releaseObject(const CLID& id, const std::string& key) {
1459 lock_t lock (m_mutex);
1460 DataProxy *pP(0);
1461 if (0 != (pP = proxy(id, key))) {
1462 // remove all entries from t2p map
1464 SG::DataProxy::CLIDCont_t::const_iterator i(clids.begin()), e(clids.end());
1465 while (i != e) t2pRemove(SG::DataProxy_cast (pP, *i++));
1466 DataBucketBase *pDBB(dynamic_cast<DataBucketBase*>(pP->object()));
1467 //tell the bucket to let go of the data object
1468 if (0 != pDBB) pDBB->relinquish(); //somebody else better took ownership
1469 bool hard_reset = (m_numSlots > 1);
1470 pP->reset (hard_reset);
1471 }
1472}
1473
1474void
1476 lock_t lock (m_mutex);
1477
1478 // Remove transient pointer entries for this proxy.
1479 // But do that only if the proxy has a valid object.
1480 // Otherwise, we could trigger I/O --- which we don't want since it's useless
1481 // (we'd just destroy the object immediately). In some cases it can also
1482 // lead to a deadlock (see ATR-24482).
1483 if (dp->isValidObject()) {
1484 SG::DataProxy::CLIDCont_t clids = dp->transientID();
1485 SG::DataProxy::CLIDCont_t::const_iterator i(clids.begin()), e(clids.end());
1486 while (i != e) {
1487 t2pRemove(SG::DataProxy_cast (dp, *i++));
1488 }
1489 }
1490
1491 bool hard_reset = (m_numSlots > 1);
1492 dp->reset (hard_reset);
1493}
1494
1495
1504 sgkey_t target,
1505 off_t index_offset)
1506{
1507 lock_t lock (m_remapMutex);
1508 SG::RemapImpl::remap_t payload;
1509 payload.target = target;
1510 payload.index_offset = index_offset;
1511 m_remap_impl->m_remaps[source] = payload;
1512}
1513
1514
1523bool SGImplSvc::tryELRemap (sgkey_t sgkey_in, size_t index_in,
1524 sgkey_t& sgkey_out, size_t& index_out)
1525{
1526 lock_t lock (m_remapMutex);
1527 SG::RemapImpl::remap_map_t::iterator i =
1528 m_remap_impl->m_remaps.find (sgkey_in);
1529 if (i == m_remap_impl->m_remaps.end())
1530 return false;
1531 const SG::RemapImpl::remap_t& payload = i->second;
1532 sgkey_out = payload.target;
1533 index_out = index_in + payload.index_offset;
1534 return true;
1535}
1536
1537
1539 const std::string& key)
1540{
1541 lock_t lock (m_mutex);
1542 DataObject* obj = nullptr;
1543 SG::DataProxy* dp = proxy (clid, key);
1544 //we do not want anyone to mess up with our copy hence we release it immediately.
1545 if (dp && dp->isValid()) {
1546 obj = dp->object();
1547 obj->addRef();
1548 clearProxyPayload (dp);
1549 }
1550 return obj;
1551}
1552
1553
1554CLID SGImplSvc::clid( const std::string& key ) const
1555{
1556 lock_t lock (m_mutex);
1558 store()->tRange(s_iter, s_end).ignore();
1559
1560 for ( ; s_iter != s_end; ++s_iter ) {
1561 if ( s_iter->second.find( key ) != s_iter->second.end() ) {
1562 return s_iter->first;
1563 }
1564 }
1565
1566 return CLID_NULL;
1567}
1568
1569
1570std::vector<CLID> SGImplSvc::clids( const std::string& key ) const
1571{
1572 lock_t lock (m_mutex);
1573 std::vector<CLID> clids;
1575 store()->tRange(s_iter, s_end).ignore();
1576
1577 for ( ; s_iter != s_end; ++s_iter ) {
1578 if ( s_iter->second.find( key ) != s_iter->second.end() ) {
1579 clids.push_back(s_iter->first);
1580 }
1581 }
1582
1583 return clids;
1584}
1585
1586
1588void SGImplSvc::addAutoSymLinks (const std::string& key,
1589 CLID clid,
1590 DataProxy* dp,
1591 const std::type_info* tinfo,
1592 bool warn_nobib /*= true*/)
1593{
1594 // Automatically make all legal base class symlinks
1595 if (!tinfo) {
1597 }
1598 const SG::BaseInfoBase* bib = nullptr;
1599 if (tinfo) {
1600 bib = SG::BaseInfoBase::find (*tinfo);
1601 }
1602 if (!bib) {
1603 // Could succeed where the previous fails if clid for DataVector<T>
1604 // but tinfo is for ConstDataVector<DataVector<T> >.
1606 }
1607 if ( bib ) {
1608 const std::vector<CLID>& bases = bib->get_bases();
1609 for ( std::size_t i = 0, iMax = bases.size(); i < iMax; ++i ) {
1610 if ( bases[i] != clid ) {
1611 if ( addSymLink( bases[i], dp ).isSuccess() ) {
1612 // register with t2p
1613 if (dp->object())
1614 this->t2pRegister( SG::DataProxy_cast( dp, bases[i] ), dp ).ignore();
1615 }
1616 else {
1617 warning() << "record_impl: Doing auto-symlinks for object with CLID "
1618 << clid
1619 << " and SG key " << key
1620 << ": Proxy already set for base CLID " << bases[i]
1621 << "; not making auto-symlink." << endmsg;
1622 }
1623 }
1624 }
1625
1626 // Handle copy conversions.
1627 {
1628 for (CLID copy_clid : bib->get_copy_conversions()) {
1629 if (m_pStore->addSymLink (copy_clid, dp).isFailure()) {
1630 warning() << "record_impl: Doing auto-symlinks for object with CLID "
1631 << clid
1632 << " and SG key " << key
1633 << ": Proxy already set for copy-conversion CLID "
1634 << copy_clid
1635 << "; not making auto-symlink." << endmsg;
1636 }
1637 }
1638 }
1639 }
1640 else {
1641 if (warn_nobib) {
1642 warning() << "record_impl: Could not find suitable SG::BaseInfoBase for CLID ["
1643 << clid << "] (" << key << ") !\t"
1644 << "No auto-symlink established !"
1645 << endmsg;
1646 }
1647 }
1648}
1649
1650void
1652 lock_t lock (m_mutex);
1653
1654 // Reset handles added since the last call to commit.
1655 bool hard_reset = (m_numSlots > 1);
1656 std::vector<IResetable*> handles;
1657 m_newBoundHandles[std::this_thread::get_id()].swap (handles);
1658 for (IResetable* h : handles)
1659 h->reset (hard_reset);
1660}
1661
1662
1668void
1670{
1671 m_newBoundHandles[std::this_thread::get_id()].push_back (handle);
1672}
1673
1674
1680void
1682{
1683 std::vector<IResetable*>& v = m_newBoundHandles[std::this_thread::get_id()];
1684 std::vector<IResetable*>::iterator it =
1685 std::find (v.begin(), v.end(), handle);
1686 if (it != v.end())
1687 v.erase (it);
1688}
1689
1690
1694{
1695 lock_t lock (m_mutex);
1696 m_arena.makeCurrent();
1698}
1699
1700
1711StatusCode
1712SGImplSvc::createObj (IConverter* cvt,
1713 IOpaqueAddress* addr,
1714 DataObject*& refpObject)
1715{
1716 // This lock was here originally, but is probably not really needed ---
1717 // both DataProxy and the I/O components have their own locks.
1718 // Further, this was observed to cause deadlocks for the detector store,
1719 // and would in general be expected to be a contention issue.
1720 //lock_t lock (m_mutex);
1721 return cvt->createObj (addr, refpObject);
1722}
1723
1724
1725// This is intended to be called from the debugger.
1727{
1728 std::cout << sg->dump() << "\n";
1729}
1730void SG_dump (SGImplSvc* sg, const char* fname)
1731{
1732 std::ofstream f (fname);
1733 f << sg->dump() << "\n";
1734 f.close();
1735}
1736
1737
1744SG::SourceID SGImplSvc::sourceID (const std::string& key /*= "EventSelector"*/) const
1745{
1746 lock_t lock (m_mutex);
1748 if (dp) {
1750 if (dh) {
1751 return dh->begin()->getToken()->dbID().toString();
1752 }
1753 }
1754 return "";
1755}
1756
1757
1759// Retrieve a list of collections from Transient Store with no Key.
1760// const version
1763 SG::detail::IteratorBase& cibegin,
1764 SG::detail::IteratorBase& ciend) const
1765{
1766 lock_t lock (m_mutex);
1769
1770 if (!(proxyRange(clid,first,end)).isSuccess()) {
1771 std::string typnam;
1772 m_pCLIDSvc->getTypeNameOfID(clid, typnam).ignore();
1773 SG_MSG_DEBUG("retrieve(range): no object found "
1774 << " of type " << typnam
1775 << "(CLID " << clid << ')');
1776 }
1777
1778 (ciend.setState(end, end, true)).ignore();
1779
1780 if (!(cibegin.setState(first, end, true)).isSuccess()) {
1781 std::string typnam;
1782 m_pCLIDSvc->getTypeNameOfID(clid, typnam).ignore();
1783 SG_MSG_DEBUG("retrieve(range): Can't initialize iterator for object range "
1784 << " of type " << typnam
1785 << "(CLID " << clid << ')');
1786 return StatusCode::FAILURE;
1787 }
1788
1789 return StatusCode::SUCCESS;
1790}
1791
1792
1794 const std::string& key,
1795 CLID auxclid) const
1796{
1797 // If we already have the aux store (as should usually be the case), return
1798 // without taking out the SG lock. Otherwise, we can deadlock
1799 // if another thread is also trying to dereference a link to the aux store.
1800 // (Should _not_ be holding the SG lock when dereferencing the link!)
1801 if (ptr->hasStore()) return true;
1802
1803 lock_t lock (m_mutex);
1804 SG_MSG_VERBOSE("called associateAux_impl for key " + key);
1805 // no Aux store set yet
1806 if (!ptr->hasStore()) {
1807 SG::DataProxy* dp = proxy (auxclid, key + "Aux.", true);
1808 if (dp) {
1809 if (!dp->isConst()) {
1811 if (pAux) {
1812 ptr->setStore (pAux);
1813 return true;
1814 }
1815 }
1816
1818 if (pAux) {
1819 ptr->setStore (pAux);
1820 return true;
1821 }
1822 }
1823 }
1824 return false;
1825}
1826
1827
1829 const std::string& key,
1830 CLID auxclid) const
1831{
1832 lock_t lock (m_mutex);
1833 SG_MSG_VERBOSE("called associateAux_impl for key " + key);
1834 // no Aux store set yet
1835 if (!ptr->hasStore()) {
1836 SG::DataProxy* dp = proxy (auxclid, key + "Aux.", true);
1837 if (dp) {
1838 if (!dp->isConst()) {
1840 if (pAux) {
1841 ptr->setStore (pAux);
1842 return true;
1843 }
1844 }
1845
1847 if (pAux) {
1848 ptr->setStore (pAux);
1849 return true;
1850 }
1851 }
1852 }
1853 return false;
1854}
#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.
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
StoreMap::const_iterator ConstStoreIterator
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:673
int m_slotNumber
The Hive slot number for this store, or -1 if this isn't a Hive store.
Definition SGImplSvc.h:679
ServiceHandle< IProxyProviderSvc > m_pPPSHandle
Definition SGImplSvc.h:648
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:688
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:659
bool m_ActivateHistory
Activate the history service.
Definition SGImplSvc.h:660
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:671
virtual StatusCode start() override final
Service start.
mutex_t m_mutex
Definition SGImplSvc.h:692
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:661
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:676
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:691
IProxyProviderSvc * m_pPPS
Definition SGImplSvc.h:651
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:655
StatusCode recordAddress(const std::string &skey, CxxUtils::RefCountedPtr< IOpaqueAddress > pAddress, bool clearAddressFlag=true)
Create a proxy object using an IOpaqueAddress and a transient key.
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:694
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:656
ServiceHandle< IHistorySvc > m_pHistorySvc
Definition SGImplSvc.h:653
void releaseObject(const CLID &id, const std::string &key)
release object held by proxy, if any.
IStringPool::sgkey_t sgkey_t
Definition SGImplSvc.h:334
ServiceHandle< IIOVSvc > m_pIOVSvc
get the IOVSvc "just in time" (breaks recursion at initialize)
Definition SGImplSvc.h:667
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:682
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:669
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:645
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:658
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:693
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:646
Proxy for a group of Arenas.
Definition ArenaHeader.h:54
static ArenaHeader * defaultHeader()
Return the global default Header instance.
Base class for elements of a container that can have aux data.
Definition AuxElement.h:484
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
static IProxyDict * setStore(IProxyDict *store)
Set the current store.
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.
StatusCode tRange(ConstStoreIterator &f, ConstStoreIterator &e) const
Return an iterator over the StoreMap:
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.
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:48
Interface for const operations on an auxiliary store.
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:130
bool verbose
Definition hcg.cxx:73
Forward declaration.
DATA * DataProxy_cast(DataProxy *proxy)
cast the proxy into the concrete data object it proxies
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