Using SetBranchAddress for TTree

Hi folks,
I have been using a script for some time now without a problem, but mysteriously, I am now recieving an error when attempting to set addresses:

Error: illegal pointer to class object T 0x0 120 FILE:submit.C LINE:33
*** Interpreter error recovered ***

Here is a variant of the macro I am using that reproduces my problem:

[code]{

gROOT->Reset ();
cout << "Loading Physics Library: ";
gSystem->Load (“libPhysics”);
cout << "complete " << endl << endl;

// Connect to file containing TTree
cout << "Opening ROOT file: ";
TFile f (“momdat.root”);
cout << “complete” << endl << endl;

// Read Tree named “warmup” in memory. Tree pointer is assigned the name T
cout << "Extracting ROOT tree: ";
TTree T = (TTree)f.Get(“warmup”);
cout << “complete” << endl << endl;

// Create a timer object to benchmark this loop
TStopwatch timer;
timer.Start ();

//////////////////////////////////////////////////////////////////////////////

cout << "Creating Objects to hold event information: ";

float KpX;

//////////////////////////////////////////////////////////////////////////////

// Address Book
cout << "Setting Addresses: ";

T->SetBranchAddress (“KpX”, &KpX);

cout << "Loop over event entries: " << endl;

Int_t nentries = (Int_t) T->GetEntries ();

for (Int_t i = 0; i < 10 /nentries/; i++)
{

  T->GetEntry (i);

  cout << KpX << endl << endl;

}

cout << “Loop over entries complete” << endl << endl;

cout << "Closing ROOT files: ";
f.Close ();
cout << “complete” << endl << endl;

// Stop timer and print results
cout << "Stop Timer: ";
timer.Stop ();
cout << “complete” << endl << endl;
//Float_t mbytes = T->GetTotBytes()*1.e-6;
Double_t rtime = timer.RealTime ();
Double_t ctime = timer.CpuTime ();

printf (“RealTime=%f seconds, CpuTime=%f seconds\n”, rtime, ctime);

f.Close ();
}
[/code]

Any insight that could be offered would be greatly appreciated.

Johnny

TTree *T = (TTree*)f.Get("warmup"); Are you sure you spelled the name of the TTee correctly? Try:

TTree *T = (TTree*)f.Get("warmup"); if (T==0) { cerr << "Can not find the TTree warmup in " << f.GetName() << endl; return 0; }
Cheers,
Philippe.