The Gaudi Framework  master (37c0b60a)
NTupleItems.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 
12 // cppcheck-suppress-file passedByValue; TYP is a small type
13 
14 #ifndef GAUDI_NTUPLESVC_NTUPLEITEMS_H
15 #define GAUDI_NTUPLESVC_NTUPLEITEMS_H 1
16 
17 // The converter understands all items
18 #define ALLOW_ALL_TYPES
19 
20 // STL include files
21 #include <vector>
22 
23 // Framework include files
24 #include "NTuple.h"
25 #include <GaudiKernel/System.h>
37 // Forward declarations
38 class IDataProviderSvc;
39 class IConversionSvc;
40 
41 namespace NTuple {
42  // Local forward declarations
43  template <class TYP>
44  class DataItem;
45  template <class TYP>
46  class _DataImp;
47  template <class TYP>
48  class _ItemImp;
49  template <class TYP>
50  class _ArrayImp;
51  template <class TYP>
52  class _MatrixImp;
53 
56  template <class TYP>
57  class _DataImp : virtual public _Data<TYP> {
59  _DataImp( const _DataImp& ) = delete;
60 
61  protected:
62  typedef const std::string& CSTR;
63  typedef const std::type_info& CTYPE;
65  long m_length;
73  mutable INTupleItem* m_indexItem = nullptr;
77  TYP m_def;
82 
83  public:
87  _DataImp( INTuple* tup, std::string name, const std::type_info& info, std::string index, long len, TYP low,
88  TYP high, TYP def )
89  : m_length( len )
90  , m_tuple( tup )
91  , m_name( std::move( name ) )
92  , m_index( std::move( index ) )
93  , m_def( std::move( def ) )
94  , m_range( std::move( low ), std::move( high ) )
95  , m_info( info ) {
96  m_type = typeid( TYP ) == typeid( void* ) ? DataTypeInfo::POINTER : DataTypeInfo::ID( info );
97  this->m_buffer = new TYP[m_length];
98  reset();
99  }
101  ~_DataImp() override { delete[] this->m_buffer; }
103  std::string typeName() const override { return System::typeinfoName( this->typeID() ); }
105  void reset() override { std::fill_n( this->m_buffer, m_length, m_def ); }
107  long filled() const override {
108  long len = 1;
109  long nd = ndim();
110  if ( m_length > 1 ) {
111  for ( int l = 0; l < nd - 1; l++ ) { len *= dim( l ); }
112  if ( indexItem() ) {
113  long* ll = (long*)m_indexItem->buffer();
114  len *= *ll;
115  } else if ( nd > 0 ) {
116  len *= dim( nd - 1 );
117  }
118  }
119  return len;
120  }
122  INTupleItem* indexItem() override {
124  return m_indexItem;
125  }
127  const INTupleItem* indexItem() const override {
129  return m_indexItem;
130  }
132  const std::type_info& typeID() const override { return m_info; }
134  long size() const override { return m_length * sizeof( TYP ); }
136  void release() override { delete this; }
138  bool hasIndex() const override { return m_index.length() > 0; }
140  const std::string& index() const override { return m_index; }
142  const std::string& name() const override { return m_name; }
144  long type() const override { return m_type; }
146  void setType( long t ) override { m_type = DataTypeInfo::Type( t ); }
148  void setDefault( const TYP val ) override { m_def = val; }
150  const ItemRange& range() const override { return m_range; }
152  long length() const override { return m_length; }
154  const void* buffer() const override { return this->m_buffer; }
156  virtual void* buffer() { return this->m_buffer; }
158  long ndim() const override { return 0; }
160  long dim( long i ) const override { return ( i == 0 ) ? 1 : 0; }
162  INTuple* tuple() override { return m_tuple; }
163  };
164 
167  template <class TYP>
168  class _ItemImp : virtual public _DataImp<TYP>, virtual public _Item<TYP> {
169 
170  public:
174  _ItemImp( INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def )
175  : _DataImp<TYP>( tup, name, info, "", 1, min, max, def ) {}
177  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Item<TYP>); }
179  void setDefault( const TYP val ) override { this->m_def = val; }
181  const ItemRange& range() const override { return this->m_range; }
183  long size() const override { return this->m_length * sizeof( TYP ); }
184  };
185 
188  template <class TYP>
189  class _ArrayImp : virtual public _DataImp<TYP>, virtual public _Array<TYP> {
190  public:
194  _ArrayImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long len,
195  TYP min, TYP max, TYP def )
196  : _DataImp<TYP>( tup, name, typ, index, len, min, max, def ) {}
198  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Array<TYP>); }
200  void setDefault( const TYP val ) override { this->m_def = val; }
202  const ItemRange& range() const override { return this->m_range; }
204  long size() const override { return this->m_length * sizeof( TYP ); }
206  long ndim() const override { return 1; }
208  long dim( long i ) const override { return ( i != 0 || this->hasIndex() ) ? 0 : this->m_length; }
209  };
210 
213  template <class TYP>
214  class _MatrixImp : virtual public _DataImp<TYP>, virtual public _Matrix<TYP> {
215  public:
219  _MatrixImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long ncol,
220  long nrow, TYP min, TYP max, TYP def )
221  : _DataImp<TYP>( tup, name, typ, index, nrow * ncol, min, max, def ) {
222  this->m_rows = nrow;
223  }
225  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Matrix<TYP>);}
227  void setDefault( const TYP val ) override { this->m_def = val; }
229  const ItemRange& range() const override { return this->m_range; }
231  long size() const override { return this->m_length * sizeof( TYP ); }
233  long ndim() const override { return 2; }
235  long dim( long i ) const override {
236  return ( this->hasIndex() ) ? ( ( i == 0 ) ? this->m_rows : this->m_length / this->m_rows )
237  : ( ( i == 1 ) ? this->m_length / this->m_rows : this->m_rows );
238  }
239  };
240 } // namespace NTuple
241 #endif // GAUDI_NTUPLESVC_NTUPLEITEMS_H
NTuple::_ArrayImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:192
NTuple::_DataImp::indexItem
const INTupleItem * indexItem() const override
Pointer to index column (if present, 0 else) (CONST)
Definition: NTupleItems.h:127
DataTypeInfo::ID
static Type ID(const bool)
Access to type information: bool.
Definition: DataTypeInfo.h:58
std::string
STL class.
NTuple::_ArrayImp::range
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:202
NTuple::_DataImp::length
long length() const override
Access the buffer length.
Definition: NTupleItems.h:152
NTuple::_DataImp::setDefault
void setDefault(const TYP val) override
Set default value.
Definition: NTupleItems.h:148
NTuple::_MatrixImp::setDefault
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:227
NTuple::_DataImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:134
NTuple::_MatrixImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:217
System.h
NTuple::_DataImp::CTYPE
const std::type_info & CTYPE
Definition: NTupleItems.h:63
NTuple::_DataImp::typeName
std::string typeName() const override
Get proper type name.
Definition: NTupleItems.h:103
NTuple::_DataImp::m_index
std::string m_index
Check that values are within a certain range while filling.
Definition: NTupleItems.h:71
std::string::length
T length(T... args)
std::type_info
NTuple::_ItemImp::_ItemImp
_ItemImp(INTuple *tup, const std::string &name, const std::type_info &info, TYP min, TYP max, TYP def)
Standard Constructor.
Definition: NTupleItems.h:174
NTuple::_ArrayImp::_ArrayImp
_ArrayImp(INTuple *tup, const std::string &name, const std::type_info &typ, const std::string &index, long len, TYP min, TYP max, TYP def)
Standard Constructor.
Definition: NTupleItems.h:194
NTuple::DataItem
Definition: NTupleItems.h:44
NTuple::_DataImp::m_length
long m_length
Entire buffer length.
Definition: NTupleItems.h:65
NTuple::_DataImp::release
void release() override
Destruct object.
Definition: NTupleItems.h:136
NTuple::_ItemImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:183
DataTypeInfo::POINTER
@ POINTER
Definition: DataTypeInfo.h:50
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:315
INTuple::find
virtual const INTupleItem * find(const std::string &name) const =0
Find an item row of the Ntuple (CONST)
NTuple::_DataImp::index
const std::string & index() const override
Access the index _Column.
Definition: NTupleItems.h:140
NTuple::_DataImp
Concrete class discribing basic data items in an N tuple.
Definition: NTupleItems.h:46
NTuple::_ItemImp::setDefault
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:179
NTuple::_DataImp::setType
void setType(long t) override
Set the properties of the _Column.
Definition: NTupleItems.h:146
NTuple::_ArrayImp::ndim
long ndim() const override
Dimension.
Definition: NTupleItems.h:206
DataTypeInfo::Type
Type
Definition: DataTypeInfo.h:33
NTuple::_Data
Abstract class describing basic data in an Ntuple.
Definition: NTuple.h:48
bug_34121.t
t
Definition: bug_34121.py:31
NTuple::_ArrayImp::dim
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:208
NTuple::_DataImp::buffer
const void * buffer() const override
Access data buffer (CONST)
Definition: NTupleItems.h:154
NTuple::_DataImp::tuple
INTuple * tuple() override
Access to hosting ntuple.
Definition: NTupleItems.h:162
NTuple::_DataImp::CSTR
const std::string & CSTR
Definition: NTupleItems.h:62
NTuple::_ItemImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:172
NTuple::_MatrixImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:231
INTupleItem::buffer
virtual const void * buffer() const =0
Access data buffer (CONST)
NTuple::_DataImp::m_type
DataTypeInfo::Type m_type
_Column type
Definition: NTupleItems.h:75
NTuple.h
NTuple::_ItemImp::range
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:181
NTuple::_ArrayImp::setDefault
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:200
NTuple::_ArrayImp
Concrete class discribing a column-array in a N tuple.
Definition: NTupleItems.h:50
INTuple
Definition: INTuple.h:91
NTuple::_DataImp::~_DataImp
~_DataImp() override
Standard destructor.
Definition: NTupleItems.h:101
NTuple::_DataImp::name
const std::string & name() const override
Access _Column name.
Definition: NTupleItems.h:142
INTupleItem
Definition: INTuple.h:37
NTuple::_DataImp::m_tuple
INTuple * m_tuple
Pointer to N tuple.
Definition: NTupleItems.h:67
NTuple::_DataImp::m_info
const std::type_info & m_info
Item type information.
Definition: NTupleItems.h:81
NTuple::_DataImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:85
NTuple::_MatrixImp::_MatrixImp
_MatrixImp(INTuple *tup, const std::string &name, const std::type_info &typ, const std::string &index, long ncol, long nrow, TYP min, TYP max, TYP def)
Standard Constructor.
Definition: NTupleItems.h:219
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
NTuple::_MatrixImp
Concrete class discribing a matrix column in a N tuple.
Definition: NTupleItems.h:52
gaudirun.l
dictionary l
Definition: gaudirun.py:583
NTuple::_DataImp::filled
long filled() const override
Number of items filled.
Definition: NTupleItems.h:107
NTuple::_DataImp::m_range
Range< TYP > m_range
Check that values are within a certain range while filling.
Definition: NTupleItems.h:79
std
STL namespace.
NTuple::_MatrixImp::range
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:229
NTuple
NTuple name space.
Definition: INTupleSvc.h:19
NTuple::_DataImp::m_indexItem
INTupleItem * m_indexItem
Pointer to index item.
Definition: NTupleItems.h:73
NTuple::_DataImp::indexItem
INTupleItem * indexItem() override
Pointer to index column (if present, 0 else)
Definition: NTupleItems.h:122
NTuple::_DataImp::dim
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:160
NTuple::_DataImp::range
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:150
NTuple::_MatrixImp::ndim
long ndim() const override
Dimension.
Definition: NTupleItems.h:233
IDataProviderSvc
Definition: IDataProviderSvc.h:53
NTuple::_DataImp::buffer
virtual void * buffer()
Access data buffer.
Definition: NTupleItems.h:156
NTuple::_DataImp::m_name
std::string m_name
_Column name
Definition: NTupleItems.h:69
NTuple::_DataImp::_DataImp
_DataImp(const _DataImp &)=delete
Inhibit Copy Constructor.
std::fill_n
T fill_n(T... args)
NTuple::_MatrixImp::dim
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:235
NTuple::_DataImp::typeID
const std::type_info & typeID() const override
Compiler type ID.
Definition: NTupleItems.h:132
NTuple::_DataImp::m_def
TYP m_def
Buffer with default value.
Definition: NTupleItems.h:77
NTuple::_DataImp::hasIndex
bool hasIndex() const override
Is the tuple have an index column?
Definition: NTupleItems.h:138
NTuple::_DataImp::ndim
long ndim() const override
Dimension.
Definition: NTupleItems.h:158
NTuple::_DataImp::reset
void reset() override
Reset to default.
Definition: NTupleItems.h:105
NTuple::_DataImp::type
long type() const override
TYP information of the item.
Definition: NTupleItems.h:144
NTuple::_DataImp::_DataImp
_DataImp(INTuple *tup, std::string name, const std::type_info &info, std::string index, long len, TYP low, TYP high, TYP def)
Standard Constructor.
Definition: NTupleItems.h:87
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39
NTuple::_ItemImp
Concrete class discribing a column in a N tuple.
Definition: NTupleItems.h:48
NTuple::Range
Class defining a range.
Definition: NTuple.h:46
NTuple::_ArrayImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:204
IConversionSvc
Definition: IConversionSvc.h:47