Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 // Author: Ivana Hrivnacova, 15/09/2020 (ivan 27 // Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4Hdf5NtupleFileManager.hh" 29 #include "G4Hdf5NtupleFileManager.hh" 30 #include "G4Hdf5NtupleManager.hh" 30 #include "G4Hdf5NtupleManager.hh" 31 #include "G4Hdf5FileManager.hh" 31 #include "G4Hdf5FileManager.hh" 32 #include "G4AnalysisManagerState.hh" 32 #include "G4AnalysisManagerState.hh" 33 #include "G4AnalysisUtilities.hh" 33 #include "G4AnalysisUtilities.hh" 34 34 >> 35 #include "G4Threading.hh" >> 36 >> 37 #include <iostream> >> 38 35 using namespace G4Analysis; 39 using namespace G4Analysis; 36 40 37 // << 41 // 38 // utility methods 42 // utility methods 39 // 43 // 40 44 41 //____________________________________________ 45 //_____________________________________________________________________________ 42 G4Hdf5NtupleFileManager::G4Hdf5NtupleFileManag 46 G4Hdf5NtupleFileManager::G4Hdf5NtupleFileManager(const G4AnalysisManagerState& state) 43 : G4VNtupleFileManager(state, "hdf5") << 47 : G4VNtupleFileManager(state, "hdf5"), >> 48 fFileManager(nullptr), >> 49 fNtupleManager(nullptr) 44 {} 50 {} 45 51 >> 52 //_____________________________________________________________________________ >> 53 G4Hdf5NtupleFileManager::~G4Hdf5NtupleFileManager() >> 54 {} >> 55 >> 56 // >> 57 // private methods >> 58 // >> 59 >> 60 //_____________________________________________________________________________ >> 61 G4bool G4Hdf5NtupleFileManager::CloseNtupleFiles() >> 62 { >> 63 // Close ntuple files >> 64 >> 65 auto finalResult = true; >> 66 auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector(); >> 67 for ( auto ntupleDescription : ntupleVector) { >> 68 auto result = fFileManager->CloseNtupleFile(ntupleDescription); >> 69 finalResult = finalResult && result; >> 70 } >> 71 >> 72 return finalResult; >> 73 } >> 74 46 // 75 // 47 // public methods 76 // public methods 48 // 77 // 49 78 50 //____________________________________________ 79 //_____________________________________________________________________________ 51 std::shared_ptr<G4VNtupleManager> G4Hdf5Ntuple 80 std::shared_ptr<G4VNtupleManager> G4Hdf5NtupleFileManager::CreateNtupleManager() 52 { 81 { 53 82 54 // The managers will be deleted by the base 83 // The managers will be deleted by the base class 55 fNtupleManager = std::make_shared<G4Hdf5Ntup 84 fNtupleManager = std::make_shared<G4Hdf5NtupleManager>(fState); 56 fNtupleManager->SetFileManager(fFileManager) 85 fNtupleManager->SetFileManager(fFileManager); 57 86 58 return fNtupleManager; 87 return fNtupleManager; 59 } 88 } 60 89 61 //____________________________________________ 90 //_____________________________________________________________________________ 62 G4bool G4Hdf5NtupleFileManager::ActionAtOpenFi 91 G4bool G4Hdf5NtupleFileManager::ActionAtOpenFile(const G4String& /*fileName*/) 63 { 92 { 64 // Create ntuples if they are booked << 93 // Create ntuples if they are booked 65 // (The files will be created with creating 94 // (The files will be created with creating ntuples) 66 fNtupleManager->CreateNtuplesFromBooking( 95 fNtupleManager->CreateNtuplesFromBooking( 67 fBookingManager->GetNtupleBookingVector()) 96 fBookingManager->GetNtupleBookingVector()); 68 97 69 return true; 98 return true; 70 } 99 } 71 100 72 //____________________________________________ 101 //_____________________________________________________________________________ 73 G4bool G4Hdf5NtupleFileManager::ActionAtWrite( 102 G4bool G4Hdf5NtupleFileManager::ActionAtWrite() 74 { 103 { 75 // Nothing to be done << 104 // notify that ntuple file is not empty 76 return true; << 105 >> 106 auto finalResult = true; >> 107 >> 108 // Notify that ntuple files are not empty >> 109 auto ntupleVector >> 110 = fNtupleManager->GetNtupleDescriptionVector(); >> 111 >> 112 for ( auto ntupleDescription : ntupleVector) { >> 113 if (ntupleDescription->fFile) { >> 114 auto result = fFileManager->SetIsEmpty(ntupleDescription->fFileName, false); >> 115 finalResult = finalResult && result; >> 116 } >> 117 } >> 118 >> 119 return finalResult; 77 } 120 } 78 121 79 //____________________________________________ 122 //_____________________________________________________________________________ 80 G4bool G4Hdf5NtupleFileManager::ActionAtCloseF << 123 G4bool G4Hdf5NtupleFileManager::ActionAtCloseFile(G4bool reset) 81 { 124 { 82 auto result = true; << 125 auto finalResult = true; 83 126 84 // Close ntuple files 127 // Close ntuple files 85 auto ntupleVector = fNtupleManager->GetNtupl << 128 auto result = CloseNtupleFiles(); 86 for ( auto ntupleDescription : ntupleVector) << 129 finalResult = finalResult && result; 87 result &= fFileManager->CloseNtupleFile(nt << 130 >> 131 if ( ! reset ) { >> 132 // The ntuples must be always reset when closing file) >> 133 result = Reset(); >> 134 if ( ! result ) { >> 135 G4ExceptionDescription description; >> 136 description << " " << "Resetting data failed"; >> 137 G4Exception("G4Hdf5NtupleFileManager::CloseFile()", >> 138 "Analysis_W021", JustWarning, description); >> 139 } >> 140 finalResult = finalResult && result; 88 } 141 } 89 142 90 return result; << 143 return finalResult; 91 } 144 } 92 145 93 //____________________________________________ 146 //_____________________________________________________________________________ 94 G4bool G4Hdf5NtupleFileManager::Reset() 147 G4bool G4Hdf5NtupleFileManager::Reset() 95 { 148 { 96 return fNtupleManager->Reset(); << 149 return fNtupleManager->Reset(true); 97 } 150 } 98 151