ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RootMainNtupleManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4RootMainNtupleManager.cc
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 "G4RootNtupleManager.hh"
31 #include "G4AnalysisUtilities.hh"
32 
33 #include "tools/wroot/file"
34 #include "tools/wroot/ntuple"
35 
36 //_____________________________________________________________________________
38  G4bool rowWise,
39  const G4AnalysisManagerState& state)
40  : G4BaseAnalysisManager(state),
41  fNtupleBuilder(ntupleBuilder),
42  fRowWise(rowWise),
43  fNtupleDirectory(nullptr),
44  fNtupleVector()
45 {}
46 
47 //_____________________________________________________________________________
49 {
50  // ntuple objects are deleted automatically when closing a file
51 }
52 
53 //
54 // protected functions
55 //
56 
57 //_____________________________________________________________________________
58 void G4RootMainNtupleManager::CreateNtuple(const tools::ntuple_booking& ntupleBooking,
59  G4bool warn)
60 {
61 // Create ntuple from booking if file was open
62 
63  // Check that file is set
64  if ( ! fNtupleDirectory ) {
65  if ( warn ) {
66  G4ExceptionDescription description;
67  description
68  << " " << "Ntuple file must be defined first."
69  << G4endl
70  << " " << "Cannot create main ntuples from builder.";
71  G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
72  "Analysis_W002", JustWarning, description);
73  }
74  return;
75  }
76 
77 #ifdef G4VERBOSE
78  if ( fState.GetVerboseL4() )
80  ->Message("create", "main ntuple", ntupleBooking.name());
81 #endif
82 
83  // Create ntuple
84  auto ntuple = new tools::wroot::ntuple(*fNtupleDirectory, ntupleBooking, fRowWise);
85  // ntuple object is deleted automatically when closing a file
86  auto basketSize = fNtupleBuilder->GetBasketSize();
87  ntuple->set_basket_size(basketSize);
88 
89  fNtupleVector.push_back(ntuple);
90 
91 #ifdef G4VERBOSE
92  if ( fState.GetVerboseL3() )
94  ->Message("create", "main ntuple", ntupleBooking.name());
95 #endif
96 }
97 
98 //_____________________________________________________________________________
100 {
101 // Create ntuple from booking in master
102 
103  // Check that file is set
104  if ( ! fNtupleDirectory ) {
105  G4ExceptionDescription description;
106  description
107  << " " << "Ntuple file must be defined first."
108  << G4endl
109  << " " << "Cannot create main ntuples from builder.";
110  G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
111  "Analysis_W002", JustWarning, description);
112  return;
113  }
114 
115  auto& ntupleDescriptionVector
117 
118  for ( auto ntupleDescription : ntupleDescriptionVector ) {
119  CreateNtuple(ntupleDescription->fNtupleBooking);
120  }
121 }
122 
123 //_____________________________________________________________________________
125 {
126  for ( auto ntuple : fNtupleVector ) {
127  ntuple->merge_number_of_entries();
128  }
129 
130  return true;
131 }
132 
133 //_____________________________________________________________________________
135 {
136  for ( auto ntuple : fNtupleVector ) {
137  if ( deleteNtuple ) {
138  delete ntuple;
139  }
140  }
141 
142  fNtupleVector.clear();
143 
144  return true;
145 }