Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:34

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2021 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDI_NTUPLESVC_NTUPLEITEMS_H
0012 #define GAUDI_NTUPLESVC_NTUPLEITEMS_H 1
0013 
0014 // The converter understands all items
0015 #define ALLOW_ALL_TYPES
0016 
0017 // STL include files
0018 #include <vector>
0019 
0020 // Framework include files
0021 #include "GaudiKernel/System.h"
0022 #include "NTuple.h"
0023 /**
0024  * @class NTupleItems NTupleItems.h GaudiKernel/NTupleItems.h
0025  *
0026  * NTupleItems namespace parts definition
0027  * This header file is not intended to be included by the public!
0028  * It's only used for the ntuple service
0029  *
0030  * @author M.Frank
0031  * @author Sebastien Ponce
0032  */
0033 
0034 // Forward declarations
0035 class IDataProviderSvc;
0036 class IConversionSvc;
0037 
0038 namespace NTuple {
0039   // Local forward declarations
0040   template <class TYP>
0041   class DataItem;
0042   template <class TYP>
0043   class _DataImp;
0044   template <class TYP>
0045   class _ItemImp;
0046   template <class TYP>
0047   class _ArrayImp;
0048   template <class TYP>
0049   class _MatrixImp;
0050 
0051   /** Concrete class discribing basic data items in an N tuple.
0052    */
0053   template <class TYP>
0054   class _DataImp : virtual public _Data<TYP> {
0055     /// Inhibit Copy Constructor
0056     _DataImp( const _DataImp& ) = delete;
0057 
0058   protected:
0059     typedef const std::string&    CSTR;
0060     typedef const std::type_info& CTYPE;
0061     /// Entire buffer length
0062     long m_length;
0063     /// Pointer to N tuple
0064     INTuple* m_tuple;
0065     /// _Column name
0066     std::string m_name;
0067     /// Check that values are within a certain range while filling
0068     std::string m_index;
0069     /// Pointer to index item
0070     mutable INTupleItem* m_indexItem = nullptr;
0071     /// _Column type
0072     DataTypeInfo::Type m_type;
0073     /// Buffer with default value
0074     TYP m_def;
0075     /// Check that values are within a certain range while filling
0076     Range<TYP> m_range;
0077     /// Item type information
0078     const std::type_info& m_info;
0079 
0080   public:
0081     /// Set type definition to make life more easy easy
0082     typedef Range<TYP> ItemRange;
0083     /// Standard Constructor
0084     _DataImp( INTuple* tup, std::string name, const std::type_info& info, std::string index, long len, TYP low,
0085               TYP high, TYP def )
0086         : m_length( len )
0087         , m_tuple( tup )
0088         , m_name( std::move( name ) )
0089         , m_index( std::move( index ) )
0090         , m_def( std::move( def ) )
0091         , m_range( std::move( low ), std::move( high ) )
0092         , m_info( info ) {
0093       m_type         = typeid( TYP ) == typeid( void* ) ? DataTypeInfo::POINTER : DataTypeInfo::ID( info );
0094       this->m_buffer = new TYP[m_length];
0095       reset();
0096     }
0097     /// Standard destructor
0098     ~_DataImp() override { delete[] this->m_buffer; }
0099     /// Get proper type name
0100     std::string typeName() const override { return System::typeinfoName( this->typeID() ); }
0101     /// Reset to default
0102     void reset() override { std::fill_n( this->m_buffer, m_length, m_def ); }
0103     /// Number of items filled
0104     long filled() const override {
0105       long len = 1;
0106       long nd  = ndim();
0107       if ( m_length > 1 ) {
0108         for ( int l = 0; l < nd - 1; l++ ) { len *= dim( l ); }
0109         if ( indexItem() ) {
0110           long* ll = (long*)m_indexItem->buffer();
0111           len *= *ll;
0112         } else if ( nd > 0 ) {
0113           len *= dim( nd - 1 );
0114         }
0115       }
0116       return len;
0117     }
0118     /// Pointer to index column (if present, 0 else)
0119     INTupleItem* indexItem() override {
0120       if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
0121       return m_indexItem;
0122     }
0123     /// Pointer to index column (if present, 0 else) (CONST)
0124     const INTupleItem* indexItem() const override {
0125       if ( !m_indexItem ) m_indexItem = m_tuple->find( m_index );
0126       return m_indexItem;
0127     }
0128     /// Compiler type ID
0129     const std::type_info& typeID() const override { return m_info; }
0130     /// Size of entire object
0131     long size() const override { return m_length * sizeof( TYP ); }
0132     /// Destruct object
0133     void release() override { delete this; }
0134     /// Is the tuple have an index column?
0135     bool hasIndex() const override { return m_index.length() > 0; }
0136     /// Access the index _Column
0137     const std::string& index() const override { return m_index; }
0138     /// Access _Column name
0139     const std::string& name() const override { return m_name; }
0140     /// TYP information of the item
0141     long type() const override { return m_type; }
0142     /// Set the properties of the _Column
0143     void setType( long t ) override { m_type = DataTypeInfo::Type( t ); }
0144     /// Set default value
0145     void setDefault( const TYP val ) override { m_def = val; }
0146     /// Access the range if specified
0147     const ItemRange& range() const override { return m_range; }
0148     /// Access the buffer length
0149     long length() const override { return m_length; }
0150     /// Access data buffer (CONST)
0151     const void* buffer() const override { return this->m_buffer; }
0152     /// Access data buffer
0153     virtual void* buffer() { return this->m_buffer; }
0154     /// Dimension
0155     long ndim() const override { return 0; }
0156     /// Access individual dimensions
0157     long dim( long i ) const override { return ( i == 0 ) ? 1 : 0; }
0158     /// Access to hosting ntuple
0159     INTuple* tuple() override { return m_tuple; }
0160   };
0161 
0162   /** Concrete class discribing a column in a N tuple.
0163    */
0164   template <class TYP>
0165   class _ItemImp : virtual public _DataImp<TYP>, virtual public _Item<TYP> {
0166 
0167   public:
0168     /// Set type definition to make life more easy easy
0169     typedef Range<TYP> ItemRange;
0170     /// Standard Constructor
0171     _ItemImp( INTuple* tup, const std::string& name, const std::type_info& info, TYP min, TYP max, TYP def )
0172         : _DataImp<TYP>( tup, name, info, "", 1, min, max, def ) {}
0173     /// Compiler type ID
0174     // virtual const std::type_info& typeID() const             { return typeid(NTuple::_Item<TYP>);  }
0175     /// Set default value
0176     void setDefault( const TYP val ) override { this->m_def = val; }
0177     /// Access the range if specified
0178     const ItemRange& range() const override { return this->m_range; }
0179     /// Size of entire object
0180     long size() const override { return this->m_length * sizeof( TYP ); }
0181   };
0182 
0183   /** Concrete class discribing a column-array in a N tuple.
0184    */
0185   template <class TYP>
0186   class _ArrayImp : virtual public _DataImp<TYP>, virtual public _Array<TYP> {
0187   public:
0188     /// Set type definition to make life more easy easy
0189     typedef Range<TYP> ItemRange;
0190     /// Standard Constructor
0191     _ArrayImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long len,
0192                TYP min, TYP max, TYP def )
0193         : _DataImp<TYP>( tup, name, typ, index, len, min, max, def ) {}
0194     /// Compiler type ID
0195     // virtual const std::type_info& typeID() const             { return typeid(NTuple::_Array<TYP>); }
0196     /// Set default value
0197     void setDefault( const TYP val ) override { this->m_def = val; }
0198     /// Access the range if specified
0199     const ItemRange& range() const override { return this->m_range; }
0200     /// Size of entire object
0201     long size() const override { return this->m_length * sizeof( TYP ); }
0202     /// Dimension
0203     long ndim() const override { return 1; }
0204     /// Access individual dimensions
0205     long dim( long i ) const override { return ( i != 0 || this->hasIndex() ) ? 0 : this->m_length; }
0206   };
0207 
0208   /** Concrete class discribing a matrix column in a N tuple.
0209    */
0210   template <class TYP>
0211   class _MatrixImp : virtual public _DataImp<TYP>, virtual public _Matrix<TYP> {
0212   public:
0213     /// Set type definition to make life more easy easy
0214     typedef Range<TYP> ItemRange;
0215     /// Standard Constructor
0216     _MatrixImp( INTuple* tup, const std::string& name, const std::type_info& typ, const std::string& index, long ncol,
0217                 long nrow, TYP min, TYP max, TYP def )
0218         : _DataImp<TYP>( tup, name, typ, index, nrow * ncol, min, max, def ) {
0219       this->m_rows = nrow;
0220     }
0221     /// Compiler type ID
0222     // virtual const std::type_info& typeID() const             { return typeid(NTuple::_Matrix<TYP>);}
0223     /// Set default value
0224     void setDefault( const TYP val ) override { this->m_def = val; }
0225     /// Access the range if specified
0226     const ItemRange& range() const override { return this->m_range; }
0227     /// Size of entire object
0228     long size() const override { return this->m_length * sizeof( TYP ); }
0229     /// Dimension
0230     long ndim() const override { return 2; }
0231     /// Access individual dimensions
0232     long dim( long i ) const override {
0233       return ( this->hasIndex() ) ? ( ( i == 0 ) ? this->m_rows : this->m_length / this->m_rows )
0234                                   : ( ( i == 1 ) ? this->m_length / this->m_rows : this->m_rows );
0235     }
0236   };
0237 } // namespace NTuple
0238 #endif // GAUDI_NTUPLESVC_NTUPLEITEMS_H