5 #if ROOT_VERSION_CODE < 331013
10 #include "TObjString.h"
11 #include "TObjArray.h"
15 TRArray::TRArray(Int_t N,
const Float_t *Array): TArrayD(N), fValid(kTRUE), fIsNotOwn(kFALSE) {
16 TCL::ucopy(Array,fArray,N);
19 TRArray::TRArray(Int_t N,Double_t va_(a0), ...) : TArrayD(N), fValid(kTRUE), fIsNotOwn(kFALSE) {
23 TRArray::TRArray(Int_t N,
const Char_t *s): TArrayD(N), fValid(kTRUE), fIsNotOwn(kFALSE) {
24 static TString separator =
"([^\t ;,]+)";
26 TObjArray *array = opt.Tokenize(separator);
30 while ((objs = (TObjString *) next()) && i < N) {fArray[i++] = objs->GetString().Atof();}
34 Double_t TRArray::Mag2()
const {
35 return TCL::vdot(fArray,fArray,fN);
38 ostream& operator<<(ostream& s,
const TRArray &target) {
39 s <<
"Size \t" << target.fN << endl;
41 for (
int i = 0; i< target.fN; i++) {
42 s << Form(
"%10.3f", target.fArray[i]);
43 if ((i+1)%10 == 0) s << endl;
50 istream & operator>>(istream &s,
TRArray &target) {
53 if (N != target.fN) target.Set(N);
54 for (
int i = 0; i < N; i++) s >> target.fArray[i];
60 if (! fIsNotOwn) Set(rhs.fN, rhs.fArray);
63 memcpy(fArray,rhs.fArray, fN*
sizeof(Double_t));
69 Bool_t TRArray::Verify(
const TRArray &A, Double_t zeru, Int_t Level)
const {
72 if (fN != A.GetSize()) {
73 if (Level) cout <<
"Check length is inconsistent:" << fN <<
" != " << A.GetSize() << endl;
76 const Double_t *aArray = A.GetArray();
77 for (
int i=0; i<fN; i++) {
78 Double_t diff = TMath::Abs(aArray[i] - fArray[i]);
79 Double_t sum = TMath::Abs(aArray[i] + fArray[i]);
80 if (diff > zeru || (sum > 2. && (2 * diff ) / sum > zeru)) {
83 cout <<
"Failed:[" << i <<
"]\t" << aArray[i] <<
"\t" << fArray[i] <<
"\tdiff\t" << diff << endl;
87 cout <<
"Passed:[" << i <<
"]\t" << aArray[i] <<
"\t" << fArray[i] <<
"\tdiff\t" << diff << endl;
90 cout <<
"Failed " << fails <<
" times" << endl;
95 void TRArray::Print(Option_t *opt)
const {
if (opt) {}; cout << *
this << endl;}
97 void TRArray::AdoptA(Int_t n, Double_t *arr) {
101 if (fArray == arr)
return;
102 if (fArray && ! fIsNotOwn)
delete [] fArray;
107 void TRArray::Set(Int_t n) {
115 memset(&fArray[fN],0,(n-fN)*
sizeof(Double_t));
120 Double_t *temp = fArray;
122 fArray =
new Double_t[n];
123 if (n < fN) memcpy(fArray,temp, n*
sizeof(Double_t));
125 memcpy(fArray,temp,fN*
sizeof(Double_t));
126 memset(&fArray[fN],0,(n-fN)*
sizeof(Double_t));
131 if (fN)
delete [] temp;
136 void TRArray::Set(Int_t n,
const Float_t *array) {
139 if (fArray && fN != n && ! fIsNotOwn) {
145 if (array == 0)
return;
148 fArray =
new Double_t[fN];
150 TCL::ucopy(array,fArray,n);
153 void TRArray::Set(Int_t n,
const Double_t *array) {
156 if (fArray && fN != n && ! fIsNotOwn) {
162 if (array == 0)
return;
165 fArray =
new Double_t[fN];
167 memcpy(fArray,array, n*
sizeof(Double_t));