Dear rooters,
I am trying to write my analysis that inherits from a TSelector (among other classes). In this application I am using root files that have multiple times the same branch for each event, one branch per readout channel. The number of readout channels is not fixed and may varie up to 64.
In the header of the selector I need to declare and initialize all the pointers to be associated with my root file. The issue is that I would like this selector to usable in any case, regardless of the number of channels the file I am trying to read contains. In order to do that I declared all the pointers for the maximum number of channels (64) one by one by hand and have conditional addressing if the branch exists. This makes it quite inconvenient to use in my code.
Instead of decreeing the pointers one by one, my idea was to declare a vector of pointers, which I would then assign the branches of the file, something along the following lines:
// Vector of pointers
std::vector<std::vector<double>*> t;
std::vector<std::vector<double>*> w;
// Branches
std::vector<TBranch*> b_t; //!
std::vector<TBranch*> b_w; //!
......
// Initialization
t.reserve(64);
w.reserve(64);
for (int i = 0; i < 64; i++)
{
t.push_back(new std::vector<double>(i));
w.push_back(new std::vector<double>(i));
t.at(i) = 0;
w.at(i) = 0;
}
b_t.reserve(64);
b_w.reserve(64);
// Addressing
for (unsigned int ich = 0; ich < 64; ich++)
{
if (fChain->GetBranch(Form("t%02u", ich)))
{
fChain->SetBranchAddress(Form("t%02u", ich), &t.at(ich), &b_t.at(ich));
fChain->SetBranchAddress(Form("w%02u", ich), &w.at(ich), &b_w.at(ich));
}
}
Obviously this is failing, with no indication of what is going wrong. I have already included the header file and also the following preprocessor directive:
#ifdef __CINT__
#pragma link C++ class vector< vector<double> >+;
#endif
but it does not seem to help!!
Please let me know if there are any ideas or other solutions.
Thanks!!