Geant4 Cross Reference |
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 manager for Root output file operations. 28 29 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr) 30 31 #ifndef G4RootFileManager_h 32 #define G4RootFileManager_h 1 33 34 #include "G4VTFileManager.hh" 35 #include "G4RootFileDef.hh" 36 #include "G4AnalysisUtilities.hh" 37 #include "globals.hh" 38 39 #include <vector> 40 #include <memory> 41 #include <tuple> 42 #include <string_view> 43 44 namespace tools { 45 namespace wroot{ 46 class ntuple; 47 } 48 } 49 50 // Types alias 51 using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>; 52 53 class G4RootFileManager : public G4VTFileManager<G4RootFile> 54 { 55 public: 56 explicit G4RootFileManager(const G4AnalysisManagerState& state); 57 G4RootFileManager() = delete; 58 ~G4RootFileManager() override = default; 59 60 using G4BaseFileManager::GetNtupleFileName; 61 using G4VTFileManager<G4RootFile>::WriteFile; 62 using G4VTFileManager<G4RootFile>::CloseFile; 63 64 // Methods to manipulate file from base classes 65 G4bool OpenFile(const G4String& fileName) final; 66 67 G4String GetFileType() const final { return "root"; } 68 G4bool HasCycles() const final { return true; } 69 70 // Specific methods for files per objects 71 std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription, 72 G4int mainNumber = -1); 73 std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription, 74 G4bool perThread = true, 75 G4int mainNumber = -1) const; 76 G4bool CloseNtupleFile(RootNtupleDescription* ntupleDescription, 77 G4int mainNumber = -1); 78 79 // Set methods 80 void SetBasketSize(unsigned int basketSize); 81 void SetBasketEntries(unsigned int basketEntries); 82 83 // Get methods 84 unsigned int GetBasketSize() const; 85 unsigned int GetBasketEntries() const; 86 87 protected: 88 // Methods derived from templated base class 89 std::shared_ptr<G4RootFile> CreateFileImpl(const G4String& fileName) final; 90 G4bool WriteFileImpl(std::shared_ptr<G4RootFile> file) final; 91 G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final; 92 93 private: 94 // Methods 95 tools::wroot::directory* CreateDirectory( 96 tools::wroot::file* rfile, 97 const G4String& directoryName, 98 const G4String& objectType) const; 99 G4String GetNtupleFileName( 100 RootNtupleDescription* ntupleDescription, 101 G4bool perThread = true, 102 G4int mainNumber = -1) const; 103 104 // Static data members 105 static constexpr std::string_view fkClass { "G4RootFileManager" }; 106 107 // Data members 108 unsigned int fBasketSize { G4Analysis::kDefaultBasketSize }; 109 unsigned int fBasketEntries { G4Analysis::kDefaultBasketEntries }; 110 }; 111 112 // inline functions 113 114 //_____________________________________________________________________________ 115 inline void G4RootFileManager::SetBasketSize(unsigned int basketSize) 116 { fBasketSize = basketSize; } 117 118 //_____________________________________________________________________________ 119 inline void G4RootFileManager::SetBasketEntries(unsigned int basketEntries) 120 { fBasketEntries = basketEntries; } 121 122 //_____________________________________________________________________________ 123 inline unsigned int G4RootFileManager::GetBasketSize() const 124 { return fBasketSize; } 125 126 //_____________________________________________________________________________ 127 inline unsigned int G4RootFileManager::GetBasketEntries() const 128 { return fBasketEntries; } 129 130 #endif 131 132