From 92184f32734a1179bd115eb8a794e90b0a774eb4 Mon Sep 17 00:00:00 2001
From: Mircho Rodozov <mrodozov@cern.ch>
Date: Fri, 3 Aug 2018 17:31:40 +0200
Subject: [PATCH] Add changes to match ROOT interfaces
 https://github.com/AIDASoft/DD4hep/issues/426

---
 DDCore/include/DD4hep/MatrixHelpers.h |  1 +
 DDCore/src/MatrixHelpers.cpp          | 13 +++++++++++++
 DDCore/src/plugins/LCDDConverter.cpp  |  4 ++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/DDCore/include/DD4hep/MatrixHelpers.h b/DDCore/include/DD4hep/MatrixHelpers.h
index 68cf39f24..78e801e4b 100644
--- a/DDCore/include/DD4hep/MatrixHelpers.h
+++ b/DDCore/include/DD4hep/MatrixHelpers.h
@@ -63,6 +63,7 @@ namespace dd4hep {
 
       /// Convert a TGeoMatrix object to a generic Transform3D                                  \ingroup DD4HEP \ingroup DD4HEP_CORE
       Transform3D      _transform(const TGeoMatrix* matrix);
+      Transform3D      _transform(const TGeoMatrix& matrix);
 
       /// Decompose a generic Transform3D into a translation (Position) and a RotationZYX       \ingroup DD4HEP \ingroup DD4HEP_CORE
       void _decompose(const Transform3D& trafo, Position& pos, RotationZYX& rot);
diff --git a/DDCore/src/MatrixHelpers.cpp b/DDCore/src/MatrixHelpers.cpp
index fb4eabfb7..8b16d136e 100644
--- a/DDCore/src/MatrixHelpers.cpp
+++ b/DDCore/src/MatrixHelpers.cpp
@@ -112,6 +112,19 @@ Transform3D dd4hep::detail::matrix::_transform(const TGeoMatrix* matrix)    {
                      0e0,0e0,0e0,t[1]*MM_2_CM,
                      0e0,0e0,0e0,t[2]*MM_2_CM);
 }
+// add another implementation that takes const reference
+Transform3D dd4hep::detail::matrix::_transform(const TGeoMatrix& matrix)    {
+  const Double_t* t = matrix.GetTranslation();
+  if ( matrix.IsRotation() )  {
+    const Double_t* r = matrix.GetRotationMatrix();
+    return Transform3D(r[0],r[1],r[2],t[0]*MM_2_CM,
+                       r[3],r[4],r[5],t[1]*MM_2_CM,
+                       r[6],r[7],r[8],t[2]*MM_2_CM);
+  }
+  return Transform3D(0e0,0e0,0e0,t[0]*MM_2_CM,
+                     0e0,0e0,0e0,t[1]*MM_2_CM,
+                     0e0,0e0,0e0,t[2]*MM_2_CM);
+}
 
 dd4hep::XYZAngles dd4hep::detail::matrix::_xyzAngles(const TGeoMatrix* m) {
   return m->IsRotation() ? _xyzAngles(m->GetRotationMatrix()) : XYZAngles(0,0,0);
diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp
index da74cd441..df32ff5a7 100644
--- a/DDCore/src/plugins/LCDDConverter.cpp
+++ b/DDCore/src/plugins/LCDDConverter.cpp
@@ -549,7 +549,7 @@ xml_h LCDDConverter::handleSolid(const string& name, const TGeoShape* shape) con
         obj.setAttr(_U(unit), "cm");
       }
       if (lm->IsRotation()) {
-        TGeoMatrix& linv = lm->Inverse();
+        TGeoMatrix const & linv = lm->Inverse();
         XYZRotation  rot = getXYZangles(linv.GetRotationMatrix());
         if ((rot.X() != 0.0) || (rot.Y() != 0.0) || (rot.Z() != 0.0)) {
           first_solid.append(obj = xml_elt_t(geo.doc, _U(firstrotation)));
@@ -568,7 +568,7 @@ xml_h LCDDConverter::handleSolid(const string& name, const TGeoShape* shape) con
         solid.setRef(_U(positionref), pos.name());
       }
       if (rm->IsRotation()) {
-        TGeoMatrix& rinv = rm->Inverse();
+        TGeoMatrix const & rinv = rm->Inverse();
         XYZRotation rot = getXYZangles(rinv.GetRotationMatrix());
         if ((rot.X() != 0.0) || (rot.Y() != 0.0) || (rot.Z() != 0.0)) {
           xml_ref_t xml_rot = handleRotation(rnam+"_rot", &rinv);
-- 
GitLab