Re: pointer defined but ROOT complain "not defined"

From: wxie <wxie_at_purdue.edu>
Date: Fri, 6 Jan 2012 08:53:05 -0500


Yeah, compiling the code is fine but one need to add a lot of header file at the beginning for each macro. This is OK for complicated macros. For simple macro, a collection of prompt command would certainly a lot more convenient.

Cheers
--Wei

On 1/6/2012 5:58 AM, Chris Jones wrote:

> Marcelo Zimbres wrote:

>> Hi wxie,
>>
>> >{
>> > TFile f("oo.root");
>> > h->Divide(h0);
>> > h->Divide(h1);
>> >}
>>
>> Since this is not valid C++ code, I think it would be a better idea
>> to first get the hists from the file(I do not know why cint is not
>> doing it itself):
>>
>> {
>> TFile f("oo.root");
>> h->Divide((TH1 *) f.Get("h0"));
>> h->Divide((TH1 *) f.Get("h1"));
>> }
>
> Note that a similar thing should be done for h as well, since it 
> should also not be defined in this scope, since it is created in the 
> first scope
>
> {
>   TH1F* h = new TH1F("h", "", 1, 0, 1);
> ....
> }
> // h (should not be) not define
>
> and thus is only valid there, not in the second scope.
>
> For reasons like this I prefer to compile my macros, not use cint 
> interpret them (or use PyRoot), since it tends to let though quite a 
> few non-valid C++ constructs ...
>
> Chris
>

>>
>> Cheers,
>> Marcelo
>>
>> 2012/1/6 wxie <wxie_at_purdue.edu <mailto:wxie_at_purdue.edu>>
>>
>>
>> One more input is that this issue happens only when the histograms
>> are read from a file. The following macro have no problem to run:
>>
>>
>> {
>> TH1F* h = new TH1F("h", "", 1, 0, 1);
>> h->Fill(0.5);
>> h->Sumw2();
>>
>> TH1F* h0 = new TH1F("h0", "", 1, 0, 1);
>> h0->Sumw2();
>> h0->Fill(0.5);
>>
>> TH1F* h1 = new TH1F("h1", "", 1, 0, 1);
>> h1->Sumw2();
>> h1->Fill(0.5);
>>
>> h->Divide(h0);
>> h->Divide(h1);
>>
>> }
>>
>>
>>
>> On 1/5/2012 5:40 PM, wxie wrote:
>>
>> I run the following macro producing a file "oo.root".
>>
>> {
>> TFile f("oo.root", "recreate");
>> TH1F* h = new TH1F("h", "", 1, 0, 1);
>> h->Fill(0.5);
>> h->Sumw2();
>>
>> TH1F* h0 = new TH1F("h0", "", 1, 0, 1);
>> h0->Sumw2();
>> h0->Fill(0.5);
>>
>> TH1F* h1 = new TH1F("h1", "", 1, 0, 1);
>> h1->Sumw2();
>> h1->Fill(0.5);
>>
>> h->Write();
>> h0->Write();
>> h1->Write();
>> f.Close();
>> }
>>
>> then I run the following macro:
>> {
>> TFile f("oo.root");
>> h->Divide(h0);
>> h->Divide(h1);
>> }
>>
>> and got an error message:
>>
>> root.exe [1] h->Divide(h0);
>> root.exe [2] h->Divide(h1);
>> Error: Symbol h1 is not defined in current scope (tmpfile):1:
>> *** Interpreter error recovered ***
>>
>> People usually bypass it by defining another pointer, e.g. the
>> following macro:
>> {
>> TFile f("oo.root");
>> h->Divide(h0);
>> TH1F* h2 = h1;
>> h->Divide(h2);
>> }
>>
>> Is there a way not to redefine this new pointer?
>>
>> Thanks
>> --Wei
>>
>>
>>
>>
>>
>>
>>
>>
>>

> Received on Fri Jan 06 2012 - 14:53:15 CET

This archive was generated by hypermail 2.2.0 : Fri Jan 06 2012 - 23:50:01 CET