Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // $Id$
27 //
28 // Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
29 
31 #include "G4RootNtupleManager.hh"
32 #include "G4AnalysisUtilities.hh"
33 
34 #include "tools/wroot/file"
35 #include "tools/wroot/ntuple"
36 
37 //_____________________________________________________________________________
39  const G4AnalysisManagerState& state)
40  : G4BaseAnalysisManager(state),
41  fNtupleBuilder(ntupleBuilder),
42  fNtupleDirectory(nullptr),
43  fNtupleVector()
44 {}
45 
46 //_____________________________________________________________________________
48 {
49  // ntuple objects are deleted automatically when closing a file
50 }
51 
52 //
53 // private functions
54 //
55 
56 //
57 // protected functions
58 //
59 
60 //_____________________________________________________________________________
61 void G4RootMainNtupleManager::CreateNtuple(const tools::ntuple_booking& ntupleBooking,
62  G4bool warn)
63 {
64 // Create ntuple from booking if file was open
65 
66  // Check that file is set
67  if ( ! fNtupleDirectory ) {
68  if ( warn ) {
69  G4ExceptionDescription description;
70  description
71  << " " << "Ntuple file must be defined first."
72  << G4endl
73  << " " << "Cannot create main ntuples from builder.";
74  G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
75  "Analysis_W002", JustWarning, description);
76  }
77  return;
78  }
79 
80 #ifdef G4VERBOSE
81  if ( fState.GetVerboseL4() )
83  ->Message("create", "main ntuple", ntupleBooking.name());
84 #endif
85 
86  // Create ntuple
87  auto ntuple = new tools::wroot::ntuple(*fNtupleDirectory, ntupleBooking);
88  // ntuple object is deleted automatically when closing a file
89  auto basketSize = fNtupleBuilder->GetBasketSize();
90  ntuple->set_basket_size(basketSize);
91 
92  fNtupleVector.push_back(ntuple);
93 
94 #ifdef G4VERBOSE
95  if ( fState.GetVerboseL3() )
97  ->Message("create", "main ntuple", ntupleBooking.name());
98 #endif
99 }
100 
101 //_____________________________________________________________________________
103 {
104 // Create ntuple from booking in master
105 
106  // Check that file is set
107  if ( ! fNtupleDirectory ) {
108  G4ExceptionDescription description;
109  description
110  << " " << "Ntuple file must be defined first."
111  << G4endl
112  << " " << "Cannot create main ntuples from builder.";
113  G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
114  "Analysis_W002", JustWarning, description);
115  return;
116  }
117 
118  auto& ntupleDescriptionVector
119  = fNtupleBuilder->GetNtupleDescriptionVector();
120 
121  for ( auto ntupleDescription : ntupleDescriptionVector ) {
122  CreateNtuple(ntupleDescription->fNtupleBooking);
123  }
124 }
125 
126 //_____________________________________________________________________________
128 {
129  for ( auto ntuple : fNtupleVector ) {
130  ntuple->merge_number_of_entries();
131  }
132 
133  return true;
134 }
135 
136 //_____________________________________________________________________________
138 {
139  for ( auto ntuple : fNtupleVector ) {
140  if ( deleteNtuple ) {
141  delete ntuple;
142  }
143  }
144 
145  fNtupleVector.clear();
146 
147  return true;
148 }
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void CreateNtuple(const tools::ntuple_booking &ntupleBooking, G4bool warn=true)
const G4AnalysisVerbose * GetVerboseL3() const
const G4AnalysisVerbose * GetVerboseL4() const
bool G4bool
Definition: G4Types.hh:79
G4bool Reset(G4bool deleteNtuple)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4RootMainNtupleManager(G4RootNtupleManager *ntupleBuilder, const G4AnalysisManagerState &state)
#define G4endl
Definition: G4ios.hh:61
const G4AnalysisManagerState & fState