Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:55:33

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