Project
Loading...
Searching...
No Matches
RootTreeReader Class Reference

A generic reader interface for ROOT TTrees. More...

#include <RootTreeReader.h>

Detailed Description

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.

Usage, with some KeyType:
The first argument is the tree name, the list of files is variable, all files must be passed before the first key-branchname pair.
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);
}
Further optional constructor arguments
Optional arguments can follow in arbitrary sequence, but all arguments must be passed before the first branch definition.
  • number of entries n (int)
  • publishing mode, PublishingMode
Integration into DPL:
The class defines the functor operator which takes the DPL ProcessingContext as argument and optionally an argument pack of headers which inherit from BaseHeader, the latter will form the header stack of the message.
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
  }
}
Binary format:
The reader supports the binary format of the RootTreeWriter as counterpart. Binary data is stored as vector of char alongside with a branch storing the size, as both indicator and consistency check.
Note
In the examples, 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.

The documentation for this class was generated from the following file: