DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
VolumeBuilderBase< U > Class Template Referenceabstract
Collaboration diagram for VolumeBuilderBase< U >:
[legend]

Public Member Functions

G4VPhysicalVolume * GetPlacement () final
 
DerivedPtr MakePlacement ()
 
DerivedPtr PlaceAndFork ()
 
G4LogicalVolume * GetLogicalVolume () final
 
G4VSolid * GetBaseSolid () final
 
G4VSolid * GetFinalSolid () final
 
DerivedPtr MakeLogicalVolume (const VBHelpers::G4MaterialPtrOrString &material={}, G4String name=std::string())
 
DerivedPtr MakeSolid ()
 
DerivedPtr SetName (const G4String &name)
 
DerivedPtr AddUnion (const VolumeBuilder &other, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
 
DerivedPtr AddSubtraction (const VolumeBuilder &other, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
 
DerivedPtr AddIntersection (const VolumeBuilder &other, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
 
DerivedPtr AddBoolean (const VolumeBuilder &other, bool is_subtraction=false, bool is_intersection=false, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
 
DerivedPtr SetMaterial (const VBHelpers::G4MaterialPtrOrString &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 x=true)
 
DerivedPtr SetLogicalVolume (G4LogicalVolume *logical_volume)
 
DerivedPtr SetBooleanName (const G4String &name)
 
DerivedPtr SetPhysRotation (const G4RotationMatrix &rot)
 
DerivedPtr StackPhysRotation (const G4RotationMatrix &stacked_rot)
 
DerivedPtr SetPhysOffset (const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm})
 
DerivedPtr StackPhysOffset (const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm})
 
DerivedPtr SetPhysTransform (const UnitlessG4Transform3D &new_transform)
 
DerivedPtr StackPhysTransform (const UnitlessG4Transform3D &new_transform)
 
G4Transform3D GetPhysTransform () const final
 
DerivedPtr OverridePlacementName (const G4String &pName)
 
DerivedPtr SetCopyNo (G4int pCopyNo)
 
DerivedPtr SetSurfaceCheck (G4bool pSurfChk)
 
DerivedPtr SetMother (const VolumeBuilder &mother)
 
DerivedPtr SetAutoPlacementNaming (bool set)
 
DerivedPtr SetAutoCopyNo (bool set)
 
DerivedPtr ReflectZFinalSolid ()
 
DerivedPtr ReflectZBaseSolid ()
 
DerivedPtr ForkAndReset (const G4String &new_name) const
 
DerivedPtr ForkForFinalSolid (const G4String &new_name)
 
DerivedPtr ForkForLogicalVolume (const G4String &new_name)
 
DerivedPtr ForkForPlacement (std::optional< int > copy_no=std::nullopt, const G4String &name_override="", bool parent_name_was_set=false)
 
DerivedPtr CopyPlacementConfigsFrom (const VolumeBuilder &other)
 
DerivedPtr CopyVolumeConfigsFrom (const VolumeBuilder &other)
 
DerivedPtr SetDefaultUnit (Length unit)
 
Length GetEffectiveDefaultUnit () const
 
DerivedPtr AddTo (BuilderViewList &list) const
 
DerivedPtr AddTo (StructureViewList &list) const
 
DerivedPtr AddTo (Assembly &assembly) const
 
 ~VolumeBuilderBase () override
 
G4String GetBuilderName () const
 
template<typename U >
 VolumeBuilderBase (const VolumeBuilderBase< U > &other)
 
template<typename T , std::enable_if_t< std::is_base_of_v< IStructureBuilder, T >, int > >
 VolumeBuilderBase (const SharedPtr< T > &other, std::true_type)
 
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 Member Functions

G4VSolid * SolidConstructor (const G4String &name) override=0
 
SharedPtr< IStructureBuilderclone_impl () const override
 

Protected Attributes

std::atomic< bool > is_enabled_ {true}
 

Friends

template<typename >
class VolumeBuilderBase
 
class VolumeBuilderCore
 
class AssemblyCore
 
template<typename >
class StructureBuilderBase
 
class StructureBuilderCore
 
class RZBuilderCore
 
class BoxBuilderCore
 
class FromG4VSolidCore
 
FromG4VSolid VB::CreateFromG4VSolid (G4VSolid *solid)
 
Assembly VB::CreateAssembly (G4String names)
 

Detailed Description

template<typename U>
class DLG4::VolumeBuilders::_internals_::VolumeBuilderBase< U >

VolumeBuilder: Common functionality for volume builder classes.

Includes material and attribute setting, and union/subtraction methods. This is Not a user class. Only usable through inheritance to extend class functionality. Return most things by pointer to the derived class So we can chain operations (fluent interface).

Template Parameters
UCRTP paramter for the derived class.

Definition at line 61 of file VolumeBuilderBase.hh.

Constructor & Destructor Documentation

◆ ~VolumeBuilderBase()

template<typename U >
~VolumeBuilderBase ( )
override

Destructor Normally does not delete volume objects.

Geant takes care of that.

Definition at line 109 of file VolumeBuilderBase.hpp.

109 {
110 // optionally release resources (default)
111 // ReSharper disable once CppIfCanBeReplacedByConstexprIf
112 if (!has_ownership_) {
113 // This is SO wrong. This should be done at CREATION of members,
114 // not deletion of class.
115 // But it works for now and we're super restrictive on creation.
116 final_solid_ptr_.make_persistent();
117 solid_ptr_.make_persistent();
118 logicvol_ptr_.make_persistent();
119 placement_.make_persistent();
120 }
121 }

◆ VolumeBuilderBase() [1/2]

template<typename U >
template<typename U >
VolumeBuilderBase ( const VolumeBuilderBase< U > &  other)

Definition at line 78 of file VolumeBuilderBase.hpp.

78 : builder_configs_(other.builder_configs_),
79 boolean_configs_(other.boolean_configs_),
80 lv_configs_(other.lv_configs_),
81 placement_configs_(other.placement_configs_) {
82 // avoid masked bugs from stale view:
83 StoreBuilderView(nullptr);
84 StoreIStructurePtr(nullptr);
85 // don't copy products since they can only be linked once.
86 // Copy methods will do that.
87 }

◆ VolumeBuilderBase() [2/2]

template<typename U >
template<typename T , std::enable_if_t< std::is_base_of_v< IStructureBuilder, T >, int > >
VolumeBuilderBase ( const SharedPtr< T > &  other,
std::true_type   
)

Definition at line 95 of file VolumeBuilderBase.hpp.

97 : builder_configs_(other->builder_configs_,SET_LINK),
98 boolean_configs_(other->boolean_configs_,SET_LINK),
99 lv_configs_(other->lv_configs_, SET_LINK),
100 placement_configs_(other->placement_configs_,SET_LINK),
101 solid_ptr_(other->solid_ptr_,SET_LINK),
102 logicvol_ptr_(other->logicvol_ptr_,SET_LINK),
103 placement_(other->placement_,SET_LINK) {
104 builder_configs_->istructure_ptr = IStructurePtr(other);
105 }
#define SET_LINK
Definition Linkable.hh:64
SharedPtr< IStructureBuilder > IStructurePtr
True polymorphic class base view for all structures Mostly for internal use.

Member Function Documentation

◆ AddTo()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr AddTo ( BuilderViewList list) const

Definition at line 1002 of file VolumeBuilderBase.hpp.

1002 {
1003 list.emplace_back(this->ToVolumeBuilder());
1004 auto retval = shared_mutable_this(this);
1005 return retval;
1006 }
std::shared_ptr< T > shared_mutable_this(const std::enable_shared_from_this< T > *obj)

◆ clone_impl()

template<typename U >
SharedPtr< IStructureBuilder > clone_impl ( ) const
overrideprotectedvirtual

Implements IStructureBuilder.

Reimplemented in VolumeBuilderCore.

Definition at line 994 of file VolumeBuilderBase.hpp.

994 {
995 const U &derived_ref = static_cast<const U &>(*this); // downcast
996 auto retval = new U(derived_ref); // copy
997 auto shared_ptr = i_shared_ptr<U>(retval);
998 return shared_mutable_this(retval); // wrap and return.
999 }
A wrapper for std::shared_ptr that allows and facilitates many implicit(i) type conversions.

◆ GetBuilderName()

template<typename U >
G4String GetBuilderName ( ) const

Definition at line 970 of file VolumeBuilderBase.hpp.

970 {
971 return this->builder_configs_->name;
972 }

◆ MakeLogicalVolume()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr MakeLogicalVolume ( const VBHelpers::G4MaterialPtrOrString material = {},
G4String  name = std::string() 
)

Basically never needed now.


Builds the logical volume and returns the builder. GetLogicalVolume(), or passing the builder to any consumer will trigger the build anyway.

Parameters
materialG4Material* OR a string name of a local or NIST material!
nameOptional explicit name for logical volume. Normally already derived from builder/solid name.
Returns
This builder.

Definition at line 124 of file VolumeBuilderBase.hpp.

124 {
125 ValidateForVolumeBuild(STRINGIFY(BASE) "MakeLogicalVolume");
126 //if no volume was previously built, should be safe to reset material.
127 if (material) {
128 lv_configs_->material = material;
129 }
130 if (name.empty()) {
131 name = this->GetLogicVolName() + "_L";
132 }
133 // Implicit construction through
134 // ctor args..
135 logicvol_ptr_.ConstructAndRawLink(final_solid_ptr_,
136 lv_configs_->material,
137 name);
138 // non-owning link:
139 logicvol_ptr_.make_persistent();
140
141 ApplyAttributes_();
142 return this->shared_from_this();
143 }
#define STRINGIFY(x)
#define BASE
void ConstructAndRawLink(Args &&... args)
Non owning construct and link.
Definition Linkable.hh:299

◆ MakePlacement()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr MakePlacement ( )

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

Definition at line 460 of file VolumeBuilderBase.hpp.

460 {
461 // the copy part comes from validate below, if we're already built:
462 ValidateForPVBuild(STRINGIFY(BASE) "MakePlacement");
463 // 1. Get the logical volume for *this* builder
464 auto *currentLogical = this->GetLogicalVolume();
465 if (!(explicit_physical_copy_name_set_
466 || explicit_copyno_set_
467 || placement_configs_->auto_copy_name
468 || placement_configs_->auto_copyno)
469 ) {
470 G4cout << "Warning: Placement Builder for " + builder_configs_->name +
471 " copied without setting name or copy number and auto naming and numbering have been disabled \n"
472 "Copy number auto-incrementing will be re-enabled \n"
473 " Use SetAutoCopyNo(true), SetAuCopyName(true), OverridePlacementName(\"name\"), SetCopyNo(num) \n"
474 " to pass a name or number to MakePlacement()" << G4endl;
475 placement_configs_->copy_no = PlacementNameRegistry::GetNameCount(
476 GetPlacementBaseName());
477 }
478
479 // 2. Resolve the Mother Logical Volume
480 G4LogicalVolume *effectiveMotherLogical = nullptr;
481
482 G4String base_name = this->GetPlacementBaseName();
483 G4String final_name;
484 if (placement_configs_->auto_copy_name) {
485 // auto naming incrementing
486 final_name = base_name + "_P" +
487 std::to_string(
488 PlacementNameRegistry::GetNameCount(GetPlacementBaseName()));
489 } else {
490 final_name = GetPlacementBaseName() + "_P";
491 }
492 // unless an override was set, then take it verbatim, user's blame :):
493 if (!placement_name_override_.empty()) {
494 final_name = placement_name_override_;
495 }
496
497 if (placement_configs_->mother == nullptr || !placement_configs_->mother->
499 // will lazay trigger mother build if needed
500 G4cout << "WARNING in MakePlacement of " + final_name +
501 ". No mother volume was set or constructable.\n"
502 "Defaulting to world volume" << G4endl;
503 }
504
505 if (placement_configs_->mother) {
506 effectiveMotherLogical = placement_configs_->mother->GetLogicalVolume();
507 } else {
508 effectiveMotherLogical = nullptr; // world placement
509 }
510
511 auto transform = G4Transform3D(placement_configs_->total_rotation,
512 placement_configs_->total_translation);
513 // 4. Create the G4PVPlacement
514 // placement is <G4VPhysicalVolume> and can construct itself:
515 placement_.LinkToRaw(new G4PVPlacement(
516 transform, // G4Transform3D transform
517 currentLogical, // pCurrentLogical
518 final_name, // pName
519 effectiveMotherLogical, // pMotherLogical
520 false, // many option, only false allowed (unless you remember Geant3 :))
521 placement_configs_->copy_no, // pCopyNo
522 placement_configs_->surface_check // pSurfChk
523 ));
524 if (!placement_) {
525 throw std::runtime_error(
526 "MakeLogicalPlacement failed "
527 "for builder named: \"" + builder_configs_->name + "\"\n"
528 " pointer is null after calling G4PVPlacement().");
529 }
530 return this->shared_from_this();
531 }
void LinkToRaw(T *ptr)
Link to an existing T object via pointer (non-owning)
Definition Linkable.hh:254
G4LogicalVolume * GetLogicalVolume() final
Gets a built LogicalVolume, builds default if not built yet.

◆ MakeSolid()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr MakeSolid ( )

Make the G4VSolid.

Returns the builder. Use GetBaseSolid() to retrieve or make and retrieve it.

Returns
The builder

Definition at line 935 of file VolumeBuilderBase.hpp.

935 {
936 G4VSolid *solid;
937 G4String final_name = GetBuilderName();
938 if (builder_configs_->reflect_base_solid_z) {
939 solid = SolidConstructor(final_name + "_proto_solid");
940 solid = new G4ReflectedSolid(final_name, solid, G4ReflectZ3D(0));
941 } else {
942 solid = SolidConstructor(final_name);
943 }
944 solid_ptr_.LinkToRaw(solid);
945 return this->shared_from_this();
946 }
G4VSolid * SolidConstructor(const G4String &name) override=0
polymorphic access to solid construction

◆ 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 }

◆ SetName()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr SetName ( const G4String &  name)

SetName Sets name used for solid and derived product names.

Parameters
nameThe name
Returns
The builder

Definition at line 400 of file VolumeBuilderBase.hpp.

400 {
401 this->builder_configs_->name = name;
402 return this->shared_from_this();
403 }

◆ 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 }

