.rootlogon.C

When I run this in CINT:

TFile *_file0 = TFile::Open("wood_2.7_0.55_48mln.root");
  if(gDirectory->Get("scan")!=NULL) {
   scan->SetAlias("costh","-(z-z1v)/sqrt((x-x1v)**2+(y-y1v)**2+(z-z1v)**2)");
  }

it runs fine and sets the alias.

However, if I place the IF condition in my .rootlogon.C, and then do (from the command line)

root wood_2.7_0.55_48mln.root
it doesn’t get executed.

My guess is – it’s probably because the .root file gets loaded AFTER .rootlogon.C is executed.

Well, is there a way to reverse this? To force TFile::Open() to go first?

p.s. I realize that this is somewhat confusing…my final goal is to get an alias set up for the TTree scan, IF that tree is present.

It looks like you are wanting to open root in a certain “ready” state depending on the command-line arugment (the root file). My suggestion would be to write a short macro that you would call, e.g.:

// SetScan.C
void SetScan(TString fname)
{
TFile *_file0 = TFile::Open(s);
  if(gDirectory->Get("scan")!=NULL) 
  {
   scan->SetAlias("costh","-(z-z1v)/sqrt((x-x1v)**2+(y-y1v)**2+(z-z1v)**2)");
  }
}

I don’t know if it’s possible to do this with an “unnamed” macro, so that stuff would go into the global scope.

Jean-François