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

#include <VolumeBuilderReference.hh>

Collaboration diagram for VolumeBuilderReference:
[legend]

Public Member Functions

G4VSolid * SolidConstructor (const G4String &name) override
 
VolumeBuilderReferenceoperator= (const VolumeBuilderReference &other)=delete
 
G4VPhysicalVolume * GetPlacement () final
 
DerivedPtr MakePlacement ()
 
DerivedPtr PlaceAndFork ()
 
G4LogicalVolume * GetLogicalVolume () final
 
G4VSolid * GetBaseSolid () final
 
G4VSolid * GetFinalSolid () final
 
DerivedPtr MakeLogicalVolume (G4Material *material=nullptr, G4String name=std::string())
 
DerivedPtr MakeSolid ()
 
DerivedPtr SetName (const G4String &name)
 
DerivedPtr AddUnion (const BuilderView &other, const Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, G4RotationMatrix *rotation=nullptr)
 
DerivedPtr AddSubtraction (const BuilderView &other, const Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, G4RotationMatrix *rotation=nullptr)
 
DerivedPtr AddIntersection (const BuilderView &other, const Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, G4RotationMatrix *rotation=nullptr)
 
DerivedPtr AddBoolean (const BuilderView &other, bool is_subtraction=false, bool is_intersection=false, const Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, G4RotationMatrix *rotation=nullptr)
 
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 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 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 &new_transform)
 
G4Transform3D GetPhysTransform () const final
 
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 ReflectZFinalSolid ()
 
DerivedPtr ReflectZBaseSolid ()
 
virtual 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 BuilderView &other)
 
DerivedPtr CopyVolumeConfigsFrom (const BuilderView &other)
 
DerivedPtr SetDefaultUnit (G4double unit)
 
G4double GetEffectiveDefaultUnit () const
 
DerivedPtr AddTo (BuilderViewList &list) const
 
DerivedPtr AddTo (StructureViewList &list) const
 
DerivedPtr AddTo (AssemblyPtr &assembly) const
 
StructureView ToStructureView () const override
 
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
 
BuilderView ToBuilderView () const override
 

Protected Attributes

std::atomic< bool > is_enabled_ {true}
 

Friends

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

Detailed Description

A polymorphic, type-erased builder referencing 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<VolumeBuilderReference> ( pointer-wrapped builder). Or pass your builder to something expecting a VolumeBuilderReferencePtr, like ex: a std::vector<VolumeBuilderReferencePtr>, aka a VolumeBuilderRefList.

See also
VolumeBuilder for inherited methods.

Definition at line 39 of file VolumeBuilderReference.hh.

Member Function Documentation

