Back to home page

EIC code displayed by LXR

 
 

    


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

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 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
0028 
0029 #ifndef G4TFileManager_h
0030 #define G4TFileManager_h 1
0031 
0032 #include "G4TFileInformation.hh"
0033 
0034 #include <vector>
0035 #include <memory>
0036 #include <string_view>
0037 
0038 template <typename FT>
0039 class G4TFileManager
0040 {
0041   public:
0042     explicit G4TFileManager(const G4AnalysisManagerState& state);
0043     G4TFileManager() = delete;
0044     virtual ~G4TFileManager();
0045 
0046     // Per file methods
0047     // (implements all tests and warnings, fills the map)
0048     std::shared_ptr<FT> CreateTFile(const G4String& fileName);
0049     G4bool WriteTFile(const G4String& fileName);
0050     G4bool CloseTFile(const G4String& fileName);
0051     G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty);
0052     //
0053     std::shared_ptr<FT> GetTFile(const G4String& fileName, G4bool warn = true) const;
0054 
0055     // Methods applied to all registered files
0056     G4bool OpenFiles();
0057     G4bool WriteFiles();
0058     G4bool CloseFiles();
0059     G4bool DeleteEmptyFiles();
0060 
0061     // Clear all data
0062     void ClearData();
0063 
0064   protected:
0065     // Methods to be implemented per file type manipulate file
0066     virtual std::shared_ptr<FT> CreateFileImpl(const G4String& fileName) = 0;
0067     virtual G4bool WriteFileImpl(std::shared_ptr<FT> file) = 0;
0068     virtual G4bool CloseFileImpl(std::shared_ptr<FT> file) = 0;
0069 
0070   private:
0071     // Methods
0072     void FileNotFoundWarning(const G4String& fileName,
0073           std::string_view functionName) const;
0074     G4TFileInformation<FT>* GetFileInfoInFunction(const G4String& fileName,
0075       std::string_view functionName, G4bool warn = true) const;
0076     std::shared_ptr<FT> GetFileInFunction(const G4String& fileName,
0077       std::string_view functionName, G4bool warn = true) const;
0078 
0079     G4bool WriteTFile(std::shared_ptr<FT> file, const G4String& fileName);
0080     G4bool CloseTFile(std::shared_ptr<FT> file, const G4String& fileName);
0081     G4bool DeleteEmptyFile(const G4String& fileName);
0082 
0083     // Static data members
0084     static constexpr std::string_view fkClass { "G4TFileManager<FT>" };
0085 
0086     // Data members
0087     const G4AnalysisManagerState& fAMState;
0088     std::map<G4String, G4TFileInformation<FT>*> fFileMap;
0089  };
0090 
0091 #include "G4TFileManager.icc"
0092 
0093 #endif