Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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 ([email protected])
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 ~G4RootFileManager() override = default;
59
63
64 // Methods to manipulate file from base classes
65 G4bool OpenFile(const G4String& fileName) final;
66
67 G4String GetFileType() const final { return "root"; }
68 G4bool HasCycles() const final { return true; }
69
70 // Specific methods for files per objects
71 std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription,
72 G4int mainNumber = -1);
73 std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription,
74 G4bool perThread = true,
75 G4int mainNumber = -1) const;
77 G4int mainNumber = -1);
78
79 // Set methods
80 void SetBasketSize(unsigned int basketSize);
81 void SetBasketEntries(unsigned int basketEntries);
82
83 // Get methods
84 unsigned int GetBasketSize() const;
85 unsigned int GetBasketEntries() const;
86
87 protected:
88 // Methods derived from templated base class
89 std::shared_ptr<G4RootFile> CreateFileImpl(const G4String& fileName) final;
90 G4bool WriteFileImpl(std::shared_ptr<G4RootFile> file) final;
91 G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final;
92
93 private:
94 // Methods
95 tools::wroot::directory* CreateDirectory(
96 tools::wroot::file* rfile,
97 const G4String& directoryName,
98 const G4String& objectType) const;
99 G4String GetNtupleFileName(
100 RootNtupleDescription* ntupleDescription,
101 G4bool perThread = true,
102 G4int mainNumber = -1) const;
103
104 // Static data members
105 static constexpr std::string_view fkClass { "G4RootFileManager" };
106
107 // Data members
108 unsigned int fBasketSize { G4Analysis::kDefaultBasketSize };
109 unsigned int fBasketEntries { G4Analysis::kDefaultBasketEntries };
110};
111
112// inline functions
113
114//_____________________________________________________________________________
115inline void G4RootFileManager::SetBasketSize(unsigned int basketSize)
116{ fBasketSize = basketSize; }
117
118//_____________________________________________________________________________
119inline void G4RootFileManager::SetBasketEntries(unsigned int basketEntries)
120{ fBasketEntries = basketEntries; }
121
122//_____________________________________________________________________________
123inline unsigned int G4RootFileManager::GetBasketSize() const
124{ return fBasketSize; }
125
126//_____________________________________________________________________________
127inline unsigned int G4RootFileManager::GetBasketEntries() const
128{ return fBasketEntries; }
129
130#endif
131
std::tuple< std::shared_ptr< tools::wroot::file >, tools::wroot::directory *, tools::wroot::directory * > G4RootFile
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String GetNtupleFileName(const G4String &ntupleName, G4int cycle=0) const
unsigned int GetBasketSize() const
std::shared_ptr< G4RootFile > CreateFileImpl(const G4String &fileName) final
unsigned int GetBasketEntries() const
G4bool HasCycles() const final
~G4RootFileManager() override=default
void SetBasketSize(unsigned int basketSize)
G4bool CloseNtupleFile(RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
G4bool CloseFileImpl(std::shared_ptr< G4RootFile > file) final
G4RootFileManager()=delete
std::shared_ptr< G4RootFile > GetNtupleFile(RootNtupleDescription *ntupleDescription, G4bool perThread=true, G4int mainNumber=-1) const
void SetBasketEntries(unsigned int basketEntries)
G4bool OpenFile(const G4String &fileName) final
G4bool WriteFileImpl(std::shared_ptr< G4RootFile > file) final
std::shared_ptr< G4RootFile > CreateNtupleFile(RootNtupleDescription *ntupleDescription, G4int mainNumber=-1)
G4String GetFileType() const final
G4bool WriteFile(const G4String &fileName) final
G4bool CloseFile(const G4String &fileName) final
constexpr unsigned int kDefaultBasketSize
constexpr unsigned int kDefaultBasketEntries