]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
AliAODEvent: corrected copy constructor and assignment operator. This do not work...
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 26 Nov 2009 16:48:16 +0000 (16:48 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 26 Nov 2009 16:48:16 +0000 (16:48 +0000)
AliAODHandler: corrected destructors taking into account that ownership to AOD event and tree is lost after file closing. Corrections in the extensions to AOD's
AddTaskESDFilter.C : Added creation of the muon AOD as parameter of the macro.
AliAnalysisManager : Disabled object stats registration during the analysis manager session.

ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/macros/AddTaskESDFilter.C
STEER/AliAODEvent.cxx
STEER/AliAODHandler.cxx

index cdccc6739a951c6a6c28b517d42548aeb4b3cacd..9f790ce6912e7176722dc2d30451d7949a5f73ba 100644 (file)
@@ -89,6 +89,7 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
    fInputs     = new TObjArray();
    fOutputs    = new TObjArray();
    SetEventLoop(kTRUE);
+   TObject::SetObjectStat(kFALSE);
 }
 
 //______________________________________________________________________________
@@ -126,6 +127,7 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
    fOutputs    = new TObjArray(*other.fOutputs);
    fgCommonFileName  = "AnalysisResults.root";
    fgAnalysisManager = this;
+   TObject::SetObjectStat(kFALSE);
 }
    
 //______________________________________________________________________________
@@ -173,6 +175,7 @@ AliAnalysisManager::~AliAnalysisManager()
    if (fOutputs) delete fOutputs;
    if (fGridHandler) delete fGridHandler;
    if (fgAnalysisManager==this) fgAnalysisManager = NULL;
+   TObject::SetObjectStat(kTRUE);
 }
 
 //______________________________________________________________________________
index 63270276c60997d2bc931ce6fac31719b8f29665..dc23f323096aed8c1621375601284c2f93aa49cd 100644 (file)
@@ -1,4 +1,4 @@
-AliAnalysisTaskESDfilter *AddTaskESDFilter(Bool_t useKineFilter=kTRUE)
+AliAnalysisTaskESDfilter *AddTaskESDFilter(Bool_t useKineFilter=kTRUE, Bool_t writeMuonAOD=kFALSE)
 {
 // Creates a filter task and adds it to the analysis manager.
 
@@ -122,7 +122,7 @@ AliAnalysisTaskESDfilter *AddTaskESDFilter(Bool_t useKineFilter=kTRUE)
    esdfilter->SetV0Filter(v0Filter);
 
    // Enable writing of Muon AODs
-   esdmuonfilter->SetWriteMuonAOD(kFALSE);
+   esdmuonfilter->SetWriteMuonAOD(writeMuonAOD);
  
    // Create ONLY the output containers for the data produced by the task.
    // Get and connect other common input/output containers via the manager as below
index c4dcabcc880ed6d75903c1b2c6e1475455ddc499..d0d14978d215ecf7b3075bddf7544cb160a289e1 100644 (file)
@@ -104,6 +104,7 @@ AliAODEvent::AliAODEvent(const AliAODEvent& aod):
   AddObject(fPmdClusters);
   fConnected = aod.fConnected;
   GetStdContent();
+  CreateStdFolders();
 }
 
 //______________________________________________________________________________
@@ -111,40 +112,94 @@ AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) {
 
     // Assignment operator
 
-    if(&aod == this) return *this;
-    AliVEvent::operator=(aod);
-
-    fAODObjects      = new TList();
-    fAODFolder       = new TFolder();
-    fConnected       = aod.fConnected;
-    fHeader          = new AliAODHeader(*aod.fHeader);
-    fTracks          = new TClonesArray(*aod.fTracks);
-    fVertices        = new TClonesArray(*aod.fVertices);
-    fV0s             = new TClonesArray(*aod.fV0s);
-    fCascades        = new TClonesArray(*aod.fCascades);
-    fTracklets       = new AliAODTracklets(*aod.fTracklets);
-    fJets            = new TClonesArray(*aod.fJets);
-    fEmcalCells      = new AliAODCaloCells(*aod.fEmcalCells);
-    fPhosCells       = new AliAODCaloCells(*aod.fPhosCells);
-    fCaloClusters    = new TClonesArray(*aod.fCaloClusters);
-    fFmdClusters     = new TClonesArray(*aod.fFmdClusters);
-    fPmdClusters     = new TClonesArray(*aod.fPmdClusters);
-    
-    
-    AddObject(fHeader);
-    AddObject(fTracks);
-    AddObject(fVertices);
-    AddObject(fV0s);
-    AddObject(fCascades);
-    AddObject(fTracklets);
-    AddObject(fJets);
-    AddObject(fEmcalCells);
-    AddObject(fPhosCells);
-    AddObject(fCaloClusters);
-    AddObject(fFmdClusters);
-    AddObject(fPmdClusters);
-    GetStdContent();
-    return *this;
+  if(&aod == this) return *this;
+  AliVEvent::operator=(aod);
+
+  // This assumes that the list is already created
+  // and that the virtual void Copy(Tobject&) function
+  // is correctly implemented in the derived class
+  // otherwise only TObject::Copy() will be used
+
+  if((fAODObjects->GetSize()==0)&&(aod.fAODObjects->GetSize()>=kAODListN)){
+    // We cover the case that we do not yet have the 
+    // standard content but the source has it
+    CreateStdContent();
+  }
+  
+  // Here we have the standard content without user additions, but the content is 
+  // not matching the aod source.
+  
+  // Iterate the list of source objects
+  TIter next(aod.GetList());
+  TObject *its = 0;
+  TString name;
+  while ((its = next())) {
+    name = its->GetName();
+    // Check if we have this object type in out list
+    TObject *mine = fAODObjects->FindObject(name);    
+    if(!mine) {
+      // We have to create the same type of object.
+      TClass* pClass=TClass::GetClass(its->ClassName());     
+      if (!pClass) {
+        AliWarning(Form("Can not find class description for entry %s (%s)\n",
+                   its->ClassName(), name.Data()));
+        continue;
+      }
+      mine=(TObject*)pClass->New();
+      if(!mine){
+        // not in this: can be added to list
+        AliWarning(Form("%s:%d Could not find %s for copying \n",
+                   (char*)__FILE__,__LINE__,name.Data()));
+        continue;
+      }  
+      if(mine->InheritsFrom("TNamed")) {
+        ((TNamed*)mine)->SetName(name);
+      } else if(mine->InheritsFrom("TCollection")){
+        if(mine->InheritsFrom("TClonesArray")) {
+          TClonesArray *itscl = dynamic_cast<TClonesArray*>(its);
+          if (!itscl) {
+            AliWarning(Form("Class description for entry %s (%s) not TClonesArray\n",
+                   its->ClassName(), name.Data()));
+            continue;
+          
+          }
+              dynamic_cast<TClonesArray*>(mine)->SetClass(itscl->GetClass(), itscl->GetSize());
+        }
+        dynamic_cast<TCollection*>(mine)->SetName(name);
+      }
+      AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
+      AddObject(mine);
+    }
+    // Now we have an object of the same type and name, but different content.        
+    if(!its->InheritsFrom("TCollection")){
+      // simple objects (do they have a Copy method that calls operator= ?)
+      its->Copy(*mine);
+    } else if (its->InheritsFrom("TClonesArray")) {
+      // Create or expand the tclonesarray pointers
+      // so we can directly copy to the object
+      TClonesArray *its_tca = (TClonesArray*)its;
+      TClonesArray *mine_tca = (TClonesArray*)mine;
+      // this leaves the capacity of the TClonesArray the same
+      // except for a factor of 2 increase when size > capacity
+      // does not release any memory occupied by the tca
+      Int_t its_entries = its_tca->GetEntriesFast();
+      mine_tca->ExpandCreate(its_entries);
+      for(int i=0; i<its_entries; i++){
+        // copy 
+        TObject *mine_tca_obj = mine_tca->At(i);
+        TObject *its_tca_obj = its_tca->At(i);
+        // no need to delete first
+        // pointers within the class should be handled by Copy()...
+        // Can there be Empty slots?
+        its_tca_obj->Copy(*mine_tca_obj);
+      }
+    } else {
+      AliWarning(Form("%s:%d cannot copy TCollection \n",
+                     (char*)__FILE__,__LINE__));
+    }
+  }  
+  fConnected = aod.fConnected;
+  return *this;
 }
 
 
