From 52e6d2fee62af2c264196ca4e4411e1f877efc96 Mon Sep 17 00:00:00 2001
From: Marko Petric <marko.petric@cern.ch>
Date: Thu, 25 Jan 2018 10:43:04 +0100
Subject: [PATCH] Check dynamic cast if it was successful

---
 DDCore/src/DD4hepRootPersistency.cpp | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/DDCore/src/DD4hepRootPersistency.cpp b/DDCore/src/DD4hepRootPersistency.cpp
index 24ee51a80..eddc3ba2e 100644
--- a/DDCore/src/DD4hepRootPersistency.cpp
+++ b/DDCore/src/DD4hepRootPersistency.cpp
@@ -119,12 +119,15 @@ int DD4hepRootPersistency::load(Detector& description, const char* fname, const
       printout(ALWAYS,"DD4hepRootPersistency","+++ loaded %ld nominals....",persist->nominals.size());
       DetectorData* tar_data = dynamic_cast<DetectorData*>(&description);
       DetectorData* src_data = dynamic_cast<DetectorData*>(source);
-      tar_data->adoptData(*src_data,false);
-      TTimeStamp stop;
-      printout(ALWAYS,"DD4hepRootPersistency",
-               "+++ Successfully loaded detector description from file:%s  [%8.3f seconds]",
-               fname, stop.AsDouble()-start.AsDouble());
-      return 1;
+      if( tar_data != nullptr && src_data != nullptr ){
+        tar_data->adoptData(*src_data,false);
+        TTimeStamp stop;
+        printout(ALWAYS,"DD4hepRootPersistency",
+                 "+++ Successfully loaded detector description from file:%s  [%8.3f seconds]",
+                 fname, stop.AsDouble()-start.AsDouble());
+        return 1;
+      }
+      return 0;
     }
     printout(ERROR,"DD4hepRootPersistency",
              "+++ Cannot Cannot load instance '%s' from file '%s'.",
-- 
GitLab