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
VolumeBuilderCore Class Referencefinal

#include <VolumeBuilderCore.hh>

Collaboration diagram for VolumeBuilderCore:
[legend]

Public Member Functions

G4VSolid * SolidConstructor (const G4String &name) override
 
VolumeBuilderCoreoperator= (const VolumeBuilderCore &other)=delete
 
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
 
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 Member Functions

SharedPtr< IStructureBuilderclone_impl () const override
 
VolumeBuilder ToVolumeBuilder () const override
 

Protected Attributes

std::atomic< bool > is_enabled_ {true}
 

Friends

template<typename T >
class VolumeBuilderBase
 
template<typename T >
class StructureBuilderBase
 
template<typename T >
class i_shared_ptr
 
class i_shared_ptr< VolumeBuilderCore >
 
Assembly VB::CreateAssembly (G4String name)
 

Detailed Description

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 43 of file VolumeBuilderCore.hh.

Member Function Documentation

◆ AddBoolean()

VolumeBuilderBase< VolumeBuilderCore >::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 
)
inherited

Add a boolean operation.

This does NOT immediately trigger a build on a passed-in builder, just pre-sets the relationship.

Parameters
otherA VolumeBuilder, G4VSolid, or anything constructable by a BuilderView
is_subtractiontrue for subtraction, false for union
is_intersectiontrue for intersection, false for union
offsetOffset applied to solid
rotationApplied to solid
Returns
The builder

Definition at line 221 of file VolumeBuilderBase.hpp.

280 {
281 auto offset = ProvisionUnits(new_offset);
282
283 if (other) {
284 boolean_configs_->booleans.emplace_back(
285 BooleanSolid{other, is_subtraction, is_intersection, offset, rotation});
286 } else {
287 throw std::runtime_error("Error in AddBoolean() "
288 "for builder named: \"" + builder_configs_->name + "\"\n"
289 " volume is invalid (null)");
290 }
291 return this->shared_from_this();
292 }

◆ AddIntersection()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr AddIntersection ( const VolumeBuilder other,
const DLG4::VolumeBuilders::ThreeVecDimensioner offset = {0, 0, 0, VB::Length::mm},
G4RotationMatrix *  rotation = nullptr 
)
inherited

Define combination another volume with present one, This does NOT immediately trigger a build on a passed-in builder, just pre-sets the relationship.

Parameters
otherA VolumeBuilder, G4VSolid, or anything constructable by a BuilderView
offsetOffset applied to solid
rotationApplied to solid
Returns
The builder

Definition at line 205 of file VolumeBuilderBase.hpp.

265 {
266 if (other) {
267 bool is_subtraction = false;
268 bool is_intersection = true;
269 AddBoolean(other, is_subtraction, is_intersection, new_offset, rotation);
270 } else {
271 throw std::runtime_error("Error in AddBoolean() "
272 "for builder named: \"" + builder_configs_->name + "\"\n"
273 " volume is invalid (null)");
274 }
275 return this->shared_from_this();
276 }
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)
Add a boolean operation.

◆ AddSubtraction()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr AddSubtraction ( const VolumeBuilder other,
const DLG4::VolumeBuilders::ThreeVecDimensioner offset = {0, 0, 0, VB::Length::mm},
G4RotationMatrix *  rotation = nullptr 
)
inherited

Define combination another volume with present one, This does NOT immediately trigger a build on a passed-in builder, just pre-sets the relationship.

Parameters
otherA VolumeBuilder, G4VSolid, or anything constructable by a BuilderView
offsetOffset applied to solid
rotationApplied to solid
Returns
The builder

Definition at line 201 of file VolumeBuilderBase.hpp.

250 {
251 if (other) {
252 bool is_subtraction = true;
253 bool is_intersection = false;
254 AddBoolean(other, is_subtraction, is_intersection, new_offset, rotation);
255 } else {
256 throw std::runtime_error("Error in AddBoolean(): "
257 "for builder named: \"" + builder_configs_->name + "\"\n"
258 "volume is invalid (null)");
259 }
260 return this->shared_from_this();
261 }

◆ AddTo() [1/3]

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr AddTo ( Assembly assembly) const
inherited

