ROOT logo
// @(#)root/smatrix:$Id$
// Author: T. Glebe, L. Moneta, J. Palacios    2005  

#ifndef ROOT_Math_SVector
#define ROOT_Math_SVector
/********************************************************************
//
// source:
//
// type:      source code
//
// created:   16. Mar 2001
//
// author:    Thorsten Glebe
//            HERA-B Collaboration
//            Max-Planck-Institut fuer Kernphysik
//            Saupfercheckweg 1
//            69117 Heidelberg
//            Germany
//            E-mail: T.Glebe@mpi-hd.mpg.de
//
// Description: A fixed size Vector class
//
// changes:
// 16 Mar 2001 (TG) creation
// 21 Mar 2001 (TG) SVector::value_type added
// 21 Mar 2001 (TG) added operators +=, -=, *=, /=
// 26 Mar 2001 (TG) added place_at()
// 03 Apr 2001 (TG) Array() added
// 06 Apr 2001 (TG) CTORS added
// 07 Apr 2001 (TG) CTORS added
// 22 Aug 2001 (TG) CTOR(T*,len) added
// 04 Sep 2001 (TG) moved inlined functions to .icc file
// 14 Jan 2002 (TG) added operator==(), operator!=(), operator>(), operator<()
//
********************************************************************/

#ifndef ROOT_Math_MnConfig
#include "Math/MConfig.h"
#endif

#include <iosfwd>

// expression engine

#ifndef ROOT_Math_Expression
#include "Math/Expression.h"
#endif




namespace ROOT { 

namespace Math { 

//     template <class T, unsigned int D, unsigned int D2> class MatRepStd;

//     template <class A, class T, unsigned int D, unsigned int D2 = 1, class R = MatRepStd<T,D,D2> > class Expr;

//____________________________________________________________________________________________________________
/** 
    SVector: a generic fixed size Vector class.
    The class is template on the scalar type and on the vector size D. 
    See \ref SVectorDoc

    Original author is Thorsten Glebe
    HERA-B Collaboration, MPI Heidelberg (Germany)

    @ingroup SMatrixSVector

    @authors T. Glebe, L. Moneta and J. Palacios

*/
//==============================================================================
// SVector
//==============================================================================
template <class T, unsigned int D>
class SVector {
public:
   /** @name --- Typedefs --- */
   /// contained scalar type
   typedef T  value_type;
   
   /** STL iterator interface. */
   typedef T*  iterator;
   
   /** STL const_iterator interface. */
   typedef const T*  const_iterator;
   
   
   /** @name --- Constructors --- */
   /**
      Default constructor: vector filled with zero values 
    */
   SVector();
   /// contruct from a vector expression
   template <class A>
   SVector(const VecExpr<A,T,D>& rhs);
   /// copy contructor
   SVector(const SVector<T,D>& rhs);
      
   // new constructs using STL iterator interface
   // skip - need to solve the ambiguities 
#ifdef LATER
   /**
       Constructor with STL iterator interface. The data will be copied into the vector
       The iterator size must be equal to the vector size
    */
   template<class InputIterator>
   explicit SVector(InputIterator begin, InputIterator end); 
   
   /**
      Constructor with STL iterator interface. The data will be copied into the vector
      The size must be <= vector size
    */
   template<class InputIterator>
   explicit SVector(InputIterator begin, unsigned int size); 
   
#else 
   // if you use iterator this is not necessary
   
   /// fill from array with len must be equal to D!
   SVector( const T *  a, unsigned int len);
   
