Hello,
I have a set of ntuple files (converted using h2root)
which all have the same ntuple id (h1001) and I'd like
to chain them using
TChain::Add("~/qqgg-run/presel-ntp-189/qq-*.root/h1001")
(otherwise, root seems to assume the filename is the tree name).
However, it looks like that the part after .root is ignored:
x = new TChain;
root [9] x->Add("~/qqgg-run/presel-ntp-189/qq-*.root/h1001")
Error in <TChain::AddFile>: cannot find tree with name in file
~/qqgg-run/presel-ntp-189/qq-189-000-aa.root
Error in <TChain::AddFile>: cannot find tree with name in file
~/qqgg-run/presel-ntp-189/qq-189-001-aa.root
Error in <TChain::AddFile>: cannot find tree with name in file
~/qqgg-run/presel-ntp-189/qq-189-002-aa.root
If I'm not doing something wrong, here's a proposal for a
modified TChain::Add :
Int_t TChain::Add(const char *name, Int_t nentries)
{
// Add a new file to this chain.
// name may have the following format:
// //machine/file_name.root/subdir/tree_name
// machine, subdir and tree_name are optional. If tree_name is
missing,
// the chain name will be assumed.
// name may use the wildcarding notation, eg "xxx*.root" means all
files
// starting with xxx in the current file system directory.
//
// if nentries < 0, the file is connected and the tree header read
in memory
// to get the number of entries.
// if (nentries >= 0, the file is not connected, nentries is
assumed to be
// the number of entries in the file. In this case, no check is
made that
// the file exists and the Tree existing in the file. This second
mode
// is interesting in case the number of entries in the file is
already stored
// in a run data base for example.
// NB. To add all the files of a TChain to a chain, use Add(TChain
*chain).
// case with one single file
if (strchr(name,'*') == 0) {
return AddFile(name,nentries);
}
// wildcarding used in name
Int_t nf = 0;
Int_t nch = strlen(name);
char *aname = new char[nch+1];
strcpy(aname,name);
char *dot = (char*)strstr(aname,".root");
const char *behind_dot_root = NULL;
if (dot)
{
if (dot[5] == '/')
behind_dot_root = dot + 6;
*dot = 0;
}
char *slash = strrchr(aname,'/');
if (slash) {
*slash = 0;
slash++;
strcat(slash,".root");
} else {
strcpy(aname,gSystem->WorkingDirectory());
slash = (char*)name;
}
const char *file;
void *dir = gSystem->OpenDirectory(gSystem->ExpandPathName(aname));
if (dir) {
TRegexp re(slash,kTRUE);
while ((file = gSystem->GetDirEntry(dir))) {
if (!strcmp(file,".") || !strcmp(file,"..")) continue;
//if (IsDirectory(file)) continue;
TString s = file;
if (strcmp(slash,file) && s.Index(re) == kNPOS) continue;
if (behind_dot_root != NULL && *behind_dot_root != 0)
nf += AddFile(Form("%s/%s/%s",aname,file,behind_dot_root),-1);
else
nf += AddFile(Form("%s/%s",aname,file),-1);
}
gSystem->FreeDirectory(dir);
}
return nf;
}
best regards,
André
--
------------------+----------------------------------
Andre Holzner | +41 22 76 76750
Bureau 32 2-C13 | Building 32
CERN | Office 2-C13
CH-1211 Geneve 23 | http://wwweth.cern.ch/~holzner/
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:55 MET