StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TRArray.h
1 #ifndef ROOT_TRArray
2 #define ROOT_TRArray
3 #include <assert.h>
4 #include "Riostream.h"
5 #include "Rstrstream.h"
6 #include "Rtypes.h"
7 #include "TObject.h"
8 #include "TArrayD.h"
9 #include "TMath.h"
10 #include "Varargs.h"
11 #if ROOT_VERSION_CODE < 331013
12 #include "TCL.h"
13 #else
14 #include "TCernLib.h"
15 #endif
16 #ifndef __CINT__
17 #define __VA_LIST__(name) \
18  va_list args; \
19  va_start(args,va_(name)); \
20  for (Int_t num=0; num<fN; num++) { \
21  if (! num) fArray[0] = name; \
22  else fArray[num] = (Double_t) va_arg(args, Double_t); \
23  } \
24  va_end(args);
25 #endif
26 
27 
28 
29 class TRArray : public TArrayD {
30  public:
31  enum ETRMatrixType {kUndefined, kVector, kRectangular, kSemiPosDefinedSymMatrix, kDiagonalMatrix};
32  enum ETRMatrixCreatorsOp { kZero, kUnit, kTransposed, kInverted, kInvertedPosDef, kInvertedA,
33  kMult,
34  kAxB, kAxBT, kATxB, kATxBT,
35  kAxBxAT, kATxBxA,
36  kSxA, kAxS, kSxAT, kATxS,
37  kAxAT, kATxA,
38  kAxSxAT, kATxSxA, kRxSxR
39  };
40  TRArray(Int_t N=0): TArrayD(N), fValid(kTRUE), fIsNotOwn(kFALSE) {}
41  // TRArray(Int_t N,Double_t scalar): TArrayD(N) {if (scalar != 0) Reset(scalar);}
42 #ifndef __CINT__
43  TRArray(Int_t N,Double_t a0, ...);
44 #endif
45  TRArray(Int_t N,const Double_t *Array): TArrayD(N,Array), fValid(kTRUE), fIsNotOwn(kFALSE) {}
46  TRArray(Int_t N,const Float_t *Array);
47  TRArray(const TRArray &A,const Double_t fA, TRArray &B,const Double_t fB): TArrayD(0), fValid(kTRUE), fIsNotOwn(kFALSE) {
48  Int_t N = A.GetSize(); assert (N == B.GetSize()); Set(N);
49  TCL::vlinco(A.GetArray(),fA,B.GetArray(),fB,fArray,N);
50  }
51  TRArray(Int_t N,const Char_t *s);
52  virtual ~TRArray() {if (fIsNotOwn) fArray = 0;}
53  virtual Int_t GetNrows() const {return GetSize();}
54  virtual Int_t GetNcols() const {return 1;}
55  virtual ETRMatrixType GetMatrixType() const {return kUndefined;}
56  virtual Bool_t IsValid() const {return fValid;}
57  virtual Double_t Mag2() const;
58  virtual Double_t Mag() const {return TMath::Sqrt(Mag2());}
59  virtual void SetValid(Bool_t Valid=kTRUE) {fValid = Valid;}
60  void Set(Int_t n);
61  void Set(Int_t n, const Double_t *array);
62  void Set(Int_t n, const Float_t *array);
63  void AdoptA(Int_t n, Double_t *arr);
64  void reset() {Reset();}
65  TRArray& operator=(const TRArray &rhs);
66  virtual Double_t &operator()(Int_t i) {return operator[](i);}
67  virtual Double_t operator()(Int_t i) const {return operator[](i);}
68  friend TRArray &operator-=(TRArray &target, Double_t scalar) {
69  for (int i=0; i<target.fN; i++) target.fArray[i] -= scalar; return target;}
70  friend TRArray &operator+=(TRArray &target, Double_t scalar) {
71  for (int i=0; i<target.fN; i++) target.fArray[i] += scalar; return target;
72  }
73  friend Double_t operator*(const TRArray &target, const TRArray &source) {
74  assert(target.fN == source.GetSize());
75  Double_t sum = 0;
76  const Double_t *sArray = source.GetArray();
77  for (int i=0; i<target.fN; i++) sum += target.fArray[i]*sArray[i]; return sum;
78  }
79  friend TRArray &operator*=(TRArray &target, Double_t scalar) {
80  for (int i=0; i<target.fN; i++) target.fArray[i] *= scalar; return target;
81  }
82  friend TRArray &operator/=(TRArray &target, Double_t scalar) {
83  for (int i=0; i<target.fN; i++) target.fArray[i] /= scalar; return target;
84  }
85  friend TRArray &operator-=(TRArray &target, const TRArray &A) {
86  assert(target.fN == A.GetSize());
87  const Double_t *fA = A.GetArray();
88  for (int i=0; i<target.fN; i++) target.fArray[i] -= fA[i];
89  return target;
90  }
91  friend TRArray &operator+=(TRArray &target, const TRArray &A) {
92  assert(target.fN == A.GetSize());
93  const Double_t *fA = A.GetArray();
94  for (int i=0; i<target.fN; i++) target.fArray[i] += fA[i];
95  return target;
96  }
97 
98  friend Bool_t operator==(TRArray &target, Double_t scalar) {
99  for (int i=0; i<target.fN; i++) if (target.fArray[i] != scalar) return kFALSE;
100  return kTRUE;
101  }
102  friend Bool_t operator==(TRArray &target, const TRArray &A) {
103  if (target.fN != A.GetSize()) return kFALSE;
104  const Double_t *fB = A.GetArray();
105  for (int i=0; i<target.fN; i++) if (target.fArray[i] != fB[i]) return kFALSE; return kTRUE;
106  }
107  friend TRArray operator + (const TRArray &A, const TRArray &B) {TRArray C(A); C += B; return C;}
108  friend TRArray operator - (const TRArray &A, const TRArray &B) {TRArray C(A); C -= B; return C;}
109 
110  Bool_t Verify(const TRArray &A, const Double_t zeru=5.e-7, Int_t Level=1) const;
111  virtual void Print(Option_t *opt="") const;
112  protected:
113  Bool_t fValid;
114  Bool_t fIsNotOwn; /* == kTRUE If TRArray created via AdoptA(Int_t n, Double_t *array) method
115  then TRArray is not owner of fArray and user has to care to its size and delete
116  in contrary TArrayD */
117  public:
118  ClassDef(TRArray,1) // TRArray class (double precision)
119 };
120 std::ostream& operator<<(std::ostream& s,const TRArray &target);
121 std::istream & operator>>(std::istream &s, TRArray &target);
122 
123 #endif