Accessing file name in TChain->Draw()

Hi,

I have a number of files with a running number in the file name that I chain together. Now I would like access this running number in a TChain-Draw() command. I tried to write a method like this

double GetSubRunID() {
   TObject *oFile = gROOT->GetListOfFiles()->FindObject(filename);
  if ( oFile ) {
       TString subRun = oFile->GetName();
       TString subRunID = subRun(subRun.Last('/')+24,8);
       num = ...
  }
  return num;
};

which I then want to call ( Chain->Draw(GetSubRunID()) ) but the problem is that I have to specify the exact filename which I actually want to get back. It seems that wildcards or regular expression don’t work.

Also, is there a more direct way to get the name of the file that is currently been processed in a chain?

Regards, Alexander

Ok, I just found the answer myself. Here is the code for those interested:

double GetSubRunID() {
  double subRunID = -1;
  TChain *ch = gROOT->GetListOfSpecials()->FindObject("tree");
  if ( ch ) {
    TFile* file = ch->GetFile();
    TString subRun = file->GetName();
    subRun = subRun(subRun.Last('/')+24,8);
    if ( subRun.IsDigit() )
      subRunID = subRun.Atoi();
    else
      std::cout << "SubRun number not a number" << std::endl;
  }
  return subRunID;
};

Unfortunately, this slows down the program by a factor 2. Is it the GetListSpecials that takes so much time?

Regards, Alexander

Hi,

In your case (single thread), you can probably try:

double GetSubRunID() { double subRunID = -1; if ( ch ) { TFile* file = gFile; TString subRun = file->GetName(); subRun = subRun(subRun.Last('/')+24,8); if ( subRun.IsDigit() ) subRunID = subRun.Atoi(); else std::cout << "SubRun number not a number" << std::endl; } return subRunID; }; Cheers,
Philippe