Create a copy of TTreeReaderArray

Hello,

I am reading a TTreeReaderArray object from a tree and I need to create a copy of it to pass to a function and such as :

TTreeReaderArray<float> el_charge(reco_reader, "el_reader");
TTreeReaderArray<float> a = *el_charge;

But this throws the error :

error: indirection requires pointer operand ('TTreeReaderArray<float>' invalid)

Is there any way to make a copy of TTreeReaderArray so that I can pass it as an argument to a function? Or better yet, is there a simply way to convert it to a std::vector without having to use a for loop?

Thanks,

Charlie

ROOT Version: 6.24/06
Platform: Not Provided
Compiler: Not Provided


The proper C++ syntax would be:

TTreeReaderArray<float> el_charge(reco_reader, "el_reader");
TTreeReaderArray<float> a = el_charge;

But they are not designed to be copied (i.e. the above will fail to compile).

Is there any way to make a copy of TTreeReaderArray so that I can pass it as an argument to a function?

You can pass it by reference:

void myfunction(TTreeReaderArray<float> & el_charge);

Or better yet, is there a simply way to convert it to a std::vector without having to use a for loop?

If you mean that the value for all TTree entries should be stored in the vector, then there is no avoiding a loop short of using RDataFrame (which will do the loop for you :slight_smile: ).

If you mean that the values for a given TTree entries should be stored in the vector. You may not have to as the TTreeReaderArray<float> behave as an STL collection (it has a begin and end). Alternatively you can use that to feed a vector (std::vector v(array.begin(), array.end()))

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