]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTask.cxx
Coverity 18807
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTask.cxx
index 47edc46945ae2d97e1e153579054e85c3d1a5e3d..0d608b294ced93a4b73fd4c3665acc8c7540bc83 100644 (file)
 #include <Riostream.h>
 #include <TFile.h>
 #include <TClass.h>
+#include <TCollection.h>
 #include <TTree.h>
 #include <TROOT.h>
 
@@ -254,6 +255,47 @@ void AliAnalysisTask::CheckNotify(Bool_t init)
    fInitialized = kTRUE;
 }
 
+//______________________________________________________________________________
+Bool_t AliAnalysisTask::CheckPostData() const
+{
+// Checks if data was posted to all outputs defined by the task. If task does
+// not have output slots this returns always kTRUE.
+   Bool_t dataPosted = kTRUE;
+   AliAnalysisDataContainer *coutput;
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   for (Int_t islot=0; islot<fNoutputs; islot++) {
+      coutput = GetOutputSlot(islot)->GetContainer();
+      if (!mgr->GetOutputs()->FindObject(coutput)) continue;
+      if (!coutput->GetData()) {
+         Error("CheckPostData", "Data not posted for slot #%d of task %s (%s)", 
+               islot, GetName(), ClassName());
+         dataPosted = kFALSE;
+      }   
+   }
+   CheckOwnership();
+   return dataPosted;
+}
+
+//______________________________________________________________________________
+Bool_t AliAnalysisTask::CheckOwnership() const
+{
+// Check ownership of containers posted on output slots (1 level only)
+   TObject *outdata;
+   for (Int_t islot=0; islot<fNoutputs; islot++) {
+      outdata = GetOutputData(islot);
+      if (outdata && outdata->InheritsFrom(TCollection::Class())) {
+         TCollection *coll = (TCollection*)outdata;
+         if (!coll->IsOwner()) {
+            Error("CheckOwnership","####### IMPORTANT! ####### \n\n\n\
+                Task %s (%s) posts a container that is not owner at output #%d. This may apply for other embedded containers. \n\n\
+                ####### FIX YOUR CODE, THIS WILL PRODUCE A FATAL ERROR IN FUTURE! ##########", GetName(), ClassName(), islot);
+             return kFALSE;   
+         }
+      }
+   }
+   return kTRUE;
+}
+      
 //______________________________________________________________________________
 Bool_t AliAnalysisTask::ConnectInput(Int_t islot, AliAnalysisDataContainer *cont)
 {
@@ -554,7 +596,6 @@ Bool_t AliAnalysisTask::CheckCircularDeps()
 void AliAnalysisTask::PrintTask(Option_t *option, Int_t indent) const
 {
 // Print task info.
-   AliAnalysisTask *thistask = (AliAnalysisTask*)this;
    TString opt(option);
    opt.ToLower();
    Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
@@ -565,7 +606,7 @@ void AliAnalysisTask::PrintTask(Option_t *option, Int_t indent) const
    if (!dep || (dep && IsChecked())) {
       printf("______________________________________________________________________________\n");
       printf("%s\n", Form("%stask: %s  ACTIVE=%i POST_LOOP=%i", ind.Data(), GetName(),IsActive(),IsPostEventLoop()));
-      if (dep) thistask->SetChecked(kFALSE);
+      if (dep) const_cast<AliAnalysisTask*>(this)->SetChecked(kFALSE);
       else {
          for (islot=0; islot<fNinputs; islot++) {
             printf("%s", Form("%s   INPUT #%i: %s <- ",ind.Data(),islot, GetInputType(islot)->GetName()));