Problem with sscan

Hi I am beginner in using ROOT, mybe for y is trivial but I do not manage to make it work a simple thing.
I have a ascii file with 8 columns ( file dumped from an SQLDB at Text(TAB delimited)) and I am trying to make a tree:

hfile = TFile::Open(filename,“RECREATE”);
TTree *qa = new TTree(“qa”,“TestBuilt”);

qa->Branch(“Index”, &Index, “Index/I”);
qa->Branch(“FHS”, &FHS, “FHS/F”);
qa->Branch(“Spe”, &Spe, “Spe/F”);
qa->Branch(“STI”, &STI, “STI/F”);
qa->Branch(“Dateandtime”, &Date, “Date/C”);
qa->Branch(“WDir”, &WDir, “WDir/C”);
qa->Branch(“WSpe”, &WSpe, “WSpe/F”);
…8 branches in total
and I am using the sscan (from tutorial cernbuild.C example)
char line[84];
while (fgets(&line, 84, fp)) {
sscanf(&line[0], “%d %f %f %f %s %s”, &Index, &FHS, &Spe, &STI, Date, WDir);
sscanf(&line[38], “%f %f %f %d %f %f”, &WSpe, …rest of 5variables
qa -> Fill()

So when I run it I have the following problems.
root stops working but it creates the rootfile
when I exit and restart root I look with the TBrowser, all first 6 leaves (of the friost 6 varaibles are correct) starting with the 7-th one the data are not read correct, like it does not parse correct the file.
I have no message error, except that root window is crashing (ps I am working onoly on Windows 7 root version 5.34/32 )

I tried with a line like
sscanf(&line[0], “%d %f %f %f %s %s %f %f %f %d %f %f”, &Index, &FHS, &Spe, &STI, Date, WDir, &WSpe, &Slip, &WHgh, &SSta, &Drfw, &Draf);
but I get the message that it cannot takes more then 12 variables.

Can y tell me where I am making the mistake?

Well, try to read your file using: std::ifstream ifs("YourDataFile.txt", std::ifstream::in); while (ifs >> Index) { ifs >> FHS >> Spe >> STI >> Date >> WDir >> WSpe >> Slip >> WHgh >> SSta >> Drfw >> Draf; qa -> Fill(); } ifs.close();

I get this error, do I have to add something?

Error: Can’t call basic_ifstream<char,char_traits >::basic_ifstream<char,c
har_traits >(fp,std::ifstream::in) in current scope C:\rootFiles\VesselPar
Possible candidates are…
public: basic_ifstream<char,char_traits > basic_ifstream<char,char_traits<
char> >::basic_ifstream<char,char_traits >(void);
public: basic_ifstream<char,char_traits > basic_ifstream<char,char_traits<
char> >::basic_ifstream<char,char_traits >(const char* s,ios_base::openmod
e mode=ios_base::in);
*** Interpreter error recovered ***
root [1]

How do you actually define “Date” and “WDir”?

as Char_t. Should be different?

I would expect something like:
const Int_t MaxStringLength = 100;
Char_t Date[MaxStringLength]
Char_t WDir[MaxStringLength];

I change it, but I have the same error

Post your c++ script and your data file here so that we can “inspect” them.

here it is
TestBuild-new.dat (2.37 KB)
TestBuild.C (3.4 KB)

std::ifstream ifs(Form("%sTestBuild-new.dat",dir.Data()), std::ifstream::in); BTW. There is a problem in the attached “TestBuild-new.dat” file -> the first three bytes are “0xEF 0xBB 0xBF” (<U+FEFF>) and this will fool ROOT -> you need to make sure that this file is a simple ASCII (ISO-8859-1) file, not an UTF-8 encoded one.

I replace the line and now I have no error is creating the tree with the structure I wanted but all leaves are empty.
Any idea?

That’s the effect of “improper” “TestBuild-new.dat” file.

Hi I used another file .

Hi y were right. I managed to changed it to I used notepad++ (I am using only windows), but on the file I have 140 lines, and the root file produce is only 49 entriess for each leave.
Do y know a better converter in ASCCI?

Maybe it’s not a problem of the editor but there is something “screwy” in the line 50 ±1 (i.e. either the last line that was stored in the TTree or the next line which was not stored).
You can also post your original file here so that we can “inspect” it.

voila et merci
TestBuild-new.dat (7.86 KB)

Line 49 contains a string “NULL” (this kills ROOT -> I don’t know what this “NULL” is supposed to “represent” but maybe change it into 0.0): 768595 116.5 19 24 20150310 30P 11 7 NULL 4 11.8 11.8

Yes y are right. Now is working perfectly. It shouldn’t be NULL, but this is the download from de MySQL database.
Any idea how I can replace it with 0.0?

The simplest would be to use your editor’s “find and replace text” feature.
In long run you need to report these problems to the one who creates your files (i.e. you want ASCII files, not UTF-8 and any NULL should appear as 0).

Yes y are right, thank y very much