Syntax for reading filenames from an ASCII file list

Greetings all,

I am trying to write a simple script to read file names from a list file, but I can’t get the syntax correct.

My attempt at the script is just

{ TTree *T = new TTree("DataFile","input file names from list"); nlines = T->ReadFile("Input_files.txt","filename"); printf(" found %d lines\n",nlines); T->GetEntry(0); TString Qqqq = T->GetLeaf("filename")->GetValue(0); printf(" filename is %s \n",Qqqq); }

And the list I am trying to read just contains three entries

[quote]XZXYZ1
XZXYZ2
XZXYZ3[/quote]

The error messages I get are as follows:

[quote]root [1] .x Read.C
found 0 lines
Error: Ambiguous overload resolution (10000,2) C:\Fit_test_folder_ru98\Read.C(6)
Calling : TString::TString(Double_t);
Match rank: file line signature
ffffffff (compiled) 0 TString TString::TString(const TSubString&);
ffffffff (compiled) 0 TString TString::TString(char,Ssiz_t);

  • 10000 (compiled) 0 TString TString::TString(char);
    ffffffff (compiled) 0 TString TString::TString(const string&);
    ffffffff (compiled) 0 TString TString::TString(const char*,Ssiz_t);
    ffffffff (compiled) 0 TString TString::TString(const char*);
    1000001 (compiled) 0 TString TString::TString(const TString&);
  • 10000 (compiled) 0 TString TString::TString(Ssiz_t);
    ffffffff (compiled) 0 TString TString::TString();
    ffffffff (compiled) 0 TString TString::TString(const char*,Ssiz_t,const char*,Ssiz_t);
    *** Interpreter error recovered ***[/quote]

Any guidance you can give on what is wrong with my script would be greatly appreciated. Eventually I will want to loop through the file names, but for now I just want to read the first one in the list.

Regards

Hi,

do you really need a TTree? Why don’t you simply use ifstream and loop over all files? See e.g. cplusplus.com/doc/tutorial/files/

Cheers, Axel.

Dear Axel,

I take your point - I don’t actually need a TTree for the file list task. The example that you have linked to will do the job I want perfectly well.

But just for future reference - if I was to try to read a list of character strings into a TTree (for some reason) - why wouldn’t my script above work?

How did I create a [quote]Error: Ambiguous overload resolution (10000,2)[/quote] and what do I need to do to fix it?

My curiousity will just nag at me if I don’t figure out why my example script above doesn’t work.

Regards

TLeaf::GetValue returns a double. This cannot match with a string.
I suggest replacing your statement

TString Qqqq = T->GetLeaf("filename")->GetValue(0); by

TString Qqqq = (char*)T->GetLeaf("filename")->GetValuePointer();
Rene

Dear Rene,

Thank you for that - my curiousity is now satisfied and my problem is solved.

Regards