index ffc4524bd726729b5ab8694b626df14919043e81..002dd95edd5e9c3f6593cd21aef2fbf8c286389d 100644 (file)
@@ -105,15 +105,16 @@ AliAODHandler::AliAODHandler(const char* name, const char* title):
 AliAODHandler::~AliAODHandler() 
 {
  // Destructor.
-  delete fAODEvent;
+  if (fAODEvent) delete fAODEvent;
   if(fFileA){
     // is already handled in TerminateIO
     fFileA->Close();
     delete fFileA;
+    fTreeA = 0;
   }
-  delete fTreeA;
-  if (fExtensions) delete fExtensions;
-  if (fFilters)    delete fFilters;
+  if (fTreeA) delete fTreeA;
+  if (fExtensions) {fExtensions->Delete(); delete fExtensions;}
+  if (fFilters)    {fFilters->Delete();    delete fFilters;}
 }
 
 //______________________________________________________________________________
@@ -394,7 +395,10 @@ Bool_t AliAODHandler::FinishEvent()
     if (fFilters) {   
       TIter nextf(fFilters);
       AliAODExtension *ext;
-      while ((ext=(AliAODExtension*)nextf())) ext->FinishEvent();
+      while ((ext=(AliAODExtension*)nextf())) {
+//        ext->SetEvent(fAODEvent);
+        ext->FinishEvent();
+      }  
     }       
   }
   if (fIsStandard) fAODEvent->ResetStd();
@@ -424,6 +428,8 @@ Bool_t AliAODHandler::TerminateIO()
     fFileA->Close();
     delete fFileA;
     fFileA = 0;
+    // When closing the file, the tree is also deleted.
+    fTreeA = 0;
   }
   if (fExtensions) {
     TIter next(fExtensions);
@@ -459,6 +465,8 @@ void AliAODHandler::AddAODtoTreeUserInfo()
 {
   // Add aod event to tree user info
   fTreeA->GetUserInfo()->Add(fAODEvent);
+  // Now the tree owns our fAODEvent...
+  fAODEvent = 0;
 }
 
 //______________________________________________________________________________
@@ -614,20 +622,24 @@ AliAODExtension::AliAODExtension(const char* name, const char* title, Bool_t isf
                  fSelected(kFALSE)
 {
 // Constructor.
-   if (isfilter) TObject::SetBit(kFilteredAOD);
+  if (isfilter) {
+    TObject::SetBit(kFilteredAOD);
+    printf("####### Added AOD filter %s\n", name);
+  } else printf("####### Added AOD extension %s\n", name);
 }   
 
 //______________________________________________________________________________
 AliAODExtension::~AliAODExtension()
 {
 // Destructor.
-  if (!IsFilteredAOD()) delete fAODEvent;
   if(fFileE){
     // is already handled in TerminateIO
     fFileE->Close();
     delete fFileE;
+    fTreeE = 0;
+    fAODEvent = 0;
   }
-  delete fTreeE;
+  if (fTreeE) delete fTreeE;
 }
 
 //______________________________________________________________________________
@@ -678,7 +690,6 @@ Bool_t AliAODExtension::FinishEvent()
   }  
   // Filtered AOD. Fill only if event is selected.
   if (!fSelected) return kTRUE;
-  printf("SELECTED EVENT\n");
   fNpassed++;
   fTreeE->Fill();
   fSelected = kFALSE; // so that next event will not be selected unless demanded
@@ -715,6 +726,10 @@ void AliAODExtension::SetEvent(AliAODEvent *event)
       Error("SetEvent", "Not allowed to set external event for filtered AOD's");   
       return;
    }
+   // Use the copy constructor or assignment operator to synchronize with external event.
+//   AliAODEvent &other = *event;
+//   if (!fAODEvent)     fAODEvent = new AliAODEvent(other);
+//   else if (fSelected) *fAODEvent = other;
    fAODEvent = event;
 }
    
@@ -722,11 +737,17 @@ void AliAODExtension::SetEvent(AliAODEvent *event)
 Bool_t AliAODExtension::TerminateIO()
 {
   // Terminate IO
+  if (TObject::TestBit(kFilteredAOD))
+    printf("AOD Filter %s: events processed: %d   passed: %d\n", GetName(), fNtotal, fNpassed);
+  else
+    printf("AOD extension %s: events processed: %d\n", GetName(), fNtotal);
   if (fFileE) {
     fFileE->Write();
     fFileE->Close();
     delete fFileE;
     fFileE = 0;
+    fTreeE = 0;
+    fAODEvent = 0;
   }
   return kTRUE;
 }