Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
LinkManager.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include <GaudiKernel/DataObject.h>
12 #include <GaudiKernel/IRegistry.h>
14 #include <algorithm>
15 
16 namespace {
17  template <typename Container, typename Pred>
18  auto findLink( Container& c, Pred pred ) {
19  auto i = std::find_if( c.begin(), c.end(), pred );
20  return i != c.end() ? *i : nullptr;
21  }
22 
23 } // namespace
24 
27  for ( auto& i : m_linkVector ) delete i;
28 }
29 
32  if ( m_pObject ) {
33  IRegistry* pReg = m_pObject->registry();
34  if ( pReg ) return pReg->address();
35  }
36  return nullptr;
37 }
38 
40 const LinkManager::Link* LinkManager::link( long id ) const {
41  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
42 }
43 
45  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
46 }
47 
49 const LinkManager::Link* LinkManager::link( const DataObject* pObject ) const {
50  return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
51 }
52 
54  return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
55 }
56 
58 const LinkManager::Link* LinkManager::link( std::string_view path ) const {
59  return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
60 }
62  return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
63 }
64 
66 long LinkManager::addLink( const std::string& path, const DataObject* pObject ) {
67  long n = 0;
68  for ( auto& lnk : m_linkVector ) {
69  const DataObject* pO = lnk->object();
70  if ( pO && pO == pObject ) return n;
71  if ( lnk->path() == path ) {
72  if ( pObject && pObject != pO ) { lnk->setObject( const_cast<DataObject*>( pObject ) ); }
73  return n;
74  }
75  ++n;
76  }
77  // Link is completely unknown
78  return m_linkVector.emplace_back( new Link( m_linkVector.size(), path, const_cast<DataObject*>( pObject ) ) )->ID();
79 }
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
IOpaqueAddress
Definition: IOpaqueAddress.h:28
gaudirun.c
c
Definition: gaudirun.py:525
IRegistry
Definition: IRegistry.h:29
GaudiPartProp.tests.id
id
Definition: tests.py:111
ProduceConsume.j
j
Definition: ProduceConsume.py:104
IRegistry.h
cpluginsvc.n
n
Definition: cpluginsvc.py:234
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
DataObject.h
DataObject
Definition: DataObject.h:37
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:79