Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VAnalysisReader.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, 09/07/2013 ([email protected])
28
29#include "G4VAnalysisReader.hh"
31#include "G4HnManager.hh"
32#include "G4VRNtupleManager.hh"
33#include "G4VRFileManager.hh"
34#include "G4Threading.hh"
35
36using namespace G4Analysis;
37
38//_____________________________________________________________________________
40 : fState(type, ! G4Threading::IsWorkerThread())
41{}
42
43//_____________________________________________________________________________
45
46//
47// protected methods
48//
49
50//_____________________________________________________________________________
52{
53 fVH1Manager.reset(h1Manager);
54}
55
56//_____________________________________________________________________________
58{
59 fVH2Manager.reset(h2Manager);
60}
61
62//_____________________________________________________________________________
64{
65 fVH3Manager.reset(h3Manager);
66}
67
68//_____________________________________________________________________________
70{
71 fVP1Manager.reset(p1Manager);
72}
73
74//_____________________________________________________________________________
76{
77 fVP2Manager.reset(p2Manager);
78}
79
80//_____________________________________________________________________________
81void G4VAnalysisReader::SetNtupleManager(std::shared_ptr<G4VRNtupleManager> ntupleManager)
82{
83 fVNtupleManager = std::move(ntupleManager);
84}
85
86//_____________________________________________________________________________
87void G4VAnalysisReader::SetFileManager(std::shared_ptr<G4VRFileManager> fileManager)
88{
89 fVFileManager = std::move(fileManager);
90}
92//
93// public methods
94//
95
96//_____________________________________________________________________________
101
102//_____________________________________________________________________________
104{
105 fVFileManager->SetFileName(fileName);
106}
107
108//_____________________________________________________________________________
110{
111 return fVFileManager->GetFileName();
112}
113
114//_____________________________________________________________________________
116 const G4String& fileName,
117 const G4String& dirName)
118{
119 if ( fileName != "" ) {
120 return ReadH1Impl(h1Name, fileName, dirName, true);
121 }
122 if (fVFileManager->GetFileName() == "") {
123 Warn("Cannot get H1 " + h1Name + ". File name has to be set first.", fkClass, "ReadH1");
124 return kInvalidId;
125 }
126 return ReadH1Impl(h1Name, fVFileManager->GetFileName(), dirName, false);
127}
128
129//_____________________________________________________________________________
131 const G4String& fileName,
132 const G4String& dirName)
133{
134 if ( fileName != "" ) {
135 return ReadH2Impl(h2Name, fileName, dirName, true);
136 }
137 if (fVFileManager->GetFileName() == "") {
138 Warn("Cannot get H2 " + h2Name + ". File name has to be set first.", fkClass, "ReadH2");
139 return kInvalidId;
140 }
141 return ReadH2Impl(h2Name, fVFileManager->GetFileName(), dirName, false);
142}
143
144//_____________________________________________________________________________
146 const G4String& fileName,
147 const G4String& dirName)
148{
149 if ( fileName != "" ) {
150 return ReadH3Impl(h3Name, fileName, dirName, true);
151 }
152 if (fVFileManager->GetFileName() == "") {
153 Warn("Cannot get H3 " + h3Name + ". File name has to be set first.", fkClass, "ReadH3");
154 return kInvalidId;
155 }
156 return ReadH3Impl(h3Name, fVFileManager->GetFileName(), dirName, false);
157}
158
159//_____________________________________________________________________________
161 const G4String& fileName,
162 const G4String& dirName)
163{
164 if ( fileName != "" ) {
165 return ReadP1Impl(p1Name, fileName, dirName, true);
166 }
167 if (fVFileManager->GetFileName() == "") {
168 Warn("Cannot get P1 " + p1Name + ". File name has to be set first.", fkClass, "ReadP1");
169 return kInvalidId;
170 }
171 return ReadP1Impl(p1Name, fVFileManager->GetFileName(), dirName, false);
172}
173
174//_____________________________________________________________________________
176 const G4String& fileName,
177 const G4String& dirName)
178{
179 if ( fileName != "" ) {
180 return ReadP2Impl(p2Name, fileName, dirName, true);
181 }
182 if (fVFileManager->GetFileName() == "") {
183 Warn("Cannot get P2 " + p2Name + ". File name has to be set first.", fkClass, "ReadP2");
184 return kInvalidId;
185 }
186 return ReadP2Impl(p2Name, fVFileManager->GetFileName(), dirName, false);
187}
188
189//_____________________________________________________________________________
191{
192 auto result = true;
193
194 result &= SetFirstH1Id(firstId);
195 result &= SetFirstH2Id(firstId);
196 result &= SetFirstH3Id(firstId);
197
198 return result;
199}
200
201//_____________________________________________________________________________
203{
204 return fVH1Manager->GetHnManager()->SetFirstId(firstId);
205}
206
207//_____________________________________________________________________________
209{
210 return fVH2Manager->GetHnManager()->SetFirstId(firstId);
211}
212
213//_____________________________________________________________________________
215{
216 return fVH3Manager->GetHnManager()->SetFirstId(firstId);
217}
218
219//_____________________________________________________________________________
221{
222 auto result = true;
223
224 result &= SetFirstP1Id(firstId);
225 result &= SetFirstP2Id(firstId);
226
227 return result;
228}
229
230//_____________________________________________________________________________
232{
233 return fVP1Manager->GetHnManager()->SetFirstId(firstId);
234}
235
236//_____________________________________________________________________________
238{
239 return fVP2Manager->GetHnManager()->SetFirstId(firstId);
240}
241
242//_____________________________________________________________________________
244{
245 return fVNtupleManager->SetFirstId(firstId);
246}
247
248//_____________________________________________________________________________
250 const G4String& fileName,
251 const G4String& dirName)
252{
253 if ( fileName != "" ) {
254 return fVNtupleManager->ReadNtupleImpl(ntupleName, fileName, dirName, true);
255 }
256 // Check if fileName was set
257 if (fVFileManager->GetFileName() == "") {
258 Warn("Cannot read Ntuple " + ntupleName += ". File name has to be set first.", fkClass,
259 "ReadNtuple");
260 return kInvalidId;
261 }
262 return fVNtupleManager->ReadNtupleImpl(ntupleName, fVFileManager->GetFileName(), dirName, false);
263}
264
265//_____________________________________________________________________________
267 G4int& value)
268{
269 return fVNtupleManager->SetNtupleIColumn(columnName, value);
270}
271
272//_____________________________________________________________________________
274 G4float& value)
275{
276 return fVNtupleManager->SetNtupleFColumn(columnName, value);
277}
278
279//_____________________________________________________________________________
281 G4double& value)
282{
283 return fVNtupleManager->SetNtupleDColumn(columnName, value);
284}
285
286//_____________________________________________________________________________
288 G4String& value)
289{
290 return fVNtupleManager->SetNtupleSColumn(columnName, value);
291}
292
293//_____________________________________________________________________________
295 std::vector<int>& vector)
296{
297 return fVNtupleManager->SetNtupleIColumn(columnName, vector);
298}
299
300//_____________________________________________________________________________
302 std::vector<float>& vector)
303{
304 return fVNtupleManager->SetNtupleFColumn(columnName, vector);
305}
306
307//_____________________________________________________________________________
309 std::vector<double>& vector)
310{
311 return fVNtupleManager->SetNtupleDColumn(columnName, vector);
312}
313
314//_____________________________________________________________________________
316 std::vector<std::string>& vector)
317{
318 return fVNtupleManager->SetNtupleSColumn(columnName, vector);
319}
320
321//_____________________________________________________________________________
323 const G4String& columnName,
324 G4int& value)
325{
326 return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, value);
327}
328
329//_____________________________________________________________________________
331 const G4String& columnName,
332 G4float& value)
333{
334 return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, value);
335}
336
337//_____________________________________________________________________________
339 const G4String& columnName,
340 G4double& value)
341{
342 return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, value);
343}
344
345//_____________________________________________________________________________
347 const G4String& columnName,
348 G4String& value)
349{
350 return fVNtupleManager->SetNtupleSColumn(ntupleId, columnName, value);
351}
352
353//_____________________________________________________________________________
355 const G4String& columnName,
356 std::vector<int>& vector)
357{
358 return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, vector);
359}
360
361//_____________________________________________________________________________
363 const G4String& columnName,
364 std::vector<float>& vector)
365{
366 return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, vector);
367}
368
369//_____________________________________________________________________________
371 const G4String& columnName,
372 std::vector<double>& vector)
373{
374 return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, vector);
375}
376
377//_____________________________________________________________________________
379 const G4String& columnName,
380 std::vector<std::string>& vector)
381{
382 return fVNtupleManager->SetNtupleSColumn(ntupleId, columnName, vector);
383}
384
385//_____________________________________________________________________________
387{
388 return fVNtupleManager->GetNtupleRow();
389}
390
391
392//_____________________________________________________________________________
394{
395 return fVNtupleManager->GetNtupleRow(ntupleId);
396}
397
398//_____________________________________________________________________________
400{
401 return fVH1Manager->GetNofHns(onlyIfExist);
402}
403
404//_____________________________________________________________________________
406{
407 return fVH2Manager->GetNofHns(onlyIfExist);
408}
409
410//_____________________________________________________________________________
412{
413 return fVH3Manager->GetNofHns(onlyIfExist);
414}
415
416//_____________________________________________________________________________
418{
419 return fVP1Manager->GetNofHns(onlyIfExist);
420}
421
422//_____________________________________________________________________________
424{
425 return fVP2Manager->GetNofHns(onlyIfExist);
426}
427
428//_____________________________________________________________________________
430{
431 return fVNtupleManager->GetNofNtuples();
432}
433
434// GetH1Id(), GetH2Id in .icc
435
436// Access methods in .icc
437
438//_____________________________________________________________________________
440{
441 fState.SetVerboseLevel(verboseLevel);
442}
443
444// GetVerboseLevel() in .icc
float G4float
Definition G4Types.hh:84
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4bool SetFirstH3Id(G4int firstId)
void SetH2Manager(G4VTBaseHnManager< kDim2 > *h2Manager)
G4int ReadP2(const G4String &h2Name, const G4String &fileName="", const G4String &dirName="")
G4VAnalysisReader(const G4String &type)
G4bool SetNtupleFColumn(const G4String &columnName, G4float &value)
G4bool SetFirstP1Id(G4int firstId)
virtual G4int ReadH3Impl(const G4String &h3Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName)=0
void SetNtupleManager(std::shared_ptr< G4VRNtupleManager > ntupleManager)
G4bool SetNtupleSColumn(const G4String &columnName, G4String &value)
std::shared_ptr< G4VRFileManager > fVFileManager
G4bool SetNtupleDColumn(const G4String &columnName, G4double &value)
void SetH1Manager(G4VTBaseHnManager< kDim1 > *h1Manager)
G4bool SetFirstHistoId(G4int firstId)
G4String GetFileName() const
G4int GetNofH3s(G4bool onlyIfExist=false) const
G4int GetNofP1s(G4bool onlyIfExist=false) const
G4bool SetFirstH1Id(G4int firstId)
G4AnalysisManagerState fState
virtual G4int ReadP1Impl(const G4String &p1Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName)=0
G4int ReadH3(const G4String &h3Name, const G4String &fileName="", const G4String &dirName="")
void SetFileName(const G4String &fileName)
virtual G4int ReadH2Impl(const G4String &h2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName)=0
G4bool SetFirstNtupleId(G4int firstId)
virtual G4int ReadH1Impl(const G4String &h1Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName)=0
G4int GetNofH1s(G4bool onlyIfExist=false) const
G4int GetNofNtuples() const
void SetH3Manager(G4VTBaseHnManager< kDim3 > *h3Manager)
G4int ReadH2(const G4String &h2Name, const G4String &fileName="", const G4String &dirName="")
G4int GetNofP2s(G4bool onlyIfExist=false) const
G4bool SetFirstH2Id(G4int firstId)
G4bool CloseFiles(G4bool reset=true)
virtual ~G4VAnalysisReader()
G4bool SetFirstProfileId(G4int firstId)
virtual G4int ReadP2Impl(const G4String &p2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName)=0
G4int GetNtuple(const G4String &ntupleName, const G4String &fileName="", const G4String &dirName="")
G4bool SetNtupleIColumn(const G4String &columnName, G4int &value)
virtual G4bool CloseFilesImpl(G4bool reset)=0
G4int ReadP1(const G4String &h1Name, const G4String &fileName="", const G4String &dirName="")
void SetP1Manager(G4VTBaseHnManager< kDim2 > *p1Manager)
G4int GetNofH2s(G4bool onlyIfExist=false) const
void SetP2Manager(G4VTBaseHnManager< kDim3 > *p2Manager)
void SetVerboseLevel(G4int verboseLevel)
G4bool SetFirstP2Id(G4int firstId)
void SetFileManager(std::shared_ptr< G4VRFileManager > fileManager)
G4int ReadH1(const G4String &h1Name, const G4String &fileName="", const G4String &dirName="")
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)