The Gaudi Framework  v36r7 (7f57a304)
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 static LinkManager* ( *s_newInstance )() = nullptr;
18 
21  for ( auto& i : m_linkVector ) delete i;
22 }
23 
26  if ( m_pObject ) {
27  IRegistry* pReg = m_pObject->registry();
28  if ( pReg ) return pReg->address();
29  }
30  return nullptr;
31 }
32 
35 
37 LinkManager* LinkManager::newInstance() { return s_newInstance ? ( *s_newInstance )() : new LinkManager(); }
38 
41  return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
42 }
43 
46  if ( !pObject ) return nullptr;
47  auto i = std::find_if( m_linkVector.begin(), m_linkVector.end(), [=]( auto* j ) { return j->object() == pObject; } );
48  return i != m_linkVector.end() ? *i : nullptr;
49 }
50 
53  if ( path.empty() ) return nullptr;
54  auto i = std::find_if( m_linkVector.begin(), m_linkVector.end(), [=]( auto* j ) { return j->path() == path; } );
55  return i != m_linkVector.end() ? *i : nullptr;
56 }
57 
59 long LinkManager::addLink( const std::string& path, const DataObject* pObject ) {
60  long n = 0;
61  for ( auto& lnk : m_linkVector ) {
62  const DataObject* pO = lnk->object();
63  if ( pO && pO == pObject ) return n;
64  if ( lnk->path() == path ) {
65  if ( pObject && pObject != pO ) { lnk->setObject( const_cast<DataObject*>( pObject ) ); }
66  return n;
67  }
68  ++n;
69  }
70  // Link is completely unknown
71  return m_linkVector.emplace_back( new Link( m_linkVector.size(), path, const_cast<DataObject*>( pObject ) ) )->ID();
72 }
std::string
STL class.
IOpaqueAddress
Definition: IOpaqueAddress.h:33
std::find_if
T find_if(T... args)
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