DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Friends | List of all members
Assembly Class Referencefinal

#include <Assembly.hh>

Collaboration diagram for Assembly:
[legend]

Public Member Functions

AssemblyPtr AddStructure (const StructureView &other)
 
Assemblyoperator= (const Assembly &other)=delete
 
DerivedPtr MakePlacement ()
 
DerivedPtr ForkForPlacement (std::optional< int > copy_no=std::nullopt, const G4String &name_override="")
 
DerivedPtr ForkForLogicalVolume (const G4String &new_name)
 
DerivedPtr PlaceAndFork ()
 
DerivedPtr SetName (const G4String &name)
 
DerivedPtr SetMaterial (G4Material *material)
 
DerivedPtr SetColor (double r=0.5, double g=0.5, double b=0.5, double alpha=1.0)
 
DerivedPtr SetColor (const G4Colour &color)
 
DerivedPtr SetAlpha (G4double alpha)
 
DerivedPtr ForceSolid (bool x=true)
 
DerivedPtr SetVisibility (bool is_visible=true)
 
DerivedPtr SetPhysRotation (const G4RotationMatrix &rot)
 
DerivedPtr StackPhysRotation (const G4RotationMatrix &stacked_rot)
 
DerivedPtr SetPhysOffset (const Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
 
DerivedPtr StackPhysOffset (const Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
 
DerivedPtr SetPhysTransform (const UnitlessG4Transform3D &new_transform)
 
DerivedPtr StackPhysTransform (const UnitlessG4Transform3D &stacked_transform)
 
G4Transform3D GetPhysTransform () const
 
DerivedPtr OverridePlacementName (const G4String &pName)
 
DerivedPtr SetCopyNo (G4int pCopyNo)
 
DerivedPtr SetSurfaceCheck (G4bool pSurfChk)
 
DerivedPtr SetMother (const BuilderView &mother)
 
DerivedPtr SetAutoPlacementNaming (bool set)
 
DerivedPtr SetAutoCopyNo (bool set)
 
DerivedPtr CopyPlacementConfigsFrom (const BuilderView &other)
 
DerivedPtr SetDefaultUnit (G4double unit)
 
G4double GetEffectiveDefaultUnit () const
 
G4String GetBuilderName () const
 
std::shared_ptr< T > shared_from_this ()
 
std::shared_ptr< const T > shared_from_this () const
 
void set_shared_from_this_enabled (bool enabled)
 

Protected Attributes

std::atomic< bool > is_enabled_ {true}
 

Friends

template<typename T >
class VolumeBuilder
 
template<typename T >
class StructureBuilder
 
class i_shared_ptr< Assembly >
 
template<typename T >
class i_shared_ptr
 
AssemblyPtr CreateAssembly (G4String name)
 

Detailed Description

A type-erased (data shared view) view of a builder or assembly, ie a "structure.".

Can hold other structures, creating placement hierarchies. Behaves like a buidler, but only for logical volume properties and placement related commands. You can set VisAtt on a structure, and can set offsets and rotations of the whole structure for placement.

While this base view only supports limited methods, it is fully polymorphic and builder objects internally can trigger their full build chain.

See also
StructureBuilder for inherited methods.

Definition at line 46 of file Assembly.hh.

Member Function Documentation

◆ AddStructure()

AssemblyPtr AddStructure ( const StructureView other)

Definition at line 43 of file Assembly.cc.

43 {
44 this->placement_configs_->children.emplace_back(other);
45 return this->shared_from_this();
46 }

◆ CopyPlacementConfigsFrom()

DerivedPtr CopyPlacementConfigsFrom ( const BuilderView other)
inherited

This may help if reusing placement configs for a different structure.

Copies the placement configuration (rotation, translation, mother, etc.) from another structure. Does NOT copy any naming, as that would conflict. Also does NOT copy any products.

Parameters
otherThe builder instance to copy placement configuration from.
Returns
This builder for chaining.

◆ ForceSolid()

DerivedPtr ForceSolid ( bool  x = true)
inherited
Returns
The builder

◆ ForkForLogicalVolume()

DerivedPtr ForkForLogicalVolume ( const G4String &  new_name)
inherited

Makes final solid (including booleans) if unbuilt and copies builder with products cleared for further construction.

Configurations from ALL stages (including later) are kept.

This one seems pretty specific, but could be useful for extending a boolean build more easily possibly

Parameters
new_nameThe base name for the new builder's logical and physical volumes.
Returns
A shared pointer to the new builder instance.

◆ ForkForPlacement()

DerivedPtr ForkForPlacement ( std::optional< int >  copy_no = std::nullopt,
const G4String &  name_override = "" 
)
inherited

Calls MakeLogicalVolume() and creates a new builder instance with a copy of all placement-related configs.


This will be called automatically by consecutive calls to MakePlacement(). All physical volume and (future?) derived products are reset to be rebuilt. Copy_no and placement name can be auto incremented (number only by default) or overridden.

The copy_no will be incremented.

Parameters
copy_nono arguments or std::nullopt to leave as auto. Must set on every use to get manual numbering.
name_overrideAn optional name override for the physical volume. Leave blank to use auto controls instead.
Returns
A shared pointer to the new builder instance.

◆ GetBuilderName()

G4String GetBuilderName ( ) const
inherited

◆ GetEffectiveDefaultUnit()

G4double GetEffectiveDefaultUnit ( ) const
inherited

Get the structure default unit or global if not set.

Returns
The active default unit.

◆ GetPhysTransform()

G4Transform3D GetPhysTransform ( ) const
inlineinherited

A helper to get the Physical Volume transform with units applied This is built from rotation and translatin if they were provided, or from a transform if it was provided, with units applied as specified.

Basically allows you to get the unit-multiplied version for use in direct Geant calls.

Returns
The Physical volume G4Transform3D with units applied.

Definition at line 290 of file StructureBuilder.hh.

290 {
291 return {placement_configs_->rotation, placement_configs_->translation};
292 }

◆ MakePlacement()

DerivedPtr MakePlacement ( )
inherited

Make a placed physical volume.

Retrieve it or make and retrieve with GetPlacement() Fails (throws) if already built. Make a copy first.

Returns
The builder

◆ operator=()

Assembly & operator= ( const Assembly other)
delete

◆ OverridePlacementName()

DerivedPtr OverridePlacementName ( const G4String &  pName)
inherited

Set the placement name for the volume.


Parameters
pNameName for the placement.
Returns
This builder for chaining.

◆ PlaceAndFork()

DerivedPtr PlaceAndFork ( )
inherited

An alias for MakePlacement and ClonePlacement Used for one or many unaltered placments in sequence, usually with auto naming and/or numbering.

Returns
The builder

◆ set_shared_from_this_enabled()

template<typename T >
void set_shared_from_this_enabled ( bool  enabled)
inlineinherited

Definition at line 60 of file disableable_shared_from_this.hh.

60 {
61 is_enabled_ = enabled;
62 }

◆ SetAlpha()

DerivedPtr SetAlpha ( G4double  alpha)
inherited
Parameters
alpha
Returns
The builder

◆ SetAutoCopyNo()

DerivedPtr SetAutoCopyNo ( bool  set)
inherited

Enable (disable for false) auto Physical Volume numbering, on by default.


Adds a copy number to every name. By default copy numbers auto increment. Or you can set explicit names and numbers in ClonePlacement.

Parameters
setTrue before setting.
Returns

◆ SetAutoPlacementNaming()

DerivedPtr SetAutoPlacementNaming ( bool  set)
inherited

Enable auto Physical Volume naming.


Adds a copy number to every name. By default copy numbers auto increment.
This will turn that off. Both makes no sense.
Or you can set explicit names and numbers in ClonePlacement.

Parameters
setFalse before setting.
Returns

◆ SetColor() [1/2]

DerivedPtr SetColor ( const G4Colour &  color)
inherited
Parameters
color
Returns
The builder

◆ SetColor() [2/2]

DerivedPtr SetColor ( double  r = 0.5,
double  g = 0.5,
double  b = 0.5,
double  alpha = 1.0 
)
inherited
Returns
The builder

◆ SetCopyNo()

DerivedPtr SetCopyNo ( G4int  pCopyNo)
inherited

Set the copy number for the placement.


Parameters
pCopyNoCopy number.
Returns
This builder for chaining.

◆ SetDefaultUnit()

DerivedPtr SetDefaultUnit ( G4double  unit)
inherited

Set the per-Structure default unit for all later non-factory offsets.

Use DLG4::VolumeBuilders::SetGlobalDefaultUnit() to set a default for all builders, or fall back to the initial default of CLHEP::mm.

  • May not apply to values set before this is called.
  • Does not apply to factory units like CreateCenteredBoxBuilder();
    But should not be set and changed. Just use it once, early.
    Parameters
    unitThe unit to set, ex: CLHEP::mm
    Returns
    The builder (allows chaining)

◆ SetMaterial()

DerivedPtr SetMaterial ( G4Material *  material)
inherited

/**

Parameters
material
Returns
The builder

◆ SetMother()

DerivedPtr SetMother ( const BuilderView mother)
inherited

Set the mother volume with a builder, or G4VPhysicalVolume or G4VLogicalVolume through implicit conversion.


This does NOT immediately force a build the mother builder, just pre-sets the relationship.

Parameters
motherolumeReferencePtrparameter accepts a builder or a G4VSolid through implicit ctor
Returns
This builder for chaining.

◆ SetName()

DerivedPtr SetName ( const G4String &  name)
inherited

SetName Sets name used for solid and derived product names.

Parameters
nameThe name
Returns
The builder

◆ SetPhysOffset()

DerivedPtr SetPhysOffset ( const Unit3Vec offset = {CLHEP::mm, 0, 0, 0})
inherited

Set the translation vector for placement.

Using Set, rotation applies before translation, regardless of order set, just as in G4PVPlacement() You can pass (unit, x, y, z) or use the default unit with (x, y, z).

Examples: SetPhysOffset({CLHEP::cm, 1, 2, 3}) // 1cm, 2cm, 3cm SetPhysOffset({1, 2, 3}) // Uses default default unit (usually mm) SetDefaultUnit(CLHEP::cm); SetPhysOffset({1, 2, 3}) // 1cm, 2cm, 3cm SetDefaultUnit(1); SetPhysOffset({10*CLHEP::mm, 20*CLHEP::mm, 30*CLHEP::mm}) // Values already have units

Parameters
offsetTranslation vector. See method description for details.
Returns
This builder for chaining.

◆ SetPhysRotation()

DerivedPtr SetPhysRotation ( const G4RotationMatrix &  rot)
inherited

Set the rotation matrix for placement.

Using Set, rotation applies before translation, regardless of order set, just as in G4PVPlacement()

Parameters
rotPointer to the rotation matrix.
Returns
This builder for chaining.

◆ SetPhysTransform()

DerivedPtr SetPhysTransform ( const UnitlessG4Transform3D new_transform)
inherited

Set the G4Transform3D for placment The tranformation provided is meant to be UNITLESS unless you SetDefaultUnit(1).

Otherwise ex: SetDefaultUnit(CLHEP::cm) and proivde a UNITLESS transform. To supply units for each G4Tranform3D separately, just call SetDefaultUnit(unit) before each call. Will overwite/replace rotation and translation.

Parameters
new_transformTranslation vector.
Returns
This builder for chaining.

◆ SetSurfaceCheck()

DerivedPtr SetSurfaceCheck ( G4bool  pSurfChk)
inherited

Set the surface check flag for the placement.


Parameters
pSurfChkBoolean flag for surface check.
Returns
This builder for chaining.

◆ SetVisibility()

DerivedPtr SetVisibility ( bool  is_visible = true)
inherited
Parameters
is_visible
Returns
The builder

◆ shared_from_this() [1/2]

template<typename T >
std::shared_ptr< T > shared_from_this ( )
inlineinherited

Definition at line 44 of file disableable_shared_from_this.hh.

44 {
45 if (is_enabled_) {
46 return std::enable_shared_from_this<T>::shared_from_this();
47 } else {
48 return nullptr;
49 }
50 }

◆ shared_from_this() [2/2]

template<typename T >
std::shared_ptr< const T > shared_from_this ( ) const
inlineinherited

Definition at line 52 of file disableable_shared_from_this.hh.

52 {
53 if (is_enabled_) {
54 return std::enable_shared_from_this<T>::shared_from_this();
55 } else {
56 return nullptr;
57 }
58 }

◆ StackPhysOffset()

DerivedPtr StackPhysOffset ( const Unit3Vec offset = {CLHEP::mm, 0, 0, 0})
inherited

Like SetPhysOffset but stacks with previous transformations in order applied.

Note: Structures/Assebnlies stack transformations hierarchichicaly automatically.
This method is for manual hierarchical stacking calculations. It's probably redundant on assemblies in 99% of caases
Unlike with G4Transform multiplication, stacking is done in a way that allows mutiple objects to move together. The first transformations can set individual objects, and a uniform transformation can be applied to them all to create a rigid motion of the collection.

Parameters
offset
Returns
The builder

◆ StackPhysRotation()

DerivedPtr StackPhysRotation ( const G4RotationMatrix &  stacked_rot)
inherited

Like SetPhysRotation but stacks with previous transformations in order applied.

Note: Structures/Assebnlies stack transformations hierarchichicaly automatically.
This method is for manual hierarchical stacking calculations. It's probably redundant on assemblies in 99% of caases
Unlike with G4Transform multiplication, stacking is done in a way that allows mutiple objects to move together. The first transformations can set individual objects, and a uniform transformation can be applied to them all to create a rigid motion of the collection.

Parameters
stacked_rot
Returns
The builder

◆ StackPhysTransform()

DerivedPtr StackPhysTransform ( const UnitlessG4Transform3D stacked_transform)
inherited

Like SetPhysTransform but stacks with previous transformations in order applied.

Note: Structures/Assebnlies stack transformations hierarchichicaly automatically.
This method is for manual hierarchical stacking calculations. It's probably redundant on assemblies in 99% of caases

Parameters
stacked_transform
Returns
The builder

Friends And Related Symbol Documentation

◆ CreateAssembly

AssemblyPtr CreateAssembly ( G4String  name)
friend

Assembly of strucures, ie builders and/or other assemblies.

Definition at line 25 of file Assembly.cc.

25 {
26 // Haha... assemblies actually are builders!!!
27 auto object = AssemblyPtr(new Assembly());
28 // ... with is_builder set to false.
29 object->placement_configs_->is_builder = false;
30 //We're storing a pointer to the view in the builder by writing to the builder through that same view!
31 BuilderView builder_view = object->ToBuilderView();
32 builder_view->StoreBuilderView(builder_view);
33 // Then store itself in its new builder (that links to its data).
34 //object->builder_configs_->builder_view->StoreIStructurePtr(IStructurePtr(object.get())); // this is the owning copy.
35 // ... and viewed through a reduced StructureView interface:
36 object->SetName(name);
37 auto return_obj = AssemblyPtr(object);
38 return return_obj;
39
40 // This let's us reuse builder methods!
41 }
SharedPtr< VolumeBuilderReference > BuilderView
Common interface for all volume builder types.
SharedPtr< Assembly > AssemblyPtr

◆ i_shared_ptr

template<typename T >
friend class i_shared_ptr
friend

Definition at line 75 of file Assembly.hh.

◆ i_shared_ptr< Assembly >

friend class i_shared_ptr< Assembly >
friend

Definition at line 51 of file Assembly.hh.

◆ StructureBuilder

template<typename T >
friend class StructureBuilder
friend

Definition at line 50 of file Assembly.hh.

◆ VolumeBuilder

template<typename T >
friend class VolumeBuilder
friend

Definition at line 48 of file Assembly.hh.

Member Data Documentation

◆ is_enabled_

template<typename T >
std::atomic<bool> is_enabled_ {true}
protectedinherited

Definition at line 37 of file disableable_shared_from_this.hh.

37{true};

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