2// ********************************************************************
3// * License and Disclaimer *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
27// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
29#include "G4AnalysisUtilities.hh"
31#include "tools/rcsv_histo"
33//_____________________________________________________________________________
36G4String G4CsvHnRFileManager<HT>::GetHnFileName(
37 const G4String& hnType, const G4String& hnName,
38 const G4String& fileName, G4bool isUserFileName) const
40 if ( isUserFileName ) {
41 return fRFileManager->GetFullFileName(fileName);
44 return fRFileManager->GetHnFileName(hnType, hnName);
48//_____________________________________________________________________________
51HT* G4CsvHnRFileManager<HT>::ReadT(
52 std::istream& htFile, const G4String& fileName, std::string_view inFunction)
54 tools::rcsv::histo handler(htFile);
55 std::string objectTypeInFile;
58 if ( ! handler.read(G4cout, objectTypeInFile, object, verbose) ) {
60 "Cannot get " + G4Analysis::GetHnType<HT>() + " in file " + fileName,
64 if ( objectTypeInFile.compare(HT::s_class()) != 0 ) {
66 "Object type read in " + G4Analysis::GetHnType<HT>() +" does not match",
71 return static_cast<HT*>(object);
74//_____________________________________________________________________________
77HT* G4CsvHnRFileManager<HT>::Read(
78 const G4String& htName, const G4String& fileName, const G4String& dirName,
79 G4bool isUserFileName)
83 GetHnFileName(G4Analysis::GetHnType<HT>(), htName, fileName, isUserFileName);
85 // Update directory path
86 if ( ! dirName.empty() ) {
87 htFileName = "./" + dirName + "/" + htFileName;
90 std::ifstream htFile(htFileName);
91 if ( ! htFile.is_open() ) {
92 G4Analysis::Warn("Cannot open file " + htFileName, fkClass, "Read");
96 auto ht = ReadT(htFile, htFileName, "Read");