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, 20/07/2017 (ivana 27 // Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4Hdf5NtupleManager.hh" 29 #include "G4Hdf5NtupleManager.hh" 30 #include "G4Hdf5FileManager.hh" 30 #include "G4Hdf5FileManager.hh" 31 #include "G4AnalysisManagerState.hh" 31 #include "G4AnalysisManagerState.hh" 32 #include "G4AnalysisUtilities.hh" 32 #include "G4AnalysisUtilities.hh" 33 #include "G4UnitsTable.hh" 33 #include "G4UnitsTable.hh" 34 34 35 #include "tools/ntuple_booking" 35 #include "tools/ntuple_booking" 36 36 >> 37 #include <iostream> >> 38 //#include <cstdio> >> 39 37 using namespace G4Analysis; 40 using namespace G4Analysis; 38 41 39 //____________________________________________ 42 //_____________________________________________________________________________ 40 G4Hdf5NtupleManager::G4Hdf5NtupleManager(const 43 G4Hdf5NtupleManager::G4Hdf5NtupleManager(const G4AnalysisManagerState& state) 41 : G4TNtupleManager<toolx::hdf5::ntuple, G4Hdf << 44 : G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>(state), >> 45 fFileManager(nullptr) 42 {} 46 {} 43 47 44 // << 48 //_____________________________________________________________________________ >> 49 G4Hdf5NtupleManager::~G4Hdf5NtupleManager() >> 50 {} >> 51 >> 52 // 45 // private methods 53 // private methods 46 // 54 // 47 //____________________________________________ 55 //_____________________________________________________________________________ 48 void G4Hdf5NtupleManager::CreateTNtuple( 56 void G4Hdf5NtupleManager::CreateTNtuple( 49 Hdf5NtupleDescription* ntupleDescription, G4 57 Hdf5NtupleDescription* ntupleDescription, G4bool warn) 50 { 58 { 51 // Ntuple will be created from ntupleDescripti 59 // Ntuple will be created from ntupleDescription if file is open, 52 // return with or without warning otherwise 60 // return with or without warning otherwise 53 61 54 // Get ntuple file from ntuple description 62 // Get ntuple file from ntuple description 55 auto ntupleFile = ntupleDescription->GetFile << 63 auto ntupleFile = ntupleDescription->fFile; 56 if (! ntupleFile) { 64 if (! ntupleFile) { 57 ntupleFile = fFileManager->GetFile(); 65 ntupleFile = fFileManager->GetFile(); 58 } 66 } 59 67 60 // Check file 68 // Check file 61 if ( ! ntupleFile ) { 69 if ( ! ntupleFile ) { 62 if (warn) { 70 if (warn) { 63 Warn( "Cannot create ntuple. Ntuple file << 71 G4String inFunction = "G4Hdf5NtupleManager::::CreateTNtuple"; 64 fkClass, "CreateTNtuple"); << 72 G4ExceptionDescription description; >> 73 description << " " >> 74 << "Cannot create ntuple. Ntuple file does not exist." << G4endl; >> 75 G4Exception(inFunction, "Analysis_W002", JustWarning, description); 65 } 76 } 66 return; 77 return; 67 } 78 } 68 79 69 auto directory = std::get<2>(*ntupleFile); 80 auto directory = std::get<2>(*ntupleFile); 70 auto basketSize = fFileManager->GetBasketSiz 81 auto basketSize = fFileManager->GetBasketSize(); 71 auto compressionLevel = fFileManager->GetCom << 82 // auto compressionLevel = fState.GetCompressionLevel(); 72 << 83 auto compressionLevel = 0; 73 // Update ntuple name if cycle >0 << 74 auto ntupleBooking = ntupleDescription->GetN << 75 if (GetCycle() > 0) { << 76 auto newNtupleName = ntupleDescription->Ge << 77 newNtupleName.append("_v"); << 78 newNtupleName.append(std::to_string(GetCyc << 79 ntupleBooking.set_name(newNtupleName); << 80 } << 81 84 82 // create ntuple 85 // create ntuple 83 ntupleDescription->SetNtuple( << 86 ntupleDescription->fNtuple 84 new toolx::hdf5::ntuple( << 87 = new tools::hdf5::ntuple( 85 G4cout, directory, ntupleBooking, co << 88 G4cout, directory, ntupleDescription->fNtupleBooking, >> 89 compressionLevel, basketSize); >> 90 >> 91 fNtupleVector.push_back(ntupleDescription->fNtuple); 86 } 92 } 87 93 88 //____________________________________________ 94 //_____________________________________________________________________________ 89 void G4Hdf5NtupleManager::CreateTNtupleFromBoo 95 void G4Hdf5NtupleManager::CreateTNtupleFromBooking( 90 Hdf5NtupleDescription* ntupleDescription) 96 Hdf5NtupleDescription* ntupleDescription) 91 { 97 { 92 // Create file if file name per object is se 98 // Create file if file name per object is set 93 if (ntupleDescription->GetFileName().size() << 99 if ( ntupleDescription->fFileName.size() ) { 94 fFileManager->CreateNtupleFile(ntupleDescr 100 fFileManager->CreateNtupleFile(ntupleDescription); 95 } 101 } 96 102 97 // Create ntuple from booking and print a wa 103 // Create ntuple from booking and print a warning if file is not open 98 CreateTNtuple(ntupleDescription, true); 104 CreateTNtuple(ntupleDescription, true); 99 } 105 } 100 106 101 //____________________________________________ 107 //_____________________________________________________________________________ 102 void G4Hdf5NtupleManager::FinishTNtuple( 108 void G4Hdf5NtupleManager::FinishTNtuple( 103 Hdf5NtupleDescription* ntupleDescription, 109 Hdf5NtupleDescription* ntupleDescription, 104 G4bool /*fromBooking*/) 110 G4bool /*fromBooking*/) 105 { 111 { 106 if (ntupleDescription->GetNtuple() == nullpt << 112 if ( ! ntupleDescription->fNtuple ) { 107 // Create ntuple from booking if file is o << 113 // Create ntuple from booking if file is open, do nothing otherwise 108 CreateTNtuple(ntupleDescription, false); 114 CreateTNtuple(ntupleDescription, false); 109 } 115 } 110 116 111 fFileManager->LockDirectoryNames(); 117 fFileManager->LockDirectoryNames(); 112 } 118 } 113 119 114 120