VMC Version 2.2
Loading...
Searching...
No Matches
TMCRNTupleWriter.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2013 - 2018 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
17
18#include "TMCRNTupleWriter.h"
19
20#include <TFile.h>
21
22#if (ROOT_VERSION_CODE >= ROOT_VERSION(6, 38, 0))
23
24//
25// ctors, dtor
26//
27
28//_____________________________________________________________________________
29TMCRNTupleWriter::TMCRNTupleWriter(const char *storageName, TFile* file, Bool_t workerMode)
30 : TMCVNtupleWriter(storageName, file, workerMode)
31 {
32 fModel = RNTupleModel::Create();
33 }
34
35//
36// public methods
37//
38
39//_____________________________________________________________________________
41{
42 if (!fFile) {
43 Error("TMCRNTupleWriter", "File not found, cannot create rntuple.");
44 return;
45 }
46
47 fWriter = RNTupleWriter::Append(std::move(fModel), fStorageName.c_str(), *fFile);
48 fEntry = fWriter->GetModel().CreateBareEntry();
49 for (auto nameAddress : fNameAddress) {
50 fEntry->BindRawPtr(nameAddress.first, nameAddress.second);
51 }
52}
53
54//_____________________________________________________________________________
56{
58 RNTupleFillStatus status;
59 fWriter->FillNoFlush(*fEntry, status);
60 if (status.ShouldFlushCluster()) {
61 // If we are asked to flush, first try to do as much work as possible outside of the critical section:
62 // FlushColumns() will flush column data and trigger compression, but not actually write to storage.
63 // (A framework may of course also decide to flush more often.)
64 fWriter->FlushColumns();
65 {
66 // FlushCluster() will flush data to the underlying TFile, so it requires synchronization.
67 fWriter->FlushCluster();
68 }
69 }
70}
71
72//_____________________________________________________________________________
74{
76 fModel.reset();
77 fWriter.reset();
78}
79
80#endif
Definition of the TMCRNTupleWriter class.
std::unique_ptr< REntry > fEntry
virtual void WriteAll() override
virtual void Fill() override
TMCRNTupleWriter()=delete
std::unique_ptr< RNTupleModel > fModel
std::unique_ptr< RNTupleWriter > fWriter
virtual void CreateRNTuple() override
std::vector< std::pair< std::string, void * > > fNameAddress
std::string fStorageName
TMCVNtupleWriter(const char *storageName, TFile *file, Bool_t workerMode)