◆ SolidConstructor()

template<typename U >
G4VSolid * SolidConstructor ( const G4String &  name)
overrideprotectedpure virtual

polymorphic access to solid construction

Implements IStructureBuilder.

Implemented in BoxBuilderCore, RZBuilderCore, and VolumeBuilderCore.

◆ StackPhysOffset()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr StackPhysOffset ( const DLG4::VolumeBuilders::ThreeVecDimensioner offset = {0, 0, 0, VB::Length::mm})

Like SetPhysOffset but stacks with previous transformations in order applied.

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

Definition at line 567 of file VolumeBuilderBase.hpp.

567 {
568 const auto &offset = ProvisionUnits(stacked_offset);
569 placement_configs_->translation += offset; // add translation
570 PropagateTransform();
571 return this->shared_from_this();
572 }

◆ StackPhysRotation()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr StackPhysRotation ( const G4RotationMatrix &  stacked_rot)

Like SetPhysRotation but stacks with previous transformations in order applied.

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

Definition at line 543 of file VolumeBuilderBase.hpp.

543 {
544 // some aliases
545 const auto &old_rot = placement_configs_->rotation;
546 const auto &old_trans = placement_configs_->translation;
547 // sanitize input
548 auto new_rot = rot * old_rot; // order matters.
549 auto new_trans = rot * old_trans;
550 this->placement_configs_->rotation = new_rot;
551 this->placement_configs_->translation = new_trans;
552 PropagateTransform();
553 return this->shared_from_this();
554 }

