Hello,
A simple question hopefully – How can I fill a branch variable automatically using the TTreeReader?
I thought I could do something like this …
#include "Event/SimEvent.h"
#include "TFile.h"
#include "TTreeReader.h"
void simpleTreeReaderTest(const char *fname) {
auto file = TFile::Open(fname);
TTreeReader reader("Event_Tree", file);
auto event = new event::SimEvent();
auto branch = reader.GetTree()->GetBranch("Event");
branch->SetAddress(event);
while (reader.Next()) {
std::cout << "Entry: " << reader.GetCurrentEntry() << std::endl;
std::cout << "Event: " << event->getEventNumber() << std::endl;
std::cout << std::endl;
}
}
But it doesn’t seem to work, as the event object is not filled and I see that the event number does not change as I call the reader.Next() method.
I have done this with the tree->GetEntry() method in the past but I wasn’t sure if this is usable given that I’m trying to use the reader’s state instead now inside a loop.
Thanks.
–Jeremy