644 template <
typename U>
647 throw std::runtime_error(
"Error in VolumeBuilder::SetMother,"
648 "for builder named: \"" + builder_configs_->name +
"\"\n"
649 " no valid mother physical volume provided");
653 this->placement_configs_->mother = mother;
654 return this->shared_from_this();
658 template <
typename U>
659 DERIVED BASE::ForkAndReset(
const G4String &new_name)
const {
660 NoNameCheck(new_name,
"CopySolidBuilder");
662 copy->SetName(new_name);
663 copy->SetBooleanName(
"");
667 template <
typename U>
668 DERIVED BASE::ForkForFinalSolid(
const G4String &new_name) {
669 NoNameCheck(new_name,
"ForkForFinalSolid");
674 copy->SetName(new_name);
675 copy->SetBooleanName(
"");
677 copy->solid_ptr_.Link(this->solid_ptr_);
681 template <
typename U>
682 DERIVED BASE::ForkForLogicalVolume(
const G4String &new_name) {
683 NoNameCheck(new_name,
"ForkForLogicalVolume");
684 if (!final_solid_ptr_ && placement_configs_->is_builder) {
685 [[maybe_unused]]
auto discard = GetFinalSolid();
688 copy->SetName(new_name);
689 copy->SetBooleanName(
"");
691 if (solid_ptr_ && placement_configs_->is_builder) {
692 copy->solid_ptr_.Link(this->solid_ptr_);
694 if (final_solid_ptr_ && placement_configs_->is_builder) {
695 copy->final_solid_ptr_.Link(this->final_solid_ptr_);
700 template <
typename U>
701 DERIVED BASE::ForkForPlacement(std::optional<int> copy_no,
702 const G4String &name_override,
bool parent_name_was_set) {
704 if (!logicvol_ptr_ && placement_configs_->is_builder) {
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;
712 copy->placement_configs_->copy_no = PlacementNameRegistry::IncrementNameCount(
713 GetPlacementBaseName());
715 copy->placement_configs_->copy_no = copy_no.value_or(copy->placement_configs_->copy_no);
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_);
726 template <
typename U>
727 DERIVED BASE::SetAutoPlacementNaming(
const bool set) {
728 placement_configs_->auto_copy_name = set;
730 placement_configs_->auto_copyno =
false;
732 return this->shared_from_this();
735 template <
typename U>
737 placement_configs_->auto_copyno = set;
739 placement_configs_->auto_copy_name =
false;
741 return this->shared_from_this();
746 template <
typename U>
747 G4String BASE::GetPlacementBaseName()
const {
750 G4String base_name = boolean_configs_->boolean_name;
751 if (base_name.empty()) {
752 if (builder_configs_->name.empty()) {
753 if (placement_name_override_.empty()) {
754 throw std::runtime_error(
"Err in DLG4::VolumeBuilders::"
755 "for builder named: \"" + builder_configs_->name +
757 "GetPlacementBaseName\n"
758 "No names are defined. Cannot build");
760 base_name = placement_name_override_;
763 base_name = builder_configs_->name;
767 if (!placement_configs_->parent_name.empty()) {
768 base_name = placement_configs_->parent_name +
":" + base_name;
774 template <
typename U>
776 this->placement_configs_ = other->placement_configs_;
780 return this->shared_from_this();
783 template <
typename U>
787 auto name = this->builder_configs_->name;
788 auto booleans = this->boolean_configs_->booleans;
789 this->lv_configs_ = other->lv_configs_;
791 this->builder_configs_->name = name;
792 this->boolean_configs_->booleans = booleans;
793 return this->shared_from_this();
797 template <
typename U>
798 void BASE::make_persistent(
const std::shared_ptr<void> &obj) {
803 template <
typename U>
804 void BASE::ValidateSolidNotBuilt(
const std::string &operation)
const {
806 throw std::runtime_error(
"Cannot " + operation +
" - solid already built "
807 "for builder named: \"" + builder_configs_->name +
"\"\n"
812 template <
typename U>
813 void BASE::ValidateBooleanNotBuilt(
const std::string &operation)
const {
814 if (final_solid_ptr_) {
815 throw std::runtime_error(
"Cannot " + operation +
" - boolean already built!"
816 "for builder named: \"" + builder_configs_->name +
"\"\n"
821 template <
typename U>
822 void BASE::ValidateLogicalNotBuilt(
const std::string &operation)
const {
824 throw std::runtime_error(
"Cannot " + operation +
" - logical volume already built!"
825 "for builder named: \"" + builder_configs_->name +
"\"\n"
830 template <
typename U>
831 void BASE::ValidatePlacementNotBuilt(
const std::string &operation)
const {
833 throw std::runtime_error(
"Cannot " + operation +
" - placement already built!"
834 "for builder named: \"" + builder_configs_->name +
"\"\n"
842 template <
typename U>
843 void BASE::ValidateForPVBuild(std::string
const &site) {
845 throw std::runtime_error(
">>> Error in " + site +
" Physical Volume was already built\n"
846 "for builder named: \"" + builder_configs_->name +
"\"\n"
847 "Use ForkForPlacement to copy and rebuild.");
850 if (!logicvol_ptr_ && enable_full_lazy_builds && placement_configs_->is_builder) {
853 if (!logicvol_ptr_ && placement_configs_->is_builder) {
854 throw std::runtime_error(
855 "Error in " + site +
": LogicVolume is null after MakeLogicalVolume()."
856 "for builder named: \"" + builder_configs_->name +
"\"\n"
861 template <
typename U>
862 void BASE::ValidateForVolumeBuild(std::string
const &site) {
864 std::string error =
"Error in " + site +
" Booleans were already built\n"
865 "for builder named: \"" + builder_configs_->name +
"\"\n"
866 "You can copy and rename the builder to reset it and build again.\n";
867 throw std::runtime_error(error);
870 if (!final_solid_ptr_ && enable_full_lazy_builds && placement_configs_->is_builder) {
873 if (!final_solid_ptr_ && placement_configs_->is_builder) {
875 throw std::runtime_error(
876 "Error in ValidateForVolumeBuild from " + site +
877 "for builder named: \"" + builder_configs_->name +
"\"\n"
878 ": It's not possible to produce this error.");
882 template <
typename U>
883 void BASE::ValidateForBooleanBuild(std::string
const &site) {
884 if (final_solid_ptr_) {
885 std::string error =
"Error in " + site +
" A solid was already built\n"
886 "for builder named: \"" + builder_configs_->name +
"\"\n"
887 "You can copy and rename the builder to reset it and build again.";
888 throw std::runtime_error(error);
891 if (!solid_ptr_ && enable_full_lazy_builds && placement_configs_->is_builder) {
894 if (!solid_ptr_ && placement_configs_->is_builder) {
895 throw std::runtime_error(
"Error in " + site +
": "
896 "for builder named: \"" + builder_configs_->name +
"\"\n"
897 "Solid is null after MakeSolid().");
901 template <
typename U>
903 this->builder_configs_->default_unit = unit;
904 return this->shared_from_this();
907 template <
typename U>
908 G4double BASE::GetEffectiveDefaultUnit()
const {
909 auto temp = builder_configs_.get();
910 auto local = temp->default_unit;
913 G4double default_unit = local.value_or(global);
917 template <
typename U>
919 if (final_solid_ptr_) {
920 throw std::runtime_error(
"Error VolumeBuilder::ReflectZFinalSolid, \n"
921 "The final solid is already built. \n");
923 boolean_configs_->reflect_z =
true;
924 return this->shared_from_this();
927 template <
typename U>
929 if (final_solid_ptr_) {
930 throw std::runtime_error(
"Error VolumeBuilder::ReflectZBaseSolid, \n"
931 "The base solid is already built. \n");
933 builder_configs_->reflect_base_solid_z =
true;
934 return this->shared_from_this();
937 template <
typename U>
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));
945 solid = SolidConstructor(final_name);
947 solid_ptr_.LinkToRaw(solid);
948 return this->shared_from_this();
954 template <
typename U>
955 G4ThreeVector BASE::ProvisionUnits(
const Unit3Vec &vec)
const {
960 template <
typename U>
961 void BASE::StoreIStructurePtr(
const IStructurePtr &istructure_ptr) {
963 builder_configs_->istructure_ptr =
IStructurePtr(istructure_ptr);
966 template <
typename U>
967 void BASE::StoreBuilderView(
const BuilderView &builder_view) {
969 builder_configs_->builder_view = builder_view;
972 template <
typename U>
973 G4String BASE::GetBuilderName()
const {
974 return this->builder_configs_->name;
977 template <
typename U>
981 std::shared_ptr<U> builder_std_ptr =
982 std::const_pointer_cast<U>(this->shared_from_this());
987 template <
typename U>
990 std::shared_ptr<U> builder_std_ptr =
991 std::const_pointer_cast<U>(this->shared_from_this());
996 template <
typename U>
998 const U &derived_ref =
static_cast<const U &
>(*this);
999 auto retval =
new U(derived_ref);