Geant4-11
G4RootFileManager.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27// The manager for Root output file operations.
28
29// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
30
31#ifndef G4RootFileManager_h
32#define G4RootFileManager_h 1
33
34#include "G4VTFileManager.hh"
35#include "G4RootFileDef.hh"
37#include "globals.hh"
38
39#include <vector>
40#include <memory>
41#include <tuple>
42#include <string_view>
43
44namespace tools {
45namespace wroot{
46class ntuple;
47}
48}
49
50// Types alias
52
53class G4RootFileManager : public G4VTFileManager<G4RootFile>
54{
55 public:
56 explicit G4RootFileManager(const G4AnalysisManagerState& state);
58 virtual ~G4RootFileManager() = default;
59
63
64 // Methods to manipulate file from base classes
65 virtual G4bool OpenFile(const G4String& fileName) final;
66
67 virtual G4String GetFileType() const final { return "root"; }
68
69 // Specific methods for files per objects
70 std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription,
71 G4int mainNumber = -1);
72 std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription,
73 G4bool perThread = true,
74 G4int mainNumber = -1) const;
77
78 // Set methods
79 void SetBasketSize(unsigned int basketSize);
80 void SetBasketEntries(unsigned int basketEntries);
81
82 // Get methods
83 unsigned int GetBasketSize() const;
84 unsigned int GetBasketEntries() const;
85
86 protected:
87 // Methods derived from templated base class
88 virtual std::shared_ptr<G4RootFile> CreateFileImpl(const G4String& fileName) final;
89 virtual G4bool WriteFileImpl(std::shared_ptr<G4RootFile> file) final;
90 virtual G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final;
91
92 private:
93 // Methods
94 tools::wroot::directory* CreateDirectory(
95 tools::wroot::file* rfile,
96 const G4String& directoryName,
97 const G4String& objectType) const;
99 RootNtupleDescription* ntupleDescription,
100 G4bool perThread = true,
101 G4int mainNumber = -1) const;
102
103 // Static data members
104 static constexpr std::string_view fkClass { "G4RootFileManager" };
105
106 // Data members
109};
110
111// inline functions
112
113//_____________________________________________________________________________
114inline void G4RootFileManager::SetBasketSize(unsigned int basketSize)
115{ fBasketSize = basketSize; }
116
117//_____________________________________________________________________________
118inline void G4RootFileManager::SetBasketEntries(unsigned int basketEntries)
119{ fBasketEntries = basketEntries; }
120
121//_____________________________________________________________________________
122inline unsigned int G4RootFileManager::GetBasketSize() const
123{ return fBasketSize; }
124
125//_____________________________________________________________________________
126inline unsigned int G4RootFileManager::GetBasketEntries() const
127{ return fBasketEntries; }
128
129#endif
130
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4String GetNtupleFileName(const G4String &ntupleName) const
static constexpr std::string_view fkClass
G4bool CloseNtupleFile(RootNtupleDescription *ntupleDescription)
G4bool WriteNtupleFile(RootNtupleDescription *ntupleDescription)
unsigned int GetBasketSize() const
unsigned int fBasketSize
virtual std::shared_ptr< G4RootFile > CreateFileImpl(const G4String &fileName) final
unsigned int GetBasketEntries() const
tools::wroot::directory * CreateDirectory(tools::wroot::file *rfile, const G4String &directoryName, const G4String &objectType) const
G4String GetNtupleFileName(RootNtupleDescription *ntupleDescription, G4bool perThread=true, G4int mainNumber=-1) const
void SetBasketSize(unsigned int basketSize)
virtual G4String GetFileType() const final
virtual G4bool CloseFileImpl(std::shared_ptr< G4RootFile > file) final
unsigned int fBasketEntries
virtual ~G4RootFileManager()=default
G4RootFileManager()=delete
std::shared_ptr< G4RootFile > GetNtupleFile(RootNtupleDescription *ntupleDescription, G4bool perThread=true, G4int mainNumber=-1) const
void SetBasketEntries(unsigned int basketEntries)
virtual G4bool OpenFile(const G4String &fileName) final
virtual G4bool WriteFileImpl(std::shared_ptr< G4RootFile > file) final
std::shared_ptr< G4RootFile > CreateNtupleFile(RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
constexpr unsigned int kDefaultBasketSize
constexpr unsigned int kDefaultBasketEntries