Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBufferMerger.cxx
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
13
14#include "TBufferFile.h"
15#include "TError.h"
16#include "TROOT.h"
17#include "TVirtualMutex.h"
18
19#include <utility>
20
21namespace ROOT {
22
23TBufferMerger::TBufferMerger(const char *name, Option_t *option, Int_t compress)
24{
25 // We cannot chain constructors or use in-place initialization here because
26 // instantiating a TBufferMerger should not alter gDirectory's state.
28 Init(std::unique_ptr<TFile>(TFile::Open(name, option, /* title */ name, compress)));
29}
30
31TBufferMerger::TBufferMerger(std::unique_ptr<TFile> output)
32{
33 Init(std::move(output));
34}
35
36void TBufferMerger::Init(std::unique_ptr<TFile> output)
37{
38 if (!output || !output->IsWritable() || output->IsZombie())
39 Error("TBufferMerger", "cannot write to output file");
40
41 fMerger.OutputFile(std::move(output));
42}
43
45{
46 for (const auto &f : fAttachedFiles)
47 if (!f.expired()) Fatal("TBufferMerger", " TBufferMergerFiles must be destroyed before the server");
48
49 // Since we support purely incremental merging, Merge does not write the target objects
50 // that are attached to the file (TTree and histograms) and thus we need to write them
51 // now.
52 if (TFile *out = fMerger.GetOutputFile())
53 out->Write("",TObject::kOverwrite);
54}
55
56std::shared_ptr<TBufferMergerFile> TBufferMerger::GetFile()
57{
59 std::shared_ptr<TBufferMergerFile> f(new TBufferMergerFile(*this));
60 gROOT->GetListOfFiles()->Remove(f.get());
61 fAttachedFiles.push_back(f);
62 return f;
63}
64
66{
67 return fMerger.GetMergeOptions();
68}
69
70
72{
73 fMerger.SetMergeOptions(options);
74}
75
77{
78 std::lock_guard q(fMergeMutex);
79 memfile->WriteStreamerInfo();
80 fMerger.AddFile(memfile);
83 fMerger.Reset();
84}
85
86} // namespace ROOT
#define f(i)
Definition RSha256.hxx:104
const char Option_t
Definition RtypesCore.h:66
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition TError.cxx:244
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
float * q
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:406
#define R__LOCKGUARD(mutex)
A TBufferMergerFile is similar to a TMemFile, but when data is written to it, it is appended to the T...
void Merge(TBufferMergerFile *memfile)
std::vector< std::weak_ptr< TBufferMergerFile > > fAttachedFiles
virtual ~TBufferMerger()
Destructor.
std::shared_ptr< TBufferMergerFile > GetFile()
Returns a TBufferMergerFile to which data can be written.
const char * GetMergeOptions()
Returns the current merge options.
TBufferMerger()
TBufferMerger has no default constructor.
void SetMergeOptions(const TString &options)
Sets the merge options.
void Init(std::unique_ptr< TFile >)
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
TFile * GetOutputFile() const
Definition TFileMerger.h:92
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...
const char * GetMergeOptions()
Definition TFileMerger.h:97
@ kAll
Merge all type of objects (default)
Definition TFileMerger.h:76
@ kIncremental
Merge the input file with the content of the output file (if already existing).
Definition TFileMerger.h:71
@ kKeepCompression
Keep compression level unchanged for each input files.
Definition TFileMerger.h:81
@ kDelayWrite
Delay the TFile write (to reduce the number of write when reusing the file)
Definition TFileMerger.h:74
void SetMergeOptions(const TString &options)
Definition TFileMerger.h:98
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
virtual void Reset()
Reset merger file list.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
virtual void WriteStreamerInfo()
Write the list of TStreamerInfo as a single object in this file The class Streamer description for al...
Definition TFile.cxx:3792
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4089
@ kOverwrite
overwrite existing object with same name
Definition TObject.h:92
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...
static void output()