Passing arguments to a function

Hi,

I know that I’ve asked this question before but my gui has to be completed in 2 weeks and despite trying I can not display my histograms. How do I pass the name of the chain that I type into the textentry to this function so that the function knows that the entered name is equal to the argument “chainname” and uses it to carry out the instructions written within it.

I currently have:

gROOT->ProcessLine(Form(fText->GetBuffer()->GetString()));
fFrame->AddHistArray(“chainname”, “arrayname”,“plotname”);

However, when I try to display the histogram I get:

Warning in H1AnalysisExample::GetChain: NoSuchChain named chainname found in Analysis. Possibilities are:
OBJ: H1AnalysisDataChain Data H1AnalysisDataChain : 0 at: 0x9600740
OBJ: H1AnalysisExampleModelChain Django H1AnalysisExampleModelChain : 0 at: 0x9756fb0

Reading chain
Getting histos from chain

*** Break *** segmentation violation

I would be grateful for your help.

Regards,

Lisa

Hi Lisa,

First, there is an error in:
gROOT->ProcessLine(Form(fText->GetBuffer()->GetString()));
It should be
gROOT->ProcessLine(Form("%s",fText->GetBuffer()->GetString()));

Next, if you have only the chainname in the text entry the command above will do nothing. You might want to process the second line you have provided.

In this case do:
gROOT->ProcessLine(Form("((Class_Name_Of_fFrame *)0x%lx)->AddHistArray(%s,%s,%s);", fFrame,fText->GetBuffer()->GetString(), arrayname_ptr, plotname_ptr));

Cheers, Ilka

Hi Ilka,

Thank you for your suggestion. I have tried:

const char* arrayname = TString(arrayname);
const char* plotname = TString(plotname);
gROOT->ProcessLine(Form("((MainFrame*)0x%lx)->AddHistArray(%s,%s,%s);", fFrame,fText->GetBuffer()->GetString(), arrayname, plotname));

but two things happen and I’m unsure of how to solve them. First, I get the errors:

Error: Symbol Data is not defined in current scope FILE:(tmpfile) LINE:1
Error: Symbol P‘a is not defined in current scope FILE:(tmpfile) LINE:1
Syntax Error: P‘a@ FILE:(tmpfile) LINE:1
Warning: Empty arg3 FILE:(tmpfile) LINE:1

Data is not the name of an object, it is the name of a chain that I want to pass to the AddHistArray function, this function then knows what to do with the name and how to create the histogram. Do you know how I can solve this error?

The second problem is that when I press the close button, ROOT gives me a list of errors. I have used a degugger and got the error:

#0 0x00000400 in ?? ()
#1 0x4272ea91 in TGTextButton::~TGTextButton() ()
from /opt/products/root/4.00.08/lib/libGui.so.4.00
#2 0x4001f338 in ~MainFrame (this=0x94686e8) at MainFrame.C:104
#3 0x4002104d in ~MyDialog (this=0x9722478) at MyDialog.C:71
#4 0x40021185 in MyDialog::CloseWindow() (this=0x948fda0) at MyDialog.C:80
#5 0x4002913c in G__MyDialogDict_385_7_2 (result7=0x94b3bf8, funcname=0x0,
libp=0x979d124, hash=0) at i586_linux24/MyDialogDict.C:418

Have you any idea what this refers to?

Many thanks for your help and patience.

Regards,

Lisa

I am confused.  What do you expect from this code?  You define arrayname and then pass it to the TString constructor and then assign something back to it?  In addition if you have
[code] const char* arrayname = TString(some_string);[/code]
This results in the likely usage of deleted memory.  This is because TString(some_string) creates a __temporary object__ which is then deleted so that arrayname nows points to a memory space that was allocated and then deleted by the temporary TString object.

We are missing quite a few details to be really helpfull (especially I am confused and whether chainname is supposed to be the name of variable and the name of an object or something else).
Anyway to most ressemble the tiny code snippet you mentioned you might want to try:
[code]gROOT->ProcessLine(Form("((MainFrame*)0x%lx)->AddHistArray(\"%s\",\"%s\",\"%s\");", fFrame,fText->GetBuffer()->GetString(), arrayname, plotname));[/code]

[quote]Error: Symbol P‘a is not defined in current scope FILE:(tmpfile) LINE:1[/quote]
I suppose that this was due to your weirdiss definition of arrayname (and plotname).

Philippe.

I am confused. What do you expect from this code? You define arrayname and then pass it to the TString constructor and then assign something back to it? In addition if you have

This results in the likely usage of deleted memory. This is because TString(some_string) creates a temporary object which is then deleted so that arrayname nows points to a memory space that was allocated and then deleted by the temporary TString object.

We are missing quite a few details to be really helpfull (especially I am confused and whether chainname is supposed to be the name of variable and the name of an object or something else).
Anyway to most ressemble the tiny code snippet you mentioned you might want to try:

I suppose that this was due to your weirdiss definition of arrayname (and plotname).

Philippe.

Hi Philippe,

Thank you for you help. The line of code that you suggested worked, I can now display my histograms and my project is almost completed and ready to be submitted. I have one further request if you don’t mind helping me out? I have to write about what this line of code does.

gROOT->ProcessLine(Form("((MainFrame*)0x%lx)->AddHistArray("%s","%s","%s");", fFrame,fChainName->GetBuffer()->GetString(), fArrayName->GetBuffer()->GetString(),fPlotName->GetBuffer()->GetString()));

I know that gRoot->process line is equivalent to typing a command in the command promt and that Form creates a string, but what does 0x%lx mean?

Thanks once again.

Regards,

Lisa

Hi Lisa,

[quote=“lbdwyer”]I know that […] Form creates a string, but what does 0x%lx mean?[/quote]Under unix you can type “man 3 printf” to read about the syntax (because Form uses the printf syntax). Form(“0x%lx”,p) means print “0x” and then the argument (i.e. p) as a long (l) hex (x) number. So you’ll get what you might know from Cint: “0x67ac85” or something. It’s just the common way to transform a pointer into a string; the leading “0x” signals that the following characters are in hexadecimal (base 16) notation - that’s where the a…f (10…15) come from.
Axel.

Thanks, Axel.