Wrong entries for Ttree ReadFile

Hi, I am trying to convert a csv into root. Previously I done this and it has worked correctly. But for some reasons for this particular set of files I had issue as although it manage to run without error, my entries in root are all zero

I have put an example of one of the lines of the csv file.

Could it be that the “Time” entry I have to do it differently? If so can someone enlighten me about how to do it properly?

tree -> ReadFile("data.csv","Scan/I:Time/C:DigitalGauge1/F:alarm101/I:DigitalGauge2/F:alarm102/I:DigitalGauge3/F:alarm103/I:DigitalGauge4/F:alarm104/I:DigitalGauge5/F:alarm105/I:PiraniGauge/F:alarm106/I:107VDC/F:alarm107/I:108VDC/F:alarm108/I:109VDC/F:alarm109/I:110VDC/F:alarm110/I:111VDC/F:alarm111/I:112VDC/F:alarm112/I:1KPot/F:alarm113/I:MixingChamber/F:alarm114/I:HeatExchanger/F:alarm115/I:Still/F:alarm116/I",',');

with data.csv being

1,2017/03/22 21:08:21:256,3.0216646,0,2.996026,0,2.999162,0,2.9948355,0,3.021831,0,0.009563304,0,0.005924331,0,-0.011202323,0,-0.000468457,0,-0.062406373,0,-0.039981009,0,-0.017782287,0,0.1360781,0,0.1006473,0,2165.986,0,6376.459,0

Hi,

I just tried with ROOT 5 on Windows and ROOT 6 on Linux, and it works… What did you change since it worked?

Cheers, Bertrand.

Hi Bertrand,

I have not change any things at all, therefore it was puzzling as why it was happening.

In my main, I wrote

File *f = new TFile("data.root","RECREATE");
TTree *tree = new TTree("tree","data from csv file");
tree->ReadFile("precool_data.csv","Scan/I:Time/C:DigitalGauge1/F:alarm101/I:DigitalGauge2/F:alarm102/I:DigitalGauge3/F:alarm103/I:DigitalGauge4/F:alarm104/I:DigitalGauge5/F:alarm105/I:PiraniGauge/F:alarm106/I:107VDC/F:alarm107/I:1KPot/F:alarm113/I:MixingChamber/F:alarm114/I:HeatExchanger/F:alarm115/I:Still/F:alarm116/I:squid/F:alarm117/I",',');
f->Write();

This has worked well when I’m dealing with the other work I have done where i needed to do this. But as for some reasons with dealing with the files with the entries as in my first post, I’m getting all entries with 0 when i did a check with tree->Scan() and tree->Print().

My guess that it may have something to do with how the string/Char for column “Time”? but I cant be sure as I could not find the problem of why this occurring to me.

Here is what I get with your type of data (I only changed the scan and time values):

root [0] TFile *f = TFile::Open("myFile.root", "RECREATE");
root [1] TTree *myTree = new TTree("myTree", "myTree");
root [2] myTree->ReadFile("data.csv","Scan/I:Time/C:DigitalGauge1/F:alarm101/I:DigitalGauge2/F:alarm102/I:DigitalGauge3/F:alarm103/I:DigitalGauge4/F:alarm104/I:DigitalGauge5/F:alarm105/I:PiraniGauge/F:alarm106/I:107VDC/F:alarm107/I:108VDC/F:alarm108/I:109VDC/F:alarm109/I:110VDC/F:alarm110/I:111VDC/F:alarm111/I:112VDC/F:alarm112/I:1KPot/F:alarm113/I:MixingChamber/F:alarm114/I:HeatExchanger/F:alarm115/I:Still/F:alarm116/I",',');
root [3] f->Write();
root [4] myTree->Scan()
************************************************************************************************************
*    Row   *      Scan *      Time * DigitalGa *  alarm101 * DigitalGa *  alarm102 * DigitalGa *  alarm103 *
************************************************************************************************************
*        0 *         1 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        1 *         2 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        2 *         3 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        3 *         4 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        4 *         5 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        5 *         6 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        6 *         7 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        7 *         8 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        8 *         9 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*        9 *        10 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*       10 *        11 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*       11 *        12 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*       12 *        13 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*       13 *        14 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*       14 *        15 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
*       15 *        16 * 2017/03/2 * 3.0216646 *         0 * 2.9960260 *         0 * 2.9991619 *         0 *
************************************************************************************************************
(long long) 16
root [5]

Well I did the same as you but problem presists

root [0] TFile *f = new TFile("precool_data.root","RECREATE");
root [1] TTree *tree = new TTree("tree","from raw data");
root [2] tree->ReadFile("precool_data.csv","Scan/I:Time/C:DigitalGauge1/F:alarm101/I:DigitalGauge2/F:alarm102/I:DigitalGauge3/F:alarm103/I:DigitalGauge4/F:alarm104/I:DigitalGauge5/F:alarm105/I:PiraniGauge/F:alarm106/I:VDC107/F:alarm107/I:KPot/F:alarm113/I:MixingChamber/F:alarm114/I:HeatExchanger/F:alarm115/I:Still/F:alarm116/I:squid/F:alarm117/I",',');
root [3] f->Write();
root [4] tree->Scan()
************************************************************************************************************
*    Row   *      Scan *      Time * DigitalGa *  alarm101 * DigitalGa *  alarm102 * DigitalGa *  alarm103 *
************************************************************************************************************
*        0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        1 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        2 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        3 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        4 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        5 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        6 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        7 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        8 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*        9 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       10 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       11 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       12 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       13 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       14 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       15 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       16 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       17 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       18 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       19 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       20 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       21 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       22 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       23 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
*       24 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *         0 *
Type <CR> to continue or q to quit ==> 

Im running on CentOs7 with root being 6.09/01 I testing on others files where i usually do, they work fine but not this

Can you make your file available somewhere?

Converted it to .txt so i can upload it. The post before was the wrong file
precool_data.txt (2.7 MB)

Hi,

Check the format of your file. It looks like it is in a binary format. I had to open it in Excel and save it as DOS/CSV to be able to read it…
If you cannot open it in text editor (or just try with ‘more’ or ‘less’), then ROOT will not be able to read it…

Cheers, Bertrand.

Try: sed -i -e '{s/\c@//g}' precool_data.txt

Hi guys,

I did what Wile_E_Coyote, and then it works. Thanks Wile

In my CentOs it shows the file as text type rather than binary. And I can open it via my usual text editor “Sublime Text” and I can see the entries. I tried with other editor it appears something else?

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