I have questions about the ability to read multiple separate branches of a TTree more efficiently.
Writing a standalone C++ script. I have existing .root files generated by someone else. I create a TTreeReader for it:
TFile myFile("myFile.root");
TTree* myTree = (TTree*)myFile.Get("cell");
TTreeReader myReader(myTree);
myTree->Print();
>
> ******************************************************************************
> *Tree :cell : Event *
> *Entries : 625000 : Total = 283063547 bytes File Size = 125481168 : : *
> *Tree compression factor = 2.26 *
> ******************************************************************************
> *Br 22 :nFiber1 : Int_t cell *
> *Entries : 625000 : Total Size= 5008744 bytes File Size = 1285896 *
> *Baskets : 78 : Basket Size= 32000 bytes Compression= 3.89 *
> *............................................................................*
> *Br 23 :nFiber2 : Int_t cell *
> *Entries : 625000 : Total Size= 5008744 bytes File Size = 1284406 *
> *Baskets : 78 : Basket Size= 32000 bytes Compression= 3.89 *
> *............................................................................*
> *Br 24 :nFiber3 : Int_t cell *
> *Entries : 625000 : Total Size= 5008744 bytes File Size = 1282746 *
> *Baskets : 78 : Basket Size= 32000 bytes Compression= 3.90 *
> *............................................................................*
The TTree contains many separate branches: “nFiber1”, “nFiber2”, “nFiber3”,… all the way to 24. It wasn’t written in the best way. I wish it was written as an array but that’s what I have. I could read it with lots of lines:
TTreeReaderValue<Int_t> nFiber1(myReader, "nFiber1");
TTreeReaderValue<Int_t> nFiber2(myReader, "nFiber2");
....
And then combine that into a single array later in the code. But that’s a lot of lines, and I’m actually reading 3 files in at the same time. So this is very clumsy.
My Question is: is there a way to read multiple branches with a TTreeReaderArray? Something like:
TTreeReaderArray<Int_t> nFiberChannels(myReader, "nFiber1","nFiber2","nFiber3");
....
I don’t think the above is possible though.
Even something like the below would be helpful:
TTreeReaderValue<Int_t> nFiberChannels[0](myReader, "nFiber1");
TTreeReaderValue<Int_t> nFiberChannels[1](myReader, "nFiber1");
...