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

#include <G4RootNtupleFileManager.hh>

+ Inheritance diagram for G4RootNtupleFileManager:

Public Member Functions

 G4RootNtupleFileManager (const G4AnalysisManagerState &state)
 
 G4RootNtupleFileManager ()=delete
 
 ~G4RootNtupleFileManager () override
 
void SetNtupleMerging (G4bool mergeNtuples, G4int nofReducedNtupleFiles=0) override
 
void SetNtupleRowWise (G4bool rowWise, G4bool rowMode=true) override
 
void SetBasketSize (unsigned int basketSize) override
 
void SetBasketEntries (unsigned int basketEntries) override
 
G4bool ActionAtOpenFile (const G4String &fileName) override
 
G4bool ActionAtWrite () override
 
G4bool ActionAtCloseFile () override
 
G4bool Reset () override
 
G4bool IsNtupleMergingSupported () const override
 
std::shared_ptr< G4VNtupleManagerCreateNtupleManager () override
 
void SetFileManager (std::shared_ptr< G4RootFileManager > fileManager)
 
G4NtupleMergeMode GetMergeMode () const override
 
std::shared_ptr< G4RootNtupleManagerGetNtupleManager () const
 
- Public Member Functions inherited from G4VNtupleFileManager
 G4VNtupleFileManager (const G4AnalysisManagerState &state, G4String fileType)
 
 G4VNtupleFileManager ()=delete
 
virtual ~G4VNtupleFileManager ()=default
 
 G4VNtupleFileManager (const G4VNtupleFileManager &rhs)=delete
 
G4VNtupleFileManageroperator= (const G4VNtupleFileManager &rhs)=delete
 
virtual void SetNtupleMerging (G4bool mergeNtuples, G4int nofReducedNtupleFiles=0)
 
virtual void SetNtupleRowWise (G4bool rowWise, G4bool rowMode=true)
 
virtual void SetBasketSize (unsigned int basketSize)
 
virtual void SetBasketEntries (unsigned int basketEntries)
 
virtual std::shared_ptr< G4VNtupleManagerCreateNtupleManager ()=0
 
virtual void SetBookingManager (std::shared_ptr< G4NtupleBookingManager > bookingManager)
 
virtual G4bool ActionAtOpenFile (const G4String &)=0
 
virtual G4bool ActionAtWrite ()=0
 
virtual G4bool ActionAtCloseFile ()=0
 
virtual G4bool Reset ()=0
 
virtual G4bool IsNtupleMergingSupported () const
 
virtual G4NtupleMergeMode GetMergeMode () const
 
G4String GetFileType () const
 

Friends

class G4RootMpiNtupleFileManager
 

Additional Inherited Members

- Protected Member Functions inherited from G4VNtupleFileManager
void Message (G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
 
- Protected Attributes inherited from G4VNtupleFileManager
const G4AnalysisManagerStatefState
 
G4String fFileType
 
std::shared_ptr< G4NtupleBookingManagerfBookingManager { nullptr }
 

Detailed Description

Definition at line 46 of file G4RootNtupleFileManager.hh.

Constructor & Destructor Documentation

◆ G4RootNtupleFileManager() [1/2]

G4RootNtupleFileManager::G4RootNtupleFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 50 of file G4RootNtupleFileManager.cc.

51 : G4VNtupleFileManager(state, "root")
52{
53 if ( G4Threading::IsMasterThread() ) fgMasterInstance = this;
54
55 // Do not merge ntuples by default
56 // Merging may require user code migration as analysis manager
57 // must be created both on master and workers.
58 auto mergeNtuples = false;
59 SetNtupleMergingMode(mergeNtuples, fNofNtupleFiles);
60}
G4VNtupleFileManager()=delete
G4bool IsMasterThread()
Definition: G4Threading.cc:124

◆ G4RootNtupleFileManager() [2/2]

G4RootNtupleFileManager::G4RootNtupleFileManager ( )
delete

◆ ~G4RootNtupleFileManager()

G4RootNtupleFileManager::~G4RootNtupleFileManager ( )
override

Definition at line 63 of file G4RootNtupleFileManager.cc.

64{
65 if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
66}
const G4AnalysisManagerState & fState

Member Function Documentation

◆ ActionAtCloseFile()

G4bool G4RootNtupleFileManager::ActionAtCloseFile ( )
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 350 of file G4RootNtupleFileManager.cc.

351{
352 if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave) {
353 fSlaveNtupleManager->SetNewCycle(false);
354 return true;
355 }
356
357 return CloseNtupleFiles();
358}

