Geant4-11
G4VTFileManager.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 common implementaion of G4VFileManager functions via G4TFileManager.
28
29// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
30
31#ifndef G4VTFileManager_h
32#define G4VTFileManager_h 1
33
34#include "G4VFileManager.hh"
36#include "G4TFileManager.hh"
37#include "globals.hh"
38
39#include "tools/wcsv_ntuple"
40
41template <typename FT>
43 public G4TFileManager<FT>
44{
45 public:
47 : G4VFileManager(state), G4TFileManager<FT>(state) {}
48 virtual ~G4VTFileManager() = default;
49
52
53 // Methods applied to file per name
54 virtual G4bool CreateFile(const G4String& fileName) final;
55 virtual G4bool WriteFile(const G4String& fileName) final;
56 virtual G4bool CloseFile(const G4String& fileName) final;
57 virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) final;
58
59 // Methods applied to all registered files
60 virtual G4bool WriteFiles() final;
61 virtual G4bool CloseFiles() final;
62 virtual G4bool DeleteEmptyFiles() final;
63
64 // Clear all data
65 virtual void Clear() final;
66
67 // Get method
68 std::shared_ptr<FT> GetFile() const;
69
70 protected:
71 // Data members
72 // Default file - created at OpenFile call
73 std::shared_ptr<FT> fFile { nullptr };
74};
75
76//_____________________________________________________________________________
77template <typename FT>
78inline
80{
81 return (G4TFileManager<FT>::CreateTFile(fileName) != nullptr);
82}
83
84//_____________________________________________________________________________
85template <typename FT>
86inline
88{
89 return G4TFileManager<FT>::WriteTFile(fileName);
90}
91
92//_____________________________________________________________________________
93template <typename FT>
94inline
96{
97 return G4TFileManager<FT>::CloseTFile(fileName);
98}
99
100//_____________________________________________________________________________
101template <typename FT>
102inline
104{
105 return G4TFileManager<FT>::SetIsEmpty(fileName, isEmpty);
106}
107
108//_____________________________________________________________________________
109template <typename FT>
110inline
112{
114}
115
116//_____________________________________________________________________________
117template <typename FT>
118inline
120{
121 auto result = G4TFileManager<FT>::CloseFiles();
122
123 fIsOpenFile = false;
124 fFile.reset();
125
126 return result;
127}
128
129//_____________________________________________________________________________
130template <typename FT>
131inline
133{
135}
136
137//_____________________________________________________________________________
138template <typename FT>
139inline
141{
143 UnlockDirectoryNames();
144}
145
146//_____________________________________________________________________________
147template <typename FT>
148inline std::shared_ptr<FT> G4VTFileManager<FT>::GetFile() const
149{
150 return fFile;
151}
152
153#endif
bool G4bool
Definition: G4Types.hh:86
G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty)
G4bool CloseTFile(const G4String &fileName)
G4bool DeleteEmptyFiles()
G4bool CloseFiles()
G4bool WriteFiles()
G4bool WriteTFile(const G4String &fileName)
virtual G4bool CloseFile(const G4String &fileName)=0
virtual G4bool WriteFile(const G4String &fileName)=0
virtual G4bool SetIsEmpty(const G4String &fileName, G4bool isEmpty) final
G4VTFileManager(const G4AnalysisManagerState &state)
std::shared_ptr< FT > GetFile() const
virtual G4bool WriteFiles() final
virtual G4bool WriteFile(const G4String &fileName) final
virtual G4bool CreateFile(const G4String &fileName) final
virtual void Clear() final
virtual G4bool CloseFile(const G4String &fileName) final
virtual G4bool CloseFiles() final
std::shared_ptr< FT > fFile
virtual ~G4VTFileManager()=default
virtual G4bool DeleteEmptyFiles() final
std::shared_ptr< T > shared_ptr
Definition: memory.h:15