All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
KeyedObject.cpp
Go to the documentation of this file.
1 // $Id $
2 // Include files
3 #include "GaudiKernel/Kernel.h"
10 
16 namespace Objects {
17  bool access(const ContainedObject* from, ContainedObject** to);
18  bool access(const DataObject* from, DataObject** to);
19 
20  template <class TO, class FROM>
21  TO* reference(FROM* from) {
22  ContainedObject* to = 0;
23  if ( access(from, &to) ) {
24  return dynamic_cast<TO*>(to);
25  }
26  return 0;
27  }
28 }
29 
30 bool Objects::access(const DataObject* from, DataObject** to)
31 {
32  DataObject* src = const_cast<DataObject*>(from);
33  DataObject* tar = 0;
34  if ( src != 0 )
35  {
36  LinkManager* mgr = src->linkMgr();
37  if ( 0 != mgr )
38  {
39  LinkManager::Link* link = mgr->link(long(0));
40  if ( 0 != link )
41  {
42  tar = link->object();
43  if ( 0 == tar )
44  {
45  IRegistry* reg = src->registry();
46  if ( 0 != reg )
47  {
48  IDataProviderSvc* ds = reg->dataSvc();
49  if ( 0 != ds )
50  {
51  if ( ds->retrieveObject(link->path(), tar).isSuccess() )
52  {
53  link->setObject(tar);
54  }
55  }
56  }
57  }
58  }
59  }
60  }
61  *to = tar;
62  return tar != 0;
63 }
64 
65 // Load on demand: ContainedObject type references
67 {
68  *to = 0;
69  if ( from )
70  {
71  DataObject *tar = 0;
72  if ( access(from->parent(), &tar) )
73  {
74  ObjectContainerBase* cnt = dynamic_cast<ObjectContainerBase*>(tar);
75  if ( cnt )
76  {
77  *to = cnt->containedObject(from->index());
78  }
79  }
80  }
81  return (*to) != 0;
82 }
83 
virtual long index() const
Distance in the parent container.
virtual ContainedObject * containedObject(long dist) const =0
Pointer to an object of a given distance.
bool access(const DataObject *from, DataObject **to)
Definition: KeyedObject.cpp:30
Data provider interface definition.
const ObjectContainerBase * parent() const
Access to parent object.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:69
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:73
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
bool access(const ContainedObject *from, ContainedObject **to)
Definition: KeyedObject.cpp:66
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
ObjectContainerBase is the base class for Gaudi container classes.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
TO * reference(FROM *from)
Definition: KeyedObject.cpp:21
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.