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 // The manager for Csv output file operations.
0028 
0029 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4CsvFileManager_h
0032 #define G4CsvFileManager_h 1
0033 
0034 #include "G4VTFileManager.hh"
0035 #include "G4TNtupleDescription.hh"
0036 #include "globals.hh"
0037 
0038 #include "tools/wcsv_ntuple"
0039 
0040 #include <string_view>
0041 
0042 // Type aliases
0043 using CsvNtupleDescription = G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>;
0044 
0045 class G4CsvFileManager : public G4VTFileManager<std::ofstream>
0046 {
0047   public:
0048     explicit G4CsvFileManager(const G4AnalysisManagerState& state);
0049     G4CsvFileManager() = delete;
0050     ~G4CsvFileManager() override = default;
0051 
0052     using G4BaseFileManager::GetNtupleFileName;
0053     using G4VTFileManager<std::ofstream>::WriteFile;
0054     using G4VTFileManager<std::ofstream>::CloseFile;
0055 
0056     // Methods to manipulate output files
0057     G4bool OpenFile(const G4String& fileName) final;
0058 
0059     G4bool SetHistoDirectoryName(const G4String& dirName) final;
0060     G4bool SetNtupleDirectoryName(const G4String& dirName) final;
0061 
0062     G4String GetFileType() const final { return "csv"; }
0063 
0064     // Specific methods for files per objects
0065     G4bool NotifyNtupleFile(CsvNtupleDescription* ntupleDescription);
0066     G4bool CreateNtupleFile(CsvNtupleDescription* ntupleDescription);
0067     G4bool CloseNtupleFile(CsvNtupleDescription* ntupleDescription);
0068 
0069     G4bool IsHistoDirectory() const;
0070     G4bool IsNtupleDirectory() const;
0071 
0072   protected:
0073     // Methods derived from templated base class
0074     std::shared_ptr<std::ofstream> CreateFileImpl(const G4String& fileName) final;
0075     G4bool WriteFileImpl(std::shared_ptr<std::ofstream> file) final;
0076     G4bool CloseFileImpl(std::shared_ptr<std::ofstream> file) final;
0077 
0078   private:
0079     // Utility method
0080     G4String GetNtupleFileName(CsvNtupleDescription* ntupleDescription);
0081 
0082     // Static data members
0083     static constexpr std::string_view fkClass { "G4CsvFileManager" };
0084 
0085     // Data members
0086     G4bool fIsHistoDirectory { false };
0087     G4bool fIsNtupleDirectory { false };
0088 };
0089 
0090 // inline functions
0091 
0092 inline G4bool G4CsvFileManager::IsHistoDirectory() const
0093 { return fIsHistoDirectory; }
0094 
0095 inline G4bool G4CsvFileManager::IsNtupleDirectory() const
0096 { return fIsNtupleDirectory; }
0097 
0098 #endif