Add the builder an assembly geometrically joined manipulation.

Parameters
assemblyThe assembly to add to.
Returns
the builder

Definition at line 630 of file VolumeBuilderBase.hpp.

1016 {
1017 assembly->AddStructure(this->ToStructureView());
1018 auto retval = shared_mutable_this(this);
1019 return retval;
1020 }
std::shared_ptr< T > shared_mutable_this(const std::enable_shared_from_this< T > *obj)

◆ AddTo() [2/3]

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr AddTo ( BuilderViewList list) const
inherited

Definition at line 612 of file VolumeBuilderBase.hpp.

1002 {
1003 list.emplace_back(this->ToVolumeBuilder());
1004 auto retval = shared_mutable_this(this);
1005 return retval;
1006 }

◆ AddTo() [3/3]

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr AddTo ( StructureViewList list) const
inherited

Add the builder a list for group/batch manipulations.

Parameters
listThe list to add to.
Returns
the builder

Definition at line 621 of file VolumeBuilderBase.hpp.

1009 {
1010 list.emplace_back(this->ToStructureView());
1011 auto retval = shared_mutable_this(this);
1012 return retval;
1013 }

◆ AddUnion()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr AddUnion ( const VolumeBuilder other,
const DLG4::VolumeBuilders::ThreeVecDimensioner offset = {0, 0, 0, VB::Length::mm},
G4RotationMatrix *  rotation = nullptr 
)
inherited

Define combination another volume with present one, This does NOT immediately trigger a build on a passed-in builder, just pre-sets the relationship.

Parameters
otherA VolumeBuilder, G4VSolid, or anything constructable by a BuilderView
offsetOffset applied to solid
rotationApplied to solid
Returns
The builder

Definition at line 197 of file VolumeBuilderBase.hpp.

241 {
242 bool is_subtraction = false;
243 bool is_intersection = false;
244 AddBoolean(other, is_subtraction, is_intersection, new_offset, rotation);
245 return this->shared_from_this();
246 }

◆ clone_impl()

SharedPtr< IStructureBuilder > clone_impl ( ) const
overrideprotectedvirtual

Reimplemented from VolumeBuilderBase< VolumeBuilderCore >.

Definition at line 60 of file VolumeBuilderCore.cc.

60 {
61 // have the erased base clone itself:
62 auto copy = builder_configs_->istructure_ptr->clone_impl();
63 // Then have it create a Builder from itself:
64 auto builder_view = copy->ToVolumeBuilder();
65 builder_view->StoreIStructurePtr(copy); // this is the owning copy.
66 builder_view->StoreBuilderView(builder_view);
67
68 //return static_cast<std::shared_ptr<ISolidBuilder>>(builder_view) ; // and return the builder
69 return builder_view; // and return the builder
70 }

◆ CopyPlacementConfigsFrom()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr CopyPlacementConfigsFrom ( const VolumeBuilder other)
inherited

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

Copies the placement configuration (rotation, translation, mother, etc.) from another builder. Does NOT copy any naming, as that would conflict. Also does NOT copy any products. Use CopyPlacement Builder for that. Names will derive from present object, or you can override with Setters as usual.

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

Definition at line 565 of file VolumeBuilderBase.hpp.

772 {
773 this->placement_configs_ = other->placement_configs_;
774 // receiver is responsible for unique naming/numbering.
775 // we can't clobber auto-name/number incrementing from another config:
776 // Does not copy the solid/boolean, just to get configs ONLY
777 return this->shared_from_this();
778 }

◆ CopyVolumeConfigsFrom()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr CopyVolumeConfigsFrom ( const VolumeBuilder other)
inherited

Copies the LogicalVolume configuration (material, VisAttributes, etc.) from another builder.

This DOES NOT include copying any booleans. This is useful for setting up multiple placements with similar configurations.

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

Definition at line 576 of file VolumeBuilderBase.hpp.

781 {
782 // Booleans are NOT considered as part of Volume Configs.
783 // We keep our booleans.
784 auto name = this->builder_configs_->name; // backup our name
785 auto booleans = this->boolean_configs_->booleans;
786 this->lv_configs_ = other->lv_configs_;
787 // restor name. This is easier than keeping name separately. :P
788 this->builder_configs_->name = name;
789 this->boolean_configs_->booleans = booleans; // restore ours.
790 return this->shared_from_this();
791 }

