TFile

I have a program that open a file (the user input the name of the file … as been solicited).
I need the file to make various types of analysis … anyone of them are functions.
Well, there is a way to record the name of the file in a variable that could be used after by any function ?

Thks

Cheers,

JP

Hi,

You need to either use a global variable or pass as a parameter either a pointer or a reference to an object that can be passed to other functions.

Cheers,
Philippe.

Yea … I had allready try this but I couldn’t make the things work …

Hi Joao,

I strongly recommend that you try to find a C++ specialist that you can meet in person to discuss the issues you currently have. You latest questions are very general (i.e. they do not seem require any knowledge of ROOT to investigate). In addition you are not specific enough in your question for us to be able to decipher what might be going wrong. (My previous answer to your general question still stand … and I have not the beginning of a clue on how/why it failed for you).

Cheers,
Philippe.

I could try to explain …
I open a file with TFile Object but my problem is that I want to save the name of the file in a variable that could be used after…
I have something like this …

void main()
{
char iname;
cout << “input the name of the file to analyze …” << endl;
cin >> iname;

F1();
F2();

and so on … (it depends on the type of analysis required)

}

void F1()
{
cout << iname << endl;

TFile *file1=new TFile(iname, …);


}

that’s something like this that I want …

the user input the name of the file
them the program analyse it … accordlly with the the type of analysis selected … avaiible in a menu

thks

Cheers

JP

that won’t be correct for a filename (unless all your files name are only 1 character long).
Try a string.

void F1() { cout << iname << endl;
Did you try something as simple as

void F1(const string &iname) { cout << iname << endl;
What did you actually try???

Cheers,
Philippe.

Well it’s a mistake … beacuse what I want to write is char *iname …
I try your suggestion but inside the ROOT it seems that doens’t work …

I only want to know a way to record into a variable the name of one file … intruduced by the user (only one time) … and after that I pass the value of this variable into the functions that I was builded …

Cheers,

JP

Yes !?? How does it fail? What did you try? It is hard to help you out when your issue stay so vague.

As I send a global variable would solve your problem (or maybe a function static).
I still think you would benefit from seating down with a C++/programming expert and discuss this issue face to face.

Cheers,
Philippe.

Yeah
but I know how to do that in C++ … and in C++ it works fine …
but when I try it in ROOT everything works bad …

Cheers

JP

but when I try it in ROOT everything works bad …
Except for forgetting to create a dictionary for some symbol, there are no reason why something which in C++, would not work when also using ROOT. You do not provide enough information to have any clue on what your problem is.

Philippe

JP, you should compile your programs instead to trying to make ROOT
macros out of them. I never use macros because if you comile a program you
can use all the power and flexebility of C++, use any external
librairies… just do anything including linking ROOT libraries and using
anything from ROOT :smiley: If you stick only to macros you often become limited
in what you can do :frowning:

If all your program is one file MyAnalysis.C this is a simple make file showing how
to compile it with ROOT libraries:

=========================

PROGRAM_NAME = MyAnalysis

ROOTLIB = $(shell root-config --glibs) -lMinuit -lpthread -lThread
LIBS = -L/usr/X11R6/lib -lXpm -lXext -lX11 -lm -ldl -rdynamic -lcrypt

exe : $(PROGRAM_NAME).C
g++ -o $(PROGRAM_NAME).exe
-I${ROOTSYS}/include
$(ROOTLIB)
$(LIBS)
$(PROGRAM_NAME).C