g4system
Loading...
Searching...
No Matches
G4ObjectsFactory Class Referenceabstract

Base class orchestrating the conversion of a GVolume into a Geant4 representation. More...

#include <g4objectsFactory.h>

Public Member Functions

 ~G4ObjectsFactory () override=default
 
 G4ObjectsFactory (const std::shared_ptr< GOptions > &g)
 Construct a factory using the global option set.
 
void initialize_context (int checkOverlaps, const std::string &backupMaterial)
 Configure overlap checking and backup material behavior for this factory.
 
bool build_g4volume (const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
 Build (or retrieve) solid, logical, and physical volumes for a given GVolume.
 
virtual std::string_view className () const =0
 Short, human-readable factory name for logging.
 
- Public Member Functions inherited from GBase< G4ObjectsFactory >
 GBase (const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
 
 GBase (const std::shared_ptr< GLogger > &logger)
 
 GBase (const GBase &)=default
 
 GBase (GBase &&) noexcept=default
 
virtual ~GBase ()
 
GBaseoperator= (const GBase &)=default
 
GBaseoperator= (GBase &&) noexcept=default
 

Protected Member Functions

virtual G4VSolid * buildSolid (const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)=0
 Build the G4VSolid for a volume.
 
virtual G4LogicalVolume * buildLogical (const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
 Build or retrieve the G4LogicalVolume for a volume.
 
virtual G4VPhysicalVolume * buildPhysical (const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
 Build or retrieve the G4VPhysicalVolume for a volume.
 
G4VolumegetOrCreateG4Volume (const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
 Get or create a G4Volume wrapper entry in the map.
 
G4VisAttributes createVisualAttributes (const GVolume *s)
 Build visualization attributes from the volume definition.
 
bool checkSolidDependencies (const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
 Check whether all prerequisites to build a solid are satisfied.
 
bool checkPhysicalDependencies (const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
 Verify prerequisites to build a physical placement.
 

Static Protected Member Functions

static G4VSolid * getSolidFromMap (const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
 Lookup solid in the g4s map.
 
static G4LogicalVolume * getLogicalFromMap (const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
 Lookup logical volume in the g4s map.
 
static G4VPhysicalVolume * getPhysicalFromMap (const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
 Lookup physical volume in the g4s map.
 
static bool checkLogicalDependencies (const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
 Logical dependency check placeholder.
 
static G4RotationMatrix * getRotation (const GVolume *s)
 Parse rotation string and build a Geant4 rotation matrix.
 
static G4ThreeVector getPosition (const GVolume *s)
 Parse position and optional shift strings to compute placement translation.
 

Protected Attributes

int checkOverlaps {0}
 
std::string backupMaterial
 Backup material name used if the requested material is absent.
 
- Protected Attributes inherited from GBase< G4ObjectsFactory >
std::shared_ptr< GLoggerlog
 

Detailed Description

The public entry point build_g4volume() ensures that a volume has:

  • a G4VSolid
  • a G4LogicalVolume
  • a G4VPhysicalVolume

The factory may short-circuit and return false when dependencies are not available yet (for example, a mother volume is not built). The world builder can then retry on a later pass.

Definition at line 52 of file g4objectsFactory.h.

Constructor & Destructor Documentation

◆ ~G4ObjectsFactory()

G4ObjectsFactory::~G4ObjectsFactory ( )
overridedefault

Virtual destructor (subclasses may own additional resources).

◆ G4ObjectsFactory()

G4ObjectsFactory::G4ObjectsFactory ( const std::shared_ptr< GOptions > & g)
inlineexplicit
Parameters
gShared option set used to initialize the logging base and other behaviors.

Definition at line 62 of file g4objectsFactory.h.

Member Function Documentation

◆ build_g4volume()

bool G4ObjectsFactory::build_g4volume ( const GVolume * s,
std::unordered_map< std::string, G4Volume * > * g4s )
Parameters
sPointer to the GEMC volume definition.
g4sMap that stores and caches the resulting G4Volume wrappers.
Returns
true if solid, logical, and physical objects were successfully created; otherwise false.

This method calls:

Implementations are expected to return nullptr when dependencies are not satisfied.

Definition at line 186 of file g4objectsFactory.cc.

◆ buildLogical()

G4LogicalVolume * G4ObjectsFactory::buildLogical ( const GVolume * s,
std::unordered_map< std::string, G4Volume * > * g4s )
protectedvirtual
Parameters
sVolume definition to convert.
g4sMap of cached G4Volume wrappers.
Returns
Pointer to the created/retrieved logical volume, or nullptr if dependencies are missing.

The default implementation:

  • ensures the solid exists (or it was copied from another volume)
  • looks up the requested material in the Geant4 material tables
  • optionally falls back to the configured backup material
  • sets visualization attributes derived from the volume definition

Definition at line 102 of file g4objectsFactory.cc.

◆ buildPhysical()

G4VPhysicalVolume * G4ObjectsFactory::buildPhysical ( const GVolume * s,
std::unordered_map< std::string, G4Volume * > * g4s )
protectedvirtual
Parameters
sVolume definition to convert.
g4sMap of cached G4Volume wrappers.
Returns
Pointer to the created/retrieved physical volume, or nullptr if dependencies are missing.

The default implementation:

  • checks existence and mother/logical dependencies
  • computes rotation and translation from the volume definition
  • places the logical volume into its mother via G4PVPlacement

Definition at line 146 of file g4objectsFactory.cc.

◆ buildSolid()

virtual G4VSolid * G4ObjectsFactory::buildSolid ( const GVolume * s,
std::unordered_map< std::string, G4Volume * > * g4s )
protectedpure virtual
Parameters
sVolume definition to convert.
g4sMap of cached G4Volume wrappers.
Returns
Pointer to the created/retrieved solid, or nullptr on failure or missing dependencies.

Subclasses implement the actual conversion from the GEMC type/parameters to a Geant4 solid.

Implemented in G4CadSystemFactory, and G4NativeSystemFactory.

◆ checkLogicalDependencies()

bool G4ObjectsFactory::checkLogicalDependencies ( const GVolume * s,
std::unordered_map< std::string, G4Volume * > * g4s )
staticprotected
Parameters
sCandidate volume.
g4sMap containing all created wrappers so far.
Returns
Always true for now.

The hook exists for future extensions (material prerequisites, sensitive detector constraints, etc.).

Definition at line 72 of file geant4Dependencies.cc.

◆ checkPhysicalDependencies()

bool G4ObjectsFactory::checkPhysicalDependencies ( const GVolume * s,
std::unordered_map< std::string, G4Volume * > * g4s )
protected
Parameters
sCandidate volume.
g4sMap containing all created wrappers so far.
Returns
true if the candidate logical volume and mother logical volume exist; otherwise false.

This check ensures:

  • the candidate wrapper exists in the map
  • the candidate logical volume exists (or its copy source logical exists)
  • the mother logical exists unless the candidate is the world volume

Definition at line 81 of file geant4Dependencies.cc.

◆ checkSolidDependencies()

bool G4ObjectsFactory::checkSolidDependencies ( const GVolume * s,
std::unordered_map< std::string, G4Volume * > * g4s )
protected
Parameters
sCandidate volume.
g4sMap containing all created wrappers so far.
Returns
true if dependencies are satisfied, otherwise false.

The function handles mutually exclusive scenarios:

  • "copy of" another volume (solid already exists)
  • boolean solid operations (operand solids must exist)
  • ordinary primitive solids (no extra prerequisites)

Definition at line 20 of file geant4Dependencies.cc.

◆ className()

virtual std::string_view G4ObjectsFactory::className ( ) const
pure virtual
Returns
String view valid for the lifetime of the factory.

Implemented in G4CadSystemFactory, and G4NativeSystemFactory.

◆ createVisualAttributes()

G4VisAttributes G4ObjectsFactory::createVisualAttributes ( const GVolume * s)
protected
Parameters
sVolume definition containing color/opacity/style/visibility.
Returns
A G4VisAttributes instance configured accordingly.

Definition at line 54 of file g4objectsFactory.cc.

◆ getLogicalFromMap()

G4LogicalVolume * G4ObjectsFactory::getLogicalFromMap ( const std::string & volume_name,
std::unordered_map< std::string, G4Volume * > * g4s )
staticprotected

Definition at line 41 of file g4objectsFactory.cc.

◆ getOrCreateG4Volume()

G4Volume * G4ObjectsFactory::getOrCreateG4Volume ( const std::string & volume_name,
std::unordered_map< std::string, G4Volume * > * g4s )
inlineprotected
Parameters
volume_nameKey used for the volume.
g4sMap holding cached wrappers.
Returns
Pointer to an existing wrapper if found, otherwise a newly allocated wrapper.

The wrapper is created once and reused for solid/logical/physical caching across build passes.

Definition at line 173 of file g4objectsFactory.h.

◆ getPhysicalFromMap()

G4VPhysicalVolume * G4ObjectsFactory::getPhysicalFromMap ( const std::string & volume_name,
std::unordered_map< std::string, G4Volume * > * g4s )
staticprotected

Definition at line 48 of file g4objectsFactory.cc.

◆ getPosition()

G4ThreeVector G4ObjectsFactory::getPosition ( const GVolume * s)
staticprotected
Parameters
sVolume definition containing position and optional shift.
Returns
Translation vector to use for placement.

Definition at line 88 of file g4objectsFactory.cc.

◆ getRotation()

G4RotationMatrix * G4ObjectsFactory::getRotation ( const GVolume * s)
staticprotected
Parameters
sVolume definition containing rotation specification.
Returns
Newly allocated G4RotationMatrix pointer.

Definition at line 73 of file g4objectsFactory.cc.

◆ getSolidFromMap()

G4VSolid * G4ObjectsFactory::getSolidFromMap ( const std::string & volume_name,
std::unordered_map< std::string, G4Volume * > * g4s )
staticprotected

Definition at line 34 of file g4objectsFactory.cc.

◆ initialize_context()

void G4ObjectsFactory::initialize_context ( int checkOverlaps,
const std::string & backupMaterial )
Parameters
checkOverlapsForwarded to placement calls to enable overlap checking.
backupMaterialMaterial name used if a requested material is missing.
  • If backupMaterial is empty, a missing material is treated as an error.
  • If overlap checking is enabled, placements may perform overlap checks at construction time.

Definition at line 27 of file g4objectsFactory.cc.

Field Documentation

◆ backupMaterial

std::string G4ObjectsFactory::backupMaterial
protected

Empty string means: no fallback; missing material lookup becomes fatal.

Definition at line 257 of file g4objectsFactory.h.

◆ checkOverlaps

int G4ObjectsFactory::checkOverlaps {0}
protected

Overlap-check mode forwarded to G4PVPlacement.

Definition at line 250 of file g4objectsFactory.h.


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