]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAOD.cxx
Warnings fixed.
[u/mrichter/AliRoot.git] / ANALYSIS / AliAOD.cxx
index 4c620e7b70bd6ff03f9138355444d958cd83334e..18a6a631d52986aeb79499efb40df34f38fb8776 100644 (file)
@@ -1,4 +1,3 @@
-#include "AliAOD.h"
 /**************************************************************************
  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  *                                                                        *
@@ -26,6 +25,8 @@
 #include <TParticle.h>
 #include <TClass.h>
 #include <TString.h>
+
+#include "AliAOD.h"
 #include "AliAODParticle.h"
 #include "AliTrackPoints.h"
 
@@ -46,6 +47,36 @@ AliAOD::AliAOD():
 }
 /**************************************************************************/
 
+AliAOD::AliAOD(const AliAOD& in):
+ TObject(in),
+ fParticles((TClonesArray*)in.fParticles->Clone()),
+  fIsRandomized(in.fIsRandomized),
+  fPrimaryVertexX(fPrimaryVertexX),
+  fPrimaryVertexY(in.fPrimaryVertexY),
+  fPrimaryVertexZ(in.fPrimaryVertexZ),
+  fParticleClass(in.fParticleClass)
+{
+//copy constructor
+}
+/**************************************************************************/
+
+AliAOD& AliAOD::operator=(const AliAOD& in)
+{
+//assigment operator  
+
+  if (this == &in ) return *this;
+  
+  delete fParticles;
+  fParticles = (TClonesArray*)in.fParticles->Clone();
+  fIsRandomized = in.fIsRandomized ;
+  fPrimaryVertexX = in.fPrimaryVertexX ;
+  fPrimaryVertexY = in.fPrimaryVertexY ;
+  fPrimaryVertexZ = in.fPrimaryVertexZ ;
+  fParticleClass = in.fParticleClass ; //althought it is pointer, this points to object in class list of gROOT
+  return *this;
+}
+/**************************************************************************/
+
 AliAOD::~AliAOD()
 {
   //Destructor
@@ -55,6 +86,92 @@ AliAOD::~AliAOD()
 }
 /**************************************************************************/
 
+void AliAOD::CopyData(AliAOD* aod)
+{
+ //Copys all data from aod, but leaves local type of particles
+ if (aod == 0x0) return;
+ if (aod == this) return;
+ AliAOD& in = *this;
+ fIsRandomized = in.fIsRandomized ;
+ fPrimaryVertexX = in.fPrimaryVertexX ;
+ fPrimaryVertexY = in.fPrimaryVertexY ;
+ fPrimaryVertexZ = in.fPrimaryVertexZ ;
+ fParticleClass = in.fParticleClass ; //althought it is pointer, this points to object in class list of gROOT
+
+ if (in.fParticles == 0x0)
+  {//if in obj has null fParticles we delete ours
+    delete fParticles;
+    fParticles = 0x0;
+  }
+ else
+  { 
+    if (fParticles)
+     { //if ours particles were already created
+       if (fParticles->GetClass() != in.fParticles->GetClass())
+        {//if in obj has 
+          delete fParticles;
+          fParticles = (TClonesArray*)in.fParticles->Clone();
+        }
+       else
+        {
+         //it should be faster than cloning
+          Int_t inentr = in.fParticles->GetEntriesFast();
+          Int_t curentr = fParticles->GetEntriesFast();
+
+          TClonesArray& arr = *fParticles;
+
+          //we have to take care about different sizes of arrays
+          if ( curentr < inentr )
+           {
+             for (Int_t i = 0; i < curentr; i++)
+              {
+                TObject& inobj = *(in.fParticles->At(i));
+                TObject& obj = *(fParticles->At(i));
+                obj = inobj;
+              }
+             
+             TClass* partclass = GetParticleClass();
+             if (partclass == 0x0)
+              {
+                Fatal("CopyData","Can not get particle class");
+                return;//pro forma
+              }
+              
+             for (Int_t i = curentr; i < inentr; i++)
+              {
+                TObject& inobj = *(in.fParticles->At(i));
+                TObject& obj =  *((TObject*)(partclass->New(arr[i])));
+                obj = inobj;
+              }
+           }
+          else 
+           {
+             for (Int_t i = 0; i < inentr; i++)
+              {
+                TObject& inobj = *(in.fParticles->At(i));
+                TObject& obj = *(fParticles->At(i));
+                obj = inobj;
+              }
+             
+             for (Int_t i = curentr ; i >= inentr ; i--)
+              {
+                fParticles->RemoveAt(i);
+              }
+           }
+        } 
+     }
+    else
+     {
+       fParticles = (TClonesArray*)in.fParticles->Clone();
+     } 
+  } 
+}
+/**************************************************************************/
+
 void AliAOD::SetParticleClassName(const char* classname)
 {
 //Sets type of particle that is going to be stored 
@@ -91,6 +208,17 @@ void AliAOD::SetParticleClass(TClass* pclass)
      fParticles = new TClonesArray(fParticleClass);
    }
 }
