TChain problem

Hi!

I have root files with several TTree objects:

===================================================================================
root [1] TFile f("/data/etp/mameghan/aant_tuples/ttbar_5200/ttbar_5200_1.root")
root [2] f.ls()
TFile** /data/etp/mameghan/aant_tuples/ttbar_5200/ttbar_5200_1.root
TFile* /data/etp/mameghan/aant_tuples/ttbar_5200/ttbar_5200_1.root
KEY: AttributeListLayout Schema;1
KEY: TDirectory RecoHistogram;1 RecoHistogram
KEY: TDirectory TruthHistogram;1 TruthHistogram
KEY: TTree CollectionTree;1 CollectionTree
KEY: TTree Truth0;1 Truth0
KEY: TTree FullReco0;1 FullReco0
KEY: TTree FullRecoAna0;1 FullRecoAna0
KEY: TTree TruthAna0;1 TruthAna0

Since I have a couple of these files I want to use TChains.
At first I created classes with the commands

CollectionTree->MakeClass(“CollectionTree”)
FullReco0->MakeClass(“EvTree”)

But now the following code does not work (standalone c++, not cint, root version 5.12):

===================================================================================
int main(int argc, char* argv[]) {

TChain* chain = new TChain("CollectionTree");
chain->AddFile("/data/etp/mameghan/aant_tuples/ttbar_5200/ttbar_5200_1.root", 0);
std::cout << "Entries: " << chain->GetEntries() << std::endl;
CollectionTree* tree = new CollectionTree(chain);
std::cout << "Looping over events..." << std::endl;

for (Long64_t event = 0; event < chain->GetEntries(); event++) {
	std::cout << "event " << event << std::endl;
	tree->GetEntry(event);
}

return 0;

}

Console output:

===================================================================================
Warning in TClass::TClass: no dictionary for class AttributeListLayout is available
Warning in TClass::TClass: no dictionary for class pair<string,string> is available
Entries: 20000
Looping over events…
event 0
Error in TFile::TFile: file ttbar_5200_1.root does not exist

*** Break *** segmentation violation
Generating stack trace…
0x066569e5 in TTree::LoadTree(long long) + 0xe1 from /share/cernlib/Linux_fc3/root_v5.12.00/lib/libTree.so
0x0662c7ea in TChain::LoadTree(long long) + 0xa22 from /share/cernlib/Linux_fc3/root_v5.12.00/lib/libTree.so
0x0662b8c1 in TChain::GetEntry(long long, int) + 0x19 from /share/cernlib/Linux_fc3/root_v5.12.00/lib/libTree.so
0x08049cab in CollectionTree::GetEntry(long long) + 0x2b from ./Semileptonic
0x0804985e in main + 0xf2 from ./Semileptonic
0x07dabe23 in __libc_start_main + 0xd3 from /lib/tls/libc.so.6
0x080496e5 in __gxx_personality_v0 + 0x61 from ./Semileptonic
Aborted

But if I use a different TTree object (‘FullReco0’ instead of ‘CollectionTree’) from the input
file everything works:

===================================================================================
int main(int argc, char* argv[]) {

TChain* chain = new TChain("FullReco0");
chain->AddFile("/data/etp/mameghan/aant_tuples/ttbar_5200/ttbar_5200_1.root", 0);
std::cout << "Entries: " << chain->GetEntries() << std::endl;
EvTree* tree = new EvTree(chain);
std::cout << "Looping over events..." << std::endl;

for (Long64_t event = 0; event < chain->GetEntries(); event++) {
	std::cout << "event " << event << std::endl;
	tree->GetEntry(event);
}

return 0;

}

Console output:

===================================================================================
Warning in TClass::TClass: no dictionary for class AttributeListLayout is available
Warning in TClass::TClass: no dictionary for class pair<string,string> is available
Entries: 20000
Looping over events…
event 0
event 1
event 2

No problems occur if I again use the ‘CollectionTree’ but do not have a filename with a
path (e.g. create a symbolic link in my working directory):

int main(int argc, char* argv[]) {

TChain* chain = new TChain("CollectionTree");
chain->AddFile("ttbar_5200_1.root", 0);
std::cout << "Entries: " << chain->GetEntries() << std::endl;
CollectionTree* tree = new CollectionTree(chain);
std::cout << "Looping over events..." << std::endl;

for (Long64_t event = 0; event < chain->GetEntries(); event++) {
	std::cout << "event " << event << std::endl;
	tree->GetEntry(event);
}

return 0;

}

Using a TFile instead of a TChain also works:

===================================================================================
int main(int argc, char* argv[]) {

TFile* file = new TFile("/data/etp/mameghan/aant_tuples/ttbar_5200/ttbar_5200_1.root");
TTree* my_collection_tree = (TTree*)gDirectory->Get("CollectionTree");
CollectionTree* my_collection = new CollectionTree(my_collection_tree);
my_collection_tree->GetEntries();
std::cout << "Entries: " << my_collection_tree->GetEntries() << std::endl;
std::cout << "Looping over events..." << std::endl;

for (Long64_t event = 0; event < my_collection_tree->GetEntries(); event++) {
	std::cout << "event " << event << std::endl;
	my_collection->GetEntry(event);
}

return 0;

===================================================================================

Is anyone there with an idea what my problem might be? I really do not want to go
back to TFiles…

Raphael[/code]

Hi,

Could you please provide a running example showing the failure (it is weird and sounds like a bug … that I do not see by simply looking at the code).

Cheers,
Philippe