36 #include <tools/aida_ntuple>
37 #include <tools/rcsv_histo>
42 using namespace G4Analysis;
54 void* 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)
111 <<
"G4CsvAnalysisReader already exists."
112 <<
"Cannot create another instance.";
113 G4Exception(
"G4CsvAnalysisReader::G4CsvAnalysisReader()",
145 G4bool isUserFileName)
const
147 if ( isUserFileName ) {
160 auto finalResult =
true;
163 finalResult = finalResult && result;
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");
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);
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);
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 ) {