38 #include <tools/rroot/file>
39 #include <tools/rroot/streamers>
40 #include <tools/rroot/fac>
41 #include <tools/rroot/tree>
42 #include <tools/rroot/ntuple>
47 using namespace G4Analysis;
55 if ( fgInstance ==
nullptr ) {
66 fNtupleManager(nullptr),
69 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
73 <<
"G4RootAnalysisReader already exists."
74 <<
"Cannot create another instance.";
75 G4Exception(
"G4RootAnalysisReader::G4RootAnalysisReader()",
78 if ( isMaster ) fgMasterInstance =
this;
113 G4bool isPerThread =
false;
116 auto rfile = fFileManager->
GetRFile(fileName, isPerThread);
118 if ( ! fFileManager->
OpenRFile(fileName, isPerThread) )
return nullptr;
119 rfile = fFileManager->
GetRFile(fileName, isPerThread);
123 = ( ! rfile ) ?
nullptr : rfile->dir().find_key(objectName);
128 char* charBuffer = 0;
129 if ( key ) charBuffer = key->get_object_buffer(*rfile, size);
131 if ( ! charBuffer ) {
135 <<
"Cannot get " << objectName <<
" in file " << fileName;
140 auto verbose =
false;
142 key->key_length(), verbose);
146 G4bool G4RootAnalysisReader::Reset()
150 auto finalResult =
true;
153 finalResult = finalResult &&
result;
155 result = fNtupleManager->
Reset();
156 finalResult = finalResult &&
result;
175 auto buffer = GetBuffer(fileName, h1Name,
"ReadH1Impl");
178 auto h1 = tools::rroot::TH1D_stream(*
buffer);
185 <<
"Streaming " << h1Name <<
" in file " << fileName <<
" failed.";
211 auto buffer = GetBuffer(fileName, h2Name,
"ReadH2Impl");
219 auto h2 = tools::rroot::TH2D_stream(*
buffer);
226 <<
"Streaming " << h2Name <<
" in file " << fileName <<
" failed.";
253 auto buffer = GetBuffer(fileName, h3Name,
"ReadH3Impl");
256 auto h3 = tools::rroot::TH3D_stream(*
buffer);
263 <<
"Streaming " << h3Name <<
" in file " << fileName <<
" failed.";
293 auto buffer = GetBuffer(fileName, p1Name,
"ReadP1Impl");
296 auto p1 = tools::rroot::TProfile_stream(*
buffer);
303 <<
"Streaming " << p1Name <<
" in file " << fileName <<
" failed.";
330 auto buffer = GetBuffer(fileName, p2Name,
"ReadP2Impl");
333 auto p2 = tools::rroot::TProfile2D_stream(*
buffer);
340 <<
"Streaming " << p2Name <<
" in file " << fileName <<
" failed.";
368 auto isPerThread =
true;
369 if ( isUserFileName ) isPerThread =
false;
372 auto rfile = fFileManager->
GetRFile(fileName, isPerThread);
375 rfile = fFileManager->
GetRFile(fileName, isPerThread);
378 auto key = rfile->dir().find_key(ntupleName);
383 <<
"Key " << ntupleName <<
" for Ntuple not found in file " << fileName;
384 G4Exception(
"G4RootAnalysisReader::ReadNtupleImpl()",
390 char* charBuffer = key->get_object_buffer(*rfile, size);
391 if ( ! charBuffer ) {
395 <<
"Cannot get data buffer for Ntuple " << ntupleName <<
" in file " << fileName;
396 G4Exception(
"G4RootAnalysisReader::ReadNtupleImpl()",
401 auto verbose =
false;
404 key->key_length(), verbose);
407 auto tree =
new tools::rroot::tree(*rfile, *fac);
408 if ( ! tree->stream(*
buffer) ) {
412 <<
"TTree streaming failed for Ntuple " << ntupleName <<
" in file " << fileName;
413 G4Exception(
"G4RootAnalysisReader::ReadNtupleImpl()",
422 =
new tools::rroot::ntuple(*tree);
423 auto rntupleDescription
426 auto id = fNtupleManager->
SetNtuple(rntupleDescription);
G4double G4ParticleHPJENDLHEData::G4double result
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::ostringstream G4ExceptionDescription
virtual G4int ReadNtupleImpl(const G4String &ntupleName, const G4String &fileName, G4bool isUserFileName) final
G4AnalysisManagerState fState
virtual G4int ReadH3Impl(const G4String &h3Name, const G4String &fileName, G4bool isUserFileName) final
const G4AnalysisVerbose * GetVerboseL2() const
G4int SetNtuple(G4RootRNtupleDescription *rntupleDescription)
virtual G4bool OpenRFile(const G4String &fileName, G4bool isPerThread)
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL4() const
virtual G4int ReadH2Impl(const G4String &h2Name, const G4String &fileName, G4bool isUserFileName) final
tools::rroot::file * GetRFile(const G4String &fileName, G4bool isPerThread) const
void SetNtupleManager(G4VRNtupleManager *ntupleManager)
virtual ~G4RootAnalysisReader()
virtual G4int ReadH1Impl(const G4String &h1Name, const G4String &fileName, G4bool isUserFileName) final
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static G4RootAnalysisReader * Instance()
G4bool GetIsMaster() const
virtual G4int ReadP1Impl(const G4String &p1Name, const G4String &fileName, G4bool isUserFileName) final
static const G4double fac
G4RootAnalysisReader(G4bool isMaster=true)
virtual G4int ReadP2Impl(const G4String &p2Name, const G4String &fileName, G4bool isUserFileName) final
void SetFileManager(G4BaseFileManager *fileManager)