Fixes for some mem-leaks: most changes where pretty basic (i.e. adding deletes).
[u/mrichter/AliRoot.git] / STEER / AliVertex.cxx
index 8584bc3f7133d061b1a36fb298a895b11027f172..593ff60ed91b00afe804f022920b79a6bde2c0f8 100644 (file)
 ClassImp(AliVertex)
 
 //--------------------------------------------------------------------------
-AliVertex::AliVertex() : TNamed() {
+AliVertex::AliVertex() :
+  TNamed(),
+  fSigma(0),
+  fNContributors(0),
+  fNIndices(0)
+{
 //
 // Default Constructor, set everything to 0
 //
   for(Int_t k=0;k<3;k++) fPosition[k]   = 0;
-  fSigma = 0;
-  fNContributors=0;
+  fIndices = 0;
 }
 
 //--------------------------------------------------------------------------
 AliVertex::AliVertex(Double_t position[3],Double_t dispersion,
-               Int_t nContributors): TNamed() {
+                    Int_t nContributors):
+  TNamed(),
+  fSigma(dispersion),
+  fNContributors(nContributors),
+  fNIndices(0)
+{
   //
   // Standard Constructor
   //
 
   for(Int_t k=0;k<3;k++) fPosition[k]   = position[k];
-  fSigma         = dispersion;
-  fNContributors = nContributors;
+  fIndices = 0;
   SetName("BaseVertex");
 
 }
 
+//--------------------------------------------------------------------------
+AliVertex::AliVertex(const AliVertex &source):
+  TNamed(source),
+  fSigma(source.GetDispersion()),
+  fNContributors(source.GetNContributors()),
+  fNIndices(source.GetNIndices()),
+  fIndices(0x0)
+{
+  //
+  // Copy constructor
+  //
+  for(Int_t i=0;i<3;i++)fPosition[i] = source.fPosition[i];
+  if(source.fNIndices>0) {
+    fIndices = new UShort_t[fNIndices];
+    memcpy(fIndices,source.fIndices,fNIndices*sizeof(UShort_t));
+  }
+}
+
+//--------------------------------------------------------------------------
+AliVertex &AliVertex::operator=(const AliVertex &source){
+  //
+  // assignment operator
+  //
+  if(&source != this){
+    TNamed::operator=(source);
+    for(Int_t i=0;i<3;i++)fPosition[i] = source.fPosition[i];
+    fSigma = source.GetDispersion();
+    fNContributors = source.GetNContributors();
+    fNIndices = source.GetNIndices();
+    if(fIndices)delete [] fIndices;
+    fIndices = 0;
+    if(fNIndices>0) {
+      fIndices = new UShort_t[fNIndices];
+      memcpy(fIndices,source.fIndices,fNIndices*sizeof(UShort_t));
+    }
+  }
+  return *this;
+}
+
 
 //--------------------------------------------------------------------------
 AliVertex::~AliVertex() {
 //  
 // Default Destructor
 //
-
+  delete [] fIndices;
+  fIndices = 0;
 }
 //--------------------------------------------------------------------------
 void AliVertex::GetXYZ(Double_t position[3]) const {
@@ -70,6 +118,29 @@ void AliVertex::GetXYZ(Double_t position[3]) const {
   return;
 }
 //--------------------------------------------------------------------------
+void AliVertex::SetIndices(Int_t nindices,UShort_t *indices) {
+//
+// Set indices of tracks used for vertex determination 
+//
+  if(fNContributors<1)  { printf("fNContributors<1"); return; }
+  fNIndices = nindices;
+  delete [] fIndices;
+  fIndices = new UShort_t[fNIndices];
+  for(Int_t i=0;i<fNIndices;i++) fIndices[i] = indices[i]; 
+  return;
+}
+//--------------------------------------------------------------------------
+Bool_t AliVertex::UsesTrack(Int_t index) const {
+//
+// checks if a track is used for the vertex 
+//
+  if(fNIndices<1)  { printf("fNIndices<1"); return kFALSE; }
+  for(Int_t i=0;i<fNIndices;i++) {
+    if((Int_t)fIndices[i]==index) return kTRUE;
+  }
+  return kFALSE;
+}
+//--------------------------------------------------------------------------
 void AliVertex::Print(Option_t* /*option*/) const {
 //
 // Print out information on all data members