|
||||
File indexing completed on 2025-01-18 10:10:50
0001 // @(#)root/io:$Id$ 0002 // Author: Philippe Canal, Witold Pokorski, and Guilherme Amadio 0003 0004 /************************************************************************* 0005 * Copyright (C) 1995-2017, 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_TBufferMerger 0013 #define ROOT_TBufferMerger 0014 0015 #include "TFileMerger.h" 0016 #include "TMemFile.h" 0017 #include "ROOT/RConfig.hxx" 0018 0019 #include <functional> 0020 #include <memory> 0021 #include <mutex> 0022 #include <queue> 0023 0024 namespace ROOT { 0025 0026 class TBufferMergerFile; 0027 0028 /** 0029 * \class TBufferMerger TBufferMerger.hxx 0030 * \ingroup IO 0031 * 0032 * TBufferMerger is a class to facilitate writing data in 0033 * parallel from multiple threads, while writing to a single 0034 * output file. Its purpose is similar to TParallelMergingFile, 0035 * but instead of using processes that connect to a network 0036 * socket, TBufferMerger uses threads that each write to a 0037 * TBufferMergerFile, which in turn push data into a queue 0038 * managed by the TBufferMerger. 0039 */ 0040 0041 class TBufferMerger { 0042 public: 0043 /** Constructor 0044 * @param name Output file name 0045 * @param option Output file creation options 0046 * @param compress Output file compression level 0047 */ 0048 TBufferMerger(const char *name, Option_t *option = "RECREATE", 0049 Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault); 0050 0051 /** Constructor 0052 * @param output Output \c TFile 0053 */ 0054 TBufferMerger(std::unique_ptr<TFile> output); 0055 0056 /** Destructor */ 0057 virtual ~TBufferMerger(); 0058 0059 /** Returns a TBufferMergerFile to which data can be written. 0060 * At the end, all TBufferMergerFiles get merged into the output file. 0061 * The user is responsible to "cd" into the file to associate objects 0062 * such as histograms or trees to it. 0063 * 0064 * After the creation of this file, the user must reset the kMustCleanup 0065 * bit on any objects attached to it and take care of their deletion, as 0066 * there is a possibility that a race condition will happen that causes 0067 * a crash if ROOT manages these objects. 0068 */ 0069 std::shared_ptr<TBufferMergerFile> GetFile(); 0070 0071 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") 0072 size_t GetQueueSize() const { return 0; } 0073 0074 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") 0075 size_t GetBuffered() const { return 0; } 0076 0077 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") 0078 size_t GetAutoSave() const { return 0; } 0079 0080 /** Returns the current merge options. */ 0081 const char* GetMergeOptions(); 0082 0083 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") 0084 void SetAutoSave(size_t /*size*/) {} 0085 0086 /** Sets the merge options. SetMergeOptions("fast") will disable 0087 * recompression of input data into the output if they have different 0088 * compression settings. 0089 * @param options TFileMerger/TFileMergeInfo merge options 0090 */ 0091 void SetMergeOptions(const TString& options); 0092 0093 /** Indicates that any TTree objects in the file should be skipped 0094 * and thus that steps that are specific to TTree can be skipped */ 0095 void SetNotrees(Bool_t notrees=kFALSE) 0096 { 0097 fMerger.SetNotrees(notrees); 0098 } 0099 0100 /** Returns whether the file has been marked as not containing any TTree objects 0101 * and thus that steps that are specific to TTree can be skipped */ 0102 Bool_t GetNotrees() const 0103 { 0104 return fMerger.GetNotrees(); 0105 } 0106 0107 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") 0108 void SetCompressTemporaryKeys(Bool_t /*request_compression*/ = true) {} 0109 0110 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") 0111 Bool_t GetCompressTemporaryKeys() const { return false; } 0112 0113 friend class TBufferMergerFile; 0114 0115 private: 0116 /** TBufferMerger has no default constructor */ 0117 TBufferMerger(); 0118 0119 /** TBufferMerger has no copy constructor */ 0120 TBufferMerger(const TBufferMerger &); 0121 0122 /** TBufferMerger has no copy operator */ 0123 TBufferMerger &operator=(const TBufferMerger &); 0124 0125 void Init(std::unique_ptr<TFile>); 0126 0127 void Merge(TBufferMergerFile *memfile); 0128 0129 TFileMerger fMerger{false, false}; //< TFileMerger used to merge all buffers 0130 std::mutex fMergeMutex; //< Mutex used to lock fMerger 0131 std::vector<std::weak_ptr<TBufferMergerFile>> fAttachedFiles; //< Attached files 0132 }; 0133 0134 /** 0135 * \class TBufferMergerFile TBufferMerger.hxx 0136 * \ingroup IO 0137 * 0138 * A TBufferMergerFile is similar to a TMemFile, but when data 0139 * is written to it, it is appended to the TBufferMerger queue. 0140 * The TBufferMerger merges all data into the output file on disk. 0141 */ 0142 0143 class TBufferMergerFile : public TMemFile { 0144 private: 0145 TBufferMerger &fMerger; //< TBufferMerger this file is attached to 0146 0147 /** Constructor. Can only be called by TBufferMerger. 0148 * @param m Merger this file is attached to. */ 0149 TBufferMergerFile(TBufferMerger &m); 0150 0151 /** TBufferMergerFile has no default constructor. */ 0152 TBufferMergerFile(); 0153 0154 /** TBufferMergerFile has no copy constructor. */ 0155 TBufferMergerFile(const TBufferMergerFile &); 0156 0157 /** TBufferMergerFile has no copy operator */ 0158 TBufferMergerFile &operator=(const TBufferMergerFile &); 0159 0160 friend class TBufferMerger; 0161 0162 public: 0163 /** Destructor */ 0164 ~TBufferMergerFile() override; 0165 0166 using TMemFile::Write; 0167 0168 /** Write data into a TBufferFile and append it to TBufferMerger. 0169 * @param name Name 0170 * @param opt Options 0171 * @param bufsize Buffer size 0172 * This function must be called before the TBufferMergerFile gets destroyed, 0173 * or no data is appended to the TBufferMerger. 0174 */ 0175 Int_t Write(const char *name = nullptr, Int_t opt = 0, Int_t bufsize = 0) override; 0176 0177 ClassDefOverride(TBufferMergerFile, 0); 0178 }; 0179 0180 } // namespace ROOT 0181 0182 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |