RootUtils
FileUtils Namespace Reference

Functions

TList * findFilesInDirectory (const char *dirPath, const char *extension=0)
 Obtain list of file paths in directory (with given extension). More...
 
TFile * openFile (const char *filePathName, Option_t *option="READ")
 Open ROOT file with given absolute path. More...
 
TTree * getTree (TFile *file, const char *treeName)
 Parse absolute file path into path, name and extension. More...
 
TBranch * getBranch (TTree *tree, const char *branchName)
 Safely get a branch from a ROOT tree. More...
 
Double_t getBranchMinimum (TTree *tree, const char *branchName)
 Get minimum value in a tree branch. More...
 
Double_t getBranchMaximum (TTree *tree, const char *branchName)
 Get maximum value in a tree branch. More...
 
Double_t getBranchMinimumInFiles (TList *filePaths, const char *treeName, const char *branchName)
 Get minimum value in a tree branch across multiple files. More...
 
Double_t getBranchMaximumInFiles (TList *filePaths, const char *treeName, const char *branchName)
 Get maximum value in a tree branch across multiple files. More...
 
TH1 * getBranchHistogram (TTree *tree, const char *branchName, Int_t nBins=150)
 Shortcut to get a histogram from ROOT tree branch. More...
 
PathComponents parseFilePath (const char *filePathName)
 Parse absolute file path into path, name and extension. More...
 
Int_t exportValuesToGnuplot (const char *filename, std::vector< std::string > colNames, std::vector< double > values, const char *delimeter=" ")
 Append or save data to a Gnuplot file. More...
 
Int_t exportCanvasToGnuplot (TCanvas *canvas, const char *delimeter=" ")
 Export ROOT canvas to ASCII file with data columns. More...
 

Detailed Description

Contains useful functions for ROOT file manipulation.

Function Documentation

◆ exportCanvasToGnuplot()

Int_t FileUtils::exportCanvasToGnuplot ( TCanvas *  canvas,
const char *  delimeter = "   " 
)

Export ROOT canvas to ASCII file with data columns.

Function saves objects on Canvas - histograms, graph, function - to a text file ready to plot in Gnuplot.

Parameters
filenameabsolute file path.
canvasROOT canvas to be saved.
delimetercolumn delimeter (default " ").
Returns
0 if success, 1 if error.

◆ exportValuesToGnuplot()

Int_t FileUtils::exportValuesToGnuplot ( const char *  filename,
std::vector< std::string >  colNames,
std::vector< double >  values,
const char *  delimeter = "   " 
)

Append or save data to a Gnuplot file.

Function creates a new or opens existing ASCII file. Next, it appends a line of values to the file.

Parameters
filenameabsolute file path.
colNamesvector of strings with column names.
colNamesvector of doubles with row values.
delimetercolumn delimeter (default " ").
Returns
0 if success, 1 if error.

◆ findFilesInDirectory()

TList * FileUtils::findFilesInDirectory ( const char *  dirPath,
const char *  extension = 0 
)

Obtain list of file paths in directory (with given extension).

Function returns a TList* of TObjString* with full absolute paths of files in a given directory with given extension. Program exits if directory does not exist or not readable.

Parameters
dirPathDirectory path.
extensionOptional extension of files to find.
Returns
TList* of TObjString* with full absolute paths.

◆ getBranch()

TBranch * FileUtils::getBranch ( TTree *  tree,
const char *  branchName 
)

Safely get a branch from a ROOT tree.

Function will stop program execution if the branch is not found.

Parameters
treepointer to the TTree.
Returns
branchName name of the branch to be found.

◆ getBranchHistogram()

TH1 * FileUtils::getBranchHistogram ( TTree *  tree,
const char *  branchName,
Int_t  nBins = 150 
)

Shortcut to get a histogram from ROOT tree branch.

Function automatically determines histogram minimum and maximum.

Parameters
treePointer to the tree.
branchNamebranchName name of a branch.
nBinsnumber of bins in the histogram. Default is 150.
Returns
TH1* pointer to the histogram.

◆ getBranchMaximum()

Double_t FileUtils::getBranchMaximum ( TTree *  tree,
const char *  branchName 
)

Get maximum value in a tree branch.

Parameters
treepointer to the TTree.
Returns
branchName name of the branch.

◆ getBranchMaximumInFiles()

Double_t FileUtils::getBranchMaximumInFiles ( TList *  filePaths,
const char *  treeName,
const char *  branchName 
)

Get maximum value in a tree branch across multiple files.

Function is useful when simultaneously plotting a number of ROOT files with the same structure.

Parameters
filePathslist of filepaths to be opened (TObjStrings*).
treeNamename of the tree in the ROOT file.
Returns
branchName name of the branch in the tree.

◆ getBranchMinimum()

Double_t FileUtils::getBranchMinimum ( TTree *  tree,
const char *  branchName 
)

Get minimum value in a tree branch.

Parameters
treepointer to the TTree.
Returns
branchName name of the branch.

◆ getBranchMinimumInFiles()

Double_t FileUtils::getBranchMinimumInFiles ( TList *  filePaths,
const char *  treeName,
const char *  branchName 
)

Get minimum value in a tree branch across multiple files.

Function is useful when simultaneously plotting a number of ROOT files with the same structure.

Parameters
filePathslist of filepaths to be opened (TObjStrings*).
treeNamename of the tree in the ROOT file.
Returns
branchName name of the branch in the tree.

◆ getTree()

TTree * FileUtils::getTree ( TFile *  file,
const char *  treeName 
)

Parse absolute file path into path, name and extension.

Function parses file path into components: path, basename, name, extension.

Parameters
filePathNameabsolute file path.
Returns
PathComponents struct with path components.

◆ openFile()

TFile * FileUtils::openFile ( const char *  filePathName,
Option_t *  option = "READ" 
)

Open ROOT file with given absolute path.

Function checks if a file is good and returns a pointer to a ROOT file TFile* with given absolute path.

Parameters
filePathNamefull ROOT file URI.
filePathNameROOT option "NEW", "RECREATE", "UPDATE", "READ".. (optional, default is "READ").
Returns
Pointer to TFile* object.

◆ parseFilePath()

PathComponents FileUtils::parseFilePath ( const char *  filePathName)

Parse absolute file path into path, name and extension.

Function parses file path into components: path, basename, name, extension.

Parameters
filePathNameabsolute file path.
Returns
PathComponents struct with path components.