]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODEvent.cxx
Adding to ESD the primary vertex reconstructed with TPC stand-alone
[u/mrichter/AliRoot.git] / STEER / AliAODEvent.cxx
index cd03bf9fa472cc8fc3974a386250f994156a422a..2518e7be4366deedecd03d1897bd4c783051047b 100644 (file)
@@ -35,7 +35,8 @@ ClassImp(AliAODEvent)
                                                      "v0s",
                                                      "tracklets",
                                                      "jets",
-                                                     "caloCells",
+                                                     "emcalCells",
+                                                     "phosCells",
                                                      "caloClusters",
                                                      "fmdClusters",
                                                      "pmdClusters"
@@ -50,7 +51,8 @@ AliAODEvent::AliAODEvent() :
   fV0s(0),
   fTracklets(0),
   fJets(0),
-  fCaloCells(0),
+  fEmcalCells(0),
+  fPhosCells(0),
   fCaloClusters(0),
   fFmdClusters(0),
   fPmdClusters(0)
@@ -68,13 +70,21 @@ AliAODEvent::~AliAODEvent()
 //______________________________________________________________________________
 void AliAODEvent::AddObject(TObject* obj) 
 {
-  // Add an object to the list of object.
+  // Add an object to the list of objects.
   // Please be aware that in order to increase performance you should
   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
   
   fAODObjects->AddLast(obj);
 }
 
+//______________________________________________________________________________
+void AliAODEvent::RemoveObject(TObject* obj) 
+{
+  // Removes an object from the list of objects.
+  
+  fAODObjects->Remove(obj);
+}
+
 //______________________________________________________________________________
 TObject *AliAODEvent::FindListObject(const char *objName)
 {
@@ -96,10 +106,10 @@ void AliAODEvent::CreateStdContent()
   AddObject(new AliAODTracklets());
   AddObject(new TClonesArray("AliAODJet", 0));
   AddObject(new AliAODCaloCells());
+  AddObject(new AliAODCaloCells());
   AddObject(new TClonesArray("AliAODCaloCluster", 0));
   AddObject(new TClonesArray("AliAODFmdCluster", 0));
   AddObject(new TClonesArray("AliAODPmdCluster", 0));
-  
   // set names
   SetStdNames();
 
@@ -141,7 +151,8 @@ void AliAODEvent::GetStdContent()
   fV0s           = (TClonesArray*)fAODObjects->FindObject("v0s");
   fTracklets     = (AliAODTracklets*)fAODObjects->FindObject("tracklets");
   fJets          = (TClonesArray*)fAODObjects->FindObject("jets");
-  fCaloCells     = (AliAODCaloCells*)fAODObjects->FindObject("caloCells");
+  fEmcalCells    = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells");
+  fPhosCells     = (AliAODCaloCells*)fAODObjects->FindObject("phosCells");
   fCaloClusters  = (TClonesArray*)fAODObjects->FindObject("caloClusters");
   fFmdClusters   = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
   fPmdClusters   = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
@@ -185,6 +196,12 @@ void AliAODEvent::ResetStd(Int_t trkArrSize,
   fPmdClusters->Delete();
   if (pmdClusSize > fPmdClusters->GetSize()) 
     fPmdClusters->Expand(pmdClusSize);
+
+  // Reset the tracklets
+  fTracklets->DeleteContainer();
+  fPhosCells->DeleteContainer();  
+  fEmcalCells->DeleteContainer();
+
 }
 
 void AliAODEvent::ClearStd()
@@ -194,11 +211,12 @@ void AliAODEvent::ClearStd()
   fVertices      ->Clear();
   fV0s           ->Clear();
   fTracklets     ->DeleteContainer();
-  fJets          ->Clear();
-  fCaloCells     ->DeleteContainer();
-  fCaloClusters ->Clear();
-  fFmdClusters  ->Clear();
-  fPmdClusters  ->Clear();
+  fJets          ->Delete();
+  fEmcalCells    ->DeleteContainer();
+  fPhosCells     ->DeleteContainer();
+  fCaloClusters  ->Clear();
+  fFmdClusters   ->Clear();
+  fPmdClusters   ->Clear();
 }
 
 //______________________________________________________________________________
@@ -223,17 +241,84 @@ void AliAODEvent::ReadFromTree(TTree *tree)
 {
   // connects aod event to tree
   
+  if(!tree){
+    Printf("%s %d AliAODEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
+    return;
+  }
   // load the TTree
-  tree->LoadTree(0);
-
-  fAODObjects = (TList*)((AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent"))->GetList(); 
-  TIter next(fAODObjects);
-  TNamed *el;
-  while((el=(TNamed*)next())){
-    TString bname(el->GetName());
-    tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
+  if(!tree->GetTree())tree->LoadTree(0);
+
+  // Try to find AliAODEvent
+  AliAODEvent *aodEvent = 0;
+  aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
+  if(aodEvent){
+    // Check if already connected to tree
+    TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
+    if (connectedList) {
+      // If connected use the connected list if objects
+      fAODObjects->Delete();
+      fAODObjects = connectedList;
+      GetStdContent(); 
+      return;
+    }
+    // Connect to tree
+    // prevent a memory leak when reading back the TList
+    delete fAODObjects;
+    fAODObjects = 0;
+    // create a new TList from the UserInfo TList... 
+    // copy constructor does not work...
+    fAODObjects = (TList*)(aodEvent->GetList()->Clone());
+    fAODObjects->SetOwner(kFALSE);
+    if(fAODObjects->GetEntries()<kAODListN){
+      printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
+            (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN);
+    }
+    // set the branch addresses
+    TIter next(fAODObjects);
+    TNamed *el;
+    while((el=(TNamed*)next())){
+      TString bname(el->GetName());
+      // check if branch exists under this Name
+      TBranch *br = tree->GetBranch(bname.Data());
+      if(br){
+       tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
+      }
+      else{
+       br = tree->GetBranch(Form("%s.",bname.Data()));
+       if(br){
+         tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
+       }
+       else{
+         printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s or %s. \n",
+                (char*)__FILE__,__LINE__,bname.Data(),bname.Data());
+       }       
+      }
+    }
+    
+    GetStdContent();
+    // when reading back we are not owner of the list 
+    // must not delete it
+    fAODObjects->SetOwner(kFALSE);
+    fAODObjects->SetName("AODObjectsConnectedToTree");
+    // we are not owner of the list objects 
+    // must not delete it
+    tree->GetUserInfo()->Add(fAODObjects);
+  }// no aodEvent
+  else {
+    // we can't get the list from the user data, create standard content
+    // and set it by hand
+    CreateStdContent();
+    TIter next(fAODObjects);
+    TNamed *el;
+    while((el=(TNamed*)next())){
+      TString bname(el->GetName());    
+      tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
+    }
+    GetStdContent();
+    // when reading back we are not owner of the list 
+    // must not delete it
+    fAODObjects->SetOwner(kFALSE);
   }
-  GetStdContent();
 }
 
 //______________________________________________________________________________