#include <Riostream.h>
#include <TFile.h>
#include <TClass.h>
+#include <TCollection.h>
#include <TTree.h>
#include <TROOT.h>
fOutputReady(NULL),
fPublishedData(NULL),
fInputs(NULL),
- fOutputs(NULL)
+ fOutputs(NULL),
+ fBranchNames()
{
// Default constructor.
}
fOutputReady(NULL),
fPublishedData(NULL),
fInputs(NULL),
- fOutputs(NULL)
+ fOutputs(NULL),
+ fBranchNames()
{
// Constructor.
fInputs = new TObjArray(2);
fOutputReady(NULL),
fPublishedData(NULL),
fInputs(NULL),
- fOutputs(NULL)
+ fOutputs(NULL),
+ fBranchNames(task.fBranchNames)
{
// Copy ctor.
fInputs = new TObjArray((fNinputs)?fNinputs:2);
fOutputReady[i] = IsOutputReady(i);
fOutputs->AddAt(new AliAnalysisDataSlot(*task.GetOutputSlot(i)),i);
}
+ fBranchNames = task.fBranchNames;
return *this;
}
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 (!coutput) continue;
+ if (coutput->IsExchange() || !mgr->GetOutputs()->FindObject(coutput) || coutput==mgr->GetCommonOutputContainer()) 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)
{
Error("OpenFile", "No output slot for task %s with index %d", GetName(), iout);
return NULL;
}
- // We allow file opening also on the slaves (AG)
- AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+ // Method delegated to the analysis manager (A.G. 02/11/09)
AliAnalysisDataContainer *cont = GetOutputSlot(iout)->GetContainer();
- TFile *f = NULL;
- if (!strlen(cont->GetFileName())) {
- Error("OpenFile", "No file name specified for container %s", cont->GetName());
- return f;
- }
- if (mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis && cont->IsSpecialOutput())
- f = mgr->OpenProofFile(cont->GetFileName(),option);
- else {
- // Check first if the file is already opened
- f = (TFile*)gROOT->GetListOfFiles()->FindObject(cont->GetFileName());
- if (!f) f = new TFile(cont->GetFileName(), option);
- }
- if (f && !f->IsZombie()) {
- cont->SetFile(f);
- return f;
- }
- cont->SetFile(NULL);
- return NULL;
+ return AliAnalysisManager::OpenFile(cont, option);
}
//______________________________________________________________________________
}
}
+//______________________________________________________________________________
+void AliAnalysisTask::Reset()
+{
+// Clear activity flag. Reset data for exchange containers.
+ fActive = kFALSE;
+ fHasExecuted = kFALSE;
+ // Call PostData(islot, 0) for all slots connected to exchange containers
+ Int_t islot;
+ AliAnalysisDataContainer *cont;
+ for (islot=0; islot<fNinputs; islot++) {
+ cont = GetInputSlot(islot)->GetContainer();
+ if (cont && cont->IsExchange()) cont->Reset();
+ }
+}
+
//______________________________________________________________________________
Bool_t AliAnalysisTask::CheckCircularDeps()
{
SetChecked(kFALSE);
return kFALSE;
}
-
+
+//______________________________________________________________________________
+Bool_t AliAnalysisTask::ProducersTouched() const
+{
+// Check if all producer containers are in the "touched" state.
+ Int_t islot;
+ AliAnalysisDataContainer *cont;
+ for (islot=0; islot<fNinputs; islot++) {
+ cont = GetInputSlot(islot)->GetContainer();
+ // Simulate the data flow so the tasks are printed only when all inputs
+ // are touched
+ if (cont && !cont->IsTouched()) return kFALSE;
+ }
+ return kTRUE;
+}
+
//______________________________________________________________________________
void AliAnalysisTask::PrintTask(Option_t *option, Int_t indent) const
{
// Print task info.
- AliAnalysisTask *thistask = (AliAnalysisTask*)this;
+ Int_t islot;
+ AliAnalysisDataContainer *cont;
+ if (fActive) return;
+ if (!ProducersTouched()) return;
TString opt(option);
opt.ToLower();
Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
TString ind;
- Int_t islot;
- AliAnalysisDataContainer *cont;
for (Int_t i=0; i<indent; i++) ind += " ";
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()));
}
}
}
+ ((AliAnalysisTask*)this)->SetActive(kTRUE);
PrintContainers(option, indent+3);
+ if (!fBranchNames.IsNull()) printf("%sRequested branches: %s\n", ind.Data(), fBranchNames.Data());
}
//______________________________________________________________________________
}
}
+//______________________________________________________________________________
+void AliAnalysisTask::GetBranches(const char *type, TString &result) const
+{
+// Get the list of branches for a given type (ESD, AOD). The list of branches
+// requested by a task has to ve declared in the form:
+// SetBranches("ESD:branch1,branch2,...,branchN AOD:branch1,branch2,...,branchM")
+ result = "";
+ if (fBranchNames.IsNull()) return;
+ Int_t index1 = fBranchNames.Index(type);
+ if (index1<0) return;
+ index1 += 1+strlen(type);
+ Int_t index2 = fBranchNames.Index(" ", index1);
+ if (index2<0) index2 = fBranchNames.Length();
+ result = fBranchNames(index1, index2-index1);
+}