Getting TFile from user input

Hi,

I have a macro that opens a TFile where you input the path or name of the root file in the macro and plots the histograms.

That part of my code is below:
TFile* in_file = new TFile(“C:/Users/LeptoLab/Documents/CNC_Probe_Data/10.09.15/10.09.15 Changing voltages.root”);

Is there a way that when you run ROOT, it tells you to enter file name and it finds it for you.

Any example or help will be appreciated. Thank you. [-o<

Leo.

You can start ROOT the following way:

$ root file_name.root

Hi,

Sorry that’s not what I meant.

What I meant to say was, when you run the macro, is there a way for it to do this:

“Please enter file name:”

You enter it right there on the ROOT session and it finds the file instead of manually changing the macro to include the name of the file.

I hope I explained much better now.

Leo

That’s normal C++. have a look here:

cplusplus.com/doc/tutorial/basic_io/

section:

cin and strings

The example there works directly with root.


$ cat cinc.C
{
  string mystr;
  cout << "What's your name? ";
  getline (cin, mystr);
  cout << "Hello " << mystr << ".\n";
  cout << "What is your favorite team? ";
  getline (cin, mystr);
  cout << "I like " << mystr << " too!\n";
  return 0;
}

$ root cinc.C
   ---------------------------------------------------------------
  | Welcome to ROOT 6.05/03                   http://root.cern.ch |
  |                                  (c) 1995-2014, The ROOT Team |
  | Built for macosx64                                            |
  | From heads/master@v6-05-02-63-g1927dc4, Sep 16 2015, 17:11:26 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'    |
   ---------------------------------------------------------------

root [0] 
Processing cinc.C...
What's your name? Olivier
Hello Olivier.
What is your favorite team? France
I like France too!
root [1]