From 62502aba61e999a532663e461ce66381016aa61e Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Fri, 3 Feb 2017 09:40:10 +0100
Subject: [PATCH] Evolve alignments and conditions -- not backwards compatible!

---
 DDAlign/src/GlobalAlignmentOperators.cpp      |  10 +-
 DDCond/include/DDCond/ConditionsTags.h        |   2 +
 .../plugins/ConditionsRepositoryParser.cpp    |  19 +-
 .../plugins/ConditionsRepositoryWriter.cpp    | 224 +++++++++++++-----
 DDCore/include/DD4hep/ComponentProperties.h   |  10 +-
 DDCore/include/DD4hep/IOV.h                   |  12 +-
 DDCore/include/DD4hep/LCDDData.h              |  26 +-
 DDCore/include/DD4hep/MultiSegmentation.h     |   1 +
 DDCore/include/DD4hep/Path.h                  |  18 +-
 DDCore/include/DD4hep/PolarGridRPhi.h         |   1 +
 DDCore/include/DD4hep/PolarGridRPhi2.h        |   1 +
 DDCore/include/DD4hep/WaferGridXY.h           |   1 +
 DDCore/src/ComponentProperties.cpp            |   5 +
 DDCore/src/IOV.cpp                            |   2 +
 DDCore/src/LCDDData.cpp                       |   2 +-
 DDCore/src/XML/XMLElements.cpp                |   2 +-
 DDDB/include/DDDB/DDDBConversion.h            |   2 +-
 DDDB/src/CondDB2DDDB.cpp                      |   4 +-
 DDDB/src/DDDB2Objects.cpp                     |   6 +-
 DDDB/src/DDDBConversion.cpp                   |   2 +-
 DDDB/src/DDDBFileReader.cpp                   |  26 +-
 DDEve/include/DDEve/DisplayConfiguration.h    |  12 +-
 DDEve/src/DisplayConfiguration.cpp            |   6 +-
 DDEve/src/DisplayConfigurationParser.cpp      |   8 +-
 DDEve/src/Projection.cpp                      |   3 +-
 DDEve/src/Utilities.cpp                       |   1 -
 DDG4/g4FromXML.cpp                            |  20 +-
 DDG4/include/DDG4/DDG4Dict.h                  |  13 +-
 DDG4/include/DDG4/Geant4Handle.h              |   9 +-
 DDG4/src/Geant4Converter.cpp                  |   8 +-
 DDG4/src/Geant4Handle.cpp                     |  83 ++++---
 DDG4/src/Geant4ParticleHandler.cpp            |  30 ++-
 UtilityApps/src/converter.cpp                 | 127 +++++-----
 UtilityApps/src/dumpdetector.cpp              |   8 +-
 UtilityApps/src/plugin_runner.cpp             |  67 ++++--
 examples/AlignDet/CMakeLists.txt              |  26 ++
 36 files changed, 524 insertions(+), 273 deletions(-)

diff --git a/DDAlign/src/GlobalAlignmentOperators.cpp b/DDAlign/src/GlobalAlignmentOperators.cpp
index 38df2649f..cff58cd10 100644
--- a/DDAlign/src/GlobalAlignmentOperators.cpp
+++ b/DDAlign/src/GlobalAlignmentOperators.cpp
@@ -90,8 +90,14 @@ template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_reset>::
           else if ( i==nLvl ) {
             TGeoHMatrix* hm = dynamic_cast<TGeoHMatrix*>(mm);
             TGeoMatrix*  org = p->GetOriginalMatrix();
-            hm->SetTranslation(org->GetTranslation());
-            hm->SetRotation(org->GetRotationMatrix());
+            if ( hm && org )  {
+              hm->SetTranslation(org->GetTranslation());
+              hm->SetRotation(org->GetRotationMatrix());
+            }
+            else  {
+              printout(ALWAYS,"GlobalAlignmentActor<reset>",
+                       "Invalid operation: %p %p", (void*)hm, (void*)org);
+            }
           }
           *glob *= *mm;
         }
diff --git a/DDCond/include/DDCond/ConditionsTags.h b/DDCond/include/DDCond/ConditionsTags.h
index 62a5c202e..a0253a212 100644
--- a/DDCond/include/DDCond/ConditionsTags.h
+++ b/DDCond/include/DDCond/ConditionsTags.h
@@ -41,11 +41,13 @@ namespace DD4hep {
       UNICODE(iov);
       UNICODE(iov_type);
       UNICODE(manager);
+      UNICODE(property);
 
       UNICODE(hash);
       UNICODE(mapping);
       UNICODE(sequence);
       UNICODE(alignment);
+      UNICODE(repository);
     }
     // User must ensure there are no clashes. If yes, then the clashing entry is unnecessary.
     using namespace ::DD4hep::XML::Conditions;
diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp
index 83403f75d..2813051cf 100644
--- a/DDCond/src/plugins/ConditionsRepositoryParser.cpp
+++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp
@@ -227,14 +227,19 @@ namespace DD4hep {
    */
   template <> void Converter<iov>::operator()(xml_h element) const {
     xml_dim_t e   = element;
-    string    ref = e.attr<string>(_U(ref));
     string    val = e.attr<string>(_U(validity));
     ConversionArg* arg  = _param<ConversionArg>();
     CurrentPool pool(arg);
-    printout(s_parseLevel,"XMLConditions","++ Reading IOV file: %s -> %s", val.c_str(), ref.c_str());
+
     pool.set(arg->manager.registerIOV(val));
-    XML::DocumentHolder doc(XML::DocumentHandler().load(element, element.attr_value(_U(ref))));
-    Converter<conditions>(lcdd,param,optional)(doc.root());
+    if ( e.hasAttr(_U(ref)) )  {
+      string    ref = e.attr<string>(_U(ref));
+      printout(s_parseLevel,"XMLConditions","++ Reading IOV file: %s -> %s",val.c_str(),ref.c_str());
+      XML::DocumentHolder doc(XML::DocumentHandler().load(element, element.attr_value(_U(ref))));
+      Converter<conditions>(lcdd,param,optional)(doc.root());
+      return;
+    }
+    xml_coll_t(e,_UC(detelement)).for_each(Converter<arbitrary>(lcdd,param,optional));
   }
 
   /// Convert manager repository objects
@@ -245,13 +250,13 @@ namespace DD4hep {
    */
   template <> void Converter<manager>::operator()(xml_h element) const {
     ConversionArg* arg  = _param<ConversionArg>();
-    for( xml_coll_t c(element,_Unicode(property)); c; ++c)  {
+    for( xml_coll_t c(element,_UC(property)); c; ++c)  {
       xml_dim_t d = c;
       string nam = d.nameStr();
       string val = d.valueStr();
       try  {
         printout(s_parseLevel,"XMLConditions","++ Setup conditions Manager[%s] = %s",nam.c_str(),val.c_str());
-        arg->manager[nam] = val;
+        arg->manager[nam].str(val);
       }
       catch(const std::exception& e)  {
         printout(ERROR,"XMLConditions","++ FAILED: conditions Manager[%s] = %s [%s]",nam.c_str(),val.c_str(),e.what());
@@ -516,6 +521,8 @@ namespace DD4hep {
       Converter<repository>(lcdd,param,optional)(e);
     else if ( tag == "manager" )  
       Converter<manager>(lcdd,param,optional)(e);
+    else if ( tag == "conditions" )  
+      Converter<conditions>(lcdd,param,optional)(e);
     else if ( tag == "detelement" )
       Converter<detelement>(lcdd,param,optional)(e);
     else if ( tag == "iov" )         // Processing repository file
diff --git a/DDCond/src/plugins/ConditionsRepositoryWriter.cpp b/DDCond/src/plugins/ConditionsRepositoryWriter.cpp
index 8dad40c3d..6cb994099 100644
--- a/DDCond/src/plugins/ConditionsRepositoryWriter.cpp
+++ b/DDCond/src/plugins/ConditionsRepositoryWriter.cpp
@@ -15,18 +15,19 @@
 
 // Framework include files
 #include "DD4hep/LCDD.h"
-#include "DDCond/ConditionsManager.h"
 #include "XML/XMLElements.h"
+#include "DDCond/ConditionsManager.h"
 
 // C/C++ include files
 
-
-
 /// Namespace for the AIDA detector description toolkit
 namespace DD4hep {
 
   /// Namespace for the geometry part of the AIDA detector description toolkit
   namespace Conditions {
+
+    // Forward declarations
+    class ConditionsSlice;
     
     /// Conditions slice object. Defines which conditions should be loaded by the ConditionsManager.
     /**
@@ -44,25 +45,26 @@ namespace DD4hep {
      *  \ingroup DD4HEP_CONDITIONS
      */
     class ConditionsXMLRepositoryWriter  {
-      ConditionsManager manager;
     public:
       /// Default constructor
-      ConditionsXMLRepositoryWriter() = delete;
+      ConditionsXMLRepositoryWriter() = default;
       /// Copy constructor (Special, partial copy only. Hence no assignment!)
-      ConditionsXMLRepositoryWriter(const ConditionsXMLRepositoryWriter& copy) = delete;
-      /// Initializing constructor
-      ConditionsXMLRepositoryWriter(ConditionsManager& mgr);
+      ConditionsXMLRepositoryWriter(const ConditionsXMLRepositoryWriter& copy) = default;
       /// Default destructor. 
-      virtual ~ConditionsXMLRepositoryWriter();
+      virtual ~ConditionsXMLRepositoryWriter() = default;
      
       /// Dump the tree content into a XML document structure
-      size_t collectConditions(XML::Element root,
-                               ConditionsSlice& slice,
-                               DetElement detector)  const;
+      XML::Document dump(ConditionsSlice& slice)  const;
+      /// Dump the ConditionsManager configuration properties into a XML document structure
+      XML::Document dump(ConditionsManager manager)  const;
+      /// Dump the tree content into an existing XML document structure
+      size_t collect(XML::Element root,ConditionsSlice& slice,DetElement detector)  const;
+      /// Dump the ConditionsManager configuration properties into an existing XML document structure
+      size_t collect(XML::Element root, ConditionsManager manager)  const;
+      /// Dump the conditions tree content into a XML document structure
+      size_t collect(XML::Element root, ConditionsSlice& slice)  const;
       /// Write the XML document structure to a file.
       long write(XML::Document doc, const std::string& output)   const;
-      /// Dump the tree content into a XML document structure
-      XML::Document dump(ConditionsSlice& slice, DetElement element)  const;
     };
     
   }        /* End namespace Conditions                          */
@@ -96,7 +98,7 @@ namespace DD4hep {
 
 #include "DDCond/ConditionsTags.h"
 #include "DDCond/ConditionsSlice.h"
-#include "DDCond/ConditionsManager.h"
+#include "DDCond/ConditionsManagerObject.h"
 
 // C/C++ include files
 #include <stdexcept>
@@ -125,6 +127,21 @@ namespace {
   class alignment;
   class value;
   class sequence;
+
+  class PropertyDumper {
+    XML::Element root;
+  public:
+    PropertyDumper(XML::Element p) : root(p)  {}
+    void operator()(const std::pair<string,Property>& p)  const  {
+      XML::Element e = XML::Element(root.document(),_UC(property));
+      string val = p.second.str();
+      if ( val[0] == '\'' ) val = p.second.str().c_str()+1;
+      if ( !val.empty() && val[val.length()-1] == '\'' ) val[val.length()-1] = 0;
+      e.setAttr(_U(name), p.first);
+      e.setAttr(_U(value), val);
+      root.append(e);
+    }
+  };
   
   template <typename T> XML::Element _convert(XML::Element par, Condition c);
 
@@ -222,29 +239,69 @@ namespace {
   }
 }
 
-/// Initializing constructor
-ConditionsXMLRepositoryWriter::ConditionsXMLRepositoryWriter(ConditionsManager& mgr)
-  : manager(mgr)
-{
-}
-
-/// Default destructor. 
-ConditionsXMLRepositoryWriter::~ConditionsXMLRepositoryWriter()   {
+/// Dump the tree content into a XML document structure
+XML::Document ConditionsXMLRepositoryWriter::dump(ConditionsSlice& slice)  const {
+  XML::DocumentHandler docH;
+  XML::Document doc = docH.create("conditions", docH.defaultComment());
+  collect(doc.root(),slice);
+  return doc;
 }
 
-/// Dump the tree content into a XML document structure
-XML::Document ConditionsXMLRepositoryWriter::dump(ConditionsSlice& slice, DetElement element)  const {
+/// Dump the ConditionsManager configuration properties into a XML document structure
+XML::Document ConditionsXMLRepositoryWriter::dump(ConditionsManager manager)  const {
   XML::DocumentHandler docH;
   XML::Document doc  = docH.create("conditions", docH.defaultComment());
   XML::Element  root = doc.root();
-  collectConditions(root,slice,element);
+  collect(root,manager);
   return doc;
 }
 
-/// Dump the tree content into a XML document structure
-size_t ConditionsXMLRepositoryWriter::collectConditions(XML::Element root,
-                                                        ConditionsSlice& slice,
-                                                        DetElement detector)  const
+/// Dump the conditions tree content into a XML document structure
+size_t ConditionsXMLRepositoryWriter::collect(XML::Element root, ConditionsSlice& slice)  const  {
+  XML::Element  repo(root.document(),_UC(repository));
+  XML::Element  iov (repo.document(),_UC(iov));
+  const IOV&    validity = slice.pool->validity();
+  char text[128];
+
+  root.append(repo);
+  repo.append(iov);
+  ::snprintf(text,sizeof(text),"%ld,%ld#%s",
+             validity.keyData.first,validity.keyData.second,
+             validity.iovType->name.c_str());
+  iov.setAttr(_UC(validity),text);
+  return collect(iov,slice,slice.manager->lcdd().world());
+}
+
+/// Dump the ConditionsManager configuration properties into an existing XML document structure
+size_t ConditionsXMLRepositoryWriter::collect(XML::Element root,
+                                              ConditionsManager manager)  const
+{
+  size_t count = 0;
+  if ( manager.isValid() )  {
+    /// Access to the property manager
+    PropertyManager& prp = manager.properties();
+    XML::Element     rep(root.document(),_UC(repository));
+    XML::Element     mgr(rep.document(),_UC(manager));
+    const auto iovs = manager.iovTypesUsed();
+
+    prp.for_each(PropertyDumper(mgr));
+    rep.append(mgr);
+    count += prp.size();
+    for ( const auto t : iovs )  {
+      XML::Element iov_typ(rep.document(),_UC(iov_type));
+      iov_typ.setAttr(_U(name),t->name);
+      iov_typ.setAttr(_U(id),int(t->type));
+      rep.append(iov_typ);
+    }
+    root.append(rep);
+  }
+  return count;
+}
+
+/// Dump the conditions tree content into a XML document structure
+size_t ConditionsXMLRepositoryWriter::collect(XML::Element root,
+                                              ConditionsSlice& slice,
+                                              DetElement detector)  const
 {
   size_t count = 0;
   if ( detector.isValid() )  {
@@ -288,51 +345,56 @@ size_t ConditionsXMLRepositoryWriter::collectConditions(XML::Element root,
                    typ == typeid(int)    || typ == typeid(unsigned int)   ||
                    typ == typeid(long)   || typ == typeid(unsigned long)  ||
                    typ == typeid(float)  || typ == typeid(double)         ||
-                   typ == typeid(string) )
+                   typ == typeid(bool)   || typ == typeid(string) )
 #else
-              if ( typ == typeid(int)    || typ == typeid(long)           ||
-                   typ == typeid(float)  || typ == typeid(double)         ||
-                   typ == typeid(string) )
+                if ( typ == typeid(int)    || typ == typeid(long)           ||
+                     typ == typeid(float)  || typ == typeid(double)         ||
+                     typ == typeid(bool)   || typ == typeid(string) )
 #endif
-              {
-                conditions.append(_convert<value>(conditions,c));
-              }
-              else if ( ::strstr(data.dataType().c_str(),"::vector<") )  {
-                conditions.append(_convert<std::vector<void*> >(conditions,c));
-              }
-              else if ( ::strstr(data.dataType().c_str(),"::list<") )  {
-                conditions.append(_convert<std::list<void*> >(conditions,c));
-              }
-              else if ( ::strstr(data.dataType().c_str(),"::set<") )  {
-                conditions.append(_convert<std::set<void*> >(conditions,c));
-              }
-              else   {
-                comment.str("");
-                comment << "\n ** Unconverted condition: "
-                        << "Unknown data type of condition: " << cn
-                        << " [" << (void*)k.first << "] -> "
-                        << c.name() << "  Flags:" << (unsigned int)c->flags << "\n";
-                conditions.addComment(comment.str());
-                printout(ERROR,"Writer",comment.str());
-                comment.str("");
-                comment << c.data().str() << " [" << c.data().dataType() << "]\n";
-                conditions.addComment(comment.str());
-              }
+                {
+                  conditions.append(_convert<value>(conditions,c));
+                }
+                else if ( ::strstr(data.dataType().c_str(),"::vector<") )  {
+                  conditions.append(_convert<std::vector<void*> >(conditions,c));
+                }
+                else if ( ::strstr(data.dataType().c_str(),"::list<") )  {
+                  conditions.append(_convert<std::list<void*> >(conditions,c));
+                }
+                else if ( ::strstr(data.dataType().c_str(),"::set<") )  {
+                  conditions.append(_convert<std::set<void*> >(conditions,c));
+                }
+                else   {
+                  comment.str("");
+                  comment << "\n ** Unconverted condition: "
+                          << "Unknown data type of condition: " << cn
+                          << " [" << (void*)k.first << "] -> "
+                          << c.name() << "  Flags:" << (unsigned int)c->flags << "\n";
+                  conditions.addComment(comment.str());
+                  printout(ERROR,"Writer",comment.str());
+                  comment.str("");
+                  comment << c.data().str() << " [" << c.data().dataType() << "]\n";
+                  conditions.addComment(comment.str());
+                }
             }
           }
         }
       }
     }
     for (const auto& i : detector.children())
-      count += collectConditions(root,slice,i.second);
+      count += collect(root,slice,i.second);
   }
   return count;
 }
+// ======================================================================================
 
 /// Write the XML document structure to a file.
 long ConditionsXMLRepositoryWriter::write(XML::Document doc, const string& output)   const {
   XML::DocumentHandler docH;
-  return docH.output(doc, output);
+  long ret = docH.output(doc, output);
+  if ( !output.empty() )  {
+    printout(INFO,"Writer","++ Successfully wrote conditions file: %s",output.c_str());
+  }
+  return ret;
 }
 
 /// Basic entry point to read alignment conditions files
@@ -345,6 +407,7 @@ static long write_repository_conditions(lcdd_t& lcdd, int argc, char** argv)  {
   ConditionsManager manager  =  ConditionsManager::from(lcdd);
   const IOVType*    iovtype  =  0;
   long              iovvalue = -1;
+  long              mgr_prop = 0;
   string            output;
 
   for(int i=0; i<argc; ++i)  {
@@ -354,9 +417,12 @@ static long write_repository_conditions(lcdd_t& lcdd, int argc, char** argv)  {
       iovvalue = ::atol(argv[++i]);
     else if ( ::strncmp(argv[i],"-output",4) == 0 && argc>i+1)
       output = argv[++i];
+    else if ( ::strncmp(argv[i],"-manager",4) == 0 )
+      mgr_prop = 1;
     else if ( ::strncmp(argv[i],"-help",2) == 0 )  {
       printout(ALWAYS,"Plugin-Help","Usage: DD4hep_XMLConditionsRepositoryWriter --opt [--opt]           ");
       printout(ALWAYS,"Plugin-Help","  -output    <string>   Output file name. Default: stdout           ");
+      printout(ALWAYS,"Plugin-Help","  -manager   <string>   Add manager properties to the output.       ");
       printout(ALWAYS,"Plugin-Help","  -iov_type  <string>   IOV type to be selected.                    ");
       printout(ALWAYS,"Plugin-Help","  -iov_value <string>   IOV value to create the conditions snapshot.");
       ::exit(EINVAL);
@@ -376,9 +442,43 @@ static long write_repository_conditions(lcdd_t& lcdd, int argc, char** argv)  {
            cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing,
            iovtype ? iov.str().c_str() : "???");
   
-  ConditionsXMLRepositoryWriter writer(manager);
-  XML::Document doc = writer.dump(*slice,lcdd.world());
+  ConditionsXMLRepositoryWriter writer;  
+  XML::Document doc(0);
+  if ( mgr_prop )  {
+    doc = writer.dump(manager);
+    writer.collect(doc.root(), *slice);
+  }
+  else  {
+    doc = writer.dump(*slice);
+  }
   writer.write(doc, output);
   return 1;
 }
 DECLARE_APPLY(DD4hep_ConditionsXMLRepositoryWriter,write_repository_conditions)
+// ======================================================================================
+/// Basic entry point to read alignment conditions files
+/**
+ *  \author  M.Frank
+ *  \version 1.0
+ *  \date    01/04/2014
+ */
+static long write_repository_manager(lcdd_t& lcdd, int argc, char** argv)  {
+  ConditionsManager manager  =  ConditionsManager::from(lcdd);
+  string            output;
+
+  for(int i=0; i<argc; ++i)  {
+    if ( ::strncmp(argv[i],"-output",4) == 0 && argc>i+1)
+      output = argv[++i];
+    else if ( ::strncmp(argv[i],"-help",2) == 0 )  {
+      printout(ALWAYS,"Plugin-Help","Usage: DD4hep_XMLConditionsManagerWriter --opt [--opt]           ");
+      printout(ALWAYS,"Plugin-Help","  -output    <string>   Output file name. Default: stdout        ");
+      ::exit(EINVAL);
+    }
+  }
+  ConditionsXMLRepositoryWriter writer;
+  XML::Document doc = writer.dump(manager);
+  writer.write(doc, output);
+  return 1;
+}
+DECLARE_APPLY(DD4hep_ConditionsXMLManagerWriter,write_repository_manager)
+// ======================================================================================
diff --git a/DDCore/include/DD4hep/ComponentProperties.h b/DDCore/include/DD4hep/ComponentProperties.h
index 25e155c44..178cbe474 100644
--- a/DDCore/include/DD4hep/ComponentProperties.h
+++ b/DDCore/include/DD4hep/ComponentProperties.h
@@ -189,6 +189,8 @@ namespace DD4hep {
     PropertyManager();
     /// Default destructor
     virtual ~PropertyManager();
+    /// Access total number of properties
+    size_t size()  const;
     /// Check for existence
     bool exists(const std::string& name) const;
     /// Access property by name (CONST)
@@ -202,13 +204,17 @@ namespace DD4hep {
     /// Add a new property
     void add(const std::string& name, const Property& property);
     /// Add a new property
-    template <typename T> void add(const std::string& name, T& value) {
+    template <typename T> void add(const std::string& name, T& value)   {
       add(name, Property(value));
     }
     /// Bulk set of all properties
     void set(const std::string& component_name, PropertyConfigurator& setup);
     /// Apply functor on properties
-    template <typename FUNCTOR> void for_each(FUNCTOR& func) {
+    template <typename FUNCTOR> void for_each(FUNCTOR& func)   {
+      std::for_each(m_properties.begin(), m_properties.end(), func);
+    }
+    /// Apply functor on properties
+    template <typename FUNCTOR> void for_each(const FUNCTOR& func)   {
       std::for_each(m_properties.begin(), m_properties.end(), func);
     }
     /// Export properties of another instance
diff --git a/DDCore/include/DD4hep/IOV.h b/DDCore/include/DD4hep/IOV.h
index ff10f206e..4a65ac322 100644
--- a/DDCore/include/DD4hep/IOV.h
+++ b/DDCore/include/DD4hep/IOV.h
@@ -43,9 +43,13 @@ namespace DD4hep {
     /// Standard Destructor
     ~IOVType() = default;
     /// Copy constructor
-    IOVType(const IOVType& copy) : type(copy.type), name(copy.name) {}
+    IOVType(const IOVType& copy) = default; //: type(copy.type), name(copy.name) {}
+    /// Move constructor
+    IOVType(IOVType&& copy) = default;
     /// Assignment operator
-    IOVType& operator=(const IOVType& copy);
+    IOVType& operator=(const IOVType& copy) = default;
+    /// Move assignment operator
+    IOVType& operator=(IOVType&& copy) = default;
     /// Conversion to string
     std::string str() const;
   };
@@ -81,10 +85,14 @@ namespace DD4hep {
     explicit IOV(const IOVType* typ, Key_first_type iov_value);
     /// Copy constructor
     IOV(const IOV& copy) = default;
+    /// Move constructor
+    IOV(IOV&& copy) = default;
     /// Standard Destructor
     ~IOV() = default;
     /// Assignment operator
     IOV& operator=(const IOV& c) = default;
+    /// Move assignment operator
+    IOV& operator=(IOV&& c) = default;
     /// Move the data content: 'from' will be reset to NULL
     void move(IOV& from);
     /// Create string representation of the IOV
diff --git a/DDCore/include/DD4hep/LCDDData.h b/DDCore/include/DD4hep/LCDDData.h
index 2ec09ecd5..53806c01a 100644
--- a/DDCore/include/DD4hep/LCDDData.h
+++ b/DDCore/include/DD4hep/LCDDData.h
@@ -85,17 +85,17 @@ namespace DD4hep {
       };
 
     protected:
-      TGeoManager* m_manager;
-      ObjectHandleMap m_readouts;
-      ObjectHandleMap m_idDict;
-      ObjectHandleMap m_limits;
-      ObjectHandleMap m_regions;
-      ObjectHandleMap m_detectors;
-      ObjectHandleMap m_alignments;
-
-      ObjectHandleMap m_sensitive;
-      ObjectHandleMap m_display;
-      ObjectHandleMap m_fields;
+      TGeoManager*     m_manager;
+      ObjectHandleMap  m_readouts;
+      ObjectHandleMap  m_idDict;
+      ObjectHandleMap  m_limits;
+      ObjectHandleMap  m_regions;
+      ObjectHandleMap  m_detectors;
+      ObjectHandleMap  m_alignments;
+
+      ObjectHandleMap  m_sensitive;
+      ObjectHandleMap  m_display;
+      ObjectHandleMap  m_fields;
 
       ObjectHandleMap  m_motherVolumes;
 
@@ -118,10 +118,10 @@ namespace DD4hep {
       /// Definition of the extension type
       ObjectExtensions m_extensions;
       /// Volume manager reference
-      VolumeManager m_volManager;
+      VolumeManager    m_volManager;
 
       /// Flag to inhibit the access to global constants. Value set by constants section 'LCDD_InhibitConstants'
-      bool m_inhibitConstants;
+      bool             m_inhibitConstants;
 
     protected:
       /// Default constructor
diff --git a/DDCore/include/DD4hep/MultiSegmentation.h b/DDCore/include/DD4hep/MultiSegmentation.h
index e933afdb8..38eaa4e1b 100644
--- a/DDCore/include/DD4hep/MultiSegmentation.h
+++ b/DDCore/include/DD4hep/MultiSegmentation.h
@@ -1,3 +1,4 @@
+//==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
diff --git a/DDCore/include/DD4hep/Path.h b/DDCore/include/DD4hep/Path.h
index a89c8aee0..ffd096785 100644
--- a/DDCore/include/DD4hep/Path.h
+++ b/DDCore/include/DD4hep/Path.h
@@ -49,7 +49,9 @@ namespace DD4hep {
     /// Initializing constructor
     Path(const std::string& c) : std::string(c) {                    }
     /// Copy constructor
-    Path(const Path& c) : std::string(c)    {                        }
+    Path(const Path& c) : std::string(c)        {                    }
+    /// Move constructor
+    Path(Path&& c) : std::string(c)             {                    }
     /// Assigning constructor
     template <class Iter> Path(Iter _begin,Iter _end)  {
       if ( _begin != _end )  {
@@ -69,6 +71,16 @@ namespace DD4hep {
       this->std::string::operator=(c);
       return *this;
     }
+    /// Move assignment operator from Path object
+    Path& operator=(Path&& c)          {
+      this->std::string::operator=(c);
+      return *this;
+    }
+    /// Assignment operator from string object
+    Path& operator=(std::string&& c)   {
+      this->std::string::operator=(c);
+      return *this;
+    }
     /// Append operation
     Path& append(const std::string& c);
     /// Append operation
@@ -101,5 +113,5 @@ namespace DD4hep {
       static const Path& dot_dot_path();
     };
   };
-} /* End namespace DD4hep           */
-#endif    /* DD4HEP_DDCORE_PATH_H   */
+}         /* End namespace DD4hep           */
+#endif    /* DD4HEP_DDCORE_PATH_H           */
diff --git a/DDCore/include/DD4hep/PolarGridRPhi.h b/DDCore/include/DD4hep/PolarGridRPhi.h
index d8cf860db..b4ee8e03d 100644
--- a/DDCore/include/DD4hep/PolarGridRPhi.h
+++ b/DDCore/include/DD4hep/PolarGridRPhi.h
@@ -1,3 +1,4 @@
+//==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
diff --git a/DDCore/include/DD4hep/PolarGridRPhi2.h b/DDCore/include/DD4hep/PolarGridRPhi2.h
index 7fbb67fd3..bba033874 100644
--- a/DDCore/include/DD4hep/PolarGridRPhi2.h
+++ b/DDCore/include/DD4hep/PolarGridRPhi2.h
@@ -1,3 +1,4 @@
+//==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
diff --git a/DDCore/include/DD4hep/WaferGridXY.h b/DDCore/include/DD4hep/WaferGridXY.h
index 52322ddbf..e4b5eba88 100644
--- a/DDCore/include/DD4hep/WaferGridXY.h
+++ b/DDCore/include/DD4hep/WaferGridXY.h
@@ -1,3 +1,4 @@
+//==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
diff --git a/DDCore/src/ComponentProperties.cpp b/DDCore/src/ComponentProperties.cpp
index d4d697c5e..677d526d6 100644
--- a/DDCore/src/ComponentProperties.cpp
+++ b/DDCore/src/ComponentProperties.cpp
@@ -124,6 +124,11 @@ PropertyManager::~PropertyManager() {
   m_properties.clear();
 }
 
+/// Access total number of properties
+size_t PropertyManager::size()  const   {
+  return m_properties.size();
+}
+
 /// Export properties of another instance
 void PropertyManager::adopt(const PropertyManager& copy)   {
   m_properties = copy.m_properties;
diff --git a/DDCore/src/IOV.cpp b/DDCore/src/IOV.cpp
index 43c248445..09ffc4647 100644
--- a/DDCore/src/IOV.cpp
+++ b/DDCore/src/IOV.cpp
@@ -23,6 +23,7 @@
 using namespace std;
 using namespace DD4hep;
 
+#if 0
 /// Assignment operator
 IOVType& IOVType::operator=(const IOVType& copy)  {
   if ( &copy != this )  {
@@ -31,6 +32,7 @@ IOVType& IOVType::operator=(const IOVType& copy)  {
   }
   return *this;
 }
+#endif
 
 /// Conversion to string
 std::string IOVType::str()  const   {
diff --git a/DDCore/src/LCDDData.cpp b/DDCore/src/LCDDData.cpp
index d728282d3..d0fb90e5b 100644
--- a/DDCore/src/LCDDData.cpp
+++ b/DDCore/src/LCDDData.cpp
@@ -30,7 +30,7 @@ using namespace DD4hep;
 LCDDData::LCDDData()
   : m_manager(0), m_world(), m_trackers(), m_worldVol(),
     m_trackingVol(), m_field("global"),
-    m_extensions(typeid(LCDDData)), m_volManager(),
+    m_buildType(BUILD_DEFAULT), m_extensions(typeid(LCDDData)), m_volManager(),
     m_inhibitConstants(false)
 {
   InstanceCount::increment(this);
diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp
index 1f79aea97..84fac499c 100644
--- a/DDCore/src/XML/XMLElements.cpp
+++ b/DDCore/src/XML/XMLElements.cpp
@@ -1121,7 +1121,7 @@ Handle_t Element::setChild(const XmlChar* t) const {
   return e ? Handle_t(e) : addChild(t);
 }
 
-#ifdef DD4HEP_USE_TINYXML
+#ifndef DD4HEP_USE_TINYXML
 /// Add comment node to the element
 void Element::addComment(const XmlChar* text_value) const {
   _N(m_element)->appendChild(_D(document().m_doc)->createComment(text_value));
diff --git a/DDDB/include/DDDB/DDDBConversion.h b/DDDB/include/DDDB/DDDBConversion.h
index 9b3fdbe37..ac8b94bad 100644
--- a/DDDB/include/DDDB/DDDBConversion.h
+++ b/DDDB/include/DDDB/DDDBConversion.h
@@ -490,7 +490,7 @@ namespace DD4hep {
       int           level, typeID;
       /// Default constructor
       Catalog();
-      Catalog(const Catalog&, const DetElement&) {}
+      Catalog(const Catalog&, const DetElement&) : level(0), typeID(0) {}
       /// Default destructor
       virtual ~Catalog();
       /// Reference count mechanism
diff --git a/DDDB/src/CondDB2DDDB.cpp b/DDDB/src/CondDB2DDDB.cpp
index 7c156f535..6ff3c1c85 100644
--- a/DDDB/src/CondDB2DDDB.cpp
+++ b/DDDB/src/CondDB2DDDB.cpp
@@ -443,7 +443,7 @@ namespace DD4hep {
         for(dddb::Volumes::iterator j=det->logvolrefs.begin(); j!=det->logvolrefs.end(); ++j)  {
           LogVol* c = (*j).second;
           if ( !c )  {
-            printout(ERROR,"fixCatalogs","++  MISSING Volume: %s child:%s",det->id.c_str(),c->id.c_str());
+            printout(ERROR,"fixCatalogs","++  MISSING Volume: %s child:%s",det->id.c_str(),(*j).first.c_str());
             continue;
           }
           dddb::Volumes::const_iterator k = geo->volumes.find(c->id);
@@ -1051,6 +1051,8 @@ namespace DD4hep {
             // Error. What to do? 
             // Anyhow: ShapeConv<BooleanOperation> throws exception if the
             //         shape is unknown. We never get here.
+            printout(ERROR,"ShapeConv","++ Invalid boolean shape operation. [Invalid operand]");
+            continue;
           }
           op.shape->id = id + "/" + op.shape->name;
           ++p;
diff --git a/DDDB/src/DDDB2Objects.cpp b/DDDB/src/DDDB2Objects.cpp
index 6ecedee41..3003e8eb8 100644
--- a/DDDB/src/DDDB2Objects.cpp
+++ b/DDDB/src/DDDB2Objects.cpp
@@ -261,13 +261,15 @@ namespace DD4hep {
         for(auto i = o->isotopes.begin(); i != o->isotopes.end(); ++i)  {
           auto iso = context->geo->isotopes.find((*i).first);
           if ( iso == context->geo->isotopes.end() )  {
-            /// Error!
+            printout(ERROR,"DDDB","++ Invalid isotope: %s [Ignore Isotope]",(*i).first.c_str());
+            continue;
           }
           Isotope* isotope = (*iso).second;
           TGeoIsotope* geo_iso = 
             (TGeoIsotope*)CNV<Isotope>(context->lcdd,context).convert(isotope);
           if ( !geo_iso )  {
-            /// Error!
+            printout(ERROR,"DDDB","++ Invalid isotope: %s [Ignore Isotope]",(*iso).first.c_str());
+            continue;
           }
           e->AddIsotope(geo_iso, (*i).second);
         }
diff --git a/DDDB/src/DDDBConversion.cpp b/DDDB/src/DDDBConversion.cpp
index 45ebbaa4f..2bb6e4492 100644
--- a/DDDB/src/DDDBConversion.cpp
+++ b/DDDB/src/DDDBConversion.cpp
@@ -241,7 +241,7 @@ namespace DD4hep  {
     string rest = nam.substr(cat->path.length()+1);
     size_t idx = rest.find('/');
     string sub = rest.substr(0,idx);
-    while( idx != string::npos )  {
+    while( cat && idx != string::npos )  {
       dddb::Catalogs::const_iterator ic = cat->catalogs.find(sub);
       if ( ic != cat->catalogs.end() )  {
         rest = rest.substr(idx+1);
diff --git a/DDDB/src/DDDBFileReader.cpp b/DDDB/src/DDDBFileReader.cpp
index 1e971099f..8331ec885 100644
--- a/DDDB/src/DDDBFileReader.cpp
+++ b/DDDB/src/DDDBFileReader.cpp
@@ -71,19 +71,21 @@ 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);
-    int done = 0, len = buff.st_size;
-    char* b  = new char[len+1];
-    b[0] = 0;
-    while ( done<len )  {
-      int sc = ::read(fid, b+done, buff.st_size-done);
-      if ( sc >= 0 ) { done += sc; continue; }
-      break;
+    if ( fid > 0 )   {
+      int done = 0, len = buff.st_size;
+      char* b  = new char[len+1];
+      b[0] = 0;
+      while ( done<len )  {
+        int sc = ::read(fid, b+done, buff.st_size-done);
+        if ( sc >= 0 ) { done += sc; continue; }
+        break;
+      }
+      ::close(fid);
+      b[done] = 0;
+      buffer = b;
+      delete [] b;
+      if ( done>=len ) return 1;
     }
-    ::close(fid);
-    b[done] = 0;
-    buffer = b;
-    delete [] b;
-    if ( done>=len ) return 1;
   }
   return 0;
 }
diff --git a/DDEve/include/DDEve/DisplayConfiguration.h b/DDEve/include/DDEve/DisplayConfiguration.h
index c4e06b46a..268d6223f 100644
--- a/DDEve/include/DDEve/DisplayConfiguration.h
+++ b/DDEve/include/DDEve/DisplayConfiguration.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -39,11 +38,12 @@ namespace DD4hep {
   protected:
     Display* m_display;
   public:
-    enum { CALODATA=1<<1, 
-           DETELEMENT=1<<2, 
-           VIEW=1<<3, 
-           PANEL=1<<4,
-           COLLECTION=1<<5
+    enum { NO_DATA    = 0,
+           CALODATA   = 1<<1, 
+           DETELEMENT = 1<<2, 
+           VIEW       = 1<<3, 
+           PANEL      = 1<<4,
+           COLLECTION = 1<<5
     };
     struct Defaults {
       char  load_geo;
diff --git a/DDEve/src/DisplayConfiguration.cpp b/DDEve/src/DisplayConfiguration.cpp
index 9765d6614..09f171818 100644
--- a/DDEve/src/DisplayConfiguration.cpp
+++ b/DDEve/src/DisplayConfiguration.cpp
@@ -33,7 +33,10 @@ DisplayConfiguration::~DisplayConfiguration()  {
 }
 
 /// Default constructor
-DisplayConfiguration::ViewConfig::ViewConfig() : Config()  {
+DisplayConfiguration::ViewConfig::ViewConfig()
+  : Config(), type(),
+    subdetectors(), show_sensitive(false), show_structure(false)
+{
 }
 
 /// Copy constructor
@@ -64,6 +67,7 @@ DisplayConfiguration::Config::Config()   {
   data.defaults.load_geo = -1;
   data.defaults.show_evt =  1;
   data.defaults.alpha = 0.5;
+  type = NO_DATA;
 }
 
 /// Copy constructor
diff --git a/DDEve/src/DisplayConfigurationParser.cpp b/DDEve/src/DisplayConfigurationParser.cpp
index 3dd5a87b9..d8451d14c 100644
--- a/DDEve/src/DisplayConfigurationParser.cpp
+++ b/DDEve/src/DisplayConfigurationParser.cpp
@@ -246,8 +246,12 @@ template <> void Converter<collection>::operator()(xml_h e)  const  {
  *  @date    01/06/2014
  */
 template <> void Converter<include>::operator()(xml_h e)  const  {
-  LCDDLoad* load = dynamic_cast<LCDDLoad*>(&this->lcdd);
-  load->processXML(e,e.attr<string>(_U(ref)));
+  if ( e )  {
+    LCDDLoad* load = dynamic_cast<LCDDLoad*>(&this->lcdd);
+    load->processXML(e,e.attr<string>(_U(ref)));
+    return;
+  }
+  except("DisplayConfiguration","++ Attempt to parse invalid include statement [Invalid XML element]");
 }
 
 /** Convert display configuration elements of tag type ddeve/include
diff --git a/DDEve/src/Projection.cpp b/DDEve/src/Projection.cpp
index 31a6dd427..ba17545a2 100644
--- a/DDEve/src/Projection.cpp
+++ b/DDEve/src/Projection.cpp
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -58,7 +57,7 @@ TEveElement* Projection::ImportElement(TEveElement* el, TEveElementList* list)
   }
   TEveElement* e = m_projMgr->ImportElements(el, list);
   printout(INFO,"Projection","ImportElement %s [%s] into list: %s Projectable:%s [%p]",
-           Utilities::GetName(el),el->IsA()->GetName(),list->GetName(),
+           Utilities::GetName(el),el->IsA()->GetName(), list ? list->GetName() : "???",
            dynamic_cast<TEveProjectable*>(list) ? "true" : "false", e);
 
   unprojected->AddElement(el);
diff --git a/DDEve/src/Utilities.cpp b/DDEve/src/Utilities.cpp
index 9d9ca5e75..3f5fa0b42 100644
--- a/DDEve/src/Utilities.cpp
+++ b/DDEve/src/Utilities.cpp
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
diff --git a/DDG4/g4FromXML.cpp b/DDG4/g4FromXML.cpp
index f21bec1b9..f28e363ba 100644
--- a/DDG4/g4FromXML.cpp
+++ b/DDG4/g4FromXML.cpp
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -16,11 +15,13 @@
 #include "DDG4/Geant4Config.h"
 
 // C/C++ include files
+#include <stdexcept>
 #include <iostream>
+#include <cerrno>
 
 using namespace DD4hep::Simulation::Setup;
 
-void setupG4_XML()  {
+int setupG4_XML()  {
   DD4hep::Geometry::LCDD& lcdd = DD4hep::Geometry::LCDD::getInstance();
   Kernel& kernel = Kernel::instance(lcdd);
   kernel.loadGeometry("file:../DD4hep.trunk/DDExamples/CLICSiD/compact/compact.xml");
@@ -32,10 +33,19 @@ void setupG4_XML()  {
   kernel.run();
   std::cout << "Successfully executed application .... " << std::endl;
   kernel.terminate();
+  return 1;
 }
 
-
+/// Main entry point as a program
 int main(int, char**)   {
-  setupG4_XML();
-  return 1;
+  try  {
+    return setupG4_XML();
+  }
+  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/DDG4/include/DDG4/DDG4Dict.h b/DDG4/include/DDG4/DDG4Dict.h
index 7e4619e9b..52b5c60e5 100644
--- a/DDG4/include/DDG4/DDG4Dict.h
+++ b/DDG4/include/DDG4/DDG4Dict.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -109,11 +108,11 @@ namespace DD4hep {
   namespace Simulation {
 #define NO_CALL {      throw "This function shoule never ever be called!";    }
     /// Default constructor
-    inline SimpleRun::SimpleRun() {    }
+    inline SimpleRun::SimpleRun() : runID(0), numEvents(0)  {    }
     /// Default destructor
     inline SimpleRun::~SimpleRun() {    }
     /// Default constructor
-    inline SimpleEvent::SimpleEvent() {    }
+    inline SimpleEvent::SimpleEvent() : runID(0), eventID(0) {    }
     /// Default destructor
     inline SimpleEvent::~SimpleEvent() {    }
 
@@ -130,13 +129,13 @@ namespace DD4hep {
     /// Remove daughter from set
     inline void Geant4Particle::removeDaughter(int)   {   NO_CALL  }
     /// Default constructor
-    inline Geant4HitData::Geant4HitData()   {    }
+    inline Geant4HitData::Geant4HitData(): cellID(0), flag(0), g4ID(0)   {    }
     /// Default destructor
     inline  Geant4HitData::~Geant4HitData()  {    }
     /// Extract the MC contribution for a given hit from the step information
     inline Geant4HitData::Contribution Geant4HitData::extractContribution(const G4Step*) { return Contribution(); }
     /// Default constructor
-    inline Geant4Tracker::Hit::Hit()   {    }
+    inline Geant4Tracker::Hit::Hit() : length(0), energyDeposit(0e0)  {    }
     /// Initializing constructor
     inline Geant4Tracker::Hit::Hit(int, int, double, double)   {}
     /// Default destructor
@@ -148,9 +147,9 @@ namespace DD4hep {
     /// Store Geant4 point and step information into tracker hit structure.
     inline Geant4Tracker::Hit& Geant4Tracker::Hit::storePoint(const G4Step*, const G4StepPoint*)  { return *this;}
     /// Default constructor
-    inline Geant4Calorimeter::Hit::Hit()   {    }
+    inline Geant4Calorimeter::Hit::Hit() : energyDeposit(0e0)  {    }
     /// Initializing constructor
-    inline Geant4Calorimeter::Hit::Hit(const Position&)  {}
+    inline Geant4Calorimeter::Hit::Hit(const Position&) : energyDeposit(0e0) {}
     /// Default destructor
     inline Geant4Calorimeter::Hit::~Hit()   {    }
   }
diff --git a/DDG4/include/DDG4/Geant4Handle.h b/DDG4/include/DDG4/Geant4Handle.h
index ac90244a7..83b660cd0 100644
--- a/DDG4/include/DDG4/Geant4Handle.h
+++ b/DDG4/include/DDG4/Geant4Handle.h
@@ -1,4 +1,3 @@
-// $Id: $
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -45,9 +44,9 @@ namespace DD4hep {
     public:
       typedef TYPE handled_type;
       /// Pointer to referenced object
-      mutable handled_type* value;
+      mutable handled_type* value = 0;
       /// Default constructor
-      explicit Geant4Handle();
+      explicit Geant4Handle() = default;
       /// Construction initialized with object pointer
       Geant4Handle(handled_type* typ);
       /// Cross type initialization
@@ -56,6 +55,8 @@ namespace DD4hep {
       }
       /// Copy constructor
       Geant4Handle(const Geant4Handle& handle);
+      /// Move constructor
+      //Geant4Handle(Geant4Handle&& handle) = default;
       /// Initializing constructor
       Geant4Handle(Geant4Kernel&, const char* type_name, bool shared=false);
       /// Initializing constructor
@@ -68,6 +69,8 @@ namespace DD4hep {
       Property& operator[](const std::string& property_name) const;
       /// Assignment operator
       Geant4Handle& operator=(const Geant4Handle& handle);
+      /// Move assignment operator
+      //Geant4Handle& operator=(Geant4Handle&& handle) = default;
       /// Assignment operator
       Geant4Handle& operator=(handled_type* ptr);
       /// Validity check
diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp
index ce6a1d976..053a05693 100644
--- a/DDG4/src/Geant4Converter.cpp
+++ b/DDG4/src/Geant4Converter.cpp
@@ -702,12 +702,12 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node)
     TGeoVolume* vol = node->GetVolume();
     TGeoMatrix* tr = node->GetMatrix();
     if (!tr) {
-      printout(FATAL, "Geant4Converter", "++ Attempt to handle placement without transformation:%p %s of type %s vol:%p", node,
-               node->GetName(), node->IsA()->GetName(), vol);
+      except("Geant4Converter", "++ Attempt to handle placement without transformation:%p %s of type %s vol:%p", node,
+             node->GetName(), node->IsA()->GetName(), vol);
     }
     else if (0 == vol) {
-      printout(FATAL, "Geant4Converter", "++ Unknown G4 volume:%p %s of type %s ptr:%p", node, node->GetName(),
-               node->IsA()->GetName(), vol);
+      except("Geant4Converter", "++ Unknown G4 volume:%p %s of type %s ptr:%p", node, node->GetName(),
+             node->IsA()->GetName(), vol);
     }
     else {
       int copy = node->GetNumber();
diff --git a/DDG4/src/Geant4Handle.cpp b/DDG4/src/Geant4Handle.cpp
index bccb6663a..46008a4b2 100644
--- a/DDG4/src/Geant4Handle.cpp
+++ b/DDG4/src/Geant4Handle.cpp
@@ -53,22 +53,18 @@ namespace DD4hep {
       if (p) {
         return p;
       }
-      throw runtime_error(format("Geant4Handle", "Attempt to access an invalid object of type:%s!", typeName(typeid(TYPE)).c_str()));
+      except("Geant4Handle","Attempt to access an invalid object of type:%s!",
+             typeName(typeid(TYPE)).c_str());
+      return 0;
     }
 
-    template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle()
-      : value(0) {
-    }
-
-    template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(TYPE* typ)
-      : value(typ) {
+    template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(TYPE* typ) : value(typ)  {
       if (value)
         value->addRef();
     }
 
     template <typename TYPE> Geant4Handle<TYPE>::Geant4Handle(const Geant4Handle<TYPE>& handle)
-      : value(0) {
-      value = handle.get();
+      : value(handle.get()) {
       if (value)
         value->addRef();
     }
@@ -94,10 +90,11 @@ namespace DD4hep {
         if (ptr)  {
           return ptr;
         }
-        throw runtime_error(format("Geant4Handle", "Failed to convert object of type %s to handle of type %s!",
-                                   typ.first.c_str(),typ.second.c_str()));
+        except("Geant4Handle", "Failed to convert object of type %s to handle of type %s!",
+               typ.first.c_str(),typ.second.c_str());
       }
-      throw runtime_error(format("Geant4Handle", "Failed to create object of type %s!", typ.first.c_str()));
+      except("Geant4Handle", "Failed to create object of type %s!", typ.first.c_str());
+      return 0;
     }
 
     template <typename TYPE, typename CONT> 
@@ -185,20 +182,23 @@ namespace DD4hep {
       return checked_value(value);
     }
 
+    /// Assignment operator
     template <typename TYPE> Geant4Handle<TYPE>& Geant4Handle<TYPE>::operator=(const Geant4Handle& handle) {
       if ( &handle != this )  {
-        if (value) value->release();
+        TYPE* point = value;
         value = handle.get();
-        if (value) value->addRef();
+        if ( value ) value->addRef();
+        if ( point ) point->release();
       }
       return *this;
     }
 
-    template <typename TYPE> Geant4Handle<TYPE>& Geant4Handle<TYPE>::operator=(TYPE* typ) {
-      if ( typ != value )  {
-        if (value)    value->release();
-        value = typ;
-        if (value)    value->addRef();
+    template <typename TYPE> Geant4Handle<TYPE>& Geant4Handle<TYPE>::operator=(TYPE* pointer) {
+      if ( pointer != value )  {
+        TYPE* point = value;
+        value = pointer;
+        if ( value ) value->addRef();
+        if ( point ) point->release();
       }
       return *this;
     }
@@ -214,7 +214,8 @@ namespace DD4hep {
     KernelHandle KernelHandle::worker()  {
       Geant4Kernel* k = value ? &value->worker(Geant4Kernel::thread_self()) : 0;
       if ( k ) return KernelHandle(k);
-      throw runtime_error(format("KernelHandle", "Cannot access worker context [Invalid Handle]"));
+      except("KernelHandle", "Cannot access worker context [Invalid Handle]");
+      return KernelHandle(0);
     }
     void KernelHandle::destroy()  {
       if ( value ) delete value;
@@ -223,56 +224,68 @@ namespace DD4hep {
 
     template <> 
     Geant4Handle<Geant4RunAction>::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::runAction,type_name,"Geant4SharedRunAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::runAction,type_name,
+                            "Geant4SharedRunAction",shared,(handled_type*)0);
     }
     template <> 
     Geant4Handle<Geant4RunAction>::Geant4Handle(Geant4Kernel& kernel, const char* type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::runAction,type_name,"Geant4SharedRunAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::runAction,type_name,
+                            "Geant4SharedRunAction",shared,(handled_type*)0);
     }
 
     template <> 
     Geant4Handle<Geant4EventAction>::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::eventAction,type_name,"Geant4SharedEventAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::eventAction,type_name,
+                            "Geant4SharedEventAction",shared,(handled_type*)0);
     }
     template <> 
     Geant4Handle<Geant4EventAction>::Geant4Handle(Geant4Kernel& kernel, const char* type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::eventAction,type_name,"Geant4SharedEventAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::eventAction,type_name,
+                            "Geant4SharedEventAction",shared,(handled_type*)0);
     }
 
     template <> 
     Geant4Handle<Geant4GeneratorAction>::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::generatorAction,type_name,"Geant4SharedGeneratorAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::generatorAction,type_name,
+                            "Geant4SharedGeneratorAction",shared,(handled_type*)0);
     }
     template <> 
     Geant4Handle<Geant4GeneratorAction>::Geant4Handle(Geant4Kernel& kernel, const char* type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::generatorAction,type_name,"Geant4SharedGeneratorAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::generatorAction,type_name,
+                            "Geant4SharedGeneratorAction",shared,(handled_type*)0);
     }
 
     template <> 
     Geant4Handle<Geant4TrackingAction>::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::trackingAction,type_name,"Geant4SharedTrackingAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::trackingAction,type_name,
+                            "Geant4SharedTrackingAction",shared,(handled_type*)0);
     }
     template <> 
     Geant4Handle<Geant4TrackingAction>::Geant4Handle(Geant4Kernel& kernel, const char* type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::trackingAction,type_name,"Geant4SharedTrackingAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::trackingAction,type_name,
+                            "Geant4SharedTrackingAction",shared,(handled_type*)0);
     }
 
     template <> 
     Geant4Handle<Geant4SteppingAction>::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::steppingAction,type_name,"Geant4SharedSteppingAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::steppingAction,type_name,
+                            "Geant4SharedSteppingAction",shared,(handled_type*)0);
     }
     template <> 
     Geant4Handle<Geant4SteppingAction>::Geant4Handle(Geant4Kernel& kernel, const char* type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::steppingAction,type_name,"Geant4SharedSteppingAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::steppingAction,type_name,
+                            "Geant4SharedSteppingAction",shared,(handled_type*)0);
     }
 
     template <> 
     Geant4Handle<Geant4StackingAction>::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::stackingAction,type_name,"Geant4SharedStackingAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::stackingAction,type_name,
+                            "Geant4SharedStackingAction",shared,(handled_type*)0);
     }
     template <> 
     Geant4Handle<Geant4StackingAction>::Geant4Handle(Geant4Kernel& kernel, const char* type_name, bool shared)  {
-      value = _create_share(kernel,&Geant4ActionContainer::stackingAction,type_name,"Geant4SharedStackingAction",shared,(handled_type*)0);
+      value = _create_share(kernel,&Geant4ActionContainer::stackingAction,type_name,
+                            "Geant4SharedStackingAction",shared,(handled_type*)0);
     }
 
     template <> Geant4Handle<Geant4Sensitive>::Geant4Handle(Geant4Kernel& kernel, const string& type_name,
@@ -294,9 +307,9 @@ namespace DD4hep {
       catch (...) {
         printout(ERROR, "Geant4Handle<Geant4Sensitive>", "Exception: Unknown exception");
       }
-      throw runtime_error(format("Geant4Handle<Geant4Sensitive>", 
-                                 "Failed to create sensitive object of type %s for detector %s!",
-                                 type_name.c_str(), detector.c_str()));
+      except("Geant4Handle<Geant4Sensitive>", 
+             "Failed to create sensitive object of type %s for detector %s!",
+             type_name.c_str(), detector.c_str());
     }
   
 
diff --git a/DDG4/src/Geant4ParticleHandler.cpp b/DDG4/src/Geant4ParticleHandler.cpp
index 92d7f8968..823963b85 100644
--- a/DDG4/src/Geant4ParticleHandler.cpp
+++ b/DDG4/src/Geant4ParticleHandler.cpp
@@ -54,18 +54,18 @@ Geant4ParticleHandler::Geant4ParticleHandler(Geant4Context* ctxt, const string&
 {
   InstanceCount::increment(this);
   //generatorAction().adopt(this);
-  eventAction().callAtBegin(this,&Geant4ParticleHandler::beginEvent);
-  eventAction().callAtEnd(this,&Geant4ParticleHandler::endEvent);
-  trackingAction().callAtFinal(this,&Geant4ParticleHandler::end,CallbackSequence::FRONT);
-  trackingAction().callUpFront(this,&Geant4ParticleHandler::begin,CallbackSequence::FRONT);
-  steppingAction().call(this,&Geant4ParticleHandler::step);
+  eventAction().callAtBegin(this,    &Geant4ParticleHandler::beginEvent);
+  eventAction().callAtEnd(this,      &Geant4ParticleHandler::endEvent);
+  trackingAction().callAtFinal(this, &Geant4ParticleHandler::end,CallbackSequence::FRONT);
+  trackingAction().callUpFront(this, &Geant4ParticleHandler::begin,CallbackSequence::FRONT);
+  steppingAction().call(this,        &Geant4ParticleHandler::step);
   m_globalParticleID = 0;
-  declareProperty("PrintEndTracking",    m_printEndTracking = false);
-  declareProperty("PrintStartTracking",  m_printStartTracking = false);
-  declareProperty("KeepAllParticles",    m_keepAll = false);
-  declareProperty("SaveProcesses",       m_processNames);
-  declareProperty("MinimalKineticEnergy",m_kinEnergyCut = 100e0*CLHEP::MeV);
-  declareProperty("MinDistToParentVertex",m_minDistToParentVertex = 2.2e-14*CLHEP::mm);//default tolerance for g4ThreeVector isNear
+  declareProperty("PrintEndTracking",      m_printEndTracking = false);
+  declareProperty("PrintStartTracking",    m_printStartTracking = false);
+  declareProperty("KeepAllParticles",      m_keepAll = false);
+  declareProperty("SaveProcesses",         m_processNames);
+  declareProperty("MinimalKineticEnergy",  m_kinEnergyCut = 100e0*CLHEP::MeV);
+  declareProperty("MinDistToParentVertex", m_minDistToParentVertex = 2.2e-14*CLHEP::mm);//default tolerance for g4ThreeVector isNear
   m_needsControl = true;
 }
 
@@ -74,6 +74,14 @@ Geant4ParticleHandler::Geant4ParticleHandler()
   : Geant4GeneratorAction(0,""), Geant4MonteCarloTruth(),
     m_ownsParticles(false), m_userHandler(0), m_primaryMap(0)
 {
+  m_globalParticleID = 0;
+  declareProperty("PrintEndTracking",      m_printEndTracking = false);
+  declareProperty("PrintStartTracking",    m_printStartTracking = false);
+  declareProperty("KeepAllParticles",      m_keepAll = false);
+  declareProperty("SaveProcesses",         m_processNames);
+  declareProperty("MinimalKineticEnergy",  m_kinEnergyCut = 100e0*CLHEP::MeV);
+  declareProperty("MinDistToParentVertex", m_minDistToParentVertex = 2.2e-14*CLHEP::mm);//default tolerance for g4ThreeVector isNear
+  m_needsControl = true;
 }
 
 /// Default destructor
diff --git a/UtilityApps/src/converter.cpp b/UtilityApps/src/converter.cpp
index 649a15f5d..d4ce1e7fe 100644
--- a/UtilityApps/src/converter.cpp
+++ b/UtilityApps/src/converter.cpp
@@ -39,70 +39,83 @@ namespace {
          << endl;
     exit(EINVAL);
   }
-}
 
 
-//______________________________________________________________________________
-int main(int argc,char** argv)  {
-  bool ascii = false;
-  bool volmgr = false;
-  bool destroy      = false;
-  bool compact2lcdd = false;
-  bool compact2gdml = false;
-  bool compact2pand = false;
-  bool compact2vis  = false;
-  int output = 0;
-  vector<char*> geo_files;
-  for(int i=1; i<argc;++i) {
-    if ( argv[i][0]=='-' ) {
-      if ( strncmp(argv[i],"-compact2lcdd",12)==0 )
-        compact2lcdd = true;
-      else if ( strncmp(argv[i],"-compact2gdml",12)==0 )
-        compact2gdml = true;
-      else if ( strncmp(argv[i],"-compact2pandora",12)==0 )
-        compact2pand = true;
-      else if ( strncmp(argv[i],"-compact2vis",12)==0 )
-        compact2vis = true;
-      else if ( strncmp(argv[i],"-input",2)==0 )
-        geo_files.push_back(argv[++i]);
-      else if ( strncmp(argv[i],"-output",2)==0 )
-        output = ++i;
-      else if ( strncmp(argv[i],"-ascii",5)==0 )
-        ascii = true;
-      else if ( strncmp(argv[i],"-destroy",2)==0 )
-        destroy = true;
-      else if ( strncmp(argv[i],"-volmgr",2)==0 )
-        volmgr = true;
-      else
+  //______________________________________________________________________________
+  int invoke_converter(int argc,char** argv)  {
+    bool ascii = false;
+    bool volmgr = false;
+    bool destroy      = false;
+    bool compact2lcdd = false;
+    bool compact2gdml = false;
+    bool compact2pand = false;
+    bool compact2vis  = false;
+    int output = 0;
+    vector<char*> geo_files;
+    for(int i=1; i<argc;++i) {
+      if ( argv[i][0]=='-' ) {
+        if ( strncmp(argv[i],"-compact2lcdd",12)==0 )
+          compact2lcdd = true;
+        else if ( strncmp(argv[i],"-compact2gdml",12)==0 )
+          compact2gdml = true;
+        else if ( strncmp(argv[i],"-compact2pandora",12)==0 )
+          compact2pand = true;
+        else if ( strncmp(argv[i],"-compact2vis",12)==0 )
+          compact2vis = true;
+        else if ( strncmp(argv[i],"-input",2)==0 )
+          geo_files.push_back(argv[++i]);
+        else if ( strncmp(argv[i],"-output",2)==0 )
+          output = ++i;
+        else if ( strncmp(argv[i],"-ascii",5)==0 )
+          ascii = true;
+        else if ( strncmp(argv[i],"-destroy",2)==0 )
+          destroy = true;
+        else if ( strncmp(argv[i],"-volmgr",2)==0 )
+          volmgr = true;
+        else
+          usage();
+      }
+      else {
         usage();
+      }
     }
-    else {
+    if ( geo_files.empty() || (!compact2lcdd && !compact2gdml && !compact2pand && !compact2vis))
       usage();
+
+    LCDD& lcdd = dd4hep_instance();
+    // Load compact files
+    for(size_t i=0; i<geo_files.size(); ++i)  {
+      const char* plugin_argv[] = {geo_files[i], 0};
+      run_plugin(lcdd,"DD4hepCompactLoader",1,(char**)plugin_argv);
     }
+    // Create volume manager and populate it required
+    if ( volmgr  ) run_plugin(lcdd,"DD4hepVolumeManager",0,0);
+    // Execute data converter.
+    if ( compact2lcdd )
+      run_plugin(lcdd,"DD4hepGeometry2LCDD",output,&argv[output]);
+    else if ( compact2gdml )
+      run_plugin(lcdd,"DD4hepGeometry2GDML",output,&argv[output]);
+    else if ( compact2pand )
+      run_plugin(lcdd,"DD4hepGeometry2PANDORA",output,&argv[output]);
+    else if ( compact2vis && ascii )
+      run_plugin(lcdd,"DD4hepGeometry2VISASCII",output,&argv[output]);
+    else if ( compact2vis )
+      run_plugin(lcdd,"DD4hepGeometry2VIS",output,&argv[output]);
+    if ( destroy ) delete &lcdd;
+    return 0;
   }
-  if ( geo_files.empty() || (!compact2lcdd && !compact2gdml && !compact2pand && !compact2vis))
-    usage();
+}
 
-  LCDD& lcdd = dd4hep_instance();
-  // Load compact files
-  for(size_t i=0; i<geo_files.size(); ++i)  {
-    const char* plugin_argv[] = {geo_files[i], 0};
-    run_plugin(lcdd,"DD4hepCompactLoader",1,(char**)plugin_argv);
+/// Main entry point as a program
+int main(int argc, char** argv)   {
+  try  {
+    return invoke_converter(argc, argv);
   }
-  // Create volume manager and populate it required
-  if ( volmgr  ) run_plugin(lcdd,"DD4hepVolumeManager",0,0);
-  // Execute data converter.
-  if ( compact2lcdd )
-    run_plugin(lcdd,"DD4hepGeometry2LCDD",output,&argv[output]);
-  else if ( compact2gdml )
-    run_plugin(lcdd,"DD4hepGeometry2GDML",output,&argv[output]);
-  else if ( compact2pand )
-    run_plugin(lcdd,"DD4hepGeometry2PANDORA",output,&argv[output]);
-  else if ( compact2vis && ascii )
-    run_plugin(lcdd,"DD4hepGeometry2VISASCII",output,&argv[output]);
-  else if ( compact2vis )
-    run_plugin(lcdd,"DD4hepGeometry2VIS",output,&argv[output]);
-  if ( destroy ) delete &lcdd;
-  return 0;
+  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/dumpdetector.cpp b/UtilityApps/src/dumpdetector.cpp
index 4ed85de76..ff9589d36 100644
--- a/UtilityApps/src/dumpdetector.cpp
+++ b/UtilityApps/src/dumpdetector.cpp
@@ -38,7 +38,7 @@ using namespace DDSurfaces ;
 using namespace dd4hep ;
 
 //=============================================================================
-void printDetectorData( DetElement det ){
+static void printDetectorData( DetElement det ){
 
   try{ 
     FixedPadSizeTPCData* d = det.extension<FixedPadSizeTPCData>() ; 
@@ -63,7 +63,7 @@ void printDetectorData( DetElement det ){
 
 }
 
-void printDetectorSets( std::string name, unsigned int includeFlag,  unsigned int excludeFlag=DetType::IGNORE ){
+static void printDetectorSets( std::string name, unsigned int includeFlag,  unsigned int excludeFlag=DetType::IGNORE ){
 
   LCDD& lcdd = LCDD::getInstance();
   const std::vector<DetElement>& dets = DetectorSelector(lcdd).detectors( includeFlag, excludeFlag ) ;
@@ -76,7 +76,7 @@ void printDetectorSets( std::string name, unsigned int includeFlag,  unsigned in
 
 //=============================================================================
 
-int run_main(int argc, char** argv ){
+static int invoke_dump_detector(int argc, char** argv ){
     
   if( argc < 2 ) {
     std::cout << " usage: dumpdetector compact.xml [-s]" 
@@ -233,7 +233,7 @@ int run_main(int argc, char** argv ){
 
 int main(int argc, char** argv ){
   try {
-    return run_main(argc,argv);
+    return invoke_dump_detector(argc,argv);
   }
   catch(const std::exception& e)  {
     std::cout << "Got uncaught exception: " << e.what() << std::endl;
diff --git a/UtilityApps/src/plugin_runner.cpp b/UtilityApps/src/plugin_runner.cpp
index d94e03923..47cb4fbae 100644
--- a/UtilityApps/src/plugin_runner.cpp
+++ b/UtilityApps/src/plugin_runner.cpp
@@ -29,39 +29,54 @@ namespace {
     print_default_args() << endl;
     exit(EINVAL);
   }
-}
 
-//______________________________________________________________________________
-int main(int argc,char** argv)  {
-  Args arguments;
-  for(int i=1; i<argc;++i) {
-    if ( argv[i][0]=='-' ) {
-      if ( arguments.handle(i,argc,argv) )
-        continue;
+  //______________________________________________________________________________
+  int invoke_plugin_runner(int argc,char** argv)  {
+    Args arguments;
+    for(int i=1; i<argc;++i) {
+      if ( argv[i][0]=='-' ) {
+        if ( arguments.handle(i,argc,argv) )
+          continue;
+      }
+      else {
+        usage();
+      }
     }
-    else {
+    if ( arguments.plugins.empty() )
       usage();
+
+    LCDD& lcdd = dd4hep_instance();
+    // Load compact files if required by plugin
+    if ( !arguments.geo_files.empty() )   {
+      load_compact(lcdd, arguments);
+    }
+    else  {
+      cout << "geoPluginRun: No geometry input supplied. No geometry will be loaded." << endl;
     }
+    // Create volume manager and populate it required
+    if ( arguments.volmgr  ) run_plugin(lcdd,"DD4hepVolumeManager",0,0);
+    // Execute plugin
+    for(size_t i=0; i<arguments.plugins.size(); ++i)   {
+      std::vector<const char*>& plug = arguments.plugins[i];
+      int num_arg = int(plug.size())-2;
+      run_plugin(lcdd,plug[0], num_arg,(char**)&plug[1]);
+    }
+    if ( arguments.destroy ) delete &lcdd;
+    return 0;
   }
-  if ( arguments.plugins.empty() )
-    usage();
+}
+
 
-  LCDD& lcdd = dd4hep_instance();
-  // Load compact files if required by plugin
-  if ( !arguments.geo_files.empty() )   {
-    load_compact(lcdd, arguments);
+/// Main entry point as a program
+int main(int argc, char** argv)   {
+  try  {
+    return invoke_plugin_runner(argc, argv);
   }
-  else  {
-    cout << "geoPluginRun: No geometry input supplied. No geometry will be loaded." << endl;
+  catch(const std::exception& e)  {
+    std::cout << "Got uncaught exception: " << e.what() << std::endl;
   }
-  // Create volume manager and populate it required
-  if ( arguments.volmgr  ) run_plugin(lcdd,"DD4hepVolumeManager",0,0);
-  // Execute plugin
-  for(size_t i=0; i<arguments.plugins.size(); ++i)   {
-    std::vector<const char*>& plug = arguments.plugins[i];
-    int num_arg = int(plug.size())-2;
-    run_plugin(lcdd,plug[0], num_arg,(char**)&plug[1]);
+  catch (...)  {
+    std::cout << "Got UNKNOWN uncaught exception." << std::endl;
   }
-  if ( arguments.destroy ) delete &lcdd;
-  return 0;
+  return EINVAL;    
 }
diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt
index e71a3d540..8d5389420 100644
--- a/examples/AlignDet/CMakeLists.txt
+++ b/examples/AlignDet/CMakeLists.txt
@@ -55,6 +55,32 @@ dd4hep_add_test_reg( test_AlignDet_Telescope_stress
       -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml -iovs 20 -runs 111
   REGEX_PASS "Summary: # of IOV:  20  # of Runs: 111")
 #
+#---Testing: Write out alignment file from the alignment data using a detelement scan
+dd4hep_add_test_reg( test_AlignDet_Telescope_dump_xml
+  COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh"
+  EXEC_ARGS  geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_read_xml
+  -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml
+  -delta file:${DD4hep_DIR}/examples/Conditions/data/repository.xml
+  -plugin DD4hep_ConditionsXMLRepositoryWriter -iov_type run -iov_value 1500
+  REGEX_PASS "-- DDCond conditions for DetElement /world/Telescope/module_9/sensor Total of 1 Entries.  -->")
+#
+#---Testing: Write out alignment file from the alignment data using a detelement scan
+dd4hep_add_test_reg( test_AlignDet_Telescope_write_xml
+  COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh"
+  EXEC_ARGS  geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_read_xml
+  -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml
+  -delta file:${DD4hep_DIR}/examples/Conditions/data/repository.xml
+  -plugin DD4hep_ConditionsXMLRepositoryWriter -iov_type run -iov_value 1500 -manager -output new_cond.xml
+  REGEX_PASS "Successfully wrote conditions file: new_cond.xml")
+#
+#---Testing: Load Telescope geometry and read and print alignments --------
+dd4hep_add_test_reg( test_AlignDet_Telescope_readback_xml
+  COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh"
+  EXEC_ARGS  geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_read_xml
+     -input  file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml
+     -deltas file:./new_cond.xml
+  REGEX_PASS "\\[7522800AD665C239\\] -> \\[7522800AD665C239\\] /world/Telescope/module_9/sensor#alignment/Tranformations")
+#
 #---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"
-- 
GitLab