Merge only part of the content of a set of files.
This macro demonstrates how to merge only a part of the content of a set of input files, specified via the interface.
void AddObjectNames(const char *name)
Add object names for PartialMerge().
The method can be called several times to add object names, or using a single string with names separated by a blank. Directory names contained in the files to be merged are accepted.
Two modes are supported:
- kOnlyListed: via TFileMerger::PartialMerge(kOnlyListed) This will merge only the objects in the files having the names in the specified list. If a folder is specified, its whole content will be merged
- kSkipListed: via TFileMerger::PartialMerge(kSkipListed) This will skip merging of specified objects. If a folder is specified, its whole content will be skipped.
Important note: the kOnlyListed and kSkipListed flags have to be bitwise OR-ed on top of the merging defaults: kAll | kIncremental (as in the example)
The files to be merged have the following structure:
- hpx (TH1F)
- hpxpy (TH2F)
- hprof (TProfile)
- ntuple (TNtuple)
- folder (TDirectory)
The example first merges exclusively hprof and the content of "folder", producing the file exclusive.root, then merges all content but skipping hprof and the content of "folder". The result can be inspected in the browser.
void CreateFile(const char *);
void mergeSelective(
Int_t nfiles=5)
{
if (
gROOT->LoadMacro(tutdir +
"/hsimple.C"))
return;
for (i=0; i<nfiles; i++) CreateFile(
Form(
"tomerge%03d.root",i));
for (i=0; i<nfiles; i++) fm->
AddFile(
Form(
"tomerge%03d.root",i));
for (i=0; i<nfiles; i++) fm->
AddFile(
Form(
"tomerge%03d.root",i));
delete fm;
for (i=0; i<nfiles; i++)
gSystem->Unlink(
Form(
"tomerge%03d.root",i));
}
void CreateFile(const char *fname)
{
if (!example) return;
hpx->SetName("hpx1");
hpx->Write();
example->Close();
if (sname.Contains("000")) {
}
}
int Int_t
Signed integer 4 bytes (int).
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Using a TBrowser one can browse all ROOT objects.
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
virtual Bool_t cd()
Change current directory to "this" directory.
This class provides file copy and merging services.
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress)
Add the TFile to this file merger and give ownership of the TFile to this object (unless kFALSE is re...
@ kAll
Merge all type of objects (default).
@ kIncremental
Merge the input file with the content of the output file (if already existing).
@ kSkipListed
Skip objects specified in fObjectNames list.
@ kOnlyListed
Only the objects specified in fObjectNames list.
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
virtual void Reset()
Reset merger file list.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
virtual Bool_t Cp(const char *dst, Bool_t progressbar=kTRUE, UInt_t bufsize=1000000)
Allows to copy this file to the dst URL.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void Close(Option_t *option="") override
Close a file.
1-D histogram with a float per channel (see TH1 documentation)
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void Print(Option_t *option="") const override
Print the real and cpu time passed between the start and stop events.
- Author
- The Root Team
Definition in file mergeSelective.C.