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 // Class for Root pntuple management.
0028 //
0029 // Author: Ivana Hrivnacova, 04/10/2016  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4RootPNtupleManager_h
0032 #define G4RootPNtupleManager_h 1
0033 
0034 #include "G4BaseNtupleManager.hh"
0035 #include "G4RootMainNtupleManager.hh"
0036 #include "G4RootPNtupleDescription.hh"
0037 #include "G4AnalysisManagerState.hh"
0038 #include "G4AnalysisUtilities.hh"
0039 #include "G4AutoLock.hh"
0040 #include "globals.hh"
0041 
0042 #include <vector>
0043 #include <string_view>
0044 
0045 class G4RootMainNtupleManager;
0046 
0047 namespace tools {
0048 namespace wroot {
0049 class file;
0050 class ntuple;
0051 class imt_ntuple;
0052 }
0053 }
0054 
0055 // Mutex implementation as in pwroot.cpp
0056 // with replacement tools::mutex -> G4Mutex
0057 
0058 class mutex : public virtual tools::wroot::imutex {
0059   using parent = tools::wroot::imutex;
0060 public:
0061   bool lock() override
0062   {
0063     // G4cout << "!!! Mutex lock" << G4endl;
0064     m_mutex.lock();
0065     return true;
0066   }
0067   bool unlock() override
0068   {
0069     m_mutex.unlock();
0070     // G4cout << "!!! Mutex unlock" << G4endl;
0071     return true;
0072   }
0073   //virtual bool trylock() {return m_mutex.trylock();}
0074 public:
0075   mutex(G4AutoLock& a_mutex):m_mutex(a_mutex){}
0076   ~mutex() override = default;
0077 
0078 protected:
0079   mutex(const mutex& a_from) = default;
0080   mutex& operator=(const mutex&){return *this;}
0081 protected:
0082   G4AutoLock& m_mutex;
0083 };
0084 
0085 class G4RootPNtupleManager : public G4BaseNtupleManager
0086 {
0087   friend class G4RootAnalysisManager;
0088   friend class G4RootNtupleFileManager;
0089 
0090   public:
0091     G4RootPNtupleManager(const G4AnalysisManagerState& state,
0092                          std::shared_ptr<G4NtupleBookingManager> bookingManger,
0093                          std::shared_ptr<G4RootMainNtupleManager> main,
0094                          G4bool rowWise, G4bool rowMode);
0095     G4RootPNtupleManager() = delete;
0096     ~G4RootPNtupleManager() override;
0097 
0098   private:
0099     // Methods to manipulate ntuples
0100     void CreateNtupleFromMain(G4RootPNtupleDescription* ntupleDescription,
0101                               tools::wroot::ntuple* mainNtuple);
0102     void CreateNtupleDescriptionsFromBooking();
0103     void CreateNtuplesFromMain();
0104     void CreateNtuplesIfNeeded();
0105 
0106     // Methods to create ntuples
0107     //
0108     G4int CreateNtuple(G4NtupleBooking* booking) final;
0109 
0110     // Methods to fill ntuples
0111     // Methods for ntuple with id = FirstNtupleId (from base class)
0112     using G4BaseNtupleManager::FillNtupleIColumn;
0113     using G4BaseNtupleManager::FillNtupleFColumn;
0114     using G4BaseNtupleManager::FillNtupleDColumn;
0115     using G4BaseNtupleManager::FillNtupleSColumn;
0116     using G4BaseNtupleManager::AddNtupleRow;
0117     // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
0118     G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
0119     G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
0120     G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
0121     G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId, const G4String& value) final;
0122     G4bool AddNtupleRow(G4int ntupleId) final;
0123     virtual G4bool Merge() final;
0124 
0125     virtual G4bool Reset();
0126     void Clear() final;
0127 
0128     // Method to delete selected ntuple
0129     G4bool Delete(G4int id) final;
0130 
0131     // Activation option
0132     //
0133     void SetActivation(G4bool activation) final;
0134     void SetActivation(G4int ntupleId, G4bool activation) final;
0135     G4bool GetActivation(G4int ntupleId) const final;
0136 
0137     // New cycle option
0138     void SetNewCycle(G4bool value) final;
0139     G4bool GetNewCycle() const final;
0140 
0141     // Set methods
0142     void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
0143 
0144   private:
0145     G4RootPNtupleDescription*
0146       GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn = true) const;
0147     tools::wroot::base_pntuple*
0148       GetNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
0149     tools::wroot::ntuple*
0150       GetMainNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
0151 
0152     template <typename T>
0153     G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
0154 
0155     template <typename T>
0156     G4bool FillNtupleTColumn(G4int columnId, const T& value);
0157 
0158     // Static data members
0159     static constexpr std::string_view fkClass { "G4RootPNtupleManager" };
0160 
0161     // Data members
0162     std::shared_ptr<G4NtupleBookingManager> fBookingManager;
0163     std::shared_ptr<G4RootMainNtupleManager>  fMainNtupleManager;
0164     std::vector<G4RootPNtupleDescription*> fNtupleDescriptionVector;
0165     std::vector<tools::wroot::imt_ntuple*> fNtupleVector;
0166     G4bool fRowWise;
0167     G4bool fRowMode;
0168     G4bool fCreateNtuples { true };
0169     G4bool fNewCycle { false };
0170 };
0171 
0172 #include "G4RootPNtupleManager.icc"
0173 
0174 #endif