Logo ROOT  
Reference Guide
TFileMerger.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Andreas Peters + Fons Rademakers 26/5/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TFileMerger
13 #define ROOT_TFileMerger
14 
15 #include "TObject.h"
16 #include "TList.h"
17 #include "TString.h"
18 #include "TStopwatch.h"
19 #include <string>
20 
21 class TFile;
22 class TDirectory;
23 
24 namespace ROOT {
25 class TIOFeatures;
26 } // namespace ROOT
27 
28 class TFileMerger : public TObject {
29 private:
31 
32  TFileMerger(const TFileMerger&) = delete;
33  TFileMerger& operator=(const TFileMerger&) = delete;
34 
35 protected:
36  TStopwatch fWatch; ///< Stop watch to measure file copy speed
37  TList fFileList; ///< A list the file (TFile*) which shall be merged
38  TFile *fOutputFile{nullptr}; ///< The outputfile for merging
39  TString fOutputFilename; ///< The name of the outputfile for merging
40  Bool_t fFastMethod{kTRUE}; ///< True if using Fast merging algorithm (default)
41  Bool_t fNoTrees{kFALSE}; ///< True if Trees should not be merged (default is kFALSE)
42  Bool_t fExplicitCompLevel{kFALSE}; ///< True if the user explicitly requested a compressio level change (default kFALSE)
43  Bool_t fCompressionChange{kFALSE}; ///< True if the output and input have different compression level (default kFALSE)
44  Int_t fPrintLevel{0}; ///< How much information to print out at run time
45  TString fMergeOptions; ///< Options (in string format) to be passed down to the Merge functions
46  TIOFeatures *fIOFeatures{nullptr}; ///< IO features to use in the output file.
47  TString fMsgPrefix{"TFileMerger"}; ///< Prefix to be used when printing informational message (default TFileMerger)
48 
49  Int_t fMaxOpenedFiles; ///< Maximum number of files opened at the same time by the TFileMerger
50  Bool_t fLocal; ///< Makes local copies of merging files if True (default is kTRUE)
51  Bool_t fHistoOneGo; ///< Merger histos in one go (default is kTRUE)
52  TString fObjectNames; ///< List of object names to be either merged exclusively or skipped
53  TList fMergeList; ///< list of TObjString containing the name of the files need to be merged
54  TList fExcessFiles; ///<! List of TObjString containing the name of the files not yet added to fFileList due to user or system limitiation on the max number of files opened.
55 
57  virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress);
58  virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type = kRegular | kAll);
59 
60 public:
61  /// Type of the partial merge
63  kRegular = 0, ///< Normal merge, overwritting the output file.
64  kIncremental = BIT(1), ///< Merge the input file with the content of the output file (if already exising).
65  kResetable = BIT(2), ///< Only the objects with a MergeAfterReset member function.
66  kNonResetable = BIT(3), ///< Only the objects without a MergeAfterReset member function.
67 
68  kAll = BIT(2)|BIT(3), ///< Merge all type of objects (default)
69  kAllIncremental = kIncremental | kAll, ///< Merge incrementally all type of objects.
70 
71  kOnlyListed = BIT(4), ///< Only the objects specified in fObjectNames list
72  kSkipListed = BIT(5), ///< Skip objects specified in fObjectNames list
73  kKeepCompression= BIT(6) ///< Keep compression level unchanged for each input files
74  };
75 
76  TFileMerger(Bool_t isLocal = kTRUE, Bool_t histoOneGo = kTRUE);
77  virtual ~TFileMerger();
78 
79  Int_t GetPrintLevel() const { return fPrintLevel; }
80  void SetPrintLevel(Int_t level) { fPrintLevel = level; }
82  const char *GetOutputFileName() const { return fOutputFilename; }
83  TList *GetMergeList() { return &fMergeList; }
84  TFile *GetOutputFile() const { return fOutputFile; }
86  void SetMaxOpenedFiles(Int_t newmax);
87  const char *GetMsgPrefix() const { return fMsgPrefix; }
88  void SetMsgPrefix(const char *prefix);
89  const char *GetMergeOptions() { return fMergeOptions; }
90  void SetMergeOptions(const TString &options) { fMergeOptions = options; }
91  void SetMergeOptions(const std::string_view &options) { fMergeOptions = options; }
92  void SetIOFeatures(ROOT::TIOFeatures &features) { fIOFeatures = &features; }
93  void AddObjectNames(const char *name) {fObjectNames += name; fObjectNames += " ";}
94  const char *GetObjectNames() const {return fObjectNames.Data();}
96 
97  //--- file management interface
98  virtual Bool_t SetCWD(const char * /*path*/) { MayNotUse("SetCWD"); return kFALSE; }
99  virtual const char *GetCWD() { MayNotUse("GetCWD"); return 0; }
100 
101  //--- file merging interface
102  virtual void Reset();
103  virtual Bool_t AddFile(const char *url, Bool_t cpProgress = kTRUE);
104  virtual Bool_t AddFile(TFile *source, Bool_t cpProgress = kTRUE);
105  virtual Bool_t AddAdoptFile(TFile *source, Bool_t cpProgress = kTRUE);
106  virtual Bool_t OutputFile(const char *url, Bool_t force);
107  virtual Bool_t OutputFile(const char *url, Bool_t force, Int_t compressionLevel);
108  virtual Bool_t OutputFile(const char *url, const char *mode = "RECREATE");
109  virtual Bool_t OutputFile(const char *url, const char *mode, Int_t compressionLevel);
110  virtual Bool_t OutputFile(std::unique_ptr<TFile> file);
111  virtual void PrintFiles(Option_t *options);
112  virtual Bool_t Merge(Bool_t = kTRUE);
114  virtual void SetFastMethod(Bool_t fast=kTRUE) {fFastMethod = fast;}
115  virtual void SetNotrees(Bool_t notrees=kFALSE) {fNoTrees = notrees;}
116  virtual void RecursiveRemove(TObject *obj);
117 
118  ClassDef(TFileMerger, 6) // File copying and merging services
119 };
120 
121 #endif
122 
TFileMerger::kAllIncremental
@ kAllIncremental
Merge incrementally all type of objects.
Definition: TFileMerger.h:69
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TFileMerger::kRegular
@ kRegular
Normal merge, overwritting the output file.
Definition: TFileMerger.h:63
TFileMerger::kResetable
@ kResetable
Only the objects with a MergeAfterReset member function.
Definition: TFileMerger.h:65
TFileMerger::Reset
virtual void Reset()
Reset merger file list.
Definition: TFileMerger.cxx:116
Option_t
const char Option_t
Definition: RtypesCore.h:66
TFileMerger::EPartialMergeType
EPartialMergeType
Type of the partial merge.
Definition: TFileMerger.h:62
TFileMerger::Merge
virtual Bool_t Merge(Bool_t=kTRUE)
Merge the files.
Definition: TFileMerger.cxx:369
TFileMerger::GetMergeOptions
const char * GetMergeOptions()
Definition: TFileMerger.h:89
TFileMerger::GetCWD
virtual const char * GetCWD()
Definition: TFileMerger.h:99
TFileMerger::fMaxOpenedFiles
Int_t fMaxOpenedFiles
Maximum number of files opened at the same time by the TFileMerger.
Definition: TFileMerger.h:49
TFileMerger::fWatch
TStopwatch fWatch
Stop watch to measure file copy speed.
Definition: TFileMerger.h:36
TString::Data
const char * Data() const
Definition: TString.h:369
TFileMerger::GetOutputFile
TFile * GetOutputFile() const
Definition: TFileMerger.h:84
TFileMerger::kIncremental
@ kIncremental
Merge the input file with the content of the output file (if already exising).
Definition: TFileMerger.h:64
TFileMerger::TFileMerger
TFileMerger(const TFileMerger &)=delete
TFileMerger::GetObjectNames
const char * GetObjectNames() const
Definition: TFileMerger.h:94
TFileMerger::fMergeList
TList fMergeList
list of TObjString containing the name of the files need to be merged
Definition: TFileMerger.h:53
TStopwatch.h
TFileMerger::kOnlyListed
@ kOnlyListed
Only the objects specified in fObjectNames list.
Definition: TFileMerger.h:71
string_view
basic_string_view< char > string_view
Definition: libcpp_string_view.h:785
TFileMerger::GetMergeList
TList * GetMergeList()
Definition: TFileMerger.h:83
TFileMerger::kAll
@ kAll
Merge all type of objects (default)
Definition: TFileMerger.h:68
TFileMerger::OpenExcessFiles
Bool_t OpenExcessFiles()
Open up to fMaxOpenedFiles of the excess files.
Definition: TFileMerger.cxx:915
Int_t
int Int_t
Definition: RtypesCore.h:45
TFileMerger::GetMaxOpenedFiles
Int_t GetMaxOpenedFiles() const
Definition: TFileMerger.h:85
TFileMerger::SetCWD
virtual Bool_t SetCWD(const char *)
Definition: TFileMerger.h:98
TList.h
TFileMerger::fMergeOptions
TString fMergeOptions
Options (in string format) to be passed down to the Merge functions.
Definition: TFileMerger.h:45
TFileMerger::fHistoOneGo
Bool_t fHistoOneGo
Merger histos in one go (default is kTRUE)
Definition: TFileMerger.h:51
TObject::MayNotUse
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:943
TFileMerger::SetMsgPrefix
void SetMsgPrefix(const char *prefix)
Set the prefix to be used when printing informational message.
Definition: TFileMerger.cxx:992
TFileMerger::SetNotrees
virtual void SetNotrees(Bool_t notrees=kFALSE)
Definition: TFileMerger.h:115
TFileMerger::AddAdoptFile
virtual Bool_t AddAdoptFile(TFile *source, Bool_t cpProgress=kTRUE)
Add the TFile to this file merger and give ownership of the TFile to this object (unless kFALSE is re...
Definition: TFileMerger.cxx:205
ROOT::TIOFeatures
TIOFeatures provides the end-user with the ability to change the IO behavior of data written via a TT...
Definition: TIOFeatures.hxx:69
TFileMerger::fOutputFile
TFile * fOutputFile
The outputfile for merging.
Definition: TFileMerger.h:38
TString
Basic string class.
Definition: TString.h:136
TFileMerger::fCompressionChange
Bool_t fCompressionChange
True if the output and input have different compression level (default kFALSE)
Definition: TFileMerger.h:43
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TFileMerger::AddFile
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...
Definition: TFileMerger.cxx:216
TString::Clear
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1176
TString.h
bool
TFileMerger::kSkipListed
@ kSkipListed
Skip objects specified in fObjectNames list.
Definition: TFileMerger.h:72
TFileMerger::fOutputFilename
TString fOutputFilename
The name of the outputfile for merging.
Definition: TFileMerger.h:39
TFileMerger::GetPrintLevel
Int_t GetPrintLevel() const
Definition: TFileMerger.h:79
TFileMerger::AddObjectNames
void AddObjectNames(const char *name)
Definition: TFileMerger.h:93
TFileMerger::fFileList
TList fFileList
A list the file (TFile*) which shall be merged.
Definition: TFileMerger.h:37
TFileMerger::RecursiveRemove
virtual void RecursiveRemove(TObject *obj)
Intercept the case where the output TFile is deleted!
Definition: TFileMerger.cxx:962
TFileMerger::GetOutputFileName
const char * GetOutputFileName() const
Definition: TFileMerger.h:82
TFileMerger::SetMaxOpenedFiles
void SetMaxOpenedFiles(Int_t newmax)
Set a limit to the number of files that TFileMerger will open simultaneously.
Definition: TFileMerger.cxx:976
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TFileMerger::ClearObjectNames
void ClearObjectNames()
Definition: TFileMerger.h:95
TFileMerger::fObjectNames
TString fObjectNames
List of object names to be either merged exclusively or skipped.
Definition: TFileMerger.h:52
BIT
#define BIT(n)
Definition: Rtypes.h:85
TFileMerger::GetMsgPrefix
const char * GetMsgPrefix() const
Definition: TFileMerger.h:87
TFileMerger::OutputFile
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
Definition: TFileMerger.cxx:286
TFileMerger::SetPrintLevel
void SetPrintLevel(Int_t level)
Definition: TFileMerger.h:80
TFileMerger::fMsgPrefix
TString fMsgPrefix
Prefix to be used when printing informational message (default TFileMerger)
Definition: TFileMerger.h:47
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TFileMerger::SetMergeOptions
void SetMergeOptions(const TString &options)
Definition: TFileMerger.h:90
TFileMerger::fNoTrees
Bool_t fNoTrees
True if Trees should not be merged (default is kFALSE)
Definition: TFileMerger.h:41
TFileMerger::kKeepCompression
@ kKeepCompression
Keep compression level unchanged for each input files.
Definition: TFileMerger.h:73
TFileMerger::fLocal
Bool_t fLocal
Makes local copies of merging files if True (default is kTRUE)
Definition: TFileMerger.h:50
TFileMerger::MergeRecursive
virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type=kRegular|kAll)
Merge all objects in a directory.
Definition: TFileMerger.cxx:395
TFileMerger::fFastMethod
Bool_t fFastMethod
True if using Fast merging algorithm (default)
Definition: TFileMerger.h:40
TObject.h
TFileMerger::PrintFiles
virtual void PrintFiles(Option_t *options)
Print list of files being merged.
Definition: TFileMerger.cxx:356
TFileMerger::operator=
TFileMerger & operator=(const TFileMerger &)=delete
file
Definition: file.py:1
TFileMerger::SetIOFeatures
void SetIOFeatures(ROOT::TIOFeatures &features)
Definition: TFileMerger.h:92
TStopwatch
Stopwatch class.
Definition: TStopwatch.h:28
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TFileMerger::SetFastMethod
virtual void SetFastMethod(Bool_t fast=kTRUE)
Definition: TFileMerger.h:114
name
char name[80]
Definition: TGX11.cxx:110
TFileMerger::kNonResetable
@ kNonResetable
Only the objects without a MergeAfterReset member function.
Definition: TFileMerger.h:66
TFileMerger::~TFileMerger
virtual ~TFileMerger()
Cleanup.
Definition: TFileMerger.cxx:104
TDirectory
Describe directory structure in memory.
Definition: TDirectory.h:40
TFileMerger
This class provides file copy and merging services.
Definition: TFileMerger.h:28
TFileMerger::fExcessFiles
TList fExcessFiles
! List of TObjString containing the name of the files not yet added to fFileList due to user or syste...
Definition: TFileMerger.h:54
TFileMerger::PartialMerge
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
Definition: TFileMerger.cxx:813
type
int type
Definition: TGX11.cxx:121
TFileMerger::fIOFeatures
TIOFeatures * fIOFeatures
IO features to use in the output file.
Definition: TFileMerger.h:46
TFileMerger::fExplicitCompLevel
Bool_t fExplicitCompLevel
True if the user explicitly requested a compressio level change (default kFALSE)
Definition: TFileMerger.h:42
TFileMerger::HasCompressionChange
Bool_t HasCompressionChange() const
Definition: TFileMerger.h:81
ROOT
VSD Structures.
Definition: StringConv.hxx:21
TFileMerger::SetMergeOptions
void SetMergeOptions(const std::string_view &options)
Definition: TFileMerger.h:91
TList
A doubly linked list.
Definition: TList.h:44
TFileMerger::fPrintLevel
Int_t fPrintLevel
How much information to print out at run time.
Definition: TFileMerger.h:44
int