Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:27

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // The common implementaion of G4VFileManager functions via G4TFileManager.
0028 
0029 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4VTFileManager_h
0032 #define G4VTFileManager_h 1
0033 
0034 #include "G4VFileManager.hh"
0035 #include "G4TNtupleDescription.hh"
0036 #include "G4TFileManager.hh"
0037 #include "globals.hh"
0038 
0039 #include "tools/wcsv_ntuple"
0040 
0041 template <typename FT>
0042 class G4VTFileManager : public G4VFileManager,
0043                         public G4TFileManager<FT>
0044 {
0045   public:
0046     explicit G4VTFileManager(const G4AnalysisManagerState& state)
0047       : G4VFileManager(state), G4TFileManager<FT>(state) {}
0048     ~G4VTFileManager() override = default;
0049 
0050     using G4VFileManager::WriteFile;
0051     using G4VFileManager::CloseFile;
0052 
0053     // Methods applied to file per name
0054     G4bool CreateFile(const G4String& fileName) final;
0055     G4bool WriteFile(const G4String& fileName) final;
0056     G4bool CloseFile(const G4String& fileName) final;
0057     G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) final;
0058 
0059     // Methods applied to all registered files
0060     G4bool OpenFiles() final;
0061     G4bool WriteFiles() final;
0062     G4bool CloseFiles() final;
0063     G4bool DeleteEmptyFiles() final;
0064 
0065     // Clear all data
0066     void Clear() final;
0067 
0068     // Get method
0069     std::shared_ptr<FT> GetFile() const;
0070 
0071   protected:
0072     // Data members
0073     // Default file - created at OpenFile call
0074     std::shared_ptr<FT> fFile { nullptr };
0075 };
0076 
0077 //_____________________________________________________________________________
0078 template <typename FT>
0079 inline
0080 G4bool G4VTFileManager<FT>::CreateFile(const G4String& fileName)
0081 {
0082   return (G4TFileManager<FT>::CreateTFile(fileName) != nullptr);
0083 }
0084 
0085 //_____________________________________________________________________________
0086 template <typename FT>
0087 inline
0088 G4bool G4VTFileManager<FT>::WriteFile(const G4String& fileName)
0089 {
0090   return G4TFileManager<FT>::WriteTFile(fileName);
0091 }
0092 
0093 //_____________________________________________________________________________
0094 template <typename FT>
0095 inline
0096 G4bool G4VTFileManager<FT>::CloseFile(const G4String& fileName)
0097 {
0098   return G4TFileManager<FT>::CloseTFile(fileName);
0099 }
0100 
0101 //_____________________________________________________________________________
0102 template <typename FT>
0103 inline
0104 G4bool G4VTFileManager<FT>::SetIsEmpty(const G4String& fileName, G4bool isEmpty)
0105 {
0106   return G4TFileManager<FT>::SetIsEmpty(fileName, isEmpty);
0107 }
0108 
0109 //_____________________________________________________________________________
0110 template <typename FT>
0111 inline
0112 G4bool G4VTFileManager<FT>::OpenFiles()
0113 {
0114   return G4TFileManager<FT>::OpenFiles();
0115 }
0116 
0117 //_____________________________________________________________________________
0118 template <typename FT>
0119 inline
0120 G4bool G4VTFileManager<FT>::WriteFiles()
0121 {
0122   return G4TFileManager<FT>::WriteFiles();
0123 }
0124 
0125 //_____________________________________________________________________________
0126 template <typename FT>
0127 inline
0128 G4bool G4VTFileManager<FT>::CloseFiles()
0129 {
0130   auto result = G4TFileManager<FT>::CloseFiles();
0131 
0132   fIsOpenFile = false;
0133   fFile.reset();
0134 
0135   return result;
0136 }
0137 
0138 //_____________________________________________________________________________
0139 template <typename FT>
0140 inline
0141 G4bool G4VTFileManager<FT>::DeleteEmptyFiles()
0142 {
0143   auto result = G4TFileManager<FT>::DeleteEmptyFiles();
0144 
0145   // clean-up also all stored information about file names
0146   Clear();
0147 
0148   return result;
0149 }
0150 
0151 //_____________________________________________________________________________
0152 template <typename FT>
0153 inline
0154 void G4VTFileManager<FT>::Clear()
0155 {
0156   G4TFileManager<FT>::ClearData();
0157   G4BaseFileManager::ClearData();
0158   UnlockDirectoryNames();
0159 }
0160 
0161 //_____________________________________________________________________________
0162 template <typename FT>
0163 inline std::shared_ptr<FT> G4VTFileManager<FT>::GetFile() const
0164 {
0165   return fFile;
0166 }
0167 
0168 #endif