Hi all,
I have a problem with TChain and rootd.
If I work in local I don’t have problem to chain several files, in general I use this way:
TChain *JetChain;
JetChain = new TChain("Jet");
for (int num=1; num<=75; num++)
{
ostringstream string_num;
string_num << num;
const char *num_st = string_num.str().c_str();
JetChain->AddFile("mini-ntuple_bhhs1a."+num_st+".root", TChain::kBigNumber);
}
But when I work in remote I can’t.
With rootd I tried different way but nothing.
I tried:
JetChain->AddFile("root://blabla.fnal.gov:5151//mini-ntuple_bhhs1a.*.root", TChain::kBigNumber);
JetChain->AddFile("root://blabla.fnal.gov:5151//mini-ntuple_bhhs1a.*", TChain::kBigNumber);
JetChain->AddFile("root://blabla.fnal.gov:5151//*.root", TChain::kBigNumber);
JetChain->AddFile("root://blabla.fnal.gov:5151//*.*", TChain::kBigNumber);
But nothing, it chains only the first file…
The only way I found is:
TChain *JetChain;
JetChain = new TChain("Jet");
JetChain->AddFile("root://blabla.fnal.gov:5151//mini-ntuple_bhhs1a.1.root", TChain::kBigNumber);
JetChain->AddFile("root://blabla.fnal.gov:5151//mini-ntuple_bhhs1a.2.root", TChain::kBigNumber);
...
but I have over 300 files…
Is not a way to simplify this work?
Thank you
Ciccio
cplager
September 17, 2010, 5:29pm
2
Hi,
I recommend writing a subroutine that takes a text file containing all of the files you have as input and adds them to your TChain.
Cheers,
Charles
p.s. This question comes up enough that it might be a nice feature to add to the TChain class…
pcanal
September 17, 2010, 8:11pm
3
Hi,
Doesn’t:[code]TChain *JetChain;
JetChain = new TChain(“Jet”);
for (int num=1; num<=75; num++)
{
ostringstream string_num;
string_num << num;
const char *num_st = string_num.str().c_str();
JetChain->AddFile(TString::Format("root://blabla.fnal.gov:5151//mini-ntuple_bhhs1a.%d.root",num_st), TChain::kBigNumber);
}[/code]work?
Philippe.
Philippe.
pcanal
September 17, 2010, 8:11pm
4
Hi,
Doesn’t:[code]TChain *JetChain;
JetChain = new TChain(“Jet”);
for (int num=1; num<=75; num++)
{
JetChain->AddFile(TString::Format(“root://blabla.fnal.gov:5151//mini-ntuple_bhhs1a.%d.root”,num), TChain::kBigNumber);
}[/code]work?
Philippe.
Hi Charles and Philippe,
thank you very much for your answers, both methods work!
Thank you
Ciccio
cplager
September 20, 2010, 12:46pm
6
[quote=“pcanal”]Hi,
Doesn’t:[code]TChain *JetChain;
JetChain = new TChain(“Jet”);
for (int num=1; num<=75; num++)
{
JetChain->AddFile(TString::Format(“root://blabla.fnal.gov:5151//mini-ntuple_bhhs1a.%d.root”,num), TChain::kBigNumber);
}[/code]work?
Philippe.[/quote]
It probably works in this case
But a lot of experiments give their files non-sequential names and so this doesn’t work in general.
Cheers,
Charles
pcanal
September 20, 2010, 3:28pm
7
Hi,
[quote]But a lot of experiments give their files non-sequential names and so this doesn’t work in general.[/quote]humm … well it works perfectly in this case :~) and for the general case you are indeed welcome to propose a patch implementing this feature.
Cheers,
Philippe.
cplager
September 20, 2010, 3:35pm
8
[quote=“pcanal”]Hi,
[quote]But a lot of experiments give their files non-sequential names and so this doesn’t work in general.[/quote]humm … well it works perfectly in this case :~) and for the general case you are indeed welcome to propose a patch implementing this feature.
Cheers,
Philippe.[/quote]
I’m pretty much suggesting a member function that looks like this:
Hi Jibo,
I believe you’re almost certainly better of having code like:
TChain *chainPtr = new TChain ("someTree")
loadFilesToChain (chainPtr, "listOfFiles.txt")
where loadFilesToChain looks something like this (you’ll need the right headers, etc).
void loadFilesToChain (TChain *chainPtr, const std::string &filename)
{
string line;
ifstream source (listname.c_str(), ios::in);
while ( getline (source, line) )
{
// you may want to clean line here...
chainPtr->AddFile( line…
Cheers,
Charles