Geant4-11
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 (ivana@ipno.in2p3.fr)
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}
52{
53 public:
54 explicit G4VFileManager(const G4AnalysisManagerState& state);
55 G4VFileManager() = delete;
56 virtual ~G4VFileManager() = 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 WriteFiles() = 0;
69 virtual G4bool CloseFiles() = 0;
70 virtual G4bool DeleteEmptyFiles() = 0;
71
72 // Clear all data
73 virtual void Clear() = 0;
74
75 // Methods for handling files and directories names
76 virtual G4bool SetFileName(const G4String& fileName) final;
77 virtual G4bool SetHistoDirectoryName(const G4String& dirName);
78 virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
79
80 void LockDirectoryNames();
82
83 G4bool IsOpenFile() const;
86
87 // Access to helpers
88 template <typename HT>
89 std::shared_ptr<G4VTHnFileManager<HT>> GetHnFileManager() const;
90
91 protected:
92 // Static data members
93 static constexpr std::string_view fkClass { "G4VFileManager" };
94
95 // Data members
100
101 // FileManagers per object type
102 std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>> fH1FileManager { nullptr };
103 std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>> fH2FileManager { nullptr };
104 std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>> fH3FileManager { nullptr };
105 std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>> fP1FileManager { nullptr };
106 std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>> fP2FileManager { nullptr };
107};
108
109// inline functions
110
112{ fLockDirectoryNames = true; }
113
115{ fLockDirectoryNames = false; }
116
118{ return fIsOpenFile; }
119
121{ return fHistoDirectoryName; }
122
124{ return fNtupleDirectoryName; }
125
126template <>
127inline
128std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>>
129G4VFileManager::GetHnFileManager<tools::histo::h1d>() const
130{ return fH1FileManager; }
131
132template <>
133inline
134std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>>
135G4VFileManager::GetHnFileManager<tools::histo::h2d>() const
136{ return fH2FileManager; }
137
138template <>
139inline
140std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>>
141G4VFileManager::GetHnFileManager<tools::histo::h3d>() const
142{ return fH3FileManager; }
143
144template <>
145inline
146std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>>
147G4VFileManager::GetHnFileManager<tools::histo::p1d>() const
148{ return fP1FileManager; }
149
150template <>
151inline
152std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>>
153G4VFileManager::GetHnFileManager<tools::histo::p2d>() const
154{ return fP2FileManager; }
155
156#endif
bool G4bool
Definition: G4Types.hh:86
virtual ~G4VFileManager()=default
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
std::shared_ptr< G4VTHnFileManager< tools::histo::h3d > > fH3FileManager
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 fLockDirectoryNames
virtual G4bool SetFileName(const G4String &fileName) final
virtual G4bool CloseFiles()=0
virtual G4bool SetNtupleDirectoryName(const G4String &dirName)
virtual void Clear()=0
void LockDirectoryNames()
virtual G4bool OpenFile(const G4String &fileName)=0
std::shared_ptr< G4VTHnFileManager< tools::histo::h2d > > fH2FileManager
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