   /** fill from a SVector iterator of type T*   
      (for ambiguities iterator cannot be generic )
   */
   SVector(const_iterator begin, const_iterator end);
   
#endif
   /// construct a vector of size 1 from a single scalar value
   explicit SVector(const T& a1);
   /// construct a vector of size 2 from 2 scalar values 
   SVector(const T& a1, const T& a2);
   /// construct a vector of size 3 from 3 scalar values 
   SVector(const T& a1, const T& a2, const T& a3);
   /// construct a vector of size 4 from 4 scalar values  
   SVector(const T& a1, const T& a2, const T& a3, const T& a4);
   /// construct a vector of size 5 from 5 scalar values  
   SVector(const T& a1, const T& a2, const T& a3, const T& a4,
           const T& a5);
   /// construct a vector of size 6 from 6 scalar values  
   SVector(const T& a1, const T& a2, const T& a3, const T& a4,
           const T& a5, const T& a6);
   /// construct a vector of size 7 from 7 scalar values  
   SVector(const T& a1, const T& a2, const T& a3, const T& a4,
           const T& a5, const T& a6, const T& a7);
   /// construct a vector of size 8 from 8 scalar values  
   SVector(const T& a1, const T& a2, const T& a3, const T& a4,
           const T& a5, const T& a6, const T& a7, const T& a8);
   /// construct a vector of size 9 from 9 scalar values  
   SVector(const T& a1, const T& a2, const T& a3, const T& a4,
           const T& a5, const T& a6, const T& a7, const T& a8,
           const T& a9);
   /// construct a vector of size 10 from 10 scalar values  
   SVector(const T& a1, const T& a2, const T& a3, const T& a4,
           const T& a5, const T& a6, const T& a7, const T& a8,
           const T& a9, const T& a10);
   
   
   
   /// assignment from a scalar (only for size 1 vector)
   SVector<T,D>& operator=(const T& a1);
   /// assignment  from Vector Expression
   template <class A>
   SVector<T,D>& operator=(const VecExpr<A,T,D>& rhs);
   
   /** @name --- Access functions --- */
   
   /**
      Enumeration defining the Vector size
    */
   enum {
      /// return vector size
      kSize = D
   };
   
   
   /// return dimension $D$
   inline static unsigned int Dim() { return D; }
   /// access the parse tree. Index starts from zero
   T apply(unsigned int i) const;
   /// return read-only pointer to internal array
   const T* Array() const;
   /// return non-const pointer to internal array
   T* Array();
   
   /** @name --- STL-like interface --- */
   
   
   /** STL iterator interface. */
   iterator begin();
   
   /** STL iterator interface. */
   iterator end();
   
   /** STL const_iterator interface. */
   const_iterator begin() const;
   
   /** STL const_iterator interface. */
   const_iterator end() const;

   /// set vector elements copying the values 
   /// iterator size must match vector size
   template<class InputIterator>
   void SetElements(InputIterator begin, InputIterator end); 

   /// set vector elements copying the values 
   /// size must be <= vector size
   template<class InputIterator>
   void SetElements(InputIterator begin, unsigned int size); 
   
   
   /** @name --- Operators --- */
   
   /// element wise comparison
   bool operator==(const T& rhs) const;
   /// element wise comparison
   bool operator!=(const T& rhs) const;
   /// element wise comparison
   bool operator==(const SVector<T,D>& rhs) const;
   /// element wise comparison
   bool operator!=(const SVector<T,D>& rhs) const;
   /// element wise comparison
   template <class A>
   bool operator==(const VecExpr<A,T,D>& rhs) const;
   /// element wise comparison
   template <class A>
   bool operator!=(const VecExpr<A,T,D>& rhs) const;
   
   /// element wise comparison
   bool operator>(const T& rhs) const;
   /// element wise comparison
   bool operator<(const T& rhs) const;
   /// element wise comparison
   bool operator>(const SVector<T,D>& rhs) const;
   /// element wise comparison
   bool operator<(const SVector<T,D>& rhs) const;
   /// element wise comparison
   template <class A>
   bool operator>(const VecExpr<A,T,D>& rhs) const;
   /// element wise comparison
   template <class A>
   bool operator<(const VecExpr<A,T,D>& rhs) const;
   
   /// read-only access of vector elements. Index starts from 0. 
   const T& operator[](unsigned int i) const;
   /// read-only access of vector elements. Index starts from 0. 
   const T& operator()(unsigned int i) const;
   /// read-only access of vector elements with check on index. Index starts from 0.
   const T& At(unsigned int i) const;
   /// read/write access of vector elements. Index starts from 0. 
   T& operator[](unsigned int i);
   /// read/write access of vector elements. Index starts from 0. 
   T& operator()(unsigned int i);
   /// read/write access of vector elements with check on index. Index starts from 0.
   T& At(unsigned int i);
   
