From 8badfb9e7c38ca494a82c813e3971dd4471c2ce0 Mon Sep 17 00:00:00 2001 From: Markus FRANK <Markus.Frank@cern.ch> Date: Wed, 2 Dec 2020 15:40:14 +0100 Subject: [PATCH] Enable conditional builds with scaled shapes and G4<10.3 --- DDCore/src/Handle.cpp | 12 ++++++++++-- DDG4/src/Geant4Converter.cpp | 8 +++++++- DDParsers/include/Evaluator/Evaluator.h | 11 +++++++++++ DDParsers/src/Evaluator/Evaluator.cpp | 12 ++++++++++++ examples/ClientTests/CMakeLists.txt | 18 +++++++++++++++--- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/DDCore/src/Handle.cpp b/DDCore/src/Handle.cpp index abd6f3f46..93f76a3f7 100644 --- a/DDCore/src/Handle.cpp +++ b/DDCore/src/Handle.cpp @@ -238,7 +238,14 @@ namespace dd4hep { v.erase(0, 1); auto result = eval.evaluate(v, err); check_evaluation(v, result, err); - eval.setVariable(n, result.second); + err.str(""); + if ( eval.setVariable(n, result.second, err) != tools::Evaluator::OK ) { + stringstream err_msg; + err_msg << "dd4hep: " << err.str() << " : value=" + << result.second + << " [setVariable error]"; + throw runtime_error(err_msg.str()); + } } } @@ -255,7 +262,8 @@ namespace dd4hep { auto ret = eval.getEnviron(v, err); if ( ret.first != tools::Evaluator::OK) { cerr << env << ": " << err.str() << endl; - throw runtime_error("dd4hep: Severe error during environment lookup of " + env); + throw runtime_error("dd4hep: Severe error during environment lookup of " + env + + " " + err.str()); } v = env.substr(0,id1); v += ret.second; diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index ce9a0d0e1..2704d750b 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -66,7 +66,6 @@ #include "G4Transform3D.hh" #include "G4ThreeVector.hh" #include "G4PVPlacement.hh" -#include "G4ScaledSolid.hh" #include "G4ElectroMagneticField.hh" #include "G4FieldManager.hh" #include "G4ReflectionFactory.hh" @@ -77,6 +76,9 @@ #if G4VERSION_NUMBER >= 1040 #include "G4MaterialPropertiesIndex.hh" #endif +#if G4VERSION_NUMBER >= 1030 +#include "G4ScaledSolid.hh" +#endif #include "CLHEP/Units/SystemOfUnits.h" // C/C++ include files @@ -587,6 +589,7 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c #endif else if (isa == TGeoScaledShape::Class()) { TGeoScaledShape* sh = (TGeoScaledShape*) shape; +#if G4VERSION_NUMBER >= 1030 TGeoShape* sol = sh->GetShape(); const double* vals = sh->GetScale()->GetScale(); G4Scale3D scal(vals[0], vals[1], vals[2]); @@ -595,6 +598,9 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c solid = new G4ScaledSolid(sh->GetName(), g4solid, scal); else solid = new G4ReflectedSolid(g4solid->GetName()+"_refl", g4solid, scal); +#else + except("Geant4Converter","++ TGeoScaledShape are only supported by Geant4 for versions >= 10.3"); +#endif } else if (isa == TGeoCompositeShape::Class()) { const TGeoCompositeShape* sh = (const TGeoCompositeShape*) shape; diff --git a/DDParsers/include/Evaluator/Evaluator.h b/DDParsers/include/Evaluator/Evaluator.h index fff500012..eee6210c9 100644 --- a/DDParsers/include/Evaluator/Evaluator.h +++ b/DDParsers/include/Evaluator/Evaluator.h @@ -201,6 +201,17 @@ namespace dd4hep { */ int setVariable(const std::string& name, double value) const; + /** + * Adds to the dictionary a variable with given value. + * If a variable with such a name already exist in the dictionary, + * then status will be set to WARNING_EXISTING_VARIABLE. + * + * @param name name of the variable. + * @param value value assigned to the variable. + * @return result of the evaluation. + */ + int setVariable(const std::string& name, double value, std::ostream& os) const; + /** * Adds to the dictionary a variable with an arithmetic expression * assigned to it. diff --git a/DDParsers/src/Evaluator/Evaluator.cpp b/DDParsers/src/Evaluator/Evaluator.cpp index 5d4ab4ffb..6f4155633 100644 --- a/DDParsers/src/Evaluator/Evaluator.cpp +++ b/DDParsers/src/Evaluator/Evaluator.cpp @@ -902,6 +902,18 @@ int Evaluator::setVariable(const std::string& name, double value) const { return result; } +//--------------------------------------------------------------------------- +int Evaluator::setVariable(const std::string& name, double value, std::ostream& os) const { + object->lock(); + object->setVariable(name.c_str(), value); + int result = object->status(); + if ( result != OK ) { + object->print_error(os); + } + object->unlock(); + return result; +} + //--------------------------------------------------------------------------- int Evaluator::setVariable(const std::string& name, const std::string& value) const { object->lock(); diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt index f17c669b8..837267134 100644 --- a/examples/ClientTests/CMakeLists.txt +++ b/examples/ClientTests/CMakeLists.txt @@ -194,10 +194,22 @@ set(ClientTests_ShapeTests) list(APPEND ClientTests_ShapeTests Box Cone ConeSegment Tube ElTube CutTube Hyperboloid Paraboloid) list(APPEND ClientTests_ShapeTests EightPointSolid Eightpoint_Reflect_Volume Eightpoint_Reflect_DetElement) list(APPEND ClientTests_ShapeTests Polycone Polyhedra PseudoTrap PseudoTrap2 Sphere Torus Trap Trd1 Trd2) -list(APPEND ClientTests_ShapeTests TruncatedTube ExtrudedPolygon Scaled_Cone) -if(${ROOT_VERSION} VERSION_GREATER 6.21.00) -list(APPEND ClientTests_ShapeTests Tessellated) +list(APPEND ClientTests_ShapeTests TruncatedTube ExtrudedPolygon) +# +# +if( ${ROOT_VERSION} VERSION_GREATER 6.21.00 ) + # message(STATUS "++ ROOT version: ${ROOT_VERSION} ... adding tests...") + list(APPEND ClientTests_ShapeTests Tessellated) +else() + message(STATUS "++ ROOT version: ${ROOT_VERSION} ... NO version specific tests for ROOT>6.21...") endif() +if( ${Geant4_VERSION} VERSION_GREATER 10.2.99 ) + # message(STATUS "++ Geant4 version: ${Geant4_VERSION} ... adding tests...") + list(APPEND ClientTests_ShapeTests Scaled_Cone) +else() + message(STATUS "++ Geant4 version: ${Geant4_VERSION} ... NO version specific tests for G4>=10.3...") +endif() + foreach (test ${ClientTests_ShapeTests}) dd4hep_add_test_reg( ClientTests_Check_Shape_${test} COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh" -- GitLab