File indexing completed on 2025-01-18 09:58:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "G4AnalysisUtilities.hh"
0030
0031 #include "tools/rcsv_histo"
0032
0033
0034 template <typename HT>
0035 inline
0036 G4String G4CsvHnRFileManager<HT>::GetHnFileName(
0037 const G4String& hnType, const G4String& hnName,
0038 const G4String& fileName, G4bool isUserFileName) const
0039 {
0040 if ( isUserFileName ) {
0041 return fRFileManager->GetFullFileName(fileName);
0042 }
0043 return fRFileManager->GetHnFileName(hnType, hnName);
0044 }
0045
0046
0047 template <typename HT>
0048 inline
0049 HT* G4CsvHnRFileManager<HT>::ReadT(
0050 std::istream& htFile, const G4String& fileName, std::string_view inFunction)
0051 {
0052 tools::rcsv::histo handler(htFile);
0053 std::string objectTypeInFile;
0054 void* object;
0055 auto verbose = false;
0056 if ( ! handler.read(G4cout, objectTypeInFile, object, verbose) ) {
0057 G4Analysis::Warn(
0058 "Cannot get " + G4Analysis::GetHnType<HT>() + " in file " + fileName,
0059 fkClass, inFunction);
0060 return nullptr;
0061 }
0062 if (objectTypeInFile != HT::s_class()) {
0063 G4Analysis::Warn(
0064 "Object type read in " + G4Analysis::GetHnType<HT>() +" does not match",
0065 fkClass, inFunction);
0066 return nullptr;
0067 }
0068
0069 return static_cast<HT*>(object);
0070 }
0071
0072
0073 template <typename HT>
0074 inline
0075 HT* G4CsvHnRFileManager<HT>::Read(
0076 const G4String& htName, const G4String& fileName, const G4String& dirName,
0077 G4bool isUserFileName)
0078 {
0079
0080 auto htFileName =
0081 GetHnFileName(G4Analysis::GetHnType<HT>(), htName, fileName, isUserFileName);
0082
0083
0084 if ( ! dirName.empty() ) {
0085 htFileName = "./" + dirName + "/" + htFileName;
0086 }
0087
0088 std::ifstream htFile(htFileName);
0089 if ( ! htFile.is_open() ) {
0090 G4Analysis::Warn("Cannot open file " + htFileName, fkClass, "Read");
0091 return nullptr;
0092 }
0093
0094 auto ht = ReadT(htFile, htFileName, "Read");
0095 return ht;
0096 }