The problem with ReadFile function

The data file “test.txt” with 980 columns is attached. My code for writing data to TTree is as follow:

{
    TFile *f = new TFile("test.root", "RECREATE");
    TTree *t = new TTree("t", "tree of test");
    Long64_t nlines = t->ReadFile("test.txt", "s_utc/F:s_inc/F:se[976]/F:s_qs/I:s_orbit/I");
    t->Write();
    printf("read %d lines\n", nlines); 
}

After this done, the code for reading data in root file “test.root” as follow:

{
	TFile f("test.root");
	TTree *t = (TTree*)f.Get("t");
	float time;
	t->SetBranchAddress("s_utc", &time);
	for(long i=0; i<t->GetEntries(); i++){
		t->GetEntry(i);
		cout<<setprecision(17)<<time<<endl;
	}
}

I want to check the data stored in root file (“test.root” also attached). But I found a strange thing. The first column data was all the same with the value is “20110519566336” while they are different in text file.

What’s wrong? The ROOT version in my PC is 5.34/21.
Thank you for your attention!
test.root (80.4 KB)
test.txt (1.59 MB)

Well, “s_utc/F” means a 32 bit floating point value (a “float”), which gives 6 to 9 decimal digits precision.
You could try “s_utc/D”, a 64 bit floating point value (a “double”), which would give you at least 15 decimal digits precision, but not more than 17.
However, looking at the first column of your “test.txt” file, I can see that you would like to have 17 decimal digits precision all the time -> well, if this column is an IEEE 754 double precision number converted to a decimal string with 17 significant digits, then converting this string back to double should match the original (and so you could safely use a “double” variable here).

[quote=“Wile E. Coyote”]Well, “s_utc/F” means a 32 bit floating point value (a “float”), which gives 6 to 9 decimal digits precision.
You could try “s_utc/D”, a 64 bit floating point value (a “double”), which would give you at least 15 decimal digits precision, but not more than 17.
However, looking at the first column of your “test.txt” file, I can see that you would like to have 17 decimal digits precision all the time -> well, if this column is an IEEE 754 double precision number converted to a decimal string with 17 significant digits, then converting this string back to double should match the original (and so you could safely use a “double” variable here).[/quote]

Thank you very much for your advice!

I have the same problem. I am reading timestamps from a .csv file and saving it on a Ttree branch but it is always rounding the number.
A typical time on the file is 3611169011.349 and it is saved as 3611169011.

I have used “double” but I still get the same problem.
I also tried reading it as a string and convert it to double I and get the same result.
Is there any way to avoid this rounding or set the desired significant figures.
Many thanks,
ReadData.C (966 Bytes)