The Gaudi Framework  v30r4 (9b837755)
DataHandle.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_DATAHANDLE
2 #define GAUDIKERNEL_DATAHANDLE 1
3 
6 #include "GaudiKernel/Property.h"
7 #include <string>
8 #include <type_traits>
9 
10 //---------------------------------------------------------------------------
11 
25 //---------------------------------------------------------------------------
26 
27 class IDataHandleHolder;
28 
29 namespace Gaudi
30 {
31 
32  inline namespace v1
33  {
34  class DataHandle
35  {
36  public:
37  enum Mode { Reader = 1 << 2, Writer = 1 << 4, Updater = Reader | Writer };
38 
39  DataHandle( const DataObjID& k, Mode a = Reader, IDataHandleHolder* owner = nullptr )
40  : m_key( k ), m_owner( owner ), m_mode( a ){};
41 
42  DataHandle( const DataObjID& k, const bool& isCond, Mode a = Reader, IDataHandleHolder* owner = nullptr )
43  : m_key( k ), m_owner( owner ), m_mode( a ), m_isCond( isCond ){};
44 
45  virtual ~DataHandle() = default;
46 
47  virtual void setOwner( IDataHandleHolder* o ) { m_owner = o; }
48  virtual IDataHandleHolder* owner() const { return m_owner; }
49 
50  virtual Mode mode() const { return m_mode; }
51 
52  virtual void setKey( const DataObjID& key ) const { m_key = key; }
53  virtual void updateKey( const std::string& key ) const { m_key.updateKey( key ); }
54 
55  virtual const std::string& objKey() const { return m_key.key(); }
56  virtual const DataObjID& fullKey() const { return m_key; }
57 
58  virtual void reset( bool ){};
59 
60  virtual std::string pythonRepr() const;
61  virtual bool init() { return true; }
62 
63  // is this a ConditionHandle?
64  virtual bool isCondition() const { return m_isCond; }
65 
66  protected:
73  mutable DataObjID m_key = {"NONE"};
75 
76  private:
78  bool m_isCond = false;
79  };
80  }
81 
82  namespace v2
83  {
91  class DataHandle
92  {
93  public:
94  // DataHandles are used for the purpose of accounting component data
95  // dependencies, and should thus never be copied.
96  DataHandle( const DataHandle& ) = delete;
97  DataHandle& operator=( const DataHandle& ) = delete;
98 
99  // DataHandles pass a pointer to themselves to the host Algorithm during
100  // registration, which happens at construction time. They should thus
101  // not be moved, as that would invalidate said pointer.
102  //
103  // The only reason why we don't delete the DataHandle move constructor
104  // as well is that it would also forbid some safe and useful forms of
105  // in-place construction.
106  //
107  // We will be able to plug this memory safety hole, and set this to
108  // "= delete" the way it should be, once Gaudi switches to C++17-only and
109  // guaranteed copy elision can be taken for granted.
110  //
111  DataHandle( DataHandle&& ) = default;
112  DataHandle& operator=( DataHandle&& ) = delete;
113 
114  // Manner in which this DataHandle will be accessing its whiteboard
116  AccessMode access() const { return m_property.metadata().access(); }
117 
133  const DataObjID& targetKey() const { return m_property.targetKey(); }
134 
136  void setTargetKey( const DataObjID& id ) { m_property.setTargetKey( id ); }
137 
144  virtual void initialize( const IDataHandleHolder& owner ) = 0;
145 
152  bool ownerSetupDone() const { return m_ownerSetupDone; }
153 
160  template <typename Owner, std::enable_if_t<std::is_base_of<IDataHandleHolder, Owner>::value>* = nullptr>
161  void setOwner( Owner& owner )
162  {
163  if ( m_ownerSetupDone ) {
164  throw std::runtime_error( "Attempted to set DataHandle owner twice" );
165  }
166  m_property.setOwner( &owner );
167  m_ownerSetupDone = true;
168  }
169 
170  protected:
173  template <typename Owner, typename T = DataObjID,
174  std::enable_if_t<std::is_base_of<IDataHandleHolder, Owner>::value>* = nullptr>
175  DataHandle( Owner& owner, const std::string& propertyName, T&& defaultID, const std::string& docString,
176  const IDataHandleMetadata& metadata )
177  : m_property{&owner, propertyName, {metadata, std::forward<T>( defaultID )}, docString}
178  , m_ownerSetupDone{true}
179  {
180  }
181 
191  template <typename T = DataObjID>
192  explicit DataHandle( const std::string& propertyName, T&& defaultID, const std::string& docString,
193  const IDataHandleMetadata& metadata )
194  : m_property{propertyName, {metadata, std::forward<T>( defaultID )}, docString}, m_ownerSetupDone{false}
195  {
196  }
197 
198  private:
201 
204  };
205  }
206 }
207 
208 #endif
DataObjID m_key
The key of the object behind this DataHandle Although it may look strange to have it mutable...
Definition: DataHandle.h:73
virtual void reset(bool)
Definition: DataHandle.h:58
DataHandle(const DataObjID &k, const bool &isCond, Mode a=Reader, IDataHandleHolder *owner=nullptr)
Definition: DataHandle.h:42
Implementation of property with value of concrete type.
Definition: Property.h:383
AccessMode
Tell how the whiteboard class will be accessed.
const DataObjID & targetKey() const
(Configurable) ID of the data being accessed via this handle
Definition: DataHandle.h:133
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:48
void updateKey(const std::string &key)
Definition: DataObjID.h:100
IDataHandleHolder * m_owner
Definition: DataHandle.h:74
virtual bool init()
Definition: DataHandle.h:61
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
void setOwner(Owner &owner)
Setup the owner of this DataHandle.
Definition: DataHandle.h:161
Entity which holds DataHandles and can track the associated data dependencies for the Scheduler...
virtual void setOwner(IDataHandleHolder *o)
Definition: DataHandle.h:47
DataHandle(const DataObjID &k, Mode a=Reader, IDataHandleHolder *owner=nullptr)
Definition: DataHandle.h:39
DataHandle(const std::string &propertyName, T &&defaultID, const std::string &docString, const IDataHandleMetadata &metadata)
The above constructor is easier to use correctly, and therefore preferred.
Definition: DataHandle.h:192
bool ownerSetupDone() const
Truth that owner setup has been performed.
Definition: DataHandle.h:152
virtual const DataObjID & fullKey() const
Definition: DataHandle.h:56
const std::string & key() const
Definition: DataObjID.h:49
virtual Mode mode() const
Definition: DataHandle.h:50
Base class to all new-style data handles.
Definition: DataHandle.h:91
virtual bool isCondition() const
Definition: DataHandle.h:64
virtual void setKey(const DataObjID &key) const
Definition: DataHandle.h:52
Interface to some class-wide metadata of DataHandle subclasses.
void setTargetKey(const DataObjID &id)
Change the ID of the target data.
Definition: DataHandle.h:136
bool m_ownerSetupDone
Truth that owner setup has been performed.
Definition: DataHandle.h:203
Gaudi::Property< DataHandleConfigurable > m_property
Configurable property associated with a DataHandle.
Definition: DataHandle.h:200
virtual ~DataHandle()=default
virtual std::string pythonRepr() const
DataHandle(Owner &owner, const std::string &propertyName, T &&defaultID, const std::string &docString, const IDataHandleMetadata &metadata)
Handles are constructed like a Gaudi property (and effectively behave as one, which sets the associat...
Definition: DataHandle.h:175
virtual void updateKey(const std::string &key) const
Definition: DataHandle.h:53
AccessMode access() const
Definition: DataHandle.h:116
virtual const std::string & objKey() const
Definition: DataHandle.h:55
Helper functions to set/get the application return code.
Definition: __init__.py:1