VMC
Version 2.2
Toggle main menu visibility
Loading...
Searching...
No Matches
source
include
TMCRootManager.h
Go to the documentation of this file.
1
#ifndef ROOT_TMCRootManager
2
#define ROOT_TMCRootManager
3
4
//------------------------------------------------
5
// The Geant4 Virtual Monte Carlo package
6
// Copyright (C) 2013 - 2018 Ivana Hrivnacova
7
// All rights reserved.
8
//
9
// For the licensing terms see geant4_vmc/LICENSE.
10
// Contact: root-vmc@cern.ch
11
//-------------------------------------------------
12
17
18
#include "
TMCtls.h
"
19
#include <Rtypes.h>
20
21
#include "TFile.h"
22
#include "TTree.h"
23
24
class
TParticle;
25
26
#if (ROOT_VERSION_CODE >= ROOT_VERSION(6, 38, 0))
27
#include <ROOT/REntry.hxx>
28
#include <ROOT/RField.hxx>
29
#include <ROOT/RNTuple.hxx>
30
#include <ROOT/RNTupleFillStatus.hxx>
31
#include <ROOT/RNTupleModel.hxx>
32
#include <ROOT/RNTupleParallelWriter.hxx>
33
#include <ROOT/RNTupleWriter.hxx>
34
35
using
ROOT::RNTupleParallelWriter;
36
37
using
ROOT::RNTupleFillStatus;
38
using
REntry
= ROOT::REntry;
39
using
RNTupleModel
= ROOT::RNTupleModel;
40
using
RNTupleWriter
= ROOT::RNTupleWriter;
41
using
RNTupleFillContext
= ROOT::RNTupleFillContext;
42
using
RNTParaWriter
= ROOT::RNTupleParallelWriter;
43
#endif
44
45
51
52
class
TMCRootManager
{
53
public
:
55
enum
FileMode
{
56
kRead
,
// Read mode
57
kWrite
// Write mode
58
};
59
enum
StorageMode
{
60
kTTree
,
// TTree storage
61
kRNTuple
// RNTuple storage
62
};
63
64
public
:
65
// static access method
66
static
TMCRootManager
*
Instance
();
67
68
// static method for activating debug mode
69
static
void
SetDebug
(Bool_t debug);
70
static
Bool_t
GetDebug
();
71
72
TMCRootManager
(
const
char
*projectName,
FileMode
fileMode =
kWrite
, Int_t threadRank = -1);
73
TMCRootManager
(
const
char
*projectName, StorageMode storageMode,
FileMode
fileMode =
kWrite
, Int_t threadRank = -1);
74
#if (ROOT_VERSION_CODE >= ROOT_VERSION(6, 38, 0))
75
TMCRootManager
(std::shared_ptr<RNTParaWriter> sharedWriter);
76
#endif
77
virtual
~TMCRootManager
();
78
79
// methods
80
template
<
typename
T>
81
void
Register
(
const
char
*name, T *&obj);
82
void
Register
(
const
char
*name,
const
char
*className,
void
*objAddress);
83
void
Register
(
const
char
*name,
const
char
*className,
const
void
*objAddress);
84
void
Fill
();
85
void
WriteAll
();
86
void
Close
();
87
void
WriteAndClose
();
88
void
ReadEvent
(Int_t i);
89
90
#if (ROOT_VERSION_CODE >= ROOT_VERSION(6, 38, 0))
91
void
CreateRNTuple
(
bool
parallelMode =
false
,
bool
workerMode =
false
);
92
std::shared_ptr<RNTParaWriter>
GetParallelRNTupleWriter
() {
return
fParaWriter
; }
93
#endif
94
95
private
:
96
// not implemented
97
TMCRootManager
(
const
TMCRootManager
&rhs);
98
TMCRootManager
&
operator=
(
const
TMCRootManager
&rhs);
99
100
// global static data members
101
static
Int_t
fgCounter
;
// The counter of instances
102
// static data members
103
static
Bool_t
fgDebug
;
// Option to activate debug printings
104
105
#if !defined(__CINT__)
106
static
TMCThreadLocal
TMCRootManager
*
fgInstance
;
// singleton instance
107
#else
108
static
TMCRootManager
*
fgInstance
;
// singleton instance
109
#endif
110
111
// Methods
112
void
OpenFile
(
const
char
*projectName,
FileMode
fileMode, Int_t threadRank);
113
114
// data members
115
Int_t
fId
;
// This manager ID
116
TFile *
fFile
{
nullptr
};
// Root output file
117
TTree *
fTree
{
nullptr
};
// Root output tree
118
119
#if (ROOT_VERSION_CODE >= ROOT_VERSION(6, 38, 0))
120
std::string
fStorageName
{};
121
std::vector<std::pair<std::string, void *>>
fNameAddress
;
122
std::unique_ptr<REntry>
fEntry
;
123
std::unique_ptr<RNTupleModel>
fModel
;
124
std::unique_ptr<RNTupleWriter>
fWriter
;
125
std::shared_ptr<RNTParaWriter>
fParaWriter
;
126
std::shared_ptr<RNTupleFillContext>
fFillContext
;
127
#endif
128
129
StorageMode
fStorageMode
{
kTTree
};
130
131
Bool_t
fIsClosed
{
false
};
// Info whether its file was closed
132
};
133
134
// inline functions
135
136
inline
void
TMCRootManager::SetDebug
(Bool_t debug)
137
{
138
fgDebug
= debug;
139
}
140
141
inline
Bool_t
TMCRootManager::GetDebug
()
142
{
143
return
fgDebug
;
144
}
145
146
template
<
typename
T>
147
void
TMCRootManager::Register
(
const
char
*brname, T *&obj)
148
{
149
if
(
fStorageMode
==
kTTree
) {
150
fFile
->cd();
151
if
(!
fTree
->GetBranch(brname))
152
fTree
->Branch(brname, &obj, 32000, 99);
153
else
154
fTree
->GetBranch(brname)->SetAddress(&obj);
155
}
156
#if (ROOT_VERSION_CODE >= ROOT_VERSION(6, 38, 0))
157
if
(
fStorageMode
==
kRNTuple
) {
158
if
(
fModel
) {
159
fModel
->MakeField<T>(brname);
160
}
161
std::string oString;
162
oString = brname;
163
fNameAddress
.push_back(std::make_pair(oString, obj));
164
}
165
#endif
166
}
167
168
#endif
// ROOT_TMCRootManager
REntry
ROOT::REntry REntry
Definition
TMCRootManager.h:38
RNTupleWriter
ROOT::RNTupleWriter RNTupleWriter
Definition
TMCRootManager.h:40
RNTParaWriter
ROOT::RNTupleParallelWriter RNTParaWriter
Definition
TMCRootManager.h:42
RNTupleModel
ROOT::RNTupleModel RNTupleModel
Definition
TMCRootManager.h:39
RNTupleFillContext
ROOT::RNTupleFillContext RNTupleFillContext
Definition
TMCRootManager.h:41
TMCtls.h
TMCRootManager
The Root IO manager for VMC examples for both sequential and multi-threaded applications.
Definition
TMCRootManager.h:52
TMCRootManager::fModel
std::unique_ptr< RNTupleModel > fModel
Definition
TMCRootManager.h:123
TMCRootManager::fId
Int_t fId
Definition
TMCRootManager.h:115
TMCRootManager::fFile
TFile * fFile
Definition
TMCRootManager.h:116
TMCRootManager::WriteAll
void WriteAll()
Definition
TMCRootManager.cxx:300
TMCRootManager::OpenFile
void OpenFile(const char *projectName, FileMode fileMode, Int_t threadRank)
Definition
TMCRootManager.cxx:167
TMCRootManager::TMCRootManager
TMCRootManager(const TMCRootManager &rhs)
TMCRootManager::ReadEvent
void ReadEvent(Int_t i)
Definition
TMCRootManager.cxx:351
TMCRootManager::Fill
void Fill()
Definition
TMCRootManager.cxx:269
TMCRootManager::fgInstance
static TMCThreadLocal TMCRootManager * fgInstance
Definition
TMCRootManager.h:106
TMCRootManager::Close
void Close()
Definition
TMCRootManager.cxx:322
TMCRootManager::FileMode
FileMode
Root file mode.
Definition
TMCRootManager.h:55
TMCRootManager::kWrite
@ kWrite
Definition
TMCRootManager.h:57
TMCRootManager::kRead
@ kRead
Definition
TMCRootManager.h:56
TMCRootManager::fWriter
std::unique_ptr< RNTupleWriter > fWriter
Definition
TMCRootManager.h:124
TMCRootManager::fFillContext
std::shared_ptr< RNTupleFillContext > fFillContext
Definition
TMCRootManager.h:126
TMCRootManager::operator=
TMCRootManager & operator=(const TMCRootManager &rhs)
TMCRootManager::fgDebug
static Bool_t fgDebug
Definition
TMCRootManager.h:103
TMCRootManager::fNameAddress
std::vector< std::pair< std::string, void * > > fNameAddress
Definition
TMCRootManager.h:121
TMCRootManager::fIsClosed
Bool_t fIsClosed
Definition
TMCRootManager.h:131
TMCRootManager::WriteAndClose
void WriteAndClose()
Definition
TMCRootManager.cxx:342
TMCRootManager::fStorageMode
StorageMode fStorageMode
Definition
TMCRootManager.h:129
TMCRootManager::fTree
TTree * fTree
Definition
TMCRootManager.h:117
TMCRootManager::fParaWriter
std::shared_ptr< RNTParaWriter > fParaWriter
Definition
TMCRootManager.h:125
TMCRootManager::fStorageName
std::string fStorageName
Definition
TMCRootManager.h:120
TMCRootManager::~TMCRootManager
virtual ~TMCRootManager()
Definition
TMCRootManager.cxx:139
TMCRootManager::fgCounter
static Int_t fgCounter
Definition
TMCRootManager.h:101
TMCRootManager::Instance
static TMCRootManager * Instance()
Definition
TMCRootManager.cxx:60
TMCRootManager::SetDebug
static void SetDebug(Bool_t debug)
Definition
TMCRootManager.h:136
TMCRootManager::TMCRootManager
TMCRootManager(const char *projectName, FileMode fileMode=kWrite, Int_t threadRank=-1)
Definition
TMCRootManager.cxx:72
TMCRootManager::fEntry
std::unique_ptr< REntry > fEntry
Definition
TMCRootManager.h:122
TMCRootManager::StorageMode
StorageMode
Definition
TMCRootManager.h:59
TMCRootManager::kRNTuple
@ kRNTuple
Definition
TMCRootManager.h:61
TMCRootManager::kTTree
@ kTTree
Definition
TMCRootManager.h:60
TMCRootManager::CreateRNTuple
void CreateRNTuple(bool parallelMode=false, bool workerMode=false)
Definition
TMCRootManager.cxx:243
TMCRootManager::GetDebug
static Bool_t GetDebug()
Definition
TMCRootManager.h:141
TMCRootManager::Register
void Register(const char *name, T *&obj)
Definition
TMCRootManager.h:147
TMCRootManager::GetParallelRNTupleWriter
std::shared_ptr< RNTParaWriter > GetParallelRNTupleWriter()
Definition
TMCRootManager.h:92
Generated on
for VMC by
1.17.0