Logo ROOT  
Reference Guide
TFoamVect.cxx
Go to the documentation of this file.
1// @(#)root/foam:$Id$
2// Author: S. Jadach <mailto:Stanislaw.jadach@ifj.edu.pl>, P.Sawicki <mailto:Pawel.Sawicki@ifj.edu.pl>
3
4//_____________________________________________________________________________
5// //
6// Auxiliary class TFoamVect of n-dimensional vector, with dynamic allocation //
7// used for the cartesian geometry of the TFoam cells //
8// //
9//_____________________________________________________________________________
10
11#include "Riostream.h"
12#include "TSystem.h"
13#include "TFoamVect.h"
14
15/** \class TFoamVect
16
17Auxiliary class TFoamVect of n-dimensional vector, with dynamic allocation
18used for the cartesian geometry of the TFoam cells
19
20*/
21
23
24////////////////////////////////////////////////////////////////////////////////
25/// Default constructor for streamer
26
28{
29 fDim =0;
30 fCoords =0;
31}
32
33////////////////////////////////////////////////////////////////////////////////
34/// User constructor creating n-dimensional vector
35/// and allocating dynamically array of components
36
38{
39 Int_t i;
40 fDim=n;
41 fCoords = 0;
42 if (n>0) {
43 fCoords = new Double_t[fDim];
44 if(gDebug) {
45 if(fCoords == 0)
46 Error("TFoamVect", "Constructor failed to allocate\n");
47 }
48 for (i=0; i<n; i++) *(fCoords+i)=0.0;
49 }
50 if(gDebug) Info("TFoamVect", "USER CONSTRUCTOR TFoamVect(const Int_t)\n ");
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Copy constructor
55
57{
58 fDim = Vect.fDim; fCoords = 0;
59 if(fDim > 0) fCoords = new Double_t[fDim];
60
61 if(gDebug) {
62 if(fCoords == 0) {
63 Error("TFoamVect", "Constructor failed to allocate fCoords\n");
64 }
65 }
66
67 for(Int_t i=0; i<fDim; i++)
68 fCoords[i] = Vect.fCoords[i];
69
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Destructor
74
76{
77 if(gDebug) Info("TFoamVect"," DESTRUCTOR TFoamVect~ \n");
78 delete [] fCoords; // free(fCoords)
79 fCoords=0;
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// substitution operator
84
86{
87 Int_t i;
88 if (&Vect == this) return *this;
89 if( Vect.fDim < 0 )
90 Error("TFoamVect","operator= : invalid dimensions : %d and %d \n ",fDim,Vect.fDim);
91 if( fDim != Vect.fDim ) { // cleanup
92 delete [] fCoords;
93 fCoords = new Double_t[Vect.fDim];
94 }
95 fDim=Vect.fDim;
96 for(i=0; i<fDim; i++)
97 fCoords[i] = Vect.fCoords[i];
98 if(gDebug) Info("TFoamVect", "SUBSITUTE operator =\n ");
99 return *this;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// [] is for access to elements as in ordinary matrix like a[j]=b[j]
104/// (Perhaps against some strict rules but rather practical.)
105/// Range protection is built in, consequently for substitution
106/// one should use rather use a=b than explicit loop!
107
109{
110 if ((n<0) || (n>=fDim)) {
111 Error( "TFoamVect","operator[], out of range \n");
112 }
113 return fCoords[n];
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// unary multiplication operator *=
118
120{
121 for(Int_t i=0;i<fDim;i++)
122 fCoords[i] = fCoords[i]*x;
123 return *this;
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// unary addition operator +=; adding vector c*=x,
128
130{
131 if( fDim != Shift.fDim){
132 Error( "TFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
133 }
134 for(Int_t i=0;i<fDim;i++)
135 fCoords[i] = fCoords[i]+Shift.fCoords[i];
136 return *this;
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// unary subtraction operator -=
141
143{
144 if( fDim != Shift.fDim) {
145 Error( "TFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
146 }
147 for(Int_t i=0;i<fDim;i++)
148 fCoords[i] = fCoords[i]-Shift.fCoords[i];
149 return *this;
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// addition operator +; sum of 2 vectors: c=a+b, a=a+b,
154/// NEVER USE IT, VERY SLOW!!!
155
157{
158 TFoamVect temp(fDim);
159 temp = (*this);
160 temp += p2;
161 return temp;
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// subtraction operator -; difference of 2 vectors; c=a-b, a=a-b,
166/// NEVER USE IT, VERY SLOW!!!
167
169{
170 TFoamVect temp(fDim);
171 temp = (*this);
172 temp -= p2;
173 return temp;
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Loading in ordinary double prec. vector, sometimes can be useful
178
180{
181 Int_t i;
182 for(i=0; i<fDim; i++)
183 fCoords[i] = Vect[i];
184 return *this;
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Loading in double prec. number, sometimes can be useful
189
191{
192 if(fCoords != 0) {
193 for(Int_t i=0; i<fDim; i++)
194 fCoords[i] = x;
195 }
196 return *this;
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Printout of all vector components on "std::cout"
201
202void TFoamVect::Print(Option_t *option) const
203{
204 if(!option) Error("Print ", "No option set \n");
205 Int_t i;
206 Int_t pr = std::cout.precision(7);
207 std::cout << "(";
208 for(i=0; i<fDim-1; i++) std::cout << std::setw(12) << *(fCoords+i) << ",";
209 std::cout << std::setw(12) << *(fCoords+fDim-1);
210 std::cout << ")";
211 std::cout.precision(pr);
212}
double Double_t
Definition: RtypesCore.h:57
R__EXTERN Int_t gDebug
Definition: RtypesCore.h:117
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
Auxiliary class TFoamVect of n-dimensional vector, with dynamic allocation used for the cartesian geo...
Definition: TFoamVect.h:10
TFoamVect & operator=(const TFoamVect &)
substitution operator
Definition: TFoamVect.cxx:85
TFoamVect operator+(const TFoamVect &)
addition operator +; sum of 2 vectors: c=a+b, a=a+b, NEVER USE IT, VERY SLOW!!!
Definition: TFoamVect.cxx:156
TFoamVect operator-(const TFoamVect &)
subtraction operator -; difference of 2 vectors; c=a-b, a=a-b, NEVER USE IT, VERY SLOW!...
Definition: TFoamVect.cxx:168
TFoamVect & operator*=(const Double_t &)
unary multiplication operator *=
Definition: TFoamVect.cxx:119
TFoamVect & operator+=(const TFoamVect &)
unary addition operator +=; adding vector c*=x,
Definition: TFoamVect.cxx:129
TFoamVect & operator-=(const TFoamVect &)
unary subtraction operator -=
Definition: TFoamVect.cxx:142
Double_t * fCoords
[fDim] Coordinates
Definition: TFoamVect.h:14
Int_t fDim
Dimension.
Definition: TFoamVect.h:13
TFoamVect()
Default constructor for streamer.
Definition: TFoamVect.cxx:27
Double_t & operator[](Int_t)
[] is for access to elements as in ordinary matrix like a[j]=b[j] (Perhaps against some strict rules ...
Definition: TFoamVect.cxx:108
virtual ~TFoamVect()
Destructor.
Definition: TFoamVect.cxx:75
void Print(Option_t *option) const
Printout of all vector components on "std::cout".
Definition: TFoamVect.cxx:202
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:865
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16