diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 6c979a911883a0c0d01ceeaa991b24659d2a4e5b..d66d2da781ba79a71839bf1775993c286ebf146a 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -1460,24 +1460,34 @@ template <> void Converter<XMLFile>::operator()(xml_h element) const { template <> void Converter<World>::operator()(xml_h element) const { xml_elt_t x_world(element); xml_comp_t x_shape = x_world.child(_U(shape), false); + xml_attr_t att = x_world.getAttr(_U(material)); + Material mat = att ? description.material(x_world.attr<string>(att)) : description.air(); Volume world_vol; /// Create the shape and the corresponding volume if ( x_shape ) { - Solid sol(x_shape.createShape()); - xml_attr_t att = x_world.getAttr(_U(material)); - Material mat = att ? description.material(x_world.attr<string>(att)) : description.air(); + Solid sol(x_shape.createShape()); world_vol = Volume("world_volume", sol, mat); - printout(INFO, "Compact", - "++ Created successfully world volume %s. shape: %s material:%s.", - world_vol.name(), sol.type(), mat.name()); + printout(INFO, "Compact", "++ Created successfully world volume '%s'. shape: %s material:%s.", + world_vol.name(), sol.type(), mat.name()); description.manager().SetTopVolume(world_vol.ptr()); } else { world_vol = description.worldVolume(); - if ( !world_vol ) { + if ( !world_vol && att ) { + /// If we require a user configured world, but no shape is given, define the standard box. + /// Implicitly assumes that the box dimensions are given in the standard way. + Box sol("world_x", "world_y", "world_z"); + world_vol = Volume("world_volume", sol, mat); + printout(INFO, "Compact", "++ Created world volume '%s' as %s (%.2f, %.2f %.2f [cm]) material:%s.", + world_vol.name(), sol.type(), + sol.x()/dd4hep::cm, sol.y()/dd4hep::cm, sol.z()/dd4hep::cm, + mat.name()); + description.manager().SetTopVolume(world_vol.ptr()); + } + else if ( !world_vol ) { except("Compact", "++ Logical error: " - "You cannot configure the world volume before it is created."); + "You cannot configure the world volume before it is created and not giving creation instructions."); } } // Delegate further configuration o0f the world volume to the xml utilities: diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt index fceccea3c295f52d91888a0dc7475c769137ceda..91bf1889e74f8624847401dde4e8db04c3592fbc 100644 --- a/examples/ClientTests/CMakeLists.txt +++ b/examples/ClientTests/CMakeLists.txt @@ -410,13 +410,21 @@ dd4hep_add_test_reg( minitel_config_plugins_include_command_xml ) # # Test setting properties to the world volume and a single sub-detector -dd4hep_add_test_reg( minitel_config_subdet +dd4hep_add_test_reg( minitel_config_world_volume COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" EXEC_ARGS geoPluginRun -input ${ClientTestsEx_INSTALL}/compact/WorldSettings.xml REGEX_PASS "\\+\\+ Applied 5 settings to MyLHCBdetector5" REGEX_FAIL "Exception;EXCEPTION;ERROR" ) # +# Test creation of the world volume with user specified material +dd4hep_add_test_reg( minitel_config_world_material + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" + EXEC_ARGS geoPluginRun -input ${ClientTestsEx_INSTALL}/compact/WorldMaterial.xml -print INFO -destroy -load + REGEX_PASS "\\+\\+ Created world volume 'world_volume' as TGeoBBox \\(50.00, 50.00 50.00 \\[cm\\]\\) material:Steel235" + REGEX_FAIL "Exception;EXCEPTION;ERROR" +) +# # Test setting properties to the world volume and a single sub-detector dd4hep_add_test_reg( minitel_config_world COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" diff --git a/examples/ClientTests/compact/WorldMaterial.xml b/examples/ClientTests/compact/WorldMaterial.xml new file mode 100644 index 0000000000000000000000000000000000000000..0b741382cfb4c32c311a327bec9d02a5a6d1baa5 --- /dev/null +++ b/examples/ClientTests/compact/WorldMaterial.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd> +<!-- #========================================================================== + # AIDA Detector description implementation + #========================================================================== + # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) + # All rights reserved. + # + # For the licensing terms see $DD4hepINSTALL/LICENSE. + # For the list of contributors see $DD4hepINSTALL/doc/CREDITS. + # + #========================================================================== +--> + + <info name="SiliconBlock" + title="Test with 2 simple silicon boxes" + author="Markus Frank" + url="http://www.cern.ch/lhcb" + status="development" + version="$Id: compact.xml 513 2013-04-05 14:31:53Z gaede $"> + <comment>Alignment test with 2 simple boxes</comment> + </info> + + <includes> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/materials.xml"/> + </includes> + + + <!-- Note: + You can either see the world volume itself (showDaughters="false") + or the children (showDaughters="true") not both. + --> + <display> + <vis name="Invisible" showDaughters="false" visible="false"/> + <vis name="InvisibleWithChildren" showDaughters="true" visible="false"/> + <vis name="WorldVis" alpha="0.8" r="1.0" g="1.0" b="0.0" showDaughters="false" visible="true" drawingStyle="solid" lineStyle="solid"/> + <vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" showDaughters="true" visible="true" drawingStyle="solid" lineStyle="solid"/> + </display> + + <define> + <constant name="world_side" value="50*cm"/> + <constant name="world_x" value="world_side"/> + <constant name="world_y" value="world_side"/> + <constant name="world_z" value="world_side"/> + </define> + + <world material="Steel235"/> + + <detectors> + <detector id="1" name="SiliconBlock" type="DD4hep_BoxSegment" vis="VisibleGreen"> + <material name="Silicon"/> + <sensitive type="tracker"/> + <box x="20*cm" y="20*cm" z="20*cm"/> + <position x="0" y="0" z="0"/> + <rotation x="0" y="0" z="0"/> + </detector> + </detectors> +</lccdd>