Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RootMainNtupleManager Class Reference

#include <G4RootMainNtupleManager.hh>

+ Inheritance diagram for G4RootMainNtupleManager:

Public Member Functions

 G4RootMainNtupleManager (G4RootNtupleManager *ntupleBuilder, std::shared_ptr< G4NtupleBookingManager > bookingManager, G4bool rowWise, G4int fileNumber, const G4AnalysisManagerState &state)
 
 G4RootMainNtupleManager ()=delete
 
 ~G4RootMainNtupleManager () override=default
 
void CreateNtuplesFromBooking ()
 
- Public Member Functions inherited from G4BaseAnalysisManager
 G4BaseAnalysisManager (const G4AnalysisManagerState &state)
 
 G4BaseAnalysisManager ()=delete
 
virtual ~G4BaseAnalysisManager ()=default
 
G4bool SetFirstId (G4int firstId)
 
void SetLockFirstId (G4bool lockFirstId)
 
G4int GetFirstId () const
 
G4int GetCycle () const
 

Protected Member Functions

void CreateNtuple (RootNtupleDescription *ntupleDescription, G4bool warn=true)
 
G4bool Delete (G4int id)
 
G4bool Merge ()
 
G4bool Reset ()
 
void ClearData ()
 
void SetFileManager (std::shared_ptr< G4RootFileManager > fileManager)
 
void SetRowWise (G4bool rowWise)
 
std::shared_ptr< G4RootFileGetNtupleFile (RootNtupleDescription *ntupleDescription) const
 
void SetNewCycle (G4bool value)
 
G4bool GetNewCycle () const
 
const std::vector< tools::wroot::ntuple * > & GetNtupleVector ()
 
unsigned int GetBasketEntries () const
 
- Protected Member Functions inherited from G4BaseAnalysisManager
G4bool IsVerbose (G4int verboseLevel) const
 
void Message (G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
 

Friends

class G4RootPNtupleManager
 
class G4RootNtupleManager
 

Additional Inherited Members

- Protected Attributes inherited from G4BaseAnalysisManager
const G4AnalysisManagerStatefState
 
G4int fFirstId { 0 }
 
G4bool fLockFirstId { false }
 

Detailed Description

Definition at line 59 of file G4RootMainNtupleManager.hh.

Constructor & Destructor Documentation

◆ G4RootMainNtupleManager() [1/2]

G4RootMainNtupleManager::G4RootMainNtupleManager ( G4RootNtupleManager * ntupleBuilder,
std::shared_ptr< G4NtupleBookingManager > bookingManager,
G4bool rowWise,
G4int fileNumber,
const G4AnalysisManagerState & state )

Definition at line 40 of file G4RootMainNtupleManager.cc.

46 : G4BaseAnalysisManager(state),
47 fNtupleBuilder(ntupleBuilder),
48 fBookingManager(std::move(bookingManager)),
49 fRowWise(rowWise),
50 fFileNumber(fileNumber)
51{}
G4BaseAnalysisManager()=delete

◆ G4RootMainNtupleManager() [2/2]

G4RootMainNtupleManager::G4RootMainNtupleManager ( )
delete

◆ ~G4RootMainNtupleManager()

G4RootMainNtupleManager::~G4RootMainNtupleManager ( )
overridedefault

Member Function Documentation

◆ ClearData()

void G4RootMainNtupleManager::ClearData ( )
protected

Definition at line 200 of file G4RootMainNtupleManager.cc.

201{
202 fNtupleDescriptionVector.clear();
203 fNtupleVector.clear();
204
205 Message(G4Analysis::kVL2, "clear", "main ntuples");
206}
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
constexpr G4int kVL2

◆ CreateNtuple()

void G4RootMainNtupleManager::CreateNtuple ( RootNtupleDescription * ntupleDescription,
G4bool warn = true )
protected

Definition at line 105 of file G4RootMainNtupleManager.cc.

107{
108// Create ntuple from booking if file was open
109
110 // Get/Create main ntuple file
111 auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription, fFileNumber);
112 if ( ntupleFile == nullptr ) {
113 if ( warn ) {
114 Warn("Ntuple file must be defined first.\n"
115 "Cannot create main ntuple.",
116 fkClass, "CreateNtuple");
117 }
118 return;
119 }
120
121 // Create ntuple from g4 booking
122 auto g4NtupleBooking = ntupleDescription->GetG4NtupleBooking();
123 auto index = CreateNtupleFromBooking(g4NtupleBooking, ntupleFile);
124
125 // Return if ntuple was not created
126 if (index == G4Analysis::kInvalidId) return;
127
128 // Allocate the ntuple description pair vector element(s) if needed
129 while ( index >= G4int(fNtupleDescriptionVector.size()) ) {
130 fNtupleDescriptionVector.push_back(std::make_pair(nullptr, nullptr));
131 }
132
133 // Save ntuple description pair in vectors
134 fNtupleDescriptionVector[index] = std::make_pair(ntupleDescription, ntupleFile);
135}
int G4int
Definition G4Types.hh:85
G4NtupleBooking * GetG4NtupleBooking() const
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