◆ ForceSolid()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr ForceSolid ( bool  x = true)
inherited
Returns
The builder

Definition at line 266 of file VolumeBuilderBase.hpp.

433 {
434 lv_configs_->force_solid = x;
435 ApplyAttributes_();
436 return this->shared_from_this();
437 }

◆ ForkAndReset()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr ForkAndReset ( const G4String &  new_name) const
inherited

Copy a configured/unbuilt Builder, with a new name.

This is the most generic all-purpose copier, but can result in some duplication of constituent solids, etc.

Copies all configurations. You can modify and rebuild all products. Copying-Transformations are not remembered. Base implementation is in VolumeBuilder, but can be overridden for Solid-Builder specific needs.

Parameters
new_name
Returns

Definition at line 499 of file VolumeBuilderBase.hpp.

656 {
657 NoNameCheck(new_name, "CopySolidBuilder");
658 DerivedPtr copy = this->Clone();
659 copy->SetName(new_name); // Set base name for derived class
660 copy->SetBooleanName("");
661 return copy;
662 }

◆ ForkForFinalSolid()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr ForkForFinalSolid ( const G4String &  new_name)
inherited

Calls MakeSolid() and copies builder with products cleared for further construction.

Configurations from ALL stages (including later) are kept.

Parameters
new_nameThe base name for the new builder's Geant products.
Returns
A shared pointer to the new builder instance.

Definition at line 510 of file VolumeBuilderBase.hpp.

665 {
666 NoNameCheck(new_name, "ForkForFinalSolid");
667 if (!solid_ptr_) {
668 MakeSolid();
669 }
670 DerivedPtr copy = this->Clone();
671 copy->SetName(new_name); // Set base name for derived class
672 copy->SetBooleanName("");
673 // all products are cleared by default, (re)build up to Solid
674 copy->solid_ptr_.Link(this->solid_ptr_);
675 return copy;
676 }

◆ ForkForLogicalVolume()

VolumeBuilderBase< VolumeBuilderCore >::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.

Definition at line 525 of file VolumeBuilderBase.hpp.

679 {
680 NoNameCheck(new_name, "ForkForLogicalVolume");
681 if (!final_solid_ptr_ && placement_configs_->is_builder) {
682 [[maybe_unused]] auto discard = GetFinalSolid();
683 }
684 DerivedPtr copy = this->Clone();
685 copy->SetName(new_name); // Set base name for derived class
686 copy->SetBooleanName("");
687 // all products are cleared by default, (re)build up to Solid
688 if (solid_ptr_ && placement_configs_->is_builder) {
689 copy->solid_ptr_.Link(this->solid_ptr_);
690 }
691 if (final_solid_ptr_ && placement_configs_->is_builder) {
692 copy->final_solid_ptr_.Link(this->final_solid_ptr_);
693 }
694 return copy;
695 }
G4VSolid * GetFinalSolid() final
Gets a complete final built Solid, including configured Boolean operaions if any.

◆ ForkForPlacement()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr ForkForPlacement ( std::optional< int >  copy_no = std::nullopt,
const G4String &  name_override = "",
bool  parent_name_was_set = false 
)
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.

Definition at line 542 of file VolumeBuilderBase.hpp.

699 {
700 // really a clone of logical volume:
701 if (!logicvol_ptr_ && placement_configs_->is_builder) {
703 }
704 DerivedPtr copy = this->Clone();
705 copy->explicit_copyno_set_ = static_cast<bool>(copy_no);
706 copy->explicit_physical_copy_name_set_ = !name_override.empty() || parent_name_was_set;
707 copy->placement_name_override_ = name_override;
708 // register name and get provisional copy_no:
709 copy->placement_configs_->copy_no = PlacementNameRegistry::IncrementNameCount(
710 GetPlacementBaseName());
711 //Override if copy_no was passed:
712 copy->placement_configs_->copy_no = copy_no.value_or(copy->placement_configs_->copy_no);
713
714 // Restore logical_volume pointer and below
715 copy->solid_ptr_.Link(this->solid_ptr_);
716 copy->final_solid_ptr_.Link(this->final_solid_ptr_);
717 copy->logicvol_ptr_.Link(this->logicvol_ptr_);
718
719 return copy;
720 }
DerivedPtr MakeLogicalVolume(const VBHelpers::G4MaterialPtrOrString &material={}, G4String name=std::string())
Basically never needed now.

