How to make Snapshot of RDataFrame that contains STL collections?

Hello,
I would like to select and store a subset of entries from the original big TTree that contains branches with STL collections. Here is an example of the code:

import ROOT
ROOT.gInterpreter.GenerateDictionary('vector<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<float> > >')
df = ROOT.RDataFrame('events', 'data.root')
df = df.Filter(...)
df.Snapshot('events', 'filtered.root', '.*')

When I am trying to run it I’m getting errors similar to this one:

Error in <TTree::Branch>: The class requested (vector<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<float> > >) for the branch "lep_p4" is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (vector<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<float> > >) to avoid to write corrupted data.

So, it seems that ROOT.gInterpreter.GenerateDictionary does not make any effect. Could you, please, suggest me how to solve this error?

Thank you!

Cheers,
Konstantin.


ROOT Version: 6.18/04
Platform: x86_64-slc6
Compiler: gcc8

Hi,
uhm I’m not sure why the GenerateDictionary call would not be picked up, maybe @pcanal knows. Here are other ways to generate dictionaries that you could try out.

Cheers,
Enrico

Hello Enrico,
thank you for the prompt reply and for the suggestion!
Indeed, using the other way to generate dictionaries helped.
Cheers,
Konstantin.


Here is a working solution for the reference.
Call ROOT.gInterpreter.ProcessLine('.L def.h+') instead of GenerateDictionary. And put pragma statement to generate dictionary into def.h:

#include <vector>
#include <Math/PtEtaPhiM4D.h>
#include <Math/LorentzVector.h>

#pragma link C++ class vector<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<float> > >;
1 Like

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