Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RootNtupleManager.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: G4RootNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4RootNtupleManager.hh"
32 #include "G4RootFileManager.hh"
34 #include "G4AnalysisUtilities.hh"
35 
36 #include "tools/wroot/file"
37 
38 using namespace G4Analysis;
39 
40 //_____________________________________________________________________________
42  G4int nofMainManagers,
43  G4bool rowWise)
44  : G4TNtupleManager<tools::wroot::ntuple>(state),
46  fFileManager(nullptr),
47  fNtupleDirectory(nullptr),
49 {
50  for ( G4int i=0; i<nofMainManagers; ++i) {
51  fMainNtupleManagers.push_back(
52  new G4RootMainNtupleManager(this, rowWise, fState));
53  }
54 }
55 
56 //_____________________________________________________________________________
58 {}
59 
60 //
61 // private methods
62 //
63 
64 //_____________________________________________________________________________
66 {
67 // Set create mode if not yet defined
68 
69 #ifdef G4VERBOSE
70  if ( fState.GetVerboseL4() )
72  ->Message("set", "ntuple create mode", "");
73 #endif
74 
75  G4String createMode;
77  if ( fMainNtupleManagers.size() ) {
78  if ( fFileManager->GetNtupleFile(0) ) {
80  createMode = "G4NtupleCreateMode::kMainAfterOpen";
81  } else {
83  createMode = "G4NtupleCreateMode::kMainBeforeOpen";
84  }
85  }
86  else {
87  if ( fNtupleDirectory ) {
89  createMode = "G4NtupleCreateMode::kNoMergeAfterOpen";
90  } else {
92  createMode = "G4NtupleCreateMode::kNoMergeBeforeOpen";
93  }
94  }
95  }
96 
97 #ifdef G4VERBOSE
98  if ( fState.GetVerboseL2() )
100  ->Message("set", "ntuple create mode", createMode);
101 #endif
102 }
103 
104 //_____________________________________________________________________________
107 {
108  if ( ! fNtupleDirectory ) {
109  G4String inFunction = "G4RootNtupleManager::::CreateTNtuple";
110  G4ExceptionDescription description;
111  description << " "
112  << "Cannot create ntuple. Ntuple directory does not exist." << G4endl;
113  G4Exception(inFunction, "Analysis_W002", JustWarning, description);
114  return;
115  }
116 
117  ntupleDescription->fNtuple
118  = new tools::wroot::ntuple(
119  *fNtupleDirectory, ntupleDescription->fNtupleBooking);
120 
121  auto basketSize = fFileManager->GetBasketSize();
122  ntupleDescription->fNtuple->set_basket_size(basketSize);
123 
124  ntupleDescription->fIsNtupleOwner = false;
125  // ntuple object is deleted automatically when closing a file
126  fNtupleVector.push_back(ntupleDescription->fNtuple);
127 }
128 
129 //_____________________________________________________________________________
132 {
134 
135  CreateTNtuple(ntupleDescription);
136  }
137 
139  auto counter = 0;
140  for ( auto manager : fMainNtupleManagers ) {
141  if ( ! manager->GetNtupleVector().size() ) {
142  // Create only once !!
143  manager->SetNtupleFile(fFileManager->GetNtupleFile(counter));
144  manager->SetNtupleDirectory(fFileManager->GetMainNtupleDirectory(counter++));
145  manager->CreateNtuplesFromBooking();
146  }
147  }
148  }
149 }
150 
151 //_____________________________________________________________________________
154 {
155 // Create main ntuples
156 
157  // Set create mode if not yet defined
158  SetCreateMode();
159 
160  // Create ntuple if file is open
162  CreateTNtuple(ntupleDescription);
163  }
164 
165  // Create main ntuples if file is open
167  auto counter = 0;
168  for ( auto manager : fMainNtupleManagers ) {
169  auto warn = true;
170  manager->SetNtupleFile(fFileManager->GetNtupleFile(counter));
171  manager->SetNtupleDirectory(fFileManager->GetMainNtupleDirectory(counter++));
172  manager->CreateNtuple(ntupleDescription->fNtupleBooking, warn);
173  }
174  }
175 }
176 
177 //_____________________________________________________________________________
179 {
181  // this will clear ntuple vector
182 
184  // clear also ntuple description vector
185  fNtupleDescriptionVector.clear();
186  }
187 
188  auto finalResult = true;
189  for ( auto manager : fMainNtupleManagers ) {
190  auto result = manager->Reset(false);
191  finalResult = result && finalResult;
192  }
193 
194  return finalResult;
195 }
196 
197 //_____________________________________________________________________________
199 {
200  auto finalResult = true;
201 
202  for ( auto manager : fMainNtupleManagers ) {
203  auto result = manager->Merge();
204  finalResult = result && finalResult;
205  }
206 
207  return finalResult;
208 }
209 
210 //_____________________________________________________________________________
212 {
213  if ( index < 0 || index >= G4int(fMainNtupleManagers.size()) ) {
214  G4String inFunction = "G4RootNtupleManager::::GetMainNtupleManager";
215  G4ExceptionDescription description;
216  description << " " << "main ntuple manager " << index << " does not exist.";
217  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
218  return nullptr;
219  }
220 
221  return fMainNtupleManagers[index];
222 }
223 
224 //_____________________________________________________________________________
226 {
227  if ( ! fFileManager ) {
228  G4String inFunction = "G4RootNtupleManager::::GetBasketSize";
229  G4ExceptionDescription description;
230  description << " " << "File manager must be defined first.";
231  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
232  return 0;
233  }
234 
235  return fFileManager->GetBasketSize();
236 }
237 
std::vector< G4TNtupleDescription< tools::wroot::ntuple > * > fNtupleDescriptionVector
const G4AnalysisVerbose * GetVerboseL2() const
G4RootMainNtupleManager * GetMainNtupleManager(G4int index) const
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4NtupleCreateMode fCreateMode
G4RootNtupleManager(const G4AnalysisManagerState &state, G4int nofMainManagers=0, G4bool rowWise=true)
TTree * ntuple
#define G4endl
Definition: G4ios.hh:61
std::vector< G4RootMainNtupleManager * > fMainNtupleManagers
unsigned int GetBasketSize() const
bool G4bool
Definition: G4Types.hh:79
G4NtupleCreateMode
const G4AnalysisVerbose * GetVerboseL4() const
virtual G4bool Reset(G4bool deleteNtuple)
void CreateTNtuple(NtupleDescriptionType *ntupleDescription)
std::shared_ptr< G4RootFileManager > fFileManager
G4bool Reset(G4bool deleteNtuple)
friend class G4RootMainNtupleManager
G4double G4ParticleHPJENDLHEData::G4double result
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
virtual void CreateTNtupleFromBooking(NtupleDescriptionType *ntupleDescription) final
tools::wroot::directory * fNtupleDirectory
virtual void FinishTNtuple(NtupleDescriptionType *ntupleDescription) final
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
tools::ntuple_booking fNtupleBooking
std::vector< tools::wroot::ntuple * > fNtupleVector
const G4AnalysisManagerState & fState