and supply the same paths that are in the .txt file as command line arguaments and my code runs perfectly. I am not sure what I am doing differently between the two as in both I am suppling a TString to TChain::Add.
Can anyone spot my mistake?
Thanks,
Paul
p.s. I am using root version 5.34.18-x86_64-slc6-gcc4.7 from ATLASLocalRootBase
I tried to make a small piece of code that can reproduce the problem. The following crashes if I SetBranchAddress for two branches but if I set either one it runs fine.
I checked that the file paths are correct.
#include "TChain.h"
#include "TTree.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
nt main(int argc, char* argv[]){
TString treename = "truth";
TChain *nt = new TChain(treename);
std::string filename = "input.txt";
std::ifstream inputfilenamestream( filename.c_str() );
if (!inputfilenamestream.is_open()) {
std::cout<<"Sorry, inputfilenamestream could not be opened!" << std::endl;
//exit(1);
}else{
std::string rootfile;
while (getline(inputfilenamestream,rootfile)){
TString rootfile2(rootfile);
nt->Add(rootfile2);
}
}
TBranch *b_top_hfor_type=0; //!
TBranch *b_top_hfor_Quarks_px=0; //!
int top_hfor_type=0;
std::vector<float> *top_hfor_Quarks_px;
nt->SetBranchAddress("top_hfor_type", &top_hfor_type, &b_top_hfor_type);
nt->SetBranchAddress("top_hfor_Quarks_px", &top_hfor_Quarks_px, &b_top_hfor_Quarks_px);
for(int i=0;i < (int)nt->GetEntries() ; i++){ //loop not needed?
Long64_t ientry = nt->LoadTree(i);
if (ientry<0)break;
std::cout << "Will I crash?" << ientry << std::endl;
int nbytes = nt->GetEntry(i);
std::cout << "I did not crash. "<< std::endl;
if(nbytes==0){ std::cout << "failed to get entry" << std::endl; continue;}
}
return 0;
}
still I am afraid this is not enough as it is not a complete reproducer.
Did you try to see if the paths to the files are correct when you read them from the txt file?
I could have a look to a dry run of your program (dry because I cannot access the actual root files ).
The names look sane and I tend to exclude a root bug here.
Said that, to recap: you can run if you add one by one the files to the chain, say hard coding the names in the program or passing those via command line but not when reading them through the txt file and the filenames look identical.
If yes, I think this looks like an issue solvable with some printouts and a cup of coffee…