Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBufferMerger.hxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Philippe Canal, Witold Pokorski, and Guilherme Amadio
3
4/*************************************************************************
5 * Copyright (C) 1995-2017, 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_TBufferMerger
13#define ROOT_TBufferMerger
14
15#include "TFileMerger.h"
16#include "TMemFile.h"
17#include "ROOT/RConfig.hxx"
18
19#include <functional>
20#include <memory>
21#include <mutex>
22#include <queue>
23
24namespace ROOT {
25
26class TBufferMergerFile;
27
28/**
29 * \class TBufferMerger TBufferMerger.hxx
30 * \ingroup IO
31 *
32 * TBufferMerger is a class to facilitate writing data in
33 * parallel from multiple threads, while writing to a single
34 * output file. Its purpose is similar to TParallelMergingFile,
35 * but instead of using processes that connect to a network
36 * socket, TBufferMerger uses threads that each write to a
37 * TBufferMergerFile, which in turn push data into a queue
38 * managed by the TBufferMerger.
39 */
40
42public:
43 /** Constructor
44 * @param name Output file name
45 * @param option Output file creation options
46 * @param compress Output file compression level
47 */
48 TBufferMerger(const char *name, Option_t *option = "RECREATE",
50
51 /** Constructor
52 * @param output Output \c TFile
53 */
54 TBufferMerger(std::unique_ptr<TFile> output);
55
56 /** Destructor */
57 virtual ~TBufferMerger();
58
59 /** Returns a TBufferMergerFile to which data can be written.
60 * At the end, all TBufferMergerFiles get merged into the output file.
61 * The user is responsible to "cd" into the file to associate objects
62 * such as histograms or trees to it.
63 *
64 * After the creation of this file, the user must reset the kMustCleanup
65 * bit on any objects attached to it and take care of their deletion, as
66 * there is a possibility that a race condition will happen that causes
67 * a crash if ROOT manages these objects.
68 */
69 std::shared_ptr<TBufferMergerFile> GetFile();
70
71 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32")
72 size_t GetQueueSize() const { return 0; }
73
74 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32")
75 size_t GetBuffered() const { return 0; }
76
77 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32")
78 size_t GetAutoSave() const { return 0; }
79
80 /** Returns the current merge options. */
81 const char* GetMergeOptions();
82
83 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32")
84 void SetAutoSave(size_t /*size*/) {}
85
86 /** Sets the merge options. SetMergeOptions("fast") will disable
87 * recompression of input data into the output if they have different
88 * compression settings.
89 * @param options TFileMerger/TFileMergeInfo merge options
90 */
91 void SetMergeOptions(const TString& options);
92
93 /** Indicates that any TTree objects in the file should be skipped
94 * and thus that steps that are specific to TTree can be skipped */
95 void SetNotrees(Bool_t notrees=kFALSE)
96 {
97 fMerger.SetNotrees(notrees);
98 }
99
100 /** Returns whether the file has been marked as not containing any TTree objects
101 * and thus that steps that are specific to TTree can be skipped */
103 {
104 return fMerger.GetNotrees();
105 }
106
107 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32")
108 void SetCompressTemporaryKeys(Bool_t /*request_compression*/ = true) {}
109
110 _R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32")
111 Bool_t GetCompressTemporaryKeys() const { return false; }
112
113 friend class TBufferMergerFile;
114
115private:
116 /** TBufferMerger has no default constructor */
118
119 /** TBufferMerger has no copy constructor */
121
122 /** TBufferMerger has no copy operator */
124
125 void Init(std::unique_ptr<TFile>);
126
127 void Merge(TBufferMergerFile *memfile);
128
129 TFileMerger fMerger{false, false}; //< TFileMerger used to merge all buffers
130 std::mutex fMergeMutex; //< Mutex used to lock fMerger
131 std::vector<std::weak_ptr<TBufferMergerFile>> fAttachedFiles; //< Attached files
132};
133
134/**
135 * \class TBufferMergerFile TBufferMerger.hxx
136 * \ingroup IO
137 *
138 * A TBufferMergerFile is similar to a TMemFile, but when data
139 * is written to it, it is appended to the TBufferMerger queue.
140 * The TBufferMerger merges all data into the output file on disk.
141 */
142
144private:
145 TBufferMerger &fMerger; //< TBufferMerger this file is attached to
146
147 /** Constructor. Can only be called by TBufferMerger.
148 * @param m Merger this file is attached to. */
150
151 /** TBufferMergerFile has no default constructor. */
153
154 /** TBufferMergerFile has no copy constructor. */
156
157 /** TBufferMergerFile has no copy operator */
159
160 friend class TBufferMerger;
161
162public:
163 /** Destructor */
164 ~TBufferMergerFile() override;
165
166 using TMemFile::Write;
167
168 /** Write data into a TBufferFile and append it to TBufferMerger.
169 * @param name Name
170 * @param opt Options
171 * @param bufsize Buffer size
172 * This function must be called before the TBufferMergerFile gets destroyed,
173 * or no data is appended to the TBufferMerger.
174 */
175 Int_t Write(const char *name = nullptr, Int_t opt = 0, Int_t bufsize = 0) override;
176
178};
179
180} // namespace ROOT
181
182#endif
#define _R__DEPRECATED_LATER(REASON)
Definition RConfig.hxx:469
bool Bool_t
Definition RtypesCore.h:63
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
A TBufferMergerFile is similar to a TMemFile, but when data is written to it, it is appended to the T...
TBufferMergerFile()
TBufferMergerFile has no default constructor.
TBufferMergerFile(const TBufferMergerFile &)
TBufferMergerFile has no copy constructor.
TBufferMergerFile & operator=(const TBufferMergerFile &)
TBufferMergerFile has no copy operator.
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write data into a TBufferFile and append it to TBufferMerger.
~TBufferMergerFile() override
Destructor.
TBufferMerger is a class to facilitate writing data in parallel from multiple threads,...
_R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") size_t GetQueueSize() const
_R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") void SetCompressTemporaryKeys(Bool_t
_R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") size_t GetAutoSave() const
Bool_t GetNotrees() const
Returns whether the file has been marked as not containing any TTree objects and thus that steps that...
void Merge(TBufferMergerFile *memfile)
std::vector< std::weak_ptr< TBufferMergerFile > > fAttachedFiles
_R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") size_t GetBuffered() const
virtual ~TBufferMerger()
Destructor.
TBufferMerger(const TBufferMerger &)
TBufferMerger has no copy constructor.
void SetNotrees(Bool_t notrees=kFALSE)
Indicates that any TTree objects in the file should be skipped and thus that steps that are specific ...
std::shared_ptr< TBufferMergerFile > GetFile()
Returns a TBufferMergerFile to which data can be written.
TBufferMerger & operator=(const TBufferMerger &)
TBufferMerger has no copy operator.
const char * GetMergeOptions()
Returns the current merge options.
_R__DEPRECATED_LATER("The queuing mechanism in TBufferMerger was removed in ROOT v6.32") void SetAutoSave(size_t)
TBufferMerger()
TBufferMerger has no default constructor.
void SetMergeOptions(const TString &options)
Sets the merge options.
void Init(std::unique_ptr< TFile >)
virtual Int_t Write(const char *=nullptr, Int_t=0, Int_t=0) override
Write this object to the current directory.
Definition TDirectory.h:264
This class provides file copy and merging services.
Definition TFileMerger.h:30
Bool_t GetNotrees() const
virtual void SetNotrees(Bool_t notrees=kFALSE)
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:19
Basic string class.
Definition TString.h:139
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
@ kUseCompiledDefault
Use the compile-time default setting.
Definition Compression.h:53
TMarker m
Definition textangle.C:8
static void output()