   /// self addition with a scalar
   SVector<T,D>& operator+=(const T& rhs);
   /// self subtraction with a scalar
   SVector<T,D>& operator-=(const T& rhs);
   /// self multiplication with a scalar 
   SVector<T,D>& operator*=(const T& rhs);
   /// self division with a scalar
   SVector<T,D>& operator/=(const T& rhs);


   /// self addition with another vector
   SVector<T,D>& operator+=(const SVector<T,D>& rhs);
   /// self subtraction with another vector
   SVector<T,D>& operator-=(const SVector<T,D>& rhs);
   /// self addition with a vector expression
   template <class A>
   SVector<T,D>& operator+=(const VecExpr<A,T,D>& rhs);
   /// self subtraction with a vector expression
   template <class A>
   SVector<T,D>& operator-=(const VecExpr<A,T,D>& rhs);


#ifdef OLD_IMPL
#ifndef __CINT__
   /// self element-wise multiplication  with another vector 
   SVector<T,D>& operator*=(const SVector<T,D>& rhs);
   /// self element-wise division with another vector 
   SVector<T,D>& operator/=(const SVector<T,D>& rhs);
      
   /// self element-wise multiplication  with a vector expression
   template <class A>
   SVector<T,D>& operator*=(const VecExpr<A,T,D>& rhs);
   /// self element-wise division  with a vector expression
   template <class A>
   SVector<T,D>& operator/=(const VecExpr<A,T,D>& rhs);
   
#endif
#endif
   
   /** @name --- Expert functions --- */
   /// transform vector into a vector of length 1
   SVector<T,D>& Unit();
   /// place a sub-vector starting from the given position
   template <unsigned int D2>
   SVector<T,D>& Place_at(const SVector<T,D2>& rhs, unsigned int row);
   /// place a sub-vector expression starting from the given position
   template <class A, unsigned int D2>
   SVector<T,D>& Place_at(const VecExpr<A,T,D2>& rhs, unsigned int row);
   
   /**
      return a subvector of size N starting at the value row
    where N is the size of the returned vector (SubVector::kSize)
    Condition  row+N <= D
    */ 
   template <class SubVector >  
   SubVector Sub(unsigned int row) const;
   

   /** 
       Function to check if a vector is sharing same memory location of the passed pointer
       This function is used by the expression templates to avoid the alias problem during  
       expression evaluation. When  the vector is in use, for example in operations 
       like V = M * V, where M is a mtrix, a temporary object storing the intermediate result is automatically 
       created when evaluating the expression. 
      
   */
   bool IsInUse(const T* p) const; 

   
   /// used by operator<<()
   std::ostream& Print(std::ostream& os) const;
   
private:
      
   /** @name --- Data member --- */
      
   /// SVector data
   T fArray[D];
}; // end of class SVector


//==============================================================================
// operator<<
//==============================================================================
template <class T, unsigned int D>
std::ostream& operator<<(std::ostream& os, const ROOT::Math::SVector<T,D>& rhs);



}  // namespace Math

}  // namespace ROOT



#ifndef __CINT__

// include implementation file
#ifndef ROOT_Math_SVector_icc
#include "Math/SVector.icc"
#endif

// include operators and functions
#ifndef ROOT_Math_UnaryOperators
#include "Math/UnaryOperators.h"
#endif
#ifndef ROOT_Math_BinaryOperators
#include "Math/BinaryOperators.h"
#endif
#ifndef ROOT_Math_MatrixFunctions
#include "Math/Functions.h"
#endif

#endif // __CINT__


