Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TFileMerger.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/io:$Id$
0002 // Author: Andreas Peters + Fons Rademakers   26/5/2005
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TFileMerger
0013 #define ROOT_TFileMerger
0014 
0015 #include "TObject.h"
0016 #include "TList.h"
0017 #include "TString.h"
0018 #include "TStopwatch.h"
0019 #include <string>
0020 
0021 class TFile;
0022 class TDirectory;
0023 class THashList;
0024 class TKey;
0025 
0026 namespace ROOT {
0027 class TIOFeatures;
0028 }  // namespace ROOT
0029 
0030 class TFileMerger : public TObject {
0031 private:
0032    using TIOFeatures = ROOT::TIOFeatures;
0033 
0034    TFileMerger(const TFileMerger&) = delete;
0035    TFileMerger& operator=(const TFileMerger&) = delete;
0036 
0037 protected:
0038    TStopwatch     fWatch;                     ///< Stop watch to measure file copy speed
0039    TList          fFileList;                  ///< A list the file (TFile*) which shall be merged
0040    TFile         *fOutputFile{nullptr};       ///< The outputfile for merging
0041    TString        fOutputFilename;            ///< The name of the outputfile for merging
0042    Bool_t         fFastMethod{kTRUE};         ///< True if using Fast merging algorithm (default)
0043    Bool_t         fNoTrees{kFALSE};           ///< True if Trees should not be merged (default is kFALSE)
0044    Bool_t         fExplicitCompLevel{kFALSE}; ///< True if the user explicitly requested a compression level change (default kFALSE)
0045    Bool_t         fCompressionChange{kFALSE}; ///< True if the output and input have different compression level (default kFALSE)
0046    Int_t          fPrintLevel{0};             ///< How much information to print out at run time
0047    TString        fMergeOptions;              ///< Options (in string format) to be passed down to the Merge functions
0048    TIOFeatures   *fIOFeatures{nullptr};       ///< IO features to use in the output file.
0049    TString        fMsgPrefix{"TFileMerger"};  ///< Prefix to be used when printing informational message (default TFileMerger)
0050 
0051    Int_t          fMaxOpenedFiles;            ///< Maximum number of files opened at the same time by the TFileMerger
0052    Bool_t         fLocal;                     ///< Makes local copies of merging files if True (default is kTRUE)
0053    Bool_t         fHistoOneGo;                ///< Merger histos in one go (default is kTRUE)
0054    TString        fObjectNames;               ///< List of object names to be either merged exclusively or skipped
0055    TList          fMergeList;                 ///< list of TObjString containing the name of the files need to be merged
0056    TList          fExcessFiles;               ///<! List of TObjString containing the name of the files not yet added to fFileList due to user or system limitation on the max number of files opened.
0057 
0058    Bool_t         OpenExcessFiles();
0059    virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress);
0060    virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type = kRegular | kAll);
0061 
0062    virtual Bool_t MergeOne(TDirectory *target, TList *sourcelist, Int_t type,
0063                 TFileMergeInfo &info, TString &oldkeyname, THashList &allNames, Bool_t &status, Bool_t &onlyListed,
0064                 const TString &path,
0065                 TDirectory *current_sourcedir, TFile *current_file,
0066                 TKey *key, TObject *obj, TIter &nextkey);
0067 public:
0068    /// Type of the partial merge
0069    enum EPartialMergeType {
0070       kRegular      = 0,             ///< Normal merge, overwriting the output file.
0071       kIncremental  = BIT(1),        ///< Merge the input file with the content of the output file (if already existing).
0072       kResetable    = BIT(2),        ///< Only the objects with a MergeAfterReset member function.
0073       kNonResetable = BIT(3),        ///< Only the objects without a MergeAfterReset member function.
0074       kDelayWrite   = BIT(4),        ///< Delay the TFile write (to reduce the number of write when reusing the file)
0075 
0076       kAll            = BIT(2)|BIT(3),      ///< Merge all type of objects (default)
0077       kAllIncremental = kIncremental | kAll, ///< Merge incrementally all type of objects.
0078 
0079       kOnlyListed     = BIT(5),        ///< Only the objects specified in fObjectNames list
0080       kSkipListed     = BIT(6),        ///< Skip objects specified in fObjectNames list
0081       kKeepCompression= BIT(7)         ///< Keep compression level unchanged for each input files
0082    };
0083 
0084    TFileMerger(Bool_t isLocal = kTRUE, Bool_t histoOneGo = kTRUE);
0085    ~TFileMerger() override;
0086 
0087    Int_t       GetPrintLevel() const { return fPrintLevel; }
0088    void        SetPrintLevel(Int_t level) { fPrintLevel = level; }
0089    Bool_t      HasCompressionChange() const { return fCompressionChange; }
0090    const char *GetOutputFileName() const { return fOutputFilename; }
0091    TList      *GetMergeList() { return &fMergeList; }
0092    TFile      *GetOutputFile() const { return fOutputFile; }
0093    Int_t       GetMaxOpenedFiles() const { return fMaxOpenedFiles; }
0094    void        SetMaxOpenedFiles(Int_t newmax);
0095    const char *GetMsgPrefix() const { return fMsgPrefix; }
0096    void        SetMsgPrefix(const char *prefix);
0097    const char *GetMergeOptions() { return fMergeOptions; }
0098    void        SetMergeOptions(const TString &options) { fMergeOptions = options; }
0099    void        SetMergeOptions(const std::string_view &options) { fMergeOptions = options; }
0100    void        SetIOFeatures(ROOT::TIOFeatures &features) { fIOFeatures = &features; }
0101    void        AddObjectNames(const char *name) {fObjectNames += name; fObjectNames += " ";}
0102    const char *GetObjectNames() const {return fObjectNames.Data();}
0103    void        ClearObjectNames() {fObjectNames.Clear();}
0104 
0105     //--- file management interface
0106    virtual Bool_t SetCWD(const char * /*path*/) { MayNotUse("SetCWD"); return kFALSE; }
0107    virtual const char *GetCWD() { MayNotUse("GetCWD"); return nullptr; }
0108 
0109    //--- file merging interface
0110    virtual void   Reset();
0111    virtual Bool_t AddFile(const char *url, Bool_t cpProgress = kTRUE);
0112    virtual Bool_t AddFile(TFile *source, Bool_t cpProgress = kTRUE);
0113    virtual Bool_t AddAdoptFile(TFile *source, Bool_t cpProgress = kTRUE);
0114    virtual Bool_t OutputFile(const char *url, Bool_t force);
0115    virtual Bool_t OutputFile(const char *url, Bool_t force, Int_t compressionLevel);
0116    virtual Bool_t OutputFile(const char *url, const char *mode = "RECREATE");
0117    virtual Bool_t OutputFile(const char *url, const char *mode, Int_t compressionLevel);
0118    virtual Bool_t OutputFile(std::unique_ptr<TFile> file);
0119    virtual void   PrintFiles(Option_t *options);
0120    virtual Bool_t Merge(Bool_t = kTRUE);
0121    virtual Bool_t PartialMerge(Int_t type = kAll | kIncremental);
0122    virtual void   SetFastMethod(Bool_t fast=kTRUE)  {fFastMethod = fast;}
0123            Bool_t GetNotrees() const { return fNoTrees; }
0124    virtual void   SetNotrees(Bool_t notrees=kFALSE) {fNoTrees = notrees;}
0125            void   RecursiveRemove(TObject *obj) override;
0126 
0127    ClassDefOverride(TFileMerger, 6)  // File copying and merging services
0128 };
0129 
0130 #endif
0131