Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4TFileManager.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// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
28
29#ifndef G4TFileManager_h
30#define G4TFileManager_h 1
31
32#include "G4TFileInformation.hh"
33
34#include <vector>
35#include <memory>
36#include <string_view>
37
38template <typename FT>
40{
41 public:
42 explicit G4TFileManager(const G4AnalysisManagerState& state);
43 G4TFileManager() = delete;
44 virtual ~G4TFileManager();
45
46 // Per file methods
47 // (implements all tests and warnings, fills the map)
48 std::shared_ptr<FT> CreateTFile(const G4String& fileName);
49 G4bool WriteTFile(const G4String& fileName);
50 G4bool CloseTFile(const G4String& fileName);
51 G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty);
52 //
53 std::shared_ptr<FT> GetTFile(const G4String& fileName, G4bool warn = true) const;
54
55 // Methods applied to all registered files
60
61 // Clear all data
62 void ClearData();
63
64 protected:
65 // Methods to be implemented per file type manipulate file
66 virtual std::shared_ptr<FT> CreateFileImpl(const G4String& fileName) = 0;
67 virtual G4bool WriteFileImpl(std::shared_ptr<FT> file) = 0;
68 virtual G4bool CloseFileImpl(std::shared_ptr<FT> file) = 0;
69
70 private:
71 // Methods
72 void FileNotFoundWarning(const G4String& fileName,
73 std::string_view functionName) const;
74 G4TFileInformation<FT>* GetFileInfoInFunction(const G4String& fileName,
75 std::string_view functionName, G4bool warn = true) const;
76 std::shared_ptr<FT> GetFileInFunction(const G4String& fileName,
77 std::string_view functionName, G4bool warn = true) const;
78
79 G4bool WriteTFile(std::shared_ptr<FT> file, const G4String& fileName);
80 G4bool CloseTFile(std::shared_ptr<FT> file, const G4String& fileName);
81 G4bool DeleteEmptyFile(const G4String& fileName);
82
83 // Static data members
84 static constexpr std::string_view fkClass { "G4TFileManager<FT>" };
85
86 // Data members
87 const G4AnalysisManagerState& fAMState;
88 std::map<G4String, G4TFileInformation<FT>*> fFileMap;
89 };
90
91#include "G4TFileManager.icc"
92
93#endif
bool G4bool
Definition G4Types.hh:86
G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty)
G4bool CloseTFile(const G4String &fileName)
virtual std::shared_ptr< FT > CreateFileImpl(const G4String &fileName)=0
virtual G4bool CloseFileImpl(std::shared_ptr< FT > file)=0
G4TFileManager(const G4AnalysisManagerState &state)
virtual ~G4TFileManager()
std::shared_ptr< FT > GetTFile(const G4String &fileName, G4bool warn=true) const
G4TFileManager()=delete
G4bool DeleteEmptyFiles()
std::shared_ptr< FT > CreateTFile(const G4String &fileName)
G4bool CloseFiles()
virtual G4bool WriteFileImpl(std::shared_ptr< FT > file)=0
G4bool WriteFiles()
G4bool WriteTFile(const G4String &fileName)
G4bool OpenFiles()