]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisDataContainer.cxx
- Bug fix in AliAnalysisDataWrapper::Merge(). Merging failed on PROOF in case of...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisDataContainer.cxx
index eb69661268fcac21b7bfa99947ffa6ca27f87936..982915b2507f764b3d25a08957c1d9bc5a22d106 100644 (file)
@@ -229,12 +229,12 @@ Long64_t AliAnalysisDataContainer::Merge(TCollection *list)
    if (!callEnv.IsValid() && !list->IsEmpty()) {
       cout << "No merge interface for data stored by " << GetName() << ". Merging not possible !" << endl;
       return 1;
-   }   
-   
+   }
+
    if (list->IsEmpty()) return 1;
 
    TIter next(list);
-   AliAnalysisDataContainer *cont;   
+   AliAnalysisDataContainer *cont;
    // Make a list where to temporary store the data to be merged.
    TList *collectionData = new TList();
    Int_t count = 0; // object counter
@@ -248,12 +248,12 @@ Long64_t AliAnalysisDataContainer::Merge(TCollection *list)
       printf(" ... merging object %s\n", data->GetName());
       collectionData->Add(data);
       count++;
-   }   
+   }
    callEnv.SetParam((Long_t) collectionData);
    callEnv.Execute(fData);
    delete collectionData;
-   
-   return count+1;   
+
+   return count+1;
 }
 
 //______________________________________________________________________________
@@ -266,7 +266,7 @@ void AliAnalysisDataContainer::PrintContainer(Option_t *option, Int_t indent) co
    opt.ToLower();
    Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
    if (!dep) {
-      printf("%sContainer: %s  type: %s", ind.Data(), GetName(), GetTitle());
+      printf("%sContainer: %s  type: %s POST_LOOP=%i", ind.Data(), GetName(), GetTitle(), IsPostEventLoop());
       if (fProducer) 
          printf("%s = Data producer: task %s",ind.Data(),fProducer->GetName());
       else
@@ -274,7 +274,8 @@ void AliAnalysisDataContainer::PrintContainer(Option_t *option, Int_t indent) co
       printf("%s = Consumer tasks: ", ind.Data());
       if (!fConsumers || !fConsumers->GetEntriesFast()) printf("-none-\n");
       else printf("\n");
-   }   
+   }
+   printf("Filename: %s\n", fFileName.Data());
    TIter next(fConsumers);
    AliAnalysisTask *task;
    while ((task=(AliAnalysisTask*)next())) task->PrintTask(option, indent+3);
@@ -300,7 +301,7 @@ Bool_t AliAnalysisDataContainer::SetData(TObject *data, Option_t *)
          }
       }      
       return kTRUE;
-   } 
+   }
    // Check if it is the producer who published the data     
    if (fProducer->GetPublishedData()==data) {
       fData = data;
@@ -353,4 +354,99 @@ void AliAnalysisDataContainer::SetProducer(AliAnalysisTask *prod, Int_t islot)
       if (!prod->GetListOfTasks()->FindObject(cons)) prod->Add(cons);
    }   
 }   
+
+//______________________________________________________________________________
+AliAnalysisDataWrapper *AliAnalysisDataContainer::ExportData() const
+{
+// Wraps data for sending it through the net.
+   AliAnalysisDataWrapper *pack = 0;
+   if (!fData) return pack;
+   pack = new AliAnalysisDataWrapper(fData);
+   pack->SetName(fName.Data());
+   return pack;
+}
+
+//______________________________________________________________________________
+void AliAnalysisDataContainer::ImportData(AliAnalysisDataWrapper *pack)
+{
+// Unwraps data from a data wrapper.
+   if (pack) {
+      fData = pack->Data();
+      fDataReady = kTRUE;
+   }   
+}      
       
+ClassImp (AliAnalysisDataWrapper)
+
+//______________________________________________________________________________
+AliAnalysisDataWrapper &AliAnalysisDataWrapper::operator=(const AliAnalysisDataWrapper &other)
+{
+// Assignment.
+   if (&other != this) {
+      TNamed::operator=(other);
+      fData = other.fData;
+   }   
+   return *this;
+}
+
+//______________________________________________________________________________
+Long64_t AliAnalysisDataWrapper::Merge(TCollection *list)
+{
+// Merge a list of containers with this one. Containers in the list must have
+// data of the same type.
+   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())) {
+      TSeqCollection *coll = (TSeqCollection*)fData;
+      if (coll->IsEmpty()) return 0;
+      Int_t nentries = coll->GetEntries();
+      AliAnalysisDataWrapper *top, *crt;
+      TIter next(list);
+      TSeqCollection *collcrt = 0;
+      TList *list1 = 0;
+      // Loop entries of the collection attached to this wrapper.
+      for (Int_t i=0; i<nentries; i++) {
+         list1 = new TList();
+         top = new AliAnalysisDataWrapper(coll->At(i));
+         next.Reset();
+         // Loop wrappers coming in the 'to merge with' list
+         while ((crt=(AliAnalysisDataWrapper*)next())) {
+            collcrt = (TSeqCollection*)crt->Data();
+            list1->Add(new AliAnalysisDataWrapper(collcrt->At(i)));
+         }
+         // Now merge 'top' wrapper with 'list1'. This may go recursively.
+         top->Merge(list1);
+         delete top;
+         list1->Delete();
+         delete list1;
+      }
+      return nentries;
+   }   
+   
+   if (fData->IsA())
+      callEnv.InitWithPrototype(fData->IsA(), "Merge", "TCollection*");
+   if (!callEnv.IsValid()) {
+      cout << "No merge interface for data stored by " << GetName() << ". Merging not possible !" << endl;
+      return 1;
+   }
+
+   TIter next1(list);
+   AliAnalysisDataWrapper *cont;
+   // Make a list where to temporary store the data to be merged.
+   TList *collectionData = new TList();
+   Int_t count = 0; // object counter
+   while ((cont=(AliAnalysisDataWrapper*)next1())) {
+      TObject *data = cont->Data();
+      if (!data) continue;
+      collectionData->Add(data);
+      count++;
+   }
+   callEnv.SetParam((Long_t) collectionData);
+   callEnv.Execute(fData);
+   delete collectionData;
+
+   return count+1;
+}