#include "Riostream.h"
#include "TSystem.h"
#include "TFoamVect.h"
#define SW2 setprecision(7) << setw(12)
ClassImp(TFoamVect);
TFoamVect::TFoamVect()
{
fDim =0;
fCoords =0;
fNext =0;
fPrev =0;
}
TFoamVect::TFoamVect(Int_t n)
{
Int_t i;
fNext=0;
fPrev=0;
fDim=n;
fCoords = 0;
if (n>0) {
fCoords = new Double_t[fDim];
if(gDebug) {
if(fCoords == 0)
Error("TFoamVect", "Constructor failed to allocate\n");
}
for (i=0; i<n; i++) *(fCoords+i)=0.0;
}
if(gDebug) Info("TFoamVect", "USER CONSTRUCTOR TFoamVect(const Int_t)\n ");
}
TFoamVect::TFoamVect(const TFoamVect &Vect): TObject(Vect)
{
fNext=0;
fPrev=0;
fDim=Vect.fDim;
fCoords = 0;
if(fDim>0) fCoords = new Double_t[fDim];
if(gDebug) {
if(fCoords == 0) {
Error("TFoamVect", "Constructor failed to allocate fCoords\n");
}
}
for(Int_t i=0; i<fDim; i++)
fCoords[i] = Vect.fCoords[i];
Error("TFoamVect","+++++ NEVER USE Copy constructor !!!!!\n ");
}
TFoamVect::~TFoamVect()
{
if(gDebug) Info("TFoamVect"," DESTRUCTOR TFoamVect~ \n");
delete [] fCoords;
fCoords=0;
}
TFoamVect& TFoamVect::operator =(const TFoamVect& Vect)
{
Int_t i;
if (&Vect == this) return *this;
if( fDim != Vect.fDim )
Error("TFoamVect","operator=Dims. are different: %d and %d \n ",fDim,Vect.fDim);
if( fDim != Vect.fDim ) {
delete [] fCoords;
fCoords = new Double_t[fDim];
}
fDim=Vect.fDim;
for(i=0; i<fDim; i++)
fCoords[i] = Vect.fCoords[i];
fNext=Vect.fNext;
fPrev=Vect.fPrev;
if(gDebug) Info("TFoamVect", "SUBSITUTE operator =\n ");
return *this;
}
Double_t &TFoamVect::operator[](Int_t n)
{
if ((n<0) || (n>=fDim)) {
Error( "TFoamVect","operator[], out of range \n");
}
return fCoords[n];
}
TFoamVect& TFoamVect::operator*=(const Double_t &x)
{
for(Int_t i=0;i<fDim;i++)
fCoords[i] = fCoords[i]*x;
return *this;
}
TFoamVect& TFoamVect::operator+=(const TFoamVect& Shift)
{
if( fDim != Shift.fDim){
Error( "TFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
}
for(Int_t i=0;i<fDim;i++)
fCoords[i] = fCoords[i]+Shift.fCoords[i];
return *this;
}
TFoamVect& TFoamVect::operator-=(const TFoamVect& Shift)
{
if( fDim != Shift.fDim) {
Error( "TFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
}
for(Int_t i=0;i<fDim;i++)
fCoords[i] = fCoords[i]-Shift.fCoords[i];
return *this;
}
TFoamVect TFoamVect::operator+(const TFoamVect &p2)
{
TFoamVect temp(fDim);
temp = (*this);
temp += p2;
return temp;
}
TFoamVect TFoamVect::operator-(const TFoamVect &p2)
{
TFoamVect temp(fDim);
temp = (*this);
temp -= p2;
return temp;
}
TFoamVect& TFoamVect::operator =(Double_t Vect[])
{
Int_t i;
for(i=0; i<fDim; i++)
fCoords[i] = Vect[i];
return *this;
}
TFoamVect& TFoamVect::operator =(Double_t x)
{
if(fCoords != 0) {
for(Int_t i=0; i<fDim; i++)
fCoords[i] = x;
}
return *this;
}
void TFoamVect::Print(Option_t *option) const
{
if(!option) Error("Print ", "No option set \n");
Int_t i;
cout << "(";
for(i=0; i<fDim-1; i++) cout << SW2 << *(fCoords+i) << ",";
cout << SW2 << *(fCoords+fDim-1);
cout << ")";
}
void TFoamVect::PrintList(void)
{
Long_t i=0;
if(this == 0) return;
TFoamVect *current=this;
while(current != 0) {
cout<<"vec["<<i<<"]=";
current->Print("1");
cout<<endl;
current = current->fNext;
i++;
}
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.