Logo ROOT   6.10/09
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 "TString.h"
17 #include "TStopwatch.h"
18 
19 class TList;
20 class TFile;
21 class TDirectory;
22 
23 
24 class TFileMerger : public TObject {
25 private:
26  TFileMerger(const TFileMerger&); // Not implemented
27  TFileMerger& operator=(const TFileMerger&); // Not implemented
28 
29 protected:
30  TStopwatch fWatch; ///< Stop watch to measure file copy speed
31  TList *fFileList; ///< A list the file (TFile*) which shall be merged
32  TFile *fOutputFile; ///< The outputfile for merging
33  TString fOutputFilename; ///< The name of the outputfile for merging
34  Bool_t fFastMethod; ///< True if using Fast merging algorithm (default)
35  Bool_t fNoTrees; ///< True if Trees should not be merged (default is kFALSE)
36  Bool_t fExplicitCompLevel;///< True if the user explicitly requested a compressio level change (default kFALSE)
37  Bool_t fCompressionChange;///< True if the output and input have different compression level (default kFALSE)
38  Int_t fPrintLevel; ///< How much information to print out at run time
39  TString fMergeOptions; ///< Options (in string format) to be passed down to the Merge functions
40  TString fMsgPrefix; ///< Prefix to be used when printing informational message (default TFileMerger)
41 
42  Int_t fMaxOpenedFiles; ///< Maximum number of files opened at the same time by the TFileMerger
43  Bool_t fLocal; ///< Makes local copies of merging files if True (default is kTRUE)
44  Bool_t fHistoOneGo; ///< Merger histos in one go (default is kTRUE)
45  TString fObjectNames; ///< List of object names to be either merged exclusively or skipped
46  TList *fMergeList; ///< list of TObjString containing the name of the files need to be merged
47  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.
48 
50  virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress);
51  virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type = kRegular | kAll);
52 
53 public:
54  /// Type of the partial merge
56  kRegular = 0, ///< Normal merge, overwritting the output file.
57  kIncremental = BIT(1), ///< Merge the input file with the content of the output file (if already exising).
58  kResetable = BIT(2), ///< Only the objects with a MergeAfterReset member function.
59  kNonResetable = BIT(3), ///< Only the objects without a MergeAfterReset member function.
60 
61  kAll = BIT(2)|BIT(3), ///< Merge all type of objects (default)
62  kAllIncremental = kIncremental | kAll, ///< Merge incrementally all type of objects.
63 
64  kOnlyListed = BIT(4), ///< Only the objects specified in fObjectNames list
65  kSkipListed = BIT(5), ///< Skip objects specified in fObjectNames list
66  kKeepCompression= BIT(6) ///< Keep compression level unchanged for each input files
67  };
68  TFileMerger(Bool_t isLocal = kTRUE, Bool_t histoOneGo = kTRUE);
69  virtual ~TFileMerger();
70 
71  Int_t GetPrintLevel() const { return fPrintLevel; }
72  void SetPrintLevel(Int_t level) { fPrintLevel = level; }
74  const char *GetOutputFileName() const { return fOutputFilename; }
75  TList *GetMergeList() const { return fMergeList; }
76  TFile *GetOutputFile() const { return fOutputFile; }
78  void SetMaxOpenedFiles(Int_t newmax);
79  const char *GetMsgPrefix() const { return fMsgPrefix; }
80  void SetMsgPrefix(const char *prefix);
81  const char *GetMergeOptions() { return fMergeOptions; }
82  void SetMergeOptions(const TString &options) { fMergeOptions = options; }
83  void SetMergeOptions(const std::string_view &options) { fMergeOptions = options; }
84  void AddObjectNames(const char *name) {fObjectNames += name; fObjectNames += " ";}
85  const char *GetObjectNames() const {return fObjectNames.Data();}
86  void ClearObjectNames() {fObjectNames.Clear();}
87 
88  //--- file management interface
89  virtual Bool_t SetCWD(const char * /*path*/) { MayNotUse("SetCWD"); return kFALSE; }
90  virtual const char *GetCWD() { MayNotUse("GetCWD"); return 0; }
91 
92  //--- file merging interface
93  virtual void Reset();
94  virtual Bool_t AddFile(const char *url, Bool_t cpProgress = kTRUE);
95  virtual Bool_t AddFile(TFile *source, Bool_t cpProgress = kTRUE);
96  virtual Bool_t AddAdoptFile(TFile *source, Bool_t cpProgress = kTRUE);
97  virtual Bool_t OutputFile(const char *url, Bool_t force);
98  virtual Bool_t OutputFile(const char *url, Bool_t force, Int_t compressionLevel);
99  virtual Bool_t OutputFile(const char *url, const char *mode = "RECREATE");
100  virtual Bool_t OutputFile(const char *url, const char *mode, Int_t compressionLevel);
101  virtual void PrintFiles(Option_t *options);
102  virtual Bool_t Merge(Bool_t = kTRUE);
104  virtual void SetFastMethod(Bool_t fast=kTRUE) {fFastMethod = fast;}
105  virtual void SetNotrees(Bool_t notrees=kFALSE) {fNoTrees = notrees;}
106  virtual void RecursiveRemove(TObject *obj);
107 
108  ClassDef(TFileMerger,5) // File copying and merging services
109 };
110 
111 #endif
112 
Merge incrementally all type of objects.
Definition: TFileMerger.h:62
Int_t fPrintLevel
How much information to print out at run time.
Definition: TFileMerger.h:38
virtual const char * GetCWD()
Definition: TFileMerger.h:90
TStopwatch fWatch
Stop watch to measure file copy speed.
Definition: TFileMerger.h:30
Int_t GetMaxOpenedFiles() const
Definition: TFileMerger.h:77
TFile * GetOutputFile() const
Definition: TFileMerger.h:76
const char Option_t
Definition: RtypesCore.h:62
#define BIT(n)
Definition: Rtypes.h:75
virtual Bool_t Merge(Bool_t=kTRUE)
Merge the files.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
const char * GetMergeOptions()
Definition: TFileMerger.h:81
Normal merge, overwritting the output file.
Definition: TFileMerger.h:56
Bool_t OpenExcessFiles()
Open up to fMaxOpenedFiles of the excess files.
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const char * GetObjectNames() const
Definition: TFileMerger.h:85
TString fMergeOptions
Options (in string format) to be passed down to the Merge functions.
Definition: TFileMerger.h:39
Bool_t fCompressionChange
True if the output and input have different compression level (default kFALSE)
Definition: TFileMerger.h:37
Only the objects specified in fObjectNames list.
Definition: TFileMerger.h:64
virtual void RecursiveRemove(TObject *obj)
Intercept the case where the output TFile is deleted!
const char * GetOutputFileName() const
Definition: TFileMerger.h:74
Merge all type of objects (default)
Definition: TFileMerger.h:61
#define ClassDef(name, id)
Definition: Rtypes.h:297
TList * fExcessFiles
! List of TObjString containing the name of the files not yet added to fFileList due to user or syste...
Definition: TFileMerger.h:47
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1150
Skip objects specified in fObjectNames list.
Definition: TFileMerger.h:65
virtual Bool_t SetCWD(const char *)
Definition: TFileMerger.h:89
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:926
Merge the input file with the content of the output file (if already exising).
Definition: TFileMerger.h:57
Bool_t fHistoOneGo
Merger histos in one go (default is kTRUE)
Definition: TFileMerger.h:44
void SetMsgPrefix(const char *prefix)
Set the prefix to be used when printing informational message.
void AddObjectNames(const char *name)
Definition: TFileMerger.h:84
virtual void SetNotrees(Bool_t notrees=kFALSE)
Definition: TFileMerger.h:105
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...
TFileMerger(const TFileMerger &)
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
TFile * fOutputFile
The outputfile for merging.
Definition: TFileMerger.h:32
TList * fMergeList
list of TObjString containing the name of the files need to be merged
Definition: TFileMerger.h:46
A doubly linked list.
Definition: TList.h:43
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...
TString fOutputFilename
The name of the outputfile for merging.
Definition: TFileMerger.h:33
Int_t GetPrintLevel() const
Definition: TFileMerger.h:71
This class provides file copy and merging services.
Definition: TFileMerger.h:24
Keep compression level unchanged for each input files.
Definition: TFileMerger.h:66
void SetPrintLevel(Int_t level)
Definition: TFileMerger.h:72
TString fMsgPrefix
Prefix to be used when printing informational message (default TFileMerger)
Definition: TFileMerger.h:40
TFileMerger & operator=(const TFileMerger &)
TString fObjectNames
List of object names to be either merged exclusively or skipped.
Definition: TFileMerger.h:45
const char * GetMsgPrefix() const
Definition: TFileMerger.h:79
void SetMaxOpenedFiles(Int_t newmax)
Set a limit to the number of files that TFileMerger will open simultaneously.
const Bool_t kFALSE
Definition: RtypesCore.h:92
virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type=kRegular|kAll)
Merge all objects in a directory.
void ClearObjectNames()
Definition: TFileMerger.h:86
Describe directory structure in memory.
Definition: TDirectory.h:34
int type
Definition: TGX11.cxx:120
Bool_t fLocal
Makes local copies of merging files if True (default is kTRUE)
Definition: TFileMerger.h:43
TList * GetMergeList() const
Definition: TFileMerger.h:75
void SetMergeOptions(const std::string_view &options)
Definition: TFileMerger.h:83
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fFastMethod
True if using Fast merging algorithm (default)
Definition: TFileMerger.h:34
Only the objects without a MergeAfterReset member function.
Definition: TFileMerger.h:59
void SetMergeOptions(const TString &options)
Definition: TFileMerger.h:82
Bool_t fNoTrees
True if Trees should not be merged (default is kFALSE)
Definition: TFileMerger.h:35
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
virtual void SetFastMethod(Bool_t fast=kTRUE)
Definition: TFileMerger.h:104
virtual ~TFileMerger()
Cleanup.
virtual void PrintFiles(Option_t *options)
Print list of files being merged.
Only the objects with a MergeAfterReset member function.
Definition: TFileMerger.h:58
virtual void Reset()
Reset merger file list.
const Bool_t kTRUE
Definition: RtypesCore.h:91
EPartialMergeType
Type of the partial merge.
Definition: TFileMerger.h:55
Int_t fMaxOpenedFiles
Maximum number of files opened at the same time by the TFileMerger.
Definition: TFileMerger.h:42
TList * fFileList
A list the file (TFile*) which shall be merged.
Definition: TFileMerger.h:31
Bool_t fExplicitCompLevel
True if the user explicitly requested a compressio level change (default kFALSE)
Definition: TFileMerger.h:36
Bool_t HasCompressionChange() const
Definition: TFileMerger.h:73
const char * Data() const
Definition: TString.h:347
Stopwatch class.
Definition: TStopwatch.h:28