From a8e34d780873ff4b47c7b31b5914508977598fc7 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Wed, 15 Feb 2017 10:16:03 +0100
Subject: [PATCH] Another round of removing Coverity defects

---
 DDCond/include/DDCond/ConditionsRepository.h  |  15 +-
 DDCond/include/DDCond/ConditionsSlice.h       |  19 ++-
 DDCond/src/plugins/ConditionsParser.cpp       |   4 +-
 .../plugins/ConditionsRepositoryParser.cpp    |   8 +-
 DDCore/src/ConditionsInterna.cpp              |   2 +-
 DDCore/src/Evaluator/Evaluator.cpp            |   2 +-
 DDCore/src/Plugins.cpp                        |   6 +-
 DDCore/src/plugins/StandardPlugins.cpp        |  24 ++-
 DDDB/src/DDDBFileReader.cpp                   |   8 +-
 DDG4/include/DDG4/Defs.h                      |   1 -
 DDG4/include/DDG4/Factories.h                 |   1 -
 DDG4/include/DDG4/Geant4ActionContainer.h     |   1 -
 DDG4/include/DDG4/Geant4ActionPhase.h         |   1 -
 DDG4/include/DDG4/Geant4AssemblyVolume.h      |  18 ++-
 DDG4/include/DDG4/Geant4Call.h                |   1 -
 DDG4/include/DDG4/Geant4Callback.h            |   1 -
 DDG4/include/DDG4/Geant4Config.h              |   1 -
 DDG4/include/DDG4/Geant4Context.h             |   1 -
 DDG4/include/DDG4/Geant4Converter.h           |   1 -
 DDG4/include/DDG4/Geant4Handle.h              |   4 +-
 DDG4/include/DDG4/Geant4VolumeManager.h       |   1 -
 DDG4/include/DDG4/IoStreams.h                 |   2 +-
 DDG4/lcio/LCIOEventReader.cpp                 |  11 +-
 DDG4/src/Geant4Handle.cpp                     |  18 ++-
 DDG4/src/Geant4Random.cpp                     |   9 +-
 DDRec/include/DDRec/API/IDDecoder.h           |  13 +-
 DDRec/include/DDRec/SurfaceManager.h          |   9 +-
 DDRec/src/SurfaceHelper.cpp                   |  62 ++++----
 .../DDSegmentation/MegatileLayerGridXY.h      |  55 +++----
 DDSegmentation/src/MegatileLayerGridXY.cpp    |   3 +-
 GaudiPluginService/CMakeLists.txt             |   4 +
 GaudiPluginService/interface/DD4hep.cpp       |  14 +-
 UtilityApps/src/graphicalMaterialScan.cpp     | 145 ++++++++++--------
 UtilityApps/src/test_surfaces.cpp             |   2 +-
 examples/AlignDet/CMakeLists.txt              |   8 +
 .../src/AlignmentExample_align_telescope.cpp  |   4 +-
 36 files changed, 280 insertions(+), 199 deletions(-)

diff --git a/DDCond/include/DDCond/ConditionsRepository.h b/DDCond/include/DDCond/ConditionsRepository.h
index 05c462092..48a9ea47d 100644
--- a/DDCond/include/DDCond/ConditionsRepository.h
+++ b/DDCond/include/DDCond/ConditionsRepository.h
@@ -45,17 +45,10 @@ namespace DD4hep {
       class Entry  {
       public:
         std::string name, address;
-        Condition::key_type key;
-        Entry() {}
-        Entry(const Entry& e) : name(e.name), address(e.address), key(e.key) {}
-        Entry& operator=(const Entry& e) {
-          if ( this != &e )  {
-            key = e.key;
-            name = e.name;
-            address = e.address;
-          }
-          return *this;
-        }
+        Condition::key_type key = 0;
+        Entry() = default;
+        Entry(const Entry& e) = default;
+        Entry& operator=(const Entry& e) = default;
       };
       typedef std::vector<Entry> Data;
 
diff --git a/DDCond/include/DDCond/ConditionsSlice.h b/DDCond/include/DDCond/ConditionsSlice.h
index a3a919251..334fc649d 100644
--- a/DDCond/include/DDCond/ConditionsSlice.h
+++ b/DDCond/include/DDCond/ConditionsSlice.h
@@ -46,8 +46,15 @@ namespace DD4hep {
        */
       class ConditionsLoadInfo {
       public:
+        /// Default constructor
+        ConditionsLoadInfo() = default;
+        /// Copy constructor
+        ConditionsLoadInfo(const ConditionsLoadInfo& copy) = default;
         /// Default destructor. 
         virtual ~ConditionsLoadInfo();
+        /// Assignment operator
+        ConditionsLoadInfo& operator=(const ConditionsLoadInfo& copy) = default;
+
         virtual const std::type_info& type() const = 0;
         virtual const void*           ptr()  const = 0;
         template<typename T> T*       data() const {  return (T*)ptr(); }
@@ -117,15 +124,13 @@ namespace DD4hep {
        */
       template <typename T> struct LoadInfo : public ConditionsLoadInfo {
         T info;
-        LoadInfo()           = default;
         LoadInfo(const T& i) : info(i) {}
-        virtual ~LoadInfo()  = default;
-        LoadInfo& operator=(const LoadInfo& copy) {
-          if ( &copy != this ) info = copy.info;
-          return *this;
-        }
+        LoadInfo()                  = default;
+        LoadInfo(const LoadInfo& c) = default;
+        virtual ~LoadInfo()         = default;
+        LoadInfo& operator=(const LoadInfo& copy) = default;
         virtual const std::type_info& type() const { return typeid(T); }
-        virtual const void*           ptr() const  { return &info;     }
+        virtual const void*           ptr()  const { return &info;     }
       };
       /// Concrete class for NO data loading information.
       /**
diff --git a/DDCond/src/plugins/ConditionsParser.cpp b/DDCond/src/plugins/ConditionsParser.cpp
index 9e1394130..d58534810 100644
--- a/DDCond/src/plugins/ConditionsParser.cpp
+++ b/DDCond/src/plugins/ConditionsParser.cpp
@@ -135,7 +135,9 @@ namespace DD4hep {
     xml_comp_t elt(e);
     string tag = elt.tag();
     ConversionArg* arg  = _param<ConversionArg>();
-    if ( tag == "conditions" )  
+    if ( !arg )
+      except("ConditionsParser","++ Invalid parser argument [Internal Error]");
+    else if ( tag == "conditions" )  
       Converter<conditions>(lcdd,param,optional)(e);
     else if ( arg->stack && tag == "detelement" )
       Converter<conditions>(lcdd,param,optional)(e);
diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp
index 719353b03..6b85a6018 100644
--- a/DDCond/src/plugins/ConditionsRepositoryParser.cpp
+++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp
@@ -207,13 +207,13 @@ namespace DD4hep {
    *  \date    01/04/2014
    */
   template <> void Converter<iov_type>::operator()(xml_h element) const {
-    xml_dim_t e  = element;
-    string nam   = e.nameStr();
-    size_t id    = size_t(e.id());
+    xml_dim_t e   = element;
+    string    nam = e.nameStr();
+    int       id  = e.id();
     ConversionArg* arg  = _param<ConversionArg>();
     printout(s_parseLevel,"XMLConditions","++ Registering IOV type: [%d]: %s",id,nam.c_str());
     const IOVType* iov_type = arg->manager.registerIOVType(id,nam).second;
-    if ( !iov_type )  {
+    if ( !iov_type )   {
       except("XMLConditions","Failed to register iov type: [%d]: %s",id,nam.c_str());
     }
   }
diff --git a/DDCore/src/ConditionsInterna.cpp b/DDCore/src/ConditionsInterna.cpp
index 09fb3aba5..f68f54b03 100644
--- a/DDCore/src/ConditionsInterna.cpp
+++ b/DDCore/src/ConditionsInterna.cpp
@@ -57,7 +57,7 @@ size_t Interna::ConditionObject::offset()   {
 /// Access the bound data payload. Exception id object is unbound
 void* Interna::ConditionObject::payload() const   {
   void** p = (void**)(((char*)this)+offset());
-  return p ? *p : 0;
+  return *p;
 }
 
 /// Move data content: 'from' will be reset to NULL
diff --git a/DDCore/src/Evaluator/Evaluator.cpp b/DDCore/src/Evaluator/Evaluator.cpp
index 034202096..2d3391a62 100644
--- a/DDCore/src/Evaluator/Evaluator.cpp
+++ b/DDCore/src/Evaluator/Evaluator.cpp
@@ -14,7 +14,7 @@
 #include <stdlib.h>     // for strtod()
 
 // Disable some diagnostics, which we know, but need to ignore
-#if defined(__GNUC__) && !defined(__APPLE__)
+#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__llvm__)
 /*  This is OK:
 ../DDCore/src/Evaluator/Evaluator.cpp: In function 'int engine(pchar, pchar, double&, char*&, const dic_type&)':
 ../DDCore/src/Evaluator/Evaluator.cpp:164:23: warning: 'pp[3]' may be used uninitialized in this function [-Wmaybe-uninitialized]
diff --git a/DDCore/src/Plugins.cpp b/DDCore/src/Plugins.cpp
index 42cfd47db..5b69d6218 100644
--- a/DDCore/src/Plugins.cpp
+++ b/DDCore/src/Plugins.cpp
@@ -84,8 +84,8 @@ namespace   {
                  void* creator_stub, 
                  const char* signature, 
                  const char* return_type);
-    PluginInterface() throw(std::exception);
-    static PluginInterface& instance()  throw(std::exception)   {
+    PluginInterface() noexcept(false);
+    static PluginInterface& instance()  noexcept(false)   {
       static PluginInterface s_instance;
       return s_instance;
     }
@@ -110,7 +110,7 @@ namespace   {
     return fp.fptr.fcn;
   }
 
-  PluginInterface::PluginInterface()   throw(std::exception)
+  PluginInterface::PluginInterface()  noexcept(false)
     : getDebug(0), setDebug(0), create(0), add(0)
   {
     void* handle = 0;
diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp
index 7bd98e634..e1645647b 100644
--- a/DDCore/src/plugins/StandardPlugins.cpp
+++ b/DDCore/src/plugins/StandardPlugins.cpp
@@ -588,13 +588,18 @@ static long dump_volume_tree(LCDD& lcdd, int argc, char** argv) {
           }
         }
         if ( m_printPositions )  {
-          const double* trans = ideal->GetMatrix()->GetTranslation();
-          ::snprintf(fmt, sizeof(fmt), "Pos: (%f,%f,%f) ",trans[0],trans[1],trans[2]);
+          if ( ideal )  {
+            const double* trans = ideal->GetMatrix()->GetTranslation();
+            ::snprintf(fmt, sizeof(fmt), "Pos: (%f,%f,%f) ",trans[0],trans[1],trans[2]);
+          }
+          else  {
+            ::snprintf(fmt, sizeof(fmt), " <ERROR: INVALID Translation matrix> ");
+          }
           log << fmt;
         }
         opt_info = log.str();
       }
-      TGeoVolume* volume = ideal->GetVolume();
+      TGeoVolume* volume = ideal ? ideal->GetVolume() : 0;
       if ( !m_printSensitivesOnly || (m_printSensitivesOnly && sensitive) )  {
         char sens = pv.volume().isSensitive() ? 'S' : ' ';
         if ( m_printPointers )    {
@@ -623,10 +628,15 @@ static long dump_volume_tree(LCDD& lcdd, int argc, char** argv) {
                  opt_info.c_str());
       }
       for (Int_t idau = 0, ndau = aligned->GetNdaughters(); idau < ndau; ++idau)  {
-        TGeoNode*   ideal_daughter   = ideal->GetDaughter(idau);
-        const char* daughter_name    = ideal_daughter->GetName();
-        TGeoNode*   aligned_daughter = volume->GetNode(daughter_name);
-        dump(ideal_daughter, aligned_daughter, level+1, volids);
+        if ( ideal )   {
+          TGeoNode*   ideal_daughter   = ideal->GetDaughter(idau);
+          const char* daughter_name    = ideal_daughter->GetName();
+          TGeoNode*   aligned_daughter = volume->GetNode(daughter_name);
+          dump(ideal_daughter, aligned_daughter, level+1, volids);
+        }
+        else  {
+          printout(ERROR,"VolumeDump"," <ERROR: INVALID IDEAL Translation matrix>: %s",aligned->GetName());
+        }
       }
       return 1;
     }
diff --git a/DDDB/src/DDDBFileReader.cpp b/DDDB/src/DDDBFileReader.cpp
index 8331ec885..74c46b286 100644
--- a/DDDB/src/DDDBFileReader.cpp
+++ b/DDDB/src/DDDBFileReader.cpp
@@ -71,7 +71,7 @@ int DD4hep::DDDB::DDDBFileReader::getObject(const std::string& system_id,
   struct stat buff;
   if ( 0 == ::stat(path.c_str(), &buff) )  {
     int fid  = ::open(path.c_str(), O_RDONLY);
-    if ( fid > 0 )   {
+    if ( fid != 0 )   {
       int done = 0, len = buff.st_size;
       char* b  = new char[len+1];
       b[0] = 0;
@@ -84,7 +84,11 @@ int DD4hep::DDDB::DDDBFileReader::getObject(const std::string& system_id,
       b[done] = 0;
       buffer = b;
       delete [] b;
-      if ( done>=len ) return 1;
+      if ( done>=len ) {
+        ::close(fid);
+        return 1;
+      }
+      ::close(fid);
     }
   }
   return 0;
diff --git a/DDG4/include/DDG4/Defs.h b/DDG4/include/DDG4/Defs.h
index 499e61b32..82cbaf045 100644
--- a/DDG4/include/DDG4/Defs.h
+++ b/DDG4/include/DDG4/Defs.h
@@ -1,4 +1,3 @@
-// $Id$
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Factories.h b/DDG4/include/DDG4/Factories.h
index 5a4152452..e4e52e058 100644
--- a/DDG4/include/DDG4/Factories.h
+++ b/DDG4/include/DDG4/Factories.h
@@ -1,4 +1,3 @@
-// $Id$
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4ActionContainer.h b/DDG4/include/DDG4/Geant4ActionContainer.h
index 2ba51e5b2..df5b1100b 100644
--- a/DDG4/include/DDG4/Geant4ActionContainer.h
+++ b/DDG4/include/DDG4/Geant4ActionContainer.h
@@ -1,4 +1,3 @@
-// $Id$
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4ActionPhase.h b/DDG4/include/DDG4/Geant4ActionPhase.h
index 86f64da6f..8fef273d4 100644
--- a/DDG4/include/DDG4/Geant4ActionPhase.h
+++ b/DDG4/include/DDG4/Geant4ActionPhase.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4AssemblyVolume.h b/DDG4/include/DDG4/Geant4AssemblyVolume.h
index 03280f348..1cc900184 100644
--- a/DDG4/include/DDG4/Geant4AssemblyVolume.h
+++ b/DDG4/include/DDG4/Geant4AssemblyVolume.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -12,10 +11,20 @@
 //
 //==========================================================================
 
+// Disable diagnostics for ROOT dictionaries
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wkeyword-macro"
+#endif
+
 #define private public
 #include "G4AssemblyVolume.hh"
 #undef private
 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
 /// Namespace for the AIDA detector description toolkit
 namespace DD4hep {
 
@@ -29,15 +38,20 @@ namespace DD4hep {
      *  \ingroup DD4HEP_SIMULATION
      */
     class Geant4AssemblyVolume : public G4AssemblyVolume {
+      
     public:
+
       std::vector<const TGeoNode*> m_entries;
       typedef std::vector<const TGeoNode*> Chain;
+
       /// Default constructor with initialization
       Geant4AssemblyVolume() {
       }
+
       /// Default destructor
       virtual ~Geant4AssemblyVolume() {
       }
+
       //std::vector<G4AssemblyTriplet>& triplets()  { return fTriplets; }
       long placeVolume(const TGeoNode* n, G4LogicalVolume* pPlacedVolume, G4Transform3D& transformation) {
         size_t id = fTriplets.size();
@@ -45,12 +59,14 @@ namespace DD4hep {
         this->AddPlacedVolume(pPlacedVolume, transformation);
         return (long)id;
       }
+
       long placeAssembly(const TGeoNode* n, Geant4AssemblyVolume* pPlacedVolume, G4Transform3D& transformation) {
         size_t id = fTriplets.size();
         m_entries.push_back(n);
         this->AddPlacedAssembly(pPlacedVolume, transformation);
         return (long)id;
       }
+
       void imprint(Geant4GeometryInfo& info,
                    const TGeoNode* n,
                    Chain chain,
diff --git a/DDG4/include/DDG4/Geant4Call.h b/DDG4/include/DDG4/Geant4Call.h
index 199990682..e0f74e50f 100644
--- a/DDG4/include/DDG4/Geant4Call.h
+++ b/DDG4/include/DDG4/Geant4Call.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4Callback.h b/DDG4/include/DDG4/Geant4Callback.h
index 39003810a..b03882f02 100644
--- a/DDG4/include/DDG4/Geant4Callback.h
+++ b/DDG4/include/DDG4/Geant4Callback.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4Config.h b/DDG4/include/DDG4/Geant4Config.h
index 4d5a05dbc..f53eeb254 100644
--- a/DDG4/include/DDG4/Geant4Config.h
+++ b/DDG4/include/DDG4/Geant4Config.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4Context.h b/DDG4/include/DDG4/Geant4Context.h
index 958e360b0..f5d5bc29c 100644
--- a/DDG4/include/DDG4/Geant4Context.h
+++ b/DDG4/include/DDG4/Geant4Context.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4Converter.h b/DDG4/include/DDG4/Geant4Converter.h
index 901fd40cb..e2d35c7f0 100644
--- a/DDG4/include/DDG4/Geant4Converter.h
+++ b/DDG4/include/DDG4/Geant4Converter.h
@@ -1,4 +1,3 @@
-// $Id$
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/Geant4Handle.h b/DDG4/include/DDG4/Geant4Handle.h
index 83b660cd0..e7790aad5 100644
--- a/DDG4/include/DDG4/Geant4Handle.h
+++ b/DDG4/include/DDG4/Geant4Handle.h
@@ -56,7 +56,7 @@ namespace DD4hep {
       /// Copy constructor
       Geant4Handle(const Geant4Handle& handle);
       /// Move constructor
-      //Geant4Handle(Geant4Handle&& handle) = default;
+      Geant4Handle(Geant4Handle&& handle);
       /// Initializing constructor
       Geant4Handle(Geant4Kernel&, const char* type_name, bool shared=false);
       /// Initializing constructor
@@ -70,7 +70,7 @@ namespace DD4hep {
       /// Assignment operator
       Geant4Handle& operator=(const Geant4Handle& handle);
       /// Move assignment operator
-      //Geant4Handle& operator=(Geant4Handle&& handle) = default;
+      Geant4Handle& operator=(Geant4Handle&& handle);
       /// Assignment operator
       Geant4Handle& operator=(handled_type* ptr);
       /// Validity check
diff --git a/DDG4/include/DDG4/Geant4VolumeManager.h b/DDG4/include/DDG4/Geant4VolumeManager.h
index 4b1b5f20a..66fcac9ef 100644
--- a/DDG4/include/DDG4/Geant4VolumeManager.h
+++ b/DDG4/include/DDG4/Geant4VolumeManager.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/include/DDG4/IoStreams.h b/DDG4/include/DDG4/IoStreams.h
index af045ae00..1c6173db6 100644
--- a/DDG4/include/DDG4/IoStreams.h
+++ b/DDG4/include/DDG4/IoStreams.h
@@ -87,7 +87,7 @@ namespace DD4hep {
     /// Constructors taking file desciptors
     dd4hep_file(const char* fname, BOOST_IOS::openmode mode);
     /// Default destructor
-    ~dd4hep_file() = default;
+    //~dd4hep_file() = default;
     /// open overloads taking file descriptors
     void open(handle_type fd, dd4hep_file_flags flags);
     /// open overload taking C-style string
diff --git a/DDG4/lcio/LCIOEventReader.cpp b/DDG4/lcio/LCIOEventReader.cpp
index faa6e23b4..b689e3fff 100644
--- a/DDG4/lcio/LCIOEventReader.cpp
+++ b/DDG4/lcio/LCIOEventReader.cpp
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -61,7 +60,7 @@ LCIOEventReader::~LCIOEventReader()   {
 /// Read an event and fill a vector of MCParticles.
 LCIOEventReader::EventReaderStatus
 LCIOEventReader::readParticles(int event_number, 
-			       Vertices& vertices,
+                               Vertices& vertices,
                                vector<Particle*>& particles)
 {
   EVENT::LCCollection*        primaries = 0;
@@ -150,11 +149,11 @@ LCIOEventReader::readParticles(int event_number,
     }
 
     if ( p->parents.size() == 0 )  {
-      PropertyMask status(p->status);
-      if ( status.isSet(G4PARTICLE_GEN_EMPTY) || status.isSet(G4PARTICLE_GEN_DOCUMENTATION) )
-	vtx->in.insert(p->id);  // Beam particles and primary quarks etc.
+      PropertyMask st(p->status);
+      if ( st.isSet(G4PARTICLE_GEN_EMPTY) || st.isSet(G4PARTICLE_GEN_DOCUMENTATION) )
+        vtx->in.insert(p->id);  // Beam particles and primary quarks etc.
       else
-	vtx->out.insert(p->id); // Stuff, to be given to Geant4 together with daughters
+        vtx->out.insert(p->id); // Stuff, to be given to Geant4 together with daughters
     }
 
     if ( mcp->isCreatedInSimulation() )       status.set(G4PARTICLE_SIM_CREATED);
diff --git a/DDG4/src/Geant4Handle.cpp b/DDG4/src/Geant4Handle.cpp
index 46008a4b2..371f6a03e 100644
--- a/DDG4/src/Geant4Handle.cpp
+++ b/DDG4/src/Geant4Handle.cpp
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -63,12 +62,17 @@ namespace DD4hep {
         value->addRef();
     }
 
-    template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(const Geant4Handle<TYPE>& handle)
-      : value(handle.get()) {
+    template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(const Geant4Handle<TYPE>& handle) : value(handle.get())
+    {
       if (value)
         value->addRef();
     }
 
+    template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(Geant4Handle<TYPE>&& handle) : value(handle.get())
+    {
+      handle.value = 0;
+    }
+
     template <typename TYPE> TYPE* _create_object(Geant4Kernel& kernel, const TypeName& typ)    {
       Geant4Context* ctxt = kernel.workerContext();
       Geant4Action* object = PluginService::Create<Geant4Action*>(typ.first, ctxt, typ.second);
@@ -193,6 +197,14 @@ namespace DD4hep {
       return *this;
     }
 
+    /// Assignment move operator
+    template <typename TYPE> Geant4Handle<TYPE>& Geant4Handle<TYPE>::operator=(Geant4Handle&& handle) {
+      if ( value ) value->release();
+      value = handle.get();
+      handle.value = 0;
+      return *this;
+    }
+
     template <typename TYPE> Geant4Handle<TYPE>& Geant4Handle<TYPE>::operator=(TYPE* pointer) {
       if ( pointer != value )  {
         TYPE* point = value;
diff --git a/DDG4/src/Geant4Random.cpp b/DDG4/src/Geant4Random.cpp
index a2b207087..9e48e44b5 100644
--- a/DDG4/src/Geant4Random.cpp
+++ b/DDG4/src/Geant4Random.cpp
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -249,9 +248,13 @@ void Geant4Random::showStatus() const    {
   printP2("   Instance is %sidentical to ROOT's gRandom instance.",
           gRandom == m_rootRandom ? "" : "NOT ");
 
-  if ( gRandom != m_rootRandom )  {
+  if ( gRandom != m_rootRandom )   {
     printP2("      Local TRandom: 0x%p  gRandom: 0x%p",m_rootRandom,gRandom);
-  }  
+  }
+  else if ( !m_engine )   {
+    error("   Geant4Random instance has not engine attached!");
+    return;
+  }
   m_engine->showStatus();
 }
 
diff --git a/DDRec/include/DDRec/API/IDDecoder.h b/DDRec/include/DDRec/API/IDDecoder.h
index 321842472..8ea3190aa 100644
--- a/DDRec/include/DDRec/API/IDDecoder.h
+++ b/DDRec/include/DDRec/API/IDDecoder.h
@@ -39,10 +39,15 @@ public:
 			EndcapNorth,
 			n_BarrelEndcapID
 		};
-		BarrelEndcapFlag(unsigned int val) :
-			value(static_cast<BarrelEncapID>(val)) {}
+		BarrelEndcapFlag(unsigned int val) : value(static_cast<BarrelEncapID>(val)) {}
 
-		virtual ~BarrelEndcapFlag() {}
+		BarrelEndcapFlag() = default;
+
+    BarrelEndcapFlag(const BarrelEndcapFlag& copy) = default;
+
+		virtual ~BarrelEndcapFlag() = default;
+
+		BarrelEndcapFlag& operator=(const BarrelEndcapFlag& copy) = default;
 
 		bool isBarrel() const {
 			return value == Barrel;
@@ -65,7 +70,7 @@ public:
 		}
 
 	protected:
-		BarrelEncapID value;
+		BarrelEncapID value = Barrel;
 	};
 
 	/// Access to the global IDDecoder instance
diff --git a/DDRec/include/DDRec/SurfaceManager.h b/DDRec/include/DDRec/SurfaceManager.h
index ee80e7532..6208b7645 100644
--- a/DDRec/include/DDRec/SurfaceManager.h
+++ b/DDRec/include/DDRec/SurfaceManager.h
@@ -24,10 +24,17 @@ namespace DD4hep {
       typedef std::map< std::string,  SurfaceMap > SurfaceMapsMap ;
 
     public:
-
+      /// Default constructor
       SurfaceManager();
+
+      /// No copy constructor
+      SurfaceManager(const SurfaceManager& copy) = delete;
       
+      /// Default destructor
       ~SurfaceManager();
+
+      /// No assignment operator
+      SurfaceManager& operator=(const SurfaceManager& copy) = delete;
       
       /** Get the maps of all surfaces associated to the given detector or
        *  type of detectors, e.g. map("tracker") returns a map with all surfaces
diff --git a/DDRec/src/SurfaceHelper.cpp b/DDRec/src/SurfaceHelper.cpp
index a838003de..b15e8f882 100644
--- a/DDRec/src/SurfaceHelper.cpp
+++ b/DDRec/src/SurfaceHelper.cpp
@@ -27,7 +27,7 @@ namespace DD4hep {
       // have to populate the volume manager once in order to have 
       // the volumeIDs attached to the DetElements
       LCDD& lcdd = LCDD::getInstance();
-      VolumeManager volMgr = VolumeManager::getVolumeManager(lcdd);
+      /* VolumeManager volMgr = */ VolumeManager::getVolumeManager(lcdd);
 
       //------------------ breadth first tree traversal ---------
       std::list< DetElement > dets ;
@@ -38,16 +38,16 @@ namespace DD4hep {
       
       while( ! daugs.empty() ) {
 	
-	for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){
-	  DetElement dau = *li ;
-	  DetElement::Children chMap = dau.children() ;
-	  for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){
-	    DetElement de = (*it).second ;
-	    gdaugs.push_back( de ) ;
-	  }  
-	}
-	dets.splice( dets.end() , daugs ) ;
-	daugs.splice( daugs.end() , gdaugs ) ;
+        for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){
+          DetElement dau = *li ;
+          DetElement::Children chMap = dau.children() ;
+          for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){
+            DetElement de = (*it).second ;
+            gdaugs.push_back( de ) ;
+          }  
+        }
+        dets.splice( dets.end() , daugs ) ;
+        daugs.splice( daugs.end() , gdaugs ) ;
       }
       //------------------ end tree traversal ---------
       
@@ -55,34 +55,34 @@ namespace DD4hep {
       
       for( std::list< DetElement >::iterator li=dets.begin() ; li != dets.end() ; ++li ) {
 	
-	DetElement det = (*li) ;
+        DetElement det = (*li) ;
 	
 
 
-	// create surfaces
-	DetectorSurfaces ds( det ) ;
+        // create surfaces
+        DetectorSurfaces ds( det ) ;
 	
-	const SurfaceList& detSL = ds.surfaceList() ;
+        const SurfaceList& detSL = ds.surfaceList() ;
 
 
-	// // ---------------------- debug printout
-	// std::cout << " ---- DetElement id: " << det.volumeID() << " name : " << det.name() << "  #surfaces : " << detSL.size() << std::endl ; 
-	// PlacedVolume pv = det.placement() ;
-	// if( pv.isValid() ) {
-	//   try{ // needed as above is also true for world whcih has invalid placment ...
-	//     PlacedVolume::VolIDs volIDs = pv.volIDs() ;
-	//     for(unsigned i=0,n=volIDs.size(); i<n ; ++i){
-	//       std::cout << "        " << volIDs[i].first << " : " << volIDs[i].second << std::endl ;
-	//     }
-	//   }catch(...){}
-	// }else{
-	//   std::cout << "        invalid placement for DetElement ??? !! " << std::endl ;
-	// }
-	// // ------------------------- end debug printout
+        // // ---------------------- debug printout
+        // std::cout << " ---- DetElement id: " << det.volumeID() << " name : " << det.name() << "  #surfaces : " << detSL.size() << std::endl ; 
+        // PlacedVolume pv = det.placement() ;
+        // if( pv.isValid() ) {
+        //   try{ // needed as above is also true for world whcih has invalid placment ...
+        //     PlacedVolume::VolIDs volIDs = pv.volIDs() ;
+        //     for(unsigned i=0,n=volIDs.size(); i<n ; ++i){
+        //       std::cout << "        " << volIDs[i].first << " : " << volIDs[i].second << std::endl ;
+        //     }
+        //   }catch(...){}
+        // }else{
+        //   std::cout << "        invalid placement for DetElement ??? !! " << std::endl ;
+        // }
+        // // ------------------------- end debug printout
 
 
-	// and add copy them to this list
-	_sL.insert( _sL.end(), detSL.begin(), detSL.end() );
+        // and add copy them to this list
+        _sL.insert( _sL.end(), detSL.begin(), detSL.end() );
       }
       
     }
diff --git a/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h b/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h
index fd9104d1e..b09871946 100644
--- a/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h
+++ b/DDSegmentation/include/DDSegmentation/MegatileLayerGridXY.h
@@ -16,19 +16,19 @@
 
 /*
 
-a megatile is a rectangule in x-y, split into a grid along x and y, with an exactly integer number of cells in x and y.
+  a megatile is a rectangule in x-y, split into a grid along x and y, with an exactly integer number of cells in x and y.
 
-this class assumes a mostly-common megatile size, with possibility for a number of "special" megatiles of non-standard size / segmentation
+  this class assumes a mostly-common megatile size, with possibility for a number of "special" megatiles of non-standard size / segmentation
 
-the segmentation of standard megatiles is defined layer-by-layer.
+  the segmentation of standard megatiles is defined layer-by-layer.
 
-some changes wrt previous version from Kotera et al.
-- significantly simplified. 
-- complications due to end-of-slab moved to higher level detector drivers.
+  some changes wrt previous version from Kotera et al.
+  - significantly simplified. 
+  - complications due to end-of-slab moved to higher level detector drivers.
 
-D. Jeans - Nov 2016
+  D. Jeans - Nov 2016
 
- */
+*/
 
 
 namespace DD4hep {
@@ -65,15 +65,15 @@ namespace DD4hep {
       }
 
       void setMegaTileCellsXY( unsigned int layer, int ix, int iy ) {
-	assert ( layer < MAX_LAYERS );
-	_nCellsX[layer] = ix;
-	_nCellsY[layer] = iy;
+        assert ( layer < MAX_LAYERS );
+        _nCellsX[layer] = ix;
+        _nCellsY[layer] = iy;
       }
 
       void setSpecialMegaTile( unsigned int layer, unsigned int tile, 
-			       double sizex, double sizey,
-			       double offsetx, double offsety,
-			       unsigned int ncellsx, unsigned int ncellsy );
+                               double sizex, double sizey,
+                               double offsetx, double offsety,
+                               unsigned int ncellsx, unsigned int ncellsy );
 
       /// access the field name used for X
       const std::string& fieldNameX() const {
@@ -100,12 +100,13 @@ namespace DD4hep {
     protected:
 
       struct segInfo {
-	double megaTileSizeX;
-	double megaTileSizeY;
-	double megaTileOffsetX;
-	double megaTileOffsetY;
-	unsigned int nCellsX;
-	unsigned int nCellsY;
+        double megaTileSizeX = 0;
+        double megaTileSizeY = 0;
+        double megaTileOffsetX = 0;
+        double megaTileOffsetY = 0;
+        unsigned int nCellsX = 0;
+        unsigned int nCellsY = 0;
+        segInfo() = default;
       };
 
       mutable segInfo _currentSegInfo;
@@ -117,11 +118,11 @@ namespace DD4hep {
       //  the segmentation may change layer-to-layer (e.g. orthogonal strips)
 
       // total size of surface in X,Y
-      double  _megaTileSizeX; // [MAX_LAYERS][MAX_WAFERS];
-      double  _megaTileSizeY; //[MAX_LAYERS][MAX_WAFERS];
+      double  _megaTileSizeX = 0; // [MAX_LAYERS][MAX_WAFERS];
+      double  _megaTileSizeY = 0; //[MAX_LAYERS][MAX_WAFERS];
 
-      double  _megaTileOffsetX; 
-      double  _megaTileOffsetY; 
+      double  _megaTileOffsetX = 0;
+      double  _megaTileOffsetY = 0;
 
       // number of cells per megatile in X, Y
       unsigned int _nCellsX[MAX_LAYERS];
@@ -145,6 +146,6 @@ namespace DD4hep {
 
     };
 
-  } /* namespace DDSegmentation */
-} /* namespace DD4hep */
-#endif /* DDSegmentation_WAFERGRIDXY_H_ */
+  }    /* namespace DDSegmentation              */
+}      /* namespace DD4hep                      */
+#endif /* DDSegmentation_MEGATILELAYERGRIDXY_H_ */
diff --git a/DDSegmentation/src/MegatileLayerGridXY.cpp b/DDSegmentation/src/MegatileLayerGridXY.cpp
index ad4854d07..b28124101 100644
--- a/DDSegmentation/src/MegatileLayerGridXY.cpp
+++ b/DDSegmentation/src/MegatileLayerGridXY.cpp
@@ -18,7 +18,8 @@ namespace DD4hep {
 
     /// default constructor using an encoding string
     MegatileLayerGridXY::MegatileLayerGridXY(const std::string& cellEncoding) :
-      CartesianGrid(cellEncoding) {
+      CartesianGrid(cellEncoding)
+    {
       setup();
     }
 
diff --git a/GaudiPluginService/CMakeLists.txt b/GaudiPluginService/CMakeLists.txt
index 9e7aef7c8..66e152b17 100644
--- a/GaudiPluginService/CMakeLists.txt
+++ b/GaudiPluginService/CMakeLists.txt
@@ -9,6 +9,9 @@ add_definitions(-DGaudi=DD4hep_Flavor)
 if( APPLE ) 
   add_definitions( -DAPPLE) 
 endif()
+target_compile_options(DD4hepGaudiPluginMgr PRIVATE -Wno-unused-function)
+target_compile_options(DD4hepGaudiPluginMgr PRIVATE -Wno-deprecated)
+target_compile_options(DD4hepGaudiPluginMgr PRIVATE -Wno-shadow)
 
 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 target_link_libraries(DD4hepGaudiPluginMgr ${CMAKE_DL_LIBS})
@@ -21,6 +24,7 @@ endif()
 
 add_executable(listcomponents src/listcomponents.cpp ) #src/PluginService.cpp)
 target_link_libraries(listcomponents DD4hepGaudiPluginMgr  ${CMAKE_DL_LIBS} )
+target_compile_options(listcomponents PRIVATE -Wno-deprecated)
 
 install(TARGETS listcomponents DD4hepGaudiPluginMgr
   RUNTIME DESTINATION bin
diff --git a/GaudiPluginService/interface/DD4hep.cpp b/GaudiPluginService/interface/DD4hep.cpp
index 535548a03..f5f3480d7 100644
--- a/GaudiPluginService/interface/DD4hep.cpp
+++ b/GaudiPluginService/interface/DD4hep.cpp
@@ -1,4 +1,3 @@
-// $Id$
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -18,12 +17,23 @@
 #include <typeinfo>
 #include <utility>
 
+#define Gaudi DD4hep_Flavor
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wkeyword-macro"
+#endif
+
 #define private public
 // This define will give us a version of the gaudi plugin manager,
 // which will NOT clash with Gaudi! It of course has a correspondance in the
 // compiler options of the GaudiPluginService package.
-#define Gaudi DD4hep_Flavor
 #include "Gaudi/PluginService.h"
+#undef private
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 
 extern "C"  {
   /// Access debug level
diff --git a/UtilityApps/src/graphicalMaterialScan.cpp b/UtilityApps/src/graphicalMaterialScan.cpp
index 8fa054d17..ab3fb19ac 100644
--- a/UtilityApps/src/graphicalMaterialScan.cpp
+++ b/UtilityApps/src/graphicalMaterialScan.cpp
@@ -46,7 +46,7 @@ using DDSurfaces::Vector3D;
 using std::cout;
 using std::endl;
 
-int main(int argc, char** argv)   {
+int main_wrapper(int argc, char** argv)   {
   struct Handler  {
     Handler() { SetErrorHandler(Handler::print); }
     static void print(int level, Bool_t abort, const char *location, const char *msg)  {
@@ -54,11 +54,11 @@ int main(int argc, char** argv)   {
     }
     static void usage()  {
       std::cout << " usage: graphicalMaterialScan compact.xml axis xMin yMin zMin xMax yMax zMax nSlices nBins nSamples" << std::endl
-		<< " axis (X, Y, or Z)             : perpendicular to the slices" << std::endl 
-		<< " xMin yMin zMin xMax yMax zMax : range of scans " << std::endl 
-		<< " nSlices                       : number of slices (equally spaced along chose axis)" << std::endl 
-		<< " nBins                         : number of bins along each axis of histograms" << std::endl 
-		<< " nSamples                      : the number of times each bin is sampled " << std::endl 
+                << " axis (X, Y, or Z)             : perpendicular to the slices" << std::endl 
+                << " xMin yMin zMin xMax yMax zMax : range of scans " << std::endl 
+                << " nSlices                       : number of slices (equally spaced along chose axis)" << std::endl 
+                << " nBins                         : number of bins along each axis of histograms" << std::endl 
+                << " nSamples                      : the number of times each bin is sampled " << std::endl 
                 << "        -> produces graphical scans of the detector material "
                 << std::endl;
       exit(1);
@@ -159,8 +159,8 @@ int main(int argc, char** argv)   {
 
     for (int j=1; j<=2; j++) {
       if ( mmax[index[j]] - mmin[index[j]] < 1e-4 ) {
-	cout << "ERROR: max and min of axis are the same!" << endl;
-	assert(0);
+        cout << "ERROR: max and min of axis are the same!" << endl;
+        assert(0);
       }
     }
 
@@ -181,62 +181,62 @@ int main(int argc, char** argv)   {
 
       for (int iy=1; iy<=h2slice->GetNbinsY(); iy++) { // and the other axis
 
-	double ymin = h2slice->GetYaxis()->GetBinLowEdge(iy);
-	double ymax = h2slice->GetYaxis()->GetBinUpEdge(iy);
-
-	// for this bin, estimate the material
-	double sum_lambda(0);
-	double sum_x0(0);
-	double sum_length(0);
-
-	std::map < std::string , float > materialmap;
-
-	for (unsigned int jx=0; jx<2*mm; jx++) {
-	  if ( jx<mm ) {
-	    double xcom = xmin + (1+jx)*( xmax - xmin )/(mm+1.);
-	    p0.array()[index[1]] = xcom;  p0.array()[index[2]] = ymin;
-	    p1.array()[index[1]] = xcom;  p1.array()[index[2]] = ymax;
-	  } else {
-	    double ycom =  ymin + (jx-mm+1)*( ymax - ymin )/(mm+1.);
-	    p0.array()[index[1]] = xmin;  p0.array()[index[2]] = ycom;
-	    p1.array()[index[1]] = xmax;  p1.array()[index[2]] = ycom;
-	  }
-
-	  const MaterialVec& materials = matMgr.materialsBetween(p0, p1);
-	  for( unsigned i=0,n=materials.size();i<n;++i){
-	    TGeoMaterial* mat =  materials[i].first->GetMaterial();
-	    double length = materials[i].second;
-	    sum_length += length;
-	    double nx0 = length / mat->GetRadLen();
-	    sum_x0 += nx0;
-	    double nLambda = length / mat->GetIntLen();
-	    sum_lambda += nLambda;
-
-	    std::string mname = mat->GetName();
-	    if ( materialmap.find( mname )!=materialmap.end() ) {
-	      materialmap[mname]+=length;
-	    } else {
-	      materialmap[mname]=length;
-	    }
-
-	  }
-
-	}
+        double ymin = h2slice->GetYaxis()->GetBinLowEdge(iy);
+        double ymax = h2slice->GetYaxis()->GetBinUpEdge(iy);
+
+        // for this bin, estimate the material
+        double sum_lambda(0);
+        double sum_x0(0);
+        double sum_length(0);
+
+        std::map < std::string , float > materialmap;
+
+        for (unsigned int jx=0; jx<2*mm; jx++) {
+          if ( jx<mm ) {
+            double xcom = xmin + (1+jx)*( xmax - xmin )/(mm+1.);
+            p0.array()[index[1]] = xcom;  p0.array()[index[2]] = ymin;
+            p1.array()[index[1]] = xcom;  p1.array()[index[2]] = ymax;
+          } else {
+            double ycom =  ymin + (jx-mm+1)*( ymax - ymin )/(mm+1.);
+            p0.array()[index[1]] = xmin;  p0.array()[index[2]] = ycom;
+            p1.array()[index[1]] = xmax;  p1.array()[index[2]] = ycom;
+          }
+
+          const MaterialVec& materials = matMgr.materialsBetween(p0, p1);
+          for( unsigned i=0,n=materials.size();i<n;++i){
+            TGeoMaterial* mat =  materials[i].first->GetMaterial();
+            double length = materials[i].second;
+            sum_length += length;
+            double nx0 = length / mat->GetRadLen();
+            sum_x0 += nx0;
+            double nLambda = length / mat->GetIntLen();
+            sum_lambda += nLambda;
+
+            std::string mname = mat->GetName();
+            if ( materialmap.find( mname )!=materialmap.end() ) {
+              materialmap[mname]+=length;
+            } else {
+              materialmap[mname]=length;
+            }
+
+          }
+
+        }
 	
-	scanmap["x0"]->SetBinContent(ix, iy, sum_x0/sum_length); // normalise to cm (ie x0/cm density: indep of bin size)
-	scanmap["lambda"]->SetBinContent(ix, iy, sum_lambda/sum_length);
-
-	for (  std::map < std::string , float >::iterator jj = materialmap.begin(); jj!=materialmap.end(); jj++) {
-	  if ( scanmap.find( jj->first )==scanmap.end() ) {
-	    hn = "slice"; hn+=isl; hn+="_"+jj->first;
-	    hnn = jj->first; hnn += " "+XYZ; hnn+="="; 
-	    // hnn+=sz; 
-	    hnn += Form("%7.3f",sz);
-	    hnn+=" [cm]";
-	    scanmap[jj->first] = new TH2F( hn, hnn, nbins, mmin[index[1]], mmax[index[1]], nbins, mmin[index[2]], mmax[index[2]] );
-	  }
-	  scanmap[jj->first]->SetBinContent(ix, iy, jj->second / sum_length );
-	}
+        scanmap["x0"]->SetBinContent(ix, iy, sum_x0/sum_length); // normalise to cm (ie x0/cm density: indep of bin size)
+        scanmap["lambda"]->SetBinContent(ix, iy, sum_lambda/sum_length);
+
+        for (  std::map < std::string , float >::iterator jj = materialmap.begin(); jj!=materialmap.end(); jj++) {
+          if ( scanmap.find( jj->first )==scanmap.end() ) {
+            hn = "slice"; hn+=isl; hn+="_"+jj->first;
+            hnn = jj->first; hnn += " "+XYZ; hnn+="="; 
+            // hnn+=sz; 
+            hnn += Form("%7.3f",sz);
+            hnn+=" [cm]";
+            scanmap[jj->first] = new TH2F( hn, hnn, nbins, mmin[index[1]], mmax[index[1]], nbins, mmin[index[2]], mmax[index[2]] );
+          }
+          scanmap[jj->first]->SetBinContent(ix, iy, jj->second / sum_length );
+        }
 
 
       }
@@ -247,13 +247,22 @@ int main(int argc, char** argv)   {
       jj->second->GetXaxis()->SetTitle(labx);
       jj->second->GetYaxis()->SetTitle(laby);
     }
-
-
   }
-
-
   f->Write();
   f->Close();
-
   return 0;
 }
+
+/// Main entry point as a program
+int main(int argc, char** argv)   {
+  try  {
+    return main_wrapper(argc, argv);
+  }
+  catch(const std::exception& e)  {
+    std::cout << "Got uncaught exception: " << e.what() << std::endl;
+  }
+  catch (...)  {
+    std::cout << "Got UNKNOWN uncaught exception." << std::endl;
+  }
+  return EINVAL;    
+}
diff --git a/UtilityApps/src/test_surfaces.cpp b/UtilityApps/src/test_surfaces.cpp
index 59e3c6afd..13d9e84b0 100644
--- a/UtilityApps/src/test_surfaces.cpp
+++ b/UtilityApps/src/test_surfaces.cpp
@@ -81,7 +81,7 @@ int main(int argc, char** argv ){
   }
 #else  
 
-  SurfaceManager surfMan = *lcdd.extension< SurfaceManager >() ;
+  SurfaceManager& surfMan = *lcdd.extension< SurfaceManager >() ;
   const SurfaceMap& surfMap = *surfMan.map( "world" ) ;
 
 #endif
diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt
index 89d8259bb..01d6f1cfb 100644
--- a/examples/AlignDet/CMakeLists.txt
+++ b/examples/AlignDet/CMakeLists.txt
@@ -81,6 +81,14 @@ dd4hep_add_test_reg( test_AlignDet_Telescope_readback_xml
      -deltas file:./new_cond.xml
   REGEX_PASS "\\[7438F09CE3AD4ACA\\] -> \\[7438F09CE3AD4ACA\\] /world/Telescope/module_9/sensor#alignment/Transformations")
 #
+#---Testing: Load Telescope geometry and read and print alignments --------
+dd4hep_add_test_reg( test_AlignDet_Telescope_align_new
+  COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh"
+  EXEC_ARGS  geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_align_telescope
+     -input  file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml
+     -setup  file:${DD4hep_DIR}/examples/Conditions/data/manager.xml 
+  REGEX_PASS "World transformation of: /world/Telescope/module_3/sensor  Tr:\\( 3.9e\\+02,       0,     4.9 \\[cm\\]\\)")
+#
 #---Testing: Extended stress: Load CLICSiD geometry and have multiple runs on IOVs
 dd4hep_add_test_reg( test_AlignDet_CLICSiD_stress_LONGTEST
   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh"
diff --git a/examples/AlignDet/src/AlignmentExample_align_telescope.cpp b/examples/AlignDet/src/AlignmentExample_align_telescope.cpp
index 17f673262..ec2298ad7 100644
--- a/examples/AlignDet/src/AlignmentExample_align_telescope.cpp
+++ b/examples/AlignDet/src/AlignmentExample_align_telescope.cpp
@@ -48,7 +48,9 @@ using Geometry::Position;
 static void print_world_trafo(AlignmentsCalib& calib, const std::string& path)  {
   DetAlign  d(calib.detector(path));
   Alignment a = d.alignments().get("Alignment",*calib.slice.pool);
-  printout(INFO,"Example","++ World transformation of: %s", path.c_str());
+  const double* tr = a->worldTransformation().GetTranslation();
+  printout(INFO,"Example","++ World transformation of: %-32s  Tr:(%8.2g,%8.2g,%8.2g [cm])",
+           path.c_str(), tr[0],tr[1],tr[2]);
   a->worldTransformation().Print();
 }
 
-- 
GitLab