GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros
Public Member Functions
GGSSaveTGeoAction Class Reference
Inheritance diagram for GGSSaveTGeoAction:
Inheritance graph
[legend]
Collaboration diagram for GGSSaveTGeoAction:
Collaboration graph
[legend]

Public Member Functions

 GGSSaveTGeoAction ()
 Constructor.
 
 ~GGSSaveTGeoAction ()=default
 Destructor.
 
void BeginOfRunAction (const G4Run *run)
 Actions executed at beginning of run. More...
 
void EndOfRunAction (const G4Run *run)
 Actions executed at end of run. More...
 
void SetOutputFileBase (const std::string &outFileBase)
 Sets the output file base name. More...
 
- Public Member Functions inherited from GGSUserAction
 GGSUserAction ()
 Constructor. More...
 
virtual ~GGSUserAction ()
 Destructor.
 
G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *)
 Override of the ClassifyNewTrack method. More...
 

Detailed Description

Definition at line 21 of file GGSSaveTGeoAction.h.

Member Function Documentation

void GGSSaveTGeoAction::BeginOfRunAction ( const G4Run *  run)

Actions executed at beginning of run.

Method executed at the beginning of each run. A new ROOT file is created for each run.

Parameters
runPointer to the G4Run

Definition at line 31 of file GGSSaveTGeoAction.cpp.

31  { // -----------------
32  const std::string routineName("GGSSaveTGeoAction::BeginOfRunAction");
33 
34  // Open the run file
35  // -----------------
36  if (GGSRootFileService::GetInstance().GetOutputMode() == GGSRootFileService::OutputMode::MULTIFILE ||
37  G4Threading::G4GetThreadId() <= 0) {
38  _outFile = GGSRootFileService::GetInstance().GetFileForThisRun(_outBase, run);
39  if (!_outFile || (_outFile && _outFile->IsZombie())) {
40  GGSCOUT(ERROR) << "Cannot open ROOT file " << _outBase << "for run" << run->GetRunID() << GGSENDL;
41  throw std::runtime_error("");
42  }
43  }
44 }
TFile * GetFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
#define GGSENDL
Definition: GGSSmartLog.h:131
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void GGSSaveTGeoAction::EndOfRunAction ( const G4Run *  run)

Actions executed at end of run.

Method executed at the end of each run. The TGeo object is written to file and the file is closed.

Parameters
runPointer to a G4Run

Definition at line 49 of file GGSSaveTGeoAction.cpp.

49  {
50  const std::string routineName("GGSSaveTGeoAction::EndOfRunAction");
51 
52  if (GGSRootFileService::GetInstance().GetOutputMode() == GGSRootFileService::OutputMode::MULTIFILE ||
53  G4Threading::G4GetThreadId() <= 0) {
54 
55  // Acquire a lock since VGM is probably not thread-safe
56  G4AutoLock lock(mutexForSaveTGeo);
57 
59  if (!geometry) {
60  GGSCOUT(ERROR) << "Can't get the geometry. Exit." << GGSENDL;
61  throw std::runtime_error("Invalid geometry");
62  }
63 
64  auto physVolume = geometry->GetVolume();
65 
66  auto g4Factory = std::make_unique<Geant4GM::Factory>();
67  if (GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
68  g4Factory->SetDebug(1);
69  g4Factory->Import(physVolume);
70 
71  // Export VGM geometry to Root
72  auto rtFactory = std::make_unique<RootGM::Factory>();
73  if (GGSSmartLog::verboseLevel >= GGSSmartLog::DEBUG)
74  rtFactory->SetDebug(1);
75  g4Factory->Export(rtFactory.get());
76  gGeoManager->CloseGeometry();
77 
78  _outFile->WriteObject(gGeoManager, "GGSGeometry");
79 
81  }
82 }
Abstract class needed to load GGS geometry.
static GGSGeoPluginManager & GetInstance()
Get the singleton instance.
#define GGSENDL
Definition: GGSSmartLog.h:131
void CloseFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Closes the ROOT output file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
GGSVGeometryConstruction * GetGeoConstruction()
Returns the geometry construction object.
virtual G4VPhysicalVolume * GetVolume()=0
Get the detector VPhysicalVolume - virtual method.
void GGSSaveTGeoAction::SetOutputFileBase ( const std::string &  outFileBase)
inline

Sets the output file base name.

The file base name can be with or without extension (.root will be automatically used as extension). For each run, the run number will be appended to the base name before the .root extension. If no value is provided the file base name will fallback to the default value set in GSRootFileservice.

Parameters
outFileBaseThe output file base name.
See Also
GGSRootFileservice

Definition at line 58 of file GGSSaveTGeoAction.h.

58 { _outBase = outFileBase; }

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