Large data entry, additional entries appears from no where in TBrowser()

Hi , I have a code written down here to covert large csv data set to root format for easy analysis. The csv file I have contains 7,000,001 row of 9 parameter values. However, When I used TBrowser(), I notice beside the 7,000,001 set of “ntuple3”, there was a second set of “ntuples2” that have around 5,000,000~ entry which is weird as it looks like it appear from no where.

I have tried check the branches and leafs of the tree in root, I could not figure out what the cause. I figure it may have to something to do with the code i written(below).

void convertCSV_root() {

   TString dir = gSystem->UnixPathName(__FILE__);
   dir.ReplaceAll("convertCSV_root.cc","");
   dir.ReplaceAll("/./","/");

   TFile *f = new TFile("DataFile_B0002.root","RECREATE");
   TTree *tree = new TTree("ntuple","data from csv file");

   TFile *fin = new TFile("DataFile_B0002_data.csv","rb");
   char line[20];
   // while (fgets(&line,20,fin))
   tree->ReadFile("DataFile_B0002_data.csv","Time/F:CH11/F:CH12/F:CH21/F:CH22/F:CH31/F:CH32/F:CH41/F:CH42/F",',');
   f->Write();
}

a portion of the csv file

0.00000000e+000,0.00000e+000,-2.00000e-003,-2.00000e-003,-4.00000e-003,-2.00000e-003,-2.00000e-003,-4.00000e-003,-2.00000e-003
1.000000000e-003,+8.00000e-003,0.00000e+000,-2.00000e-003,-4.00000e-003,-4.0000e-003,0.00000e+000,-1.00000e-003,-2.00000e-003
....

Has anyone encounter this before?

See e.g. https://root.cern.ch/root/htmldoc/guides/users-guide/InputOutput.html#viewing-the-logical-file-contents

TTree stores a snapshot of the TTree header after a while ("ntuple;1"). When you store it there will be another “cycle” added called "ntuple;2". The most recent can be accessed as "ntuple" (i.e. without cycle number).

(And yes that’s a bit arcane; we are “fixing” that with the new interfaces / nicknamed “ROOT 7”.)

Cheers, Axel.

Hi Axel, Thanks for the reply.

I am not very sure what you mean there.(still rookie root user >.<). Does that mean in the actual root file it is still the same 7,000,001 entries?

I attach a picture of what i observed, ntuple;3=7,000,001 entries, ntuple;2 =5,746,320 entries

are the entries still the same as the original then?

Danny

This means that while you fill the tree, ROOT creates backups / snapshots of the tree in your TFile, once a while. Then when you call file->Write() it will store yet another (the final) snapshot. The snapshots are numbered, separated by ;. The last snapshot supersedes previous ones; it’s thus enough to look at the last one.

There is an additional “helpfulness” in ROOT filling TTrees: if they become too large (2GB), ROOT will switch to a new file and will continue writing the TTree into that. The files are numbered; “out.root”, “out_1.root” etc. You can call TTree::SetMaxTreeSize(100000000000LL) to set that point to 100GB.

Cheers, Axel.

Thank you very much Axel, now I get it. :slight_smile:

Danny

void convertCSV_root() {

TString dir = gSystem->UnixPathName(FILE);
dir.ReplaceAll(“convertCSV_root.cc”,“”);
dir.ReplaceAll(“/./”,“/”);

TFile *f = new TFile(“DataFile_B0002.root”,“RECREATE”);
TTree *tree = new TTree(“ntuple”,“data from csv file”);

TFile *fin = new TFile(“DataFile_B0002_data.csv”,“rb”);
char line[20];
// while (fgets(&line,20,fin))
tree->ReadFile(“DataFile_B0002_data.csv”,“Time/F:CH11/F:CH12/F:CH21/F:CH22/F:CH31/F:CH32/F:CH41/F:CH42/F”,‘,’);
f->Write();
}

a portion of the csv file

0.00000000e+000,0.00000e+000,-2.00000e-003,-2.00000e-003,-4.00000e-003,-2.00000e-003,-2.00000e-003,-4.00000e-003,-2.00000e-003
1.000000000e-003,+8.00000e-003,0.00000e+000,-2.00000e-003,-4.00000e-003,-4.0000e-003,0.00000e+000,-1.00000e-003,-2.00000e-003

*A follow up question that is unrelated to the title.

So now I have a .txt file that contain the start time(a constant value) and I want to add to the “Time” branch which is from 0ms to 7000s with an increment of 1ms.

Is there a way in root that I can do what I described and change that into UNIX time format(or something similar to it).

For new questions, start a new topic is always less confusing.

Can you be more explicit in what you want? Where do you want “UNIX time format”? And what is that - a string representation?

Axel.

Okay I will remember that next time. Apologies if it was not clear before.

So I have the start time “17-03-25”,“06:16:15.49” and I want to add this to the first “Time” branch.(adding a new branch for date and another for time where the time is added with the value of the “time” branch)

0.00000000e+000 ........
1.00000000e-003 .........
2.00000000e-003 ........
.....

and so on. After this I would want to convert that date and time format to Unix time(aka Epoch time). example:-

17-03-25 06:16:15.49.002 --> 1490683559002

To do this conversion you can use:
https://root.cern/doc/master/classTDatime.html

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.