Skip to content

Commit

Permalink
Merge branch 'master' into optical_tracker_SDAction
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch authored Oct 18, 2023
2 parents ee49446 + 88ed20d commit 6725f8d
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 14 deletions.
31 changes: 28 additions & 3 deletions DDCAD/src/plugins/CADPlugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,36 @@
#include <DDCAD/ASSIMPWriter.h>

// C/C++ include files
#include <filesystem>

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;
Expand Down Expand Up @@ -61,7 +86,7 @@ DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_read_CAD_volumes,read_CAD_Volume)
static Handle<TObject> create_CAD_Shape(Detector& dsc, xml_h e) {
xml_elt_t elt(e);
cad::ASSIMPReader rdr(dsc);
string fname = elt.attr<string>(_U(ref));
string fname = resolve_path(e, elt.attr<string>(_U(ref)));
long flags = elt.hasAttr(_U(flags)) ? elt.attr<long>(_U(flags)) : 0;
double unit = elt.hasAttr(_U(unit)) ? elt.attr<double>(_U(unit)) : dd4hep::cm;

Expand Down Expand Up @@ -97,7 +122,7 @@ DECLARE_XML_SHAPE(CAD_Shape__shape_constructor,create_CAD_Shape)

static Handle<TObject> create_CAD_Assembly(Detector& dsc, xml_h e) {
xml_elt_t elt(e);
string fname = elt.attr<string>(_U(ref));
string fname = resolve_path(e, elt.attr<string>(_U(ref)));
double unit = elt.hasAttr(_U(unit)) ? elt.attr<double>(_U(unit)) : dd4hep::cm;
auto volumes = cad::ASSIMPReader(dsc).readVolumes(fname, unit);
if ( volumes.empty() ) {
Expand Down Expand Up @@ -159,8 +184,8 @@ DECLARE_XML_VOLUME(CAD_Assembly__volume_constructor,create_CAD_Assembly)
*/
static Handle<TObject> create_CAD_Volume(Detector& dsc, xml_h e) {
xml_elt_t elt(e);
string fname = elt.attr<string>(_U(ref));
double unit = elt.attr<double>(_U(unit));
string fname = resolve_path(e, elt.attr<string>(_U(ref)));
long flags = elt.hasAttr(_U(flags)) ? elt.attr<long>(_U(flags)) : 0;
cad::ASSIMPReader rdr(dsc);

Expand Down
33 changes: 28 additions & 5 deletions DDCore/src/plugins/Compact2Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
#include <TMath.h>

// C/C++ include files
#include <climits>
#include <filesystem>
#include <iostream>
#include <iomanip>
#include <climits>
#include <set>

using namespace std;
Expand Down Expand Up @@ -1443,17 +1444,38 @@ template <> void Converter<IncludeFile>::operator()(xml_h element) const {
template <> void Converter<JsonFile>::operator()(xml_h element) const {
string base = xml::DocumentHandler::system_directory(element);
string file = element.attr<string>(_U(ref));
vector<char*> argv{&file[0],&base[0]};
vector<char*> 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<XMLFile>::operator()(xml_h element) const {
PrintLevel level = s_debug.includes ? ALWAYS : DEBUG;
string fname = element.attr<string>(_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
Expand Down Expand Up @@ -1716,6 +1738,7 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
}
xml_coll_t(compact, _U(plugins)).for_each(_U(plugin), Converter<Plugin> (description));
xml_coll_t(compact, _U(plugins)).for_each(_U(include), Converter<XMLFile> (description));
xml_coll_t(compact, _U(plugins)).for_each(_U(xml), Converter<XMLFile> (description));
}

#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion DDG4/include/DDG4/Geant4SensDetAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// Geant4 include files
#include <G4ThreeVector.hh>
#include <G4VTouchable.hh>

// C/C++ include files
#include <vector>
Expand All @@ -28,7 +29,6 @@
class G4HCofThisEvent;
class G4Step;
class G4Event;
class G4VTouchable;
class G4TouchableHistory;
class G4VHitsCollection;
class G4VReadOutGeometry;
Expand Down
3 changes: 2 additions & 1 deletion DDG4/include/DDG4/Geant4TouchableHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
#ifndef DDG4_GEANT4TOUCHABLEHANDLER_H
#define DDG4_GEANT4TOUCHABLEHANDLER_H

#include <G4VTouchable.hh>

// C/C++ include files
#include <vector>
#include <string>

// Forward declarations
class G4VPhysicalVolume;
class G4VTouchable;
class G4Step;

/// Namespace for the AIDA detector description toolkit
Expand Down
2 changes: 1 addition & 1 deletion DDG4/include/DDG4/Geant4VolumeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <DD4hep/IDDescriptor.h>
#include <DDG4/Geant4Primitives.h>

#include <G4VTouchable.hh>
// Geant4 forward declarations
class G4VTouchable;
class G4VPhysicalVolume;


Expand Down
2 changes: 1 addition & 1 deletion DDG4/python/DDSim/Helper/Gun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion DDTest/python/userSteeringFile.PY
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/ClientTests/compact/IncludePlugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<plugins>
<include ref="${DD4hepExamplesINSTALL}/examples/ClientTests/compact/ExamplePlugins.xml"/>
</plugins>
<!-- This here is parsed at the very end -->
<plugins>
<include ref="ExamplePlugins.xml"/>
</plugins>


</lccdd>
2 changes: 1 addition & 1 deletion examples/DDCAD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 30 additions & 0 deletions examples/DDCAD/compact/Check_Shape_RelativePath.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<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.
#
#==========================================================================
Test to verify functionality of loading CAD files with pathes relative
to the declaring xml file. [See Issue 1166: Allow to give CAD files with
relative paths similar to importing xml files (DDCAD) ]
-->

<includes>
<gdmlFile ref="../../ClientTests/compact/CheckShape.xml"/>
</includes>

<detectors>
<detector id="1" name="Shape_MS3D" type="DD4hep_TestShape_Creator">
<check vis="Shape1_vis">
<shape type="CAD_MultiVolume" ref="../models/MS3D/jeep1.ms3d" unit="cm"/>
</check>
</detector>
</detectors>
</lccdd>

0 comments on commit 6725f8d

Please sign in to comment.