Geant4-11
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 (ivana@ipno.in2p3.fr)
28
29#include "G4VAnalysisReader.hh"
31#include "G4HnManager.hh"
32#include "G4VH1Manager.hh"
33#include "G4VH2Manager.hh"
34#include "G4VH3Manager.hh"
35#include "G4VP1Manager.hh"
36#include "G4VP2Manager.hh"
37#include "G4VRNtupleManager.hh"
38#include "G4VRFileManager.hh"
39#include "G4Threading.hh"
40
41using namespace G4Analysis;
42
43//_____________________________________________________________________________
45 : fState(type, ! G4Threading::IsWorkerThread())
46{}
47
48//_____________________________________________________________________________
50
51//
52// protected methods
53//
54
55//_____________________________________________________________________________
57{
58 fVH1Manager.reset(h1Manager);
59}
60
61//_____________________________________________________________________________
63{
64 fVH2Manager.reset(h2Manager);
65}
66
67//_____________________________________________________________________________
69{
70 fVH3Manager.reset(h3Manager);
71}
72
73//_____________________________________________________________________________
75{
76 fVP1Manager.reset(p1Manager);
77}
78
79//_____________________________________________________________________________
81{
82 fVP2Manager.reset(p2Manager);
83}
84
85//_____________________________________________________________________________
86void G4VAnalysisReader::SetNtupleManager(std::shared_ptr<G4VRNtupleManager> ntupleManager)
87{
88 fVNtupleManager = std::move(ntupleManager);
90
91//_____________________________________________________________________________
92void G4VAnalysisReader::SetFileManager(std::shared_ptr<G4VRFileManager> fileManager)
93{
94 fVFileManager = std::move(fileManager);
95}
96
97//
98// public methods
99//
100
101//_____________________________________________________________________________
103{
104 return CloseFilesImpl(reset);
105}
106
107//_____________________________________________________________________________
109{
110 fVFileManager->SetFileName(fileName);
111}
112
113//_____________________________________________________________________________
115{
116 return fVFileManager->GetFileName();
117}
118
119//_____________________________________________________________________________
121 const G4String& fileName,
122 const G4String& dirName)
123{
124 if ( fileName != "" ) {
125 return ReadH1Impl(h1Name, fileName, dirName, true);
126 }
127 else {
128 if ( fVFileManager->GetFileName() == "" ) {
129 Warn("Cannot get H1 " + h1Name + ". File name has to be set first.",
130 fkClass, "ReadH1");
131 return kInvalidId;
132 }
133 return ReadH1Impl(h1Name, fVFileManager->GetFileName(), dirName, false);
134 }
135}
136
137//_____________________________________________________________________________
139 const G4String& fileName,
140 const G4String& dirName)
141{
142 if ( fileName != "" ) {
143 return ReadH2Impl(h2Name, fileName, dirName, true);
144 }
145 else {
146 if ( fVFileManager->GetFileName() == "" ) {
147 Warn("Cannot get H2 " + h2Name + ". File name has to be set first.",
148 fkClass, "ReadH2");
149 return kInvalidId;
150 }
151 return ReadH2Impl(h2Name, fVFileManager->GetFileName(), dirName, false);
152 }
153}
154
155//_____________________________________________________________________________
157 const G4String& fileName,
158 const G4String& dirName)
159{
160 if ( fileName != "" ) {
161 return ReadH3Impl(h3Name, fileName, dirName, true);
162 }
163 else {
164 if ( fVFileManager->GetFileName() == "" ) {
165 Warn("Cannot get H3 " + h3Name + ". File name has to be set first.",
166 fkClass, "ReadH3");
167 return kInvalidId;
168 }
169 return ReadH3Impl(h3Name, fVFileManager->GetFileName(), dirName, false);
170 }
171}
172
173//_____________________________________________________________________________
175 const G4String& fileName,
176 const G4String& dirName)
177{
178 if ( fileName != "" ) {
179 return ReadP1Impl(p1Name, fileName, dirName, true);
180 }
181 else {
182 if ( fVFileManager->GetFileName() == "" ) {
183 Warn("Cannot get P1 " + p1Name + ". File name has to be set first.",
184 fkClass, "ReadP1");
185 return kInvalidId;
186 }
187 return ReadP1Impl(p1Name, fVFileManager->GetFileName(), dirName, false);
188 }
189}
190
191//_____________________________________________________________________________
193 const G4String& fileName,
194 const G4String& dirName)
195{
196 if ( fileName != "" ) {
197 return ReadP2Impl(p2Name, fileName, dirName, true);
198 }
199 else {
200 if ( fVFileManager->GetFileName() == "" ) {
201 Warn("Cannot get P2 " + p2Name + ". File name has to be set first.",
202 fkClass, "ReadP2");
203 return kInvalidId;
204 }
205 return ReadP2Impl(p2Name, fVFileManager->GetFileName(), dirName, false);
206 }
207}
208
209//_____________________________________________________________________________
211{
212 auto result = true;
213
214 result &= SetFirstH1Id(firstId);
215 result &= SetFirstH2Id(firstId);
216 result &= SetFirstH3Id(firstId);
217
218 return result;
219}
220
221//_____________________________________________________________________________
223{
224 return fVH1Manager->GetHnManager()->SetFirstId(firstId);
225}
226
227//_____________________________________________________________________________
229{
230 return fVH2Manager->GetHnManager()->SetFirstId(firstId);
231}
232
233//_____________________________________________________________________________
235{
236 return fVH3Manager->GetHnManager()->SetFirstId(firstId);
237}
238
239//_____________________________________________________________________________
241{
242 auto result = true;
243
244 result &= SetFirstP1Id(firstId);
245 result &= SetFirstP2Id(firstId);
246
247 return result;
248}
249
250//_____________________________________________________________________________
252{
253 return fVP1Manager->GetHnManager()->SetFirstId(firstId);
254}
255
256//_____________________________________________________________________________
258{
259 return fVP2Manager->GetHnManager()->SetFirstId(firstId);
260}
261
262//_____________________________________________________________________________
264{
265 return fVNtupleManager->SetFirstId(firstId);
266}
267
268//_____________________________________________________________________________
270 const G4String& fileName,
271 const G4String& dirName)
272{
273 if ( fileName != "" ) {
274 return fVNtupleManager->ReadNtupleImpl(ntupleName, fileName, dirName, true);
275 }
276 else {
277 // Check if fileName was set
278 if ( fVFileManager->GetFileName() == "" ) {
279 Warn("Cannot read Ntuple " + ntupleName += ". File name has to be set first.",
280 fkClass, "ReadNtuple");
281 return kInvalidId;
282 }
283 return fVNtupleManager->ReadNtupleImpl(
284 ntupleName, fVFileManager->GetFileName(), dirName, false);
285 }
286}
287
288//_____________________________________________________________________________
290 G4int& value)
291{
292 return fVNtupleManager->SetNtupleIColumn(columnName, value);
293}
294
295//_____________________________________________________________________________
297 G4float& value)
298{
299 return fVNtupleManager->SetNtupleFColumn(columnName, value);
300}
301
302//_____________________________________________________________________________
304 G4double& value)
305{
306 return fVNtupleManager->SetNtupleDColumn(columnName, value);
307}
308
309//_____________________________________________________________________________
311 G4String& value)
312{
313 return fVNtupleManager->SetNtupleSColumn(columnName, value);
314}
315
316//_____________________________________________________________________________
318 std::vector<int>& vector)
319{
320 return fVNtupleManager->SetNtupleIColumn(columnName, vector);
321}
322
323//_____________________________________________________________________________
325 std::vector<float>& vector)
326{
327 return fVNtupleManager->SetNtupleFColumn(columnName, vector);
328}
329
330//_____________________________________________________________________________
332 std::vector<double>& vector)
333{
334 return fVNtupleManager->SetNtupleDColumn(columnName, vector);
335}
336
337//_____________________________________________________________________________
339 std::vector<std::string>& vector)
340{
341 return fVNtupleManager->SetNtupleSColumn(columnName, vector);
342}
343
344//_____________________________________________________________________________
346 const G4String& columnName,
347 G4int& value)
348{
349 return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, value);
350}
351
352//_____________________________________________________________________________
354 const G4String& columnName,
355 G4float& value)
356{
357 return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, value);
358}
359
360//_____________________________________________________________________________
362 const G4String& columnName,
363 G4double& value)
364{
365 return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, value);
366}
367
368//_____________________________________________________________________________
370 const G4String& columnName,
371 G4String& value)
372{
373 return fVNtupleManager->SetNtupleSColumn(ntupleId, columnName, value);
374}
375
376//_____________________________________________________________________________
378 const G4String& columnName,
379 std::vector<int>& vector)
380{
381 return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, vector);
382}
383
384//_____________________________________________________________________________
386 const G4String& columnName,
387 std::vector<float>& vector)
388{
389 return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, vector);
390}
391
392//_____________________________________________________________________________
394 const G4String& columnName,
395 std::vector<double>& vector)
396{
397 return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, vector);
398}
399
400//_____________________________________________________________________________
402 const G4String& columnName,
403 std::vector<std::string>& vector)
404{
405 return fVNtupleManager->SetNtupleSColumn(ntupleId, columnName, vector);
406}
407
408//_____________________________________________________________________________
410{
411 return fVNtupleManager->GetNtupleRow();
412}
413
414
415//_____________________________________________________________________________
417{
418 return fVNtupleManager->GetNtupleRow(ntupleId);
419}
420
421//_____________________________________________________________________________
423{
424 return fVH1Manager->GetHnManager()->GetNofHns();
425}
426
427//_____________________________________________________________________________
429{
430 return fVH2Manager->GetHnManager()->GetNofHns();
431}
432
433//_____________________________________________________________________________
435{
436 return fVH3Manager->GetHnManager()->GetNofHns();
437}
438
439//_____________________________________________________________________________
441{
442 return fVP1Manager->GetHnManager()->GetNofHns();
443}
444
445//_____________________________________________________________________________
447{
448 return fVP2Manager->GetHnManager()->GetNofHns();
449}
450
451//_____________________________________________________________________________
453{
454 return fVNtupleManager->GetNofNtuples();
455}
456
457// GetH1Id(), GetH2Id in .icc
458
459// Access methods in .icc
460
461//_____________________________________________________________________________
463{
464 fState.SetVerboseLevel(verboseLevel);
465}
466
467// 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
void SetVerboseLevel(G4int verboseLevel)
G4bool SetFirstH3Id(G4int firstId)
G4int ReadP2(const G4String &h2Name, const G4String &fileName="", const G4String &dirName="")
std::unique_ptr< G4VH1Manager > fVH1Manager
G4VAnalysisReader(const G4String &type)
G4bool SetNtupleFColumn(const G4String &columnName, G4float &value)
G4int GetNofH2s() const
static constexpr std::string_view fkClass
G4bool SetFirstP1Id(G4int firstId)
virtual G4int ReadH3Impl(const G4String &h3Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName)=0
std::unique_ptr< G4VP2Manager > fVP2Manager
G4int GetNofH1s() const
void SetNtupleManager(std::shared_ptr< G4VRNtupleManager > ntupleManager)
void SetP1Manager(G4VP1Manager *p1Manager)
G4bool SetNtupleSColumn(const G4String &columnName, G4String &value)
std::shared_ptr< G4VRFileManager > fVFileManager
G4int GetNofP2s() const
G4bool SetNtupleDColumn(const G4String &columnName, G4double &value)
G4bool SetFirstHistoId(G4int firstId)
void SetP2Manager(G4VP2Manager *p2Manager)
G4String GetFileName() const
G4bool SetFirstH1Id(G4int firstId)
G4AnalysisManagerState fState
std::unique_ptr< G4VP1Manager > fVP1Manager
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 GetNofNtuples() const
void SetH2Manager(G4VH2Manager *h2Manager)
G4int ReadH2(const G4String &h2Name, const G4String &fileName="", const G4String &dirName="")
G4bool SetFirstH2Id(G4int firstId)
G4bool CloseFiles(G4bool reset=true)
G4int GetNofP1s() const
virtual ~G4VAnalysisReader()
G4bool SetFirstProfileId(G4int firstId)
void SetH1Manager(G4VH1Manager *h1Manager)
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)
std::unique_ptr< G4VH3Manager > fVH3Manager
virtual G4bool CloseFilesImpl(G4bool reset)=0
G4int ReadP1(const G4String &h1Name, const G4String &fileName="", const G4String &dirName="")
G4int GetNofH3s() const
void SetVerboseLevel(G4int verboseLevel)
G4bool SetFirstP2Id(G4int firstId)
void SetFileManager(std::shared_ptr< G4VRFileManager > fileManager)
void SetH3Manager(G4VH3Manager *h3Manager)
std::unique_ptr< G4VH2Manager > fVH2Manager
G4int ReadH1(const G4String &h1Name, const G4String &fileName="", const G4String &dirName="")
std::shared_ptr< G4VRNtupleManager > fVNtupleManager
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
G4bool IsWorkerThread()
Definition: G4Threading.cc:123