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