Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hadd.cxx File Reference
#include "Compression.h"
#include "TClass.h"
#include "TFile.h"
#include "TFileMerger.h"
#include "THashList.h"
#include "TKey.h"
#include "TSystem.h"
#include "TUUID.h"
#include <ROOT/RConfig.hxx>
#include <ROOT/StringConv.hxx>
#include <ROOT/TIOFeatures.hxx>
#include "haddCommandLineOptionsHelp.h"
#include <climits>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <optional>
#include <sstream>
#include <string>
#include "ROOT/TProcessExecutor.hxx"
Include dependency graph for hadd.cxx:

Classes

struct  FlagConvResult< T >
 
struct  HAddArgs
 

Macros

#define PARSE_FLAG(func, ...)
 

Typedefs

using IntFlag_t = uint32_t
 

Enumerations

enum class  EFlagResult { kIgnored , kParsed , kErr }
 

Functions

template<typename T >
static FlagConvResult< T > ConvertArg (const char *)
 
template<>
FlagConvResult< IntFlag_tConvertArg< IntFlag_t > (const char *arg)
 
template<>
FlagConvResult< ROOT::TIOFeaturesConvertArg< ROOT::TIOFeatures > (const char *arg)
 
static FlagConvResult< TStringConvertCacheSize (const char *arg)
 
static FlagConvResult< Int_tConvertFilterType (const char *arg)
 
std::ostream & Err ()
 
template<typename T >
static EFlagResult FlagArg (int argc, char **argv, int &argIdxInOut, const char *flagStr, std::optional< T > &flagOut, std::optional< T > defaultVal=std::nullopt, FlagConvResult< T >(*conv)(const char *)=ConvertArg< T >)
 
static EFlagResult FlagF (const char *arg, HAddArgs &args)
 
static EFlagResult FlagToggle (const char *arg, const char *flagStr, bool &flagOut)
 
std::ostream & Info ()
 
int main (int argc, char **argv)
 
static std::optional< HAddArgsParseArgs (int argc, char **argv)
 
static Int_t ParseFilterFile (const std::optional< std::string > &filterFileName, std::optional< Int_t > objectFilterType, TFileMerger &fileMerger)
 
static std::optional< IntFlag_tStrToUInt (const char *str)
 
static bool ValidCompressionSettings (int compSettings)
 
std::ostream & Warn ()
 

Detailed Description

This program will merge compatible ROOT objects, such as histograms, Trees and RNTuples, from a list of root files and write them to a target root file.

In order for a ROOT object to be mergeable, it must implement the Merge() function. Non-mergeable objects will have all instances copied as-is into the target file. The target file must not be identical to one of the source files.

Syntax:

Flags can be passed before or after the positional arguments. The first positional (non-flag) argument will be interpreted as the targetfile. After that, the first sequence of positional arguments will be interpreted as the input files. If two sequences of positional arguments are separated by flags, hadd will emit an error and abort.

By default, any argument starting with - is interpreted as a flag. If you want to pass filenames starting with - you need to pass them after --:

hadd [flags] -- -file1 -file2 ...

Note that in this case you need to pass ALL positional arguments after --.

If a flag requires an argument, the argument can be specified in any of these ways:

All equally valid:

-j 16 -j16 -j=16

The first syntax is the preferred one since it's backward-compatible with previous versions of hadd. The -f flag is an exception to this rule: it only supports the -f[0-9] syntax.

Note that merging multiple flags is NOT supported: -jfa will be interpreted as -j=fa, which is invalid!

The flags are as follows:

Parameters
-aAppend to the output
-cachesize<SIZE> Resize the prefetching cache used to speed up I/O operations (use 0 to disable).
-d<DIR> Carry out the partial multiprocess execution in the specified directory
-dbgEnable verbosity. If -j was specified, do not not delete partial files stored inside working directory.
-experimental-io-features<FEATURES> Enables the corresponding experimental feature for output trees.
See also
ROOT::Experimental::EIOFeatures
Parameters
-fForce overwriting of output file.
-f[0-9]Set target compression level. 0 = uncompressed, 9 = highly compressed. Default is 101 (kDefaultZLIB). You can also specify the full compression algorithm, e.g. -f505.
-fkSets the target file to contain the baskets with the same compression as the input files (unless -O is specified). Compresses the meta data using the compression level specified in the first input or the compression setting after fk (for example 505 when using -fk505)
-ffThe compression level used is the one specified in the first input
-j[N_JOBS] Parallelise the execution in N_JOBS processes. If the number of processes is not specified, or is 0, use the system maximum.
-kSkip corrupt or non-existent files, do not exit
-L<FILE> Read the list of objects from FILE and either only merge or skip those objects depending on the value of "-Ltype". FILE must contain one object name per line, which cannot contain whitespaces or '/'. You can also pass TDirectory names, which apply to the entire directory content. Lines beginning with '#' are ignored. If this flag is passed, "-Ltype" MUST be passed as well.
-Ltype<SkipListed|OnlyListed> Sets the type of operation performed on the objects listed in FILE given with the "-L" flag. "SkipListed" will skip all the listed objects; "OnlyListed" will only merge those objects. If this flag is passed, "-L" must be passed as well.
-n<N_FILES> Open at most N files at once (use 0 to request to use the system maximum - which is also the default)
-ORe-optimize basket size when merging TTree
-TDo not merge Trees
-v[LEVEL] Explicitly set the verbosity level: 0 request no output, 99 is the default
Returns
hadd returns a status code: 0 if OK, 1 otherwise

