| The Gaudi Framework v32r1 (f65d50dc)

LinkManager.cpp
Go to the documentation of this file.
1 // Experiment specific include files
2 #include "GaudiKernel/LinkManager.h"
3 #include "GaudiKernel/DataObject.h"
4 #include "GaudiKernel/IRegistry.h"
5
6 static LinkManager* ( *s_newInstance )() = nullptr;
7
9 LinkManager::~LinkManager() {
10 for ( auto& i : m_linkVector ) delete i;
11 }
12
14 IOpaqueAddress* LinkManager::Link::address() {
15 if ( m_pObject ) {
16 IRegistry* pReg = m_pObject->registry();
17 if ( pReg ) return pReg->address();
18 }
19 return nullptr;
20 }
21
23 void LinkManager::setInstantiator( LinkManager* ( *newInstance )() ) { s_newInstance = newInstance; }
24
26 LinkManager* LinkManager::newInstance() { return s_newInstance ? ( *s_newInstance )() : new LinkManager(); }
27
29 LinkManager::Link* LinkManager::link( long id ) {
30 return ( 0 <= id && (unsigned)id < m_linkVector.size() ) ? m_linkVector[id] : nullptr;
31 }
32
34 LinkManager::Link* LinkManager::link( const DataObject* pObject ) {
35 if ( pObject ) {
36 for ( auto& i : m_linkVector ) {
37 if ( i->object() == pObject ) return i;
38 }
39 }
40 return nullptr;
41 }
42
44 LinkManager::Link* LinkManager::link( const std::string& path ) {
45 if ( 0 != path.length() ) {
46 for ( auto& i : m_linkVector ) {
47 if ( i->path() == path ) return i;
48 }
49 }
50 return nullptr;
51 }
52
54 long LinkManager::addLink( const std::string& path, const DataObject* pObject ) const {
55 long n = 0;
56 for ( auto& lnk : m_linkVector ) {
57 const DataObject* pO = lnk->object();
58 if ( pO && pO == pObject ) return n;
59 if ( lnk->path() == path ) {
60 if ( pObject && pObject != pO ) { lnk->setObject( const_cast<DataObject*>( pObject ) ); }
61 return n;
62 }
63 ++n;
64 }
65 // Link is completely unknown
66 m_linkVector.emplace_back( new Link( m_linkVector.size(), path, const_cast<DataObject*>( pObject ) ) );
67 return m_linkVector.back()->ID();
68 }
69
70 // Remove a link by object reference
71 long LinkManager::removeLink( const DataObject* pObject ) const {
72 long n = 0;
73 for ( auto i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
74 if ( ( *i )->object() == pObject ) {
75 delete *i;
76 m_linkVector.erase( i );
77 return n;
78 }
79 ++n;
80 }
81 return INVALID;
82 }
83
84 // Remove a link by object reference
85 long LinkManager::removeLink( const std::string& path ) const {
86 long n = 0;
87 for ( auto i = m_linkVector.begin(); i != m_linkVector.end(); i++ ) {
88 if ( ( *i )->path() == path ) {
89 delete *i;
90 m_linkVector.erase( i );
91 return n;
92 }
93 n++;
94 }
95 return INVALID;
96 }
97
98 // Remove a link by object reference
99 long LinkManager::removeLink( long id ) const {
100 auto i = std::next( m_linkVector.begin(), id );
101 delete *i;
102 m_linkVector.erase( i );
103 return id;
104 }
105
107 void LinkManager::clearLinks() {
108 for ( auto& i : m_linkVector ) delete i;
109 m_linkVector.clear();
110 }
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
LinkManager.h
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:932
LinkManager::removeLink
long removeLink(const DataObject *pObject) const
Remove link by object reference.
Definition: LinkManager.cpp:71
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
LinkManager::setInstantiator
static void setInstantiator(LinkManager *(*newInstance)())
Assign new instantiator.
Definition: LinkManager.cpp:23
LinkManager::Link::address
IOpaqueAddress * address()
Access to the object's address.
Definition: LinkManager.cpp:14
LinkManager::m_linkVector
std::vector< Link * > m_linkVector
@ TODO: replace by std::vector<std::unique_ptr<Link>> once ROOT does 'automatic' schema conversion fr...
Definition: LinkManager.h:88
std::next
T next(T... args)
LinkManager::clearLinks
void clearLinks()
Remove all possibly existing symbolic links.
Definition: LinkManager.cpp:107
LinkManager::link
Link * link(long id)
Retrieve symbolic link identified by ID.
Definition: LinkManager.cpp:29
LinkManager::newInstance
static LinkManager * newInstance()
Static instantiation.
Definition: LinkManager.cpp:26
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
LinkManager::LinkManager
LinkManager()=default
Standard Constructor.
LinkManager::INVALID
Definition: LinkManager.h:25
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
LinkManager::Link
Embedded class defining a symbolic link Note: No copy constructor; bitwise copy (done by the compiler...
Definition: LinkManager.h:31
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
LinkManager::Link::m_pObject
DataObject * m_pObject
Pointer to object behind the link.
Definition: LinkManager.h:37
LinkManager
A LinkManager is the object aggregated into a DataObject, which is responsible for the handling of no...
Definition: LinkManager.h:21
LinkManager::~LinkManager
virtual ~LinkManager()
Standard Destructor.
Definition: LinkManager.cpp:9
DataObject.h
LinkManager::addLink
long addLink(const std::string &path, const DataObject *pObject) const
Add link by object reference and path.
Definition: LinkManager.cpp:54