Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:21

0001 // @(#)root/smatrix:$Id$
0002 // Author: T. Glebe, L. Moneta, J. Palacios    2005
0003 
0004 #ifndef ROOT_Math_SVector
0005 #define ROOT_Math_SVector
0006 /********************************************************************
0007 //
0008 // source:
0009 //
0010 // type:      source code
0011 //
0012 // created:   16. Mar 2001
0013 //
0014 // author:    Thorsten Glebe
0015 //            HERA-B Collaboration
0016 //            Max-Planck-Institut fuer Kernphysik
0017 //            Saupfercheckweg 1
0018 //            69117 Heidelberg
0019 //            Germany
0020 //            E-mail: T.Glebe@mpi-hd.mpg.de
0021 //
0022 // Description: A fixed size Vector class
0023 //
0024 // changes:
0025 // 16 Mar 2001 (TG) creation
0026 // 21 Mar 2001 (TG) SVector::value_type added
0027 // 21 Mar 2001 (TG) added operators +=, -=, *=, /=
0028 // 26 Mar 2001 (TG) added place_at()
0029 // 03 Apr 2001 (TG) Array() added
0030 // 06 Apr 2001 (TG) CTORS added
0031 // 07 Apr 2001 (TG) CTORS added
0032 // 22 Aug 2001 (TG) CTOR(T*,len) added
0033 // 04 Sep 2001 (TG) moved inlined functions to .icc file
0034 // 14 Jan 2002 (TG) added operator==(), operator!=(), operator>(), operator<()
0035 //
0036 ********************************************************************/
0037 
0038 #include "Math/MConfig.h"
0039 
0040 #include <iosfwd>
0041 
0042 // expression engine
0043 
0044 #include "Math/Expression.h"
0045 
0046 
0047 
0048 
0049 namespace ROOT {
0050 
0051 namespace Math {
0052 
0053 //     template <class T, unsigned int D, unsigned int D2> class MatRepStd;
0054 
0055 //     template <class A, class T, unsigned int D, unsigned int D2 = 1, class R = MatRepStd<T,D,D2> > class Expr;
0056 
0057 //____________________________________________________________________________________________________________
0058 /**
0059     SVector: a generic fixed size Vector class.
0060     The class is template on the scalar type and on the vector size D.
0061     See \ref SVectorDoc
0062 
0063     Original author is Thorsten Glebe
0064     HERA-B Collaboration, MPI Heidelberg (Germany)
0065 
0066     @ingroup SMatrixSVector
0067 
0068     @authors T. Glebe, L. Moneta and J. Palacios
0069 
0070 */
0071 //==============================================================================
0072 // SVector
0073 //==============================================================================
0074 template <class T, unsigned int D>
0075 class SVector {
0076 public:
0077    /** @name --- Typedefs --- */
0078    /// contained scalar type
0079    typedef T  value_type;
0080 
0081    /** STL iterator interface. */
0082    typedef T*  iterator;
0083 
0084    /** STL const_iterator interface. */
0085    typedef const T*  const_iterator;
0086 
0087 
0088    /** @name --- Constructors --- */
0089    /**
0090       Default constructor: vector filled with zero values
0091     */
0092    SVector();
0093    /// construct from a vector expression
0094    template <class A>
0095    SVector(const VecExpr<A,T,D>& rhs);
0096    /// copy constructor
0097    SVector(const SVector<T,D>& rhs);
0098 
0099    // new constructs using STL iterator interface
0100    // skip - need to solve the ambiguities
0101 #ifdef LATER
0102    /**
0103        Constructor with STL iterator interface. The data will be copied into the vector
0104        The iterator size must be equal to the vector size
0105     */
0106    template<class InputIterator>
0107    explicit SVector(InputIterator begin, InputIterator end);
0108 
0109    /**
0110       Constructor with STL iterator interface. The data will be copied into the vector
0111       The size must be <= vector size
0112     */
0113    template<class InputIterator>
0114    explicit SVector(InputIterator begin, unsigned int size);
0115 
0116 #else
0117    // if you use iterator this is not necessary
0118 
0119    /// fill from array with len must be equal to D!
0120    SVector( const T *  a, unsigned int len);
0121 
0122    /** fill from a SVector iterator of type T*
0123       (for ambiguities iterator cannot be generic )
0124    */
0125    SVector(const_iterator begin, const_iterator end);
0126 
0127 #endif
0128    /// construct a vector of size 1 from a single scalar value
0129    explicit SVector(const T& a1);
0130    /// construct a vector of size 2 from 2 scalar values
0131    SVector(const T& a1, const T& a2);
0132    /// construct a vector of size 3 from 3 scalar values
0133    SVector(const T& a1, const T& a2, const T& a3);
0134    /// construct a vector of size 4 from 4 scalar values
0135    SVector(const T& a1, const T& a2, const T& a3, const T& a4);
0136    /// construct a vector of size 5 from 5 scalar values
0137    SVector(const T& a1, const T& a2, const T& a3, const T& a4,
0138            const T& a5);
0139    /// construct a vector of size 6 from 6 scalar values
0140    SVector(const T& a1, const T& a2, const T& a3, const T& a4,
0141            const T& a5, const T& a6);
0142    /// construct a vector of size 7 from 7 scalar values
0143    SVector(const T& a1, const T& a2, const T& a3, const T& a4,
0144            const T& a5, const T& a6, const T& a7);
0145    /// construct a vector of size 8 from 8 scalar values
0146    SVector(const T& a1, const T& a2, const T& a3, const T& a4,
0147            const T& a5, const T& a6, const T& a7, const T& a8);
0148    /// construct a vector of size 9 from 9 scalar values
0149    SVector(const T& a1, const T& a2, const T& a3, const T& a4,
0150            const T& a5, const T& a6, const T& a7, const T& a8,
0151            const T& a9);
0152    /// construct a vector of size 10 from 10 scalar values
0153    SVector(const T& a1, const T& a2, const T& a3, const T& a4,
0154            const T& a5, const T& a6, const T& a7, const T& a8,
0155            const T& a9, const T& a10);
0156 
0157 
0158 
0159    /// assignment from a scalar (only for size 1 vector)
0160    SVector<T,D>& operator=(const T& a1);
0161    /// assignment from another vector
0162    SVector<T,D>& operator=(const SVector<T,D>& rhs);
0163    /// assignment  from Vector Expression
0164    template <class A>
0165    SVector<T,D>& operator=(const VecExpr<A,T,D>& rhs);
0166 
0167    /** @name --- Access functions --- */
0168 
0169    /**
0170       Enumeration defining the Vector size
0171     */
0172    enum {
0173       /// return vector size
0174       kSize = D
0175    };
0176 
0177 
0178    /// return dimension \f$D\f$
0179    inline static unsigned int Dim() { return D; }
0180    /// access the parse tree. Index starts from zero
0181    T apply(unsigned int i) const;
0182    /// return read-only pointer to internal array
0183    const T* Array() const;
0184    /// return non-const pointer to internal array
0185    T* Array();
0186 
0187    /** @name --- STL-like interface --- */
0188 
0189 
0190    /** STL iterator interface. */
0191    iterator begin();
0192 
0193    /** STL iterator interface. */
0194    iterator end();
0195 
0196    /** STL const_iterator interface. */
0197    const_iterator begin() const;
0198 
0199    /** STL const_iterator interface. */
0200    const_iterator end() const;
0201 
0202    /// set vector elements copying the values
0203    /// iterator size must match vector size
0204    template<class InputIterator>
0205    void SetElements(InputIterator begin, InputIterator end);
0206 
0207    /// set vector elements copying the values
0208    /// size must be <= vector size
0209    template<class InputIterator>
0210    void SetElements(InputIterator begin, unsigned int size);
0211 
0212 
0213    /** @name --- Operators --- */
0214 
0215    /// element wise comparison
0216    bool operator==(const T& rhs) const;
0217    /// element wise comparison
0218    bool operator!=(const T& rhs) const;
0219    /// element wise comparison
0220    bool operator==(const SVector<T,D>& rhs) const;
0221    /// element wise comparison
0222    bool operator!=(const SVector<T,D>& rhs) const;
0223    /// element wise comparison
0224    template <class A>
0225    bool operator==(const VecExpr<A,T,D>& rhs) const;
0226    /// element wise comparison
0227    template <class A>
0228    bool operator!=(const VecExpr<A,T,D>& rhs) const;
0229 
0230    /// element wise comparison
0231    bool operator>(const T& rhs) const;
0232    /// element wise comparison
0233    bool operator<(const T& rhs) const;
0234    /// element wise comparison
0235    bool operator>(const SVector<T,D>& rhs) const;
0236    /// element wise comparison
0237    bool operator<(const SVector<T,D>& rhs) const;
0238    /// element wise comparison
0239    template <class A>
0240    bool operator>(const VecExpr<A,T,D>& rhs) const;
0241    /// element wise comparison
0242    template <class A>
0243    bool operator<(const VecExpr<A,T,D>& rhs) const;
0244 
0245    /// read-only access of vector elements. Index starts from 0.
0246    const T& operator[](unsigned int i) const;
0247    /// read-only access of vector elements. Index starts from 0.
0248    const T& operator()(unsigned int i) const;
0249    /// read-only access of vector elements with check on index. Index starts from 0.
0250    const T& At(unsigned int i) const;
0251    /// read/write access of vector elements. Index starts from 0.
0252    T& operator[](unsigned int i);
0253    /// read/write access of vector elements. Index starts from 0.
0254    T& operator()(unsigned int i);
0255    /// read/write access of vector elements with check on index. Index starts from 0.
0256    T& At(unsigned int i);
0257 
0258    /// self addition with a scalar
0259    SVector<T,D>& operator+=(const T& rhs);
0260    /// self subtraction with a scalar
0261    SVector<T,D>& operator-=(const T& rhs);
0262    /// self multiplication with a scalar
0263    SVector<T,D>& operator*=(const T& rhs);
0264    /// self division with a scalar
0265    SVector<T,D>& operator/=(const T& rhs);
0266 
0267 
0268    /// self addition with another vector
0269    SVector<T,D>& operator+=(const SVector<T,D>& rhs);
0270    /// self subtraction with another vector
0271    SVector<T,D>& operator-=(const SVector<T,D>& rhs);
0272    /// self addition with a vector expression
0273    template <class A>
0274    SVector<T,D>& operator+=(const VecExpr<A,T,D>& rhs);
0275    /// self subtraction with a vector expression
0276    template <class A>
0277    SVector<T,D>& operator-=(const VecExpr<A,T,D>& rhs);
0278 
0279 
0280 #ifdef OLD_IMPL
0281    /// self element-wise multiplication  with another vector
0282    SVector<T,D>& operator*=(const SVector<T,D>& rhs);
0283    /// self element-wise division with another vector
0284    SVector<T,D>& operator/=(const SVector<T,D>& rhs);
0285 
0286    /// self element-wise multiplication  with a vector expression
0287    template <class A>
0288    SVector<T,D>& operator*=(const VecExpr<A,T,D>& rhs);
0289    /// self element-wise division  with a vector expression
0290    template <class A>
0291    SVector<T,D>& operator/=(const VecExpr<A,T,D>& rhs);
0292 
0293 #endif
0294 
0295    /** @name --- Expert functions --- */
0296    /// transform vector into a vector of length 1
0297    SVector<T,D>& Unit();
0298    /// place a sub-vector starting from the given position
0299    template <unsigned int D2>
0300    SVector<T,D>& Place_at(const SVector<T,D2>& rhs, unsigned int row);
0301    /// place a sub-vector expression starting from the given position
0302    template <class A, unsigned int D2>
0303    SVector<T,D>& Place_at(const VecExpr<A,T,D2>& rhs, unsigned int row);
0304 
0305    /**
0306       return a subvector of size N starting at the value row
0307     where N is the size of the returned vector (SubVector::kSize)
0308     Condition  row+N <= D
0309     */
0310    template <class SubVector >
0311    SubVector Sub(unsigned int row) const;
0312 
0313 
0314    /**
0315        Function to check if a vector is sharing same memory location of the passed pointer
0316        This function is used by the expression templates to avoid the alias problem during
0317        expression evaluation. When  the vector is in use, for example in operations
0318        like V = M * V, where M is a mtrix, a temporary object storing the intermediate result is automatically
0319        created when evaluating the expression.
0320 
0321    */
0322    bool IsInUse(const T* p) const;
0323 
0324 
0325    /// used by operator<<()
0326    std::ostream& Print(std::ostream& os) const;
0327 
0328 private:
0329 
0330    /** @name --- Data member --- */
0331 
0332    /// SVector data
0333    T fArray[D];
0334 }; // end of class SVector
0335 
0336 
0337 //==============================================================================
0338 // operator<<
0339 //==============================================================================
0340 template <class T, unsigned int D>
0341 std::ostream& operator<<(std::ostream& os, const ROOT::Math::SVector<T,D>& rhs);
0342 
0343 
0344 
0345 }  // namespace Math
0346 
0347 }  // namespace ROOT
0348 
0349 
0350 
0351 // include implementation file
0352 #include "Math/SVector.icc"
0353 
0354 // include operators and functions
0355 #include "Math/UnaryOperators.h"
0356 #include "Math/BinaryOperators.h"
0357 #include "Math/Functions.h"
0358 
0359 #endif  /* ROOT_Math_SVector  */