◆ StackPhysTransform()

template<typename U >
VolumeBuilderBase< U >::DerivedPtr StackPhysTransform ( const UnitlessG4Transform3D new_transform)

Like SetPhysTransform but stacks with previous transformations in order applied.

Parameters
new_transform
Returns
The builder

Definition at line 583 of file VolumeBuilderBase.hpp.

583 {
584 //order matters when stacking. Not when "setting"
585 StackPhysRotation(new_transform.getRotation()); // gets a copy on stack
586 StackPhysOffset({new_transform.getTranslation(),GetEffectiveDefaultUnit()});
587 PropagateTransform();
588 return this->shared_from_this();
589 }
DerivedPtr StackPhysRotation(const G4RotationMatrix &stacked_rot)
Like SetPhysRotation but stacks with previous transformations in order applied.
DerivedPtr StackPhysOffset(const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm})
Like SetPhysOffset but stacks with previous transformations in order applied.
Length GetEffectiveDefaultUnit() const
Get the builder default unit or global if not set.

Friends And Related Symbol Documentation

◆ AssemblyCore

template<typename U >
friend class AssemblyCore
friend

Definition at line 73 of file VolumeBuilderBase.hh.

◆ BoxBuilderCore

template<typename U >
friend class BoxBuilderCore
friend

