From 0c222649d04686a5e915da07c5cca8c7d95e4b74 Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Wed, 11 Oct 2023 14:44:22 +0200 Subject: [PATCH 1/4] G4VTouchable: for Geant4 11.1.ref09 cannot forward declare the class any more --- DDG4/include/DDG4/Geant4SensDetAction.h | 2 +- DDG4/include/DDG4/Geant4TouchableHandler.h | 3 ++- DDG4/include/DDG4/Geant4VolumeManager.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DDG4/include/DDG4/Geant4SensDetAction.h b/DDG4/include/DDG4/Geant4SensDetAction.h index a192bc366..c15040281 100644 --- a/DDG4/include/DDG4/Geant4SensDetAction.h +++ b/DDG4/include/DDG4/Geant4SensDetAction.h @@ -20,6 +20,7 @@ // Geant4 include files #include +#include // C/C++ include files #include @@ -28,7 +29,6 @@ class G4HCofThisEvent; class G4Step; class G4Event; -class G4VTouchable; class G4TouchableHistory; class G4VHitsCollection; class G4VReadOutGeometry; diff --git a/DDG4/include/DDG4/Geant4TouchableHandler.h b/DDG4/include/DDG4/Geant4TouchableHandler.h index 042f30405..0be5a58c1 100644 --- a/DDG4/include/DDG4/Geant4TouchableHandler.h +++ b/DDG4/include/DDG4/Geant4TouchableHandler.h @@ -13,13 +13,14 @@ #ifndef DDG4_GEANT4TOUCHABLEHANDLER_H #define DDG4_GEANT4TOUCHABLEHANDLER_H +#include + // C/C++ include files #include #include // Forward declarations class G4VPhysicalVolume; -class G4VTouchable; class G4Step; /// Namespace for the AIDA detector description toolkit diff --git a/DDG4/include/DDG4/Geant4VolumeManager.h b/DDG4/include/DDG4/Geant4VolumeManager.h index 6cbee9517..02027ad3e 100644 --- a/DDG4/include/DDG4/Geant4VolumeManager.h +++ b/DDG4/include/DDG4/Geant4VolumeManager.h @@ -18,8 +18,8 @@ #include #include +#include // Geant4 forward declarations -class G4VTouchable; class G4VPhysicalVolume; From fbc39bbbcb1e1590dd270dff5ee8cd66879d5a9a Mon Sep 17 00:00:00 2001 From: Markus Frank Date: Mon, 9 Oct 2023 16:28:57 +0200 Subject: [PATCH 2/4] Allow to load CAD files with relative path w/r to declaring xml file (Issue 1166) --- DDCAD/src/plugins/CADPlugins.cpp | 31 +++++++++++++++++-- examples/DDCAD/CMakeLists.txt | 2 +- .../compact/Check_Shape_RelativePath.xml | 30 ++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 examples/DDCAD/compact/Check_Shape_RelativePath.xml diff --git a/DDCAD/src/plugins/CADPlugins.cpp b/DDCAD/src/plugins/CADPlugins.cpp index 8a646ebe9..17f9c037a 100644 --- a/DDCAD/src/plugins/CADPlugins.cpp +++ b/DDCAD/src/plugins/CADPlugins.cpp @@ -20,11 +20,36 @@ #include // C/C++ include files +#include using namespace std; using namespace dd4hep; using namespace dd4hep::detail; +/// If the path to the CAD file does not directly exist try to resolve it: +static string resolve_path(xml_h e, const string& file) { + error_code errc; + std::string fname; + /// Use the xml utilities in the DocumentHandler to resolve the relative path + if ( file.length() > 7 && file.substr(0,7) == "file://" ) + fname = file.substr(7); + else + fname = file; + if ( !filesystem::exists(fname, errc) ) { + string fn = xml::DocumentHandler::system_path(e, fname); + if ( fn.length() > 7 && fn.substr(0,7) == "file://" ) + fn = fn.substr(7); + if ( !std::filesystem::exists(fn, errc) ) { + auto fp = filesystem::path(xml::DocumentHandler::system_path(e)).parent_path(); + except("CAD_Shape","+++ CAD file: %s (= %s + %s) is not accessible [%d: %s]", + fn.c_str(), fp.c_str(), fname.c_str(), + errc.value(), errc.message().c_str()); + } + return fn; + } + return fname; +} + static void* read_CAD_Volume(Detector& dsc, int argc, char** argv) { string fname; double scale = 1.0; @@ -61,7 +86,7 @@ DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_read_CAD_volumes,read_CAD_Volume) static Handle create_CAD_Shape(Detector& dsc, xml_h e) { xml_elt_t elt(e); cad::ASSIMPReader rdr(dsc); - string fname = elt.attr(_U(ref)); + string fname = resolve_path(e, elt.attr(_U(ref))); long flags = elt.hasAttr(_U(flags)) ? elt.attr(_U(flags)) : 0; double unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : dd4hep::cm; @@ -97,7 +122,7 @@ DECLARE_XML_SHAPE(CAD_Shape__shape_constructor,create_CAD_Shape) static Handle create_CAD_Assembly(Detector& dsc, xml_h e) { xml_elt_t elt(e); - string fname = elt.attr(_U(ref)); + string fname = resolve_path(e, elt.attr(_U(ref))); double unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : dd4hep::cm; auto volumes = cad::ASSIMPReader(dsc).readVolumes(fname, unit); if ( volumes.empty() ) { @@ -159,8 +184,8 @@ DECLARE_XML_VOLUME(CAD_Assembly__volume_constructor,create_CAD_Assembly) */ static Handle create_CAD_Volume(Detector& dsc, xml_h e) { xml_elt_t elt(e); - string fname = elt.attr(_U(ref)); double unit = elt.attr(_U(unit)); + string fname = resolve_path(e, elt.attr(_U(ref))); long flags = elt.hasAttr(_U(flags)) ? elt.attr(_U(flags)) : 0; cad::ASSIMPReader rdr(dsc); diff --git a/examples/DDCAD/CMakeLists.txt b/examples/DDCAD/CMakeLists.txt index 91f2d8a2f..0d9e38ec7 100644 --- a/examples/DDCAD/CMakeLists.txt +++ b/examples/DDCAD/CMakeLists.txt @@ -72,7 +72,7 @@ endforeach() # # Multi-shape tests # Not working: OBJ_spider -list(APPEND DDCAD_Tests_MV COB_dwarf MS3D_jeep) +list(APPEND DDCAD_Tests_MV COB_dwarf MS3D_jeep RelativePath) foreach (test ${DDCAD_Tests_MV}) dd4hep_add_test_reg( DDCAD_Check_Shape_${test} COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDCAD.sh" diff --git a/examples/DDCAD/compact/Check_Shape_RelativePath.xml b/examples/DDCAD/compact/Check_Shape_RelativePath.xml new file mode 100644 index 000000000..39b1627b2 --- /dev/null +++ b/examples/DDCAD/compact/Check_Shape_RelativePath.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + From 8e1d0be969e6401a67cd2aa4eb3bdb00db44e86b Mon Sep 17 00:00:00 2001 From: Alvaro Tolosa Delgado Date: Mon, 16 Oct 2023 20:48:35 +0200 Subject: [PATCH 3/4] Typo in printout fixed --- DDG4/python/DDSim/Helper/Gun.py | 2 +- DDTest/python/userSteeringFile.PY | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DDG4/python/DDSim/Helper/Gun.py b/DDG4/python/DDSim/Helper/Gun.py index 608b41f7c..c3cfb7cf7 100644 --- a/DDG4/python/DDSim/Helper/Gun.py +++ b/DDG4/python/DDSim/Helper/Gun.py @@ -35,7 +35,7 @@ def __init__(self): self.momentumMin = 0 * GeV self._momentumMax_EXTRA = {'help': "Maximal momentum when using distribution (default = 0.0)"} self.momentumMax = 10 * GeV - self._energy_EXTRA = {'help': "The kinetic energy for the particle gun.\n\n" + self._energy_EXTRA = {'help': "Total energy (including mass) for the particle gun.\n\n" "If not None, it will overwrite the setting of momentumMin and momentumMax"} self.energy = None diff --git a/DDTest/python/userSteeringFile.PY b/DDTest/python/userSteeringFile.PY index e21e6e66c..11a8eee6e 100644 --- a/DDTest/python/userSteeringFile.PY +++ b/DDTest/python/userSteeringFile.PY @@ -211,7 +211,7 @@ SIM.gun.direction = (0, 0, 1) ## SIM.gun.distribution = None -## The kinetic energy for the particle gun. +## Total energy (including mass) for the particle gun. ## ## If not None, it will overwrite the setting of momentumMin and momentumMax SIM.gun.energy = None From 88ed20d5fbf8970852ac6f462ccc63f8a626dc5d Mon Sep 17 00:00:00 2001 From: Markus Frank Date: Wed, 18 Oct 2023 11:29:28 +0200 Subject: [PATCH 4/4] Allow for XML processing of files relative to xml tag location (See issue https://github.com/AIDASoft/DD4hep/issues/1180 for details) --- DDCore/src/plugins/Compact2Objects.cpp | 33 ++++++++++++++++--- .../ClientTests/compact/IncludePlugins.xml | 4 +++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index aae992573..20a286f2b 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -50,9 +50,10 @@ #include // C/C++ include files -#include +#include #include #include +#include #include using namespace std; @@ -1443,17 +1444,38 @@ template <> void Converter::operator()(xml_h element) const { template <> void Converter::operator()(xml_h element) const { string base = xml::DocumentHandler::system_directory(element); string file = element.attr(_U(ref)); - vector argv{&file[0],&base[0]}; + vector argv{&file[0], &base[0]}; description.apply("DD4hep_JsonProcessor",int(argv.size()), &argv[0]); } /// Read alignment entries from a seperate file in one of the include sections of the geometry template <> void Converter::operator()(xml_h element) const { + PrintLevel level = s_debug.includes ? ALWAYS : DEBUG; string fname = element.attr(_U(ref)); - if ( s_debug.includes ) { - printout(ALWAYS, "Compact","++ Processing xml document %s.", fname.c_str()); + size_t idx = fname.find("://"); + std::error_code ec; + + if ( idx == string::npos && filesystem::exists(fname, ec) ) { + // Regular file without protocol specification + printout(level, "Compact","++ Processing xml document %s.", fname.c_str()); + this->description.fromXML(fname); + } + else if ( idx == string::npos ) { + // File relative to location of xml tag (protocol specification not possible) + string location = xml::DocumentHandler::system_path(element, fname); + printout(level, "Compact","++ Processing xml document %s.", location.c_str()); + this->description.fromXML(location); + } + else if ( idx > 0 ) { + // File with protocol specification: must trust the location and the parser capabilities + printout(level, "Compact","++ Processing xml document %s.", fname.c_str()); + this->description.fromXML(fname); + } + else { + // Are there any other possibilities ? + printout(level, "Compact","++ Processing xml document %s.", fname.c_str()); + this->description.fromXML(fname); } - this->description.fromXML(fname); } /// Read material entries from a seperate file in one of the include sections of the geometry @@ -1716,6 +1738,7 @@ template <> void Converter::operator()(xml_h element) const { } xml_coll_t(compact, _U(plugins)).for_each(_U(plugin), Converter (description)); xml_coll_t(compact, _U(plugins)).for_each(_U(include), Converter (description)); + xml_coll_t(compact, _U(plugins)).for_each(_U(xml), Converter (description)); } #ifdef _WIN32 diff --git a/examples/ClientTests/compact/IncludePlugins.xml b/examples/ClientTests/compact/IncludePlugins.xml index b527abfb0..08a00248b 100644 --- a/examples/ClientTests/compact/IncludePlugins.xml +++ b/examples/ClientTests/compact/IncludePlugins.xml @@ -42,6 +42,10 @@ + + + +