Performance in creating tree from ascii file


I have this macro that creates a root tree from a text file, and as the number of lines in the files increases, it takes much more time (this makes sense).
So I thought maybe there was a way to increase performance by modifying the way I read the text file and I fill the tree.
Unfortunately my knowledge is quite limited and I don’t know how to optimize the code for performance.
This is why I ask if any of you can take a look at the function and see if there is a better and quicker way to create my tree.
I have attached the part of the macro that creates the tree from the text file (it should work by itself) and a sample of the file I am using.

Thanks for your help.
Sample.txt (461 Bytes)
create_tree.C (3.16 KB)

Your file create_tree.C has
-many C++ coding errors
-bad branches definition

I suggest to simply use something like:

void Sample() { TFile *f = TFile::Open("Sample.root","recreate"); TTree *T = new TTree("T","Sample"); T->ReadFile("Sample.txt","date/C:time/C:pm/C:mod/I:ch/I:Vm/F:Im/F:sts/I"); T->Print(); T->Write(); }


Thank for the reply.

Could you please be more specific about the coding errors I have ? This code is what I managed to put together using the web and the root tutorials, so any suggestions are welcome.

Also I will try to use T->ReadFile , it seems powerful, but the thing is I have to keep the tree structure as it is on the original macro (ie one branch for each value of ‘ch’, and inside four leaves ‘im’ ‘vm’ ‘t’ ‘sts’) where t is the time is seconds converted from the time string (I also have an offset leaf).

So could you be please help me understand how to do all that ?

Thank you.

To see the many problems in your original script, I suggest to use ACLIC, ie
root > .L create_treeC+

In the attachment, you will find your original file modified. Many lines have been modified such that it compiles). Look at the differences very carefully.
Your script produces a Tree with more than one thousand branches.
This looks like an overkill given your input data, hence my proposal.


Thank you for your answer!
However I don’t see any new attachment…

I forgot the attachment

create_tree.C (3.32 KB)

Thank you for cleaning up the code.
I still can’t compile it though, I get this error :

root [0] .L create_tree.C+
Info in <TUnixSystem::ACLiC>: creating shared library /afs/
/afs/ could not read symbols: File in wrong format
collect2: ld returned 1 exit status
Error in <ACLiC>: Compilation failed!

As for the tree structure, I don’t see how to modify it, because I need to be able to acces the data for each channel independently, hence the number of branches… Any suggestions on this ?


This is not a compilation but a link problem.
It could be that you are using the 32 bit version of ROOT on an lxplus machine
where the defaut is now 64 bit mode. Use the right version of ROOT, eg