EventAnalysis
1.3.0
|
A chain that reads only branches which have an address. More...
#include <SparseChain.h>
Public Member Functions | |
template<typename T > | |
Int_t | SetBranchAddress (const char *bname, T **add, TBranch **ptr=0) |
Set branch address and adds the branch to the branch list. More... | |
Int_t | SetBranchAddress (const char *bname, void *add, TClass *realClass, EDataType datatype, Bool_t isptr) |
Set branch address adds the branch to the branch list. More... | |
Int_t | GetEntry (Long64_t entry=0, Int_t getall=0) |
Reads data from branches with an address. More... | |
Private Attributes | |
std::vector< std::string > | _branchesWithAddress |
A chain that reads only branches which have an address.
The standard TChain class reads by default all the branches; not just the ones for which an address has been set; this can impair the I/O performance severely when not every branch is of interest. The TTree::SetBranchStatus member function can be used to disable all the branches and then selectively re-enable only the interesting ones.
This procedure sometimes just doesn't work as expected, since branches are enabled by name, so if a class A has a member named m, and two objects a1 and a2 of class A are written on the file then two split branches named "m" will be present; enabling "m" will then enable both, also if only one among a1.m and a2.m is of interest. The solution of using a trailing dot in the name of the main branches (e.g. "a1." instead of "a1") will result in split branches named "a1.m" and "a2.m", with no name degeneration. This has a couple of minor side effects, like the necessity to also append the trailing dot to the branch name when setting the branch address for readout, and the fact that for branches containing a class like std::vector<int> the trailing dot will be removed from the branch name; in the end, some branches will have a trailing dot and some others not.
The SparseChain class is meant to simplify the readout of just a subset of branches (i.e. a "sparse" readout) from a set of trees written in a Root file. It keeps a list of branches whose address has been set, and its override of TChain::GetEntry calls GetEntry only for those branches and split sub-branches. Its usage is identical to that of the usual TChain:
In the example above, only the branch mc and its split sub-branches are enabled and effectively read from disk, improving the I/O performance.
Technical note: using the same strategy of #SparseTree, i.e. disabling all the branches and re-enabling only some of them, doesn't work with a chain. TChain keeps an internal list of enabled and disabled branches, and will call TTree::SetBranchStatus every time it jumps from one Root file to another (see TChain::LoadTree). So the solution adopted by SparseChain is to keep all the branches active and to selectively call GetEntry only for those who have an address set.
Int_t EA::SparseChain::GetEntry | ( | Long64_t | entry = 0 , |
Int_t | getall = 0 |
||
) |
Reads data from branches with an address.
This method reads the given entry from all those branches whose address has been set by means of #setBranchAddress.
entry | The entry to be read. |
getall | If != 0 then all the branches will be read (default TChain behavior). |
Int_t EA::SparseChain::SetBranchAddress | ( | const char * | bname, |
T ** | add, | ||
TBranch ** | ptr = 0 |
||
) |
Set branch address and adds the branch to the branch list.
This method sets the branch address and adds the branch to the list of branches that will be read upon a call to GetEntry.
bname | the name of the branch. |
add | the address of the pointer to the buffer object. |
ptr |
Int_t EA::SparseChain::SetBranchAddress | ( | const char * | bname, |
void * | add, | ||
TClass * | realClass, | ||
EDataType | datatype, | ||
Bool_t | isptr | ||
) |
Set branch address adds the branch to the branch list.
This method sets the branch address and adds the branch to the list of branches that will be read upon a call to GetEntry.
bname | the name of the branch. |
add | the address of the pointer to the buffer object. |
realClass | the TClass describing the buffer object |
datatype | the data type of the buffer object |
isptr | true if add is the address of a pointer, false if add is the address of a object. |
|
private |