X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=blobdiff_plain;f=ANALYSIS%2FAliAnalysisDataSlot.cxx;h=d859515d381a35f85ca438e8b48687ea9ea1003b;hp=9804a952593cd56e6485b84e44fa9a1dd2650727;hb=44fd53ca929e7d21599553f220998b2e933f3c0d;hpb=d3106602d3c855aa5df55fbfcee909b983a83f4e diff --git a/ANALYSIS/AliAnalysisDataSlot.cxx b/ANALYSIS/AliAnalysisDataSlot.cxx index 9804a952593..d859515d381 100644 --- a/ANALYSIS/AliAnalysisDataSlot.cxx +++ b/ANALYSIS/AliAnalysisDataSlot.cxx @@ -39,8 +39,11 @@ // match. //============================================================================== -#include "TClass.h" -#include "AliLog.h" +#include +#include +#include +#include +#include #include "AliAnalysisDataSlot.h" #include "AliAnalysisTask.h" @@ -48,29 +51,138 @@ ClassImp(AliAnalysisDataSlot) +//______________________________________________________________________________ +AliAnalysisDataSlot::AliAnalysisDataSlot(TClass *type, AliAnalysisTask *task) + :TNamed(), + fType(type), + fParent(task), + fContainer(NULL) +{ +// Default constructor. + SetTitle(fType->GetName()); +} + +//______________________________________________________________________________ +AliAnalysisDataSlot::AliAnalysisDataSlot(const AliAnalysisDataSlot &slot) + :TNamed(slot), + fType(NULL), + fParent(slot.fParent), + fContainer(slot.fContainer) +{ +// Copy ctor. + GetType(); +} + +//______________________________________________________________________________ +AliAnalysisDataSlot& AliAnalysisDataSlot::operator=(const AliAnalysisDataSlot &slot) +{ +// Assignment + if (&slot == this) return *this; + TNamed::operator=(slot); + GetType(); + fParent = slot.fParent; + fContainer = slot.fContainer; + return *this; +} + //______________________________________________________________________________ Bool_t AliAnalysisDataSlot::ConnectContainer(AliAnalysisDataContainer *cont) { // Connect the data slot with a given container. The operation will succeed only // if the type defined by the slot inherits from the type enforced by the container. // The error message in case of failure is posted by the caller. - if (!cont || !fType) return kFALSE; + if (!cont || !GetType()) return kFALSE; if (!fType->InheritsFrom(cont->GetType())) { - AliError(Form("Data slot of type %s of task %s cannot be connected to data container %s of type %s", - fType->GetName(), fParent->GetName(), cont->GetName(), cont->GetType()->GetName())); + cout<<"Data slot of type "<GetName()<<" cannot be connected to data container "<GetName()<<" of type "<GetTitle()<GetName(), fParent->GetName(), cont->GetName(), cont->GetType()->GetName())); return kFALSE; } fContainer = cont; return kTRUE; } +//______________________________________________________________________________ +TClass *AliAnalysisDataSlot::GetType() const +{ +// Get class type for this slot. + AliAnalysisDataSlot *slot = (AliAnalysisDataSlot*)this; + if (!fType) slot->SetType(gROOT->GetClass(fTitle.Data())); + if (!fType) printf("AliAnalysisDataSlot: Unknown class: %s\n", GetTitle()); + return fType; +} + +//______________________________________________________________________________ +void *AliAnalysisDataSlot::GetBranchAddress(const char *branchname) const +{ +// Retrieve the address for a given branch. One should always test this before +// using SetBranchAddress because the address gets set by the first caller. +// Call this in MyTask::Init() + if (!GetType()) return NULL; + if (!fType->InheritsFrom(TTree::Class())) { + cout<<"Cannot call GetBranchAddress() for data slot of task "<GetName()<<" not pointing to tree-type data"<GetName())); + return NULL; + } + if (!IsDataReady()) { + cout<<"Cannot call GetBranchAddress() for data slot of task "<GetName()<<" while data is not ready"<GetName())); + return NULL; + } + TTree *tree = (TTree*)GetData(); + TBranch *br = tree->GetBranch(branchname); + if (!br) { + cout<<"Branch "<GetName()<<" as input of task "<GetName()<<"..."<GetName(), fParent->GetName())); + return NULL; + } + return br->GetAddress(); +} + +//______________________________________________________________________________ +Int_t AliAnalysisDataSlot::EnableBranch(const char *bname, TTree *tree) +{ +// Static method to enable recursively a branch in a tree (why this in not in ROOT?) + TBranch *branch = tree->GetBranch(bname); + Int_t count = 0; +// static Int_t indent = 0; + if (!branch) return count; +// TString s; +// for (Int_t i=0; iGetName(), branch->TestBit(kDoNotProcess)); + branch->SetBit(kDoNotProcess, kFALSE); + TIter next(branch->GetListOfBranches()); + TBranch *branch_sub; + // Activate all sub-branches +// indent++; + while ((branch_sub=(TBranch*)next())) { + count += AliAnalysisDataSlot::EnableBranch(branch_sub->GetName(), tree); + } +// indent--; + return count; +} + +//______________________________________________________________________________ +Bool_t AliAnalysisDataSlot::SetBranchAddress(const char *branchname, void *address) +{ +// Set a branch address for input tree. To be called during MyTask::Init() +// only if GetBranchAddress() returns a NULL pointer for a tree-type slot. + if (GetBranchAddress(branchname)) { + Error("SetBranchAddress","Branch address for %s already set by other task. Call first GetBranchAddress() in %s::ConnectInputData()",branchname, fParent->GetName()); + return kFALSE; + } + TTree *tree = (TTree*)GetData(); + tree->SetBranchAddress(branchname, address); + return kTRUE; +} + //______________________________________________________________________________ TObject *AliAnalysisDataSlot::GetData() const { // Retreives the data from the container if it is ready. if (!fContainer) { - AliError(Form("Data slot of type %s of task %s has no connected data container", - fType->GetName(), fParent->GetName())); + cout<<"Data slot of type "<GetName()<<" has no connected data container"<GetName(), fParent->GetName())); return NULL; } if (!fContainer->IsDataReady()) return NULL; @@ -82,8 +194,8 @@ Bool_t AliAnalysisDataSlot::IsDataReady() const { // Check if data for this slot is ready in its container. if (!fContainer) { - AliError(Form("Data slot of type %s of task %s has no connected data container", - fType->GetName(), fParent->GetName())); + cout<<"Data slot of type "<GetName()<<" has no connected data container"<GetName(), fParent->GetName())); return kFALSE; } return fContainer->IsDataReady();