Hi,
I have TTree with several branches filled with vector
I am trying to loop over the branches and read the values.
The code is quite complex and part of a MakeClass skeleton
a summary of the Loop
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
TObjArray *branches = fChain->GetListOfBranches();
TObjArrayIter next(branches);
TObject* br;
while ( ( br = next() ) ) {
TString varName = br->GetName();
if( !varName.Contains("mini_jet") ) continue;
TBranch* myBr = (TBranch*) br;
TLeaf* leaf = (TLeaf*)myBr->GetListOfLeaves()->First();
if( (TString)leaf->GetTypeName() == "vector<float>" ){
leaf->PrintValue();
vector<float> *v = (vector<float> *)leaf->GetValuePointer();
cout << v << " " << &v << endl;
}
}
the problem is that I can’t really get the pointer with GetValuePointer().
v is always 0 while the leaf->PrintValue() produces something like:
but I cannot get that very memory reference with GetValuePointer().
Any idea?
I have seen on other topics that the preferred solution would be to use (and it works):
vector<Float_t> *v = 0;
fChain->SetBranchAddress( br->GetName() ,&v );
fChain->GetEntry(jentry);
but I really would like to do this after I have already called: fChain->GetEntry(jentry);
cheers,
delo