Geant4-11
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 (ivana@ipno.in2p3.fr)
28
30#include "G4RootFileManager.hh"
33
34#include "tools/wroot/file"
35#include "tools/wroot/ntuple"
36
37using namespace G4Analysis;
38
39//_____________________________________________________________________________
41 G4RootNtupleManager* ntupleBuilder,
42 std::shared_ptr<G4NtupleBookingManager> bookingManager,
43 G4bool rowWise,
44 G4int fileNumber,
45 const G4AnalysisManagerState& state)
46 : G4BaseAnalysisManager(state),
47 fNtupleBuilder(ntupleBuilder),
48 fBookingManager(std::move(bookingManager)),
49 fRowWise(rowWise),
50 fFileNumber(fileNumber)
51{}
52
53//
54// protected functions
55//
56
57//_____________________________________________________________________________
59 G4bool warn)
60{
61// Create ntuple from booking if file was open
62
63 // Get/Create main ntuple file
64 auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription, fFileNumber);
65 if ( ! ntupleFile ) {
66 if ( warn ) {
67 Warn("Ntuple file must be defined first.\n"
68 "Cannot create main ntuple.",
69 fkClass, "CreateNtuple");
70 }
71 return;
72 }
73
74 // Get ntuple booking
75 auto ntupleBooking = ntupleDescription->fNtupleBooking;
76
77 Message(kVL4, "create", "main ntuple", ntupleBooking.name());
78
79 // Create ntuple
80 auto ntuple = new tools::wroot::ntuple(*std::get<2>(*ntupleFile), ntupleBooking, fRowWise);
81 // ntuple object is deleted automatically when closing a file
82 auto basketSize = fNtupleBuilder->GetBasketSize();
83 ntuple->set_basket_size(basketSize);
84
85 fNtupleVector.push_back(ntuple);
86 fNtupleDescriptionVector.push_back(ntupleDescription);
87
88 Message(kVL3, "create", "main ntuple", ntupleBooking.name());
89}
90
91//_____________________________________________________________________________
93{
94 std::size_t counter = 0;
95
96 for ( auto ntuple : fNtupleVector ) {
97 ntuple->merge_number_of_entries();
98
99 // Notify ntuple description that file is not empty
100 if ( ntuple->entries() ) {
101 auto ntupleDescription = fNtupleDescriptionVector.at(counter);
102 ntupleDescription->fHasFill = true;
103 }
104 ++counter;
105 }
106
107 return true;
108}
109
110//_____________________________________________________________________________
112{
113 // ntuple object is deleted automatically when closing a file
114
115 fNtupleVector.clear();
117
118 return true;
119}
120
121//_____________________________________________________________________________
123{
124 // Reset function clears all data
125 Reset();
126
127 Message(G4Analysis::kVL2, "clear", "main ntuples");
128}
129
130//_____________________________________________________________________________
131std::shared_ptr<G4RootFile>
133{
134 auto perThread = false;
135 return fFileManager->GetNtupleFile(ntupleDescription, perThread, fFileNumber);
136}
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
std::vector< tools::wroot::ntuple * > fNtupleVector
std::shared_ptr< G4RootFile > GetNtupleFile(RootNtupleDescription *ntupleDescription) const
static constexpr std::string_view fkClass
G4RootMainNtupleManager()=delete
G4RootNtupleManager * fNtupleBuilder
std::shared_ptr< G4RootFileManager > fFileManager
std::vector< RootNtupleDescription * > fNtupleDescriptionVector
void CreateNtuple(RootNtupleDescription *ntupleDescription, G4bool warn=true)
unsigned int GetBasketSize() const
constexpr G4int kVL2
constexpr G4int kVL3
constexpr G4int kVL4
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
tools::ntuple_booking fNtupleBooking