VMC Version 2.2
Loading...
Searching...
No Matches
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 "TMCRNTupleWriter.h"
21#include "TMCTTreeWriter.h"
22
23#include <Rtypes.h>
24
25class TFile;
26
32
34public:
36 enum FileMode {
37 kRead, // Read mode
38 kWrite // Write mode
39 };
41 kTTree, // TTree storage
42 kRNTuple, // RNTuple storage
43 kRNTupleParallel // RNTuple storage with parallel write
44 };
45
46public:
47 // static access method
48 static TMCRootManager *Instance();
49
50 // static method for activating debug mode
51 static void SetDebug(Bool_t debug);
52 static Bool_t GetDebug();
53 static void SetStorageMode(StorageMode mode);
55 static TString GetFileModifier(StorageMode mode);
56
57 TMCRootManager(const char *projectName, FileMode fileMode = kWrite, Int_t threadRank = -1);
58 virtual ~TMCRootManager();
59
60 // methods
61 template <typename T>
62 void Register(const char *name, T *&obj);
63 void Register(const char *name, const char *className, void *objAddress);
64 void Register(const char *name, const char *className, const void *objAddress);
65 void CreateRNTuple();
66 void Fill();
67 void WriteAll();
68 void Close();
69 void WriteAndClose();
70 void ReadEvent(Int_t i);
71
72 // get methods
73 TString GetFileModifier() const;
75
76private:
77 // not implemented
80
81 // global static data members
82 static Int_t fgCounter; // The counter of instances
83 // static data members
84 static Bool_t fgDebug; // Option to activate debug printings
86
87#if !defined(__CINT__)
88 static TMCThreadLocal TMCRootManager *fgInstance; // singleton thread local instance
89#else
90 static TMCRootManager *fgInstance; // singleton instance
91#endif
92
93 // Methods
94 void OpenFile(const char *projectName, FileMode fileMode, Int_t threadRank);
95
96 // data members
97 Int_t fId{0}; // This manager ID
98 TFile *fFile{nullptr}; // Root output file
99 TMCVNtupleWriter* fNtupleWriter{nullptr}; // ntuple manager
100 Bool_t fIsClosed{false}; // Info whether its file was closed
101};
102
103// inline functions
104
105inline void TMCRootManager::SetDebug(Bool_t debug)
106{
107 fgDebug = debug;
108}
109
111{
112 return fgDebug;
113}
114
119
120template <typename T>
121void TMCRootManager::Register(const char *brname, T *&obj)
122{
123 if (fgStorageMode == kTTree) {
124 dynamic_cast<TMCTTreeWriter*>(fNtupleWriter)->Register<T>(brname, obj);
125 }
126 if (fgStorageMode == kRNTuple) {
127 dynamic_cast<TMCRNTupleWriter*>(fNtupleWriter)->Register<T>(brname, obj);
128 }
130 dynamic_cast<TMCRNTupleParallelWriter*>(fNtupleWriter)->Register<T>(brname, obj);
131 }
132}
133
134#endif // ROOT_TMCRootManager
Definition of the TMCRNTupleParallelWriter class.
Definition of the TMCRNTupleWriter class.
Definition of the TMCTTreeWriter class.
The Root IO manager for VMC examples for both sequential and multi-threaded applications.
TMCVNtupleWriter * fNtupleWriter
void OpenFile(const char *projectName, FileMode fileMode, Int_t threadRank)
TMCRootManager(const TMCRootManager &rhs)
void ReadEvent(Int_t i)
static TMCThreadLocal TMCRootManager * fgInstance
FileMode
Root file mode.
static StorageMode fgStorageMode
TMCRootManager & operator=(const TMCRootManager &rhs)
static Bool_t fgDebug
TString GetFileModifier() const
virtual ~TMCRootManager()
static Int_t fgCounter
static TMCRootManager * Instance()
static void SetDebug(Bool_t debug)
TMCRootManager(const char *projectName, FileMode fileMode=kWrite, Int_t threadRank=-1)
static StorageMode GetStorageMode()
TMCVNtupleWriter * GetNtupleWriter()
static Bool_t GetDebug()
static void SetStorageMode(StorageMode mode)
void Register(const char *name, T *&obj)