Discussion:
[ROOT] static - no memory
Jan Malinowski
2008-10-13 09:59:19 UTC
Permalink
Dear Rooters,

the function Rnd() (below) good work at many compilers. I have the
problem with static, and maybe const, in root macro (root ver. 5.18).
I received the error: "No memory for static..."

It is not much important problem for me. I may to do it at other way.
But this error give some discomfort at work.

Best regards,
Jan Malinowski

//===============================================================
/* Random number generator */
//===============================================================

double Rnd() {
const unsigned long a=397204094;
const unsigned long b=0;
const unsigned long c=2147483647;

static unsigned long x1;
static unsigned long x2=1.0;
double R;
x1=x2;
x2=(a*x1 + b) % c;
R=double(x2)/double(c);
return R;
}
//---------------------------------------------------------------
int main()
{
gROOT->Reset();
gStyle->SetOptStat(1110);

TCanvas* c1 = new TCanvas("c1","RNG",1,1,800,600);
TH1D* hist = new TH1D("hist","hrng", 50, 0.0, 1.0);

for(int i=0; i<10; ++i)
{
double x=Rnd();
hist->Fill(x);
}

hist->SetTitle("Xmax distr.;Xmax;dN/dXmax");
hist->Draw(); // it mean "HIST";
c1->Update();
}
//===============================================================
Rene Brun
2008-10-13 09:55:39 UTC
Permalink
Delete the statement
gROOT->Reset();

THIS SHOULD NEVER BE CALLED IN A NAMED MACRO !!!!!

Rene Brun
Post by Jan Malinowski
Dear Rooters,
the function Rnd() (below) good work at many compilers. I have the
problem with static, and maybe const, in root macro (root ver. 5.18).
I received the error: "No memory for static..."
It is not much important problem for me. I may to do it at other way.
But this error give some discomfort at work.
Best regards,
Jan Malinowski
//===============================================================
/* Random number generator */
//===============================================================
double Rnd() {
const unsigned long a=397204094;
const unsigned long b=0;
const unsigned long c=2147483647;
static unsigned long x1;
static unsigned long x2=1.0;
double R;
x1=x2;
x2=(a*x1 + b) % c;
R=double(x2)/double(c);
return R;
}
//---------------------------------------------------------------
int main()
{
gROOT->Reset();
gStyle->SetOptStat(1110);
TCanvas* c1 = new TCanvas("c1","RNG",1,1,800,600);
TH1D* hist = new TH1D("hist","hrng", 50, 0.0, 1.0);
for(int i=0; i<10; ++i)
{
double x=Rnd();
hist->Fill(x);
}
hist->SetTitle("Xmax distr.;Xmax;dN/dXmax");
hist->Draw(); // it mean "HIST";
c1->Update();
}
//===============================================================
Loading...