diff --git a/DDCore/src/ComponentProperties.cpp b/DDCore/src/ComponentProperties.cpp index f3662acad47a86e8523c6dca599e26debd09b10c..d3eeb6d3f1460b4cf2e97fdd4ca2cf199c4641aa 100644 --- a/DDCore/src/ComponentProperties.cpp +++ b/DDCore/src/ComponentProperties.cpp @@ -81,14 +81,14 @@ string Property::type() const { } const PropertyGrammar& Property::grammar() const { - if (m_hdl) + if ( m_hdl ) return *m_hdl; throw runtime_error("Attempt to access property grammar from invalid object."); } /// Conversion to string value string Property::str() const { - if (m_hdl && m_par ) { + if ( m_hdl && m_par ) { return m_hdl->str(m_par); } throw runtime_error("Attempt to access property grammar from invalid object."); @@ -96,7 +96,7 @@ string Property::str() const { /// Conversion from string value const Property& Property::str(const std::string& input) const { - if (m_hdl && m_par ) { + if ( m_hdl && m_par ) { m_hdl->fromString(m_par,input); return *this; } @@ -105,22 +105,16 @@ const Property& Property::str(const std::string& input) const { /// Conversion from string value Property& Property::str(const std::string& input) { - if (m_hdl && m_par ) { + if ( m_hdl && m_par ) { m_hdl->fromString(m_par,input); return *this; } throw runtime_error("Attempt to access property grammar from invalid object."); } -/// Assignment operator / set new balue -//Property& Property::operator=(const string& val) { -// this->set<string>(val); -// return *this; -//} - /// Assignment operator / set new balue Property& Property::operator=(const char* val) { - if (val) { + if ( val ) { this->set < string > (val); return *this; } diff --git a/DDCore/src/ConditionsPrinter.cpp b/DDCore/src/ConditionsPrinter.cpp index 7386d9f588f6c541c6437a054ecdf3ee2e958773..44497d826e07425cfa7092280e25116bdd511493 100644 --- a/DDCore/src/ConditionsPrinter.cpp +++ b/DDCore/src/ConditionsPrinter.cpp @@ -48,7 +48,9 @@ protected: /// Parent object ConditionsPrinter* m_parent = 0; public: + /// Prefix to tag print statements std::string prefix; + /// Used printout level PrintLevel printLevel = INFO; public: /// Copy constructor diff --git a/DDCore/src/ShapeUtilities.cpp b/DDCore/src/ShapeUtilities.cpp index 093c993560de1df4ab1892a500e95bdbae7fb433..1daeb2ab7cb425dae1284372c45131571f9cb58c 100644 --- a/DDCore/src/ShapeUtilities.cpp +++ b/DDCore/src/ShapeUtilities.cpp @@ -51,44 +51,41 @@ namespace dd4hep { except("Solid","+++ Shape:%s setDimension: Invalid number of parameters: %ld", (sh ? typeName(typeid(*sh)) : typeName(typeid(sh))).c_str(), params.size()); } - inline bool check_shape_type(const Handle<TGeoShape>& solid, const TClass* cl) { - return solid.isValid() && solid->IsA() == cl; + template <typename T> inline bool check_shape_type(const Handle<TGeoShape>& solid) { + return solid.isValid() && solid->IsA() == T::Class(); } } /// Type check of various shapes. Result like dynamic_cast. Compare with python's isinstance(obj,type) template <typename SOLID> bool isInstance(const Handle<TGeoShape>& solid) { - return check_shape_type(solid, SOLID::Object::Class()); - } - template bool isInstance<Box>(const Handle<TGeoShape>& solid); - template bool isInstance<ShapelessSolid>(const Handle<TGeoShape>& solid); - template bool isInstance<HalfSpace>(const Handle<TGeoShape>& solid); - template bool isInstance<ConeSegment>(const Handle<TGeoShape>& solid); - template bool isInstance<CutTube>(const Handle<TGeoShape>& solid); - template bool isInstance<EllipticalTube>(const Handle<TGeoShape>& solid); - template bool isInstance<Trap>(const Handle<TGeoShape>& solid); - template bool isInstance<Trd1>(const Handle<TGeoShape>& solid); - template bool isInstance<Trd2>(const Handle<TGeoShape>& solid); - template bool isInstance<Torus>(const Handle<TGeoShape>& solid); - template bool isInstance<Sphere>(const Handle<TGeoShape>& solid); - template bool isInstance<Paraboloid>(const Handle<TGeoShape>& solid); - template bool isInstance<Hyperboloid>(const Handle<TGeoShape>& solid); - template bool isInstance<PolyhedraRegular>(const Handle<TGeoShape>& solid); - template bool isInstance<Polyhedra>(const Handle<TGeoShape>& solid); - template bool isInstance<ExtrudedPolygon>(const Handle<TGeoShape>& solid); - template bool isInstance<BooleanSolid>(const Handle<TGeoShape>& solid); + return check_shape_type<typename SOLID::Object>(solid); + } + template bool isInstance<Box> (const Handle<TGeoShape>& solid); + template bool isInstance<ShapelessSolid> (const Handle<TGeoShape>& solid); + template bool isInstance<HalfSpace> (const Handle<TGeoShape>& solid); + template bool isInstance<ConeSegment> (const Handle<TGeoShape>& solid); + template bool isInstance<CutTube> (const Handle<TGeoShape>& solid); + template bool isInstance<EllipticalTube> (const Handle<TGeoShape>& solid); + template bool isInstance<Trap> (const Handle<TGeoShape>& solid); + template bool isInstance<Trd1> (const Handle<TGeoShape>& solid); + template bool isInstance<Trd2> (const Handle<TGeoShape>& solid); + template bool isInstance<Torus> (const Handle<TGeoShape>& solid); + template bool isInstance<Sphere> (const Handle<TGeoShape>& solid); + template bool isInstance<Paraboloid> (const Handle<TGeoShape>& solid); + template bool isInstance<Hyperboloid> (const Handle<TGeoShape>& solid); + template bool isInstance<PolyhedraRegular> (const Handle<TGeoShape>& solid); + template bool isInstance<Polyhedra> (const Handle<TGeoShape>& solid); + template bool isInstance<ExtrudedPolygon> (const Handle<TGeoShape>& solid); + template bool isInstance<BooleanSolid> (const Handle<TGeoShape>& solid); template <> bool isInstance<Cone>(const Handle<TGeoShape>& solid) { - return check_shape_type(solid, TGeoConeSeg::Class()) - || check_shape_type(solid, TGeoCone::Class()); + return check_shape_type<TGeoConeSeg>(solid) || check_shape_type<TGeoCone>(solid); } template <> bool isInstance<Tube>(const Handle<TGeoShape>& solid) { - return check_shape_type(solid, TGeoTubeSeg::Class()) - || check_shape_type(solid, TGeoCtub::Class()); + return check_shape_type<TGeoTubeSeg>(solid) || check_shape_type<TGeoCtub>(solid); } template <> bool isInstance<Polycone>(const Handle<TGeoShape>& solid) { - return check_shape_type(solid, TGeoPcon::Class()) - || check_shape_type(solid, TGeoPgon::Class()); + return check_shape_type<TGeoPcon>(solid) || check_shape_type<TGeoPgon>(solid); } template <> bool isInstance<EightPointSolid>(const Handle<TGeoShape>& solid) { if ( solid.isValid() ) { @@ -98,18 +95,12 @@ namespace dd4hep { return false; } template <> bool isInstance<TruncatedTube>(const Handle<TGeoShape>& solid) { - if ( solid.isValid() ) { - return solid->IsA() == TGeoCompositeShape::Class() - && ::strcmp(solid->GetTitle(), TRUNCATEDTUBE_TAG) == 0; - } - return false; + return check_shape_type<TGeoCompositeShape>(solid) + && ::strcmp(solid->GetTitle(), TRUNCATEDTUBE_TAG) == 0; } template <> bool isInstance<PseudoTrap>(const Handle<TGeoShape>& solid) { - if ( solid.isValid() ) { - return solid->IsA() == TGeoCompositeShape::Class() - && ::strcmp(solid->GetTitle(), PSEUDOTRAP_TAG) == 0; - } - return false; + return check_shape_type<TGeoCompositeShape>(solid) + && ::strcmp(solid->GetTitle(), PSEUDOTRAP_TAG) == 0; } template <> bool isInstance<SubtractionSolid>(const Handle<TGeoShape>& solid) { TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr(); @@ -129,7 +120,7 @@ namespace dd4hep { /// Type check of various shapes. Do not allow for polymorphism. Types must match exactly template <typename SOLID> bool isA(const Handle<TGeoShape>& solid) { - return check_shape_type(solid, SOLID::Object::Class()); + return check_shape_type<typename SOLID::Object>(solid); } template bool isA<Box>(const Handle<TGeoShape>& solid); template bool isA<ShapelessSolid>(const Handle<TGeoShape>& solid); @@ -153,36 +144,30 @@ namespace dd4hep { template bool isA<EightPointSolid>(const Handle<TGeoShape>& solid); template <> bool isA<TruncatedTube>(const Handle<TGeoShape>& solid) { - if ( solid.isValid() ) { - return solid->IsA() == TGeoCompositeShape::Class() - && ::strcmp(solid->GetTitle(), TRUNCATEDTUBE_TAG) == 0; - } - return false; + return check_shape_type<TGeoCompositeShape>(solid) + && ::strcmp(solid->GetTitle(), TRUNCATEDTUBE_TAG) == 0; } template <> bool isA<PseudoTrap>(const Handle<TGeoShape>& solid) { - if ( solid.isValid() ) { - return solid->IsA() == TGeoCompositeShape::Class() - && ::strcmp(solid->GetTitle(), PSEUDOTRAP_TAG) == 0; - } - return false; + return check_shape_type<TGeoCompositeShape>(solid) + && ::strcmp(solid->GetTitle(), PSEUDOTRAP_TAG) == 0; } template <> bool isA<SubtractionSolid>(const Handle<TGeoShape>& solid) { TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr(); return sh && sh->IsA() == TGeoCompositeShape::Class() && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoSubtraction - && ::strcmp(solid->GetTitle(), SUBTRACTION_TAG) == 0; + && ::strcmp(sh->GetTitle(), SUBTRACTION_TAG) == 0; } template <> bool isA<UnionSolid>(const Handle<TGeoShape>& solid) { TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr(); return sh && sh->IsA() == TGeoCompositeShape::Class() && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoUnion - && ::strcmp(solid->GetTitle(), UNION_TAG) == 0; + && ::strcmp(sh->GetTitle(), UNION_TAG) == 0; } template <> bool isA<IntersectionSolid>(const Handle<TGeoShape>& solid) { TGeoCompositeShape* sh = (TGeoCompositeShape*)solid.ptr(); return sh && sh->IsA() == TGeoCompositeShape::Class() && sh->GetBoolNode()->GetBooleanOperator() == TGeoBoolNode::kGeoIntersection - && ::strcmp(solid->GetTitle(), INTERSECTION_TAG) == 0; + && ::strcmp(sh->GetTitle(), INTERSECTION_TAG) == 0; } template <typename T> vector<double> dimensions(const TGeoShape* shape) {