Get TreeNumber of chain in PROOF


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.22
Platform: Not Provided
Compiler: Not Provided


Hello,
I want to use chain->GetTreeNumber() in my proof code. Considering this example including ProofFriends.h and ProofFriends.C. I defined TreeNum() function in ProofFriends.h file:
virtual Int_t TreeNum(){ return fChain->GetTreeNumber() ; }
I added ProofFriends::TreeNum() into the Process(entry) in the ProofFriends.C code but ProofFriends::TreeNum() returns 0.
What’s going wrong here? Isn’t it possible to get tree number of chain? If yes, how?
Thanks in advance

Hello,

So if I understand correctly, you have a call to fChain->GetTreeNumber() in your Process method and that always returns 0, even though you are working with a chain with multiple trees?

Indeed that shouldn’t be the case, pinging @ganis in case he has a hint.

Hello etejedor,
not directly putting in fChain->GetTreeNumber() in Process but I defined a function as below in .h file:
virtual Int_t TreeNum(){ return fChain->GetTreeNumber() ; }
:point_down:

   ProofFriends();
   virtual ~ProofFriends() { }
   virtual Int_t   Version() const { return 2; }
   virtual void    Begin(TTree *tree);
   virtual void    SlaveBegin(TTree *tree);
   virtual void    Init(TTree *tree);
   virtual Bool_t  Notify();
   virtual Bool_t  Process(Long64_t entry);
   virtual Int_t   GetEntry(Long64_t entry, Int_t getall = 0) { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; }
   virtual Int_t TreeNum(){ return fChain->GetTreeNumber() ; }
   virtual void    SetOption(const char *option) { fOption = option; }
   virtual void    SetObject(TObject *obj) { fObject = obj; }
   virtual void    SetInputList(TList *input) { fInput = input; }
   virtual TList  *GetOutputList() const { return fOutput; }
   virtual void    SlaveTerminate();
   virtual void    Terminate();

Then I called it in Process as below, but it returns 0 value.

Bool_t ProofFriends::Process(Long64_t entry){
   ProofFriends::TreeNum();
...
}

Hello,

Can you print both the entry number and the tree number inside Process, to check that actually you are moving to another tree but you still get number of tree zero?

the log file size is big so i take some part of log file here:

entry: 131 Treenum: 0
entry :131
passed trigger
start mu
start mu roc
muPtSFRochester: 1.00008
start roc cut
after mu roc
start mu roc
muPtSFRochester: 1.00028
start roc cut
after mu roc
entry: 132 Treenum: 0
entry :132
passed trigger
start mu
entry: 133 Treenum: 0
entry :133
passed trigger
start mu
start mu roc
muPtSFRochester: 1.0014
start roc cut
after mu roc
entry: 134 Treenum: 0
entry :134
passed trigger
start mu
entry: 135 Treenum: 0
entry :135
passed trigger
start mu
start mu roc

This output is for one of the workers, I checked the other workers output also. The tree number value is 0 yet.

Could you detect in one of your workers a printed line where the entry number does not correspond to tree number zero, but to another tree? You can know that by checking how many entries every tree of the chain has.

I checked that for all workers it returns 0. It seems it’s not possible to get tree number in chain of trees, because the value of entry belongs to each trees not chain. Actually when i save the value of entry, then the entry numbers are repeated as many as number of trees.

I see, but if you do something like what’s below with your files:

>>> import ROOT
>>> c = ROOT.TChain("events")
>>> c.Add("./roottest/python/cmdLineUtils/simpleTree.root")
1
>>> c.Add("./roottest/python/cmdLineUtils/simpleTree.root")
1
>>> for e in c: print(c.GetTreeNumber())
... 
0
0
0
0
0
0
1
1
1
1
1
1

You still get all zeros for all the trees you added to the chain?

No, I get the non-zero tree numbers:

root [4] vector <TString> TT2L2Nu_po18{"TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/UL2018/211002_064432/0000/", "TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/UL2018/211002_064432/0001/", "TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/UL2018/211002_064432/0002/"};
root [5] for (int i=0; i<3; ++i)  ch->Add(path + TT2L2Nu_po18[i]+ "*");
root [6] ch->GetNtrees()
(int) 2929
root [7] for (int i =0; i< ch->GetNtrees(); ++i) cout << i << endl;
0
1
2
3
4
5

Just a wild trial …
virtual Int_t TreeNum() { return ((TChain*)fChain)->GetTreeNumber() ; }

Still returns zero for the all trees

@ganis @pcanal any idea of what could be the problem?

Isn’t it the expected behavior? On each node, the tree number is that of the “local” chain and not of the whole chain. This means that each node will always start at tree number 0 even though it may (or may not) be a distinct file. You would see an increase the local tree number if and only there is enough files in the chain that a given node needs to process more than one file.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.