The Gaudi Framework  master (37c0b60a)
LinkManager.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 // Experiment specific include files
12 #include <GaudiKernel/DataObject.h>
13 #include <GaudiKernel/IRegistry.h>
15 #include <algorithm>
16 
17 namespace {
18  template <typename Container, typename Pred>
19  auto findLink( Container& c, Pred pred ) {
20  auto i = std::find_if( c.begin(), c.end(), pred );
21  return i != c.end() ? *i : nullptr;
22  }
23 
24 } // namespace
25 
28  for ( auto& i : m_linkVector ) delete i;
29 }
30 
33  if ( m_pObject ) {
34  IRegistry* pReg = m_pObject->registry();
35  if ( pReg ) return pReg->address();
36  }
37  return nullptr;
38 }
39 
41 const LinkManager::Link* LinkManager::link( long id ) const {
42  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
43 }
44 
46  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
47 }
48 
50 const LinkManager::Link* LinkManager::link( const DataObject* pObject ) const {
51  return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
52 }
53 
55  return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
56 }
57 
59 const LinkManager::Link* LinkManager::link( std::string_view path ) const {
60  return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
61 }
63  return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
64 }
65 
67 long LinkManager::addLink( const std::string& path, const DataObject* pObject ) {
68  long n = 0;
69  for ( auto& lnk : m_linkVector ) {
70  const DataObject* pO = lnk->object();
71  if ( pO && pO == pObject ) return n;
72  if ( lnk->path() == path ) {
73  if ( pObject && pObject != pO ) { lnk->setObject( const_cast<DataObject*>( pObject ) ); }
74  return n;
75  }
76  ++n;
77  }
78  // Link is completely unknown
79  return m_linkVector.emplace_back( new Link( m_linkVector.size(), path, const_cast<DataObject*>( pObject ) ) )->ID();
80 }
std::string
STL class.
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
IOpaqueAddress
Definition: IOpaqueAddress.h:33
std::find_if
T find_if(T... args)
gaudirun.c
c
Definition: gaudirun.py:525
IRegistry
Definition: IRegistry.h:32
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:36
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:78