The Gaudi Framework  master (6507eef1)
Loading...
Searching...
No Matches
DataHandle.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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#pragma once
12
15#include <GaudiKernel/System.h>
16
17#include <span>
18#include <sstream>
19#include <tuple>
20#include <vector>
21
22//---------------------------------------------------------------------------
23
36
37//---------------------------------------------------------------------------
38
40
41namespace Gaudi {
42
43 class DataHandle {
44 public:
45 enum Mode { Reader = 1 << 2, Writer = 1 << 4 };
46
48 : m_key( std::move( k ) ), m_owner( owner ), m_mode( a ) {}
49
50 DataHandle( DataObjID k, bool isCond, Mode a = Reader, IDataHandleHolder* owner = nullptr )
51 : m_key( std::move( k ) ), m_owner( owner ), m_mode( a ), m_isCond( isCond ) {}
52
54
55 virtual ~DataHandle() = default;
56
57 virtual void setOwner( IDataHandleHolder* o ) { m_owner = o; }
58 virtual IDataHandleHolder* owner() const { return m_owner; }
59
60 virtual Mode mode() const { return m_mode; }
61
62 virtual void setKey( DataObjID key ) { m_key = std::move( key ); }
63 virtual void updateKey( std::string key ) { m_key.updateKey( std::move( key ) ); }
64
65 virtual const std::string& objKey() const { return m_key.key(); }
66 virtual const DataObjID& fullKey() const { return m_key; }
67
68 virtual void reset( bool ) {}
69
70 virtual std::string pythonRepr() const;
71 virtual bool init() { return true; }
72
73 // is this a ConditionHandle?
74 virtual bool isCondition() const { return m_isCond; }
75
76 friend std::ostream& operator<<( std::ostream& str, const DataHandle& d );
77
78 protected:
85 DataObjID m_key = { "NONE" };
87
88 static const std::string default_type;
89
90 private:
92 bool m_isCond = false;
93 };
94
101 public:
103
104 virtual ~DataHandleVectorBase() = default;
105
107 virtual void setKeys( std::span<const DataObjID> keys ) = 0;
109 virtual const std::vector<DataObjID>& keys() const = 0;
111 virtual DataHandle::Mode mode() const = 0;
113 virtual std::string type() const = 0;
114
116 std::string pythonPropertyClassName() const { return "DataHandleVector"; }
118 std::string semantics() const;
120 std::string pythonRepr() const;
121 };
122
131 template <template <typename> class Handle, typename T>
133 public:
141 template <typename Owner>
142 DataHandleVector( Owner* parent, std::string name, const std::vector<std::string>& keys, std::string doc = "" )
143 : m_owner{ parent } {
144 std::vector<DataObjID> ids;
145 ids.reserve( keys.size() );
146 for ( const auto& key : keys ) ids.emplace_back( key );
147 setKeys( ids );
148 auto p = parent->declareProperty( std::move( name ), *this, std::move( doc ) );
149 p->template setOwnerType<Owner>();
150 }
151
158 template <typename Owner>
159 DataHandleVector( Owner* parent, const std::pair<std::string, std::vector<std::string>>& keys )
160 : DataHandleVector{ parent, keys.first, keys.second } {}
161
167 template <typename Owner, typename Keys>
168 DataHandleVector( std::tuple<Owner, Keys>&& keys ) : DataHandleVector{ std::get<0>( keys ), std::get<1>( keys ) } {}
169
175 template <typename Owner, typename Name, typename Keys>
176 DataHandleVector( std::tuple<Owner, Name, Keys>&& keys )
177 : DataHandleVector{ std::get<0>( keys ), std::get<1>( keys ), std::get<2>( keys ) } {}
178
180 void setKeys( std::span<const DataObjID> keys ) override {
181 m_keys.assign( keys.begin(), keys.end() );
182 m_handles.clear();
183 m_handles.reserve( m_keys.size() );
184 for ( const auto& key : m_keys ) m_handles.emplace_back( key, m_owner );
185 }
186
188 void clear() { setKeys( std::span<const DataObjID>{} ); }
189
191 const std::vector<DataObjID>& keys() const override { return m_keys; }
193 const std::vector<Handle<T>>& handles() const { return m_handles; }
195 const DataObjID& at( std::size_t i ) const { return m_keys.at( i ); }
197 auto size() const { return m_handles.size(); }
198
200 DataHandle::Mode mode() const override { return Handle<T>::mode_v; }
202 std::string type() const override { return System::typeinfoName( typeid( T ) ); }
203
204 protected:
206 std::vector<DataObjID> m_keys;
207 std::vector<Handle<T>> m_handles;
208 };
209
210 namespace Parsers {
211 StatusCode parse( DataHandle&, std::string_view );
212 }
213 namespace Utils {
214 GAUDI_API std::ostream& toStream( const DataHandle& v, std::ostream& o );
215 }
216} // namespace Gaudi
#define GAUDI_API
Definition Kernel.h:49
DataHandleProperty.h GaudiKernel/DataHandleProperty.h.
virtual bool init()
Definition DataHandle.h:71
DataHandle(DataObjID k, bool isCond, Mode a=Reader, IDataHandleHolder *owner=nullptr)
Definition DataHandle.h:50
virtual void setOwner(IDataHandleHolder *o)
Definition DataHandle.h:57
static const std::string default_type
Definition DataHandle.h:88
virtual std::string pythonRepr() const
friend std::ostream & operator<<(std::ostream &str, const DataHandle &d)
DataObjID m_key
The key of the object behind this DataHandle Although it may look strange to have it mutable,...
Definition DataHandle.h:85
virtual bool isCondition() const
Definition DataHandle.h:74
IDataHandleHolder * m_owner
Definition DataHandle.h:86
virtual IDataHandleHolder * owner() const
Definition DataHandle.h:58
virtual const std::string & objKey() const
Definition DataHandle.h:65
virtual void updateKey(std::string key)
Definition DataHandle.h:63
virtual Mode mode() const
Definition DataHandle.h:60
virtual void setKey(DataObjID key)
Definition DataHandle.h:62
virtual ~DataHandle()=default
virtual const DataObjID & fullKey() const
Definition DataHandle.h:66
DataHandleProperty PropertyType
Definition DataHandle.h:53
DataHandle(DataObjID k, Mode a=Reader, IDataHandleHolder *owner=nullptr)
Definition DataHandle.h:47
virtual void reset(bool)
Definition DataHandle.h:68
Type-erased interface for a configurable sequence of data handles.
Definition DataHandle.h:100
virtual std::string type() const =0
Demangled C++ type of the data accessed by each handle.
std::string semantics() const
GaudiConfig2 semantics name including handle mode and value type.
virtual const std::vector< DataObjID > & keys() const =0
Configured TES keys, in property order.
virtual void setKeys(std::span< const DataObjID > keys)=0
Replace the configured TES keys and rebuild the typed handles.
virtual DataHandle::Mode mode() const =0
Access mode shared by all handles in the vector.
DataHandleVectorProperty PropertyType
Definition DataHandle.h:102
std::string pythonPropertyClassName() const
Python class used to represent the property value.
Definition DataHandle.h:116
std::string pythonRepr() const
Python expression reproducing the configured value.
virtual ~DataHandleVectorBase()=default
const DataObjID & at(std::size_t i) const
Configured TES key at i.
Definition DataHandle.h:195
std::string type() const override
Demangled C++ type accessed by every contained handle.
Definition DataHandle.h:202
DataHandle::Mode mode() const override
Access mode shared by every contained handle.
Definition DataHandle.h:200
DataHandleVector(std::tuple< Owner, Name, Keys > &&keys)
Adapt the owner/name/default tuple produced internally by DataHandleMixin to the public constructor.
Definition DataHandle.h:176
DataHandleVector(std::tuple< Owner, Keys > &&keys)
Adapt the owner/name-and-default tuple produced internally by DataHandleMixin to the public construct...
Definition DataHandle.h:168
const std::vector< Handle< T > > & handles() const
Typed handles, in property order.
Definition DataHandle.h:193
void clear()
Remove all configured keys and unregister their typed handles.
Definition DataHandle.h:188
auto size() const
Number of configured handles.
Definition DataHandle.h:197
DataHandleVector(Owner *parent, std::string name, const std::vector< std::string > &keys, std::string doc="")
Declare a vector data-handle property on an owning component.
Definition DataHandle.h:142
DataHandleVector(Owner *parent, const std::pair< std::string, std::vector< std::string > > &keys)
Construct from the property-name/default-value pair used by the Functional algorithm data-handle mach...
Definition DataHandle.h:159
void setKeys(std::span< const DataObjID > keys) override
Replace the configured TES keys and their registered typed handles.
Definition DataHandle.h:180
std::vector< OutputHandleFor< Tr, Default >::template type< T > > m_handles
Definition DataHandle.h:207
const std::vector< DataObjID > & keys() const override
Definition DataHandle.h:191
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition ToStream.h:307
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:254
STL namespace.