Reading multiple tab delimited text files into tree

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

Dear ROOT users,

I have text files with names in the following form: example_0_1000.txt, example_500_1500.txt, example_1000_2000.txt, example_1500_2500.txt… where all have the same structure.

Currently, I can read any single one of these in using tree->ReadFile(). I loop over the ReadFile() to get different filenames by replacing the numbers with an iterator, so that I can read all of the possible files. Does this overwrite the previous data or ‘merge’ the two input files’ data into tree?

My main problem is how I can merge different trees, say tree1 with another tree: tree2. I have tried to use TChain::Add() but that only seems to work for .root files. I’d like to merge trees together directly from the text files. How can I do this?


would cat-ting the txt files together be enough? You can do it on osx and linux with the cat command.



It turns out that is definitely a valid solution, although I decided to just loop over all filenames as that way I still have control over which I take in using an if statement. I’m sure I’ll need to use cat though, so I really appreciate your answer!

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