36#include <tools/aida_ntuple>
37#include <tools/rcsv_histo>
54void* ReadObject(std::istream& hnFile,
59 tools::rcsv::histo handler(hnFile);
60 std::string objectTypeInFile;
63 if ( ! handler.read(
G4cout, objectTypeInFile,
object, verbose) ) {
67 <<
"Cannot get "<< objectType <<
" in file " << fileName;
68 G4String inFunctionFull =
"G4CsvAnalysisReader::";
69 inFunctionFull.
append(inFunction);
73 if ( objectTypeInFile != objectType ) {
77 <<
"Object type read in "<< fileName
78 <<
" does not match" <<
G4endl;
79 G4String inFunctionFull =
"G4CsvAnalysisReader::";
80 inFunctionFull.
append(inFunction);
93 if ( fgInstance ==
nullptr ) {
104 fNtupleManager(nullptr),
105 fFileManager(nullptr)
107 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
111 <<
"G4CsvAnalysisReader already exists."
112 <<
"Cannot create another instance.";
113 G4Exception(
"G4CsvAnalysisReader::G4CsvAnalysisReader()",
116 if ( isMaster ) fgMasterInstance =
this;
133 fgInstance =
nullptr;
141G4String G4CsvAnalysisReader::GetHnFileName(
145 G4bool isUserFileName)
const
147 if ( isUserFileName ) {
156G4bool G4CsvAnalysisReader::Reset()
160 auto finalResult =
true;
163 finalResult = finalResult && result;
165 result = fNtupleManager->
Reset();
166 finalResult = finalResult && result;
187 auto h1FileName = GetHnFileName(
"h1", h1Name, fileName, isUserFileName);
188 std::ifstream hnFile(h1FileName);
189 if ( ! hnFile.is_open() ) {
191 description <<
" " <<
"Cannot open file " << h1FileName;
199 ->
Message(
"open",
"read file", h1FileName);
203 = ReadObject(hnFile, tools::histo::h1d::s_class(), h1FileName,
"ReadH1Impl");
206 auto h1 =
static_cast<tools::histo::h1d*
>(object);
229 auto h2FileName = GetHnFileName(
"h2", h2Name, fileName, isUserFileName);
230 std::ifstream hnFile(h2FileName);
231 if ( ! hnFile.is_open() ) {
233 description <<
" " <<
"Cannot open file " << h2FileName;
241 ->
Message(
"open",
"read file", h2FileName);
245 = ReadObject(hnFile, tools::histo::h2d::s_class(), h2FileName,
"ReadH2Impl");
248 auto h2 =
static_cast<tools::histo::h2d*
>(object);
271 auto h3FileName = GetHnFileName(
"h3", h3Name, fileName, isUserFileName);
272 std::ifstream hnFile(h3FileName);
273 if ( ! hnFile.is_open() ) {
275 description <<
" " <<
"Cannot open file " << h3FileName;
283 ->
Message(
"open",
"read file", h3FileName);
287 = ReadObject(hnFile, tools::histo::h3d::s_class(), h3FileName,
"ReadH3Impl");
290 auto h3 =
static_cast<tools::histo::h3d*
>(object);
313 G4String p1FileName = GetHnFileName(
"p1", p1Name, fileName, isUserFileName);
314 std::ifstream hnFile(p1FileName);
315 if ( ! hnFile.is_open() ) {
317 description <<
" " <<
"Cannot open file " << p1FileName;
325 ->
Message(
"open",
"read file", p1FileName);
329 = ReadObject(hnFile, tools::histo::p1d::s_class(), fileName,
"ReadP1Impl");
332 auto p1 =
static_cast<tools::histo::p1d*
>(object);
355 G4String p2FileName = GetHnFileName(
"p2", p2Name, fileName, isUserFileName);
356 std::ifstream hnFile(p2FileName);
357 if ( ! hnFile.is_open() ) {
359 description <<
" " <<
"Cannot open file " << p2FileName;
367 ->
Message(
"open",
"read file", p2FileName);
371 = ReadObject(hnFile, tools::histo::p2d::s_class(), p2FileName,
"ReadP2Impl");
374 auto p2 =
static_cast<tools::histo::p2d*
>(object);
401 if ( ! isUserFileName ) {
407 auto ntupleFile = fFileManager->
GetRFile(fullFileName);
410 auto rntuple =
new tools::rcsv::ntuple(*ntupleFile);
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
const G4AnalysisVerbose * GetVerboseL1() const
G4bool GetIsMaster() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
G4String GetHnFileName(const G4String &hnType, const G4String &hnName) const
G4String GetNtupleFileName(const G4String &ntupleName) const
virtual G4int ReadNtupleImpl(const G4String &ntupleName, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
G4CsvAnalysisReader(G4bool isMaster=true)
static G4CsvAnalysisReader * Instance()
virtual G4int ReadP1Impl(const G4String &p1Name, 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 ReadH1Impl(const G4String &h1Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual G4int ReadH2Impl(const G4String &h2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
virtual ~G4CsvAnalysisReader()
virtual G4int ReadP2Impl(const G4String &p2Name, const G4String &fileName, const G4String &dirName, G4bool isUserFileName) final
std::ifstream * GetRFile(const G4String &fileName) const
virtual G4bool OpenRFile(const G4String &fileName)
G4String & append(const G4String &)
G4int SetNtuple(G4TRNtupleDescription< TNTUPLE > *rntupleDescription)
void SetFileManager(G4BaseFileManager *fileManager)
void SetNtupleManager(G4VRNtupleManager *ntupleManager)
G4AnalysisManagerState fState