The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
NTupleItems.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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#pragma once
15
16// The converter understands all items
17#define ALLOW_ALL_TYPES
18
19#include "NTuple.h"
20#include <GaudiKernel/System.h>
21#include <vector>
22
33
34// Forward declarations
36class IConversionSvc;
37
38namespace 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;
66 std::string m_name;
68 std::string m_index;
70 mutable INTupleItem* m_indexItem = nullptr;
74 TYP m_def;
78 const std::type_info& m_info;
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 }
97
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 }
118
119 INTupleItem* indexItem() override {
120 if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
121 return m_indexItem;
122 }
123
124 const INTupleItem* indexItem() const override {
125 if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
126 return m_indexItem;
127 }
128
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 ) {}
173
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 ) {}
194
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 }
221
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
static Type ID(const bool)
Access to type information: bool.
Data provider interface definition.
NTuple interface class definition.
Definition INTuple.h:86
NTuple interface class definition.
Definition INTuple.h:32
Abstract class describing a column-array in a N tuple.
Definition NTuple.h:159
Concrete class discribing a column-array in a N tuple.
long ndim() const override
Dimension.
const ItemRange & range() const override
Access the range if specified.
_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.
void setDefault(const TYP val) override
Compiler type ID.
long size() const override
Size of entire object.
Range< TYP > ItemRange
Set type definition to make life more easy easy.
long dim(long i) const override
Access individual dimensions.
Abstract class describing basic data in an Ntuple.
Definition NTuple.h:122
TYP * m_buffer
Pointer to data buffer.
Definition NTuple.h:125
Concrete class discribing basic data items in an N tuple.
Definition NTupleItems.h:54
long filled() const override
Number of items filled.
void release() override
Destruct object.
const std::type_info & typeID() const override
Compiler type ID.
long size() const override
Size of entire object.
const std::type_info & m_info
Item type information.
Definition NTupleItems.h:78
INTuple * tuple() override
Access to hosting ntuple.
void setType(long t) override
Set the properties of the _Column.
bool hasIndex() const override
Is the tuple have an index column?
Range< TYP > m_range
Check that values are within a certain range while filling.
Definition NTupleItems.h:76
const std::string & index() const override
Access the index _Column.
INTupleItem * m_indexItem
Pointer to index item.
Definition NTupleItems.h:70
std::string m_name
_Column name
Definition NTupleItems.h:66
_DataImp(const _DataImp &)=delete
Inhibit Copy Constructor.
long length() const override
Access the buffer length.
TYP m_def
Buffer with default value.
Definition NTupleItems.h:74
const std::string & name() const override
Access _Column name.
long type() const override
TYP information of the item.
INTuple * m_tuple
Pointer to N tuple.
Definition NTupleItems.h:64
virtual void * buffer()
Access data buffer.
void setDefault(const TYP val) override
Set default value.
void reset() override
Reset to default.
_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
long ndim() const override
Dimension.
long dim(long i) const override
Access individual dimensions.
const std::type_info & CTYPE
Definition NTupleItems.h:60
std::string m_index
Check that values are within a certain range while filling.
Definition NTupleItems.h:68
const INTupleItem * indexItem() const override
Pointer to index column (if present, 0 else) (CONST)
const void * buffer() const override
Access data buffer (CONST)
DataTypeInfo::Type m_type
_Column type
Definition NTupleItems.h:72
~_DataImp() override
Standard destructor.
Definition NTupleItems.h:98
std::string typeName() const override
Get proper type name.
const ItemRange & range() const override
Access the range if specified.
long m_length
Entire buffer length.
Definition NTupleItems.h:62
Range< TYP > ItemRange
Set type definition to make life more easy easy.
Definition NTupleItems.h:82
INTupleItem * indexItem() override
Pointer to index column (if present, 0 else)
const std::string & CSTR
Definition NTupleItems.h:59
Abstract class describing a column in a N tuple.
Definition NTuple.h:139
Concrete class discribing a column in a N tuple.
void setDefault(const TYP val) override
Compiler type ID.
_ItemImp(INTuple *tup, const std::string &name, const std::type_info &info, TYP min, TYP max, TYP def)
Standard Constructor.
Range< TYP > ItemRange
Set type definition to make life more easy easy.
long size() const override
Size of entire object.
const ItemRange & range() const override
Access the range if specified.
Abstract class describing a matrix column in a N tuple.
Definition NTuple.h:188
long m_rows
Number of rows per column.
Definition NTuple.h:191
Concrete class discribing a matrix column in a N tuple.
long size() const override
Size of entire object.
long dim(long i) const override
Access individual dimensions.
_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.
void setDefault(const TYP val) override
Compiler type ID.
const ItemRange & range() const override
Access the range if specified.
Range< TYP > ItemRange
Set type definition to make life more easy easy.
long ndim() const override
Dimension.
Class defining a range.
Definition NTuple.h:58
NTuple name space.
Definition INTupleSvc.h:16
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260
STL namespace.