#endif  /* ROOT_Math_SVector  */
 SVector.h:1
 SVector.h:2
 SVector.h:3
 SVector.h:4
 SVector.h:5
 SVector.h:6
 SVector.h:7
 SVector.h:8
 SVector.h:9
 SVector.h:10
 SVector.h:11
 SVector.h:12
 SVector.h:13
 SVector.h:14
 SVector.h:15
 SVector.h:16
 SVector.h:17
 SVector.h:18
 SVector.h:19
 SVector.h:20
 SVector.h:21
 SVector.h:22
 SVector.h:23
 SVector.h:24
 SVector.h:25
 SVector.h:26
 SVector.h:27
 SVector.h:28
 SVector.h:29
 SVector.h:30
 SVector.h:31
 SVector.h:32
 SVector.h:33
 SVector.h:34
 SVector.h:35
 SVector.h:36
 SVector.h:37
 SVector.h:38
 SVector.h:39
 SVector.h:40
 SVector.h:41
 SVector.h:42
 SVector.h:43
 SVector.h:44
 SVector.h:45
 SVector.h:46
 SVector.h:47
 SVector.h:48
 SVector.h:49
 SVector.h:50
 SVector.h:51
 SVector.h:52
 SVector.h:53
 SVector.h:54
 SVector.h:55
 SVector.h:56
 SVector.h:57
 SVector.h:58
 SVector.h:59
 SVector.h:60
 SVector.h:61
 SVector.h:62
 SVector.h:63
 SVector.h:64
 SVector.h:65
 SVector.h:66
 SVector.h:67
 SVector.h:68
 SVector.h:69
 SVector.h:70
 SVector.h:71
 SVector.h:72
 SVector.h:73
 SVector.h:74
 SVector.h:75
 SVector.h:76
 SVector.h:77
 SVector.h:78
 SVector.h:79
 SVector.h:80
 SVector.h:81
 SVector.h:82
 SVector.h:83
 SVector.h:84
 SVector.h:85
 SVector.h:86
 SVector.h:87
 SVector.h:88
 SVector.h:89
 SVector.h:90
 SVector.h:91
 SVector.h:92
 SVector.h:93
 SVector.h:94
 SVector.h:95
 SVector.h:96
 SVector.h:97
 SVector.h:98
 SVector.h:99
 SVector.h:100
 SVector.h:101
 SVector.h:102
 SVector.h:103
 SVector.h:104
 SVector.h:105
 SVector.h:106
 SVector.h:107
 SVector.h:108
 SVector.h:109
 SVector.h:110
 SVector.h:111
 SVector.h:112
 SVector.h:113
 SVector.h:114
 SVector.h:115
 SVector.h:116
 SVector.h:117
 SVector.h:118
 SVector.h:119
 SVector.h:120
 SVector.h:121
 SVector.h:122
 SVector.h:123
 SVector.h:124
 SVector.h:125
 SVector.h:126
 SVector.h:127
 SVector.h:128
 SVector.h:129
 SVector.h:130
 SVector.h:131
 SVector.h:132
 SVector.h:133
 SVector.h:134
 SVector.h:135
 SVector.h:136
 SVector.h:137
 SVector.h:138
 SVector.h:139
 SVector.h:140
 SVector.h:141
 SVector.h:142
 SVector.h:143
 SVector.h:144
 SVector.h:145
 SVector.h:146
 SVector.h:147
 SVector.h:148
 SVector.h:149
 SVector.h:150
 SVector.h:151
 SVector.h:152
 SVector.h:153
 SVector.h:154
 SVector.h:155
 SVector.h:156
 SVector.h:157
 SVector.h:158
 SVector.h:159
 SVector.h:160
 SVector.h:161
 SVector.h:162
 SVector.h:163
 SVector.h:164
 SVector.h:165
 SVector.h:166
 SVector.h:167
 SVector.h:168
 SVector.h:169
 SVector.h:170
 SVector.h:171
 SVector.h:172
 SVector.h:173
 SVector.h:174
 SVector.h:175
 SVector.h:176
 SVector.h:177
 SVector.h:178
 SVector.h:179
 SVector.h:180
 SVector.h:181
 SVector.h:182
 SVector.h:183
 SVector.h:184
 SVector.h:185
 SVector.h:186
 SVector.h:187
 SVector.h:188
 SVector.h:189
 SVector.h:190
 SVector.h:191
 SVector.h:192
 SVector.h:193
 SVector.h:194
 SVector.h:195
 SVector.h:196
 SVector.h:197
 SVector.h:198
 SVector.h:199
 SVector.h:200
 SVector.h:201
 SVector.h:202
 SVector.h:203
 SVector.h:204
 SVector.h:205
 SVector.h:206
 SVector.h:207
 SVector.h:208
 SVector.h:209
 SVector.h:210
 SVector.h:211
 SVector.h:212
 SVector.h:213
 SVector.h:214
 SVector.h:215
 SVector.h:216
 SVector.h:217
 SVector.h:218
 SVector.h:219
 SVector.h:220
 SVector.h:221
 SVector.h:222
 SVector.h:223
 SVector.h:224
 SVector.h:225
 SVector.h:226
 SVector.h:227
 SVector.h:228
 SVector.h:229
 SVector.h:230
 SVector.h:231
 SVector.h:232
 SVector.h:233
 SVector.h:234
 SVector.h:235
 SVector.h:236
 SVector.h:237
 SVector.h:238
 SVector.h:239
 SVector.h:240
 SVector.h:241
 SVector.h:242
 SVector.h:243
 SVector.h:244
 SVector.h:245
 SVector.h:246
 SVector.h:247
 SVector.h:248
 SVector.h:249
 SVector.h:250
 SVector.h:251
 SVector.h:252
 SVector.h:253
 SVector.h:254
 SVector.h:255
 SVector.h:256
 SVector.h:257
 SVector.h:258
 SVector.h:259
 SVector.h:260
 SVector.h:261
 SVector.h:262
 SVector.h:263
 SVector.h:264
 SVector.h:265
 SVector.h:266
 SVector.h:267
 SVector.h:268
 SVector.h:269
 SVector.h:270
 SVector.h:271
 SVector.h:272
 SVector.h:273
 SVector.h:274
 SVector.h:275
 SVector.h:276
 SVector.h:277
 SVector.h:278
 SVector.h:279
 SVector.h:280
 SVector.h:281
 SVector.h:282
 SVector.h:283
 SVector.h:284
 SVector.h:285
 SVector.h:286
 SVector.h:287
 SVector.h:288
 SVector.h:289
 SVector.h:290
 SVector.h:291
 SVector.h:292
 SVector.h:293
 SVector.h:294
 SVector.h:295
 SVector.h:296
 SVector.h:297
 SVector.h:298
 SVector.h:299
 SVector.h:300
 SVector.h:301
 SVector.h:302
 SVector.h:303
 SVector.h:304
 SVector.h:305
 SVector.h:306
 SVector.h:307
 SVector.h:308
 SVector.h:309
 SVector.h:310
 SVector.h:311
 SVector.h:312
 SVector.h:313
 SVector.h:314
 SVector.h:315
 SVector.h:316
 SVector.h:317
 SVector.h:318
 SVector.h:319
 SVector.h:320
 SVector.h:321
 SVector.h:322
 SVector.h:323
 SVector.h:324
 SVector.h:325
 SVector.h:326
 SVector.h:327
 SVector.h:328
 SVector.h:329
 SVector.h:330
 SVector.h:331
 SVector.h:332
 SVector.h:333
 SVector.h:334
 SVector.h:335
 SVector.h:336
 SVector.h:337
 SVector.h:338
 SVector.h:339
 SVector.h:340
 SVector.h:341
 SVector.h:342
 SVector.h:343
 SVector.h:344
 SVector.h:345
 SVector.h:346
 SVector.h:347
 SVector.h:348
 SVector.h:349
 SVector.h:350
 SVector.h:351
 SVector.h:352
 SVector.h:353
 SVector.h:354
 SVector.h:355
 SVector.h:356
 SVector.h:357
 SVector.h:358
 SVector.h:359
 SVector.h:360
 SVector.h:361
 SVector.h:362
 SVector.h:363
 SVector.h:364
 SVector.h:365
 SVector.h:366
 SVector.h:367
 SVector.h:368
 SVector.h:369
 SVector.h:370
 SVector.h:371
 SVector.h:372
 SVector.h:373
 SVector.h:374
 SVector.h:375
 SVector.h:376