38 #include <tools/aida_ntuple>
39 #include <tools/rcsv_histo>
56 void* ReadObject(std::istream& hnFile,
61 tools::rcsv::histo handler(hnFile);
62 std::string objectTypeInFile;
65 if ( ! handler.read(
G4cout, objectTypeInFile,
object, verbose) ) {
69 <<
"Cannot get "<< objectType <<
" in file " << fileName;
70 G4String inFunctionFull =
"G4CsvAnalysisReader::";
71 inFunctionFull.
append(inFunction);
75 if ( objectTypeInFile != objectType ) {
79 <<
"Object type read in "<< fileName
80 <<
" does not match" <<
G4endl;
81 G4String inFunctionFull =
"G4CsvAnalysisReader::";
82 inFunctionFull.
append(inFunction);
95 if ( fgInstance ==
nullptr ) {
106 fNtupleManager(nullptr),
107 fFileManager(nullptr)
113 <<
"G4CsvAnalysisReader already exists."
114 <<
"Cannot create another instance.";
115 G4Exception(
"G4CsvAnalysisReader::G4CsvAnalysisReader()",
147 G4bool isUserFileName)
const
149 if ( isUserFileName ) {
162 auto finalResult =
true;
165 finalResult = finalResult && result;
168 finalResult = finalResult && result;
188 auto h1FileName =
GetHnFileName(
"h1", h1Name, fileName, isUserFileName);
189 std::ifstream hnFile(h1FileName);
190 if ( ! hnFile.is_open() ) {
192 description <<
" " <<
"Cannot open file " << h1FileName;
200 ->
Message(
"open",
"read file", h1FileName);
204 = ReadObject(hnFile, tools::histo::h1d::s_class(), h1FileName,
"ReadH1Impl");
207 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);
270 auto h3FileName =
GetHnFileName(
"h3", h3Name, fileName, isUserFileName);
271 std::ifstream hnFile(h3FileName);
272 if ( ! hnFile.is_open() ) {
274 description <<
" " <<
"Cannot open file " << h3FileName;
282 ->
Message(
"open",
"read file", h3FileName);
286 = ReadObject(hnFile, tools::histo::h3d::s_class(), h3FileName,
"ReadH3Impl");
289 auto h3 =
static_cast<tools::histo::h3d*
>(object);
312 std::ifstream hnFile(p1FileName);
313 if ( ! hnFile.is_open() ) {
315 description <<
" " <<
"Cannot open file " << p1FileName;
323 ->
Message(
"open",
"read file", p1FileName);
327 = ReadObject(hnFile, tools::histo::p1d::s_class(), fileName,
"ReadP1Impl");
330 auto p1 =
static_cast<tools::histo::p1d*
>(object);
353 std::ifstream hnFile(p2FileName);
354 if ( ! hnFile.is_open() ) {
356 description <<
" " <<
"Cannot open file " << p2FileName;
364 ->
Message(
"open",
"read file", p2FileName);
368 = ReadObject(hnFile, tools::histo::p2d::s_class(), p2FileName,
"ReadP2Impl");
371 auto p2 =
static_cast<tools::histo::p2d*
>(object);
397 if ( ! isUserFileName ) {
406 auto rntuple =
new tools::rcsv::ntuple(*ntupleFile);
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
virtual G4int ReadNtupleImpl(const G4String &ntupleName, const G4String &fileName, G4bool isUserFileName) final
std::ostringstream G4ExceptionDescription
G4String GetNtupleFileName(const G4String &ntupleName) const
static G4CsvAnalysisReader * Instance()
virtual G4int ReadH3Impl(const G4String &h3Name, const G4String &fileName, G4bool isUserFileName) final
virtual G4int ReadP2Impl(const G4String &p2Name, const G4String &fileName, G4bool isUserFileName) final
virtual ~G4CsvAnalysisReader()
G4AnalysisManagerState fState
G4String GetHnFileName(const G4String &hnType, const G4String &hnName) const
const G4AnalysisVerbose * GetVerboseL2() const
virtual G4int ReadH2Impl(const G4String &h2Name, const G4String &fileName, G4bool isUserFileName) final
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL4() const
std::ifstream * GetRFile(const G4String &fileName) const
G4CsvRFileManager * fFileManager
static G4ThreadLocal G4CsvAnalysisReader * fgInstance
void SetNtupleManager(G4VRNtupleManager *ntupleManager)
virtual G4int ReadH1Impl(const G4String &h1Name, const G4String &fileName, G4bool isUserFileName) final
G4String GetHnFileName(const G4String &hnType, const G4String &hnName, const G4String &baseFileName, G4bool isUserFileName) const
G4int SetNtuple(G4CsvRNtupleDescription *rntupleDescription)
G4CsvRNtupleManager * fNtupleManager
static G4CsvAnalysisReader * fgMasterInstance
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4CsvAnalysisReader(G4bool isMaster=true)
G4String & append(const G4String &)
G4bool GetIsMaster() const
virtual G4int ReadP1Impl(const G4String &p1Name, const G4String &fileName, G4bool isUserFileName) final
virtual G4bool OpenRFile(const G4String &fileName)
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisVerbose * GetVerboseL1() const
void SetFileManager(G4BaseFileManager *fileManager)