◆ ActionAtOpenFile()

G4bool G4RootNtupleFileManager::ActionAtOpenFile ( const G4String fileName)
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 292 of file G4RootNtupleFileManager.cc.

293{
294 // Check if fNtupleBookingManager is set
295
296 if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ||
297 fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
298
299 G4String objectType = "analysis file";
300 if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
301 objectType = "main analysis file";
302 }
303 Message(kVL4, "open", objectType, fileName);
304
305 // Creating files is triggered from CreateNtuple
306 fNtupleManager->CreateNtuplesFromBooking(
307 fBookingManager->GetNtupleBookingVector());
308
309 Message(kVL1, "open", objectType, fileName);
310 }
311
312 // Creating ntuples from main is triggered from the first Fill call
313 // if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
314 // // G4cout << "Going to create slave ntuples from main" << G4endl;
315 // fSlaveNtupleManager->CreateNtuplesFromMain();
316 // }
317
318 return true;
319}
std::shared_ptr< G4NtupleBookingManager > fBookingManager
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
constexpr G4int kVL1
constexpr G4int kVL4

◆ ActionAtWrite()

G4bool G4RootNtupleFileManager::ActionAtWrite ( )
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 322 of file G4RootNtupleFileManager.cc.

323{
324 if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
325 return true;
326 }
327
328 auto result = true;
329
330 G4String ntupleType;
331 if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) ntupleType = "main ntuples";
332 if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) ntupleType = "slave ntuples";
333
334 Message(kVL4, "merge", ntupleType);
335
336 if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
337 result &= fNtupleManager->Merge();
338 }
339
340 if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
341 result &= fSlaveNtupleManager->Merge();
342 }
343
344 Message(kVL1, "merge", ntupleType, "", result);
345
346 return result;
347}

◆ CreateNtupleManager()

std::shared_ptr< G4VNtupleManager > G4RootNtupleFileManager::CreateNtupleManager ( )
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 225 of file G4RootNtupleFileManager.cc.

226{
227// Create and return ntuple manager.
228// If ntuple merging is activated, managers of different types are created
229// on master/worker.
230
231 Message(kVL4, "create", "ntuple manager");
232
233 // Check that file manager and anaysis manager are set !
234
235 std::shared_ptr<G4VNtupleManager> activeNtupleManager = nullptr;
236 switch ( fNtupleMergeMode )
237 {
238 case G4NtupleMergeMode::kNone:
239 fNtupleManager
240 = make_shared<G4RootNtupleManager>(
241 fState, fBookingManager, 0, 0, fNtupleRowWise, fNtupleRowMode);
242 fNtupleManager->SetFileManager(fFileManager);
243 activeNtupleManager = fNtupleManager;
244 break;
245
246 case G4NtupleMergeMode::kMain: {
247 G4int nofMainManagers = fNofNtupleFiles;
248 if (nofMainManagers == 0) {
249 // create one manager if merging required into the histos & profiles files
250 nofMainManagers = 1;
251 }
252 fNtupleManager
253 = make_shared<G4RootNtupleManager>(
254 fState, fBookingManager, nofMainManagers, fNofNtupleFiles, fNtupleRowWise, fNtupleRowMode);
255 fNtupleManager->SetFileManager(fFileManager);
256 activeNtupleManager = fNtupleManager;
257 break;
258 }
259
260 case G4NtupleMergeMode::kSlave:
261 fNtupleManager = fgMasterInstance->fNtupleManager;
262 // The master class is used only in Get* functions
263 auto mainNtupleManager
264 = fNtupleManager->GetMainNtupleManager(GetNtupleFileNumber());
265 fSlaveNtupleManager
266 = make_shared<G4RootPNtupleManager>(
267 fState, fBookingManager, mainNtupleManager, fNtupleRowWise, fNtupleRowMode);
268 activeNtupleManager = fSlaveNtupleManager;
269 break;
270 }
271
272 G4String mergeMode;
273 switch ( fNtupleMergeMode ) {
274 case G4NtupleMergeMode::kNone:
275 mergeMode = "";
276 break;
277 case G4NtupleMergeMode::kMain:
278 mergeMode = "main ";
279 break;
280 case G4NtupleMergeMode::kSlave:
281 mergeMode = "slave ";
282 break;
283 }
284 Message(kVL3, "create", mergeMode + "ntuple manager");
285
286 fIsInitialized = true;
287
288 return activeNtupleManager;
289}
int G4int
Definition: G4Types.hh:85
constexpr G4int kVL3

◆ GetMergeMode()

G4NtupleMergeMode G4RootNtupleFileManager::GetMergeMode ( ) const
inlineoverridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 103 of file G4RootNtupleFileManager.hh.

104{ return fNtupleMergeMode; }

◆ GetNtupleManager()

std::shared_ptr< G4RootNtupleManager > G4RootNtupleFileManager::GetNtupleManager ( ) const
inline

Definition at line 109 of file G4RootNtupleFileManager.hh.

110{ return fNtupleManager; }

◆ IsNtupleMergingSupported()

G4bool G4RootNtupleFileManager::IsNtupleMergingSupported ( ) const
inlineoverridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 106 of file G4RootNtupleFileManager.hh.

107{ return true; }

◆ Reset()

G4bool G4RootNtupleFileManager::Reset ( )
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 361 of file G4RootNtupleFileManager.cc.

362{
363// Reset ntuples
364
365 auto result = true;
366
367 if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ||
368 fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
369 result &= fNtupleManager->Reset();
370 }
371
372 if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
373 fSlaveNtupleManager->Reset();
374 }
375
376 return result;
377}

◆ SetBasketEntries()

void G4RootNtupleFileManager::SetBasketEntries ( unsigned int  basketEntries)
overridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 219 of file G4RootNtupleFileManager.cc.

220{
221 fFileManager->SetBasketEntries(basketEntries);
222}

◆ SetBasketSize()

void G4RootNtupleFileManager::SetBasketSize ( unsigned int  basketSize)
overridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 213 of file G4RootNtupleFileManager.cc.

214{
215 fFileManager->SetBasketSize(basketSize);
216}

◆ SetFileManager()

void G4RootNtupleFileManager::SetFileManager ( std::shared_ptr< G4RootFileManager fileManager)
inline

Definition at line 97 of file G4RootNtupleFileManager.hh.

99{
100 fFileManager = std::move(fileManager);
101}

◆ SetNtupleMerging()

void G4RootNtupleFileManager::SetNtupleMerging ( G4bool  mergeNtuples,
G4int  nofReducedNtupleFiles = 0 
)
overridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 163 of file G4RootNtupleFileManager.cc.

166{
167 if ( fIsInitialized ) {
168 Warn("Cannot change merging mode.\n"
169 "The function must be called before OpenFile().",
170 fkClass, "SetNtupleMerging");
171 return;
172 }
173
174 // Set ntuple merging mode
175 SetNtupleMergingMode(mergeNtuples, nofNtupleFiles);
176}
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

◆ SetNtupleRowWise()

void G4RootNtupleFileManager::SetNtupleRowWise ( G4bool  rowWise,
G4bool  rowMode = true 
)
overridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 179 of file G4RootNtupleFileManager.cc.

180{
181
182 // Print info even when setting makes no effect
183 // (as we do not get printed the default setting in the output)
184 G4String rowWiseMode;
185 if ( rowWise ) {
186 rowWiseMode = "row-wise with extra branch";
187 }
188 else if ( rowMode ) {
189 rowWiseMode = "row-wise";
190 }
191 else {
192 rowWiseMode = "column-wise";
193 }
194
195 Message(kVL1, "set", "ntuple merging row mode", rowWiseMode);
196
197 // Do nothing if the mode is not changed
198 if ( fNtupleRowWise == rowWise && fNtupleRowMode == rowMode ) return;
199
200 fNtupleRowWise = rowWise;
201 fNtupleRowMode = rowMode;
202
203 if ( fNtupleManager ) {
204 fNtupleManager->SetNtupleRowWise(rowWise, rowMode);
205 }
206
207 if ( fSlaveNtupleManager ) {
208 fSlaveNtupleManager->SetNtupleRowWise(rowWise, rowMode);
209 }
210}

Friends And Related Function Documentation

◆ G4RootMpiNtupleFileManager

friend class G4RootMpiNtupleFileManager
friend

Definition at line 48 of file G4RootNtupleFileManager.hh.


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