Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:05

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
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   // Get file name
0080   auto htFileName =
0081     GetHnFileName(G4Analysis::GetHnType<HT>(), htName, fileName, isUserFileName);
0082 
0083   // Update directory path
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 }