Problem with a loop

Hi everyone, I’ve a for cycle

for (a=0;a<=23;++a){ 
...
}

but I’m having problems using it, because I don’t get error in the code but, sometimes ROOT runs the macro, other times it closes automatically without running it. How should it be possible?

Thanks
si-500274.root (2.7 MB)

calo.cpp (18.5 KB)


ROOT Version: 5.34/38
Platform: Windows


Your .cpp file had many C mistake. They are fixed in the attached version.

calo.cpp (8.0 KB)

Hi couet, thank you, but running your macro I have the same problem…

As it is on Windows may be @bellenot have some idea about it.
I ran your macro on mac with ROOT 6. I got many C++ errors.
I fixed them and now it runs fine, always, on my machine.

One thing you can try is to run your macro using Aclic

root[0] .x calo.cpp+
1 Like

Hi,

Yes, please run with ACLiC, it looks like the problem comes from the interpreter…

Cheers, Bertrand.

In the attachment there is the macro that I used on saturday and it worked (I got plots) …now I’m trying to run it and I’ve the same problems due to the for cycle

for (b=0;b<=23;++b){
...
}

…It’ s strange that it worked on saturday, but it isn’t working today :face_with_raised_eyebrow:

calo.cpp (15.4 KB)

si-500427.root (944.4 KB)

Using Aclic I get this error (caloc is your macro, but obiuvsly I get it also using mine).

To run with ACLiC, you need to have the Microsoft compiler to be installed and run from a Developer Command Prompt for VS2013, or call the vcvars32.bat batch script to properly set the environment variables.

Also have a look at the mods i did. in particular the declaration of timenamesuba … you declare it several in if statements and use it outside the if. It goes out of scope. that’s not valid C++. I will try (again) to modify your new macro.

also you do things like:

int c_YTitleOffset=1.55;

it should be:

double c_YTitleOffset=1.55;

@bellenote
is it this one https://www.microsoft.com/it-it/download/confirmation.aspx?id=30679 ?

@couet you are right for the declaration int c_YTitleOffset=1.55, the reason is that I first setted the values 1, later I changed to 1.55 and I forgot to change from int to double

Anyway, if I don’t use the for cycle the macro works…it looks like some problem due to the for cycle (especially because I get same problem with your macro).

No, you need the complete Visual Studio, not only the redistributable. And the version depends on which version of the ROOT binaries you installed on your system…

Looking at your code I found many C++ syntax mistakes but error one is really fatal and I do not know how to fix it. You have the line:

 		lemma->SetScanField(0);

but lemma is not declared …

@bellenot this one https://my.visualstudio.com/Downloads?q=visual%20studio%202012&wt.mc_id=o~msft~vscom~older-downloads ?

@couet… yes…I declared lemma

char fobject[200]= "lemma";
....
TTree *t=0;
		f->GetObject(fobject,t);
....

I don’t know, the link is not valid…

Yes…because I opened this page https://visualstudio.microsoft.com/it/vs/older-downloads/ then I clicked on the download button of visual studio 2012, but the download doesn’t work

Then you must instanciate your object with:

   t->SetScanField(0);

And this is very basic C/C++ :confused:

Then there is not much we can do. Try to fix the errors in your code

@bellenot thank you I fixed the

t->SetScanField(0);

Anyway there are things very strange

  1. If I don’t use the “for cycles” the macro works (See attachment)
  2. I’m trying to run the macro that I used on saturday but on saturday the for cycle worked, today it isn’t working
  3. Couet’s macro doesn’t work too (on my computer).

calo.cpp (18.7 KB)

I’m trying to fix the many errors you have in your code…