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 main ntuple management.
0028 //
0029 // Author: Ivana Hrivnacova, 04/10/2016  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4RootMainNtupleManager_h
0032 #define G4RootMainNtupleManager_h 1
0033 
0034 #include "G4BaseAnalysisManager.hh"
0035 #include "G4NtupleBookingManager.hh"
0036 #include "G4RootFileDef.hh"
0037 #include "G4RootNtupleManager.hh"
0038 #include "G4TNtupleDescription.hh"
0039 #include "globals.hh"
0040 
0041 #include <string_view>
0042 #include <utility>
0043 #include <vector>
0044 
0045 class G4RootFileManager;
0046 class G4RootNtupleManager;
0047 class G4NtupleBookingManager;
0048 
0049 namespace tools {
0050 namespace wroot {
0051 class ntuple;
0052 }
0053 }
0054 
0055 // Types alias
0056 using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>;
0057 using RootMainNtupleDescription = std::pair<RootNtupleDescription*, std::shared_ptr<G4RootFile>>;
0058 
0059 class G4RootMainNtupleManager : public G4BaseAnalysisManager
0060 {
0061   friend class G4RootPNtupleManager;
0062   friend class G4RootNtupleManager;
0063 
0064   public:
0065     G4RootMainNtupleManager(
0066                G4RootNtupleManager* ntupleBuilder,
0067                std::shared_ptr<G4NtupleBookingManager> bookingManager,
0068                G4bool rowWise, G4int fileNumber,
0069                const G4AnalysisManagerState& state);
0070     G4RootMainNtupleManager() = delete;
0071     ~G4RootMainNtupleManager() override = default;
0072 
0073     void CreateNtuplesFromBooking();
0074 
0075   protected:
0076     // Methods to manipulate ntuples
0077     void   CreateNtuple(RootNtupleDescription* ntupleDescription, G4bool warn = true);
0078     G4bool Delete(G4int id);
0079     G4bool Merge();
0080     G4bool Reset();
0081     void ClearData();
0082 
0083     // Set/get methods
0084     void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
0085     void SetRowWise(G4bool rowWise);
0086     std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription) const;
0087 
0088     // New cycle option
0089     void SetNewCycle(G4bool value);
0090     G4bool GetNewCycle() const;
0091 
0092     // Access functions
0093     const std::vector<tools::wroot::ntuple*>& GetNtupleVector()
0094       { return fNtupleVector; }
0095     unsigned int GetBasketEntries() const;
0096 
0097   private:
0098     // Static data members
0099     static constexpr std::string_view fkClass { "G4RootMainNtupleManager" };
0100 
0101     // Methods
0102     G4int CreateNtupleFromBooking(G4NtupleBooking* ntupleBooking,
0103             std::shared_ptr<G4RootFile> ntupleFile);
0104 
0105     // Data members
0106     G4RootNtupleManager* fNtupleBuilder { nullptr };
0107     std::shared_ptr<G4NtupleBookingManager> fBookingManager { nullptr };
0108     std::shared_ptr<G4RootFileManager> fFileManager { nullptr };
0109     G4bool  fRowWise;
0110     G4int  fFileNumber;
0111     std::vector<tools::wroot::ntuple*>  fNtupleVector;
0112     std::vector<RootMainNtupleDescription> fNtupleDescriptionVector;
0113     G4bool fNewCycle { false };
0114 };
0115 
0116 inline void  G4RootMainNtupleManager::SetFileManager(
0117   std::shared_ptr<G4RootFileManager> fileManager)
0118 {
0119   fFileManager = std::move(fileManager);
0120 }
0121 
0122 inline void G4RootMainNtupleManager::SetRowWise(G4bool rowWise)
0123 { fRowWise = rowWise; }
0124 
0125 inline unsigned int G4RootMainNtupleManager::GetBasketEntries() const
0126 { return fNtupleBuilder->GetBasketEntries(); }
0127 
0128 inline void G4RootMainNtupleManager::SetNewCycle(G4bool value)
0129 { fNewCycle = value; }
0130 
0131 inline G4bool G4RootMainNtupleManager::GetNewCycle() const
0132 { return fNewCycle; }
0133 
0134 #endif