The Gaudi Framework  v29r0 (ff2e7097)
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 {
30  // Local forward declarations
31  template <class TYP>
32  class DataItem;
33  template <class TYP>
34  class _DataImp;
35  template <class TYP>
36  class _ItemImp;
37  template <class TYP>
38  class _ArrayImp;
39  template <class TYP>
40  class _MatrixImp;
41 
44  template <class TYP>
45  class _DataImp : virtual public _Data<TYP>
46  {
48  _DataImp( const _DataImp& ) = delete;
49 
50  protected:
51  typedef const std::string& CSTR;
52  typedef const std::type_info& CTYPE;
54  long m_length;
62  mutable INTupleItem* m_indexItem = nullptr;
66  TYP m_def;
71 
72  public:
76  _DataImp( INTuple* tup, std::string name, const std::type_info& info, std::string index, long len, TYP low,
77  TYP high, TYP def )
78  : m_length( len )
79  , m_tuple( tup )
80  , m_name( std::move( name ) )
81  , m_index( std::move( index ) )
82  , m_def( std::move( def ) )
83  , m_range( std::move( low ), std::move( high ) )
84  , m_info( info )
85  {
86  m_type = typeid( TYP ) == typeid( void* ) ? DataTypeInfo::POINTER : DataTypeInfo::ID( info );
87  this->m_buffer = new TYP[m_length];
88  reset();
89  }
91  ~_DataImp() override { delete[] this->m_buffer; }
93  std::string typeName() const override { return System::typeinfoName( this->typeID() ); }
95  void reset() override { std::fill_n( this->m_buffer, m_length, m_def ); }
97  long filled() const override
98  {
99  int len = 1;
100  int nd = ndim();
101  if ( m_length > 1 ) {
102  for ( int l = 0; l < nd - 1; l++ ) {
103  len *= dim( l );
104  }
105  if ( indexItem() ) {
106  long* ll = (long*)m_indexItem->buffer();
107  len *= *ll;
108  } else if ( nd > 0 ) {
109  len *= dim( nd - 1 );
110  }
111  }
112  return len;
113  }
115  INTupleItem* indexItem() override
116  {
117  if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
118  return m_indexItem;
119  }
121  const INTupleItem* indexItem() const override
122  {
123  if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
124  return m_indexItem;
125  }
127  const std::type_info& typeID() const override { return m_info; }
129  long size() const override { return m_length * sizeof( TYP ); }
131  void release() override { delete this; }
133  bool hasIndex() const override { return m_index.length() > 0; }
135  const std::string& index() const override { return m_index; }
137  const std::string& name() const override { return m_name; }
139  long type() const override { return m_type; }
141  void setType( long t ) override { m_type = DataTypeInfo::Type( t ); }
143  void setDefault( const TYP val ) override { m_def = val; }
145  const ItemRange& range() const override { return m_range; }
147  long length() const override { return m_length; }
149  const void* buffer() const override { return this->m_buffer; }
151  virtual void* buffer() { return this->m_buffer; }
153  long ndim() const override { return 0; }
155  long dim( long i ) const override { return ( i == 0 ) ? 1 : 0; }
157  INTuple* tuple() override { return m_tuple; }
158  };
159 
162  template <class TYP>
163  class _ItemImp : virtual public _DataImp<TYP>, virtual public _Item<TYP>
164  {
165 
166  public:
170  _ItemImp( INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def )
171  : _DataImp<TYP>( tup, name, info, "", 1, min, max, def )
172  {
173  }
175  ~_ItemImp() override = default;
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  {
191  public:
195  _ArrayImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long len,
196  TYP min, TYP max, TYP def )
197  : _DataImp<TYP>( tup, name, typ, index, len, min, max, def )
198  {
199  }
201  ~_ArrayImp() override = default;
203  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Array<TYP>); }
205  void setDefault( const TYP val ) override { this->m_def = val; }
207  const ItemRange& range() const override { return this->m_range; }
209  long size() const override { return this->m_length * sizeof( TYP ); }
211  long ndim() const override { return 1; }
213  long dim( long i ) const override { return ( i != 0 || this->hasIndex() ) ? 0 : this->m_length; }
214  };
215 
218  template <class TYP>
219  class _MatrixImp : virtual public _DataImp<TYP>, virtual public _Matrix<TYP>
220  {
221  public:
225  _MatrixImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long ncol,
226  long nrow, TYP min, TYP max, TYP def )
227  : _DataImp<TYP>( tup, name, typ, index, nrow * ncol, min, max, def )
228  {
229  this->m_rows = nrow;
230  }
232  ~_MatrixImp() override = default;
234  // virtual const std::type_info& typeID() const { return typeid(NTuple::_Matrix<TYP>);}
236  void setDefault( const TYP val ) override { this->m_def = val; }
238  const ItemRange& range() const override { return this->m_range; }
240  long size() const override { return this->m_length * sizeof( TYP ); }
242  long ndim() const override { return 2; }
244  long dim( long i ) const override
245  {
246  return ( this->hasIndex() ) ? ( ( i == 0 ) ? this->m_rows : this->m_length / this->m_rows )
247  : ( ( i == 1 ) ? this->m_length / this->m_rows : this->m_rows );
248  }
249  };
250 } // end name space NTuple
251 #endif // GAUDI_NTUPLESVC_NTUPLEITEMS_H
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:181
const std::string & index() const override
Access the index _Column.
Definition: NTupleItems.h:135
_DataImp(const _DataImp &)=delete
Inhibit Copy Constructor.
~_DataImp() override
Standard destructor.
Definition: NTupleItems.h:91
long filled() const override
Number of items filled.
Definition: NTupleItems.h:97
_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:195
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:329
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:223
Abstract class describing a matrix column in a N tuple.
Definition: NTuple.h:45
static Type ID(const bool)
Access to type information: bool.
Definition: DataTypeInfo.h:49
Abstract class describing a column in a N tuple.
Definition: NTuple.h:41
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:238
Concrete class discribing a matrix column in a N tuple.
Definition: NTupleItems.h:40
DataTypeInfo::Type m_type
_Column type
Definition: NTupleItems.h:64
INTupleItem * indexItem() override
Pointer to index column (if present, 0 else)
Definition: NTupleItems.h:115
STL namespace.
TYP m_def
Buffer with default value.
Definition: NTupleItems.h:66
Range< TYP > m_range
Check that values are within a certain range while filling.
Definition: NTupleItems.h:68
_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:225
const std::string & CSTR
Definition: NTupleItems.h:51
const std::string & name() const override
Access _Column name.
Definition: NTupleItems.h:137
_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:76
std::string typeName() const override
Get proper type name.
Definition: NTupleItems.h:93
Data provider interface definition.
virtual void * buffer()
Access data buffer.
Definition: NTupleItems.h:151
NTuple name space.
Definition: INTupleSvc.h:9
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:193
STL class.
long length() const override
Access the buffer length.
Definition: NTupleItems.h:147
NTuple interface class definition.
Definition: INTuple.h:82
const std::type_info & typeID() const override
Compiler type ID.
Definition: NTupleItems.h:127
std::string m_index
Check that values are within a certain range while filling.
Definition: NTupleItems.h:60
NTuple interface class definition.
Definition: INTuple.h:27
void reset() override
Reset to default.
Definition: NTupleItems.h:95
long size() const override
Size of entire object.
Definition: NTupleItems.h:240
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:155
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:213
bool hasIndex() const override
Is the tuple have an index column?
Definition: NTupleItems.h:133
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:207
void setDefault(const TYP val) override
Set default value.
Definition: NTupleItems.h:143
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:236
Concrete class discribing a column-array in a N tuple.
Definition: NTupleItems.h:38
long type() const override
TYP information of the item.
Definition: NTupleItems.h:139
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:145
long ndim() const override
Dimension.
Definition: NTupleItems.h:153
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:74
Abstract class describing basic data in an Ntuple.
Definition: NTuple.h:39
void release() override
Destruct object.
Definition: NTupleItems.h:131
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:168
const void * buffer() const override
Access data buffer (CONST)
Definition: NTupleItems.h:149
long ndim() const override
Dimension.
Definition: NTupleItems.h:211
long m_length
Entire buffer length.
Definition: NTupleItems.h:54
dictionary l
Definition: gaudirun.py:440
virtual const void * buffer() const =0
Access data buffer (CONST)
INTuple * m_tuple
Pointer to N tuple.
Definition: NTupleItems.h:56
T length(T...args)
long size() const override
Size of entire object.
Definition: NTupleItems.h:209
long size() const override
Size of entire object.
Definition: NTupleItems.h:183
Concrete class discribing a column in a N tuple.
Definition: NTupleItems.h:36
const std::type_info & m_info
Item type information.
Definition: NTupleItems.h:70
T fill_n(T...args)
Class defining a range.
Definition: NTuple.h:37
Concrete class discribing basic data items in an N tuple.
Definition: NTupleItems.h:34
TYP * m_buffer
Pointer to data buffer.
Definition: NTuple.h:130
std::string m_name
_Column name
Definition: NTupleItems.h:58
const INTupleItem * indexItem() const override
Pointer to index column (if present, 0 else) (CONST)
Definition: NTupleItems.h:121
INTuple * tuple() override
Access to hosting ntuple.
Definition: NTupleItems.h:157
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:205
void setType(long t) override
Set the properties of the _Column.
Definition: NTupleItems.h:141
long size() const override
Size of entire object.
Definition: NTupleItems.h:129
long ndim() const override
Dimension.
Definition: NTupleItems.h:242
_ItemImp(INTuple *tup, const std::string &name, const std::type_info &info, TYP min, TYP max, TYP def)
Standard Constructor.
Definition: NTupleItems.h:170
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:244
INTupleItem * m_indexItem
Pointer to index item.
Definition: NTupleItems.h:62
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:179
const std::type_info & CTYPE
Definition: NTupleItems.h:52
Abstract class describing a column-array in a N tuple.
Definition: NTuple.h:43