Increment by variable names in SetBranchAddress

Hi there! This may be a very simple answer, I am not sure. But, I was wondering for a variable number of branches in root that are named incrementally ( Detector_P0, Detector_P2, etc.) how one would use the SetBranchAddress all in one step to read them into correctly named variables (typed double). This is what I have so far: (I have it working for the branchName, but not the &variableName in SetBranchAddress())

for (int i = 0; i < nb_det; i++) {

std::string branchVarName = "Detector_P" + std::string(to_string(i));

const char * branchVarNameC;

 branchVarNameC = branchVarName.c_str();

All->SetBranchAddress(branchVarNameC,&("detectorP" + i, ???);


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.20/04
Platform: Not Provided
Compiler: Not Provided

Hi @lfisher5,
Unfortunately what you are trying to do is not possible in standard c++. You could try initializing an array of pointers and then give the elements as arguments to SetBranchAddress in the loop.