Logo ROOT   6.14/05
Reference Guide
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Andreas Peters + Fons Rademakers 26/5/2005
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  *************************************************************************/
12 #ifndef ROOT_TFileMerger
13 #define ROOT_TFileMerger
15 #include "TList.h"
16 #include "TObject.h"
17 #include "TString.h"
18 #include "TStopwatch.h"
20 #include <memory>
22 class TList;
23 class TFile;
24 class TDirectory;
26 namespace ROOT {
27 class TIOFeatures;
28 } // namespace ROOT
30 class TFileMerger : public TObject {
31 private:
34  TFileMerger(const TFileMerger&) = delete;
35  TFileMerger& operator=(const TFileMerger&) = delete;
37 protected:
38  TStopwatch fWatch; ///< Stop watch to measure file copy speed
39  TList fFileList; ///< A list the file (TFile*) which shall be merged
40  TFile *fOutputFile{nullptr}; ///< The outputfile for merging
41  TString fOutputFilename; ///< The name of the outputfile for merging
42  Bool_t fFastMethod{kTRUE}; ///< True if using Fast merging algorithm (default)
43  Bool_t fNoTrees{kFALSE}; ///< True if Trees should not be merged (default is kFALSE)
44  Bool_t fExplicitCompLevel{kFALSE}; ///< True if the user explicitly requested a compressio level change (default kFALSE)
45  Bool_t fCompressionChange{kFALSE}; ///< True if the output and input have different compression level (default kFALSE)
46  Int_t fPrintLevel{0}; ///< How much information to print out at run time
47  TString fMergeOptions; ///< Options (in string format) to be passed down to the Merge functions
48  TIOFeatures *fIOFeatures{nullptr}; ///< IO features to use in the output file.
49  TString fMsgPrefix{"TFileMerger"}; ///< Prefix to be used when printing informational message (default TFileMerger)
51  Int_t fMaxOpenedFiles; ///< Maximum number of files opened at the same time by the TFileMerger
52  Bool_t fLocal; ///< Makes local copies of merging files if True (default is kTRUE)
53  Bool_t fHistoOneGo; ///< Merger histos in one go (default is kTRUE)
54  TString fObjectNames; ///< List of object names to be either merged exclusively or skipped
55  TList fMergeList; ///< list of TObjString containing the name of the files need to be merged
56  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.
58  Bool_t OpenExcessFiles();
59  virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress);
60  virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type = kRegular | kAll);
62 public:
63  /// Type of the partial merge
65  kRegular = 0, ///< Normal merge, overwritting the output file.
66  kIncremental = BIT(1), ///< Merge the input file with the content of the output file (if already exising).
67  kResetable = BIT(2), ///< Only the objects with a MergeAfterReset member function.
68  kNonResetable = BIT(3), ///< Only the objects without a MergeAfterReset member function.
70  kAll = BIT(2)|BIT(3), ///< Merge all type of objects (default)
71  kAllIncremental = kIncremental | kAll, ///< Merge incrementally all type of objects.
73  kOnlyListed = BIT(4), ///< Only the objects specified in fObjectNames list
74  kSkipListed = BIT(5), ///< Skip objects specified in fObjectNames list
75  kKeepCompression= BIT(6) ///< Keep compression level unchanged for each input files
76  };
78  TFileMerger(Bool_t isLocal = kTRUE, Bool_t histoOneGo = kTRUE);
79  virtual ~TFileMerger();
81  Int_t GetPrintLevel() const { return fPrintLevel; }
82  void SetPrintLevel(Int_t level) { fPrintLevel = level; }
83  Bool_t HasCompressionChange() const { return fCompressionChange; }
84  const char *GetOutputFileName() const { return fOutputFilename; }
85  TList *GetMergeList() { return &fMergeList; }
86  TFile *GetOutputFile() const { return fOutputFile; }
87  Int_t GetMaxOpenedFiles() const { return fMaxOpenedFiles; }
88  void SetMaxOpenedFiles(Int_t newmax);
89  const char *GetMsgPrefix() const { return fMsgPrefix; }
90  void SetMsgPrefix(const char *prefix);
91  const char *GetMergeOptions() { return fMergeOptions; }
92  void SetMergeOptions(const TString &options) { fMergeOptions = options; }
93  void SetMergeOptions(const std::string_view &options) { fMergeOptions = options; }
94  void SetIOFeatures(ROOT::TIOFeatures &features) { fIOFeatures = &features; }
95  void AddObjectNames(const char *name) {fObjectNames += name; fObjectNames += " ";}
96  const char *GetObjectNames() const {return fObjectNames.Data();}
97  void ClearObjectNames() {fObjectNames.Clear();}
99  //--- file management interface
100  virtual Bool_t SetCWD(const char * /*path*/) { MayNotUse("SetCWD"); return kFALSE; }
101  virtual const char *GetCWD() { MayNotUse("GetCWD"); return 0; }
103  //--- file merging interface
104  virtual void Reset();
105  virtual Bool_t AddFile(const char *url, Bool_t cpProgress = kTRUE);
106  virtual Bool_t AddFile(TFile *source, Bool_t cpProgress = kTRUE);
107  virtual Bool_t AddAdoptFile(TFile *source, Bool_t cpProgress = kTRUE);
108  virtual Bool_t OutputFile(const char *url, Bool_t force);
109  virtual Bool_t OutputFile(const char *url, Bool_t force, Int_t compressionLevel);
110  virtual Bool_t OutputFile(const char *url, const char *mode = "RECREATE");
111  virtual Bool_t OutputFile(const char *url, const char *mode, Int_t compressionLevel);
112  virtual Bool_t OutputFile(std::unique_ptr<TFile> file);
113  virtual void PrintFiles(Option_t *options);
114  virtual Bool_t Merge(Bool_t = kTRUE);
115  virtual Bool_t PartialMerge(Int_t type = kAll | kIncremental);
116  virtual void SetFastMethod(Bool_t fast=kTRUE) {fFastMethod = fast;}
117  virtual void SetNotrees(Bool_t notrees=kFALSE) {fNoTrees = notrees;}
118  virtual void RecursiveRemove(TObject *obj);
120  ClassDef(TFileMerger, 6) // File copying and merging services
121 };
123 #endif
TList fExcessFiles
! List of TObjString containing the name of the files not yet added to fFileList due to user or syste...
Definition: TFileMerger.h:56
TList * GetMergeList()
Definition: TFileMerger.h:85
virtual const char * GetCWD()
Definition: TFileMerger.h:101
TStopwatch fWatch
Stop watch to measure file copy speed.
Definition: TFileMerger.h:38
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Int_t GetMaxOpenedFiles() const
Definition: TFileMerger.h:87
TFile * GetOutputFile() const
Definition: TFileMerger.h:86
const char Option_t
Definition: RtypesCore.h:62
#define BIT(n)
Definition: Rtypes.h:78
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
const char * GetMergeOptions()
Definition: TFileMerger.h:91
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const char * GetObjectNames() const
Definition: TFileMerger.h:96
TString fMergeOptions
Options (in string format) to be passed down to the Merge functions.
Definition: TFileMerger.h:47
TIOFeatures provides the end-user with the ability to change the IO behavior of data written via a TT...
Definition: TIOFeatures.hxx:62
TList fMergeList
list of TObjString containing the name of the files need to be merged
Definition: TFileMerger.h:55
const char * GetOutputFileName() const
Definition: TFileMerger.h:84
#define ClassDef(name, id)
Definition: Rtypes.h:320
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1151
virtual Bool_t SetCWD(const char *)
Definition: TFileMerger.h:100
Bool_t fHistoOneGo
Merger histos in one go (default is kTRUE)
Definition: TFileMerger.h:53
void AddObjectNames(const char *name)
Definition: TFileMerger.h:95
virtual void SetNotrees(Bool_t notrees=kFALSE)
Definition: TFileMerger.h:117
void MayNotUse(const char *method)
This function can be used in classes that should override a certain function, but in the inherited cl...
Definition: TError.cxx:269
A doubly linked list.
Definition: TList.h:44
TString fOutputFilename
The name of the outputfile for merging.
Definition: TFileMerger.h:41
Int_t GetPrintLevel() const
Definition: TFileMerger.h:81
TList fFileList
A list the file (TFile*) which shall be merged.
Definition: TFileMerger.h:39
This class provides file copy and merging services.
Definition: TFileMerger.h:30
void SetPrintLevel(Int_t level)
Definition: TFileMerger.h:82
void Reset(Detail::TBranchProxy *x)
TString fObjectNames
List of object names to be either merged exclusively or skipped.
Definition: TFileMerger.h:54
const char * GetMsgPrefix() const
Definition: TFileMerger.h:89
const Bool_t kFALSE
Definition: RtypesCore.h:88
void ClearObjectNames()
Definition: TFileMerger.h:97
Describe directory structure in memory.
Definition: TDirectory.h:34
int type
Definition: TGX11.cxx:120
basic_string_view< char > string_view
Definition: RStringView.hxx:35
Bool_t fLocal
Makes local copies of merging files if True (default is kTRUE)
Definition: TFileMerger.h:52
Binding & operator=(OUT(*fun)(void))
void SetMergeOptions(const std::string_view &options)
Definition: TFileMerger.h:93
Mother of all ROOT objects.
Definition: TObject.h:37
void SetMergeOptions(const TString &options)
Definition: TFileMerger.h:92
Definition: file.py:1
RooCmdArg OutputFile(const char *fileName)
virtual void SetFastMethod(Bool_t fast=kTRUE)
Definition: TFileMerger.h:116
void SetIOFeatures(ROOT::TIOFeatures &features)
Definition: TFileMerger.h:94
const Bool_t kTRUE
Definition: RtypesCore.h:87
Type of the partial merge.
Definition: TFileMerger.h:64
char name[80]
Definition: TGX11.cxx:109
Int_t fMaxOpenedFiles
Maximum number of files opened at the same time by the TFileMerger.
Definition: TFileMerger.h:51
Bool_t HasCompressionChange() const
Definition: TFileMerger.h:83
const char * Data() const
Definition: TString.h:364
Stopwatch class.
Definition: TStopwatch.h:28