| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# NTupleItems.h

Go to the documentation of this file.

    00001 // $Id: NTupleItems.h,v 1.7 2008/10/27 19:22:20 marcocle Exp $
    00002 #ifndef GAUDI_NTUPLESVC_NTUPLEITEMS_H
    00003 #define GAUDI_NTUPLESVC_NTUPLEITEMS_H 1
    00004
    00005 // The converter understands all items
    00006 #define ALLOW_ALL_TYPES
    00007
    00008 // STL include files
    00009 #include <vector>
    00010
    00011 // Framework include files
    00012 #include "GaudiKernel/System.h"
    00013 #include "NTuple.h"
    00025 // Forward declarations
    00026 class IDataProviderSvc;
    00027 class IConversionSvc;
    00028
    00029 namespace NTuple    {
    00030   // Local forward declarations
    00031   template <class TYP> class DataItem;
    00032   template <class TYP> class _DataImp;
    00033   template <class TYP> class _ItemImp;
    00034   template <class TYP> class _ArrayImp;
    00035   template <class TYP> class _MatrixImp;
    00036
    00039   template <class TYP> class _DataImp : virtual public _Data<TYP>  {
    00040   private:
    00042     _DataImp(const _DataImp& copy)    {}
    00043   protected:
    00044     typedef const std::string& CSTR;
    00045     typedef const std::type_info& CTYPE;
    00047     long                  m_length;
    00049     INTuple*              m_tuple;
    00051     std::string           m_name;
    00053     std::string           m_index;
    00055     mutable INTupleItem*  m_indexItem;
    00057     DataTypeInfo::Type    m_type;
    00059     TYP                   m_def;
    00061     Range<TYP>            m_range;
    00063     const std::type_info&                 m_info;
    00064   public:
    00066     typedef Range<TYP>  ItemRange;
    00068     _DataImp(INTuple* tup,const std::string& name,const std::type_info& info,const std::string& index,long len,TYP low,TYP high,TYP def)
    00069     : m_length(len), m_tuple(tup), m_name(name), m_index(index),
    00070       m_def(def), m_range(low, high), m_info(info)
    00071     {
    00072       m_indexItem = 0;
    00073       m_type = typeid(TYP) == typeid(void*) ? DataTypeInfo::POINTER : DataTypeInfo::ID(info);
    00074       this->m_buffer = new TYP[m_length];
    00075       reset();
    00076     }
    00078     virtual ~_DataImp()                      {
    00079       if ( 0 != this->m_buffer ) delete [] this->m_buffer;
    00080     }
    00082     virtual std::string typeName()   const   {
    00083       return System::typeinfoName( this->typeID() );
    00084     }
    00086     virtual void reset()                      {
    00087       TYP* buff = this->m_buffer;
    00088       for ( size_t i = 0; i < static_cast<size_t>(m_length); i++ )    {
    00089         *buff++ = m_def;
    00090       }
    00091     }
    00093     virtual long filled()  const              {
    00094       int len = 1;
    00095       int nd = ndim();
    00096       if ( m_length > 1 )   {
    00097         for ( int l = 0; l < nd-1; l++ )   {
    00098           len *= dim(l);
    00099         }
    00100         if ( indexItem() )   {
    00101           long *ll = (long*)m_indexItem->buffer();
    00102           len *= *ll;
    00103         }
    00104         else if ( nd > 0 )   {
    00105           len *= dim(nd-1);
    00106         }
    00107       }
    00108       return len;
    00109     }
    00111     virtual INTupleItem* indexItem()                  {
    00112       if ( 0 == m_indexItem )   {
    00113         m_indexItem = m_tuple->find(m_index);
    00114       }
    00115       return m_indexItem;
    00116     }
    00118     virtual const INTupleItem* indexItem() const      {
    00119       if ( 0 == m_indexItem )   {
    00120         m_indexItem = m_tuple->find(m_index);
    00121       }
    00122       return m_indexItem;
    00123     }
    00125     virtual const std::type_info& typeID() const             { return m_info;}
    00127     virtual long size() const { return m_length*sizeof(TYP); }
    00129     virtual void release() { delete this; }
    00131     virtual bool hasIndex() const { return m_index.length()>0; }
    00133     virtual const std::string& index() const { return m_index; }
    00135     virtual const std::string&  name() const { return m_name; }
    00137     virtual long type() const { return m_type; }
    00139     virtual void setType (long t) { m_type=DataTypeInfo::Type(t); }
    00141     virtual void setDefault(const TYP val) { m_def = val; }
    00143     virtual const ItemRange& range() const { return m_range; }
    00145     virtual long length() const { return m_length; }
    00147     virtual const void* buffer() const { return this->m_buffer; }
    00149     virtual void* buffer() { return this->m_buffer; }
    00151     virtual long ndim() const { return 0; }
    00153     virtual long dim(long i) const { return (i==0) ? 1 : 0; }
    00155     virtual INTuple* tuple() { return m_tuple; }
    00156   };
    00157
    00160   template <class TYP> class _ItemImp : virtual public _DataImp<TYP>,
    00161                                         virtual public _Item<TYP>  {
    00162
    00163   public:
    00165     typedef Range<TYP>  ItemRange;
    00167     _ItemImp(INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def)
    00168     : _DataImp<TYP>(tup, name, info, "", 1, min, max, def) {                       }
    00170     virtual ~_ItemImp()                      {                                     }
    00172     //virtual const std::type_info& typeID() const             { return typeid(NTuple::_Item<TYP>);  }
    00174     virtual void setDefault(const TYP val)   { this->m_def = val;                  }
    00176     virtual const ItemRange& range() const   { return this->m_range;               }
    00178     virtual long size()   const              { return this->m_length*sizeof(TYP);  }
    00179   };
    00180
    00183   template <class TYP> class _ArrayImp : virtual public _DataImp<TYP>,
    00184                                          virtual public _Array<TYP>  {
    00185   public:
    00187     typedef Range<TYP>  ItemRange;
    00189     _ArrayImp(INTuple* tup,const std::string& name,const std::type_info& typ,const std::string& index,long len,TYP min,TYP max,TYP def)
    00190     : _DataImp<TYP>(tup, name, typ, index, len, min, max, def)    {                }
    00192     virtual ~_ArrayImp()                     {                                     }
    00194     //virtual const std::type_info& typeID() const             { return typeid(NTuple::_Array<TYP>); }
    00196     virtual void setDefault(const TYP val)   { this->m_def = val;                  }
    00198     virtual const ItemRange& range() const   { return this->m_range;               }
    00200     virtual long size()   const              { return this->m_length*sizeof(TYP);  }
    00202     virtual long ndim()   const              { return 1;                     }
    00204     virtual long dim(long i) const {
    00205       return (i!=0 || this->hasIndex()) ? 0 : this->m_length;
    00206     }
    00207   };
    00208
    00211   template <class TYP> class _MatrixImp : virtual public _DataImp<TYP>,
    00212                                           virtual public _Matrix<TYP>  {
    00213   public:
    00215     typedef Range<TYP>  ItemRange;
    00217     _MatrixImp(INTuple* tup,const std::string& name,const std::type_info& typ,const std::string& index,
    00218                long ncol,long nrow,TYP min,TYP max,TYP def)
    00219     : _DataImp<TYP>(tup, name, typ, index, nrow*ncol, min, max, def)    {
    00220       this->m_rows = nrow;
    00221     }
    00223     virtual ~_MatrixImp()                    {                                     }
    00225     //virtual const std::type_info& typeID() const             { return typeid(NTuple::_Matrix<TYP>);}
    00227     virtual void setDefault(const TYP val)   { this->m_def = val;                  }
    00229     virtual const ItemRange& range() const   { return this->m_range;               }
    00231     virtual long size()   const              { return this->m_length*sizeof(TYP);  }
    00233     virtual long ndim() const                { return 2;                           }
    00235     virtual long dim(long i) const           {
    00236       return (this->hasIndex()) ?
    00237         ((i==0) ?
    00238          this->m_rows : this->m_length/this->m_rows) : ((i==1) ? this->m_length/this->m_rows : this->m_rows);
    00239     }
    00240   };
    00241 }   // end name space NTuple
    00242 #endif  // GAUDI_NTUPLESVC_NTUPLEITEMS_H