Home | News | Documentation | Download

Reading a vector of type vector<float,ROOT::Detail::VecOps::RAdoptAllocator<float> >

Dear experts,

I’m new to RDataFrame…I’m trying to read a TTree which was created with RDataFrame and its branches are vectors of this type: vector<float,ROOT::Detail::VecOps::RAdoptAllocator >

My aim is to read contents of this TTree and write them to a non-RDataFrame TTree. Is this possible?

Thanks,
Chilufya


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi @ChilufyaM ,
that’s indeed possible, ROOT should be able to properly digest the non-standard allocator without issues. For instance, you can read that branch as a normal std::vector. How are you trying to read the contents of the TTree, and what’s failing?

Here’s a full example that produces such a file and reads back the data using raw TTree:

root [0] ROOT::RDataFrame(10).Define("vec", [] { return ROOT::RVec<double>{1.,2.,3.}; }).Snapshot("t", "f.root");
root [1] TFile f("f.root")
(TFile &) Name: f.root Title: 
root [2] auto t = f.Get<TTree>("t")
(TTree *) @0x7ffce3ffdbf8
root [3] t->Print()
******************************************************************************
*Tree    :t         : t                                                      *
*Entries :       10 : Total =            1368 bytes  File  Size =        572 *
*        :          : Tree compression factor =   3.07                       *
******************************************************************************
*Br    0 :vec       : vector<double,ROOT::Detail::VecOps:                    *
*         | :RAdoptAllocator<double> >                                       *
*Entries :       10 : Total  Size=        936 bytes  File Size  =        148 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   3.07     *
*............................................................................*
root [4] auto vptr = new std::vector<double>()
(std::vector<double, std::allocator<double> > *) @0x7ffce3ffdbf8
root [5] t->SetBranchAddress("vec", &vptr)
(int) 1
root [6] t->GetEntry(0)
(int) 34
root [7] *vptr
(std::vector &) { 1.0000000, 2.0000000, 3.0000000 }

Cheers,
Enrico

P.S.
vector<T, RAdoptAllocator> is how ROOT::RVecs are currently written out.

1 Like

Hi @eguiraud,

I’ll answer based on your example. The problem must have been just that I was trying to access the contents of vptr at the first position like this: vptr[0] and the error was:
error: cannot convert ‘std::vector<double, std::allocator >’ to ‘double’

I now access it correctly like this: (*vptr)[0]

Thanks,
Chilufya

1 Like

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