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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 
 27 // Manager class for ntuple booking for all output types.
 28 //
 29 // Author: Ivana Hrivnacova, 19/06/2015  (ivana@ipno.in2p3.fr)
 30 
 31 #ifndef G4NtupleBookingManager_h
 32 #define G4NtupleBookingManager_h 1
 33 
 34 #include "G4BaseAnalysisManager.hh"
 35 #include "G4AnalysisUtilities.hh"
 36 #include "globals.hh"
 37 
 38 #include "tools/ntuple_booking"
 39 
 40 #include <set>
 41 #include <string_view>
 42 #include <vector>
 43 
 44 struct G4NtupleBooking
 45 {
 46   G4NtupleBooking() = default;
 47   ~G4NtupleBooking() = default;
 48 
 49   void SetDeleted(G4bool deleted, G4bool keepSetting) {
 50     fDeleted = std::make_pair(deleted, keepSetting);
 51   }
 52   G4bool GetDeleted() const {
 53     return fDeleted.first;
 54   }
 55   void Reset() {
 56     if (! fDeleted.second) {
 57       // Reset information unless "keepSetting" option is true
 58       fFileName.clear();
 59       fActivation = true;
 60     }
 61     SetDeleted(false, false);
 62   }
 63 
 64   tools::ntuple_booking fNtupleBooking;
 65   G4int fNtupleId { G4Analysis::kInvalidId };
 66   G4String fFileName;
 67   G4bool fActivation { true };
 68   std::pair<G4bool, G4bool> fDeleted { false, false };
 69 };
 70 
 71 class G4NtupleBookingManager : public G4BaseAnalysisManager
 72 {
 73   // Disable using the object managers outside G4VAnalysisManager and
 74   // its messenger
 75   friend class G4VAnalysisManager;
 76 
 77   public:
 78     explicit G4NtupleBookingManager(const G4AnalysisManagerState& state);
 79     G4NtupleBookingManager() = delete;
 80     ~G4NtupleBookingManager() override;
 81 
 82     const std::vector<G4NtupleBooking*>& GetNtupleBookingVector() const;
 83 
 84     // File type
 85     // (only one output file type allowed for ntuples)
 86     void SetFileType(const G4String& fileType);
 87     G4String GetFileType() const;
 88     G4bool IsEmpty() const;
 89 
 90     // Access methods
 91     tools::ntuple_booking* GetNtuple(G4bool warn,
 92                              G4bool onlyIfActive) const;
 93     tools::ntuple_booking* GetNtuple(G4int ntupleId, G4bool warn,
 94                               G4bool onlyIfActive) const;
 95 
 96   protected:
 97     // Methods to create ntuples
 98     //
 99     G4int CreateNtuple(const G4String& name, const G4String& title);
100 
101     // Create columns in the last created ntuple (from base class)
102     // Create columns in the last created ntuple
103     G4int CreateNtupleIColumn(const G4String& name,
104                               std::vector<int>* vector);
105     G4int CreateNtupleFColumn(const G4String& name,
106                               std::vector<float>* vector) ;
107     G4int CreateNtupleDColumn(const G4String& name,
108                               std::vector<double>* vector);
109     G4int CreateNtupleSColumn(const G4String& name,
110                               std::vector<std::string>* vector);
111     G4NtupleBooking*  FinishNtuple() ;
112 
113     // Create columns in the ntuple with given id
114     G4int CreateNtupleIColumn(G4int ntupleId,
115                     const G4String& name, std::vector<int>* vector);
116     G4int CreateNtupleFColumn(G4int ntupleId,
117                     const G4String& name, std::vector<float>* vector);
118     G4int CreateNtupleDColumn(G4int ntupleId,
119                     const G4String& name, std::vector<double>* vector);
120     G4int CreateNtupleSColumn(G4int ntupleId,
121                     const G4String& name, std::vector<std::string>* vector);
122     G4NtupleBooking*  FinishNtuple(G4int ntupleId);
123 
124     // The ntuple column ids are generated automatically starting from 0;
125     // with the following function it is possible to change it
126     // to start from another value
127     G4bool SetFirstNtupleColumnId(G4int firstId);
128     G4int  GetFirstNtupleColumnId() const;
129 
130     // Activation option
131     //
132     void  SetActivation(G4bool activation);
133     void  SetActivation(G4int ntupleId, G4bool activation);
134     G4bool  GetActivation(G4int ntupleId) const;
135 
136     // // File name option
137     void  SetFileName(const G4String& fileName);
138     void  SetFileName(G4int id, const G4String& fileName);
139     G4String GetFileName(G4int id) const;
140 
141     // Access methods
142     G4int GetNofNtuples(G4bool onlyIfExist = false) const;
143 
144     // Clear data
145     void ClearData();
146 
147     // Method to delete selected ntuples
148     G4bool Delete(G4int id, G4bool keepSetting);
149 
150     // List ntuples
151     G4bool List(std::ostream& output, G4bool onlyIfActive = true);
152 
153     // Data members
154     std::vector<G4NtupleBooking*> fNtupleBookingVector;
155     std::set<G4int> fFreeIds;
156 
157   private:
158     // Methods
159     // Common implementation
160     G4NtupleBooking*  GetNtupleBookingInFunction(
161                                         G4int id,
162                                         std::string_view function,
163                                         G4bool warn = true) const;
164 
165     G4bool CheckName(const G4String& name, const G4String& objectType) const;
166     template <typename T>
167     G4int CreateNtupleTColumn(G4int ntupleId,
168                     const G4String& name, std::vector<T>* vector);
169     G4int GetCurrentNtupleId() const;
170 
171     // Static data members
172     static constexpr std::string_view fkClass { "G4NtupleBookingManager" };
173 
174     // Data members
175     G4String fFileType;
176     G4int    fFirstNtupleColumnId { 0 };
177     G4bool   fLockFirstNtupleColumnId { false };
178     G4int    fCurrentNtupleId { G4Analysis::kInvalidId };
179 };
180 
181 #include "G4NtupleBookingManager.icc"
182 
183 #endif
184