pyROOT early object deconstruction

ROOT Version: 6.24/06
Platform: lxplus
Compiler: python3.6.8


Hi community,

First of all, I am sorry if this question was answered elsewhere (given how basic it is), but I did not manage to find that.

Issue is simple. When I’m trying to create an array of, e.g., TFiles, I end up with corrupted data.

The following code, even though files exist at these locations with the “events” TTree, and produce [None, None]. If one does not introduce vectorization, it goes fine.

I may be doing something stupid in the first place, but it seems to me like TFiles without assigned NAMED variables refuses to exist further than the point of creation. Therefore I would like to know if there’s a way to make this code work.

Let me know, if you cannot reproduce it or if you need any extra information. Thanks.

Pavlo

Hi @Silence2107 thanks for asking the question!

With map, the objects created in each iteration are not guaranteed to live longer then their iteration when you iterate over the map.

However, the files need to survive at least as long as the trees, otherwise the trees are not there anymore. To guarantee that, you could immediately convert the import_rootfiles map object to a list such that the files live as long as the import_rootfiles list:

import_rootfiles = list(map(lambda pid : ROOT.TFile("..."), pids))

Like this, the map object is immediately used to fill a Python list that owns references to the returned TFiles as well, hence the files don’t get get deleted right after the iteration.
Of course you could also just use a list comprehension, as the map has no advantage here.

Hope that helps!

Jonas

Hi @jonas,
Worked as expected, many thanks!

Pavlo

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