Ntuple or TTree

___Hi every body.
I wanna use Ntuple for create a two dimension array in Visual Studio. Actually I have a text file and I wanna to read it line by line and put them in an array.
Is Ntuple suitable or I should use TTree?
Notice that I am a beginner in Root.
thank you.
Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hello @Fateme,
You could give a try at RDataFrame. In particular, to create a dataframe from a text file, use the MakeCsvDataFrame function as shown in the documentation under the section “Reading file formats different from ROOT’s” .

If you use a separator other than a comma, you can give the function the delimiter you use as a parameter.

Cheers,
Vincenzo

If you have a txt file, and you want to put it to a c++ array, why not use ifstream directly? You will have full handle and the code will be short

Thank you for your help. but may you explain more?

The problem is lenght of text file. my text file is too long so I cannot use ifstream directly. actually when I run my code with simple array it does not work.

In that case, you cannot dump your txt file into array even with the help of TTree, because array lives in the memory.

If you go line by line, and do analysis on the go, only each line’s content lives in the memory so you don’t have a problem. If one line is an event, you can fill to histogram with those contents, or do more things.

I found this thread where you can use TTree’s utility to create a TTree from the txt file, and uses TTree’s mechanism if you really wish to.

If you are not restricted to c++, I recommend go python with numpy or panda dataframe for very efficient data processing with csv files, etc

…but which keep all arrays in memory i.e. back to square one :slight_smile:

TTree::ReadFile should indeed help, as Enrico suggested in your linked post.

1 Like

Thanks to you I went on to search and found that in panda dataframe you can read in by chunk-by-chunk. :slight_smile:

but that’s off-topic here i suppose

1 Like