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> class DataItem;
31  template <class TYP> class _DataImp;
32  template <class TYP> class _ItemImp;
33  template <class TYP> class _ArrayImp;
34  template <class TYP> class _MatrixImp;
35 
38  template <class TYP> class _DataImp : virtual public _Data<TYP> {
40  _DataImp(const _DataImp&) = delete;
41  protected:
42  typedef const std::string& CSTR;
43  typedef const std::type_info& CTYPE;
45  long m_length;
53  mutable INTupleItem* m_indexItem = nullptr;
57  TYP m_def;
62  public:
66  _DataImp(INTuple* tup,std::string name,const std::type_info& info,std::string index,long len,TYP low,TYP high,TYP def)
67  : m_length(len), m_tuple(tup), m_name(std::move(name)), m_index(std::move(index)),
68  m_def(std::move(def)), m_range(std::move(low), std::move(high)), m_info(info)
69  {
70  m_type = typeid(TYP) == typeid(void*) ? DataTypeInfo::POINTER : DataTypeInfo::ID(info);
71  this->m_buffer = new TYP[m_length];
72  reset();
73  }
75  ~_DataImp() override {
76  delete [] this->m_buffer;
77  }
79  std::string typeName() const override {
80  return System::typeinfoName( this->typeID() );
81  }
83  void reset() override {
84  std::fill_n(this->m_buffer, m_length, m_def );
85  }
87  long filled() const override {
88  int len = 1;
89  int nd = ndim();
90  if ( m_length > 1 ) {
91  for ( int l = 0; l < nd-1; l++ ) {
92  len *= dim(l);
93  }
94  if ( indexItem() ) {
95  long *ll = (long*)m_indexItem->buffer();
96  len *= *ll;
97  }
98  else if ( nd > 0 ) {
99  len *= dim(nd-1);
100  }
101  }
102  return len;
103  }
105  INTupleItem* indexItem() override {
106  if ( !m_indexItem ) m_indexItem = m_tuple->find(m_index);
107  return m_indexItem;
108  }
110  const INTupleItem* indexItem() const override {
111  if ( !m_indexItem ) m_indexItem = m_tuple->find(m_index);
112  return m_indexItem;
113  }
115  const std::type_info& typeID() const override { return m_info;}
117  long size() const override { return m_length*sizeof(TYP); }
119  void release() override { delete this; }
121  bool hasIndex() const override { return m_index.length()>0; }
123  const std::string& index() const override { return m_index; }
125  const std::string& name() const override { return m_name; }
127  long type() const override { return m_type; }
129  void setType (long t) override { m_type=DataTypeInfo::Type(t); }
131  void setDefault(const TYP val) override { m_def = val; }
133  const ItemRange& range() const override { return m_range; }
135  long length() const override { return m_length; }
137  const void* buffer() const override { return this->m_buffer; }
139  virtual void* buffer() { return this->m_buffer; }
141  long ndim() const override { return 0; }
143  long dim(long i) const override { return (i==0) ? 1 : 0; }
145  INTuple* tuple() override { return m_tuple; }
146  };
147 
150  template <class TYP> class _ItemImp : virtual public _DataImp<TYP>,
151  virtual public _Item<TYP> {
152 
153  public:
157  _ItemImp(INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def)
158  : _DataImp<TYP>(tup, name, info, "", 1, min, max, def) { }
160  ~_ItemImp() override = default;
162  //virtual const std::type_info& typeID() const { return typeid(NTuple::_Item<TYP>); }
164  void setDefault(const TYP val) override { this->m_def = val; }
166  const ItemRange& range() const override { return this->m_range; }
168  long size() const override { return this->m_length*sizeof(TYP); }
169  };
170 
173  template <class TYP> class _ArrayImp : virtual public _DataImp<TYP>,
174  virtual public _Array<TYP> {
175  public:
179  _ArrayImp(INTuple* tup,const std::string& name,const std::type_info& typ,const std::string& index,long len,TYP min,TYP max,TYP def)
180  : _DataImp<TYP>(tup, name, typ, index, len, min, max, def) { }
182  ~_ArrayImp() override = default;
184  //virtual const std::type_info& typeID() const { return typeid(NTuple::_Array<TYP>); }
186  void setDefault(const TYP val) override { this->m_def = val; }
188  const ItemRange& range() const override { return this->m_range; }
190  long size() const override { return this->m_length*sizeof(TYP); }
192  long ndim() const override { return 1; }
194  long dim(long i) const override {
195  return (i!=0 || this->hasIndex()) ? 0 : this->m_length;
196  }
197  };
198 
201  template <class TYP> class _MatrixImp : virtual public _DataImp<TYP>,
202  virtual public _Matrix<TYP> {
203  public:
208  long ncol,long nrow,TYP min,TYP max,TYP def)
209  : _DataImp<TYP>(tup, name, typ, index, nrow*ncol, min, max, def) {
210  this->m_rows = nrow;
211  }
213  ~_MatrixImp() override = default;
215  //virtual const std::type_info& typeID() const { return typeid(NTuple::_Matrix<TYP>);}
217  void setDefault(const TYP val) override { this->m_def = val; }
219  const ItemRange& range() const override { return this->m_range; }
221  long size() const override { return this->m_length*sizeof(TYP); }
223  long ndim() const override { return 2; }
225  long dim(long i) const override {
226  return (this->hasIndex()) ?
227  ((i==0) ?
228  this->m_rows : this->m_length/this->m_rows) : ((i==1) ? this->m_length/this->m_rows : this->m_rows);
229  }
230  };
231 } // end name space NTuple
232 #endif // GAUDI_NTUPLESVC_NTUPLEITEMS_H
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:166
const std::string & index() const override
Access the index _Column.
Definition: NTupleItems.h:123
_DataImp(const _DataImp &)=delete
Inhibit Copy Constructor.
~_DataImp() override
Standard destructor.
Definition: NTupleItems.h:75
long filled() const override
Number of items filled.
Definition: NTupleItems.h:87
_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:179
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:205
Abstract class describing a matrix column in a N tuple.
Definition: NTuple.h:40
static Type ID(const bool)
Access to type information: bool.
Definition: DataTypeInfo.h:32
Abstract class describing a column in a N tuple.
Definition: NTuple.h:38
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:219
Concrete class discribing a matrix column in a N tuple.
Definition: NTupleItems.h:34
DataTypeInfo::Type m_type
_Column type
Definition: NTupleItems.h:55
INTupleItem * indexItem() override
Pointer to index column (if present, 0 else)
Definition: NTupleItems.h:105
STL namespace.
TYP m_def
Buffer with default value.
Definition: NTupleItems.h:57
Range< TYP > m_range
Check that values are within a certain range while filling.
Definition: NTupleItems.h:59
_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:207
const std::string & CSTR
Definition: NTupleItems.h:42
const std::string & name() const override
Access _Column name.
Definition: NTupleItems.h:125
_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:66
std::string typeName() const override
Get proper type name.
Definition: NTupleItems.h:79
Data provider interface definition.
virtual void * buffer()
Access data buffer.
Definition: NTupleItems.h:139
NTuple name space.
Definition: INTupleSvc.h:10
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:177
STL class.
long length() const override
Access the buffer length.
Definition: NTupleItems.h:135
NTuple interface class definition.
Definition: INTuple.h:79
const std::type_info & typeID() const override
Compiler type ID.
Definition: NTupleItems.h:115
std::string m_index
Check that values are within a certain range while filling.
Definition: NTupleItems.h:51
NTuple interface class definition.
Definition: INTuple.h:26
void reset() override
Reset to default.
Definition: NTupleItems.h:83
long size() const override
Size of entire object.
Definition: NTupleItems.h:221
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:143
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:194
bool hasIndex() const override
Is the tuple have an index column?
Definition: NTupleItems.h:121
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:188
void setDefault(const TYP val) override
Set default value.
Definition: NTupleItems.h:131
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:217
Concrete class discribing a column-array in a N tuple.
Definition: NTupleItems.h:33
long type() const override
TYP information of the item.
Definition: NTupleItems.h:127
const ItemRange & range() const override
Access the range if specified.
Definition: NTupleItems.h:133
long ndim() const override
Dimension.
Definition: NTupleItems.h:141
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:64
Abstract class describing basic data in an Ntuple.
Definition: NTuple.h:37
void release() override
Destruct object.
Definition: NTupleItems.h:119
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition: NTupleItems.h:155
const void * buffer() const override
Access data buffer (CONST)
Definition: NTupleItems.h:137
long ndim() const override
Dimension.
Definition: NTupleItems.h:192
long m_length
Entire buffer length.
Definition: NTupleItems.h:45
dictionary l
Definition: gaudirun.py:421
virtual const void * buffer() const =0
Access data buffer (CONST)
INTuple * m_tuple
Pointer to N tuple.
Definition: NTupleItems.h:47
T length(T...args)
long size() const override
Size of entire object.
Definition: NTupleItems.h:190
long size() const override
Size of entire object.
Definition: NTupleItems.h:168
Concrete class discribing a column in a N tuple.
Definition: NTupleItems.h:32
const std::type_info & m_info
Item type information.
Definition: NTupleItems.h:61
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:31
TYP * m_buffer
Pointer to data buffer.
Definition: NTuple.h:114
std::string m_name
_Column name
Definition: NTupleItems.h:49
const INTupleItem * indexItem() const override
Pointer to index column (if present, 0 else) (CONST)
Definition: NTupleItems.h:110
INTuple * tuple() override
Access to hosting ntuple.
Definition: NTupleItems.h:145
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:186
void setType(long t) override
Set the properties of the _Column.
Definition: NTupleItems.h:129
long size() const override
Size of entire object.
Definition: NTupleItems.h:117
long ndim() const override
Dimension.
Definition: NTupleItems.h:223
_ItemImp(INTuple *tup, const std::string &name, const std::type_info &info, TYP min, TYP max, TYP def)
Standard Constructor.
Definition: NTupleItems.h:157
long dim(long i) const override
Access individual dimensions.
Definition: NTupleItems.h:225
INTupleItem * m_indexItem
Pointer to index item.
Definition: NTupleItems.h:53
void setDefault(const TYP val) override
Compiler type ID.
Definition: NTupleItems.h:164
const std::type_info & CTYPE
Definition: NTupleItems.h:43
Abstract class describing a column-array in a N tuple.
Definition: NTuple.h:39