◆ CreateNtuplesFromBooking()

void G4RootMainNtupleManager::CreateNtuplesFromBooking ( )

Definition at line 221 of file G4RootMainNtupleManager.cc.

222{
223// Create ntuples from booking (without creating ntuple description)
224// This function is triggered from workers at new cycle.
225
226 for (auto [ntupleDescription, ntupleFile] : fNtupleDescriptionVector) {
227 CreateNtupleFromBooking(ntupleDescription->GetG4NtupleBooking(), ntupleFile);
228 }
229
230 SetNewCycle(false);
231}

◆ Delete()

G4bool G4RootMainNtupleManager::Delete ( G4int id)
protected

Definition at line 138 of file G4RootMainNtupleManager.cc.

139{
140 if (fNtupleVector.empty()) {
141 // Main ntuples are delete with each new cycle
142 return true;
143 }
144
145 // Proceed with deleting if vector is not empty
146
147 Message(kVL4, "delete", "main ntuple ntupleId: " + to_string(id));
148
149 // Get ntuple description
150 auto index = id - fFirstId;
151 if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
152 G4Analysis::Warn("Main ntuple " + to_string(id) + " does not exist.",
153 fkClass, "Delete");
154 return false;
155 }
156
157 // Delete main ntuple and update ntuple vector
158 delete fNtupleVector[index];
159 fNtupleVector[index] = nullptr;
160
161 Message(kVL3, "delete", "main ntuple ntupleId: " + to_string(id));
162
163 return true;
164}
constexpr G4int kVL3
constexpr G4int kVL4

◆ GetBasketEntries()

unsigned int G4RootMainNtupleManager::GetBasketEntries ( ) const
inlineprotected

Definition at line 125 of file G4RootMainNtupleManager.hh.

126{ return fNtupleBuilder->GetBasketEntries(); }

◆ GetNewCycle()

G4bool G4RootMainNtupleManager::GetNewCycle ( ) const
inlineprotected

Definition at line 131 of file G4RootMainNtupleManager.hh.

132{ return fNewCycle; }

◆ GetNtupleFile()

std::shared_ptr< G4RootFile > G4RootMainNtupleManager::GetNtupleFile ( RootNtupleDescription * ntupleDescription) const
protected

Definition at line 210 of file G4RootMainNtupleManager.cc.

211{
212 auto perThread = false;
213 return fFileManager->GetNtupleFile(ntupleDescription, perThread, fFileNumber);
214}

◆ GetNtupleVector()

const std::vector< tools::wroot::ntuple * > & G4RootMainNtupleManager::GetNtupleVector ( )
inlineprotected

Definition at line 93 of file G4RootMainNtupleManager.hh.

94 { return fNtupleVector; }

◆ Merge()

G4bool G4RootMainNtupleManager::Merge ( )
protected

Definition at line 167 of file G4RootMainNtupleManager.cc.

168{
169 std::size_t counter = 0;
170
171 for ( auto ntuple : fNtupleVector ) {
172 // skip deleted ntuples
173 if (ntuple == nullptr) continue;
174
175 ntuple->merge_number_of_entries();
176
177 // Notify ntuple description that file is not empty
178 if (ntuple->entries() != 0u) {
179 auto ntupleDescription = fNtupleDescriptionVector.at(counter).first;
180 ntupleDescription->SetHasFill(true);
181 }
182 ++counter;
183 }
184
185 return true;
186}

◆ Reset()

G4bool G4RootMainNtupleManager::Reset ( )
protected

Definition at line 189 of file G4RootMainNtupleManager.cc.

190{
191 // The ntuples will be recreated with new cycle or new open file.
192 // Ntuple objects are deleted automatically when closing a file
193
194 fNtupleVector.clear();
195
196 return true;
197}

◆ SetFileManager()

void G4RootMainNtupleManager::SetFileManager ( std::shared_ptr< G4RootFileManager > fileManager)
inlineprotected

Definition at line 116 of file G4RootMainNtupleManager.hh.

118{
119 fFileManager = std::move(fileManager);
120}

◆ SetNewCycle()

void G4RootMainNtupleManager::SetNewCycle ( G4bool value)
inlineprotected

Definition at line 128 of file G4RootMainNtupleManager.hh.

129{ fNewCycle = value; }

Referenced by CreateNtuplesFromBooking().

◆ SetRowWise()

void G4RootMainNtupleManager::SetRowWise ( G4bool rowWise)
inlineprotected

Definition at line 122 of file G4RootMainNtupleManager.hh.

123{ fRowWise = rowWise; }

Friends And Related Symbol Documentation

◆ G4RootNtupleManager

friend class G4RootNtupleManager
friend

Definition at line 62 of file G4RootMainNtupleManager.hh.

◆ G4RootPNtupleManager

friend class G4RootPNtupleManager
friend

Definition at line 61 of file G4RootMainNtupleManager.hh.


The documentation for this class was generated from the following files: