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
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
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
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:267
char name[80]
Definition TGX11.cxx:148
float * q
#define gROOT
Definition TROOT.h:417
externTVirtualMutex * gROOTMutex
Definition TROOT.h:63
#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
friend class TBufferMergerFile
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
@ kAll
Merge all type of objects (default).
Definition TFileMerger.h:87
@ kIncremental
Merge the input file with the content of the output file (if already existing).
Definition TFileMerger.h:82
@ kKeepCompression
Keep compression level unchanged for each input files.
Definition TFileMerger.h:92
@ kDelayWrite
Delay the TFile write (to reduce the number of write when reusing the file).
Definition TFileMerger.h:85
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
virtual void WriteStreamerInfo()
Write the list of TStreamerInfo as a single object in this file The class Streamer description for al...
Definition TFile.cxx:3490
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:3787
@ kOverwrite
overwrite existing object with same name
Definition TObject.h:101
Basic string class.
Definition TString.h:138
The namespace of The Lean Mean C++ Option Parser.