Pointer Issues

From: Christopher James Schilling <cschill_at_slac.stanford.edu>
Date: Tue, 21 Jun 2005 17:13:25 -0700


Hi, I have the following, relatively simple piece of code that I am trying to run in Root, V4.03/02 on SL3.

#include "TFile.h"
#include  "TString.h"
#include  "TH1.h"
#include "iostream.h"

TFile* f=new TFile("./DAT/slg_ecalc.root");

void getHIST(TH1F* hist, int i) {

   TString emcobj;
   emcobj = "emc1"; emcobj+=i;
   hist = (TH1F*)f->Get(emcobj);
   //hist->Draw();
}

void get() {

   TH1F* hist;
   getHIST(hist, 2);
   cout << " hist = " << emechist << endl;    hist->Draw();

}

If I issue the command
>>> root -l get.C -q

I get the following output

emechist = 0
Error: illegal pointer to class object emechist 0x0 191 FILE:get.C LINE:20

If I issue the command (trying to Compile)
>>> root -l get.C+ -q

I get a segmentation violation:

 emechist = 0  

It seems as if the histogram is out of scope outside the function. The funny thing is if I change
void getHIST(TH1F* hist, int i) to void getHIST(TH1F&* hist, int i) the macro works, and the histogram is drawn, but I cannot compile since it is illegal to have a pointer to a reference.

Any ideas??
Cheers
Chris S Received on Wed Jun 22 2005 - 02:13:33 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:09 MET