Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VFileManager.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// Base class for File manager.
28//
29// Author: Ivana Hrivnacova, 18/06/2013 ([email protected])
30
31#ifndef G4VFileManager_h
32#define G4VFileManager_h 1
33
34#include "G4BaseFileManager.hh"
35#include "G4VTHnFileManager.hh"
36#include "globals.hh"
37
38#include <memory>
39#include <string_view>
40
41namespace tools {
42namespace histo {
43class h1d;
44class h2d;
45class h3d;
46class p1d;
47class p2d;
48}
49}
50
52{
53 public:
54 explicit G4VFileManager(const G4AnalysisManagerState& state);
55 G4VFileManager() = delete;
56 ~G4VFileManager() override = default;
57
58 // Method to open default file
59 virtual G4bool OpenFile(const G4String& fileName) = 0;
60
61 // Methods applied to file per name
62 virtual G4bool CreateFile(const G4String& fileName) = 0;
63 virtual G4bool WriteFile(const G4String& fileName) = 0;
64 virtual G4bool CloseFile(const G4String& fileName) = 0;
65 virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) = 0;
66
67 // Methods applied to all registered files
68 virtual G4bool OpenFiles() = 0;
69 virtual G4bool WriteFiles() = 0;
70 virtual G4bool CloseFiles() = 0;
71 virtual G4bool DeleteEmptyFiles() = 0;
72
73 // Clear all data
74 virtual void Clear() = 0;
75
76 // Methods for handling files and directories names
77 G4bool SetFileName(const G4String& fileName) final;
78 virtual G4bool SetHistoDirectoryName(const G4String& dirName);
79 virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
80
81 void LockDirectoryNames();
83
84 G4bool IsOpenFile() const;
87 G4int GetCycle() const;
88
89 // Access to helpers
90 template <typename HT>
91 std::shared_ptr<G4VTHnFileManager<HT>> GetHnFileManager() const;
92
93 protected:
94 // Static data members
95 static constexpr std::string_view fkClass { "G4VFileManager" };
96
97 // Data members
102
103 // FileManagers per object type
104 std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>> fH1FileManager { nullptr };
105 std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>> fH2FileManager { nullptr };
106 std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>> fH3FileManager { nullptr };
107 std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>> fP1FileManager { nullptr };
108 std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>> fP2FileManager { nullptr };
109};
110
111// inline functions
112
115
118
120{ return fIsOpenFile; }
121
124
127
129{ return fState.GetCycle(); }
130
131template <>
132inline
133std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>>
134G4VFileManager::GetHnFileManager<tools::histo::h1d>() const
135{ return fH1FileManager; }
136
137template <>
138inline
139std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>>
140G4VFileManager::GetHnFileManager<tools::histo::h2d>() const
141{ return fH2FileManager; }
142
143template <>
144inline
145std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>>
146G4VFileManager::GetHnFileManager<tools::histo::h3d>() const
147{ return fH3FileManager; }
148
149template <>
150inline
151std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>>
152G4VFileManager::GetHnFileManager<tools::histo::p1d>() const
153{ return fP1FileManager; }
154
155template <>
156inline
157std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>>
158G4VFileManager::GetHnFileManager<tools::histo::p2d>() const
159{ return fP2FileManager; }
160
161#endif
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4AnalysisManagerState & fState
virtual G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty)=0
virtual G4bool CloseFile(const G4String &fileName)=0
G4String GetNtupleDirectoryName() const
virtual G4bool WriteFile(const G4String &fileName)=0
G4int GetCycle() const
std::shared_ptr< G4VTHnFileManager< tools::histo::h3d > > fH3FileManager
~G4VFileManager() override=default
G4String GetHistoDirectoryName() const
virtual G4bool SetHistoDirectoryName(const G4String &dirName)
std::shared_ptr< G4VTHnFileManager< tools::histo::h1d > > fH1FileManager
std::shared_ptr< G4VTHnFileManager< tools::histo::p1d > > fP1FileManager
G4VFileManager()=delete
G4bool IsOpenFile() const
G4String fNtupleDirectoryName
std::shared_ptr< G4VTHnFileManager< HT > > GetHnFileManager() const
std::shared_ptr< G4VTHnFileManager< tools::histo::p2d > > fP2FileManager
G4bool SetFileName(const G4String &fileName) final
virtual G4bool CloseFiles()=0
virtual G4bool SetNtupleDirectoryName(const G4String &dirName)
virtual void Clear()=0
virtual G4bool OpenFile(const G4String &fileName)=0
std::shared_ptr< G4VTHnFileManager< tools::histo::h2d > > fH2FileManager
virtual G4bool OpenFiles()=0
virtual G4bool DeleteEmptyFiles()=0
virtual G4bool CreateFile(const G4String &fileName)=0
G4String fHistoDirectoryName
void UnlockDirectoryNames()
virtual G4bool WriteFiles()=0
static constexpr std::string_view fkClass