This project contains a ROOT macro to list the content of ROOT TFiles and to save to ASCII CSV files all the TNtuples that are found. A main() function is also provided, in order to compile the macro as a standalone program.

Installation

A working copy of ROOT is required. The macro list_file.C can be installed in the macros/ folder in the ROOT installation directory, or copied and used in the current folder.

The standalone program can be compiled with the provided Makefile, with the due modifications for your OS and architecture.

Files

  • Readme: README.md
  • Makefile: Makefile
  • ROOT Macro: list_file.C
  • main() function definition: list_file_main.cpp

Download all the files: list_file.tar.bz2

Usage

Macro

The list_file() function takes two arguments:

  • file_name: a char* that holds the filename;
  • save_data: a bool that enables the dumping to file of the TNtuples (optional)

The TNtuples are saved to files with names: <root_file name>_<TNtuple name>.csv

bash$ root
   ------------------------------------------------------------
  | Welcome to ROOT 6.04/08                http://root.cern.ch |
  |                               (c) 1995-2014, The ROOT Team |
  | Built for macosx64                                         |
  | From tag , 4 November 2015                                 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] .L list_file.C
root [1] list_file("datafile.root", true);
Opening file: datafile.root
TFile**     datafile.root
 TFile*     datafile.root
  KEY: TNtuple  pjmca;1
******************************************************************************
*Tree    :pjmca     :                                                        *
*Entries :  1097099 : Total =        17603277 bytes  File  Size =    7488720 *
*        :          : Tree compression factor =   2.35                       *
******************************************************************************
*Br    0 :ch0       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =    2258988 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   1.94     *
*............................................................................*
*Br    1 :ch1       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =    2343857 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   1.87     *
*............................................................................*
*Br    2 :ch2       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =    2400312 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   1.83     *
*............................................................................*
*Br    3 :ch3       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =     457302 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   9.59     *
*............................................................................*
Saving TNtuple pjmca to: datafile_pjmca.csv
root [2] .q

Standalone program

The standalone program takes a list of files as command line arguments and it lists the content of each one of the files. The optional -s argument enables the dumping to file of the TNtuples.

bash$ ./list_file -s datafile.root
Opening file: datafile.root
TFile**     datafile.root
 TFile*     datafile.root
  KEY: TNtuple  pjmca;1
******************************************************************************
*Tree    :pjmca     :                                                        *
*Entries :  1097099 : Total =        17603277 bytes  File  Size =    7488720 *
*        :          : Tree compression factor =   2.35                       *
******************************************************************************
*Br    0 :ch0       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =    2258988 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   1.94     *
*............................................................................*
*Br    1 :ch1       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =    2343857 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   1.87     *
*............................................................................*
*Br    2 :ch2       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =    2400312 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   1.83     *
*............................................................................*
*Br    3 :ch3       : Float_t                                                *
*Entries :  1097099 : Total  Size=    4417981 bytes  File Size  =     457302 *
*Baskets :      137 : Basket Size=      32000 bytes  Compression=   9.59     *
*............................................................................*
Saving TNtuple pjmca to: datafile_pjmca.csv

Changelog

  • 2009/08/23 - First version
  • 2015/11/06 - Added the option to save ntuples to file
  • 2015/11/09 - Converted from standalone to ROOT macro
  • 2016/08/09 - Cleaned up the Makefile and improved documentation

License (Modified BSD License)

Copyright (C) 2009,2015,2016, Cristiano Lino Fontana

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the University of Padua nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CRISTIANO LINO FONTANA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.