Back to home page

EIC code displayed by LXR

 
 

    


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

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 // Class template for ntuple managers for all output types.
0028 //
0029 // Author: Ivana Hrivnacova, 19/06/2015  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4TNtupleManager_h
0032 #define G4TNtupleManager_h 1
0033 
0034 #include "G4BaseNtupleManager.hh"
0035 #include "G4TNtupleDescription.hh"
0036 #include "globals.hh"
0037 
0038 #include <vector>
0039 #include <string_view>
0040 
0041 // NT - ntuple type, FT - file type
0042 template <typename NT, typename FT>
0043 class G4TNtupleManager : public G4BaseNtupleManager {
0044 
0045   public:
0046     explicit G4TNtupleManager(const G4AnalysisManagerState& state);
0047     G4TNtupleManager() = delete;
0048     ~G4TNtupleManager() override;
0049 
0050   protected:
0051     // Methods to manipulate ntuples
0052     G4int CreateNtuple(G4NtupleBooking* ntupleBooking) override;
0053 
0054     virtual void CreateNtuplesFromBooking(
0055                    const std::vector<G4NtupleBooking*>& ntupleBookings);
0056 
0057     virtual G4bool Reset();
0058     void Clear() override;
0059 
0060     // Method to delete selected ntuple
0061     G4bool Delete(G4int id) override;
0062 
0063     // Methods to create ntuples
0064     // are implemented in G4NtupleBookingManager base class
0065 
0066     // Methods to fill ntuples
0067     // Methods for ntuple with id = FirstNtupleId (from base class)
0068     using G4BaseNtupleManager::FillNtupleIColumn;
0069     using G4BaseNtupleManager::FillNtupleFColumn;
0070     using G4BaseNtupleManager::FillNtupleDColumn;
0071     using G4BaseNtupleManager::FillNtupleSColumn;
0072     using G4BaseNtupleManager::AddNtupleRow;
0073     // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
0074     G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
0075     G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
0076     G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
0077     G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId, const G4String& value) final;
0078     G4bool AddNtupleRow(G4int ntupleId) override;
0079 
0080     // Activation option
0081     //
0082     void SetActivation(G4bool activation) final;
0083     void SetActivation(G4int ntupleId, G4bool activation) final;
0084     G4bool GetActivation(G4int ntupleId) const final;
0085 
0086     // New cycle option
0087     void SetNewCycle(G4bool value) override;
0088     G4bool GetNewCycle() const override;
0089 
0090     // Access methods
0091     NT* GetNtuple() const;
0092     NT* GetNtuple(G4int ntupleId) const;
0093 
0094     // Iterators
0095     typename std::vector<NT*>::iterator BeginNtuple();
0096     typename std::vector<NT*>::iterator EndNtuple();
0097     typename std::vector<NT*>::const_iterator BeginConstNtuple() const;
0098     typename std::vector<NT*>::const_iterator EndConstNtuple() const;
0099 
0100     // Data members
0101     std::vector<G4TNtupleDescription<NT, FT>*> fNtupleDescriptionVector;
0102     std::vector<NT*> fNtupleVector;
0103     const std::vector<G4NtupleBooking*>* fNtupleBookingVector { nullptr };
0104     G4bool fNewCycle { false };
0105 
0106   private:
0107     // Methods
0108 
0109     // Fuctions which are specific to output type
0110     //
0111     virtual void CreateTNtupleFromBooking(
0112                     G4TNtupleDescription<NT, FT>* ntupleDescription) = 0;
0113 
0114     virtual void FinishTNtuple(
0115                     G4TNtupleDescription<NT, FT>* ntupleDescription,
0116                     G4bool fromBooking) = 0;
0117 
0118     // Common implementation
0119     //
0120 
0121     G4TNtupleDescription<NT, FT>*  GetNtupleDescriptionInFunction(G4int id,
0122                                         std::string_view function,
0123                                         G4bool warn = true) const;
0124     NT*  GetNtupleInFunction(G4int id,
0125                              std::string_view function,
0126                              G4bool warn = true) const;
0127 
0128     // template functions for filling ntuple columns
0129     template <typename T>
0130     G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
0131 
0132     // Static data members
0133     static constexpr std::string_view fkClass { "G4TNtupleManager<NT,FT>" };
0134 };
0135 
0136 #include "G4TNtupleManager.icc"
0137 
0138 #endif
0139