Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4Hdf5AnalysisReader.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, 20/07/2017 (ivana@ipno.in2p3.fr)
29 
30 #include "G4Hdf5AnalysisReader.hh"
31 #include "G4Hdf5RNtupleManager.hh"
32 #include "G4AnalysisVerbose.hh"
33 #include "G4AnalysisUtilities.hh"
34 #include "G4Threading.hh"
35 
36 #include <iostream>
37 #include <cstdio>
38 
39 using namespace G4Analysis;
40 
43 
44 //_____________________________________________________________________________
46 {
47  if ( fgInstance == nullptr ) {
48  G4bool isMaster = ! G4Threading::IsWorkerThread();
49  fgInstance = new G4Hdf5AnalysisReader(isMaster);
50  }
51 
52  return fgInstance;
53 }
54 
55 //_____________________________________________________________________________
57  : G4ToolsAnalysisReader("Hdf5", isMaster),
58  fNtupleManager(nullptr),
59  fFileManager(nullptr)
60 {
61  if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
62  G4ExceptionDescription description;
63  description
64  << " "
65  << "G4Hdf5AnalysisReader already exists."
66  << "Cannot create another instance.";
67  G4Exception("G4Hdf5AnalysisReader::G4Hdf5AnalysisReader()",
68  "Analysis_F001", FatalException, description);
69  }
70  if ( isMaster ) fgMasterInstance = this;
71  fgInstance = this;
72 
73  // Create managers
76 
77  // Set managers to base class
80 }
81 
82 //_____________________________________________________________________________
84 {
85  if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
86  fgInstance = nullptr;
87 }
88 
89 //
90 // private methods
91 //
92 
93 //_____________________________________________________________________________
95 {
96 // Reset histograms and ntuple
97 
98  auto finalResult = true;
99 
101  finalResult = finalResult && result;
102 
103  result = fNtupleManager->Reset();
104  finalResult = finalResult && result;
105 
106  return finalResult;
107 }
108 
109 //
110 // protected methods
111 //
112 
113 //_____________________________________________________________________________
115  const G4String& fileName,
116  const G4String& dirName,
117  G4bool /*isUserFileName*/)
118 {
119 #ifdef G4VERBOSE
120  if ( fState.GetVerboseL4() )
121  fState.GetVerboseL4()->Message("read", "h1", h1Name);
122 #endif
123 
124  auto h1 = ReadHnImpl<tools::histo::h1d>(h1Name, fileName, dirName);
125 
126  if ( ! h1 ) return kInvalidId;
127 
128  auto id = fH1Manager->AddH1(h1Name, h1);
129 
130 #ifdef G4VERBOSE
131  if ( fState.GetVerboseL2() )
132  fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
133 #endif
134 
135  return id;
136 }
137 
138 //_____________________________________________________________________________
140  const G4String& fileName,
141  const G4String& dirName,
142  G4bool /*isUserFileName*/)
143 {
144 #ifdef G4VERBOSE
145  if ( fState.GetVerboseL4() )
146  fState.GetVerboseL4()->Message("read", "h2", h2Name);
147 #endif
148 
149  auto h2 = ReadHnImpl<tools::histo::h2d>(h2Name, fileName, dirName);
150 
151  if ( ! h2 ) return kInvalidId;
152 
153  auto id = fH2Manager->AddH2(h2Name, h2);
154 
155 #ifdef G4VERBOSE
156  if ( fState.GetVerboseL2() )
157  fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
158 #endif
159 
160  return id;
161 }
162 
163 //_____________________________________________________________________________
165  const G4String& fileName,
166  const G4String& dirName,
167  G4bool /*isUserFileName*/)
168 {
169 
170 #ifdef G4VERBOSE
171  if ( fState.GetVerboseL4() )
172  fState.GetVerboseL4()->Message("read", "h3", h3Name);
173 #endif
174 
175  auto h3 = ReadHnImpl<tools::histo::h3d>(h3Name, fileName, dirName);
176 
177  if ( ! h3 ) return kInvalidId;
178 
179  auto id = fH3Manager->AddH3(h3Name, h3);
180 
181 #ifdef G4VERBOSE
182  if ( fState.GetVerboseL2() )
183  fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
184 #endif
185 
186  return id;
187 }
188 
189 //_____________________________________________________________________________
191  const G4String& fileName,
192  const G4String& dirName,
193  G4bool /*isUserFileName*/)
194 {
195 #ifdef G4VERBOSE
196  if ( fState.GetVerboseL4() )
197  fState.GetVerboseL4()->Message("read", "p1", p1Name);
198 #endif
199 
200  auto p1 = ReadPnImpl<tools::histo::p1d>(p1Name, fileName, dirName);
201 
202  if ( ! p1 ) return kInvalidId;
203 
204  auto id = fP1Manager->AddP1(p1Name, p1);
205 
206 #ifdef G4VERBOSE
207  if ( fState.GetVerboseL2() )
208  fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
209 #endif
210 
211  return id;
212 }
213 
214 //_____________________________________________________________________________
216  const G4String& fileName,
217  const G4String& dirName,
218  G4bool /*isUserFileName*/)
219 {
220 
221 #ifdef G4VERBOSE
222  if ( fState.GetVerboseL4() )
223  fState.GetVerboseL4()->Message("read", "p2", p2Name);
224 #endif
225 
226  auto p2 = ReadPnImpl<tools::histo::p2d>(p2Name, fileName, dirName);
227 
228  if ( ! p2 ) return kInvalidId;
229 
230  auto id = fP2Manager->AddP2(p2Name, p2);
231 
232 #ifdef G4VERBOSE
233  if ( fState.GetVerboseL2() )
234  fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
235 #endif
236 
237  return id;
238 }
239 
240 //_____________________________________________________________________________
242  const G4String& fileName,
243  const G4String& dirName,
244  G4bool isUserFileName)
245 {
246 #ifdef G4VERBOSE
247  if ( fState.GetVerboseL4() )
248  fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
249 #endif
250 
251  // Ntuples are saved in files per thread
252  // but apply thethe thread suffix only if fileName is not provided explicitly
253  G4String fullFileName = fileName;
254  if ( ! isUserFileName ) {
255  fullFileName = fFileManager->GetFullFileName();
256  }
257 
258  // Get directory
259  auto directory = fFileManager->GetNtupleRDirectory(fullFileName, dirName, false);
260  if ( directory < 0 ) return kInvalidId;
261 
262  // Create ntuple
263  auto rntuple = new tools::hdf5::ntuple(G4cout, directory, ntupleName);
264  auto rntupleDescription = new G4TRNtupleDescription<tools::hdf5::ntuple>(rntuple);
265  auto id = fNtupleManager->SetNtuple(rntupleDescription);
266 
267 #ifdef G4VERBOSE
268  if ( fState.GetVerboseL2() )
269  fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
270 #endif
271 
272  return id;
273 }
G4Hdf5RNtupleManager * fNtupleManager
const G4AnalysisVerbose * GetVerboseL2() const
static G4Hdf5AnalysisReader * Instance()
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4H3ToolsManager * fH3Manager
G4AnalysisManagerState fState
static G4Hdf5AnalysisReader * fgMasterInstance
TTree * ntuple
TH1F * h3
virtual G4int ReadNtupleImpl(const G4String &ntupleName, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
#define G4ThreadLocal
Definition: tls.hh:69
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
void SetNtupleManager(G4VRNtupleManager *ntupleManager)
G4int AddH1(const G4String &name, tools::histo::h1d *h1d)
void SetFileManager(G4BaseFileManager *fileManager)
bool G4bool
Definition: G4Types.hh:79
G4H2ToolsManager * fH2Manager
G4Hdf5RFileManager * fFileManager
hid_t GetNtupleRDirectory(const G4String &fileName, const G4String &dirName, G4bool isPerThread)
G4int AddH3(const G4String &name, tools::histo::h3d *h3d)
virtual G4int ReadP2Impl(const G4String &p2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
G4bool IsWorkerThread()
Definition: G4Threading.cc:129
static G4ThreadLocal G4Hdf5AnalysisReader * fgInstance
const G4AnalysisVerbose * GetVerboseL4() const
G4int AddP1(const G4String &name, tools::histo::p1d *p1d)
G4P1ToolsManager * fP1Manager
const G4int kInvalidId
virtual G4int ReadH1Impl(const G4String &h1Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
G4double G4ParticleHPJENDLHEData::G4double result
TH1F * h2
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4int SetNtuple(G4TRNtupleDescription< TNTUPLE > *rntupleDescription)
int G4int
Definition: G4Types.hh:78
G4int AddP2(const G4String &name, tools::histo::p2d *p2d)
G4P2ToolsManager * fP2Manager
virtual G4int ReadH2Impl(const G4String &h2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual G4int ReadP1Impl(const G4String &p1Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4GLOB_DLL std::ostream G4cout
G4Hdf5AnalysisReader(G4bool isMaster=true)
G4int AddH2(const G4String &name, tools::histo::h2d *h2d)
TH1F * h1
virtual G4int ReadH3Impl(const G4String &h3Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
G4H1ToolsManager * fH1Manager