Reading STL container in RDataFrame branch

Dear Users,

using RDataFrame and Foreach tools to read data from a TTree I wrote the following code:

ROOT::RDataFrame particles("INPUT_particle", input_data);
std::vector<std::vector<ExpParticle>> allParticles;

particles.Foreach( [&] (int event, int track, std::string particle)
	{
		ExpParticle current_particle(event, track, particle);			
                    // doing stuff to get correct index to place in allParticles from outside...
                    int index;
		allParticles[index].push_back(current_particle);			

	}, {"event", "track", "particle"}
);

I get the following error:

Error in TTreeReaderValueBase::GetBranchDataType(): Must use TTreeReaderArray to read branch particle: it contains an array or a collection.
Error in TTreeReaderValueBase::CreateProxy(): The branch particle contains data of type {UNDETERMINED TYPE}, which does not have a dictionary.
terminate called after throwing an instance of β€˜std::runtime_error’
what(): An error was encountered while processing the data. TTreeReader status code is: 6
Aborted (core dumped)

My question is how to create dictionary of a type std::string.
I tried to workout at the LinkDef.h file through #pragma directive but it did not work. Maybe I did not provide the correct instructions of maybe the issue is elsewhere.

Please let me know, Thank you in advance

_ROOT Version: 6.32.00
_Platform: Ubuntu 22.04
_Compiler: gcc 11.4.0

Hello,
What are the types stored in the Tree? It cannot just be a std::string since ROOT provides the dictionary for string.

Lorenzo

Hello,
thank you for your reply.
The type store in the TTree is actually G4String since it is created by geant4 Monte Carlo code.
G4String is:
class G4String : public std::string
https://geant4.kek.jp/Reference/11.2.0/G4String_8hh_source.html
That is the reason the code is expected to read a std::string.
I cannot understand.
Thanks in advance

I am happy to inform you that I have solved the issue.
The solution is here:

Thank you anyway for your time

1 Like

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