Dear Axel
Thank you for your answer and your explanation.
Most of the time I do:
TString str = Path2Name(treename,".","");
According to your explanation this should be ok.
However, in order to extract the tree names for R, I have created the following C-function:
void GetTreeNames(char **exten, int *gettitle, char **treenames)
{
// Get number of trees
int ntrees = 0;
TKey *key = 0;
TIter next(gDirectory->GetListOfKeys());
while ((key = (TKey*)next())) {
if (strcmp(key->GetClassName(), "TTree") != 0) continue;
if (!(strcmp((Path2Name(key->GetName(),".",";")).Data(), exten[0]) == 0 ||
strcmp(exten[0], "*") == 0)) continue;
ntrees++;
}//while
// Get tree names
TString names[ntrees];
ntrees = 0;
key = 0;
next.Reset();
while ((key = (TKey*)next())) {
if (strcmp(key->GetClassName(), "TTree") != 0) continue;
if (!(strcmp((Path2Name(key->GetName(),".",";")).Data(), exten[0]) == 0 ||
strcmp(exten[0], "*") == 0)) continue;
names[ntrees] = (*gettitle == 0) ? key->GetName() : key->GetTitle();
ntrees++;
}//while
for (int i=0; i<ntrees; i++) {
treenames[i] = (char*)(names[i].Data());
//? treenames[i] = strcpy(treenames[i], (char*)(names[i].Data()));
}//for_i
}
It is this function, which sometimes returns the strange result:
Do you think that this use of Path2Name() is ok?
How should I copy names[i] to treenames[i] in the last for-loop?
(I have tried strcpy() buth this did cause even more problems)
P.S.: BTW, as far as I understand, the memory for treenames[ntrees] should have been reserved by R,
however sometimes I get the following bus error when running my R package:
*** Break *** bus error
/Volumes/GigaDrive/CRAN/Workspaces/Exon/hutissues/u133p2/5163: No such file or directory.
Attaching to process 5163.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ............................................................................................. done
0x90029a67 in wait4 ()
========== STACKS OF ALL THREADS ==========
Thread 1 (process 5163 thread 0x113):
#0 0x90029a67 in wait4 ()
#1 0x90046d9b in system ()
#2 0x04a3945d in TUnixSystem::StackTrace ()
#3 0x04a3c7c9 in TUnixSystem::DispatchSignals ()
#4 0x04a3c8fd in SigHandler ()
#5 <signal handler called>
#6 0x010c0647 in Rf_allocVector (type=10, length=1) at memory.c:1970
#7 0x010410c1 in do_is (call=0x1b096a8, op=0x1819f90, args=0x2f90b24, rho=0x2f90b5c) at coerce.c:1636
#8 0x01097f60 in Rf_eval (e=0x1b096a8, rho=0x2f90b5c) at eval.c:492
#9 0x0109aa25 in do_if (call=0x1b096e0, op=0x180e460, args=0x1b096c4, rho=0x2f90b5c) at eval.c:945
#10 0x01097cfd in Rf_eval (e=0x1b096e0, rho=0x2f90b5c) at eval.c:463
#11 0x01099f88 in do_begin (call=0x1b09718, op=0x180ef04, args=0x1b096fc, rho=0x2f90b5c) at eval.c:1156
This may look as an error in the R function “allocVector()”, which is responsible for allocating the character vector
for treenames[ntrees], but I cannot believe that this function has a bug.
Best regards
Christian