![]() |
Project
|
A generic reader interface for ROOT TTrees. More...
#include <RootTreeReader.h>
A generic reader interface for ROOT TTrees.
The reader interfaces one TTree specified by its name, and supports this tree to be distributed over multiple files.
The class uses a KeyType to define sinks for specific branches, the default key type is DPL framework::Output. Branches are defined for processing by either pairs of key type and branch name, or by struct BranchDefinition. The latter allows strong typing, the type is specified as template parameter and the DPL IO decides upon serialization method.
Output data is always ROOT serialized if no type is specified.
RootTreeReader(treename, filename1, filename2, ..., KeyType{...}, branchname1, BranchDefinition<type>{KeyType{...}, branchname2}, ) reader; auto processSomething = [] (auto& key, auto& object) { // do something }; while (reader.next()) { reader.process(processSomething); }
int
)auto reader = std::make_shared<RootTreeReader>(treename, filename1, filename2, ..., Output{...}, branchname1, BranchDefinition<type>{Output{...}, branchname2}, ); // In the DPL AlgorithmSpec, the processing lambda can simply look like: // (note that the shared pointer is propagated by copy) auto processingFct = [reader](ProcessingContext& pc) { // increment the reader and invoke it for the processing context if (reader->next()) { SomeHeader specificHeader; reader(pc, specificHeader); } else { // no more data } } // another example, simply incrementing by operator++ and providing additional // custom header auto someOtherProcessingFct = [reader](ProcessingContext& pc) { // increment the reader and invoke it for the processing context SomeHeader specificHeader; if ((++reader)(pc, specificHeader) == false) { // no more data } }
reader
has to be set up in the init callback and it must be static there to persist. It can also be a shared_pointer, which then requires additional dereferencing in the syntax. The processing lambda has to capture the shared pointer instance by copy.