Geant4  10.01.p01
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 // $Id: G4VAnalysisReader.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 09/07/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4VAnalysisReader.hh"
31 #include "G4AnalysisUtilities.hh"
32 #include "G4BaseFileManager.hh"
33 #include "G4HnManager.hh"
34 #include "G4VH1Manager.hh"
35 #include "G4VH2Manager.hh"
36 #include "G4VH3Manager.hh"
37 #include "G4VP1Manager.hh"
38 #include "G4VP2Manager.hh"
39 #include "G4VRNtupleManager.hh"
40 
41 #include <iostream>
42 
43 using namespace G4Analysis;
44 
45 //_____________________________________________________________________________
47  : fState(type, isMaster),
48  fVH1Manager(0),
49  fVH2Manager(0),
50  fVH3Manager(0),
51  fVP1Manager(0),
52  fVP2Manager(0),
53  fVNtupleManager(0),
54  fFileManager(0)
55 {}
56 
57 //_____________________________________________________________________________
59 {
60  delete fVH1Manager;
61  delete fVH2Manager;
62  delete fVH3Manager;
63  delete fVP1Manager;
64  delete fVP2Manager;
65  delete fVNtupleManager;
66  delete fFileManager;
67 }
68 
69 //
70 // protected methods
71 //
72 
73 //_____________________________________________________________________________
75 {
76  fVH1Manager = h1Manager;
77 }
78 
79 //_____________________________________________________________________________
81 {
82  fVH2Manager = h2Manager;
83 }
84 
85 //_____________________________________________________________________________
87 {
88  fVH3Manager = h3Manager;
89 }
90 
91 //_____________________________________________________________________________
93 {
94  fVP1Manager = p1Manager;
95 }
96 
97 //_____________________________________________________________________________
99 {
100  fVP2Manager = p2Manager;
101 }
102 
103 //_____________________________________________________________________________
105 {
106  fVNtupleManager = ntupleManager;
107 }
108 
109 //_____________________________________________________________________________
111 {
112  fFileManager = fileManager;
113 }
114 
115 //
116 // public methods
117 //
118 
119 //_____________________________________________________________________________
121 {
122  fFileManager->SetFileName(fileName);
123 }
124 
125 //_____________________________________________________________________________
127 {
128  return fFileManager->GetFileName();
129 }
130 
131 //_____________________________________________________________________________
133  const G4String& fileName)
134 {
135  if ( fileName != "" ) {
136  return ReadH1Impl(h1Name, fileName, true);
137  }
138  else {
139  if ( fFileManager->GetFileName() == "" ) {
140  G4ExceptionDescription description;
141  description
142  << "Cannot get H1. File name has to be set first.";
143  G4Exception("G4VAnalysisReader::ReadH1()",
144  "Analysis_WR011", JustWarning, description);
145  return kInvalidId;
146  }
147  return ReadH1Impl(h1Name, fFileManager->GetFileName(), false);
148  }
149 }
150 
151 //_____________________________________________________________________________
153  const G4String& fileName)
154 {
155  if ( fileName != "" ) {
156  return ReadH2Impl(h2Name, fileName, true);
157  }
158  else {
159  if ( fFileManager->GetFileName() == "" ) {
160  G4ExceptionDescription description;
161  description
162  << "Cannot get H2. File name has to be set first.";
163  G4Exception("G4VAnalysisReader::ReadH2()",
164  "Analysis_WR011", JustWarning, description);
165  return kInvalidId;
166  }
167  return ReadH2Impl(h2Name, fFileManager->GetFileName(), false);
168  }
169 }
170 
171 //_____________________________________________________________________________
173  const G4String& fileName)
174 {
175  if ( fileName != "" ) {
176  return ReadH3Impl(h3Name, fileName, true);
177  }
178  else {
179  if ( fFileManager->GetFileName() == "" ) {
180  G4ExceptionDescription description;
181  description
182  << "Cannot get H3. File name has to be set first.";
183  G4Exception("G4VAnalysisReader::ReadH2()",
184  "Analysis_WR011", JustWarning, description);
185  return kInvalidId;
186  }
187  return ReadH3Impl(h3Name, fFileManager->GetFileName(), false);
188  }
189 }
190 
191 //_____________________________________________________________________________
193  const G4String& fileName)
194 {
195  if ( fileName != "" ) {
196  return ReadP1Impl(p1Name, fileName, true);
197  }
198  else {
199  if ( fFileManager->GetFileName() == "" ) {
200  G4ExceptionDescription description;
201  description
202  << "Cannot get P1. File name has to be set first.";
203  G4Exception("G4VAnalysisReader::ReadP1()",
204  "Analysis_WR011", JustWarning, description);
205  return kInvalidId;
206  }
207  return ReadP1Impl(p1Name, fFileManager->GetFileName(), false);
208  }
209 }
210 
211 //_____________________________________________________________________________
213  const G4String& fileName)
214 {
215  if ( fileName != "" ) {
216  return ReadP2Impl(p2Name, fileName, true);
217  }
218  else {
219  if ( fFileManager->GetFileName() == "" ) {
220  G4ExceptionDescription description;
221  description
222  << "Cannot get P2. File name has to be set first.";
223  G4Exception("G4VAnalysisReader::ReadP2()",
224  "Analysis_WR011", JustWarning, description);
225  return kInvalidId;
226  }
227  return ReadP2Impl(p2Name, fFileManager->GetFileName(), false);
228  }
229 }
230 
231 //_____________________________________________________________________________
233 {
234  G4bool finalResult = true;
235 
236  G4bool result = SetFirstH1Id(firstId);
237  finalResult = finalResult && result;
238 
239  result = SetFirstH2Id(firstId);
240  finalResult = finalResult && result;
241 
242  result = SetFirstH3Id(firstId);
243  finalResult = finalResult && result;
244 
245  return finalResult;
246 }
247 
248 //_____________________________________________________________________________
250 {
251  G4bool finalResult = true;
252  G4bool result = fVH1Manager->SetFirstId(firstId);
253  finalResult = finalResult && result;
254 
255  result = fVH1Manager->fHnManager->SetFirstId(firstId);
256  finalResult = finalResult && result;
257 
258  return finalResult;
259 }
260 
261 //_____________________________________________________________________________
263 {
264  G4bool finalResult = true;
265  G4bool result = fVH2Manager->SetFirstId(firstId);
266  finalResult = finalResult && result;
267 
268  result = fVH2Manager->fHnManager->SetFirstId(firstId);
269  finalResult = finalResult && result;
270 
271  return finalResult;
272 }
273 
274 //_____________________________________________________________________________
276 {
277  G4bool finalResult = true;
278  G4bool result = fVH3Manager->SetFirstId(firstId);
279  finalResult = finalResult && result;
280 
281  result = fVH3Manager->fHnManager->SetFirstId(firstId);
282  finalResult = finalResult && result;
283 
284  return finalResult;
285 }
286 
287 //_____________________________________________________________________________
289 {
290  G4bool finalResult = true;
291 
292  G4bool result = SetFirstP1Id(firstId);
293  finalResult = finalResult && result;
294 
295  result = SetFirstP2Id(firstId);
296  finalResult = finalResult && result;
297 
298  return finalResult;
299 }
300 
301 //_____________________________________________________________________________
303 {
304  G4bool finalResult = true;
305  G4bool result = fVP1Manager->SetFirstId(firstId);
306  finalResult = finalResult && result;
307 
308  result = fVP1Manager->fHnManager->SetFirstId(firstId);
309  finalResult = finalResult && result;
310 
311  return finalResult;
312 }
313 
314 //_____________________________________________________________________________
316 {
317  G4bool finalResult = true;
318  G4bool result = fVP2Manager->SetFirstId(firstId);
319  finalResult = finalResult && result;
320 
321  result = fVP2Manager->fHnManager->SetFirstId(firstId);
322  finalResult = finalResult && result;
323 
324  return finalResult;
325 }
326 
327 //_____________________________________________________________________________
329 {
330  return fVNtupleManager->SetFirstId(firstId);
331 }
332 
333 //_____________________________________________________________________________
335  const G4String& fileName)
336 {
337  if ( fileName != "" ) {
338  return ReadNtupleImpl(ntupleName, fileName, true);
339  }
340  else {
341  if ( fFileManager->GetFileName() == "" ) {
342  G4ExceptionDescription description;
343  description
344  << "Cannot get Ntuple. File name has to be set first.";
345  G4Exception("G4VAnalysisReader::GetNtuple()",
346  "Analysis_WR011", JustWarning, description);
347  return kInvalidId;
348  }
349  return ReadNtupleImpl(ntupleName, fFileManager->GetFileName(), false);
350  }
351 }
352 
353 //_____________________________________________________________________________
355  G4int& value)
356 {
357  return fVNtupleManager->SetNtupleIColumn(columnName, value);
358 }
359 
360 //_____________________________________________________________________________
362  G4float& value)
363 {
364  return fVNtupleManager->SetNtupleFColumn(columnName, value);
365 }
366 
367 //_____________________________________________________________________________
369  G4double& value)
370 {
371  return fVNtupleManager->SetNtupleDColumn(columnName, value);
372 }
373 
374 //_____________________________________________________________________________
376  G4String& value)
377 {
378  return fVNtupleManager->SetNtupleSColumn(columnName, value);
379 }
380 
381 //_____________________________________________________________________________
383  std::vector<int>& vector)
384 {
385  return fVNtupleManager->SetNtupleIColumn(columnName, vector);
386 }
387 
388 //_____________________________________________________________________________
390  std::vector<float>& vector)
391 {
392  return fVNtupleManager->SetNtupleFColumn(columnName, vector);
393 }
394 
395 //_____________________________________________________________________________
397  std::vector<double>& vector)
398 {
399  return fVNtupleManager->SetNtupleDColumn(columnName, vector);
400 }
401 
402 //_____________________________________________________________________________
404  const G4String& columnName,
405  G4int& value)
406 {
407  return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, value);
408 }
409 
410 //_____________________________________________________________________________
412  const G4String& columnName,
413  G4float& value)
414 {
415  return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, value);
416 }
417 
418 //_____________________________________________________________________________
420  const G4String& columnName,
421  G4double& value)
422 {
423  return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, value);
424 }
425 
426 //_____________________________________________________________________________
428  const G4String& columnName,
429  G4String& value)
430 {
431  return fVNtupleManager->SetNtupleSColumn(ntupleId, columnName, value);
432 }
433 
434 //_____________________________________________________________________________
436  const G4String& columnName,
437  std::vector<int>& vector)
438 {
439  return fVNtupleManager->SetNtupleIColumn(ntupleId, columnName, vector);
440 }
441 
442 //_____________________________________________________________________________
444  const G4String& columnName,
445  std::vector<float>& vector)
446 {
447  return fVNtupleManager->SetNtupleFColumn(ntupleId, columnName, vector);
448 }
449 
450 //_____________________________________________________________________________
452  const G4String& columnName,
453  std::vector<double>& vector)
454 {
455  return fVNtupleManager->SetNtupleDColumn(ntupleId, columnName, vector);
456 }
457 
458 //_____________________________________________________________________________
460 {
461  return fVNtupleManager->GetNtupleRow();
462 }
463 
464 
465 //_____________________________________________________________________________
467 {
468  return fVNtupleManager->GetNtupleRow(ntupleId);
469 }
470 
471 //_____________________________________________________________________________
473 {
474  return fVH1Manager->fHnManager->GetNofHns();
475 }
476 
477 //_____________________________________________________________________________
479 {
480  return fVH2Manager->fHnManager->GetNofHns();
481 }
482 
483 //_____________________________________________________________________________
485 {
486  return fVH3Manager->fHnManager->GetNofHns();
487 }
488 
489 //_____________________________________________________________________________
491 {
492  return fVP1Manager->fHnManager->GetNofHns();
493 }
494 
495 //_____________________________________________________________________________
497 {
498  return fVP2Manager->fHnManager->GetNofHns();
499 }
500 
501 //_____________________________________________________________________________
503 {
504  return fVNtupleManager->GetNofNtuples();
505 }
506 
507 // GetH1Id(), GetH2Id in .icc
508 
509 // Access methods in .icc
510 
511 //_____________________________________________________________________________
513 {
514  fState.SetVerboseLevel(verboseLevel);
515 }
516 
517 // GetVerboseLevel() in .icc
virtual G4bool SetFileName(const G4String &fileName)
G4VP1Manager * fVP1Manager
void SetP1Manager(G4VP1Manager *p1Manager)
virtual G4int ReadH3Impl(const G4String &, const G4String &, G4bool)
G4HnManager * fHnManager
G4int GetNofP2s() const
void SetP2Manager(G4VP2Manager *p2Manager)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual G4int ReadNtupleImpl(const G4String &, const G4String &, G4bool)
virtual G4bool SetNtupleSColumn(const G4String &, G4String &)
G4int ReadP1(const G4String &h1Name, const G4String &fileName="")
G4bool SetFirstProfileId(G4int firstId)
virtual ~G4VAnalysisReader()
float G4float
Definition: G4Types.hh:77
G4bool SetFirstId(G4int firstId)
G4bool SetNtupleDColumn(const G4String &columnName, G4double &value)
G4VAnalysisReader(const G4String &type, G4bool isMaster)
virtual G4bool SetNtupleDColumn(const G4String &columnName, G4double &value)=0
G4int ReadH2(const G4String &h2Name, const G4String &fileName="")
G4String GetFileName() const
G4AnalysisManagerState fState
int G4int
Definition: G4Types.hh:78
G4VP2Manager * fVP2Manager
G4HnManager * fHnManager
virtual G4int ReadH2Impl(const G4String &, const G4String &, G4bool)
G4bool SetNtupleSColumn(const G4String &columnName, G4String &value)
void SetH3Manager(G4VH3Manager *h3Manager)
G4bool SetNtupleIColumn(const G4String &columnName, G4int &value)
G4HnManager * fHnManager
G4bool SetNtupleFColumn(const G4String &columnName, G4float &value)
void SetFileName(const G4String &fileName)
G4int ReadH3(const G4String &h3Name, const G4String &fileName="")
bool G4bool
Definition: G4Types.hh:79
G4int ReadP2(const G4String &h2Name, const G4String &fileName="")
virtual G4bool SetNtupleIColumn(const G4String &columnName, G4int &value)=0
void SetNtupleManager(G4VRNtupleManager *ntupleManager)
G4int ReadH1(const G4String &h1Name, const G4String &fileName="")
virtual G4bool GetNtupleRow()=0
virtual G4int ReadP1Impl(const G4String &, const G4String &, G4bool)
G4HnManager * fHnManager
G4bool SetFirstHistoId(G4int firstId)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool SetFirstNtupleId(G4int firstId)
G4VH1Manager * fVH1Manager
G4int GetNofP1s() const
void SetH1Manager(G4VH1Manager *h1Manager)
G4HnManager * fHnManager
G4int GetNofH2s() const
G4int GetNofH1s() const
G4bool SetFirstH1Id(G4int firstId)
G4bool SetFirstH2Id(G4int firstId)
virtual G4int ReadH1Impl(const G4String &, const G4String &, G4bool)
G4VH2Manager * fVH2Manager
G4bool SetFirstP2Id(G4int firstId)
virtual G4bool SetNtupleFColumn(const G4String &columnName, G4float &value)=0
virtual G4int ReadP2Impl(const G4String &, const G4String &, G4bool)
void SetVerboseLevel(G4int verboseLevel)
G4VH3Manager * fVH3Manager
G4bool SetFirstH3Id(G4int firstId)
G4int GetNtuple(const G4String &ntupleName, const G4String &fileName="")
double G4double
Definition: G4Types.hh:76
G4bool SetFirstP1Id(G4int firstId)
virtual G4int GetNofNtuples() const
G4String GetFileName() const
void SetH2Manager(G4VH2Manager *h2Manager)
G4int GetNofH3s() const
void SetVerboseLevel(G4int verboseLevel)
const G4int kInvalidId
G4VRNtupleManager * fVNtupleManager
G4BaseFileManager * fFileManager
G4int GetNofHns() const
Definition: G4HnManager.hh:128
void SetFileManager(G4BaseFileManager *fileManager)
G4int GetNofNtuples() const