Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r11 (bdb84f5f)
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-2019 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
13 #include "GaudiKernel/DataObject.h"
14 #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 
26 static LinkManager* ( *s_newInstance )() = nullptr;
27 
30  for ( auto& i : m_linkVector ) delete i;
31 }
32 
35  if ( m_pObject ) {
36  IRegistry* pReg = m_pObject->registry();
37  if ( pReg ) return pReg->address();
38  }
39  return nullptr;
40 }
41 
44 
46 LinkManager* LinkManager::newInstance() { return s_newInstance ? ( *s_newInstance )() : new LinkManager(); }
47 
49 const LinkManager::Link* LinkManager::link( long id ) const {
50  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
51 }
52 
54  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
55 }
56 
58 const LinkManager::Link* LinkManager::link( const DataObject* pObject ) const {
59  return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
60 }
61 
63  return pObject ? findLink( m_linkVector, [=]( auto* j ) { return j->object() == pObject; } ) : nullptr;
64 }
65 
67 const LinkManager::Link* LinkManager::link( std::string_view path ) const {
68  return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
69 }
71  return !path.empty() ? findLink( m_linkVector, [=]( auto* j ) { return j->path() == path; } ) : nullptr;
72 }
73 
75 long LinkManager::addLink( const std::string& path, const DataObject* pObject ) {
76  long n = 0;
77  for ( auto& lnk : m_linkVector ) {
78  const DataObject* pO = lnk->object();
79  if ( pO && pO == pObject ) return n;
80  if ( lnk->path() == path ) {
81  if ( pObject && pObject != pO ) { lnk->setObject( const_cast<DataObject*>( pObject ) ); }
82  return n;
83  }
84  ++n;
85  }
86  // Link is completely unknown
87  return m_linkVector.emplace_back( new Link( m_linkVector.size(), path, const_cast<DataObject*>( pObject ) ) )->ID();
88 }
std::string
STL class.
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
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:961
IRegistry.h
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:235
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
DataObject.h
DataObject
Definition: DataObject.h:40
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82