Back to home page

EIC code displayed by LXR

 
 

    


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

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 // Base class for File manager.
0028 //
0029 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4VFileManager_h
0032 #define G4VFileManager_h 1
0033 
0034 #include "G4BaseFileManager.hh"
0035 #include "G4VTHnFileManager.hh"
0036 #include "globals.hh"
0037 
0038 #include <memory>
0039 #include <string_view>
0040 
0041 namespace tools {
0042 namespace histo {
0043 class h1d;
0044 class h2d;
0045 class h3d;
0046 class p1d;
0047 class p2d;
0048 }
0049 }
0050 
0051 class G4VFileManager : public G4BaseFileManager
0052 {
0053   public:
0054     explicit G4VFileManager(const G4AnalysisManagerState& state);
0055     G4VFileManager() = delete;
0056     ~G4VFileManager() override = default;
0057 
0058     // Method to open default file
0059     virtual G4bool OpenFile(const G4String& fileName) = 0;
0060 
0061     // Methods applied to file per name
0062     virtual G4bool CreateFile(const G4String& fileName) = 0;
0063     virtual G4bool WriteFile(const G4String& fileName) = 0;
0064     virtual G4bool CloseFile(const G4String& fileName) = 0;
0065     virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) = 0;
0066 
0067     // Methods applied to all registered files
0068     virtual G4bool OpenFiles() = 0;
0069     virtual G4bool WriteFiles() = 0;
0070     virtual G4bool CloseFiles() = 0;
0071     virtual G4bool DeleteEmptyFiles() = 0;
0072 
0073     // Clear all data
0074     virtual void Clear() = 0;
0075 
0076     // Methods for handling files and directories names
0077     G4bool SetFileName(const G4String& fileName) final;
0078     virtual G4bool SetHistoDirectoryName(const G4String& dirName);
0079     virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
0080 
0081     void LockDirectoryNames();
0082     void UnlockDirectoryNames();
0083 
0084     G4bool IsOpenFile() const;
0085     G4String GetHistoDirectoryName() const;
0086     G4String GetNtupleDirectoryName() const;
0087     G4int GetCycle() const;
0088 
0089     // Access to helpers
0090     template <typename HT>
0091     std::shared_ptr<G4VTHnFileManager<HT>> GetHnFileManager() const;
0092 
0093   protected:
0094     // Static data members
0095     static constexpr std::string_view fkClass { "G4VFileManager" };
0096 
0097     // Data members
0098     G4String fHistoDirectoryName;
0099     G4String fNtupleDirectoryName;
0100     G4bool   fIsOpenFile { false };
0101     G4bool   fLockDirectoryNames { false };
0102 
0103     // FileManagers per object type
0104     std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>> fH1FileManager { nullptr };
0105     std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>> fH2FileManager { nullptr };
0106     std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>> fH3FileManager { nullptr };
0107     std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>> fP1FileManager { nullptr };
0108     std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>> fP2FileManager { nullptr };
0109 };
0110 
0111 // inline functions
0112 
0113 inline void G4VFileManager::LockDirectoryNames()
0114 { fLockDirectoryNames = true; }
0115 
0116 inline void G4VFileManager::UnlockDirectoryNames()
0117 { fLockDirectoryNames = false; }
0118 
0119 inline G4bool G4VFileManager::IsOpenFile() const
0120 { return fIsOpenFile; }
0121 
0122 inline G4String G4VFileManager::GetHistoDirectoryName() const
0123 { return fHistoDirectoryName; }
0124 
0125 inline G4String G4VFileManager::GetNtupleDirectoryName() const
0126 { return fNtupleDirectoryName; }
0127 
0128 inline G4int G4VFileManager::GetCycle() const
0129 { return fState.GetCycle(); }
0130 
0131 template <>
0132 inline
0133 std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>>
0134 G4VFileManager::GetHnFileManager<tools::histo::h1d>() const
0135 {   return fH1FileManager; }
0136 
0137 template <>
0138 inline
0139 std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>>
0140 G4VFileManager::GetHnFileManager<tools::histo::h2d>() const
0141 { return fH2FileManager; }
0142 
0143 template <>
0144 inline
0145 std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>>
0146 G4VFileManager::GetHnFileManager<tools::histo::h3d>() const
0147 { return fH3FileManager; }
0148 
0149 template <>
0150 inline
0151 std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>>
0152 G4VFileManager::GetHnFileManager<tools::histo::p1d>() const
0153 { return fP1FileManager; }
0154 
0155 template <>
0156 inline
0157 std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>>
0158 G4VFileManager::GetHnFileManager<tools::histo::p2d>() const
0159 { return fP2FileManager; }
0160 
0161 #endif