How TTree are wrapped by ROOT experts in PyROOT: [ ref]

uproot: the python interpreting that's directly based on ROOT data structure

My solution to fasten the process by automatically SetBranchAddress: [ ref]


Who's the owner?

It can be very tricky in ROOT, because directories own memories and do manual freeing. This has to do with the historical reason that smart pointer didn't exist before. If you own the obj, you need to release the memory of it. This can easily done by smart pointer. If some TDirectory owns the obj, you only need to take care of the TDirectory itself, do not use a smart pointer otherwise unexpected behavior will occur. This is even more so when you code with PyROOT, where the passing of PyProxy will render destructor. So with modern smart pointer, you don't want to put complicated delete order inside destructor. But just remember to choose the correct type of pointer:

Since TTree must live with an TFile, I suggest making TTree as raw pointer, and let ~TFile() to handle the deletion.

TF1 will be add to global lists, do DefaultAddToGlobalList (false) will do.

Meanwhile, all TFile is owned by you for sure.

Histograms on the other hand, need to be taken care of, if they have directory, it behaves like TTree. But if was SetDirectory (0), you own it.


TLine, TH1, TCanvas: I observed them to be added to global lists sometimes. Event if I used SetDirectory (0)..

But they appear harmless and occurs at the end of the PyRoot script.

More Info

See here for more:



Q: missing during compilation with ROOT libraries?

A: RDataFrame now need this library. by default, it exists on lxplus local env. However if you setup root from cvmfs(including setupATLAS; lsetup root), the link breaks. To get back the link, you need to check for the LCG version by looking at $ROOTSYS, and setup LCG with the same system, compiler env from cvmfs correspondingly. For example,

$ echo $ROOTSYS
# you need this to find libdavix for this root
source /cvmfs/


Q: my workspace crashes without providing a lot of information!

A: Try this:


Q: How to use lambda function in python?

A: Have to define lambda function as string:

Q: How can I pass external variable from python to RDF?


-- RongkunWang - 2019-07-19

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r5 - 2020-04-13 - RongkunWang
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Sandbox All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback