Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SmartRefVector.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 
13 #include <GaudiKernel/SmartRef.h>
14 #include <vector>
15 
16 // forward declare _object and PyObject to avoid including Python.h here
17 struct _object;
18 namespace SmartRefVectorImpl {
19  using PyObject = _object;
20  // Avoid leaking the below into global namespace
22  // newer PyROOT will map SmartRefVector<TYPE>& operator()( ContainedObject* pObj )
23  // to "__getitem__" deleting it via this callback will make `__getitem__` call
24  // the operator [] from the base class
25  // see e.g. https://github.com/root-project/root/issues/7179
26  static void __cppyy_pythonize__( PyObject* klass, const std::string& name );
27  };
28 } // namespace SmartRefVectorImpl
29 
65 template <class TYPE>
67 protected:
71  typedef std::vector<_Entry> _Base;
72  typedef typename std::vector<_Entry>::const_iterator _BaseConstIter;
73  typedef typename std::vector<_Entry>::value_type _BaseValueType;
74 
76  mutable const DataObject* m_data;
78  mutable const ContainedObject* m_contd;
79 
81  void _setEnvironment( const DataObject* pObj, const ContainedObject* pContd ) const {
82  m_data = pObj;
83  m_contd = pContd;
84  for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); ++i ) { ( *i )._setEnvironment( pObj, pContd ); }
85  }
86 
87 public:
88  using SmartRefVectorPythonizer::__cppyy_pythonize__;
89 
91  m_contd = 0;
92  m_data = 0;
93  }
94  template <class ITERATOR>
95  SmartRefVector( ITERATOR first, ITERATOR last )
96  : std::vector<SmartRef<TYPE>>( first, last ), m_data( 0 ), m_contd( 0 ) {}
97  SmartRefVector( const SmartRefVector& copy ) : std::vector<SmartRef<TYPE>>( copy ) { *this = copy; }
98 
101  _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
102  return *this;
103  }
105  const SmartRefVector<TYPE>& operator()( const ContainedObject* pObj ) const {
106  _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
107  return *this;
108  }
111  _setEnvironment( pObj, 0 );
112  return *this;
113  }
115  const SmartRefVector<TYPE>& operator()( const DataObject* pObj ) const {
116  _setEnvironment( pObj, 0 );
117  return *this;
118  }
121  _Base::operator=( copy );
122  // Harms.... MF
123  // on copy we MUST make a 1 to 1 copy
124  // _setEnvironment( copy.m_data, copy.m_contd );
125  // use instead:
126  m_data = copy.m_data;
127  m_contd = copy.m_contd;
128  return *this;
129  }
131  const std::type_info* type() const { return &typeid( TYPE ); }
137  // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
138  friend StreamBuffer& operator<<( StreamBuffer& _s, const SmartRefVector<TYPE>& ptr ) { return ptr.writeRefs( _s ); }
140  // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
141  friend StreamBuffer& operator>>( StreamBuffer& _s, SmartRefVector<TYPE>& ptr ) { return ptr.readRefs( _s ); }
142 };
143 
144 template <class TYPE>
146  long len = _Base::size();
147  s << len;
148  for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) {
149  ( *i )._setEnvironment( m_data, m_contd );
150  ( *i ).writeRef( s );
151  }
152  return s;
153 }
154 
155 template <class TYPE>
157  long len;
158  _Base::erase( _Base::begin(), _Base::end() );
159  s >> len;
160  for ( long i = 0; i < len; i++ ) {
161  _BaseValueType entry;
162  entry._setEnvironment( m_data, m_contd );
163  entry.readRef( s );
164  _Base::push_back( entry );
165  }
166  return s;
167 }
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:23
SmartRefVector
Kernel objects: SmartRefVector.
Definition: SmartRefVector.h:66
GaudiPartProp.decorators.std
std
Definition: decorators.py:32
SmartRefVector::operator<<
friend StreamBuffer & operator<<(StreamBuffer &_s, const SmartRefVector< TYPE > &ptr)
Output Streamer operator.
Definition: SmartRefVector.h:138
gaudirun.s
string s
Definition: gaudirun.py:346
SmartRefVector::SmartRefVector
SmartRefVector()
Definition: SmartRefVector.h:90
SmartRefVector::_BaseValueType
std::vector< _Entry >::value_type _BaseValueType
Definition: SmartRefVector.h:73
SmartRefVectorImpl
Definition: SmartRefVector.h:18
SmartRefVector::operator()
SmartRefVector< TYPE > & operator()(ContainedObject *pObj)
operator(): assigns parent object for serialisation
Definition: SmartRefVector.h:100
SmartRefVector::operator()
SmartRefVector< TYPE > & operator()(DataObject *pObj)
operator(): assigns parent object for serialisation
Definition: SmartRefVector.h:110
SmartRefVector::m_contd
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefVector.h:78
StreamBuffer
Definition: StreamBuffer.h:48
SmartRefVector::operator()
const SmartRefVector< TYPE > & operator()(const DataObject *pObj) const
operator() const: assigns parent object for serialisation
Definition: SmartRefVector.h:115
SmartRefVector::SmartRefVector
SmartRefVector(const SmartRefVector &copy)
Definition: SmartRefVector.h:97
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:135
SmartRefVector::type
const std::type_info * type() const
Access to embedded type.
Definition: SmartRefVector.h:131
SmartRefVector::writeRefs
StreamBuffer & writeRefs(StreamBuffer &s) const
Helper to write references.
Definition: SmartRefVector.h:145
SmartRefVector::_BaseConstIter
std::vector< _Entry >::const_iterator _BaseConstIter
Definition: SmartRefVector.h:72
SmartRefVectorImpl::PyObject
_object PyObject
Definition: SmartRefVector.h:19
SmartRefVector::_Base
std::vector< _Entry > _Base
Object types: typedef myself as Base.
Definition: SmartRefVector.h:71
SmartRef.h
SmartRefVector::m_data
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefVector.h:76
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:59
Containers::vector
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
Definition: KeyedObjectManager.h:31
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
SmartRefVector::operator>>
friend StreamBuffer & operator>>(StreamBuffer &_s, SmartRefVector< TYPE > &ptr)
Input Streamer operator.
Definition: SmartRefVector.h:141
SmartRefVector::SmartRefVector
SmartRefVector(ITERATOR first, ITERATOR last)
Definition: SmartRefVector.h:95
SmartRefVector::_Entry
SmartRef< TYPE > _Entry
That's the type of crap I am hosting.
Definition: SmartRefVector.h:69
DataObject
Definition: DataObject.h:37
SmartRefVector::operator=
SmartRefVector< TYPE > & operator=(const SmartRefVector< TYPE > &copy)
Assignment.
Definition: SmartRefVector.h:120
SmartRefVector::operator()
const SmartRefVector< TYPE > & operator()(const ContainedObject *pObj) const
operator() const: assigns parent object for serialisation
Definition: SmartRefVector.h:105
SmartRefVector::readRefs
StreamBuffer & readRefs(StreamBuffer &s)
Helper to read references.
Definition: SmartRefVector.h:156
SmartRef
Kernel objects: SmartRef.
Definition: SmartRef.h:64
IOTest.end
end
Definition: IOTest.py:125
SmartRefVectorImpl::SmartRefVectorPythonizer
Definition: SmartRefVector.h:21
SmartRefVector::_setEnvironment
void _setEnvironment(const DataObject *pObj, const ContainedObject *pContd) const
Set the environment for the vector and all contained objects references.
Definition: SmartRefVector.h:81
ContainedObject
Definition: ContainedObject.h:37
SmartRefVectorImpl::SmartRefVectorPythonizer::__cppyy_pythonize__
static void __cppyy_pythonize__(PyObject *klass, const std::string &name)
Definition: SmartRefVector.cpp:15