Tools:

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]

Memory

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.

PyRoot

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: https://root-forum.cern.ch/t/can-i-use-smart-pointers-freely-or-do-i-need-to-account-for-roots-hidden-global-state/26385

https://root.cern.ch/root/htmldoc/guides/users-guide/ObjectOwnership.html

Q&A

ROOT

Q: libdavix.so 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
/cvmfs/sft.cern.ch/lcg/releases/LCG_96/ROOT/6.18.00/x86_64-centos7-gcc8-opt
# you need this to find libdavix for this root
source /cvmfs/sft.cern.ch/lcg/views/LCG_96/x86_64-centos7-gcc8-opt/setup.sh
 

RooStat

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

A: Try this: https://root-forum.cern.ch/t/root-crash-without-error-msg-accessing-factory-edit-pdf-ws-saved-in-another-file/37887

RDataFrame

Q: How to use lambda function in python?

A: Have to define lambda function as string: https://root-forum.cern.ch/t/using-advanced-filters-with-rdataframe-in-python/30966

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

A: https://root-forum.cern.ch/t/rdataframe-defining-new-column-evaluated-as-a-function-of-external-values-in-python/34555

-- 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