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