Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RootMainNtupleManager.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, 04/10/2016 ([email protected])
28
30#include "G4RootFileManager.hh"
33
34#include "tools/wroot/file"
35#include "tools/wroot/ntuple"
36
37//_____________________________________________________________________________
39 G4RootNtupleManager* ntupleBuilder,
40 G4NtupleBookingManager* bookingManager,
41 G4bool rowWise,
42 G4int fileNumber,
43 const G4AnalysisManagerState& state)
44 : G4BaseAnalysisManager(state),
45 fNtupleBuilder(ntupleBuilder),
46 fBookingManager(bookingManager),
47 fFileManager(nullptr),
48 fRowWise(rowWise),
49 fFileNumber(fileNumber),
50 fNtupleVector(),
51 fNtupleDescriptionVector()
52{}
53
54//_____________________________________________________________________________
56{
57 // ntuple objects are deleted automatically when closing a file
58}
59
60//
61// protected functions
62//
63
64//_____________________________________________________________________________
66 G4bool warn)
67{
68// Create ntuple from booking if file was open
69
70 // Get/Create main ntuple file
71 auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription, fFileNumber);
72 if ( ! ntupleFile ) {
73 if ( warn ) {
74 G4ExceptionDescription description;
75 description
76 << "Ntuple file must be defined first." << G4endl
77 << "Cannot create main ntuple.";
78 G4Exception("G4RootMainAnalysisManager::CreateNtuple",
79 "Analysis_W002", JustWarning, description);
80 }
81 return;
82 }
83
84 // Get ntuple booking
85 auto ntupleBooking = ntupleDescription->fNtupleBooking;
86
87#ifdef G4VERBOSE
88 if ( fState.GetVerboseL4() )
90 ->Message("create", "main ntuple", ntupleBooking.name());
91#endif
92
93 // Create ntuple
94 auto ntuple = new tools::wroot::ntuple(*std::get<2>(*ntupleFile), ntupleBooking, fRowWise);
95 // ntuple object is deleted automatically when closing a file
96 auto basketSize = fNtupleBuilder->GetBasketSize();
97 ntuple->set_basket_size(basketSize);
98
99 fNtupleVector.push_back(ntuple);
100 fNtupleDescriptionVector.push_back(ntupleDescription);
101
102#ifdef G4VERBOSE
103 if ( fState.GetVerboseL3() )
105 ->Message("create", "main ntuple", ntupleBooking.name());
106#endif
107}
108
109//_____________________________________________________________________________
111{
112 std::size_t counter = 0;
113
114 for ( auto ntuple : fNtupleVector ) {
115 ntuple->merge_number_of_entries();
116
117 // Notify ntuple description that file is not empty
118 if ( ntuple->entries() ) {
119 auto ntupleDescription = fNtupleDescriptionVector.at(counter);
120 ntupleDescription->fHasFill = true;
121 }
122 ++counter;
123 }
124
125 return true;
126}
127
128//_____________________________________________________________________________
130{
131 for ( auto ntuple : fNtupleVector ) {
132 if ( deleteNtuple ) {
133 delete ntuple;
134 }
135 }
136
137 fNtupleVector.clear();
138 fNtupleDescriptionVector.clear();
139
140 return true;
141}
142
143//_____________________________________________________________________________
144std::shared_ptr<G4RootFile>
146{
147 auto perThread = false;
148 return fFileManager->GetNtupleFile(ntupleDescription, perThread, fFileNumber);
149}
@ 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
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
const G4AnalysisVerbose * GetVerboseL3() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
G4bool Reset(G4bool deleteNtuple)
G4RootMainNtupleManager(G4RootNtupleManager *ntupleBuilder, G4NtupleBookingManager *bookingManager, G4bool rowWise, G4int fileNumber, const G4AnalysisManagerState &state)
std::shared_ptr< G4RootFile > GetNtupleFile(RootNtupleDescription *ntupleDescription) const
void CreateNtuple(RootNtupleDescription *ntupleDescription, G4bool warn=true)
tools::ntuple_booking fNtupleBooking