◆ AddBoolean()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr AddBoolean ( const BuilderView other,
bool  is_subtraction = false,
bool  is_intersection = false,
const Unit3Vec offset = {CLHEP::mm, 0, 0, 0},
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 VolumeReferencePtr
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 218 of file VolumeBuilder.hpp.

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

◆ AddIntersection()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr AddIntersection ( const BuilderView other,
const Unit3Vec offset = {CLHEP::mm, 0, 0, 0},
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 VolumeReferencePtr
offsetOffset applied to solid
rotationApplied to solid
Returns
The builder

Definition at line 202 of file VolumeBuilder.hpp.

268 {
269 if (other) {
270 bool is_subtraction = false;
271 bool is_intersection = true;
272 AddBoolean(other, is_subtraction, is_intersection, new_offset, rotation);
273 } else {
274 throw std::runtime_error("Error in AddBoolean() "
275 "for builder named: \"" + builder_configs_->name + "\"\n"
276 " volume is invalid (null)");
277 }
278 return this->shared_from_this();
279 }
DerivedPtr AddBoolean(const BuilderView &other, bool is_subtraction=false, bool is_intersection=false, const Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, G4RotationMatrix *rotation=nullptr)
Add a boolean operation.

◆ AddSubtraction()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr AddSubtraction ( const BuilderView other,
const Unit3Vec offset = {CLHEP::mm, 0, 0, 0},
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 VolumeReferencePtr
offsetOffset applied to solid
rotationApplied to solid
Returns
The builder

Definition at line 198 of file VolumeBuilder.hpp.

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

◆ AddTo() [1/3]

VolumeBuilder< VolumeBuilderReference >::DerivedPtr AddTo ( AssemblyPtr assembly) const
inherited

Add the builder an assembly geometrically joined manipulation.

Parameters
assemblyThe assembly to add to.
Returns
the builder

Definition at line 625 of file VolumeBuilder.hpp.

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

◆ AddTo() [2/3]

VolumeBuilder< VolumeBuilderReference >::DerivedPtr AddTo ( BuilderViewList list) const
inherited

Definition at line 607 of file VolumeBuilder.hpp.

1005 {
1006 list.emplace_back(this->ToBuilderView());
1007 auto retval = shared_mutable_this(this);
1008 return retval;
1009 }

◆ AddTo() [3/3]

VolumeBuilder< VolumeBuilderReference >::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 616 of file VolumeBuilder.hpp.

1012 {
1013 list.emplace_back(this->ToStructureView());
1014 auto retval = shared_mutable_this(this);
1015 return retval;
1016 }

◆ AddUnion()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr AddUnion ( const BuilderView other,
const Unit3Vec offset = {CLHEP::mm, 0, 0, 0},
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 VolumeReferencePtr
offsetOffset applied to solid
rotationApplied to solid
Returns
The builder

Definition at line 194 of file VolumeBuilder.hpp.

244 {
245 bool is_subtraction = false;
246 bool is_intersection = false;
247 AddBoolean(other, is_subtraction, is_intersection, new_offset, rotation);
248 return this->shared_from_this();
249 }

◆ clone_impl()

SharedPtr< IStructureBuilder > clone_impl ( ) const
overrideprotectedvirtual

Reimplemented from VolumeBuilder< VolumeBuilderReference >.

Definition at line 60 of file VolumeBuilderReference.cc.

60 {
61 // have the erased base clone itself:
62 auto copy = builder_configs_->istructure_ptr->clone_impl();
63 // Then have it create a builderPtr from itself:
64 auto builder_view = copy->ToBuilderView();
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()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr CopyPlacementConfigsFrom ( const BuilderView 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 560 of file VolumeBuilder.hpp.

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

◆ CopyVolumeConfigsFrom()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr CopyVolumeConfigsFrom ( const BuilderView 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 571 of file VolumeBuilder.hpp.

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

◆ ForceSolid()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr ForceSolid ( bool  x = true)
inherited
Returns
The builder

Definition at line 263 of file VolumeBuilder.hpp.

436 {
437 lv_configs_->force_solid = x;
438 ApplyAttributes_();
439 return this->shared_from_this();
440 }

◆ ForkAndReset()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr ForkAndReset ( const G4String &  new_name) const
virtualinherited

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 494 of file VolumeBuilder.hpp.

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

◆ ForkForFinalSolid()

VolumeBuilder< VolumeBuilderReference >::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 505 of file VolumeBuilder.hpp.

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

◆ ForkForLogicalVolume()

VolumeBuilder< VolumeBuilderReference >::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 520 of file VolumeBuilder.hpp.

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

◆ ForkForPlacement()

VolumeBuilder< VolumeBuilderReference >::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 537 of file VolumeBuilder.hpp.

702 {
703 // really a clone of logical volume:
704 if (!logicvol_ptr_ && placement_configs_->is_builder) {
706 }
707 DerivedPtr copy = this->Clone();
708 copy->explicit_copyno_set_ = static_cast<bool>(copy_no);
709 copy->explicit_physical_copy_name_set_ = !name_override.empty() || parent_name_was_set;
710 copy->placement_name_override_ = name_override;
711 // register name and get provisional copy_no:
712 copy->placement_configs_->copy_no = PlacementNameRegistry::IncrementNameCount(
713 GetPlacementBaseName());
714 //Override if copy_no was passed:
715 copy->placement_configs_->copy_no = copy_no.value_or(copy->placement_configs_->copy_no);
716
717 // Restore logical_volume pointer and below
718 copy->solid_ptr_.Link(this->solid_ptr_);
719 copy->final_solid_ptr_.Link(this->final_solid_ptr_);
720 copy->logicvol_ptr_.Link(this->logicvol_ptr_);
721
722 return copy;
723 }
DerivedPtr MakeLogicalVolume(G4Material *material=nullptr, 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 135 of file VolumeBuilder.hpp.

165 {
166 if (!this->solid_ptr_) {
167 MakeSolid();
168 }
169 return solid_ptr_.get_mutable();
170 }
T * get_mutable() const
Definition Linkable.hh:287

◆ GetBuilderName()

G4String GetBuilderName ( ) const
inherited

Definition at line 637 of file VolumeBuilder.hpp.

973 {
974 return this->builder_configs_->name;
975 }

◆ GetEffectiveDefaultUnit()

G4double GetEffectiveDefaultUnit ( ) const
inherited

Get the builder default unit or global if not set.

Returns
The active default unit.

Definition at line 597 of file VolumeBuilder.hpp.

908 {
909 auto temp = builder_configs_.get();
910 auto local = temp->default_unit;
911 // auto local = builder_configs_->default_unit;
912 auto global = BuilderConfigs::global_default_unit;
913 G4double default_unit = local.value_or(global);
914 return default_unit;
915 }

◆ 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 143 of file VolumeBuilder.hpp.

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

◆ 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 123 of file VolumeBuilder.hpp.

181 {
182 if (!logicvol_ptr_) {
183 BASE::MakeLogicalVolume();
184 }
185 return logicvol_ptr_.get_mutable();
186 }

◆ 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 383 of file VolumeBuilder.hh.

383 {
384 return {placement_configs_->rotation, placement_configs_->translation};
385 }

◆ 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 88 of file VolumeBuilder.hpp.

173 {
174 if (!this->placement_) {
175 BASE::MakePlacement();
176 }
177 return this->placement_.get_mutable();
178 }

◆ MakeLogicalVolume()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr MakeLogicalVolume ( G4Material *  material = nullptr,
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
materialPointer to material to use.
nameOptional explicit name for logical volume. Normally already derived from builder/solid name.
Returns
This builder.

Definition at line 157 of file VolumeBuilder.hpp.

129 {
130 ValidateForVolumeBuild(STRINGIFY(BASE) "MakeLogicalVolume");
131 //if no volume was previously built, should be safe to reset material.
132 if (material) {
133 lv_configs_->material = material;
134 }
135 if (name.empty()) {
136 name = this->GetLogicVolName() + "_L";
137 }
138 // Implicit construction through
139 // ctor args..
140 logicvol_ptr_.ConstructAndLink(final_solid_ptr_,
141 lv_configs_->material,
142 name);
143
144 ApplyAttributes_();
145 return this->shared_from_this();
146 }
#define STRINGIFY(x)
#define BASE
void ConstructAndLink(Args &&... args)
Link and own a T and link to it.
Definition Linkable.hh:278

◆ MakePlacement()

VolumeBuilder< VolumeBuilderReference >::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 98 of file VolumeBuilder.hpp.

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

◆ MakeSolid()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr MakeSolid ( )
inherited

Make the G4VSolid.

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

Returns
The builder

Definition at line 165 of file VolumeBuilder.hpp.

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

◆ operator=()

VolumeBuilderReference & operator= ( const VolumeBuilderReference other)
delete

◆ OverridePlacementName()

VolumeBuilder< VolumeBuilderReference >::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 394 of file VolumeBuilder.hpp.

622 {
623 explicit_physical_copy_name_set_ = static_cast<bool>(pName);
624 this->placement_name_override_ = pName;
625 return this->shared_from_this();
626 }

◆ 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 109 of file VolumeBuilder.hh.

109 {
110 this->MakePlacement();
111 auto clone = this->ForkForPlacement(); // default/preset options
112 return clone;
113 }
DerivedPtr MakePlacement()
Make a placed physical volume.
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()

VolumeBuilder< VolumeBuilderReference >::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 478 of file VolumeBuilder.hpp.

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

◆ ReflectZFinalSolid()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr ReflectZFinalSolid ( )
inherited

Configure final solid to be flipped in z.

Definition at line 468 of file VolumeBuilder.hpp.

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

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

VolumeBuilder< VolumeBuilderReference >::DerivedPtr SetAlpha ( G4double  alpha)
inherited
Parameters
alpha
Returns
The builder

Definition at line 256 of file VolumeBuilder.hpp.

422 {
423 lv_configs_->color.SetAlpha(alpha);
424 ApplyAttributes_();
425 return this->shared_from_this();
426 }

◆ SetAutoCopyNo()

VolumeBuilder< VolumeBuilderReference >::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 451 of file VolumeBuilder.hpp.

736 {
737 placement_configs_->auto_copyno = set;
738 if (set) {
739 placement_configs_->auto_copy_name = false;
740 }
741 return this->shared_from_this();
742 }

◆ SetAutoPlacementNaming()

VolumeBuilder< VolumeBuilderReference >::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 438 of file VolumeBuilder.hpp.

727 {
728 placement_configs_->auto_copy_name = set;
729 if (set) {
730 placement_configs_->auto_copyno = false;
731 }
732 return this->shared_from_this();
733 }

◆ SetBooleanName()

VolumeBuilder< VolumeBuilderReference >::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 299 of file VolumeBuilder.hpp.

159 {
160 this->boolean_configs_->boolean_name = name;
161 return this->shared_from_this();
162 }

◆ SetColor() [1/2]

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

Definition at line 248 of file VolumeBuilder.hpp.

429 {
430 lv_configs_->color = color;
431 ApplyAttributes_();
432 return this->shared_from_this();
433 }

◆ SetColor() [2/2]

VolumeBuilder< VolumeBuilderReference >::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 240 of file VolumeBuilder.hpp.

415 {
416 lv_configs_->color = G4Colour(r, g, b, alpha);
417 ApplyAttributes_();
418 return this->shared_from_this();
419 }

◆ SetCopyNo()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr SetCopyNo ( G4int  pCopyNo)
inherited

Set the copy number for the placement.


Parameters
pCopyNoCopy number.
Returns
This builder for chaining.

Definition at line 403 of file VolumeBuilder.hpp.

630 {
631 explicit_copyno_set_ = static_cast<bool>(pCopyNo);
632 this->placement_configs_->copy_no = pCopyNo;
633 return this->shared_from_this();
634 }

◆ SetDefaultUnit()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr SetDefaultUnit ( G4double  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 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)

Definition at line 590 of file VolumeBuilder.hpp.

902 {
903 this->builder_configs_->default_unit = unit;
904 return this->shared_from_this();
905 }

◆ SetLogicalVolume()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr SetLogicalVolume ( G4LogicalVolume *  logical_volume)
inherited

Directly Provide a Logical Volume Instead of using the builder.

Parameters
logical_volume

Definition at line 288 of file VolumeBuilder.hpp.

192 {
193 SetLogicalVolume_impl(logical_volume);
194 return this->shared_from_this();
195 }

◆ SetMaterial()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr SetMaterial ( G4Material *  material)
inherited

/**

Parameters
material
Returns
The builder

Definition at line 233 of file VolumeBuilder.hpp.

409 {
410 lv_configs_->material = material;
411 return this->shared_from_this();
412 }

◆ SetMother()

VolumeBuilder< VolumeBuilderReference >::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.

Definition at line 425 of file VolumeBuilder.hpp.

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

◆ SetName()

VolumeBuilder< VolumeBuilderReference >::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 172 of file VolumeBuilder.hpp.

403 {
404 this->builder_configs_->name = name;
405 return this->shared_from_this();
406 }

◆ SetPhysOffset()

VolumeBuilder< VolumeBuilderReference >::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.

Definition at line 338 of file VolumeBuilder.hpp.

561 {
562 const auto &offset = ProvisionUnits(new_offset);
563 placement_configs_->translation = offset;
564 PropagateTransform();
565 return this->shared_from_this();
566 }

◆ SetPhysRotation()

VolumeBuilder< VolumeBuilderReference >::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 308 of file VolumeBuilder.hpp.

538 {
539 G4RotationMatrix nullrot;
540 this->placement_configs_->rotation = rot;
541 PropagateTransform();
542 return this->shared_from_this();
543 }

◆ SetPhysTransform()

VolumeBuilder< VolumeBuilderReference >::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.

Definition at line 364 of file VolumeBuilder.hpp.

578 {
579 SetPhysRotation(new_transform.getRotation()); // gets a copy on stack
580 SetPhysOffset({GetEffectiveDefaultUnit(), new_transform.getTranslation()});
581 PropagateTransform();
582 return this->shared_from_this();
583 }
DerivedPtr SetPhysOffset(const Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
Set the translation vector for placement.
DerivedPtr SetPhysRotation(const G4RotationMatrix &rot)
Set the rotation matrix for placement.
G4double GetEffectiveDefaultUnit() const
Get the builder default unit or global if not set.

◆ SetSurfaceCheck()

VolumeBuilder< VolumeBuilderReference >::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 411 of file VolumeBuilder.hpp.

638 {
639 this->placement_configs_->surface_check = pSurfChk;
640 return this->shared_from_this();
641 }

◆ SetVisibility()

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

Definition at line 271 of file VolumeBuilder.hpp.

443 {
444 lv_configs_->is_visible = x;
445 ApplyAttributes_();
446 return this->shared_from_this();
447 }

◆ 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 VolumeBuilder< VolumeBuilderReference >.

Definition at line 18 of file VolumeBuilderReference.cc.

18 {
19 if (!this->builder_configs_->istructure_ptr) {
20 throw std::runtime_error(
21 "Error in VolumeBuilderReference::VolumeBuilderReference::SolidConstructor(const G4String &name) \n"
22 "In VolumeBuilderReference::VolumeBuilderReference::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()

VolumeBuilder< VolumeBuilderReference >::DerivedPtr StackPhysOffset ( const Unit3Vec offset = {CLHEP::mm, 0, 0, 0})
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 349 of file VolumeBuilder.hpp.

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

◆ StackPhysRotation()

VolumeBuilder< VolumeBuilderReference >::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 320 of file VolumeBuilder.hpp.

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

◆ StackPhysTransform()

VolumeBuilder< VolumeBuilderReference >::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 371 of file VolumeBuilder.hpp.

586 {
587 //order matters when stacking. Not when "setting"
588 StackPhysRotation(new_transform.getRotation()); // gets a copy on stack
589 StackPhysOffset({GetEffectiveDefaultUnit(), new_transform.getTranslation()});
590 PropagateTransform();
591 return this->shared_from_this();
592 }
DerivedPtr StackPhysOffset(const Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
Like SetPhysOffset but stacks with previous transformations in order applied.
DerivedPtr StackPhysRotation(const G4RotationMatrix &stacked_rot)
Like SetPhysRotation but stacks with previous transformations in order applied.

◆ ToBuilderView()

BuilderView ToBuilderView ( ) const
inlineoverrideprotectedvirtual

Reimplemented from VolumeBuilder< VolumeBuilderReference >.

Definition at line 102 of file VolumeBuilderReference.hh.

102 {
103 // we're already type erased, so just return ourselves.
104 return shared_mutable_this(this);
105 }

◆ ToStructureView()

StructureView ToStructureView ( ) const
overridevirtualinherited

Implements IStructureBuilder.

Definition at line 635 of file VolumeBuilder.hpp.

988 {
989 // calls the structure view copy/convert ctor:
990 std::shared_ptr<U> builder_std_ptr =
991 std::const_pointer_cast<U>(this->shared_from_this());
992 auto x = DerivedPtr(builder_std_ptr);
993 return StructureView(x);
994 }
SharedPtr< StructureBuilderReference > StructureView
Common interface for all structure types.

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 47 of file VolumeBuilderReference.hh.

◆ i_shared_ptr< VolumeBuilderReference >

friend class i_shared_ptr< VolumeBuilderReference >
friend

Definition at line 50 of file VolumeBuilderReference.hh.

◆ StructureBuilder

template<typename T >
friend class StructureBuilder
friend

Definition at line 44 of file VolumeBuilderReference.hh.

◆ VolumeBuilder

template<typename T >
friend class VolumeBuilder
friend

Definition at line 41 of file VolumeBuilderReference.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: