Geant4 10.7.0
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)
 
virtual ~G4RootNtupleFileManager ()
 
virtual void SetNtupleMerging (G4bool mergeNtuples, G4int nofReducedNtupleFiles=0) override
 
virtual void SetNtupleRowWise (G4bool rowWise, G4bool rowMode=true) override
 
virtual void SetBasketSize (unsigned int basketSize) override
 
virtual void SetBasketEntries (unsigned int basketEntries) override
 
virtual G4bool ActionAtOpenFile (const G4String &fileName) override
 
virtual G4bool ActionAtWrite () override
 
virtual G4bool ActionAtCloseFile (G4bool reset) override
 
virtual G4bool Reset () override
 
virtual G4bool IsNtupleMergingSupported () const override
 
virtual std::shared_ptr< G4VNtupleManagerCreateNtupleManager () override
 
void SetFileManager (std::shared_ptr< G4RootFileManager > fileManager)
 
G4NtupleMergeMode GetMergeMode () const
 
std::shared_ptr< G4RootNtupleManagerGetNtupleManager () const
 
- Public Member Functions inherited from G4VNtupleFileManager
 G4VNtupleFileManager (const G4AnalysisManagerState &state, const G4String &fileType)
 
virtual ~G4VNtupleFileManager ()
 
 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 (G4bool)=0
 
virtual G4bool Reset ()=0
 
virtual G4bool IsNtupleMergingSupported () const
 
G4String GetFileType () const
 

Friends

class G4RootMpiNtupleFileManager
 

Additional Inherited Members

- Protected Attributes inherited from G4VNtupleFileManager
const G4AnalysisManagerStatefState
 
G4String fFileType
 
std::shared_ptr< G4NtupleBookingManagerfBookingManager
 

Detailed Description

Definition at line 49 of file G4RootNtupleFileManager.hh.

Constructor & Destructor Documentation

◆ G4RootNtupleFileManager()

G4RootNtupleFileManager::G4RootNtupleFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 62 of file G4RootNtupleFileManager.cc.

63 : G4VNtupleFileManager(state, "root"),
64 fIsInitialized(false),
65 fNofNtupleFiles(0),
66 fNtupleRowWise(false),
67 fNtupleRowMode(true),
68 fNtupleMergeMode(G4NtupleMergeMode::kNone),
69 fNtupleManager(nullptr),
70 fSlaveNtupleManager(nullptr),
71 fFileManager(nullptr)
72{
73 if ( G4Threading::IsMasterThread() && fgMasterInstance ) {
74 G4ExceptionDescription description;
75 description
76 << " "
77 << "G4RootNtupleFileManager already exists."
78 << "Cannot create another instance.";
79 G4Exception("G4RootNtupleFileManager::G4RootNtupleFileManager()",
80 "Analysis_F001", FatalException, description);
81 }
82 if ( G4Threading::IsMasterThread() ) fgMasterInstance = this;
83
84 // Do not merge ntuples by default
85 // Merging may require user code migration as analysis manager
86 // must be created both on master and workers.
87 auto mergeNtuples = false;
88 SetNtupleMergingMode(mergeNtuples, fNofNtupleFiles);
89}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4bool IsMasterThread()
Definition: G4Threading.cc:124

◆ ~G4RootNtupleFileManager()

G4RootNtupleFileManager::~G4RootNtupleFileManager ( )
virtual

Definition at line 92 of file G4RootNtupleFileManager.cc.

93{
94 if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
95}
const G4AnalysisManagerState & fState

Member Function Documentation

◆ ActionAtCloseFile()

G4bool G4RootNtupleFileManager::ActionAtCloseFile ( G4bool  reset)
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 422 of file G4RootNtupleFileManager.cc.

423{
424 auto finalResult = true;
425
426 // close files
427 if ( fNtupleMergeMode != G4NtupleMergeMode::kSlave ) {
428 auto result = CloseNtupleFiles();
429 finalResult = finalResult && result;
430 }
431
432 if ( ! reset ) {
433 // The ntuples must be always reset when closing file)
434 auto result = Reset();
435 if ( ! result ) {
436 G4ExceptionDescription description;
437 description << " " << "Resetting data failed";
438 G4Exception("G4RootNtupleFileManager::CloseFile()",
439 "Analysis_W021", JustWarning, description);
440 }
441 finalResult = finalResult && result;
442 }
443
444 return finalResult;
445}
@ JustWarning
virtual G4bool Reset() override

◆ ActionAtOpenFile()

G4bool G4RootNtupleFileManager::ActionAtOpenFile ( const G4String fileName)
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 347 of file G4RootNtupleFileManager.cc.

349{
350 // Check if fNtupleBookingManager is set
351
352 auto finalResult = true;
353
354 if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ||
355 fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
356
357#ifdef G4VERBOSE
358 G4String objectType = "analysis file";
359 if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
360 objectType = "main analysis file";
361 }
362 if ( fState.GetVerboseL4() )
363 fState.GetVerboseL4()->Message("open", objectType, fileName);
364#endif
365
366 // Creating files is triggered from CreateNtuple
367 fNtupleManager->CreateNtuplesFromBooking(
368 fBookingManager->GetNtupleBookingVector());
369
370#ifdef G4VERBOSE
371 if ( fState.GetVerboseL1() ) {
372 fState.GetVerboseL1()->Message("open", objectType, fileName, finalResult);
373 }
374#endif
375 }
376
377 if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
378 // G4cout << "Going to create slave ntuples from main" << G4endl;
379 fSlaveNtupleManager->CreateNtuplesFromMain();
380 }
381
382 return finalResult;
383}
const G4AnalysisVerbose * GetVerboseL1() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::shared_ptr< G4NtupleBookingManager > fBookingManager

◆ ActionAtWrite()

G4bool G4RootNtupleFileManager::ActionAtWrite ( )
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 386 of file G4RootNtupleFileManager.cc.

387{
388 if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
389 return true;
390 }
391
392 auto finalResult = true;
393
394 G4String ntupleType;
395 if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) ntupleType = "main ntuples";
396 if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) ntupleType = "slave ntuples";
397
398#ifdef G4VERBOSE
399 if ( fState.GetVerboseL4() )
400 fState.GetVerboseL4()->Message("merge", ntupleType, "");
401#endif
402
403 if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
404 auto result = fNtupleManager->Merge();
405 finalResult = result && finalResult;
406 }
407
408 if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
409 auto result = fSlaveNtupleManager->Merge();
410 finalResult = result && finalResult;
411 }
412
413#ifdef G4VERBOSE
414 if ( fState.GetVerboseL1() )
415 fState.GetVerboseL1()->Message("merge", ntupleType, "");
416#endif
417
418 return finalResult;
419}

◆ CreateNtupleManager()

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

Implements G4VNtupleFileManager.

Definition at line 272 of file G4RootNtupleFileManager.cc.

273{
274// Create and return ntuple manager.
275// If ntuple merging is activated, managers of different types are created
276// on master/worker.
277
278#ifdef G4VERBOSE
279 if ( fState.GetVerboseL4() )
280 fState.GetVerboseL4()->Message("create", "ntuple manager", "");
281#endif
282
283 // Check that file manager and anaysis manager are set !
284
285 std::shared_ptr<G4VNtupleManager> activeNtupleManager = nullptr;
286 switch ( fNtupleMergeMode )
287 {
288 case G4NtupleMergeMode::kNone:
289 fNtupleManager
290 = make_shared<G4RootNtupleManager>(
291 fState, fBookingManager, 0, 0, fNtupleRowWise, fNtupleRowMode);
292 fNtupleManager->SetFileManager(fFileManager);
293 activeNtupleManager = fNtupleManager;
294 break;
295
296 case G4NtupleMergeMode::kMain: {
297 G4int nofMainManagers = fNofNtupleFiles;
298 if ( ! nofMainManagers ) nofMainManagers = 1;
299 // create one manager if merging required into the histos & profiles files
300 fNtupleManager
301 = make_shared<G4RootNtupleManager>(
302 fState, fBookingManager, nofMainManagers, fNofNtupleFiles, fNtupleRowWise, fNtupleRowMode);
303 fNtupleManager->SetFileManager(fFileManager);
304 activeNtupleManager = fNtupleManager;
305 break;
306 }
307
308 case G4NtupleMergeMode::kSlave:
309 fNtupleManager = fgMasterInstance->fNtupleManager;
310 // The master class is used only in Get* functions
311 auto mainNtupleManager
312 = fNtupleManager->GetMainNtupleManager(GetNtupleFileNumber());
313 fSlaveNtupleManager
314 = make_shared<G4RootPNtupleManager>(
315 fState, fgMasterInstance->fBookingManager, mainNtupleManager, fNtupleRowWise, fNtupleRowMode);
316 activeNtupleManager = fSlaveNtupleManager;
317 break;
318 }
319
320#ifdef G4VERBOSE
321 if ( fState.GetVerboseL3() ) {
322 G4String mergeMode;
323 switch ( fNtupleMergeMode ) {
324 case G4NtupleMergeMode::kNone:
325 mergeMode = "";
326 break;
327 case G4NtupleMergeMode::kMain:
328 mergeMode = "main ";
329 break;
330 case G4NtupleMergeMode::kSlave:
331 mergeMode = "slave ";
332 break;
333 }
334 fState.GetVerboseL3()->Message("create", mergeMode + "ntuple manager", "");
335 }
336#endif
337
338 fIsInitialized = true;
339
340 return activeNtupleManager;
341}
int G4int
Definition: G4Types.hh:85
const G4AnalysisVerbose * GetVerboseL3() const

◆ GetMergeMode()

G4NtupleMergeMode G4RootNtupleFileManager::GetMergeMode ( ) const
inline

Definition at line 102 of file G4RootNtupleFileManager.hh.

103{ return fNtupleMergeMode; }

◆ GetNtupleManager()

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

Definition at line 108 of file G4RootNtupleFileManager.hh.

109{ return fNtupleManager; }

◆ IsNtupleMergingSupported()

G4bool G4RootNtupleFileManager::IsNtupleMergingSupported ( ) const
inlineoverridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 105 of file G4RootNtupleFileManager.hh.

106{ return true; }

◆ Reset()

G4bool G4RootNtupleFileManager::Reset ( )
overridevirtual

Implements G4VNtupleFileManager.

Definition at line 448 of file G4RootNtupleFileManager.cc.

449{
450// Reset ntuples
451
452 auto result = true;
453
454 if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ||
455 fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
456 result = fNtupleManager->Reset(false);
457 }
458
459 return result;
460}

Referenced by ActionAtCloseFile().

◆ SetBasketEntries()

void G4RootNtupleFileManager::SetBasketEntries ( unsigned int  basketEntries)
overridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 266 of file G4RootNtupleFileManager.cc.

267{
268 fFileManager->SetBasketEntries(basketEntries);
269}

◆ SetBasketSize()

void G4RootNtupleFileManager::SetBasketSize ( unsigned int  basketSize)
overridevirtual

Reimplemented from G4VNtupleFileManager.

Definition at line 260 of file G4RootNtupleFileManager.cc.

261{
262 fFileManager->SetBasketSize(basketSize);
263}

◆ SetFileManager()

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

Definition at line 98 of file G4RootNtupleFileManager.hh.

100{ fFileManager = fileManager; }

◆ SetNtupleMerging()

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

Reimplemented from G4VNtupleFileManager.

Definition at line 205 of file G4RootNtupleFileManager.cc.

208{
209 if ( fIsInitialized ) {
210 G4ExceptionDescription description;
211 description
212 << "Cannot change merging mode." << G4endl
213 << "The function must be called before OpenFile().";
214 MergingException("SetNtupleMerging", description);
215 return;
216 }
217
218 // Set ntuple merging mode
219 SetNtupleMergingMode(mergeNtuples, nofNtupleFiles);
220}
#define G4endl
Definition: G4ios.hh:57

◆ SetNtupleRowWise()

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

Reimplemented from G4VNtupleFileManager.

Definition at line 223 of file G4RootNtupleFileManager.cc.

224{
225#ifdef G4VERBOSE
226 // Print info even when setting makes no effect
227 // (as we do not get printed the default setting in the output)
228 G4String rowWiseMode;
229 if ( rowWise ) {
230 rowWiseMode = "row-wise with extra branch";
231 }
232 else if ( rowMode ) {
233 rowWiseMode = "row-wise";
234 }
235 else {
236 rowWiseMode = "column-wise";
237 }
238
239 if ( fState.GetVerboseL1() )
241 ->Message("set", "ntuple merging row mode", rowWiseMode);
242#endif
243
244 // Do nothing if the mode is not changed
245 if ( fNtupleRowWise == rowWise && fNtupleRowMode == rowMode ) return;
246
247 fNtupleRowWise = rowWise;
248 fNtupleRowMode = rowMode;
249
250 if ( fNtupleManager ) {
251 fNtupleManager->SetNtupleRowWise(rowWise, rowMode);
252 }
253
254 if ( fSlaveNtupleManager ) {
255 fSlaveNtupleManager->SetNtupleRowWise(rowWise, rowMode);
256 }
257}

Friends And Related Function Documentation

◆ G4RootMpiNtupleFileManager

friend class G4RootMpiNtupleFileManager
friend

Definition at line 51 of file G4RootNtupleFileManager.hh.


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