Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

NTupleItems.h

Go to the documentation of this file.
00001 //====================================================================
00002 //  NTupleItems namespace parts definition
00003 //--------------------------------------------------------------------
00004 //
00005 //  Package    : Gaudi/NTupleSvc ( The LHCb Offline System)
00006 //  Author     : M.Frank
00007 //
00008 //  This header file is not intended to be included by the public!
00009 //  It's only used for the ntuple service 
00010 //
00011 //  +---------+----------------------------------------------+--------+
00012 //  |    Date |                 Comment                      | Who    |
00013 //  +---------+----------------------------------------------+--------+
00014 //  | 21/10/99| Initial version.                             | MF     |
00015 //  +---------+----------------------------------------------+--------+
00016 //====================================================================
00017 #ifndef GAUDI_NTUPLESVC_NTUPLEITEMS_H
00018 #define GAUDI_NTUPLESVC_NTUPLEITEMS_H 1
00019 
00020 // The converter understands all items
00021 #define ALLOW_ALL_TYPES
00022 
00023 // STL include files
00024 #include <vector>
00025 
00026 // Framework include files
00027 #include "GaudiKernel/System.h"
00028 #include "NTuple.h"
00029 
00030 // Forward declarations
00031 class IDataProviderSvc;
00032 class IConversionSvc;
00033 
00034 namespace NTuple    {
00035   // Local forward declarations
00036   template <class TYP> class DataItem;
00037   template <class TYP> class _DataImp;
00038   template <class TYP> class _ItemImp;
00039   template <class TYP> class _ArrayImp;
00040   template <class TYP> class _MatrixImp;
00041 
00044   template <class TYP> class _DataImp : virtual public _Data<TYP>  {
00045   private:
00047     _DataImp(const _DataImp& copy)    {}
00048   protected:
00050     long                  m_length;
00052     INTuple*              m_tuple;
00054     std::string           m_name;
00056     std::string           m_index;
00058     mutable INTupleItem*  m_indexItem;
00060     DataTypeInfo::Type    m_type;
00062     TYP                   m_def;
00064     Range<TYP>            m_range;
00065   public:
00067     _DataImp(INTuple* tup, const std::string& name, const std::string& index, long len, TYP low, TYP high, TYP def)
00068       : m_length(len), m_tuple(tup), m_name(name), m_index(index), 
00069       m_def(def),
00070       m_range(low, high)
00071     {
00072       m_indexItem = 0;
00073       m_type = DataTypeInfo::ID(m_def);
00074       m_buffer = new TYP[m_length];
00075       reset();
00076     }
00078     virtual ~_DataImp()                      {
00079       if ( 0 != m_buffer ) delete [] m_buffer;
00080     }
00082     virtual const std::string typeName()   const   {
00083       return System::typeinfoName( typeID() );
00084     }
00086     virtual void reset()                      {  
00087       TYP* buff = 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 > 1 )   {
00105           len *= dim(nd);
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 long size()   const                       { return m_length*sizeof(TYP);  }
00127     virtual void release()                            { delete this;                  }
00129     virtual bool                hasIndex() const      { return m_index.length()>0;    }
00131     virtual const std::string&  index() const         { return m_index;               }
00133     virtual const std::string&  name() const          { return m_name;                }
00135     virtual const long          type() const          { return m_type;                }
00137     virtual void                setType (long t)      { m_type=DataTypeInfo::Type(t); }
00139     virtual void setDefault(const TYP val)            { m_def = val;                  }
00141     virtual const ItemRange& range() const            { return m_range;               }
00143     virtual const long          length() const        { return m_length;              }
00145     virtual const void*         buffer() const        { return m_buffer;              }
00147     virtual void*               buffer()              { return m_buffer;              }
00149     virtual long                ndim() const          { return 0;                     }
00151     virtual long                dim(long i) const     { return (i==0) ? 1 : 0;        }
00153     virtual INTuple*            tuple()               { return m_tuple;               }
00154   };
00155 
00158   template <class TYP> class _ItemImp : virtual public _DataImp<TYP>, virtual public _Item<TYP>  {
00159   public:
00161     _ItemImp(INTuple* tup, const std::string& name, TYP min, TYP max, TYP def)
00162       : _DataImp<TYP>(tup, name, "", 1, min, max, def)    {                  }
00164     virtual ~_ItemImp()                      {                               }
00166     virtual const std::type_info& typeID() const {  return typeid(NTuple::_Item<TYP>);   }
00168     virtual void setDefault(const TYP val)   { m_def = val;                  }
00170     virtual const ItemRange& range() const   { return m_range;               }
00172     virtual long size()   const              { return m_length*sizeof(TYP);  }
00173   };
00174 
00177   template <class TYP> class _ArrayImp : virtual public _DataImp<TYP>, virtual public _Array<TYP>  {
00178   public:
00180     _ArrayImp(INTuple* tup, const std::string& name, const std::string& index, long len, TYP min, TYP max, TYP def)
00181     : _DataImp<TYP>(tup, name, index, len, min, max, def)    {  
00182     }
00184     virtual ~_ArrayImp()                     {                               }
00186     virtual const std::type_info& typeID() const  { return typeid(NTuple::_Array<TYP>);   }
00188     virtual void setDefault(const TYP val)   { m_def = val;                  }
00190     virtual const ItemRange& range() const   { return m_range;               }
00192     virtual long size()   const              { return m_length*sizeof(TYP);  }
00194     virtual long ndim()   const              { return 1;                     }
00196     virtual long dim(long i) const           { return (i!=0 || hasIndex()) ? 0 : m_length;  }
00197   };
00198 
00201   template <class TYP> class _MatrixImp : virtual public _DataImp<TYP>, virtual public _Matrix<TYP>  {
00202   public:
00204     _MatrixImp(INTuple* tup, const std::string& name, const std::string& index, long ncol, long nrow, TYP min, TYP max, TYP def)
00205     : _DataImp<TYP>(tup, name, index, nrow*ncol, min, max, def)    {
00206       m_rows = nrow;
00207     }
00209     virtual ~_MatrixImp()                    {                               }
00211     virtual const std::type_info& typeID() const  { return typeid(NTuple::_Matrix<TYP>);  }
00213     virtual void setDefault(const TYP val)   { m_def = val;                  }
00215     virtual const ItemRange& range() const   { return m_range;               }
00217     virtual long size()   const              { return m_length*sizeof(TYP);  }
00219     virtual long ndim() const                { return 2;                     }
00221     virtual long dim(long i) const           { 
00222       return (hasIndex()) ? ((i==0) ? m_rows : m_length/m_rows) : ((i==1) ? m_length/m_rows : m_rows);
00223     }
00224   };
00225 };   // end name space NTuple
00226 #endif  // GAUDI_NTUPLESVC_NTUPLEITEMS_H

Generated at Wed Nov 21 12:22:04 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000