For example assume 3 files f1, f2, f3 containing histograms hn and Trees Tn

  • f1 with h1 h2 h3 T1
  • f2 with h1 h4 T1 T2
  • f3 with h5 the result of
    hadd -f x.root f1.root f2.root f3.root
    #define f(i)
    Definition RSha256.hxx:104
    Double_t x[n]
    Definition legend1.C:17
    TF1 * f1
    Definition legend1.C:11
    will be a file x.root with h1 h2 h3 h4 h5 T1 T2 where
  • h1 will be the sum of the 2 histograms in f1 and f2
  • T1 will be the merge of the Trees in f1 and f2

The files may contain sub-directories.

If the source files contains histograms and Trees, one can skip the Trees with

Wildcarding and indirect files are also supported

hadd result.root myfil*.root
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result

will merge all files in myfil*.root

hadd result.root file1.root @list.txt file2. root myfil*.root

will merge file1.root, file2.root, all files in myfil*.root and all files in the indirect text file list.txt ("@" as the first character of the file indicates an indirect file. An indirect file is a text file containing a list of other files, including other indirect files, one line per file).

If the sources and and target compression levels are identical (default), the program uses the TChain::Merge function with option "fast", ie the merge will be done without unzipping or unstreaming the baskets (i.e. direct copy of the raw byte on disk). The "fast" mode is typically 5 times faster than the mode unzipping and unstreaming the baskets.

If the option -cachesize is used, hadd will resize (or disable if 0) the prefetching cache use to speed up I/O operations.

For options that take a size as argument, a decimal number of bytes is expected. If the number ends with a k, m, g, etc., the number is multiplied by 1000 (1K), 1000000 (1MB), 1000000000 (1G), etc. If this prefix is followed by i, the number is multiplied by the traditional 1024 (1KiB), 1048576 (1MiB), 1073741824 (1GiB), etc. The prefix can be optionally followed by B whose casing is ignored, eg. 1k, 1K, 1Kb and 1KB are the same.

Note
By default histograms are added. However hadd does not support the case where histograms have their bit TH1::kIsAverage set.
Authors
Rene Brun, Dirk Geppert, Sven A. Schmidt, Toby Burnett

Definition in file hadd.cxx.

Macro Definition Documentation

◆ PARSE_FLAG

#define PARSE_FLAG ( func,
... )
Value:
do { \
if (!validFlag) { \
const auto res = func(__VA_ARGS__); \
return {}; \
} \
} while (0)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.

Typedef Documentation

◆ IntFlag_t

using IntFlag_t = uint32_t

Definition at line 177 of file hadd.cxx.

Enumeration Type Documentation

◆ EFlagResult

Enumerator
kIgnored 
kParsed 
kErr 

Definition at line 207 of file hadd.cxx.

Function Documentation

◆ ConvertArg()

template<typename T >
static FlagConvResult< T > ConvertArg ( const char * )
static

◆ ConvertArg< IntFlag_t >()

template<>
FlagConvResult< IntFlag_t > ConvertArg< IntFlag_t > ( const char * arg)

Definition at line 249 of file hadd.cxx.

◆ ConvertArg< ROOT::TIOFeatures >()

Definition at line 249 of file hadd.cxx.

◆ ConvertCacheSize()

static FlagConvResult< TString > ConvertCacheSize ( const char * arg)
static

Definition at line 286 of file hadd.cxx.

◆ ConvertFilterType()

static FlagConvResult< Int_t > ConvertFilterType ( const char * arg)
static

Definition at line 308 of file hadd.cxx.

◆ Err()

std::ostream & Err ( )
inline

Definition at line 159 of file hadd.cxx.

◆ FlagArg()

template<typename T >
static EFlagResult FlagArg ( int argc,
char ** argv,
int & argIdxInOut,
const char * flagStr,
std::optional< T > & flagOut,
std::optional< T > defaultVal = std::nullopt,
FlagConvResult< T >(*)(const char *) conv = ConvertArg<T> )
static

Definition at line 324 of file hadd.cxx.

◆ FlagF()

static EFlagResult FlagF ( const char * arg,
HAddArgs & args )
static

Definition at line 409 of file hadd.cxx.

◆ FlagToggle()

static EFlagResult FlagToggle ( const char * arg,
const char * flagStr,
bool & flagOut )
static

Definition at line 209 of file hadd.cxx.

◆ Info()

std::ostream & Info ( )
inline

Definition at line 171 of file hadd.cxx.

◆ main()

int main ( int argc,
char ** argv )

Definition at line 609 of file hadd.cxx.

◆ ParseArgs()

static std::optional< HAddArgs > ParseArgs ( int argc,
char ** argv )
static

Definition at line 471 of file hadd.cxx.

◆ ParseFilterFile()

static Int_t ParseFilterFile ( const std::optional< std::string > & filterFileName,
std::optional< Int_t > objectFilterType,
TFileMerger & fileMerger )
static

Definition at line 570 of file hadd.cxx.

◆ StrToUInt()

static std::optional< IntFlag_t > StrToUInt ( const char * str)
static

Definition at line 224 of file hadd.cxx.

◆ ValidCompressionSettings()

static bool ValidCompressionSettings ( int compSettings)
static

Definition at line 375 of file hadd.cxx.

◆ Warn()

std::ostream & Warn ( )
inline

Definition at line 165 of file hadd.cxx.