3 #ifndef GAUDIKERNEL_NTUPLE_H
4 #define GAUDIKERNEL_NTUPLE_H
15 #include "GaudiKernel/DataTypeInfo.h"
16 #include "GaudiKernel/DataObject.h"
17 #include "GaudiKernel/INTuple.h"
18 #include "GaudiKernel/SmartDataPtr.h"
19 #include "GaudiKernel/IOpaqueAddress.h"
24 class NTupleDirectory;
37 template <
class TYP>
class Range;
38 template <
class TYP>
class _Data;
39 template <
class TYP>
class _Item;
40 template <
class TYP>
class _Array;
41 template <
class TYP>
class _Matrix;
42 template <
class TYP>
class _Accessor;
43 template <
class TYP>
class Item;
44 template <
class TYP>
class Array;
45 template <
class TYP>
class Matrix;
56 Range(
const TYP low,
const TYP
upper) : m_lower(low), m_upper(upper) {
59 Range(
const Range<TYP>& copy) : m_lower(copy.m_lower),
60 m_upper(copy.m_upper) {
64 m_lower = copy.m_lower;
65 m_upper = copy.m_upper;
79 static TYP
max() {
return std::numeric_limits<TYP>::max() ; }
82 template <>
class Range<bool>
86 Range(
const bool ,
const bool ) {}
88 Range(
const Range<bool>& ) {}
92 bool lower()
const {
return false; }
94 bool upper()
const {
return true; }
96 bool distance()
const {
return true; }
98 static bool min() {
return false; }
100 static bool max() {
return true; }
118 typedef Range<TYP> ItemRange;
120 virtual void setDefault(
const TYP d) = 0;
122 virtual const ItemRange&
range()
const = 0;
127 template <
class TYP>
class GAUDI_API _Item :
virtual public _Data<TYP> {
132 static _Item* create(
INTuple* tup,
133 const std::string& name,
134 const std::type_info& info,
140 _Item<TYP>& operator=(
const _Item<T>& copy) {
141 *this->m_buffer = copy.get();
145 void set(
const TYP&
item) { *this->m_buffer =
item; }
147 virtual TYP
get()
const {
return *this->m_buffer; }
152 template <
class TYP>
class GAUDI_API _Array :
virtual public _Data<TYP> {
155 static _Array* create(
INTuple* tup,
156 const std::string& name,
157 const std::type_info& info,
158 const std::string& index,
165 _Array<TYP>& operator=(
const _Array<T>& copy) {
166 long len = this->length();
167 if ( len == copy.length() ) {
168 const T* source = (
const T*)copy.buffer();
169 for (
int i = 0;
i < len;
i++ ) {
170 *(this->m_buffer +
i) = *(source +
i);
174 throw std::out_of_range
175 (
"N-tuple matrix cannot be copied! The index range does not match!");
179 const TYP& data(
long i)
const {
return *(this->m_buffer +
i); }
181 TYP& data(
long i) {
return *(this->m_buffer +
i); }
186 template <
class TYP>
class GAUDI_API _Matrix :
virtual public _Data<TYP> {
192 static _Matrix* create(
INTuple* tup,
193 const std::string& name,
194 const std::type_info& info,
195 const std::string& index,
203 _Matrix<TYP>& operator=(
const _Matrix<T>& copy) {
204 long len = this->length();
205 if ( len == copy.length() ) {
206 const T* source = (
const T*)copy.buffer();
207 for (
int i = 0;
i < len;
i++ ) {
208 *(this->m_buffer +
i) = *(source +
i);
212 throw std::out_of_range
213 (
"N-tuple matrix cannot be copied! The index range does not match!");
217 TYP* column(
long i) {
return (this->m_buffer + i*m_rows); }
219 const TYP* column(
long i)
const {
return (this->m_buffer + i*m_rows); }
224 template <
class TYP>
class _Accessor {
227 _Accessor<TYP>&
operator=(
const _Accessor<TYP>&) {
239 bool operator !()
const {
return m_ptr != 0; }
241 operator const void*()
const {
return m_ptr; }
247 const Range<TYP>&
range()
const {
return m_ptr->range(); }
252 template <
class TYP>
class Item :
virtual public _Accessor< _Item<TYP> > {
253 typedef Item<TYP>
_My;
258 operator const TYP ()
const {
return this->m_ptr->get(); }
260 TYP
operator*() {
return this->m_ptr->get(); }
262 const TYP
operator*()
const {
return this->m_ptr->get(); }
270 this->m_ptr->set( data );
276 this->m_ptr->set( data->get() );
280 this->m_ptr->set ( this->m_ptr->get() + data );
284 this->m_ptr->set ( this->m_ptr->get() - data );
288 this->m_ptr->set ( this->m_ptr->get() * data );
292 this->m_ptr->set ( this->m_ptr->get() / data );
299 template <>
class Item<bool> :
virtual public _Accessor< _Item<bool> > {
300 typedef Item<bool>
_My;
305 operator bool ()
const {
return this->m_ptr->get(); }
308 this->m_ptr->set( data );
314 this->m_ptr->set( data->get() );
321 template <
class TYP>
class Array :
virtual public _Accessor < _Array<TYP> > {
328 *(this->
m_ptr) = *(copy.operator->());
333 TYP&
operator[] (
const T i) {
return this->m_ptr->data(i); }
336 const TYP&
operator[] (
const T i)
const {
return this->m_ptr->data(i); }
342 template <
class TYP>
class Matrix :
virtual public _Accessor< _Matrix<TYP> > {
349 *(this->
m_ptr) = *(copy.operator->());
354 TYP*
operator[] (
const T i) {
return this->m_ptr->column(i); }
357 const TYP*
operator[] (
const T i)
const {
return this->m_ptr->column(i); }
372 _Item<TYPE>*& result)
const {
374 result =
dynamic_cast< _Item<TYPE>*
> (
i_find(name));
383 _Item<TYPE*>*& result)
const {
385 _Item<void*>* p =
dynamic_cast< _Item<void*>*
> (
i_find(name));
386 result = (_Item<TYPE*>*)p;
395 _Item<IOpaqueAddress*>*& result)
const {
397 result =
dynamic_cast< _Item<IOpaqueAddress*>*
> (
i_find(name));
406 _Array<TYPE>*& result)
const {
408 if (
clID() == CLID_ColumnWiseTuple ) {
409 result =
dynamic_cast< _Array<TYPE>*
> (
i_find(name));
419 _Matrix<TYPE>*& result)
const {
421 if (
clID() == CLID_ColumnWiseTuple ) {
422 result =
dynamic_cast< _Matrix<TYPE>*
> (
i_find(name));
431 template <
class TYPE>
437 _Item<TYPE>*& result) {
441 return add( result = _Item<TYPE>::create(
this, name,
typeid(TYPE), low, high, nil) );
446 template <
class TYPE>
449 const std::string& index,
452 _Array<TYPE>*& result) {
453 if ( !
i_find(name) &&
clID() == CLID_ColumnWiseTuple ) {
454 return add( result = _Array<TYPE>::create(
this,
466 template <
class TYPE>
470 const std::string& index,
473 _Matrix<TYPE>*& result) {
474 if ( !
i_find(name) &&
clID() == CLID_ColumnWiseTuple ) {
475 return add( result = _Matrix<TYPE>::create(
this,
488 i_addObject(
const std::string& name,_Item<TYPE*>*& result,
const std::type_info& ) {
489 if ( !
i_find(name) &&
clID() == CLID_ColumnWiseTuple ) {
490 return add( result = (_Item<TYPE*>*)_Item<void*>::create(
this, name,
typeid(TYPE),0,0,0) );
503 return i_item(name, result.m_ptr);
507 const Item<TYPE>& result)
const
509 return i_item(name, result.m_ptr);
513 item(
const std::string& name, Array<TYPE>& result)
515 return i_item(name, result.m_ptr);
519 const Array<TYPE>& result)
const
521 return i_item(name, result.m_ptr);
525 Matrix<TYPE>& result)
527 return i_item(name, result.m_ptr);
532 const Matrix<TYPE>& result)
const
534 return i_item(name, result.m_ptr);
551 addItem(
const std::string& name, Item<TYPE>&
itm) {
552 typedef Range<TYPE> _R;
565 addItem(
const std::string& name, Item<TYPE*>& itm) {
578 addItem(
const std::string& name, Item<IOpaqueAddress*>& itm) {
579 typedef Range<IOpaqueAddress*> _R;
601 addItem(
const std::string& name,
606 return i_addItem( name, 1,
"", TYPE(low), TYPE(high), itm.m_ptr);
623 addItem(
const std::string& name,
655 addItem(
const std::string& name,
699 template <
class TYPE,
class INDEX,
class RANGE>
StatusCode
700 addItem(
const std::string& name,
707 index->range().distance(),
739 template <
class TYPE,
class INDEX,
class RANGE>
StatusCode
747 index->range().distance(),
779 addItem(
const std::string& name,
784 index->range().distance(),
816 index->range().distance(),
841 addItem(
const std::string& name,
844 Matrix<TYPE>& matrix)
878 addItem(
const std::string& name,
881 Matrix<TYPE>& result,
920 addItem(
const std::string& name,
922 Matrix<TYPE>& matrix,
926 index->range().distance(),
956 Item<INDEX>& col_index,
958 Matrix<TYPE>& matrix)
961 col_index->range().distance(),
1001 template <
class TYPE,
class INDEX,
class RANGE>
StatusCode
1002 addItem(
const std::string& name,
1004 Matrix<TYPE>& matrix,
1010 index->range().distance(),
1045 template <
class TYPE,
class INDEX,
class RANGE>
StatusCode
1049 Matrix<TYPE>& matrix,
1054 index->range().distance(),
1075 return CLID_NTupleDirectory;
1085 class File :
public Directory {
1099 File(
long type,
const std::string name,
const std::string& logName)
1100 : m_name(name), m_logName(logName), m_type(type), m_isOpen(
false) {
1107 return CLID_NTupleFile;
1114 void setType(
const long typ) {
1122 const std::string&
name()
const {
1126 void setName(
const std::string& nam) {
1156 virtual void dummy() = 0;
1165 virtual void dummy() = 0;
1168 #ifndef ALLOW_ALL_TYPES
1170 typedef Item<bool> BoolItem;
1171 typedef Item<char> CharItem;
1172 typedef Item<unsigned char> UCharItem;
1173 typedef Item<short> ShortItem;
1174 typedef Item<unsigned short> UShortItem;
1175 typedef Item<long> LongItem;
1176 typedef Item<long long> LongLongItem;
1177 typedef Item<unsigned long> ULongItem;
1178 typedef Item<unsigned long long> ULongLongItem;
1179 typedef Item<int> IntItem;
1180 typedef Item<unsigned int> UIntItem;
1181 typedef Item<float> FloatItem;
1182 typedef Item<double> DoubleItem;
1183 typedef Array<bool> BoolArray;
1184 typedef Array<char> CharArray;
1185 typedef Array<unsigned char> UCharArray;
1186 typedef Array<short> ShortArray;
1187 typedef Array<unsigned short> UShortArray;
1188 typedef Array<long> LongArray;
1189 typedef Array<unsigned long> ULongArray;
1190 typedef Array<int> IntArray;
1191 typedef Array<unsigned int> UIntArray;
1192 typedef Array<float> FloatArray;
1193 typedef Array<double> DoubleArray;
1194 typedef Matrix<bool> BoolMatrix;
1195 typedef Matrix<char> CharMatrix;
1196 typedef Matrix<unsigned char> UCharMatrix;
1197 typedef Matrix<short> ShortMatrix;
1198 typedef Matrix<unsigned short> UShortMatrix;
1199 typedef Matrix<long> LongMatrix;
1200 typedef Matrix<unsigned long> ULongMatrix;
1201 typedef Matrix<int> IntMatrix;
1202 typedef Matrix<unsigned int> UIntMatrix;
1203 typedef Matrix<float> FloatMatrix;
1204 typedef Matrix<double> DoubleMatrix;
1208 inline std::ostream& operator<<(std::ostream& s, const Item<T>& obj)
1219 #endif // GAUDIKERNEL_NTUPLE_H
const std::string & name() const
Retrun physical file name.
void setLogicalName(const std::string &l)
Item< TYP > & operator/=(const TYP data)
Item< TYP > & operator+=(const TYP data)
void setOpen(bool flag)
Set "open" flag.
KeyedObjectManager< array > Array
Forward declaration of specialized redirection array object manager.
void setName(const std::string &nam)
Set access type.
SmartDataPtr< NTuple::File > NTupleFilePtr
TYP m_lower
Lower boundary of range.
std::string m_logName
Logical file name.
StatusCode i_item(const std::string &name, _Item< TYPE > *&result) const
Locate a _Column of data to the N tuple type safe.
TYP & operator[](const T i)
Array operator.
virtual StatusCode add(INTupleItem *item)=0
Add an item row to the N tuple.
static TYP min()
Minimal number of data.
TYP * operator->()
Dereference operator.
SmartDataPtr< NTuple::Directory > NTupleDirPtr
std::vector< Row > Matrix
StatusCode addIndexedItem(const std::string &name, Item< INDEX > &index, Array< TYPE > &array, const RANGE low, const RANGE high)
Add an indexed Array of data to a column wise N tuple with a range.
const Range< TYP > & range() const
Access the range.
long type() const
Return access type.
Item()
Standard Constructor.
static const CLID & classID()
class ID of the object
NTuple interface class definition.
Matrix & operator=(const Matrix< T > ©)
Assignment operator.
virtual ~Range()
Destructor.
Item< TYP > & operator-=(const TYP data)
NTuple interface class definition.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
This class is used for returning status codes from appropriate routines.
Matrix()
Standard Constructor.
static TYP max()
Maximal number of data.
Array()
Standard Constructor.
virtual const CLID & clID() const
class ID of the object
std::string m_name
Physical file name.
StatusCode i_addObject(const std::string &name, _Item< TYPE * > *&result, const std::type_info &)
TYP upper() const
Upper boundary of range.
bool isOpen() const
Access "open" flag.
unsigned int CLID
Class ID definition.
virtual ~File()
Standard destructor.
bool operator!() const
Check if column is present.
void setType(const long typ)
Set access type.
bool m_isOpen
Flag to indicate wether the file was opened already.
virtual const CLID & clID() const
class ID of the object
TYP distance() const
Distance between lower and upper range.
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
virtual ~_Accessor()
Standard Destructor.
TYP * operator[](const T i)
Array operator.
virtual INTupleItem * i_find(const std::string &name) const =0
Internally used by abstract classes.
Item & operator=(const TYP data)
Assignment operator.
A small class used to access easily (and efficiently) data items residing in data stores...
StatusCode addItem(const std::string &name, Item< TYPE > &itm)
Add a scalar data item a N tuple.
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
TYP m_upper
Upper boundary of range.
Item< TYP > & operator*=(const TYP data)
Array & operator=(const Array< T > ©)
Assignment operator.
StatusCode item(const std::string &name, Item< TYPE > &result)
Locate a scalar Item of data to the N tuple type safe.
Directory()
Standard constructor.
Opaque address interface definition.
TYP * m_ptr
Pointer to instance.
NamedRange_< CONTAINER > range(const CONTAINER &cnt, const std::string &name)
simple function to create the named range form arbitrary container
_Accessor()
Standard Constructor.
Range(const TYP low, const TYP upper)
Standard constructor.
A DataObject is the base class of any identifiable object on any data store.
_Accessor< TYP > & operator=(const _Accessor< TYP > &)
virtual ~Directory()
Standard destructor.
const std::string & logicalName() const
TYP operator*()
Dereference operator for pointers.
virtual ~Tuple()
Standard destructor.
TYP lower() const
Lower boundary of range.
StatusCode i_addItem(const std::string &name, long, const std::string &, TYPE low, TYPE high, _Item< TYPE > *&result)
Add a _Item of data to the N tuple.
Range & operator=(const Range< TYP > ©)
Adjust ranges.
static const CLID & classID()
class ID of the object
SmartDataPtr< NTuple::Tuple > NTuplePtr