Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Hdf5NtupleManager.cc
Go to the documentation of this file.
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// Author: Ivana Hrivnacova, 20/07/2017 ([email protected])
28
30#include "G4Hdf5FileManager.hh"
33#include "G4UnitsTable.hh"
34
35#include "tools/ntuple_booking"
36
37#include <iostream>
38//#include <cstdio>
39
40using namespace G4Analysis;
41
42//_____________________________________________________________________________
44 : G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>(state),
45 fFileManager(nullptr)
46{}
47
48//_____________________________________________________________________________
50{}
51
52//
53// private methods
54//
55//_____________________________________________________________________________
56void G4Hdf5NtupleManager::CreateTNtuple(
57 Hdf5NtupleDescription* ntupleDescription, G4bool warn)
58{
59// Ntuple will be created from ntupleDescription if file is open,
60// return with or without warning otherwise
61
62 // Get ntuple file from ntuple description
63 auto ntupleFile = ntupleDescription->fFile;
64 if (! ntupleFile) {
65 ntupleFile = fFileManager->GetFile();
66 }
67
68 // Check file
69 if ( ! ntupleFile ) {
70 if (warn) {
71 G4String inFunction = "G4Hdf5NtupleManager::::CreateTNtuple";
72 G4ExceptionDescription description;
73 description << " "
74 << "Cannot create ntuple. Ntuple file does not exist." << G4endl;
75 G4Exception(inFunction, "Analysis_W002", JustWarning, description);
76 }
77 return;
78 }
79
80 auto directory = std::get<2>(*ntupleFile);
81 auto basketSize = fFileManager->GetBasketSize();
82 // auto compressionLevel = fState.GetCompressionLevel();
83 auto compressionLevel = 0;
84
85 // create ntuple
86 ntupleDescription->fNtuple
87 = new tools::hdf5::ntuple(
88 G4cout, directory, ntupleDescription->fNtupleBooking,
89 compressionLevel, basketSize);
90
91 fNtupleVector.push_back(ntupleDescription->fNtuple);
92}
93
94//_____________________________________________________________________________
95void G4Hdf5NtupleManager::CreateTNtupleFromBooking(
96 Hdf5NtupleDescription* ntupleDescription)
97{
98 // Create file if file name per object is set
99 if ( ntupleDescription->fFileName.size() ) {
100 fFileManager->CreateNtupleFile(ntupleDescription);
101 }
102
103 // Create ntuple from booking and print a warning if file is not open
104 CreateTNtuple(ntupleDescription, true);
105}
106
107//_____________________________________________________________________________
108void G4Hdf5NtupleManager::FinishTNtuple(
109 Hdf5NtupleDescription* ntupleDescription,
110 G4bool /*fromBooking*/)
111{
112 if ( ! ntupleDescription->fNtuple ) {
113 // Create ntuple from booking if file is open, do nothing otherwise
114 CreateTNtuple(ntupleDescription, false);
115 }
116
117 fFileManager->LockDirectoryNames();
118}
119
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
std::tuple< hid_t, hid_t, hid_t > G4Hdf5File
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4Hdf5NtupleManager(const G4AnalysisManagerState &state)
std::vector< tools::hdf5::ntuple * > fNtupleVector
std::shared_ptr< TF > fFile
tools::ntuple_booking fNtupleBooking