Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
NTupleItems.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2021 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 #ifndef GAUDI_NTUPLESVC_NTUPLEITEMS_H
12 #define GAUDI_NTUPLESVC_NTUPLEITEMS_H 1
13 
14 // The converter understands all items
15 #define ALLOW_ALL_TYPES
16 
17 // STL include files
18 #include <vector>
19 
20 // Framework include files
21 #include "GaudiKernel/System.h"
22 #include "NTuple.h"
34 // Forward declarations
35 class IDataProviderSvc;
36 class IConversionSvc;
37 
38 namespace NTuple {
39  // Local forward declarations
40  template <class TYP>
41  class DataItem;
42  template <class TYP>
43  class _DataImp;
44  template <class TYP>
45  class _ItemImp;
46  template <class TYP>
47  class _ArrayImp;
48  template <class TYP>
49  class _MatrixImp;
50 
53  template <class TYP>
54  class _DataImp : virtual public _Data<TYP> {
56  _DataImp( const _DataImp& ) = delete;
57 
58  protected:
59  typedef const std::string& CSTR;
60  typedef const std::type_info& CTYPE;
62  long m_length;
70  mutable INTupleItem* m_indexItem = nullptr;
74  TYP m_def;
79 
80  public:
84  _DataImp( INTuple* tup, std::string name, const std::type_info& info, std::string index, long len, TYP low,
85  TYP high, TYP def )
86  : m_length( len )
87  , m_tuple( tup )
88  , m_name( std::move( name ) )
89  , m_index( std::move( index ) )
90  , m_def( std::move( def ) )
91  , m_range( std::move( low ), std::move( high ) )
92  , m_info( info ) {
93  m_type = typeid( TYP ) == typeid( void* ) ? DataTypeInfo::POINTER : DataTypeInfo::ID( info );
94  this->m_buffer = new TYP[m_length];
95  reset();
96  }
98  ~_DataImp() override { delete[] this->m_buffer; }
100  std::string typeName() const override { return System::typeinfoName( this->typeID() ); }
102  void reset() override { std::fill_n( this->m_buffer, m_length, m_def ); }
104  long filled() const override {
105  long len = 1;
106  long nd = ndim();
107  if ( m_length > 1 ) {
108  for ( int l = 0; l < nd - 1; l++ ) { len *= dim( l ); }
109  if ( indexItem() ) {
110  long* ll = (long*)m_indexItem->buffer();
111  len *= *ll;
112  } else if ( nd > 0 ) {
113  len *= dim( nd - 1 );
114  }
115  }
116  return len;
117  }
119  INTupleItem* indexItem() override {
121  return m_indexItem;
122  }
124  const INTupleItem* indexItem() const override {
126  return m_indexItem;
127  }
129  const std::type_info& typeID() const override { return m_info; }
131  long size() const override { return m_length * sizeof( TYP ); }
133  void release() override { delete this; }
135  bool hasIndex() const override { return m_index.length() > 0; }
137  const std::string& index() const override { return m_index; }
139  const std::string& name() const override { return m_name; }
141  long type() const override { return m_type; }
143  void setType( long t ) override { m_type = DataTypeInfo::Type( t ); }
145  void setDefault( const TYP val ) override { m_def = val; }
147  const ItemRange& range() const override { return m_range; }
149  long length() const override { return m_length; }
151  const void* buffer() const override { return this->m_buffer; }
153  virtual void* buffer() { return this->m_buffer; }
155  long ndim() const override { return 0; }
157  long dim( long i ) const override { return ( i == 0 ) ? 1 : 0; }
159  INTuple* tuple() override { return m_tuple; }
160  };
161 
164  template <class TYP>
165  class _ItemImp : virtual public _DataImp<TYP>, virtual public _Item<TYP> {
166 
167  public:
171  _ItemImp( INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def )
172  : _DataImp<TYP>( tup, name, info, "", 1, min, max, def ) {}
174  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Item<TYP>); }
176  void setDefault( const TYP val ) override { this->m_def = val; }
178  const ItemRange& range() const override { return this->m_range; }
180  long size() const override { return this->m_length * sizeof( TYP ); }
181  };
182 
185  template <class TYP>
186  class _ArrayImp : virtual public _DataImp<TYP>, virtual public _Array<TYP> {
187  public:
191  _ArrayImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long len,
192  TYP min, TYP max, TYP def )
193  : _DataImp<TYP>( tup, name, typ, index, len, min, max, def ) {}
195  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Array<TYP>); }
197  void setDefault( const TYP val ) override { this->m_def = val; }
199  const ItemRange& range() const override { return this->m_range; }
201  long size() const override { return this->m_length * sizeof( TYP ); }
203  long ndim() const override { return 1; }
205  long dim( long i ) const override { return ( i != 0 || this->hasIndex() ) ? 0 : this->m_length; }
206  };
207 
210  template <class TYP>
211  class _MatrixImp : virtual public _DataImp<TYP>, virtual public _Matrix<TYP> {
212  public:
216  _MatrixImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long ncol,
217  long nrow, TYP min, TYP max, TYP def )
218  : _DataImp<TYP>( tup, name, typ, index, nrow * ncol, min, max, def ) {
219  this->m_rows = nrow;
220  }
222  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Matrix<TYP>);}
224  void setDefault( const TYP val ) override { this->m_def = val; }
226  const ItemRange& range() const override { return this->m_range; }
228  long size() const override { return this->m_length * sizeof( TYP ); }
230  long ndim() const override { return 2; }
232  long dim( long i ) const override {
233  return ( this->hasIndex() ) ? ( ( i == 0 ) ? this->m_rows : this->m_length / this->m_rows )
234  : ( ( i == 1 ) ? this->m_length / this->m_rows : this->m_rows );
235  }
236  };
237 } // namespace NTuple
238 #endif // GAUDI_NTUPLESVC_NTUPLEITEMS_H
NTuple::_ArrayImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:189
NTuple::_DataImp::indexItem
const INTupleItem * indexItem() const override
Pointer to index column (if present, 0 else) (CONST)
Definition: NTupleItems.h:124
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:199
NTuple::_DataImp::length
long length() const override
Access the buffer length.
Definition: NTupleItems.h:149
NTuple::_DataImp::setDefault
void setDefault(const TYP val) override
Set default value.
Definition: NTupleItems.h:145
NTuple::_MatrixImp::setDefault
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:224
NTuple::_DataImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:131
NTuple::_MatrixImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:214
System.h
NTuple::_DataImp::CTYPE
const std::type_info & CTYPE
Definition: NTupleItems.h:60
NTuple::_DataImp::typeName
std::string typeName() const override
Get proper type name.
Definition: NTupleItems.h:100
NTuple::_DataImp::m_index
std::string m_index
Check that values are within a certain range while filling.
Definition: NTupleItems.h:68
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:171
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:191
NTuple::DataItem
Definition: NTupleItems.h:41
NTuple::_DataImp::m_length
long m_length
Entire buffer length.
Definition: NTupleItems.h:62
NTuple::_DataImp::release
void release() override
Destruct object.
Definition: NTupleItems.h:133
NTuple::_ItemImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:180
DataTypeInfo::POINTER
@ POINTER
Definition: DataTypeInfo.h:50
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:313
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:137
NTuple::_DataImp
Concrete class discribing basic data items in an N tuple.
Definition: NTupleItems.h:43
NTuple::_ItemImp::setDefault
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:176
NTuple::_DataImp::setType
void setType(long t) override
Set the properties of the _Column.
Definition: NTupleItems.h:143
NTuple::_ArrayImp::ndim
long ndim() const override
Dimension.
Definition: NTupleItems.h:203
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:30
NTuple::_ArrayImp::dim
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:205
NTuple::_DataImp::buffer
const void * buffer() const override
Access data buffer (CONST)
Definition: NTupleItems.h:151
NTuple::_DataImp::tuple
INTuple * tuple() override
Access to hosting ntuple.
Definition: NTupleItems.h:159
TimingHistograms.name
name
Definition: TimingHistograms.py:25
NTuple::_DataImp::CSTR
const std::string & CSTR
Definition: NTupleItems.h:59
NTuple::_ItemImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:169
NTuple::_MatrixImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:228
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:72
NTuple.h
NTuple::_ItemImp::range
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:178
NTuple::_ArrayImp::setDefault
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:197
NTuple::_ArrayImp
Concrete class discribing a column-array in a N tuple.
Definition: NTupleItems.h:47
INTuple
Definition: INTuple.h:91
NTuple::_DataImp::~_DataImp
~_DataImp() override
Standard destructor.
Definition: NTupleItems.h:98
NTuple::_DataImp::name
const std::string & name() const override
Access _Column name.
Definition: NTupleItems.h:139
min
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:212
INTupleItem
Definition: INTuple.h:37
NTuple::_DataImp::m_tuple
INTuple * m_tuple
Pointer to N tuple.
Definition: NTupleItems.h:64
NTuple::_DataImp::m_info
const std::type_info & m_info
Item type information.
Definition: NTupleItems.h:78
NTuple::_DataImp::ItemRange
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:82
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:216
NTuple::_MatrixImp
Concrete class discribing a matrix column in a N tuple.
Definition: NTupleItems.h:49
gaudirun.l
dictionary l
Definition: gaudirun.py:582
NTuple::_DataImp::filled
long filled() const override
Number of items filled.
Definition: NTupleItems.h:104
NTuple::_DataImp::m_range
Range< TYP > m_range
Check that values are within a certain range while filling.
Definition: NTupleItems.h:76
std
STL namespace.
NTuple::_MatrixImp::range
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:226
NTuple
NTuple name space.
Definition: INTupleSvc.h:19
NTuple::_DataImp::m_indexItem
INTupleItem * m_indexItem
Pointer to index item.
Definition: NTupleItems.h:70
NTuple::_DataImp::indexItem
INTupleItem * indexItem() override
Pointer to index column (if present, 0 else)
Definition: NTupleItems.h:119
NTuple::_DataImp::dim
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:157
NTuple::_DataImp::range
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:147
NTuple::_MatrixImp::ndim
long ndim() const override
Dimension.
Definition: NTupleItems.h:230
IDataProviderSvc
Definition: IDataProviderSvc.h:53
NTuple::_DataImp::buffer
virtual void * buffer()
Access data buffer.
Definition: NTupleItems.h:153
NTuple::_DataImp::m_name
std::string m_name
_Column name
Definition: NTupleItems.h:66
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:232
NTuple::_DataImp::typeID
const std::type_info & typeID() const override
Compiler type ID.
Definition: NTupleItems.h:129
NTuple::_DataImp::m_def
TYP m_def
Buffer with default value.
Definition: NTupleItems.h:74
NTuple::_DataImp::hasIndex
bool hasIndex() const override
Is the tuple have an index column?
Definition: NTupleItems.h:135
NTuple::_DataImp::ndim
long ndim() const override
Dimension.
Definition: NTupleItems.h:155
NTuple::_DataImp::reset
void reset() override
Reset to default.
Definition: NTupleItems.h:102
NTuple::_DataImp::type
long type() const override
TYP information of the item.
Definition: NTupleItems.h:141
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:84
NTuple::_ItemImp
Concrete class discribing a column in a N tuple.
Definition: NTupleItems.h:45
NTuple::Range
Class defining a range.
Definition: NTuple.h:46
NTuple::_ArrayImp::size
long size() const override
Size of entire object.
Definition: NTupleItems.h:201
IConversionSvc
Definition: IConversionSvc.h:47