36#include <tools/rroot/file>
37#include <tools/rroot/streamers>
38#include <tools/rroot/fac>
39#include <tools/rroot/tree>
40#include <tools/rroot/ntuple>
53 if ( fgInstance ==
nullptr ) {
64 fNtupleManager(nullptr),
67 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
71 <<
"G4RootAnalysisReader already exists."
72 <<
"Cannot create another instance.";
73 G4Exception(
"G4RootAnalysisReader::G4RootAnalysisReader()",
76 if ( isMaster ) fgMasterInstance =
this;
101tools::rroot::buffer* G4RootAnalysisReader::GetBuffer(
111 G4bool isPerThread =
false;
114 auto rfile = fFileManager->
GetRFile(fileName, isPerThread);
116 if ( ! fFileManager->
OpenRFile(fileName, isPerThread) )
return nullptr;
117 rfile = fFileManager->
GetRFile(fileName, isPerThread);
121 = ( ! rfile ) ?
nullptr : rfile->dir().find_key(objectName);
126 char* charBuffer = 0;
127 if ( key ) charBuffer = key->get_object_buffer(*rfile, size);
129 if ( ! charBuffer ) {
133 <<
"Cannot get " << objectName <<
" in file " << fileName;
138 auto verbose =
false;
139 return new tools::rroot::buffer(
G4cout, rfile->byte_swap(), size, charBuffer,
140 key->key_length(), verbose);
144G4bool G4RootAnalysisReader::Reset()
148 auto finalResult =
true;
151 finalResult = finalResult && result;
153 result = fNtupleManager->
Reset();
154 finalResult = finalResult && result;
174 auto buffer = GetBuffer(fileName, h1Name,
"ReadH1Impl");
177 auto h1 = tools::rroot::TH1D_stream(*
buffer);
184 <<
"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.";
254 auto buffer = GetBuffer(fileName, h3Name,
"ReadH3Impl");
257 auto h3 = tools::rroot::TH3D_stream(*
buffer);
264 <<
"Streaming " << h3Name <<
" in file " << fileName <<
" failed.";
295 auto buffer = GetBuffer(fileName, p1Name,
"ReadP1Impl");
298 auto p1 = tools::rroot::TProfile_stream(*
buffer);
305 <<
"Streaming " << p1Name <<
" in file " << fileName <<
" failed.";
333 auto buffer = GetBuffer(fileName, p2Name,
"ReadP2Impl");
336 auto p2 = tools::rroot::TProfile2D_stream(*
buffer);
343 <<
"Streaming " << p2Name <<
" in file " << fileName <<
" failed.";
372 auto isPerThread =
true;
373 if ( isUserFileName ) isPerThread =
false;
376 auto rfile = fFileManager->
GetRFile(fileName, isPerThread);
379 rfile = fFileManager->
GetRFile(fileName, isPerThread);
382 auto key = rfile->dir().find_key(ntupleName);
387 <<
"Key " << ntupleName <<
" for Ntuple not found in file " << fileName;
388 G4Exception(
"G4RootAnalysisReader::ReadNtupleImpl()",
394 char* charBuffer = key->get_object_buffer(*rfile, size);
395 if ( ! charBuffer ) {
399 <<
"Cannot get data buffer for Ntuple " << ntupleName <<
" in file " << fileName;
400 G4Exception(
"G4RootAnalysisReader::ReadNtupleImpl()",
405 auto verbose =
false;
407 =
new tools::rroot::buffer(
G4cout, rfile->byte_swap(), size, charBuffer,
408 key->key_length(), verbose);
409 buffer->set_map_objs(
true);
411 auto fac =
new tools::rroot::fac(
G4cout);
413 auto tree =
new tools::rroot::tree(*rfile, *fac);
414 if ( ! tree->stream(*
buffer) ) {
418 <<
"TTree streaming failed for Ntuple " << ntupleName <<
" in file " << fileName;
419 G4Exception(
"G4RootAnalysisReader::ReadNtupleImpl()",
427 auto rntuple =
new tools::rroot::ntuple(*tree);
430 auto id = fNtupleManager->
SetNtuple(rntupleDescription);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL2() const
G4bool GetIsMaster() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
virtual G4int ReadNtupleImpl(const G4String &ntupleName, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual G4int ReadP1Impl(const G4String &p1Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
static G4RootAnalysisReader * Instance()
virtual G4int ReadH1Impl(const G4String &h1Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual G4int ReadH3Impl(const G4String &h3Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual G4int ReadP2Impl(const G4String &p2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual ~G4RootAnalysisReader()
G4RootAnalysisReader(G4bool isMaster=true)
virtual G4int ReadH2Impl(const G4String &h2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual G4bool OpenRFile(const G4String &fileName, G4bool isPerThread)
tools::rroot::file * GetRFile(const G4String &fileName, G4bool isPerThread) const
G4int SetNtuple(G4TRNtupleDescription< TNTUPLE > *rntupleDescription)
void SetFileManager(G4BaseFileManager *fileManager)
void SetNtupleManager(G4VRNtupleManager *ntupleManager)
G4AnalysisManagerState fState