Is it possible to put an "int" variable in a title

Hi,

in my program i have a loop with an int variable as a counter. is it possible to create ## folders labelled “Run n° ##”? (## is the n° of the run)

this is because i need to store 6 trees in each folder every run.

Use Form("“Run n° %d”,index)

Philippe.

Thank you very much!

can you explain me the meaning of “index” (or tell me what part of the user guide i have to read) ?

Amir

index was meant to refer to your variable holding the information [quote] (## is the n° of the run)[/quote]
Philippe.

Sorry to bother again. i tryed to use Form(…) but even if i didn’t get error messages, the folders weren’t been created.

Since i’m very newbye of ROOT,where i can get more informations on this function?

Thank you

How did you try?

How do you assert this?

[quote]Since i’m very newbye of ROOT,where i can get more informations on this function?[/quote]I am not really sure which functions you are using (In particular since sometimes there is a confusion between TFolder and TDirectory).
So, could you please provide an explicit example of what you are trying and how it fails?

Cheers,
Philippe

After some research on the net i think i discovered how to create the folders with Form().
i have this program :

run++;//this is my counter

fOutputFile->cd();
TFolder folder1;
folder1.SetName(Form("Run n %d",run));
folder1.Write();

Now the folders are created (empty as expected) but they have all the same name: “Run n 0” but i know for sure that the counter works properly.

What can i do?
Thank you

Amir

As requested by Philippe, please send the shortest possible RUNNING script reproducing your problem.

Rene

Since i think it’s not possible to send a running part of my program because it’s an Auger Offline module, i wrote this little script:

[code]#include

int main(){
TFile *fOutputFile;

fOutputFile = new TFile(“output.root”, “RECREATE”);

for(int run=0;run<20;run++)
{

fOutputFile->cd();
TFolder folder1;
folder1.SetName(Form("Run n° %d ",run));

folder1.Write();
}

return 0;
}[/code]

and everithing behaved as expected, with the creation of 20 empty folders.

The only thing that differs is the run variable,which in my program is iterated by the Offline software.

So maybe there is a problem in the ROOT implementation in the Offline.
I have to check it.

Thank you
Amir

A few ideas for you to try:

  1. Instead of using SetName, use SetTitle. The SetName is a bit itchy when you use a name string with whitespaces.
  2. If you absolutely have to use SetName, then try something else like joining the words in the string without spaces (and possibly using capitals SuchAsInThisExample), or then using underscores _ between words.

Hope this helps :slight_smile:

I usually create histograms in loop, and I also have to name each histogram using the looping variable. This is how I usually do it:


char naam[100];
char title[100];

TH1F *Plane[9];

for (int i=0; i<9; i++)
{
	    sprintf(naam,"Plane %d",i);
	    sprintf(title, "Number of hits in plane %d for various high voltages; High Voltage /V; count", i);
	    plane[i] = new TH1F(naam,title, 7,1750,2450);
}

It is a bit long-winded, but i didnt know there was an easy short-cut like the one explained. Anyway, if that doesn’t work for you, you might want to try this method.
I can’t help you with how to make the transition from histograms to TFolder objects, because I’m not familiar with them.

I found an easy way to create titles or anything needs const char arrays.

Now i use ostringstream

#include
ostringstream pippo;
int num =14;
pippo<<“this is the number: “<<num<<” i want”;
cout<<pippo.str();//this is a string
pippo.str().c_str();//this is a char array

the output will be:“this is the number :14 i want”

Amir