Re: [ROOT] Global variable scope question

From: Edward Chen (edward@SLAC.stanford.edu)
Date: Wed Sep 04 2002 - 07:03:30 MEST


Hi - I followed the procedure listed below in your example.  It doesn't
seem to work.  Instead of using Float_t like you do in your example, I use a

Bool_t cutLepCharge;

defined in cutplots.h.

Then I run:

{
gROOT->LoadMacro("cutplots.C++");
cutplots cut1;
gROOT->Macro("esigtight.cc"); // creates chain
cutLepCharge = kTRUE;
ntp1->Process(&cut1);
}

I get the following:

The value of cutLepCharge is 0

which is called in cutplots::ProcessCut().

I also set the value of cutLepCharge in my chain file esigtight.cc, which
is an unnamed macro.  That doesn't work either.

I'm using 3.03/08.  Any idea why this doesn't work?

-Ed


On Thu, 22 Aug 2002, Rene Brun wrote:

> Hi Ed,
>
> Let's take the example we have in $ROOTSYS/tutorials/h1analysis.h,C
> This is a simple example of a TSelector.
> We had the following declration in h1analyis.h, eg
> #include <TChain.h>
> #include <TFile.h>
> #include <TSelector.h>
>
> R__EXTERN Float_t R2;  //we add this line
>
> class h1analysis : public TSelector {
>
> then in h1analysis.C, we declare a default value for R2, eg:
>
> TH1F *hdmd;
> TH2F *h2;
>
> Float_t R2=123.456; //we add this line, that' all
>
> Now run the following session
> root > .L h1analysis.C++
> root > h1analysis h1; //this will set the default value for R2=123.456
> root > R2 = 44.33; //we set a new value via the interpreter
> root > .x h1chain.C this creates a TChain with 4 files (see h1analysis
>                      comments)
> root > chain.Process(&h1);
>
> at this point the TSelector will execute with the new value of R2.
>
> Rene Brun
>
>
> On Wed, 21 Aug 2002, Edward Chen wrote:
>
> > Hi Rene - I don't explicitly call gROOT-Reset() in my selector.  It's
> > pretty much the standard selector generated from TChain::MakeSelector(),
> > with a couple modifications that I don't think call gROOT->Reset().
> >
> > However, when I do .g at the command line, I see (for example):
> >
> > (compiled)          0x2ae4d680 const Int_t kMaxInt=2147483647
> >
> > vs.
> >
> >                  11 0x8733ca0  Float_t R2=0.607421
> >
> > so my R2 variable doesn't have this (compiled) status.  And I can print
> > out the value of kMaxInt from my selector.  R2 is declared at the command
> > line (or via unnamed macro) - how do I get it into compiled status?
> >
> > Thanks.
> >
> > -Ed
> >
> > On Wed, 21 Aug 2002, Rene Brun wrote:
> >
> > > Hi Ed,
> > >
> > > If you define a global variable with CINT (eg float R2), this variable
> > > must be visible in any interpreted function.
> > > My guess is that you are calling "gROOT->Reset()" somewhere
> > > in your selector.
> > >
> > > A CINT global variable cannot be seen from the compiled code
> > > if it is not declared to CINT as well (like we do for globals
> > > like gFile, gDirectory,etc).
> > >
> > > Rene Brun
> > >
> > > On Tue, 20 Aug 2002, Edward Chen wrote:
> > >
> > > > Hi - I have a global variable which shows up when I do .g:
> > > >
> > > >
> > > >                  11 0x8733bf0  Float_t R2=0
> > > >
> > > >
> > > > I want to access the value of R2 in TSelector::ProcessCut().  Is that
> > > > possible?  I'm getting the following error message:
> > > >
> > > >
> > > > /data1/babar/edward/root/temp.C:67: `R2' undeclared (first use this
> > > > function)
> > > >
> > > > Thanks.  (I'm using ROOT 3.03/06)
> > > >
> > > > -Ed
> > > >
> > >
> > >
> >
>
>



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:06 MET