+/**************************************************************************/
+TClass* AliAOD::GetParticleClass()
+{
+//returns TClass of particle class
+  if (fParticleClass) return fParticleClass;
+  
+  if (fParticles == 0x0) return 0x0;
+  
+  fParticleClass = fParticles->GetClass();
+  return fParticleClass;
+}
 
 /**************************************************************************/
 
@@ -117,8 +245,15 @@ void  AliAOD::AddParticle(AliVAODParticle* particle)
 
   Int_t idx = fParticles->GetLast() + 1;
   TClonesArray& arr = *fParticles;
+
+  TClass* partclass = GetParticleClass();
+  if (partclass == 0x0)
+   {
+     Error("AddParticle(AliVAODParticle*)","Can not get particle class");
+     return;
+   }
   
-  AliVAODParticle* pp = (AliVAODParticle*)fParticleClass->New(arr[idx]);
+  AliVAODParticle* pp = (AliVAODParticle*)partclass->New(arr[idx]);
   pp->operator=(*particle);
   
 }
@@ -134,8 +269,15 @@ void  AliAOD::AddParticle(Int_t pdg, Int_t idx,
 
   Int_t newpartidx = fParticles->GetLast() + 1;
   TClonesArray& arr = *fParticles;
-  
-  AliVAODParticle* p =  (AliVAODParticle*)fParticleClass->New(arr[newpartidx]);
+
+  TClass* partclass = GetParticleClass();
+  if (partclass == 0x0)
+   {
+     Error("AddParticle(Int_t,...)","Can not get particle class");
+     return;
+   }
+
+  AliVAODParticle* p =  (AliVAODParticle*)partclass->New(arr[newpartidx]);
   
   p->SetPdgCode(pdg);
   p->SetUID(idx);
@@ -151,7 +293,15 @@ void AliAOD::SwapParticles(Int_t i, Int_t j)
   if ( (i<0) || (i>=GetNumberOfParticles()) ) return;
   if ( (j<0) || (j>=GetNumberOfParticles()) ) return;
   
-  AliVAODParticle* tmpobj = (AliVAODParticle*)fParticleClass->New();
+
+  TClass* partclass = GetParticleClass();
+  if (partclass == 0x0)
+   {
+     Error("SwapParticles","Can not get particle class");
+     return;
+   }
+    
+  AliVAODParticle* tmpobj = (AliVAODParticle*)partclass->New();
   AliVAODParticle& tmp = *tmpobj;
   AliVAODParticle& first = *(GetParticle(i));
   AliVAODParticle& second = *(GetParticle(j));
@@ -227,8 +377,9 @@ void AliAOD::Move(Double_t x, Double_t y, Double_t z)
      if (tp) tp->Move(x,y,z);
    }
 }
+/**************************************************************************/
 
-void AliAOD::Print(Option_t* /*option*/)
+void AliAOD::Print(const Option_t* /*option*/) const
 {
   //Prints AOD
   TString ts;