Back to home page

EIC code displayed by LXR

 
 

    


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

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 // Manager class for ntuple booking for all output types.
0028 //
0029 // Author: Ivana Hrivnacova, 19/06/2015  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4NtupleBookingManager_h
0032 #define G4NtupleBookingManager_h 1
0033 
0034 #include "G4BaseAnalysisManager.hh"
0035 #include "G4AnalysisUtilities.hh"
0036 #include "globals.hh"
0037 
0038 #include "tools/ntuple_booking"
0039 
0040 #include <set>
0041 #include <string_view>
0042 #include <vector>
0043 
0044 struct G4NtupleBooking
0045 {
0046   G4NtupleBooking() = default;
0047   ~G4NtupleBooking() = default;
0048 
0049   void SetDeleted(G4bool deleted, G4bool keepSetting) {
0050     fDeleted = std::make_pair(deleted, keepSetting);
0051   }
0052   G4bool GetDeleted() const {
0053     return fDeleted.first;
0054   }
0055   void Reset() {
0056     if (! fDeleted.second) {
0057       // Reset information unless "keepSetting" option is true
0058       fFileName.clear();
0059       fActivation = true;
0060     }
0061     SetDeleted(false, false);
0062   }
0063 
0064   tools::ntuple_booking fNtupleBooking;
0065   G4int fNtupleId { G4Analysis::kInvalidId };
0066   G4String fFileName;
0067   G4bool fActivation { true };
0068   std::pair<G4bool, G4bool> fDeleted { false, false };
0069 };
0070 
0071 class G4NtupleBookingManager : public G4BaseAnalysisManager
0072 {
0073   // Disable using the object managers outside G4VAnalysisManager and
0074   // its messenger
0075   friend class G4VAnalysisManager;
0076 
0077   public:
0078     explicit G4NtupleBookingManager(const G4AnalysisManagerState& state);
0079     G4NtupleBookingManager() = delete;
0080     ~G4NtupleBookingManager() override;
0081 
0082     const std::vector<G4NtupleBooking*>& GetNtupleBookingVector() const;
0083 
0084     // File type
0085     // (only one output file type allowed for ntuples)
0086     void SetFileType(const G4String& fileType);
0087     G4String GetFileType() const;
0088     G4bool IsEmpty() const;
0089 
0090     // Access methods
0091     tools::ntuple_booking* GetNtuple(G4bool warn,
0092                              G4bool onlyIfActive) const;
0093     tools::ntuple_booking* GetNtuple(G4int ntupleId, G4bool warn,
0094                               G4bool onlyIfActive) const;
0095 
0096   protected:
0097     // Methods to create ntuples
0098     //
0099     G4int CreateNtuple(const G4String& name, const G4String& title);
0100 
0101     // Create columns in the last created ntuple (from base class)
0102     // Create columns in the last created ntuple
0103     G4int CreateNtupleIColumn(const G4String& name,
0104                               std::vector<int>* vector);
0105     G4int CreateNtupleFColumn(const G4String& name,
0106                               std::vector<float>* vector) ;
0107     G4int CreateNtupleDColumn(const G4String& name,
0108                               std::vector<double>* vector);
0109     G4int CreateNtupleSColumn(const G4String& name,
0110                               std::vector<std::string>* vector);
0111     G4NtupleBooking*  FinishNtuple() ;
0112 
0113     // Create columns in the ntuple with given id
0114     G4int CreateNtupleIColumn(G4int ntupleId,
0115                     const G4String& name, std::vector<int>* vector);
0116     G4int CreateNtupleFColumn(G4int ntupleId,
0117                     const G4String& name, std::vector<float>* vector);
0118     G4int CreateNtupleDColumn(G4int ntupleId,
0119                     const G4String& name, std::vector<double>* vector);
0120     G4int CreateNtupleSColumn(G4int ntupleId,
0121                     const G4String& name, std::vector<std::string>* vector);
0122     G4NtupleBooking*  FinishNtuple(G4int ntupleId);
0123 
0124     // The ntuple column ids are generated automatically starting from 0;
0125     // with the following function it is possible to change it
0126     // to start from another value
0127     G4bool SetFirstNtupleColumnId(G4int firstId);
0128     G4int  GetFirstNtupleColumnId() const;
0129 
0130     // Activation option
0131     //
0132     void  SetActivation(G4bool activation);
0133     void  SetActivation(G4int ntupleId, G4bool activation);
0134     G4bool  GetActivation(G4int ntupleId) const;
0135 
0136     // // File name option
0137     void  SetFileName(const G4String& fileName);
0138     void  SetFileName(G4int id, const G4String& fileName);
0139     G4String GetFileName(G4int id) const;
0140 
0141     // Access methods
0142     G4int GetNofNtuples(G4bool onlyIfExist = false) const;
0143 
0144     // Clear data
0145     void ClearData();
0146 
0147     // Method to delete selected ntuples
0148     G4bool Delete(G4int id, G4bool keepSetting);
0149 
0150     // List ntuples
0151     G4bool List(std::ostream& output, G4bool onlyIfActive = true);
0152 
0153     // Data members
0154     std::vector<G4NtupleBooking*> fNtupleBookingVector;
0155     std::set<G4int> fFreeIds;
0156 
0157   private:
0158     // Methods
0159     // Common implementation
0160     G4NtupleBooking*  GetNtupleBookingInFunction(
0161                                         G4int id,
0162                                         std::string_view function,
0163                                         G4bool warn = true) const;
0164 
0165     G4bool CheckName(const G4String& name, const G4String& objectType) const;
0166     template <typename T>
0167     G4int CreateNtupleTColumn(G4int ntupleId,
0168                     const G4String& name, std::vector<T>* vector);
0169     G4int GetCurrentNtupleId() const;
0170 
0171     // Static data members
0172     static constexpr std::string_view fkClass { "G4NtupleBookingManager" };
0173 
0174     // Data members
0175     G4String fFileType;
0176     G4int    fFirstNtupleColumnId { 0 };
0177     G4bool   fLockFirstNtupleColumnId { false };
0178     G4int    fCurrentNtupleId { G4Analysis::kInvalidId };
0179 };
0180 
0181 #include "G4NtupleBookingManager.icc"
0182 
0183 #endif