| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NTupleItems.h
Go to the documentation of this file.
1 // $Id: NTupleItems.h,v 1.7 2008/10/27 19:22:20 marcocle Exp $
2 #ifndef GAUDI_NTUPLESVC_NTUPLEITEMS_H
3 #define GAUDI_NTUPLESVC_NTUPLEITEMS_H 1
4
5 // The converter understands all items
6 #define ALLOW_ALL_TYPES
7
8 // STL include files
9 #include <vector>
10
11 // Framework include files
12 #include "GaudiKernel/System.h"
13 #include "NTuple.h"
25 // Forward declarations
26 class IDataProviderSvc;
27 class IConversionSvc;
28
29 namespace NTuple {
30 // Local forward declarations
31 template <class TYP> class DataItem;
32 template <class TYP> class _DataImp;
33 template <class TYP> class _ItemImp;
34 template <class TYP> class _ArrayImp;
35 template <class TYP> class _MatrixImp;
36
39 template <class TYP> class _DataImp : virtual public _Data<TYP> {
40 private:
42 _DataImp(const _DataImp&) {}
43 protected:
44 typedef const std::string& CSTR;
45 typedef const std::type_info& CTYPE;
47 long m_length;
49 INTuple* m_tuple;
51 std::string m_name;
53 std::string m_index;
55 mutable INTupleItem* m_indexItem;
57 DataTypeInfo::Type m_type;
59 TYP m_def;
61 Range<TYP> m_range;
63 const std::type_info& m_info;
64 public:
66 typedef Range<TYP> ItemRange;
68 _DataImp(INTuple* tup,const std::string& name,const std::type_info& info,const std::string& index,long len,TYP low,TYP high,TYP def)
69 : m_length(len), m_tuple(tup), m_name(name), m_index(index),
70 m_def(def), m_range(low, high), m_info(info)
71 {
72 m_indexItem = 0;
73 m_type = typeid(TYP) == typeid(void*) ? DataTypeInfo::POINTER : DataTypeInfo::ID(info);
74 this->m_buffer = new TYP[m_length];
75 reset();
76 }
78 virtual ~_DataImp() {
79 if ( 0 != this->m_buffer ) delete [] this->m_buffer;
80 }
82 virtual std::string typeName() const {
83 return System::typeinfoName( this->typeID() );
84 }
86 virtual void reset() {
87 TYP* buff = this->m_buffer;
88 for ( size_t i = 0; i < static_cast<size_t>(m_length); i++ ) {
89 *buff++ = m_def;
90 }
91 }
93 virtual long filled() const {
94 int len = 1;
95 int nd = ndim();
96 if ( m_length > 1 ) {
97 for ( int l = 0; l < nd-1; l++ ) {
98 len *= dim(l);
99 }
100 if ( indexItem() ) {
101 long *ll = (long*)m_indexItem->buffer();
102 len *= *ll;
103 }
104 else if ( nd > 0 ) {
105 len *= dim(nd-1);
106 }
107 }
108 return len;
109 }
111 virtual INTupleItem* indexItem() {
112 if ( 0 == m_indexItem ) {
113 m_indexItem = m_tuple->find(m_index);
114 }
115 return m_indexItem;
116 }
118 virtual const INTupleItem* indexItem() const {
119 if ( 0 == m_indexItem ) {
120 m_indexItem = m_tuple->find(m_index);
121 }
122 return m_indexItem;
123 }
125 virtual const std::type_info& typeID() const { return m_info;}
127 virtual long size() const { return m_length*sizeof(TYP); }
129 virtual void release() { delete this; }
131 virtual bool hasIndex() const { return m_index.length()>0; }
133 virtual const std::string& index() const { return m_index; }
135 virtual const std::string& name() const { return m_name; }
137 virtual long type() const { return m_type; }
139 virtual void setType (long t) { m_type=DataTypeInfo::Type(t); }
141 virtual void setDefault(const TYP val) { m_def = val; }
143 virtual const ItemRange& range() const { return m_range; }
145 virtual long length() const { return m_length; }
147 virtual const void* buffer() const { return this->m_buffer; }
149 virtual void* buffer() { return this->m_buffer; }
151 virtual long ndim() const { return 0; }
153 virtual long dim(long i) const { return (i==0) ? 1 : 0; }
155 virtual INTuple* tuple() { return m_tuple; }
156 };
157
160 template <class TYP> class _ItemImp : virtual public _DataImp<TYP>,
161 virtual public _Item<TYP> {
162
163 public:
165 typedef Range<TYP> ItemRange;
167 _ItemImp(INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def)
168 : _DataImp<TYP>(tup, name, info, "", 1, min, max, def) { }
170 virtual ~_ItemImp() { }
172 //virtual const std::type_info& typeID() const { return typeid(NTuple::_Item<TYP>); }
174 virtual void setDefault(const TYP val) { this->m_def = val; }
176 virtual const ItemRange& range() const { return this->m_range; }
178 virtual long size() const { return this->m_length*sizeof(TYP); }
179 };
180
183 template <class TYP> class _ArrayImp : virtual public _DataImp<TYP>,
184 virtual public _Array<TYP> {
185 public:
187 typedef Range<TYP> ItemRange;
189 _ArrayImp(INTuple* tup,const std::string& name,const std::type_info& typ,const std::string& index,long len,TYP min,TYP max,TYP def)
190 : _DataImp<TYP>(tup, name, typ, index, len, min, max, def) { }
192 virtual ~_ArrayImp() { }
194 //virtual const std::type_info& typeID() const { return typeid(NTuple::_Array<TYP>); }
196 virtual void setDefault(const TYP val) { this->m_def = val; }
198 virtual const ItemRange& range() const { return this->m_range; }
200 virtual long size() const { return this->m_length*sizeof(TYP); }
202 virtual long ndim() const { return 1; }
204 virtual long dim(long i) const {
205 return (i!=0 || this->hasIndex()) ? 0 : this->m_length;
206 }
207 };
208
211 template <class TYP> class _MatrixImp : virtual public _DataImp<TYP>,
212 virtual public _Matrix<TYP> {
213 public:
215 typedef Range<TYP> ItemRange;
217 _MatrixImp(INTuple* tup,const std::string& name,const std::type_info& typ,const std::string& index,
218 long ncol,long nrow,TYP min,TYP max,TYP def)
219 : _DataImp<TYP>(tup, name, typ, index, nrow*ncol, min, max, def) {
220 this->m_rows = nrow;
221 }
223 virtual ~_MatrixImp() { }
225 //virtual const std::type_info& typeID() const { return typeid(NTuple::_Matrix<TYP>);}
227 virtual void setDefault(const TYP val) { this->m_def = val; }
229 virtual const ItemRange& range() const { return this->m_range; }
231 virtual long size() const { return this->m_length*sizeof(TYP); }
233 virtual long ndim() const { return 2; }
235 virtual long dim(long i) const {
236 return (this->hasIndex()) ?
237 ((i==0) ?
238 this->m_rows : this->m_length/this->m_rows) : ((i==1) ? this->m_length/this->m_rows : this->m_rows);
239 }
240 };
241 } // end name space NTuple
242 #endif // GAUDI_NTUPLESVC_NTUPLEITEMS_H