- AliAnalysisWrapper owns data when put in the output list (PROOF) memory leak (AG)
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 Nov 2007 14:11:13 +0000 (14:11 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 Nov 2007 14:11:13 +0000 (14:11 +0000)
ANALYSIS/AliAnalysisDataContainer.cxx
ANALYSIS/AliAnalysisDataContainer.h
ANALYSIS/AliAnalysisManager.cxx

index 982915b..4dc9932 100644 (file)
@@ -373,12 +373,30 @@ void AliAnalysisDataContainer::ImportData(AliAnalysisDataWrapper *pack)
    if (pack) {
       fData = pack->Data();
       fDataReady = kTRUE;
+      // Imported wrappers do not own data anymore (AG 13-11-07)
+      pack->SetDeleteData(kFALSE);
    }   
 }      
       
 ClassImp (AliAnalysisDataWrapper)
 
 //______________________________________________________________________________
+AliAnalysisDataWrapper::AliAnalysisDataWrapper(TObject *data)
+                       :TNamed(),
+                        fData(data)
+{
+// Ctor.
+   if (data) SetName(data->GetName());
+}
+
+//______________________________________________________________________________
+AliAnalysisDataWrapper::~AliAnalysisDataWrapper()
+{
+// Dtor.
+   if (fData && TObject::TestBit(kDeleteData)) delete fData;
+}   
+
+//______________________________________________________________________________
 AliAnalysisDataWrapper &AliAnalysisDataWrapper::operator=(const AliAnalysisDataWrapper &other)
 {
 // Assignment.
@@ -397,9 +415,9 @@ Long64_t AliAnalysisDataWrapper::Merge(TCollection *list)
    if (!fData) return 0;
    if (!list || list->IsEmpty()) return 1;
 
-   printf("Merging %d data wrappers %s\n", list->GetSize()+1, GetName());
    TMethodCall callEnv;
    if (fData->InheritsFrom(TSeqCollection::Class())) {
+//      printf("Collection wrapper %s 0x%lx (owner=%d) merge with:\n", GetName(), (ULong_t)this, TObject::TestBit(kDeleteData));
       TSeqCollection *coll = (TSeqCollection*)fData;
       if (coll->IsEmpty()) return 0;
       Int_t nentries = coll->GetEntries();
@@ -414,6 +432,7 @@ Long64_t AliAnalysisDataWrapper::Merge(TCollection *list)
          next.Reset();
          // Loop wrappers coming in the 'to merge with' list
          while ((crt=(AliAnalysisDataWrapper*)next())) {
+//            printf("  %s 0x%lx (owner=%d)\n", crt->GetName(), (ULong_t)crt, crt->TestBit(AliAnalysisDataWrapper::kDeleteData));
             collcrt = (TSeqCollection*)crt->Data();
             list1->Add(new AliAnalysisDataWrapper(collcrt->At(i)));
          }
@@ -438,7 +457,9 @@ Long64_t AliAnalysisDataWrapper::Merge(TCollection *list)
    // Make a list where to temporary store the data to be merged.
    TList *collectionData = new TList();
    Int_t count = 0; // object counter
+//   printf("Wrapper %s 0x%lx (owner=%d) merged with:\n", GetName(), (ULong_t)this, TObject::TestBit(kDeleteData));
    while ((cont=(AliAnalysisDataWrapper*)next1())) {
+//      printf("   %s 0x%lx (owner=%d)\n", cont->GetName(), (ULong_t)cont, cont->TestBit(AliAnalysisDataWrapper::kDeleteData));
       TObject *data = cont->Data();
       if (!data) continue;
       collectionData->Add(data);
index 5e2a870..3d3f235 100644 (file)
@@ -105,11 +105,15 @@ protected:
 class AliAnalysisDataWrapper : public TNamed {
 
 public:
+
+enum EAnalysisWrapperFlags {
+   kDeleteData = BIT(14)
+};     
    AliAnalysisDataWrapper() : TNamed(), fData(NULL) {}
-   AliAnalysisDataWrapper(TObject *data) : TNamed(), fData(data) {}
+   AliAnalysisDataWrapper(TObject *data);
    AliAnalysisDataWrapper(const AliAnalysisDataWrapper &other) 
                         : TNamed(other), fData(other.fData) {}
-   virtual ~AliAnalysisDataWrapper() {}
+   virtual ~AliAnalysisDataWrapper();
    
    // Assignment
    AliAnalysisDataWrapper &operator=(const AliAnalysisDataWrapper &other);
@@ -117,6 +121,7 @@ public:
    TObject                  *Data() const {return fData;}
    // Merging
    virtual Long64_t          Merge(TCollection *list);
+   void                      SetDeleteData(Bool_t flag=kTRUE) {TObject::SetBit(kDeleteData,flag);}
 
 protected:
    TObject                  *fData;       // Wrapped data
index 01cdd8d..f75df58 100644 (file)
@@ -334,8 +334,14 @@ void AliAnalysisManager::PackOutput(TList *target)
       TIter next(fOutputs);
       AliAnalysisDataContainer *output;
       while ((output=(AliAnalysisDataContainer*)next())) {
-         if (fDebug > 1) printf("   Packing container %s...\n", output->GetName());
-         if (output->GetData()) target->Add(output->ExportData());
+         if (output->GetData()) {
+            if (output->GetProducer()->IsPostEventLoop()) continue;
+            AliAnalysisDataWrapper *wrap = output->ExportData();
+            // Output wrappers must delete data after merging (AG 13/11/07)
+            wrap->SetDeleteData(kTRUE);
+            if (fDebug > 1) printf("   Packing container %s...\n", output->GetName());
+            target->Add(wrap);
+         }   
       }
    } 
    if (fDebug > 1) {
@@ -355,6 +361,7 @@ void AliAnalysisManager::ImportWrappers(TList *source)
    AliAnalysisDataWrapper   *wrap;
    Int_t icont = 0;
    while ((cont=(AliAnalysisDataContainer*)next())) {
+      if (cont->GetProducer()->IsPostEventLoop()) continue;
       wrap = (AliAnalysisDataWrapper*)source->FindObject(cont->GetName());
       if (!wrap && fDebug>1) {
          printf("(WW) ImportWrappers: container %s not found in analysis output !\n", cont->GetName());