◆ GetBaseSolid()

G4VSolid * GetBaseSolid ( )
finalvirtualinherited

You probably want GetSolid() instead!!! This Gets a built Solid, BUT NOT final Boolean.

Builds default if not built yet.

Even if you aren't doing boolean now, if you add it later, this method will miss it. GetFinalSolid() is more general.

Returns
Raw visitor pointer to the solid. (DON'T DELETE IT!)

Implements IVolumeBuilder.

Definition at line 138 of file VolumeBuilderBase.hpp.

162 {
163 if (!this->solid_ptr_) {
164 MakeSolid();
165 }
166 return solid_ptr_.get_mutable();
167 }

◆ GetBuilderName()

G4String GetBuilderName ( ) const
inherited

Definition at line 639 of file VolumeBuilderBase.hpp.

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

◆ GetEffectiveDefaultUnit()

VB::Length GetEffectiveDefaultUnit ( ) const
inherited

Get the builder default unit or global if not set.

Returns
The active default unit.

Definition at line 602 of file VolumeBuilderBase.hpp.

905 {
906 auto temp = builder_configs_.get();
907 auto local = temp->default_unit;
908 // auto local = builder_configs_->default_unit;
909 auto global = DLG4::Units::global_default_unit<DLG4::Units::Length>;
910 G4double default_unit = local.value_or(global);
911 return Length(default_unit,Length::native);
912 }

◆ GetFinalSolid()

G4VSolid * GetFinalSolid ( )
finalvirtualinherited

Gets a complete final built Solid, including configured Boolean operaions if any.

Builds default if not built yet.

Returns
Raw visitor pointer to the solid. (DON'T DELETE IT!)

Implements IVolumeBuilder.

Definition at line 146 of file VolumeBuilderBase.hpp.

295 {
296 if (!final_solid_ptr_ && placement_configs_->is_builder) {
297 MakeFinalSolid(std::string("")); // checks are done in there.
298 }
299 // should probably have a check here, although it's a bug anyway if not built now.
300 return this->final_solid_ptr_;
301 }

◆ GetLogicalVolume()

G4LogicalVolume * GetLogicalVolume ( )
finalvirtualinherited

Gets a built LogicalVolume, builds default if not built yet.

Returns
Raw visitor pointer to the logical volume (DON'T DELETE IT!)

Implements IVolumeBuilder.

Definition at line 126 of file VolumeBuilderBase.hpp.

178 {
179 if (!logicvol_ptr_) {
180 BASE::MakeLogicalVolume();
181 }
182 return logicvol_ptr_.get_mutable();
183 }

◆ GetPhysTransform()

G4Transform3D GetPhysTransform ( ) const
inlinefinalvirtualinherited

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.

Implements IVolumeBuilder.

Definition at line 387 of file VolumeBuilderBase.hh.

387 {
388 return {placement_configs_->rotation, placement_configs_->translation};
389 }

◆ GetPlacement()

G4VPhysicalVolume * GetPlacement ( )
finalvirtualinherited

Gets the (last) placed physical volume.

Constructs it if not built yet. Unlike MakePlacement(), this will NOT auto-trigger consecutive placments from copied builders. But you can call it again after MakePlacement() to get those.

Returns
Raw visitor pointer to physical volume. (DON'T DELETE IT).

Implements IVolumeBuilder.

Definition at line 91 of file VolumeBuilderBase.hpp.

170 {
171 if (!this->placement_) {
172 BASE::MakePlacement();
173 }
174 return this->placement_.get_mutable();
175 }

◆ MakeLogicalVolume()

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

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 160 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()

VolumeBuilderBase< VolumeBuilderCore >::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

Definition at line 101 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()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr MakeSolid ( )
inherited

Make the G4VSolid.

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

Returns
The builder

Definition at line 168 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

◆ operator=()

VolumeBuilderCore & operator= ( const VolumeBuilderCore other)
delete

◆ OverridePlacementName()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr OverridePlacementName ( const G4String &  pName)
inherited

Set the placement name for the volume.


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

Definition at line 398 of file VolumeBuilderBase.hpp.

619 {
620 explicit_physical_copy_name_set_ = static_cast<bool>(pName);
621 this->placement_name_override_ = pName;
622 return this->shared_from_this();
623 }

◆ PlaceAndFork()

DerivedPtr PlaceAndFork ( )
inlineinherited

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

Returns
The builder

Definition at line 112 of file VolumeBuilderBase.hh.

112 {
113 this->MakePlacement();
114 auto clone = this->ForkForPlacement(); // default/preset options
115 return clone;
116 }
DerivedPtr ForkForPlacement(std::optional< int > copy_no=std::nullopt, const G4String &name_override="", bool parent_name_was_set=false)
Calls MakeLogicalVolume() and creates a new builder instance with a copy of all placement-related con...

◆ ReflectZBaseSolid()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr ReflectZBaseSolid ( )
inherited

Configure base solid to be flipped BEFORE applying booleans.

See also
ReflectZFinalSolid() to flip entire solid with or without Booleans.
Returns
The same builder (allows chaining)

Definition at line 483 of file VolumeBuilderBase.hpp.

925 {
926 if (final_solid_ptr_) {
927 throw std::runtime_error("Error VolumeBuilderBase::ReflectZBaseSolid, \n"
928 "The base solid is already built. \n");
929 }
930 builder_configs_->reflect_base_solid_z = true;
931 return this->shared_from_this();
932 }

◆ ReflectZFinalSolid()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr ReflectZFinalSolid ( )
inherited

Configure final solid to be flipped in z.

Definition at line 473 of file VolumeBuilderBase.hpp.

915 {
916 if (final_solid_ptr_) {
917 throw std::runtime_error("Error VolumeBuilderBase::ReflectZFinalSolid, \n"
918 "The final solid is already built. \n");
919 }
920 boolean_configs_->reflect_z = true;
921 return this->shared_from_this();
922 }

◆ 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()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetAlpha ( G4double  alpha)
inherited
Parameters
alpha
Returns
The builder

Definition at line 259 of file VolumeBuilderBase.hpp.

419 {
420 lv_configs_->color.SetAlpha(alpha);
421 ApplyAttributes_();
422 return this->shared_from_this();
423 }

◆ SetAutoCopyNo()

VolumeBuilderBase< VolumeBuilderCore >::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

Definition at line 455 of file VolumeBuilderBase.hpp.

733 {
734 placement_configs_->auto_copyno = set;
735 if (set) {
736 placement_configs_->auto_copy_name = false;
737 }
738 return this->shared_from_this();
739 }

◆ SetAutoPlacementNaming()

VolumeBuilderBase< VolumeBuilderCore >::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

Definition at line 442 of file VolumeBuilderBase.hpp.

724 {
725 placement_configs_->auto_copy_name = set;
726 if (set) {
727 placement_configs_->auto_copyno = false;
728 }
729 return this->shared_from_this();
730 }

◆ SetBooleanName()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetBooleanName ( const G4String &  name)
inherited

Pre-set base name for logical and physical volumes.

_L and _P will be appended, respectively.

If not set, the builder will take it from the builder name. But this is useful for unions where the starting solid name may be more specific.

Parameters
name

Definition at line 302 of file VolumeBuilderBase.hpp.

156 {
157 this->boolean_configs_->boolean_name = name;
158 return this->shared_from_this();
159 }

◆ SetColor() [1/2]

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetColor ( const G4Colour &  color)
inherited
Parameters
color
Returns
The builder

Definition at line 251 of file VolumeBuilderBase.hpp.

426 {
427 lv_configs_->color = color;
428 ApplyAttributes_();
429 return this->shared_from_this();
430 }

◆ SetColor() [2/2]

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetColor ( double  r = 0.5,
double  g = 0.5,
double  b = 0.5,
double  alpha = 1.0 
)
inherited
Returns
The builder

Definition at line 243 of file VolumeBuilderBase.hpp.

412 {
413 lv_configs_->color = G4Colour(r, g, b, alpha);
414 ApplyAttributes_();
415 return this->shared_from_this();
416 }

◆ SetCopyNo()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetCopyNo ( G4int  pCopyNo)
inherited

Set the copy number for the placement.


Parameters
pCopyNoCopy number.
Returns
This builder for chaining.

Definition at line 407 of file VolumeBuilderBase.hpp.

627 {
628 explicit_copyno_set_ = static_cast<bool>(pCopyNo);
629 this->placement_configs_->copy_no = pCopyNo;
630 return this->shared_from_this();
631 }

◆ SetDefaultUnit()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetDefaultUnit ( VB::Length  unit)
inherited

Set the per-Builder 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 VB::Length::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 VB::Length unit to set, ex: VB::Length::mm
    Returns
    The builder (allows chaining)

Definition at line 595 of file VolumeBuilderBase.hpp.

899 {
900 this->builder_configs_->default_unit = unit.Native();
901 return this->shared_from_this();
902 }
PropertySetter Native
Definition DLG4Units.hh:182

◆ SetLogicalVolume()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetLogicalVolume ( G4LogicalVolume *  logical_volume)
inherited

Directly Provide a Logical Volume Instead of using the builder.

Parameters
logical_volume

Definition at line 291 of file VolumeBuilderBase.hpp.

189 {
190 SetLogicalVolume_impl(logical_volume);
191 return this->shared_from_this();
192 }

◆ SetMaterial()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetMaterial ( const VBHelpers::G4MaterialPtrOrString material)
inherited

/**

Parameters
materialG4Material* OR a string name of a local or NIST material!
Returns
The builder

Definition at line 236 of file VolumeBuilderBase.hpp.

406 {
407 lv_configs_->material = material;
408 return this->shared_from_this();
409 }

◆ SetMother()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetMother ( const VolumeBuilder 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
motherBuilderVew parameter accepts a builder or a G4VSolid through implicit ctor
Returns
This builder for chaining.

Definition at line 429 of file VolumeBuilderBase.hpp.

642 {
643 if (!mother) {
644 throw std::runtime_error("Error in VolumeBuilderBase::SetMother,"
645 "for builder named: \"" + builder_configs_->name + "\"\n"
646 " no valid mother physical volume provided");
647 // We cannot actually fully check this yet because we allow this to be a forward association
648 // The logical volume is not required to be constructable before we make a placement.
649 }
650 this->placement_configs_->mother = mother;
651 return this->shared_from_this();
652 }

◆ SetName()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetName ( const G4String &  name)
inherited

SetName Sets name used for solid and derived product names.

Parameters
nameThe name
Returns
The builder

Definition at line 175 of file VolumeBuilderBase.hpp.

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

◆ SetPhysOffset()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetPhysOffset ( const DLG4::VolumeBuilders::ThreeVecDimensioner offset = {0, 0, 0, VB::Length::mm})
inherited

Set the translation vector for placement.

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

Examples: SetPhysOffset({ 1, 2, 3, VB::cm}) // 1cm, 2cm, 3cm SetPhysOffset({1, 2, 3}) // Uses default default unit (usually mm) SetDefaultUnit(VB::cm); SetPhysOffset({1, 2, 3}) // 1cm, 2cm, 3cm // or work with raw geant values, must use CLHEP units, not VB: SetDefaultUnit(VB::native); SetPhysOffset({10*CLHEP::mm, 20*CLHEP::mm, 30*CLHEP::mm})

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

Definition at line 341 of file VolumeBuilderBase.hpp.

558 {
559 const auto &offset = ProvisionUnits(new_offset);
560 placement_configs_->translation = offset;
561 PropagateTransform();
562 return this->shared_from_this();
563 }

◆ SetPhysRotation()

VolumeBuilderBase< VolumeBuilderCore >::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.

Definition at line 311 of file VolumeBuilderBase.hpp.

535 {
536 G4RotationMatrix nullrot;
537 this->placement_configs_->rotation = rot;
538 PropagateTransform();
539 return this->shared_from_this();
540 }

◆ SetPhysTransform()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetPhysTransform ( const UnitlessG4Transform3D new_transform)
inherited

Set the G4Transform3D for placment.

The tranformation provided is meant to be in UNITLESS values. Ie the unit is already pre-configured but not included in the values. So passing 5 means 5cm if SetDefault(VB::Length::cm) was set. Otherwise you SetDefaultUnit(VB::roaw), and pass a value that was already multipled by units. To supply different units for each G4Tranform3D separately, just call SetDefaultUnit(unit) before each call. The call will overwite/replace rotation and translation.

Parameters
new_transformTranslation vector.
Returns
This builder for chaining.

Definition at line 368 of file VolumeBuilderBase.hpp.

575 {
576 SetPhysRotation(new_transform.getRotation()); // gets a copy on stack
577 SetPhysOffset({ (G4ThreeVector)new_transform.getTranslation(), GetEffectiveDefaultUnit()});
578 PropagateTransform();
579 return this->shared_from_this();
580 }
DerivedPtr SetPhysRotation(const G4RotationMatrix &rot)
Set the rotation matrix for placement.
DerivedPtr SetPhysOffset(const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm})
Set the translation vector for placement.
Length GetEffectiveDefaultUnit() const
Get the builder default unit or global if not set.

◆ SetSurfaceCheck()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetSurfaceCheck ( G4bool  pSurfChk)
inherited

Set the surface check flag for the placement.


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

Definition at line 415 of file VolumeBuilderBase.hpp.

635 {
636 this->placement_configs_->surface_check = pSurfChk;
637 return this->shared_from_this();
638 }

◆ SetVisibility()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr SetVisibility ( bool  x = true)
inherited
Parameters
x
Returns
The builder

Definition at line 274 of file VolumeBuilderBase.hpp.

440 {
441 lv_configs_->is_visible = x;
442 ApplyAttributes_();
443 return this->shared_from_this();
444 }

◆ 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()

G4VSolid * SolidConstructor ( const G4String &  name)
overridevirtual

polymorphic access to solid construction

Implements VolumeBuilderBase< VolumeBuilderCore >.

Definition at line 18 of file VolumeBuilderCore.cc.

18 {
19 if (!this->builder_configs_->istructure_ptr) {
20 throw std::runtime_error(
21 "Error in VolumeBuilderCore::VolumeBuilderCore::SolidConstructor(const G4String &name) \n"
22 "In VolumeBuilderCore::VolumeBuilderCore::SolidConstructor(const G4String &name): No solid configuration to construct on"
23 + this->builder_configs_->name);
24 }
25 return this->builder_configs_->istructure_ptr->SolidConstructor(name);
26 }

◆ StackPhysOffset()

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

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 352 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()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr StackPhysRotation ( const G4RotationMatrix &  stacked_rot)
inherited

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 323 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()

VolumeBuilderBase< VolumeBuilderCore >::DerivedPtr StackPhysTransform ( const UnitlessG4Transform3D new_transform)
inherited

Like SetPhysTransform but stacks with previous transformations in order applied.

Parameters
new_transform
Returns
The builder

Definition at line 375 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.

◆ ToVolumeBuilder()

VolumeBuilder ToVolumeBuilder ( ) const
inlineoverrideprotectedvirtual

Reimplemented from VolumeBuilderBase< VolumeBuilderCore >.

Definition at line 106 of file VolumeBuilderCore.hh.

106 {
107 // we're already type erased, so just return ourselves.
108 return shared_mutable_this(this);
109 }

Friends And Related Symbol Documentation

◆ i_shared_ptr

template<typename T >
friend class i_shared_ptr
friend

Definition at line 51 of file VolumeBuilderCore.hh.

◆ i_shared_ptr< VolumeBuilderCore >

friend class i_shared_ptr< VolumeBuilderCore >
friend

Definition at line 54 of file VolumeBuilderCore.hh.

◆ StructureBuilderBase

template<typename T >
friend class StructureBuilderBase
friend

Definition at line 48 of file VolumeBuilderCore.hh.

◆ VB::CreateAssembly

Assembly VB::CreateAssembly ( G4String  name)
friend

◆ VolumeBuilderBase

template<typename T >
friend class VolumeBuilderBase
friend

Definition at line 45 of file VolumeBuilderCore.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: