Multiple *.root files in TChain, crash at GetEntry()

Hello!

I have a problem reading in mulitple *.root files in a TChain object. For one single file it works, for 2+ files it crashes when reading the Entry.

In detail:

  1. I create a TChain object, reading a list of input *.root files and initialize the Tree:

[code]TChain *chain = new TChain(“physics”);
ifstream flist(<my_inputlist>);
char line[500];
int nchainentries = 0;
while(flist.getline(line,450)) {
TString fileName = line;
if(chain->Add(fileName.Data())) { //Add sample to chain
nchainentries = chain->GetEntries();
}
}
flist.close();

AnalysisTree *t = new AnalysisTree();
t->Init(chain); //Initialize the tree with the constructed chain
[/code]

  1. Then I loop the events calling LoadTree() and GetEntry() for each event

Long64_t nbytes = 0; for(Long64_t jentry = 0; jentry < nchainentries; jentry++) { //Looping all events Long64_t ientry = t->LoadTree(jentry); //Load tree from chain if(ientry < 0) { break; } else { nbytes += t->GetEntry(jentry); //Load new entry } }

If I use a list with only one *.root file, it runs fine, loading all branches properly and processing the events.

If I use a list with multiple *.root files, it seems to properly load the files into the TChain object. Also the LoadTree() function for the first event works fine, but it crashes when executing LoadEntry() for the first event.

The *.root files are proper *.root files, no Zombies or anything, and the list just contains the full paths of the *.root files.

For The GetEntry(), Init() and LoadTree() functions I use the standarad functions produced by a MakeClass on the tree of a *.root file as found below, just put together in an AnalysisTree class.

Int_t AnalysisTree::GetEntry(Long64_t entry) { 
  if(!fChain) return 0;
  return fChain->GetEntry(entry); 
}    

//______________________________________________
Long64_t AnalysisTree::LoadTree(Long64_t entry) {
  Long64_t centry;
  if(!fChain) {
    centry = -5;
  } else {
    Long64_t centry = fChain->LoadTree(entry);
    if(centry >= 0) {
      if(fChain->InheritsFrom(TChain::Class())) {
        TChain *chain = (TChain*)fChain;
        if(chain->GetTreeNumber() != fCurrent) {
          fCurrent = chain->GetTreeNumber();
          Notify();
        }
      }
    }
  }
  return centry;
}

//______________________________________________
void AnalysisTree::Init(TTree *tree) {
  [...] // Reset pointers
  if(!tree) return;
  fChain = tree;
  fCurrent = -1;
  fChain->SetMakeClass(1);
  [...] //Set pointers
}

The full crash report (if that is of any help) is like

[code] *** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x0000003cbe6ac7ae in __libc_waitpid (pid=24401, stat_loc=0x7fffde6956ec, options=0) at …/sysdeps/unix/sysv/linux/waitpid.c:32
#1 0x0000003cbe63e8c9 in do_system (line=) at …/sysdeps/posix/system.c:149
#2 0x00007fec8c53d70c in TUnixSystem::StackTrace() () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libCore.so
#3 0x00007fec8c53ff43 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libCore.so
#4
#5 0x00007fec8b34963e in int TStreamerInfoActions::VectorLooper::ReadCollectionBasicType(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libRIO.so
#6 0x00007fec8b292485 in TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libRIO.so
#7 0x00007fec89973b05 in TBranchElement::ReadLeavesMakeClass(TBuffer&) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#8 0x00007fec89969a57 in TBranch::GetEntry(long long, int) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#9 0x00007fec89974ac5 in TBranchElement::GetEntry(long long, int) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#10 0x00007fec899b3f33 in TTree::GetEntry(long long, int) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#11 0x000000000042dc63 in TopAna::RunAnalysis (this=0x7fffde6981a0) at TopAna.cpp:95
#12 0x000000000042d450 in TopAna::TopAna (this=0x7fffde6981a0, tree=0x3046d90, rh=0x29e1e10) at TopAna.cpp:20
#13 0x000000000042b521 in run () at main.cpp:614
#14 0x0000000000426685 in main (argc=10, argv=0x7fffde6987a8) at main.cpp:24

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x00007fec8b34963e in int TStreamerInfoActions::VectorLooper::ReadCollectionBasicType(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libRIO.so
#6 0x00007fec8b292485 in TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libRIO.so
#7 0x00007fec89973b05 in TBranchElement::ReadLeavesMakeClass(TBuffer&) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#8 0x00007fec89969a57 in TBranch::GetEntry(long long, int) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#9 0x00007fec89974ac5 in TBranchElement::GetEntry(long long, int) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#10 0x00007fec899b3f33 in TTree::GetEntry(long long, int) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/lib/libTree.so
#11 0x000000000042dc63 in TopAna::RunAnalysis (this=0x7fffde6981a0) at TopAna.cpp:95
#12 0x000000000042d450 in TopAna::TopAna (this=0x7fffde6981a0, tree=0x3046d90, rh=0x29e1e10) at TopAna.cpp:20
#13 0x000000000042b521 in run () at main.cpp:614
#14 0x0000000000426685 in main (argc=10, argv=0x7fffde6987a8) at main.cpp:24
===========================================================[/code]

Any help is very appreciated! Thanks!

[color=#FF0000]EDIT:[/color]

I am using

$which root
/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.10-x86_64-slc6-gcc4.7/bin/root

$which gcc
/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/Gcc/gcc472_x86_64_slc6/slc6/gcc47/bin/gcc

It was a branch issue…

I did not properly reset a branch with

my_branch = 0

before setting its branch address, so there was a conflict when opening the second file…

1 Like