00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "Riostream.h"
00012 #include "TSystem.h"
00013 #include "TFoamVect.h"
00014
00015
00016 ClassImp(TFoamVect);
00017
00018
00019 TFoamVect::TFoamVect()
00020 {
00021
00022
00023 fDim =0;
00024 fCoords =0;
00025 fNext =0;
00026 fPrev =0;
00027 }
00028
00029
00030 TFoamVect::TFoamVect(Int_t n)
00031 {
00032
00033
00034
00035 Int_t i;
00036 fNext=0;
00037 fPrev=0;
00038 fDim=n;
00039 fCoords = 0;
00040 if (n>0) {
00041 fCoords = new Double_t[fDim];
00042 if(gDebug) {
00043 if(fCoords == 0)
00044 Error("TFoamVect", "Constructor failed to allocate\n");
00045 }
00046 for (i=0; i<n; i++) *(fCoords+i)=0.0;
00047 }
00048 if(gDebug) Info("TFoamVect", "USER CONSTRUCTOR TFoamVect(const Int_t)\n ");
00049 }
00050
00051
00052 TFoamVect::TFoamVect(const TFoamVect &Vect): TObject(Vect)
00053 {
00054
00055
00056 fNext=0;
00057 fPrev=0;
00058 fDim=Vect.fDim;
00059 fCoords = 0;
00060 if(fDim>0) fCoords = new Double_t[fDim];
00061 if(gDebug) {
00062 if(fCoords == 0) {
00063 Error("TFoamVect", "Constructor failed to allocate fCoords\n");
00064 }
00065 }
00066 for(Int_t i=0; i<fDim; i++)
00067 fCoords[i] = Vect.fCoords[i];
00068 Error("TFoamVect","+++++ NEVER USE Copy constructor !!!!!\n ");
00069 }
00070
00071
00072 TFoamVect::~TFoamVect()
00073 {
00074
00075 if(gDebug) Info("TFoamVect"," DESTRUCTOR TFoamVect~ \n");
00076 delete [] fCoords;
00077 fCoords=0;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 TFoamVect& TFoamVect::operator =(const TFoamVect& Vect)
00087 {
00088
00089
00090 Int_t i;
00091 if (&Vect == this) return *this;
00092 if( fDim != Vect.fDim )
00093 Error("TFoamVect","operator=Dims. are different: %d and %d \n ",fDim,Vect.fDim);
00094 if( fDim != Vect.fDim ) {
00095 delete [] fCoords;
00096 fCoords = new Double_t[fDim];
00097 }
00098 fDim=Vect.fDim;
00099 for(i=0; i<fDim; i++)
00100 fCoords[i] = Vect.fCoords[i];
00101 fNext=Vect.fNext;
00102 fPrev=Vect.fPrev;
00103 if(gDebug) Info("TFoamVect", "SUBSITUTE operator =\n ");
00104 return *this;
00105 }
00106
00107
00108 Double_t &TFoamVect::operator[](Int_t n)
00109 {
00110
00111
00112
00113
00114
00115 if ((n<0) || (n>=fDim)) {
00116 Error( "TFoamVect","operator[], out of range \n");
00117 }
00118 return fCoords[n];
00119 }
00120
00121
00122 TFoamVect& TFoamVect::operator*=(const Double_t &x)
00123 {
00124
00125
00126 for(Int_t i=0;i<fDim;i++)
00127 fCoords[i] = fCoords[i]*x;
00128 return *this;
00129 }
00130
00131
00132 TFoamVect& TFoamVect::operator+=(const TFoamVect& Shift)
00133 {
00134
00135 if( fDim != Shift.fDim){
00136 Error( "TFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
00137 }
00138 for(Int_t i=0;i<fDim;i++)
00139 fCoords[i] = fCoords[i]+Shift.fCoords[i];
00140 return *this;
00141 }
00142
00143
00144 TFoamVect& TFoamVect::operator-=(const TFoamVect& Shift)
00145 {
00146
00147 if( fDim != Shift.fDim) {
00148 Error( "TFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
00149 }
00150 for(Int_t i=0;i<fDim;i++)
00151 fCoords[i] = fCoords[i]-Shift.fCoords[i];
00152 return *this;
00153 }
00154
00155
00156 TFoamVect TFoamVect::operator+(const TFoamVect &p2)
00157 {
00158
00159
00160 TFoamVect temp(fDim);
00161 temp = (*this);
00162 temp += p2;
00163 return temp;
00164 }
00165
00166
00167 TFoamVect TFoamVect::operator-(const TFoamVect &p2)
00168 {
00169
00170
00171 TFoamVect temp(fDim);
00172 temp = (*this);
00173 temp -= p2;
00174 return temp;
00175 }
00176
00177
00178 TFoamVect& TFoamVect::operator =(Double_t Vect[])
00179 {
00180
00181 Int_t i;
00182 for(i=0; i<fDim; i++)
00183 fCoords[i] = Vect[i];
00184 return *this;
00185 }
00186
00187
00188 TFoamVect& TFoamVect::operator =(Double_t x)
00189 {
00190
00191 if(fCoords != 0) {
00192 for(Int_t i=0; i<fDim; i++)
00193 fCoords[i] = x;
00194 }
00195 return *this;
00196 }
00197
00198
00199
00200
00201
00202 void TFoamVect::Print(Option_t *option) const
00203 {
00204
00205 if(!option) Error("Print ", "No option set \n");
00206 Int_t i;
00207 Int_t pr = cout.precision(7);
00208 cout << "(";
00209 for(i=0; i<fDim-1; i++) cout << setw(12) << *(fCoords+i) << ",";
00210 cout << setw(12) << *(fCoords+fDim-1);
00211 cout << ")";
00212 cout.precision(pr);
00213 }
00214
00215 void TFoamVect::PrintList(void)
00216 {
00217
00218 Long_t i=0;
00219 if(this == 0) return;
00220 TFoamVect *current=this;
00221 while(current != 0) {
00222 cout<<"vec["<<i<<"]=";
00223 current->Print("1");
00224 cout<<endl;
00225 current = current->fNext;
00226 i++;
00227 }
00228 }
00229
00230
00231
00232