Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $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  G4bool rowWise,
40  const G4AnalysisManagerState& state)
41  : G4BaseAnalysisManager(state),
42  fNtupleBuilder(ntupleBuilder),
43  fRowWise(rowWise),
44  fNtupleDirectory(nullptr),
45  fNtupleVector()
46 {}
47 
48 //_____________________________________________________________________________
50 {
51  // ntuple objects are deleted automatically when closing a file
52 }
53 
54 //
55 // protected functions
56 //
57 
58 //_____________________________________________________________________________
59 void G4RootMainNtupleManager::CreateNtuple(const tools::ntuple_booking& ntupleBooking,
60  G4bool warn)
61 {
62 // Create ntuple from booking if file was open
63 
64  // Check that file is set
65  if ( ! fNtupleDirectory ) {
66  if ( warn ) {
67  G4ExceptionDescription description;
68  description
69  << " " << "Ntuple file must be defined first."
70  << G4endl
71  << " " << "Cannot create main ntuples from builder.";
72  G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
73  "Analysis_W002", JustWarning, description);
74  }
75  return;
76  }
77 
78 #ifdef G4VERBOSE
79  if ( fState.GetVerboseL4() )
81  ->Message("create", "main ntuple", ntupleBooking.name());
82 #endif
83 
84  // Create ntuple
85  auto ntuple = new tools::wroot::ntuple(*fNtupleDirectory, ntupleBooking, fRowWise);
86  // ntuple object is deleted automatically when closing a file
87  auto basketSize = fNtupleBuilder->GetBasketSize();
88  ntuple->set_basket_size(basketSize);
89 
90  fNtupleVector.push_back(ntuple);
91 
92 #ifdef G4VERBOSE
93  if ( fState.GetVerboseL3() )
95  ->Message("create", "main ntuple", ntupleBooking.name());
96 #endif
97 }
98 
99 //_____________________________________________________________________________
101 {
102 // Create ntuple from booking in master
103 
104  // Check that file is set
105  if ( ! fNtupleDirectory ) {
106  G4ExceptionDescription description;
107  description
108  << " " << "Ntuple file must be defined first."
109  << G4endl
110  << " " << "Cannot create main ntuples from builder.";
111  G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
112  "Analysis_W002", JustWarning, description);
113  return;
114  }
115 
116  auto& ntupleDescriptionVector
118 
119  for ( auto ntupleDescription : ntupleDescriptionVector ) {
120  CreateNtuple(ntupleDescription->fNtupleBooking);
121  }
122 }
123 
124 //_____________________________________________________________________________
126 {
127  for ( auto ntuple : fNtupleVector ) {
128  ntuple->merge_number_of_entries();
129  }
130 
131  return true;
132 }
133 
134 //_____________________________________________________________________________
136 {
137  for ( auto ntuple : fNtupleVector ) {
138  if ( deleteNtuple ) {
139  delete ntuple;
140  }
141  }
142 
143  fNtupleVector.clear();
144 
145  return true;
146 }
std::vector< tools::wroot::ntuple * > fNtupleVector
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
TTree * ntuple
#define G4endl
Definition: G4ios.hh:61
void CreateNtuple(const tools::ntuple_booking &ntupleBooking, G4bool warn=true)
G4bool Reset(G4bool deleteNtuple)
unsigned int GetBasketSize() const
bool G4bool
Definition: G4Types.hh:79
const G4AnalysisVerbose * GetVerboseL4() const
const G4AnalysisVerbose * GetVerboseL3() const
const std::vector< NtupleDescriptionType * > & GetNtupleDescriptionVector() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4RootNtupleManager * fNtupleBuilder
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
tools::wroot::directory * fNtupleDirectory
const G4AnalysisManagerState & fState
G4RootMainNtupleManager(G4RootNtupleManager *ntupleBuilder, G4bool rowWise, const G4AnalysisManagerState &state)