Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:03

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 Root output file operations.
0028 
0029 // Author: Ivana Hrivnacova, 18/06/2013  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4RootFileManager_h
0032 #define G4RootFileManager_h 1
0033 
0034 #include "G4VTFileManager.hh"
0035 #include "G4RootFileDef.hh"
0036 #include "G4AnalysisUtilities.hh"
0037 #include "globals.hh"
0038 
0039 #include <vector>
0040 #include <memory>
0041 #include <tuple>
0042 #include <string_view>
0043 
0044 namespace tools {
0045 namespace wroot{
0046 class ntuple;
0047 }
0048 }
0049 
0050 // Types alias
0051 using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>;
0052 
0053 class G4RootFileManager : public G4VTFileManager<G4RootFile>
0054 {
0055   public:
0056     explicit G4RootFileManager(const G4AnalysisManagerState& state);
0057     G4RootFileManager() = delete;
0058     ~G4RootFileManager() override = default;
0059 
0060     using G4BaseFileManager::GetNtupleFileName;
0061     using G4VTFileManager<G4RootFile>::WriteFile;
0062     using G4VTFileManager<G4RootFile>::CloseFile;
0063 
0064     // Methods to manipulate file from base classes
0065     G4bool OpenFile(const G4String& fileName) final;
0066 
0067     G4String GetFileType() const final { return "root"; }
0068     G4bool HasCycles() const final { return true; }
0069 
0070     // Specific methods for files per objects
0071     std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription,
0072                                   G4int mainNumber = -1);
0073     std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription,
0074                                   G4bool perThread = true,
0075                                   G4int mainNumber = -1) const;
0076     G4bool CloseNtupleFile(RootNtupleDescription* ntupleDescription,
0077                                   G4int mainNumber = -1);
0078 
0079     // Set methods
0080     void  SetBasketSize(unsigned int basketSize);
0081     void  SetBasketEntries(unsigned int basketEntries);
0082 
0083     // Get methods
0084     unsigned int GetBasketSize() const;
0085     unsigned int GetBasketEntries() const;
0086 
0087   protected:
0088     // Methods derived from templated base class
0089     std::shared_ptr<G4RootFile> CreateFileImpl(const G4String& fileName) final;
0090     G4bool WriteFileImpl(std::shared_ptr<G4RootFile> file) final;
0091     G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final;
0092 
0093   private:
0094     // Methods
0095     tools::wroot::directory* CreateDirectory(
0096                                tools::wroot::file* rfile,
0097                                const G4String& directoryName,
0098                                const G4String& objectType) const;
0099     G4String GetNtupleFileName(
0100                 RootNtupleDescription* ntupleDescription,
0101                 G4bool perThread = true,
0102                 G4int mainNumber = -1) const;
0103 
0104     // Static data members
0105     static constexpr std::string_view fkClass { "G4RootFileManager" };
0106 
0107     // Data members
0108     unsigned int fBasketSize { G4Analysis::kDefaultBasketSize };
0109     unsigned int fBasketEntries { G4Analysis::kDefaultBasketEntries };
0110 };
0111 
0112 // inline functions
0113 
0114 //_____________________________________________________________________________
0115 inline void  G4RootFileManager::SetBasketSize(unsigned int basketSize)
0116 { fBasketSize = basketSize; }
0117 
0118 //_____________________________________________________________________________
0119 inline void  G4RootFileManager::SetBasketEntries(unsigned int basketEntries)
0120 { fBasketEntries = basketEntries; }
0121 
0122 //_____________________________________________________________________________
0123 inline unsigned int G4RootFileManager::GetBasketSize() const
0124 { return fBasketSize; }
0125 
0126 //_____________________________________________________________________________
0127 inline unsigned int G4RootFileManager::GetBasketEntries() const
0128 { return fBasketEntries; }
0129 
0130 #endif
0131