Definition at line 80 of file VolumeBuilderBase.hh.

◆ FromG4VSolidCore

template<typename U >
friend class FromG4VSolidCore
friend

Definition at line 81 of file VolumeBuilderBase.hh.

◆ RZBuilderCore

template<typename U >
friend class RZBuilderCore
friend

Definition at line 79 of file VolumeBuilderBase.hh.

◆ StructureBuilderBase

template<typename U >
template<typename >
friend class StructureBuilderBase
friend

Definition at line 75 of file VolumeBuilderBase.hh.

◆ StructureBuilderCore

template<typename U >
friend class StructureBuilderCore
friend

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.

This derived clas really exists for parallelism with VolumeBuilderCore.

See also
VolumeBuilder for inherited methods.

Definition at line 76 of file VolumeBuilderBase.hh.

◆ VB::CreateAssembly

template<typename U >
Assembly VB::CreateAssembly ( G4String  names)
friend

◆ VB::CreateFromG4VSolid

template<typename U >
FromG4VSolid VB::CreateFromG4VSolid ( G4VSolid *  solid)
friend

◆ VolumeBuilderBase

template<typename U >
template<typename >
friend class VolumeBuilderBase
friend

Definition at line 71 of file VolumeBuilderBase.hh.

◆ VolumeBuilderCore

template<typename U >
friend class VolumeBuilderCore
friend

A polymorphic, type-erased "view" of any specialized builder.

Use it to assign a specialized builder to a generic builder. But you don't use it directly. It has no direct public ctors or factories, but BuilderView(your_other_builder_object) constructs it as i_shared_ptr<VolumeBuilderCore> ( pointer-wrapped builder). Or pass your builder to something expecting a BuilderView, like ex: a std::vector<BuilderViewr>, aka a BuilderViewList.

See also
VolumeBuilder for inherited methods.

Definition at line 72 of file VolumeBuilderBase.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: