From 719beb200385fcd43d222f17ce33749f887e4d80 Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Thu, 30 Jan 2014 15:16:43 +0000
Subject: [PATCH] Fix bug, which appears with earlier versions than root
 5.34.10

---
 DDCore/include/DD4hep/Volumes.h | 3 ++-
 DDCore/src/VolumeManager.cpp    | 6 +++++-
 DDCore/src/Volumes.cpp          | 6 ++++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/DDCore/include/DD4hep/Volumes.h b/DDCore/include/DD4hep/Volumes.h
index ae70060aa..11d043750 100644
--- a/DDCore/include/DD4hep/Volumes.h
+++ b/DDCore/include/DD4hep/Volumes.h
@@ -126,7 +126,8 @@ namespace DD4hep {
         m_element = v.m_element;
         return *this;
       }
-
+      /// Check if placement is properly instrumented
+      Object* data() const;
       /// Add identifier
       PlacedVolume& addPhysVolID(const std::string& name, int value);
       /// Volume material
diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp
index e03801478..7e2fae6db 100644
--- a/DDCore/src/VolumeManager.cpp
+++ b/DDCore/src/VolumeManager.cpp
@@ -98,7 +98,8 @@ namespace {
         }
         for (Int_t idau = 0, ndau = node->GetNdaughters(); idau < ndau; ++idau) {
           TGeoNode* daughter = node->GetDaughter(idau);
-          if (dynamic_cast<const PlacedVolume::Object*>(daughter)) {
+	  PlacedVolume placement(daughter);
+          if ( placement.data() ) {
             size_t cnt;
             PlacedVolume pv_dau = Ref_t(daughter);
             DetElement de_dau = findElt(e, daughter);
@@ -114,6 +115,9 @@ namespace {
             }
             count += cnt;
           }
+	  else  {
+	    throw runtime_error("Invalid not instrumented placement:"+string(daughter->GetName())+" [Internal error -- bad detector constructor]");
+	  }
         }
         chain.pop_back();
       }
diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp
index 3ab070da8..14cd37c09 100644
--- a/DDCore/src/Volumes.cpp
+++ b/DDCore/src/Volumes.cpp
@@ -353,6 +353,12 @@ static PlacedVolume::Object* _data(const PlacedVolume& v) {
   throw runtime_error("DD4hep: Attempt to access invalid handle of type: PlacedVolume");
 }
 
+/// Check if placement is properly instrumented
+PlacedVolume::Object* PlacedVolume::data() const   {
+  PlacedVolume::Object* o = _userExtension(*this);
+  return o;
+}
+
 /// Add identifier
 PlacedVolume& PlacedVolume::addPhysVolID(const string& name, int value) {
   Object* obj = _data(*this);
-- 
GitLab