Memory can't handle a static value?

Hello!

I’m trying to run this script, but when I try to it says:

Warning: Automatic variable Int i is allocated light1.cpp:35:
Error: No memory for static Int i\0\0 light1.cpp:35:
*** Interpreter error recovered ***

Since it’s just a static value isn’t it a bit odd that there’s no memory for it? This is my script, the static value it’s the ProcessTracks part:

TGeoManager *geom = new TGeoManager(“geom”,“Optics Demo”);
Bool_t Ray=false;
Bool_t Lenses=true;
Int_t MAXPOINT=10;
gSystem.Load(“libPhysics.so”);

void light1() {
DefineGeometry(geom);

 geom->InitTrack(0,0,35,0,0,1);
 ProcessTracks(geom);
 for (double r=20; r<=70 ; r+=10) {
    for (double phi=0; phi<2.0*TMath::Pi(); phi+=TMath::Pi()/2) {
      Double_t th=0; 
      geom->InitTrack(r*cos(phi),r*sin(phi),-99,sin(th)*cos(phi),sin(th)*sin(phi),cos(th));
      ProcessTracks(geom);
    }
 }

 if (Ray) {
    geom->DrawTracks();
    geom->GetTopVolume()->Raytrace();
 } else {
    geom->SetNsegments(125);
    geom->GetTopVolume()->Draw("ogl");
    DrawTracks3D(geom);
 }

}

void ProcessTracks(TGeoManager geom){
TVector3 point,dir,norm;
point.GetXYZ(geom->GetCurrentPoint());
dir.GetXYZ(geom->GetCurrentDirection());
static Int_t i=0;
Int_t tid=geom->AddTrack(i,22,new TParticle());
geom->SetCurrentTrack(tid);
TVirtualGeoTrack track = geom->GetCurrentTrack();
if (i == 0) track->SetLineColor(kBlue);
else track->SetLineColor(kRed);
track->AddPoint(point[0],point[1],point[2],0);
// ********* superficies seguintes **************************
for (int j=1; j<=MAXPOINT ; j++) {
geom->SetStep(1);
geom->Step();
Double_t n1=geom->GetCurrentNode()->GetMedium()->GetMaterial()->GetDensity();
geom->FindNextBoundaryAndStep(10000);
Double_t n2=geom->GetCurrentNode()->GetMedium()->GetMaterial()->GetDensity();
norm.GetXYZ(geom->FindNormal());
point.GetXYZ(geom->GetCurrentPoint());
track->AddPoint(point[0],point[1],point[2],j);
if (geom->IsOutside()) break;
if (n2 == 0.0) {
dir=dir-2
(dir
norm)*norm;
} else {
cout << " n1="<< n1 << " n2="<< n2 << endl;
break;
}
geom->SetCurrentDirection(dir[0],dir[1],dir[2]);
}
i++;
}

void DefineGeometry(TGeoManager *geom){
TGeoMaterial *vacuum = new TGeoMaterial(“vacuum”,0,0,1.0);
TGeoMaterial *Fe = new TGeoMaterial(“Fe”,55.84,26.7,0.0);
TGeoMaterial *glass = new TGeoMaterial(“Glass”,55.84,26.7,1.5);
TGeoMedium *Air = new TGeoMedium(“Air”,0,vacuum);
TGeoMedium *Iron = new TGeoMedium(“Iron”,1,Fe);
TGeoMedium *Glass = new TGeoMedium(“Glass”,2,glass);
TGeoVolume *top = geom->MakeBox(“top”,Air,200,200,200);

geom->SetTopVolume(top);
geom->SetTopVisible(0);

TGeoVolume *s1 = geom->MakeSphere(“s1”,Iron,400,405,0,12,0,360);
s1->SetTransparency(50);
top->AddNode(s1,2,new TGeoTranslation(0,0,-225));
TGeoVolume *m2 = geom->MakeEltu(“m2”,Iron,18,22,1);
m2->SetTransparency(50);
TGeoRotation *r2=new TGeoRotation();
r2->SetAngles(0,45,0);
top->AddNode(m2,3,new TGeoCombiTrans(“combi”,0,2,0,r2));

TGeoTranslation *t1= new TGeoTranslation(“t1”,0,0,-70);
t1->RegisterYourself();
TGeoTranslation *t2= new TGeoTranslation(“t2”,0,0,70);
t2->RegisterYourself();
TGeoVolume *s1 = geom->MakeSphere(“S1”,Glass,0,75,0,90,0,360);
TGeoVolume *s2 = geom->MakeSphere(“S2”,Glass,0,75,90,180,0,360);
TGeoCompositeShape convex = new TGeoCompositeShape(“convex”,"(S1:t1)(S2:t2)");
TGeoVolume *lens1 = new TGeoVolume(“LENS1”,convex,Glass);
TGeoRotation *r3=new TGeoRotation();
r3->SetAngles(0,90,0);
if (Lenses) top->AddNode(lens1,4,new TGeoCombiTrans(“combi3”,0,-40,0,r3));

geom->CloseGeometry();
}

void DrawTracks3D(TGeoManager *geom){
TIter titer(geom->GetListOfTracks());
TGeoTrack *track2;
Double_t x,y,z,t;
while (track2= (TGeoTrack *)titer.Next()) {
TPolyLine3D *l = new TPolyLine3D(track2->Size(0,1000));
for (Int_t i=0 ;iSize(0,1000) ; i++) {
track2->GetPoint(i,x,y,z,t);
l->SetPoint(i,x,y,z);
}
l->SetLineColor(track2->GetLineColor());
l->Draw(“same”);
}
}

I appreciatte all the help someone can give me here please =)

My best regards
Pedro Gordo

Hi,

I totally agree that this is weird! Usually moving the static variable declarations up will help. But in your case I suspect this to be a CINT side effect of the wrong lines
point.GetXYZ(geom->GetCurrentPoint());
dir.GetXYZ(geom->GetCurrentDirection());

Could you fix your script (e.g. using the compiler’s error messages with .L light1.cpp+) and then try again?

Cheers, Axel.

I moved the “static Int_t i=0;” further up, and it did solved the problem! Now the problem is that the vectors point and dir are zero. I thought that when I did:
point.GetXYZ(geom->GetCurrentPoint());
dir.GetXYZ(geom->GetCurrentDirection());
the Carray would return the coordinates where the tracking currently is, and save them on the TVector3 vectors. Seems like it doesn’t… What am I doing wrong?

You are letting two getters work against each other: one tries to get the TVector3’s XYZ and put it into an array provided by the called. The array you provide is the const array returned by geom when you ask it for its position. Const means it cannot be changed. So what you are doing is similar to gettime() = sin(1.2): gettime returns something, it doesn’t set anything.

So you want to use the Set… family of functions instead of Get… on the vector, because you want to set its values.

Cheers, Axel.

Thanks! Problem solved! 8) Sorry for the noob questions :blush: