Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
NTupleItems.h
Go to the documentation of this file.
1 #ifndef GAUDI_NTUPLESVC_NTUPLEITEMS_H
2 #define GAUDI_NTUPLESVC_NTUPLEITEMS_H 1
3 
4 // The converter understands all items
5 #define ALLOW_ALL_TYPES
6 
7 // STL include files
8 #include <vector>
9 
10 // Framework include files
11 #include "GaudiKernel/System.h"
12 #include "NTuple.h"
24 // Forward declarations
25 class IDataProviderSvc;
26 class IConversionSvc;
27 
28 namespace NTuple {
29  // Local forward declarations
30  template <class TYP>
31  class DataItem;
32  template <class TYP>
33  class _DataImp;
34  template <class TYP>
35  class _ItemImp;
36  template <class TYP>
37  class _ArrayImp;
38  template <class TYP>
39  class _MatrixImp;
40 
43  template <class TYP>
44  class _DataImp : virtual public _Data<TYP> {
46  _DataImp( const _DataImp& ) = delete;
47 
48  protected:
49  typedef const std::string& CSTR;
50  typedef const std::type_info& CTYPE;
52  long m_length;
60  mutable INTupleItem* m_indexItem = nullptr;
64  TYP m_def;
69 
70  public:
74  _DataImp( INTuple* tup, std::string name, const std::type_info& info, std::string index, long len, TYP low,
75  TYP high, TYP def )
76  : m_length( len )
77  , m_tuple( tup )
78  , m_name( std::move( name ) )
79  , m_index( std::move( index ) )
80  , m_def( std::move( def ) )
81  , m_range( std::move( low ), std::move( high ) )
82  , m_info( info ) {
83  m_type = typeid( TYP ) == typeid( void* ) ? DataTypeInfo::POINTER : DataTypeInfo::ID( info );
84  this->m_buffer = new TYP[m_length];
85  reset();
86  }
88  ~_DataImp() override { delete[] this->m_buffer; }
90  std::string typeName() const override { return System::typeinfoName( this->typeID() ); }
92  void reset() override { std::fill_n( this->m_buffer, m_length, m_def ); }
94  long filled() const override {
95  int len = 1;
96  int nd = ndim();
97  if ( m_length > 1 ) {
98  for ( int l = 0; l < nd - 1; l++ ) { len *= dim( l ); }
99  if ( indexItem() ) {
100  long* ll = (long*)m_indexItem->buffer();
101  len *= *ll;
102  } else if ( nd > 0 ) {
103  len *= dim( nd - 1 );
104  }
105  }
106  return len;
107  }
109  INTupleItem* indexItem() override {
110  if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
111  return m_indexItem;
112  }
114  const INTupleItem* indexItem() const override {
115  if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
116  return m_indexItem;
117  }
119  const std::type_info& typeID() const override { return m_info; }
121  long size() const override { return m_length * sizeof( TYP ); }
123  void release() override { delete this; }
125  bool hasIndex() const override { return m_index.length() > 0; }
127  const std::string& index() const override { return m_index; }
129  const std::string& name() const override { return m_name; }
131  long type() const override { return m_type; }
133  void setType( long t ) override { m_type = DataTypeInfo::Type( t ); }
135  void setDefault( const TYP val ) override { m_def = val; }
137  const ItemRange& range() const override { return m_range; }
139  long length() const override { return m_length; }
141  const void* buffer() const override { return this->m_buffer; }
143  virtual void* buffer() { return this->m_buffer; }
145  long ndim() const override { return 0; }
147  long dim( long i ) const override { return ( i == 0 ) ? 1 : 0; }
149  INTuple* tuple() override { return m_tuple; }
150  };
151 
154  template <class TYP>
155  class _ItemImp : virtual public _DataImp<TYP>, virtual public _Item<TYP> {
156 
157  public:
161  _ItemImp( INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def )
162  : _DataImp<TYP>( tup, name, info, "", 1, min, max, def ) {}
164  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Item<TYP>); }
166  void setDefault( const TYP val ) override { this->m_def = val; }
168  const ItemRange& range() const override { return this->m_range; }
170  long size() const override { return this->m_length * sizeof( TYP ); }
171  };
172 
175  template <class TYP>
176  class _ArrayImp : virtual public _DataImp<TYP>, virtual public _Array<TYP> {
177  public:
181  _ArrayImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long len,
182  TYP min, TYP max, TYP def )
183  : _DataImp<TYP>( tup, name, typ, index, len, min, max, def ) {}
185  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Array<TYP>); }
187  void setDefault( const TYP val ) override { this->m_def = val; }
189  const ItemRange& range() const override { return this->m_range; }
191  long size() const override { return this->m_length * sizeof( TYP ); }
193  long ndim() const override { return 1; }
195  long dim( long i ) const override { return ( i != 0 || this->hasIndex() ) ? 0 : this->m_length; }
196  };
197 
200  template <class TYP>
201  class _MatrixImp : virtual public _DataImp<TYP>, virtual public _Matrix<TYP> {
202  public:
206  _MatrixImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long ncol,
207  long nrow, TYP min, TYP max, TYP def )
208  : _DataImp<TYP>( tup, name, typ, index, nrow * ncol, min, max, def ) {
209  this->m_rows = nrow;
210  }
212  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Matrix<TYP>);}
214  void setDefault( const TYP val ) override { this->m_def = val; }
216  const ItemRange& range() const override { return this->m_range; }
218  long size() const override { return this->m_length * sizeof( TYP ); }
220  long ndim() const override { return 2; }
222  long dim( long i ) const override {
223  return ( this->hasIndex() ) ? ( ( i == 0 ) ? this->m_rows : this->m_length / this->m_rows )
224  : ( ( i == 1 ) ? this->m_length / this->m_rows : this->m_rows );
225  }
226  };
227 } // namespace NTuple
228 #endif // GAUDI_NTUPLESVC_NTUPLEITEMS_H
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:168
const std::string & index() const override
Access the index _Column.
Definition: NTupleItems.h:127
_DataImp(const _DataImp &)=delete
Inhibit Copy Constructor.
~_DataImp() override
Standard destructor.
Definition: NTupleItems.h:88
long filled() const override
Number of items filled.
Definition: NTupleItems.h:94
_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:181
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:309
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:204
Abstract class describing a matrix column in a N tuple.
Definition: NTuple.h:44
static Type ID(const bool)
Access to type information: bool.
Definition: DataTypeInfo.h:48
Abstract class describing a column in a N tuple.
Definition: NTuple.h:40
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:216
Concrete class discribing a matrix column in a N tuple.
Definition: NTupleItems.h:39
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:202
DataTypeInfo::Type m_type
_Column type
Definition: NTupleItems.h:62
INTupleItem * indexItem() override
Pointer to index column (if present, 0 else)
Definition: NTupleItems.h:109
STL namespace.
TYP m_def
Buffer with default value.
Definition: NTupleItems.h:64
Range< TYP > m_range
Check that values are within a certain range while filling.
Definition: NTupleItems.h:66
_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:206
const std::string & CSTR
Definition: NTupleItems.h:49
const std::string & name() const override
Access _Column name.
Definition: NTupleItems.h:129
_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:74
std::string typeName() const override
Get proper type name.
Definition: NTupleItems.h:90
Data provider interface definition.
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215
virtual void * buffer()
Access data buffer.
Definition: NTupleItems.h:143
NTuple name space.
Definition: INTupleSvc.h:9
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:179
STL class.
long length() const override
Access the buffer length.
Definition: NTupleItems.h:139
NTuple interface class definition.
Definition: INTuple.h:81
const std::type_info & typeID() const override
Compiler type ID.
Definition: NTupleItems.h:119
std::string m_index
Check that values are within a certain range while filling.
Definition: NTupleItems.h:58
NTuple interface class definition.
Definition: INTuple.h:27
void reset() override
Reset to default.
Definition: NTupleItems.h:92
long size() const override
Size of entire object.
Definition: NTupleItems.h:218
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:147
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:195
bool hasIndex() const override
Is the tuple have an index column?
Definition: NTupleItems.h:125
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:189
void setDefault(const TYP val) override
Set default value.
Definition: NTupleItems.h:135
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:214
Concrete class discribing a column-array in a N tuple.
Definition: NTupleItems.h:37
long type() const override
TYP information of the item.
Definition: NTupleItems.h:131
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:137
long ndim() const override
Dimension.
Definition: NTupleItems.h:145
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:72
Abstract class describing basic data in an Ntuple.
Definition: NTuple.h:38
void release() override
Destruct object.
Definition: NTupleItems.h:123
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:159
const void * buffer() const override
Access data buffer (CONST)
Definition: NTupleItems.h:141
long ndim() const override
Dimension.
Definition: NTupleItems.h:193
long m_length
Entire buffer length.
Definition: NTupleItems.h:52
dictionary l
Definition: gaudirun.py:517
virtual const void * buffer() const =0
Access data buffer (CONST)
INTuple * m_tuple
Pointer to N tuple.
Definition: NTupleItems.h:54
T length(T...args)
long size() const override
Size of entire object.
Definition: NTupleItems.h:191
long size() const override
Size of entire object.
Definition: NTupleItems.h:170
Concrete class discribing a column in a N tuple.
Definition: NTupleItems.h:35
const std::type_info & m_info
Item type information.
Definition: NTupleItems.h:68
T fill_n(T...args)
Class defining a range.
Definition: NTuple.h:36
Concrete class discribing basic data items in an N tuple.
Definition: NTupleItems.h:33
TYP * m_buffer
Pointer to data buffer.
Definition: NTuple.h:123
std::string m_name
_Column name
Definition: NTupleItems.h:56
const INTupleItem * indexItem() const override
Pointer to index column (if present, 0 else) (CONST)
Definition: NTupleItems.h:114
INTuple * tuple() override
Access to hosting ntuple.
Definition: NTupleItems.h:149
virtual const INTupleItem * find(const std::string &name) const =0
Find an item row of the Ntuple (CONST)
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:187
void setType(long t) override
Set the properties of the _Column.
Definition: NTupleItems.h:133
long size() const override
Size of entire object.
Definition: NTupleItems.h:121
long ndim() const override
Dimension.
Definition: NTupleItems.h:220
_ItemImp(INTuple *tup, const std::string &name, const std::type_info &info, TYP min, TYP max, TYP def)
Standard Constructor.
Definition: NTupleItems.h:161
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:222
INTupleItem * m_indexItem
Pointer to index item.
Definition: NTupleItems.h:60
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:166
const std::type_info & CTYPE
Definition: NTupleItems.h:50
Abstract class describing a column-array in a N tuple.
Definition: NTuple.h:42