From 8f9e16702e228a7de91226517e62dc0925822dd7 Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Thu, 1 Sep 2016 16:18:48 +0000
Subject: [PATCH] Fix compiler probelms spotted by Peter.

---
 DDAlign/src/AlignmentCache.cpp                |   2 +-
 DDAlign/src/AlignmentStack.cpp                |   2 +-
 .../DDCond/ConditionsDependencyCollection.h   | 138 ++++++++
 .../DDCond/ConditionsDependencyHandler.h      |  13 +-
 DDCond/include/DDCond/ConditionsIOVPool.h     |  14 +-
 DDCond/include/DDCond/ConditionsInterna.h     | 302 +++++++++---------
 DDCond/include/DDCond/ConditionsManager.h     |  21 +-
 DDCond/include/DDCond/ConditionsSelectors.h   |  20 +-
 DDCond/src/ConditionsDependencyCollection.cpp |  58 ++++
 DDCond/src/ConditionsDependencyHandler.cpp    |  35 +-
 DDCond/src/ConditionsIOVPool.cpp              |   7 +-
 DDCond/src/plugins/ConditionsExample.cpp      |   2 +-
 DDCond/src/plugins/ConditionsLinearPool.cpp   |  16 +-
 DDCond/src/plugins/ConditionsMappedPool.cpp   |  24 +-
 DDCond/src/plugins/ConditionsMultiLoader.cpp  |  54 ++--
 DDCond/src/plugins/ConditionsPlugins.cpp      |  60 ++--
 DDCond/src/plugins/ConditionsUserPool.cpp     |  22 +-
 DDCond/src/plugins/ConditionsXmlLoader.cpp    |  32 +-
 DDCore/include/DD4hep/ConditionDerived.h      |  49 ++-
 DDCore/include/DD4hep/Conditions.h            |  27 +-
 DDCore/include/DD4hep/Detector.h              |   8 +-
 DDCore/include/DD4hep/Handle.h                |  39 ++-
 DDCore/include/DD4hep/LCDDData.h              |  28 +-
 DDCore/include/DD4hep/Primitives.h            |  63 ++--
 .../DD4hep/objects/ConditionsInterna.h        |  10 +-
 .../include/DD4hep/objects/DetectorInterna.h  |  64 ++--
 DDCore/src/ConditionDerived.cpp               |  40 ++-
 DDCore/src/Detector.cpp                       |  62 +++-
 DDCore/src/DetectorInterna.cpp                |  17 +-
 DDCore/src/LCDDImp.cpp                        |   1 +
 DDCore/src/Objects.cpp                        |   4 +-
 DDCore/src/VolumeManagerInterna.cpp           |   5 +-
 DDDB/src/DDDB2Objects.cpp                     |   2 +-
 DDDB/src/DDDBAlignmentTest.cpp                | 224 ++++++-------
 DDDB/src/DDDBConversion.cpp                   |  34 +-
 DDDB/src/DDDBDerivedCondTest.cpp              |   5 +-
 DDDB/src/DDDBExecutor.cpp                     |  17 +-
 DDG4/plugins/Geant4EventReaderHepMC.cpp       |  14 +-
 DDG4/src/Geant4Kernel.cpp                     |  12 +-
 DDG4/src/Geant4Particle.cpp                   |   2 +-
 DDG4/src/Geant4ParticleHandler.cpp            |   2 +-
 DDG4/src/Geant4Primary.cpp                    |   8 +-
 DDG4/src/Geant4SensDetAction.cpp              |   2 +-
 DDG4/src/Geant4UIMessenger.cpp                |   4 +-
 examples/DDDB/scripts/extract_dddb.sh         |  10 +-
 examples/DDDB/scripts/run_dddb.sh             |  19 +-
 46 files changed, 948 insertions(+), 646 deletions(-)
 create mode 100644 DDCond/include/DDCond/ConditionsDependencyCollection.h
 create mode 100644 DDCond/src/ConditionsDependencyCollection.cpp

diff --git a/DDAlign/src/AlignmentCache.cpp b/DDAlign/src/AlignmentCache.cpp
index c18165ebc..4a6ae6d48 100644
--- a/DDAlign/src/AlignmentCache.cpp
+++ b/DDAlign/src/AlignmentCache.cpp
@@ -52,7 +52,7 @@ AlignmentCache::AlignmentCache(LCDD& lcdd, const string& sdPath, bool top)
 AlignmentCache::~AlignmentCache()   {
   int nentries = (int)m_cache.size();
   int nsect = (int)m_detectors.size();
-  releaseObjects(m_detectors)();
+  releaseObjects(m_detectors);
   m_cache.clear();
   printout(INFO,"AlignmentCache",
            "Destroy cache for subdetector %s [%d section(s), %d entrie(s)]",
diff --git a/DDAlign/src/AlignmentStack.cpp b/DDAlign/src/AlignmentStack.cpp
index 98a67a476..74f3176de 100644
--- a/DDAlign/src/AlignmentStack.cpp
+++ b/DDAlign/src/AlignmentStack.cpp
@@ -173,7 +173,7 @@ AlignmentStack::AlignmentStack()
 
 /// Default destructor
 AlignmentStack::~AlignmentStack()   {
-  destroyObjects(m_stack)();
+  destroyObjects(m_stack);
   InstanceCount::decrement(this);
 }
 
diff --git a/DDCond/include/DDCond/ConditionsDependencyCollection.h b/DDCond/include/DDCond/ConditionsDependencyCollection.h
new file mode 100644
index 000000000..75a234594
--- /dev/null
+++ b/DDCond/include/DDCond/ConditionsDependencyCollection.h
@@ -0,0 +1,138 @@
+// $Id$
+//==========================================================================
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------------
+// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
+// All rights reserved.
+//
+// For the licensing terms see $DD4hepINSTALL/LICENSE.
+// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
+//
+// Author     : M.Frank
+//
+//==========================================================================
+#ifndef DDCOND_CONDITIONSDEPENDENCYCOLLECTION_H
+#define DDCOND_CONDITIONSDEPENDENCYCOLLECTION_H
+
+// Framework include files
+#include "DD4hep/Detector.h"
+#include "DD4hep/Conditions.h"
+#include "DD4hep/ConditionDerived.h"
+
+// C++ include files
+#include <map>
+#include <set>
+
+/// 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 UserPool;
+    class ConditionDependency;
+    
+    /// Collection of condition dependencies.
+    /** 
+     *
+     *  \author  M.Frank
+     *  \version 1.0
+     */
+    class ConditionsDependencyCollection     {
+    public:
+
+      /// Forward definition of the dependency type
+      typedef ConditionDependency                Dependency;
+      struct Holder  {
+        int         flag;
+        Dependency* dep;
+        Holder(Dependency* d) : flag(0), dep(d) {}
+        Holder& operator=(Dependency* d) { dep = d; flag=0; return *this; }
+        operator int()  const            { return dep ? 1 : 0;            }
+        operator Dependency*&()          { return dep;                    }
+        Dependency* operator->()  const  { return dep;                    }
+        Dependency* get()  const         { return dep;                    }
+      };
+
+      /// Forward definition of the dependency container type
+      typedef std::map<unsigned int,Holder>      Dependencies;
+      typedef Dependencies::const_iterator       const_iterator;
+      typedef Dependencies::iterator             iterator;
+      typedef Dependencies::key_type             key_type;
+      typedef Dependencies::mapped_type          mapped_type;
+
+      /// Functor base to create views
+      /** 
+       *
+       *  \author  M.Frank
+       *  \version 1.0
+       */
+      class Functor  {
+      public:
+        /// Forward definition of the dependency type
+        typedef ConditionsDependencyCollection::Dependency   Dependency;
+        /// Forward definition of the dependency container type
+        typedef ConditionsDependencyCollection::Dependencies Dependencies;
+      };
+      /// Dependency container
+      Dependencies dependencies;
+    public:
+      /// Initializing constructor
+      ConditionsDependencyCollection();
+      /// Copy constructor
+      ConditionsDependencyCollection(const ConditionsDependencyCollection& copy);
+      /// Default destructor
+      virtual ~ConditionsDependencyCollection();
+      /// Clear the dependency container. Destroys the contained stuff
+      void clear();
+      /// Mini-container interface: emptyness check
+      bool empty()  const            {  return dependencies.empty();      }
+      /// Mini-container interface: number of entries
+      size_t size()  const           {  return dependencies.size();       }
+      /// Mini-container interface: begin of iteration
+      iterator       begin()         {  return dependencies.begin();      }
+      /// Mini-container interface: begin of iteration (const)
+      const_iterator begin()  const  {  return dependencies.begin();      }
+      /// Mini-container interface: end of iteration
+      iterator       end()           {  return dependencies.end();        }
+      /// Mini-container interface: end of iteration (const)
+      const_iterator end()    const  {  return dependencies.end();        }
+      /// Mini-container interface: find element by key 
+      iterator       find(Condition::key_type key)
+      {  return dependencies.find(key);                                   }
+      /// Mini-container interface: find element by key (const)
+      const_iterator find(Condition::key_type key) const
+      {  return dependencies.find(key);                                   }
+      /// Mini-container interface: insert element by key
+      std::pair<iterator,bool> insert(const Dependencies::value_type& entry);
+      /// Insert new element by key
+      std::pair<iterator,bool> insert(Condition::key_type key, Dependency* dep);
+      /// Create view by application of functor
+      template <typename T> void for_each(const T& function)  const
+      {  std::for_each(dependencies.begin(),dependencies.end(),function); }
+    };
+
+    /// Collection of DetElements from the conditions dependencies.
+    /** 
+     *
+     *  \author  M.Frank
+     *  \version 1.0
+     */
+    template <typename Data, typename Oper>
+    class DependencyCollector : public ConditionsDependencyCollection::Functor    {
+    public:
+      /// Reference to collection result (Object owned by caller)
+      Data& user_data;
+      /// Reference to the collection operator (Object owned by caller)
+      const Oper& user_oper;
+      /// Initializing constructor
+      DependencyCollector(Data& d, const Oper& o) : user_data(d), user_oper(o)    {}
+      /// Default callback to work on dependency items. May be overloaded if necessary
+      void operator()(const Dependencies::value_type& e) const
+      {  user_oper(user_data, e);                                                  }
+    };
+  }        /* End namespace Conditions                   */
+}          /* End namespace DD4hep                       */
+
+#endif     /* DDCOND_CONDITIONSDEPENDENCYCOLLECTION_H    */
diff --git a/DDCond/include/DDCond/ConditionsDependencyHandler.h b/DDCond/include/DDCond/ConditionsDependencyHandler.h
index f9d742d2a..fbbcd3b8c 100644
--- a/DDCond/include/DDCond/ConditionsDependencyHandler.h
+++ b/DDCond/include/DDCond/ConditionsDependencyHandler.h
@@ -37,7 +37,6 @@ namespace DD4hep {
      */
     class ConditionsDependencyHandler : public ConditionResolver {
     public:
-      typedef Geometry::LCDD LCDD;
       typedef ConditionsManager::Dependencies Dependencies;
 
     protected:
@@ -49,13 +48,13 @@ namespace DD4hep {
       const Dependencies&        m_dependencies;
   
       /// Internal call to trigger update callback
-      Condition::Object* do_callback(const ConditionDependency* dep) const;
+      Condition::Object* do_callback(const ConditionDependency& dep) const;
 
     public:
       /// Initializing constructor
       ConditionsDependencyHandler(ConditionsManager::Object* mgr,
-				  UserPool& pool, 
-				  const Dependencies& dependencies);
+                                  UserPool& pool, 
+                                  const Dependencies& dependencies);
       /// Default destructor
       ~ConditionsDependencyHandler();
       /// ConditionResolver implementation: Access to the conditions manager
@@ -75,7 +74,7 @@ namespace DD4hep {
       Condition::Object* operator()(const ConditionDependency* dep)  const;
     };
 
-  } /* End namespace Conditions             */
-} /* End namespace DD4hep                   */
+  }        /* End namespace Conditions                */
+}          /* End namespace DD4hep                    */
 
-#endif     /* DDCOND_CONDITIONSDEPENDENCYHANDLER_H       */
+#endif     /* DDCOND_CONDITIONSDEPENDENCYHANDLER_H    */
diff --git a/DDCond/include/DDCond/ConditionsIOVPool.h b/DDCond/include/DDCond/ConditionsIOVPool.h
index 2b67ecfa6..d27fdbc09 100644
--- a/DDCond/include/DDCond/ConditionsIOVPool.h
+++ b/DDCond/include/DDCond/ConditionsIOVPool.h
@@ -40,9 +40,11 @@ namespace DD4hep {
      */
     class ConditionsIOVPool  {
     public:
-      typedef ConditionsPool* Element;
+      typedef ConditionsPool*              Element;
       typedef std::map<IOV::Key, Element > Elements;      
-      Elements       elements;
+
+      /// Container of IOV dependent conditions pools
+      Elements elements;
 
     public:
       /// Default constructor
@@ -55,13 +57,13 @@ namespace DD4hep {
       void selectRange(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result);
       /// Select all ACTIVE conditions, which do no longer match the IOV requirement
       void select(const Condition::iov_type& required_validity, 
-		  RangeConditions& valid,
-		  RangeConditions& expired,
-		  Condition::iov_type& conditions_validity);
+                  RangeConditions& valid,
+                  RangeConditions& expired,
+                  Condition::iov_type& conditions_validity);
       /// Remove all key based pools with an age beyon the minimum age. 
       /** @return Number of conditions cleaned up and removed.                       */
       int clean(int max_age);
-   };
+    };
 
   } /* End namespace Conditions             */
 } /* End namespace DD4hep                   */
diff --git a/DDCond/include/DDCond/ConditionsInterna.h b/DDCond/include/DDCond/ConditionsInterna.h
index ff6b06f8b..c050ddb4f 100644
--- a/DDCond/include/DDCond/ConditionsInterna.h
+++ b/DDCond/include/DDCond/ConditionsInterna.h
@@ -52,174 +52,174 @@ namespace DD4hep {
      */
     //namespace Interna {
 
-      /// The data class behind a conditions manager handle
-      /**
-       *  For convenience, the class definition is here.
-       *  See ConditionsManager.cpp for the implementation.
-       *
-       *  \author  M.Frank
-       *  \version 1.0
-       *  \ingroup DD4HEP_CONDITIONS
-       */
-      class ConditionsManagerObject : public NamedObject, 
-	public PropertyConfigurable,
-	public ObjectExtensions
-	{
-	  friend class DD4hep::Conditions::ConditionsPool;
-	  friend class DD4hep::Conditions::ConditionsDataLoader;
-
-	public:
-	  typedef dd4hep_ptr<ConditionsDataLoader>     Loader;
-	  typedef std::vector<IOVType>                 IOVTypes;
-	  typedef std::vector<ConditionsIOVPool*>      TypedConditionPool;
-	  typedef std::pair<ConditionsListener*,void*> Listener;
-	  typedef std::set<Listener>                   Listeners;
-	  typedef ConditionsManager::Dependencies      Dependencies;
-	  typedef Condition::key_type                  key_type;
-	  typedef Condition::iov_type                  iov_type;
-
-	public:
-	  /// Property: maximal number of IOV types to be handled
-	  int                    m_maxIOVTypes;
-	  /// Property: ConditionsPool constructor type (default: empty. MUST BE SET!)
-	  std::string            m_poolType;
-	  /// Property: UpdatePool constructor type (default: DD4hep_ConditionsLinearUpdatePool)
-	  std::string            m_updateType;
-	  /// Property: UserPool constructor type (default: DD4hep_ConditionsLinearUserPool)
-	  std::string            m_userType;
-	  /// Property: Conditions loader type (default: "multi" -> DD4hep_Conditions_multi_Loader)
-	  std::string            m_loaderType;
-
-	  /// Reference to main detector description object
-	  LCDD&                  m_lcdd;
-	  /// Collection of IOV types managed
-	  IOVTypes               m_iovTypes;
-	  /// Managed pool of typed conditions indexed by IOV-type and IOV key
-	  TypedConditionPool     m_rawPool;
-	  /// Conditions listeners on registration of new conditions
-	  Listeners              m_onRegister;
-	  /// Conditions listeners on de-registration of new conditions
-	  Listeners              m_onRemove;
-	  /// Lock to protect the update/delayed conditions pool
-	  dd4hep_mutex_t         m_updateLock;
-	  /// Lock to protect the pool of all known conditions
-	  dd4hep_mutex_t         m_poolLock;
-	  /// Reference to data loader
-	  Loader                 m_loader;
-	  /// Reference to update conditions pool
-	  dd4hep_ptr<UpdatePool> m_updatePool;
-
-	  /// Public access: if locked, DetElements stay intact and are not altered
-	  int                    locked;
-
-	protected:
-	  /// Retrieve  a condition set given a Detector Element and the conditions name according to their validity
-	  bool select(key_type key, const iov_type& req_validity, RangeConditions& conditions);
-
-	  /// Retrieve  a condition set given a Detector Element and the conditions name according to their validity
-	  bool select_range(key_type key, const iov_type& req_validity, RangeConditions& conditions);
-
-	  /// Register a set of new managed condition for an IOV range. Called by __load_immediate
-	  // void __register_immediate(RangeConditions& c);
-
-	  void registerCallee(Listeners& listeners, const Listener& callee, bool add);
-
-	  /// Listener invocation when a condition is registered to the cache
-	  void onRegister(Condition condition);
-
-	  /// Listener invocation when a condition is deregistered from the cache
-	  void onRemove(Condition condition);
-
-	public:
-	  /// Set a single conditions value to be managed.
-	  /// Requires EXTERNALLY held lock on update pool!
-	  Condition __queue_update(Conditions::Entry* data);
-
-	public:
-	  /// Standard constructor
-	  ConditionsManagerObject(LCDD& lcdd);
-
-	  /// Default destructor
-	  virtual ~ConditionsManagerObject();
-
-	  /// Access to the detector description instance
-	  LCDD& lcdd() const  {   return m_lcdd; }
-
-	  /// Access to managed pool of typed conditions indexed by IOV-type and IOV key
-	  const TypedConditionPool& conditionsPool() const  {  return m_rawPool; }
+    /// The data class behind a conditions manager handle
+    /**
+     *  For convenience, the class definition is here.
+     *  See ConditionsManager.cpp for the implementation.
+     *
+     *  \author  M.Frank
+     *  \version 1.0
+     *  \ingroup DD4HEP_CONDITIONS
+     */
+    class ConditionsManagerObject : public NamedObject, 
+                                    public PropertyConfigurable,
+                                    public ObjectExtensions
+    {
+      friend class DD4hep::Conditions::ConditionsPool;
+      friend class DD4hep::Conditions::ConditionsDataLoader;
+
+    public:
+      typedef dd4hep_ptr<ConditionsDataLoader>     Loader;
+      typedef std::vector<IOVType>                 IOVTypes;
+      typedef std::vector<ConditionsIOVPool*>      TypedConditionPool;
+      typedef std::pair<ConditionsListener*,void*> Listener;
+      typedef std::set<Listener>                   Listeners;
+      typedef ConditionsManager::Dependencies      Dependencies;
+      typedef Condition::key_type                  key_type;
+      typedef Condition::iov_type                  iov_type;
+
+    public:
+      /// Property: maximal number of IOV types to be handled
+      int                    m_maxIOVTypes;
+      /// Property: ConditionsPool constructor type (default: empty. MUST BE SET!)
+      std::string            m_poolType;
+      /// Property: UpdatePool constructor type (default: DD4hep_ConditionsLinearUpdatePool)
+      std::string            m_updateType;
+      /// Property: UserPool constructor type (default: DD4hep_ConditionsLinearUserPool)
+      std::string            m_userType;
+      /// Property: Conditions loader type (default: "multi" -> DD4hep_Conditions_multi_Loader)
+      std::string            m_loaderType;
+
+      /// Reference to main detector description object
+      LCDD&                  m_lcdd;
+      /// Collection of IOV types managed
+      IOVTypes               m_iovTypes;
+      /// Managed pool of typed conditions indexed by IOV-type and IOV key
+      TypedConditionPool     m_rawPool;
+      /// Conditions listeners on registration of new conditions
+      Listeners              m_onRegister;
+      /// Conditions listeners on de-registration of new conditions
+      Listeners              m_onRemove;
+      /// Lock to protect the update/delayed conditions pool
+      dd4hep_mutex_t         m_updateLock;
+      /// Lock to protect the pool of all known conditions
+      dd4hep_mutex_t         m_poolLock;
+      /// Reference to data loader
+      Loader                 m_loader;
+      /// Reference to update conditions pool
+      dd4hep_ptr<UpdatePool> m_updatePool;
+
+      /// Public access: if locked, DetElements stay intact and are not altered
+      int                    locked;
+
+    protected:
+      /// Retrieve  a condition set given a Detector Element and the conditions name according to their validity
+      bool select(key_type key, const iov_type& req_validity, RangeConditions& conditions);
+
+      /// Retrieve  a condition set given a Detector Element and the conditions name according to their validity
+      bool select_range(key_type key, const iov_type& req_validity, RangeConditions& conditions);
+
+      /// Register a set of new managed condition for an IOV range. Called by __load_immediate
+      // void __register_immediate(RangeConditions& c);
+
+      void registerCallee(Listeners& listeners, const Listener& callee, bool add);
+
+      /// Listener invocation when a condition is registered to the cache
+      void onRegister(Condition condition);
+
+      /// Listener invocation when a condition is deregistered from the cache
+      void onRemove(Condition condition);
+
+    public:
+      /// Set a single conditions value to be managed.
+      /// Requires EXTERNALLY held lock on update pool!
+      Condition __queue_update(Conditions::Entry* data);
+
+    public:
+      /// Standard constructor
+      ConditionsManagerObject(LCDD& lcdd);
+
+      /// Default destructor
+      virtual ~ConditionsManagerObject();
+
+      /// Access to the detector description instance
+      LCDD& lcdd() const  {   return m_lcdd; }
+
+      /// Access to managed pool of typed conditions indexed by IOV-type and IOV key
+      const TypedConditionPool& conditionsPool() const  {  return m_rawPool; }
 	  
-	  ConditionsDataLoader* loader()  const  {  return m_loader.get();  }
+      ConditionsDataLoader* loader()  const  {  return m_loader.get();  }
 
-	  void initialize();
+      void initialize();
 
-	  /// (Un)Registration of conditions listeners with callback when a new condition is registered
-	  void callOnRegister(const Listener& callee, bool add);
-	  /// (Un)Registration of conditions listeners with callback when a condition is unregistered
-	  void callOnRemove(const Listener& callee, bool add);
+      /// (Un)Registration of conditions listeners with callback when a new condition is registered
+      void callOnRegister(const Listener& callee, bool add);
+      /// (Un)Registration of conditions listeners with callback when a condition is unregistered
+      void callOnRemove(const Listener& callee, bool add);
 
-	  /// Register new IOV type if it does not (yet) exist.
-	  /** Returns (false,pointer) if IOV existed and
-	   *  (true,pointer) if new IOV was registered to the manager.
-	   */
-	  std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name);
+      /// Register new IOV type if it does not (yet) exist.
+      /** Returns (false,pointer) if IOV existed and
+       *  (true,pointer) if new IOV was registered to the manager.
+       */
+      std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name);
       
-	  /// Access IOV by its type
-	  const IOVTypes& iovTypes () const   {   return  m_iovTypes;  }
+      /// Access IOV by its type
+      const IOVTypes& iovTypes () const   {   return  m_iovTypes;  }
 
-	  /// Access IOV by its type
-	  const IOVType* iovType (size_t iov_type) const;
+      /// Access IOV by its type
+      const IOVType* iovType (size_t iov_type) const;
 
-	  /// Access IOV by its name
-	  const IOVType* iovType (const std::string& iov_name) const;
+      /// Access IOV by its name
+      const IOVType* iovType (const std::string& iov_name) const;
 
-	  /// Create IOV from string
-	  void fromString(const std::string& iov_str, IOV& iov);
+      /// Create IOV from string
+      void fromString(const std::string& iov_str, IOV& iov);
 
-	  /// Register IOV using new string data
-	  ConditionsPool* registerIOV(const std::string& data);
+      /// Register IOV using new string data
+      ConditionsPool* registerIOV(const std::string& data);
 
-	  /// Register IOV with type and key
-	  ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key);
+      /// Register IOV with type and key
+      ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key);
 
-	  /// Register new condition with the conditions store. Unlocked version, not multi-threaded
-	  bool registerUnlocked(ConditionsPool* pool, Condition cond);
+      /// Register new condition with the conditions store. Unlocked version, not multi-threaded
+      bool registerUnlocked(ConditionsPool* pool, Condition cond);
 
-	  /// Prepare all updates to the clients with the defined IOV
-	  long prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool);
+      /// Prepare all updates to the clients with the defined IOV
+      long prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool);
 
-	  /// Prepare all updates to the clients with the defined IOV
-	  long prepare(const IOV&            required_validity,
-		       dd4hep_ptr<UserPool>& user_pool,
-		       const Dependencies&   dependencies,
-		       bool                  verify_dependencies=true);
+      /// Prepare all updates to the clients with the defined IOV
+      long prepare(const IOV&            required_validity,
+                   dd4hep_ptr<UserPool>& user_pool,
+                   const Dependencies&   dependencies,
+                   bool                  verify_dependencies=true);
 
-	  /// Clean conditions, which are above the age limit.
-	  /** @return Number of conditions cleaned up and removed  */
-	  int clean(const IOVType* typ, int max_age);
+      /// Clean conditions, which are above the age limit.
+      /** @return Number of conditions cleaned up and removed  */
+      int clean(const IOVType* typ, int max_age);
 
-	  /// Full cleanup of all managed conditions.
-	  /** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */
-	  std::pair<int,int> clear();
+      /// Full cleanup of all managed conditions.
+      /** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */
+      std::pair<int,int> clear();
 
-	  /// Push all pending updates to the conditions store. 
-	  /** Note:
-	   *  This does not yet make the new conditions availible to the clients
-	   */
-	  void pushUpdates();
+      /// Push all pending updates to the conditions store. 
+      /** Note:
+       *  This does not yet make the new conditions availible to the clients
+       */
+      void pushUpdates();
  
-	  /// Register a new managed condition.
-	  /** The condition is created externally by the user.
-	   *  Lengthy and tedious procedure.
-	   */
-	  void registerCondition(Condition c);
-
-	  /// Retrieve a condition set given a Detector Element and the conditions name according to their validity
-	  Condition get(key_type key, const iov_type& req_validity);
-
-	  /// Retrieve a condition given a Detector Element and the conditions name
-	  RangeConditions getRange(key_type key, const iov_type& req_validity);
-	};
-      //    } /* End namespace Interna              */
+      /// Register a new managed condition.
+      /** The condition is created externally by the user.
+       *  Lengthy and tedious procedure.
+       */
+      void registerCondition(Condition c);
+
+      /// Retrieve a condition set given a Detector Element and the conditions name according to their validity
+      Condition get(key_type key, const iov_type& req_validity);
+
+      /// Retrieve a condition given a Detector Element and the conditions name
+      RangeConditions getRange(key_type key, const iov_type& req_validity);
+    };
+    //    } /* End namespace Interna              */
   } /* End namespace Conditions             */
 } /* End namespace DD4hep                   */
 
diff --git a/DDCond/include/DDCond/ConditionsManager.h b/DDCond/include/DDCond/ConditionsManager.h
index 8a5fb1475..135409e62 100644
--- a/DDCond/include/DDCond/ConditionsManager.h
+++ b/DDCond/include/DDCond/ConditionsManager.h
@@ -19,6 +19,7 @@
 #include "DD4hep/Detector.h"
 #include "DD4hep/Conditions.h"
 #include "DD4hep/ComponentProperties.h"
+#include "DDCond/ConditionsDependencyCollection.h"
 
 /// Namespace for the AIDA detector description toolkit
 namespace DD4hep {
@@ -34,7 +35,7 @@ namespace DD4hep {
     class ConditionDependency;
     class ConditionsDataLoader;
     class ConditionsManagerObject;
-
+    
     /// Manager class for condition handles
     /**
      *  \author  M.Frank
@@ -50,7 +51,7 @@ namespace DD4hep {
       typedef std::vector<IOVType>               IOVTypes;
       typedef std::map<IOVType*,Container>       TypeConditions;
       typedef std::map<DetElement,Container>     DetectorConditions;
-      typedef std::map<unsigned int,ConditionDependency*> Dependencies;
+      typedef ConditionsDependencyCollection     Dependencies;
 
     public:
 
@@ -74,14 +75,10 @@ namespace DD4hep {
       ConditionsManager(Object* p) : Handle<Object>(p) {}
 
       /// Constructor to assing handle of the same type
-      ConditionsManager(const ConditionsManager& c)
-        : Handle<Object>(c) {
-      }
+      ConditionsManager(const ConditionsManager& c) : Handle<Object>(c) {}
 
       /// Constructor to be used assigning from different type
-      template <typename Q> ConditionsManager(const Handle<Q>& e)
-        : Handle<Object>(e) {
-      }
+      template <typename Q> ConditionsManager(const Handle<Q>& e) : Handle<Object>(e) {}
 
       /// Default destructor
       ~ConditionsManager();
@@ -133,11 +130,11 @@ namespace DD4hep {
 
       /// Prepare all updates to the clients with the defined IOV
       long prepare(const IOV&            required_validity,
-		   dd4hep_ptr<UserPool>& user_pool,
-		   const Dependencies&   dependencies,
-		   bool                  verify_dependencies=true);
+                   dd4hep_ptr<UserPool>& user_pool,
+                   const Dependencies&   dependencies,
+                   bool                  verify_dependencies=true);
     };
 
   }       /* End namespace Geometry                 */
 }         /* End namespace DD4hep                   */
-#endif    /* DDCOND_CONDITIONSMANAGER_H    */
+#endif    /* DDCOND_CONDITIONSMANAGER_H             */
diff --git a/DDCond/include/DDCond/ConditionsSelectors.h b/DDCond/include/DDCond/ConditionsSelectors.h
index 215cecbbe..8eb9b861f 100644
--- a/DDCond/include/DDCond/ConditionsSelectors.h
+++ b/DDCond/include/DDCond/ConditionsSelectors.h
@@ -56,8 +56,8 @@ namespace DD4hep {
     public:
       ConditionsPoolRemove(ConditionsPool& p) : pool(p)         {                   }
       void operator()(object_t* o) const             {
-	pool.onRemove(o);
-	delete o;
+        pool.onRemove(o);
+        delete o;
       }
       void operator()(const cond_t& o) const         { (*this)(o.ptr());             }
       void operator()(const mapentry_t& o) const     { (*this)(o.second.ptr());      }
@@ -97,7 +97,7 @@ namespace DD4hep {
       void operator()(const ptr_mapentry_t& o)    { (*this)(o.second);               }
     };
     template <typename collection_type> 
-      CollectionSelect<collection_type> collectionSelect(collection_type& collection) {
+    CollectionSelect<collection_type> collectionSelect(collection_type& collection) {
       return CollectionSelect<collection_type>(collection);
     }
 
@@ -111,15 +111,15 @@ namespace DD4hep {
     public:
       ActiveSelect(collection_type& p) : collection(p) {}
       void operator()(object_t* o)  const {
-	if ( (o->flags & cond_t::ACTIVE) )
-	  collection.insert(collection.end(),o); 
+        if ( (o->flags & cond_t::ACTIVE) )
+          collection.insert(collection.end(),o); 
       }
       void operator()(const cond_t& o) const          { (*this)(o.ptr());            }
       void operator()(const mapentry_t& o) const      { (*this)(o.second.ptr());     }
       void operator()(const ptr_mapentry_t& o)  const { (*this)(o.second);           }
     };
     template <typename collection_type> 
-      ActiveSelect<collection_type> activeSelect(collection_type& active) {
+    ActiveSelect<collection_type> activeSelect(collection_type& active) {
       return ActiveSelect<collection_type>(active);
     }
 
@@ -132,17 +132,17 @@ namespace DD4hep {
       cond_t::key_type key;
       collection_type& collection;
     public:
-    KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) {}
+      KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) {}
       void operator()(object_t* o) const {
-	if ( o->hash == key )
-	  collection.insert(collection.end(),o); 
+        if ( o->hash == key )
+          collection.insert(collection.end(),o); 
       }
       void operator()(const cond_t& o) const          { (*this)(o.ptr());            }
       void operator()(const mapentry_t& o) const      { (*this)(o.second.ptr());     }
       void operator()(const ptr_mapentry_t& o) const  { (*this)(o.second);           }
     };
     template <typename collection_type> 
-      KeyedSelect<collection_type> keyedSelect(Condition::key_type k, collection_type& keyed) {
+    KeyedSelect<collection_type> keyedSelect(Condition::key_type k, collection_type& keyed) {
       return KeyedSelect<collection_type>(k, keyed);
     }
 
diff --git a/DDCond/src/ConditionsDependencyCollection.cpp b/DDCond/src/ConditionsDependencyCollection.cpp
new file mode 100644
index 000000000..5b1c3fc24
--- /dev/null
+++ b/DDCond/src/ConditionsDependencyCollection.cpp
@@ -0,0 +1,58 @@
+// $Id$
+//==========================================================================
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------------
+// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
+// All rights reserved.
+//
+// For the licensing terms see $DD4hepINSTALL/LICENSE.
+// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
+//
+// Author     : M.Frank
+//
+//==========================================================================
+
+// Framework include files
+#include "DD4hep/Printout.h"
+#include "DD4hep/Primitives.h"
+#include "DDCond/ConditionsDependencyCollection.h"
+
+using namespace DD4hep;
+using namespace DD4hep::Conditions;
+
+/// Default constructor
+ConditionsDependencyCollection::ConditionsDependencyCollection()
+{
+}
+
+/// Copy constructor
+ConditionsDependencyCollection::ConditionsDependencyCollection(const ConditionsDependencyCollection& copy)
+  : dependencies(copy.dependencies)
+{
+  for(Dependencies::iterator i=dependencies.begin(); i!=dependencies.end(); ++i)
+    (*i).second->addRef(), (*i).second.flag = 0;
+}
+
+/// Default destructor
+ConditionsDependencyCollection::~ConditionsDependencyCollection()   {
+  releaseObjects(dependencies);
+}
+
+/// Clear the dependency container. Destroys the contained stuff
+void ConditionsDependencyCollection::clear()   {
+  releaseObjects(dependencies);
+}
+
+/// Mini-container interface: insert element by key
+std::pair<ConditionsDependencyCollection::iterator,bool>
+ConditionsDependencyCollection::insert(const Dependencies::value_type& entry)   {
+  entry.second->addRef();
+  return dependencies.insert(entry);
+}
+
+/// Insert new element by key
+std::pair<ConditionsDependencyCollection::iterator,bool>
+ConditionsDependencyCollection::insert(Condition::key_type key, Dependency* dep)   {
+  dep->addRef();
+  return dependencies.insert(std::make_pair(key,Holder(dep)));
+}
diff --git a/DDCond/src/ConditionsDependencyHandler.cpp b/DDCond/src/ConditionsDependencyHandler.cpp
index d9fd430ce..022f6b809 100644
--- a/DDCond/src/ConditionsDependencyHandler.cpp
+++ b/DDCond/src/ConditionsDependencyHandler.cpp
@@ -21,8 +21,8 @@ using namespace DD4hep::Conditions;
 
 /// Default constructor
 ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager::Object* mgr,
-							 UserPool& pool,
-							 const Dependencies& dependencies)
+                                                         UserPool& pool,
+                                                         const Dependencies& dependencies)
   : m_manager(mgr), m_pool(pool), m_dependencies(dependencies)
 {
 }
@@ -42,25 +42,28 @@ Condition ConditionsDependencyHandler::get(unsigned int key)  const  {
     Dependencies::const_iterator i = m_dependencies.find(key);
     if ( i != m_dependencies.end() )  {
       /// This condition is no longer valid. remove it! Will be added again afterwards.
+      const ConditionDependency* dep = (*i).second.get();
       m_pool.remove(key);
-      return do_callback((*i).second);
+      return do_callback(*dep);
     }
   }
   Dependencies::const_iterator i = m_dependencies.find(key);
-  if ( i != m_dependencies.end() )
-    return do_callback((*i).second);
+  if ( i != m_dependencies.end() )   {
+    const ConditionDependency* dep = (*i).second.get();
+    return do_callback(*dep);
+  }
   return Condition();
 }
 
 
 /// Internal call to trigger update callback
 Condition::Object* 
-ConditionsDependencyHandler::do_callback(const ConditionDependency* dep)  const {
+ConditionsDependencyHandler::do_callback(const ConditionDependency& dep)  const {
   try  {
     Condition::iov_type iov(m_pool.validity().iovType);
-    ConditionUpdateCall::Context ctxt(*this, *dep, iov.reset().invert());
-    Condition          cond = (*dep->callback)(dep->target, ctxt);
-    Condition::Object* obj = cond.ptr();
+    ConditionUpdateCall::Context ctxt(*this, dep, iov.reset().invert());
+    Condition          cond = (*dep.callback)(dep.target, ctxt);
+    Condition::Object* obj  = cond.ptr();
     if ( obj )  {
       if ( !obj->hash ) obj->hash = ConditionKey::hashCode(obj->name);
       cond->setFlag(Condition::DERIVED);
@@ -72,23 +75,23 @@ ConditionsDependencyHandler::do_callback(const ConditionDependency* dep)  const
   }
   catch(const std::exception& e)   {
     printout(ERROR,"ConditionDependency",
-	     "+++ Exception while creating dependent Condition %s:",
-	     dep->target.name.c_str());
+             "+++ Exception while creating dependent Condition %s:",
+             dep.target.name.c_str());
     printout(ERROR,"ConditionDependency","\t\t%s", e.what());
   }
   catch(...)   {
     printout(ERROR,"ConditionDependency",
-	     "+++ UNKNOWN exception while creating dependent Condition %s.",
-	     dep->target.name.c_str());
+             "+++ UNKNOWN exception while creating dependent Condition %s.",
+             dep.target.name.c_str());
   }
   m_pool.print("*");
   except("ConditionDependency",
-	 "++ Exception while creating dependent Condition %s.",
-	 dep->target.name.c_str());
+         "++ Exception while creating dependent Condition %s.",
+         dep.target.name.c_str());
   return 0;
 }
 
 /// Handler callback to process multiple derived conditions
 Condition::Object* ConditionsDependencyHandler::operator()(const ConditionDependency* dep)  const   {
-  return do_callback(dep);
+  return do_callback(*dep);
 }
diff --git a/DDCond/src/ConditionsIOVPool.cpp b/DDCond/src/ConditionsIOVPool.cpp
index 0647c6d4d..8e0cc9e70 100644
--- a/DDCond/src/ConditionsIOVPool.cpp
+++ b/DDCond/src/ConditionsIOVPool.cpp
@@ -29,6 +29,7 @@ ConditionsIOVPool::ConditionsIOVPool()  {
 
 /// Default destructor
 ConditionsIOVPool::~ConditionsIOVPool()  {
+  clean(-1);
   InstanceCount::decrement(this);
 }
 
@@ -81,9 +82,9 @@ int ConditionsIOVPool::clean(int max_age)   {
 
 /// Select all ACTIVE conditions, which do no longer match the IOV requirement
 void ConditionsIOVPool::select(const Condition::iov_type& required_validity, 
-			       RangeConditions& valid,
-			       RangeConditions& expired,
-			       Condition::iov_type& conditions_validity)
+                               RangeConditions& valid,
+                               RangeConditions& expired,
+                               Condition::iov_type& conditions_validity)
 {
   if ( !elements.empty() )  {
     const IOV::Key req_key = required_validity.key(); // 16 bytes => better copy!
diff --git a/DDCond/src/plugins/ConditionsExample.cpp b/DDCond/src/plugins/ConditionsExample.cpp
index cbd8a38ea..d429da8c9 100644
--- a/DDCond/src/plugins/ConditionsExample.cpp
+++ b/DDCond/src/plugins/ConditionsExample.cpp
@@ -175,7 +175,7 @@ namespace  {
     return 1;
   }
 
- struct Callee  {
+  struct Callee  {
     int m_param;
     Callee() : m_param(0) {}
     void call(unsigned long tags, DetElement& det, void* param)    {
diff --git a/DDCond/src/plugins/ConditionsLinearPool.cpp b/DDCond/src/plugins/ConditionsLinearPool.cpp
index 241e32856..c32de44ae 100644
--- a/DDCond/src/plugins/ConditionsLinearPool.cpp
+++ b/DDCond/src/plugins/ConditionsLinearPool.cpp
@@ -53,20 +53,20 @@ namespace DD4hep {
 
       /// Total entry count
       virtual size_t count()  const   {
-	return m_entries.size();
+        return m_entries.size();
       }
 
       /// Full cleanup of all managed conditions.
       virtual void clear()   {
-	for_each(m_entries.begin(), m_entries.end(), ConditionsPoolRemove(*this));
+        for_each(m_entries.begin(), m_entries.end(), ConditionsPoolRemove(*this));
         m_entries.clear();
       }
 
       /// Check if a condition exists in the pool
       virtual Condition exists(Condition::key_type key)  const   {
         typename Mapping::const_iterator i=
-	  find_if(m_entries.begin(), m_entries.end(), HashConditionFind(key));
-	return i==m_entries.end() ? Condition() : (*i);
+          find_if(m_entries.begin(), m_entries.end(), HashConditionFind(key));
+        return i==m_entries.end() ? Condition() : (*i);
       }
 
       /// Register a new condition to this pool
@@ -108,7 +108,7 @@ namespace DD4hep {
     public:
       /// Default constructor
       ConditionsLinearUpdatePool(ConditionsManager mgr)
-	: ConditionsLinearPool<MAPPING,BASE>(mgr) 
+        : ConditionsLinearPool<MAPPING,BASE>(mgr) 
       {
       }
 
@@ -120,7 +120,7 @@ namespace DD4hep {
         MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries;
         if ( !m.empty() )  {
           for(typename MAPPING::iterator i=m.begin(); i!=m.end(); ++i)   {
-	    Condition::Object* o = *i;
+            Condition::Object* o = *i;
             entries[o->iov].push_back(Condition(o));
           }
           m.clear();        
@@ -129,8 +129,8 @@ namespace DD4hep {
 
       /// Select the conditions matching the DetElement and the conditions name
       virtual void select_range(Condition::key_type key,
-				const Condition::iov_type& req, 
-				RangeConditions& result)
+                                const Condition::iov_type& req, 
+                                RangeConditions& result)
       {
         MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries;
         if ( !m.empty() )   {
diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp
index 4564fee59..0b9a2ae93 100644
--- a/DDCond/src/plugins/ConditionsMappedPool.cpp
+++ b/DDCond/src/plugins/ConditionsMappedPool.cpp
@@ -53,34 +53,34 @@ namespace DD4hep {
 
       /// Total entry count
       virtual size_t count()  const   {
-	return m_entries.size();
+        return m_entries.size();
       }
 
       /// Register a new condition to this pool
       virtual void insert(Condition condition)    {
-	Condition::Object* c = condition.access();
+        Condition::Object* c = condition.access();
         m_entries.insert(std::make_pair(c->hash,c));
       }
 
       /// Register a new condition to this pool. May overload for performance reasons.
       virtual void insert(RangeConditions& new_entries)   {
         for(RangeConditions::iterator i=new_entries.begin(); i!=new_entries.end(); ++i)  {
-	  Condition::Object* c = (*i).access();
-	  m_entries.insert(std::make_pair(c->hash,c));
-	}
+          Condition::Object* c = (*i).access();
+          m_entries.insert(std::make_pair(c->hash,c));
+        }
       }
 
       /// Full cleanup of all managed conditions.
       virtual void clear()   {
-	for_each(m_entries.begin(), m_entries.end(), ConditionsPoolRemove(*this));
+        for_each(m_entries.begin(), m_entries.end(), ConditionsPoolRemove(*this));
         m_entries.clear();
       }
 
       /// Check if a condition exists in the pool
       virtual Condition exists(Condition::key_type key)  const   {
         typename Mapping::const_iterator i=
-	  find_if(m_entries.begin(), m_entries.end(), HashConditionFind(key));
-	return i==m_entries.end() ? Condition() : (*i).second;
+          find_if(m_entries.begin(), m_entries.end(), HashConditionFind(key));
+        return i==m_entries.end() ? Condition() : (*i).second;
       }
       /// Select the conditions matching the DetElement and the conditions name
       virtual void select(Condition::key_type key, RangeConditions& result)
@@ -113,7 +113,7 @@ namespace DD4hep {
     public:
       /// Default constructor
       ConditionsMappedUpdatePool(ConditionsManager mgr)
-	: ConditionsMappedPool<MAPPING,BASE>(mgr) 
+        : ConditionsMappedPool<MAPPING,BASE>(mgr) 
       {
       }
 
@@ -134,15 +134,15 @@ namespace DD4hep {
 
       /// Select the conditions matching the DetElement and the conditions name
       virtual void select_range(Condition::key_type key,
-				const Condition::iov_type& req, 
-				RangeConditions& result)
+                                const Condition::iov_type& req, 
+                                RangeConditions& result)
       {
         MAPPING& m = this->ConditionsMappedPool<MAPPING,BASE>::m_entries;
         if ( !m.empty() )   {
           unsigned int req_typ = req.iovType ? req.iovType->type : req.type;
           const IOV::Key& req_key = req.key();
           for(typename MAPPING::const_iterator i=m.begin(); i != m.end(); ++i)  {
-	    Condition::Object* o = (*i).second;
+            Condition::Object* o = (*i).second;
             if ( key == o->hash )  {
               const IOV* _iov = o->iov;
               unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type;
diff --git a/DDCond/src/plugins/ConditionsMultiLoader.cpp b/DDCond/src/plugins/ConditionsMultiLoader.cpp
index 9dd9b4b4d..303920ecf 100644
--- a/DDCond/src/plugins/ConditionsMultiLoader.cpp
+++ b/DDCond/src/plugins/ConditionsMultiLoader.cpp
@@ -48,7 +48,7 @@ namespace DD4hep {
       virtual ~ConditionsMultiLoader();
       /// Load  a condition set given a Detector Element and the conditions name according to their validity
       virtual size_t load(key_type key,
-			  const iov_type& req_validity,
+                          const iov_type& req_validity,
                           RangeConditions& conditions);
       /// Load  a condition set given a Detector Element and the conditions name according to their validity
       virtual size_t load_range(key_type key,
@@ -56,14 +56,30 @@ namespace DD4hep {
                                 RangeConditions& conditions);
       /// Update a range of conditions according to the required IOV
       virtual size_t update(const iov_type& req_validity,
-			    RangeConditions& conditions,
-			    iov_type& conditions_validity);
+                            RangeConditions& conditions,
+                            iov_type& conditions_validity);
     };
   } /* End namespace Geometry               */
 } /* End namespace DD4hep                   */
 
 #endif /* DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H  */
 
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------------
+// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
+// All rights reserved.
+//
+// For the licensing terms see $DD4hepINSTALL/LICENSE.
+// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
+//
+//  \author  Markus Frank
+//  \date    2016-02-02
+//  \version 1.0
+//
+//==========================================================================
+// $Id$
+
+// Framework include files
 //#include "ConditionsMultiLoader.h"
 #include "DD4hep/Printout.h"
 #include "DD4hep/Factories.h"
@@ -95,7 +111,7 @@ ConditionsMultiLoader::~ConditionsMultiLoader() {
 
 ConditionsDataLoader* 
 ConditionsMultiLoader::load_source(const std::string& nam,
-				   const iov_type& req_validity)
+                                   const iov_type& req_validity)
 {
   OpenSources::iterator iop = m_openSources.find(nam);
   if ( iop == m_openSources.end() )  {
@@ -112,8 +128,8 @@ ConditionsMultiLoader::load_source(const std::string& nam,
       const void* argv[] = {fac.c_str(), m_mgr.ptr(), 0};
       loader = createPlugin<ConditionsDataLoader>(typ,m_lcdd,2,argv);
       if ( !loader )  {
-	except("ConditionsMultiLoader",
-	       "Failed to create conditions loader of type: "+typ+" to read:"+nam);
+        except("ConditionsMultiLoader",
+               "Failed to create conditions loader of type: "+typ+" to read:"+nam);
       }
     }
     else  {
@@ -129,8 +145,8 @@ ConditionsMultiLoader::load_source(const std::string& nam,
 
 /// Load  a condition set given a Detector Element and the conditions name according to their validity
 size_t ConditionsMultiLoader::load_range(key_type key,
-					 const iov_type& req_validity,
-					 RangeConditions& conditions)
+                                         const iov_type& req_validity,
+                                         RangeConditions& conditions)
 {
   size_t len = conditions.size();
   // No better idea: Must chack all sources to find the required condition
@@ -138,9 +154,9 @@ size_t ConditionsMultiLoader::load_range(key_type key,
     const IOV& iov = (*i).second;
     if ( iov.type == req_validity.type )  {
       if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) )  { 
-	const string& nam = (*i).first;
-	ConditionsDataLoader* loader = load_source(nam, req_validity);
-	loader->load(key, req_validity, conditions);
+        const string& nam = (*i).first;
+        ConditionsDataLoader* loader = load_source(nam, req_validity);
+        loader->load(key, req_validity, conditions);
       }
     }
   }
@@ -149,8 +165,8 @@ size_t ConditionsMultiLoader::load_range(key_type key,
 
 
 size_t ConditionsMultiLoader::load(key_type key,
-				   const iov_type& req_validity,
-				   RangeConditions& conditions)
+                                   const iov_type& req_validity,
+                                   RangeConditions& conditions)
 {
   size_t len = conditions.size();
   // No better idea: Must chack all sources to find the required condition
@@ -158,9 +174,9 @@ size_t ConditionsMultiLoader::load(key_type key,
     const IOV& iov = (*i).second;
     if ( iov.type == req_validity.type )  {
       if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) )  {
-	const string& nam = (*i).first;
-	ConditionsDataLoader* loader = load_source(nam, req_validity);
-	loader->load(key, req_validity, conditions);
+        const string& nam = (*i).first;
+        ConditionsDataLoader* loader = load_source(nam, req_validity);
+        loader->load(key, req_validity, conditions);
       }
     }
   }
@@ -169,8 +185,8 @@ size_t ConditionsMultiLoader::load(key_type key,
 
 /// Update a range of conditions according to the required IOV
 size_t ConditionsMultiLoader::update(const iov_type& req_validity,
-				     RangeConditions& conditions,
-				     iov_type& conditions_validity)
+                                     RangeConditions& conditions,
+                                     iov_type& conditions_validity)
 {
   RangeConditions upda;
   for(RangeConditions::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)  {
@@ -179,7 +195,7 @@ size_t ConditionsMultiLoader::update(const iov_type& req_validity,
     if ( items < 1 )  {
       // Error: no such condition
       except("ConditionsManager",
-	     "+++ update_expired: Cannot update condition %s [%s] to iov:%s.",
+             "+++ update_expired: Cannot update condition %s [%s] to iov:%s.",
              cond->name.c_str(), cond->iov->str().c_str(), req_validity.str().c_str());
     }
   }
diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp
index 97ab9f699..a6f0aab9b 100644
--- a/DDCond/src/plugins/ConditionsPlugins.cpp
+++ b/DDCond/src/plugins/ConditionsPlugins.cpp
@@ -60,24 +60,24 @@ namespace {
     for( _T::const_iterator i = types.begin(); i != types.end(); ++i )    {
       const IOVType* type = *i;
       if ( type )   {
-	ConditionsIOVPool* pool = manager.iovPool(*type);
-	if ( pool )  {
-	  const _E& e = pool->elements;
-	  printout(INFO,"CondPoolDump","+++ ConditionsIOVPool for type %s  [%d IOV elements]",
-		   type->str().c_str(), int(e.size()));
-	  for (_E::const_iterator j=e.begin(); j != e.end(); ++j)  {
-	    ConditionsPool* cp = (*j).second;
-	    cp->print("");
-	    if ( print_conditions )   {
-	      _R rc;
-	      cp->select_all(rc);
-	      for(_R::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic)  {
-		if ( printer )  {  (*printer)(*ic);                   }
-		else            { /* print_conditions<void>(rc);  */  }
-	      }
-	    }
-	  }
-	}
+        ConditionsIOVPool* pool = manager.iovPool(*type);
+        if ( pool )  {
+          const _E& e = pool->elements;
+          printout(INFO,"CondPoolDump","+++ ConditionsIOVPool for type %s  [%d IOV elements]",
+                   type->str().c_str(), int(e.size()));
+          for (_E::const_iterator j=e.begin(); j != e.end(); ++j)  {
+            ConditionsPool* cp = (*j).second;
+            cp->print("");
+            if ( print_conditions )   {
+              _R rc;
+              cp->select_all(rc);
+              for(_R::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic)  {
+                if ( printer )  {  (*printer)(*ic);                   }
+                else            { /* print_conditions<void>(rc);  */  }
+              }
+            }
+          }
+        }
       }
     }
     printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
@@ -112,18 +112,18 @@ namespace {
       iov.set(iov_key);
       long num_updated = manager.prepare(iov, user_pool);
       if ( iov_type == "epoch" )  {
-	char   c_evt[64];
-	struct tm evt;
-	::gmtime_r(&iov_key, &evt);
-	::strftime(c_evt,sizeof(c_evt),"%T %F",&evt);
-	printout(INFO,"Conditions",
-		 "+++ ConditionsUpdate: Updated %ld conditions... event time: %s",
-		 num_updated, c_evt);
+        char   c_evt[64];
+        struct tm evt;
+        ::gmtime_r(&iov_key, &evt);
+        ::strftime(c_evt,sizeof(c_evt),"%T %F",&evt);
+        printout(INFO,"Conditions",
+                 "+++ ConditionsUpdate: Updated %ld conditions... event time: %s",
+                 num_updated, c_evt);
       }
       else  {
-	printout(INFO,"Conditions",
-		 "+++ ConditionsUpdate: Updated %ld conditions... key[%s]: %ld",
-		 num_updated, iov_type.c_str(), iov_key);
+        printout(INFO,"Conditions",
+                 "+++ ConditionsUpdate: Updated %ld conditions... key[%s]: %ld",
+                 num_updated, iov_type.c_str(), iov_key);
       }
       user_pool->print("User pool");
       manager.clean(epoch, 20);
@@ -144,8 +144,8 @@ namespace {
       string iov_type = argv[0];
       int max_age = *(int*)argv[1];
       printout(INFO,"Conditions",
-	       "+++ ConditionsUpdate: Cleaning conditions... type:%s max age:%d",
-	       iov_type.c_str(), max_age);
+               "+++ ConditionsUpdate: Cleaning conditions... type:%s max age:%d",
+               iov_type.c_str(), max_age);
       ConditionsManager manager = ConditionsManager::from(lcdd);
       const IOVType* epoch = manager.iovType(iov_type);
       manager.clean(epoch, max_age);
diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp
index 8655aebff..832de1ca5 100644
--- a/DDCond/src/plugins/ConditionsUserPool.cpp
+++ b/DDCond/src/plugins/ConditionsUserPool.cpp
@@ -93,6 +93,7 @@ namespace DD4hep {
 // Framework include files
 //#include "DDCond/ConditionsMappedPool.h"
 #include "DD4hep/Printout.h"
+#include "DD4hep/Factories.h"
 #include "DD4hep/InstanceCount.h"
 #include "DD4hep/objects/ConditionsInterna.h"
 #include "DDCond/ConditionsInterna.h"
@@ -146,7 +147,7 @@ template<typename MAPPING>
 void ConditionsMappedUserPool<MAPPING>::print(const std::string& opt)   const  {
   const IOV* iov = &m_iov;
   printout(INFO,"UserPool","+++ %s Conditions for USER pool with IOV: %-32s [%4d entries]",
-	   opt.c_str(), iov->str().c_str(), count());
+           opt.c_str(), iov->str().c_str(), count());
   if ( opt == "*" ) {
     typename MAPPING::const_iterator i=m_conditions.begin();
     for( ; i != m_conditions.end(); ++i)   {
@@ -245,24 +246,23 @@ long ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps)  {
     // Loop over the dependencies and check if they have to be upgraded
     for(_D::const_iterator i = deps.begin(); i!=deps.end(); ++i)  {
       key_type key = (*i).first;
-      const ConditionDependency* d = (*i).second;
       typename MAPPING::iterator j = m_conditions.find(key);
-      Condition::Object* cond = j==m_conditions.end() ? 0 : (*j).second;
-      if ( cond )  {
-	if ( IOV::key_is_contained(m_iov.keyData,cond->iov->keyData) )
-	  continue;
-	/// This condition is no longer valid. remove it! Will be added again afterwards.
-	m_conditions.erase(j);
+      if ( j != m_conditions.end() )  {
+        Condition::Object* cond = (*j).second;
+        if ( IOV::key_is_contained(m_iov.keyData,cond->iov->keyData) )
+          continue;
+        /// This condition is no longer valid. remove it! Will be added again afterwards.
+        m_conditions.erase(j);
       }
-      cond = handler(d);
-      m_manager->registerUnlocked(pool, cond);
+      const ConditionDependency* d = (*i).second.get();
+      Condition::Object* cond = handler(d);
+      m_manager->registerUnlocked(pool, cond); // Would bulk update be more efficient?
       ++num_updates;
     }
   }
   return num_updates;
 }
 
-#include "DD4hep/Factories.h"
 namespace {
   void* create_user_pool(DD4hep::Geometry::LCDD&, int argc, char** argv)  {
     if ( argc > 1 )  {
diff --git a/DDCond/src/plugins/ConditionsXmlLoader.cpp b/DDCond/src/plugins/ConditionsXmlLoader.cpp
index 394ce94f1..e56a33147 100644
--- a/DDCond/src/plugins/ConditionsXmlLoader.cpp
+++ b/DDCond/src/plugins/ConditionsXmlLoader.cpp
@@ -35,9 +35,9 @@ namespace DD4hep {
       Buffer m_buffer;
 
       size_t load_source  (const std::string& nam,
-			   key_type key,
-			   const iov_type& req_validity,
-			   RangeConditions& conditions);
+                           key_type key,
+                           const iov_type& req_validity,
+                           RangeConditions& conditions);
     public:
       /// Default constructor
       ConditionsXmlLoader(LCDD& lcdd, ConditionsManager mgr, const std::string& nam);
@@ -45,16 +45,16 @@ namespace DD4hep {
       virtual ~ConditionsXmlLoader();
       /// Load  a condition set given a Detector Element and the conditions name according to their validity
       virtual size_t load(key_type key,
-			  const iov_type& req_validity,
+                          const iov_type& req_validity,
                           RangeConditions& conditions);
       /// Load  a condition set given a Detector Element and the conditions name according to their validity
       virtual size_t load_range(key_type key,
-				const iov_type& req_validity,
+                                const iov_type& req_validity,
                                 RangeConditions& conditions);
       /// Update a range of conditions according to the required IOV
       virtual size_t update(const iov_type& req_validity,
-			    RangeConditions& conditions,
-			    iov_type& iov_intersection);
+                            RangeConditions& conditions,
+                            iov_type& iov_intersection);
     };
 
   } /* End namespace Conditions             */
@@ -101,9 +101,9 @@ ConditionsXmlLoader::~ConditionsXmlLoader() {
 } 
 
 size_t ConditionsXmlLoader::load_source(const std::string& nam,
-					key_type key,
-					const iov_type& req_validity,
-					RangeConditions& conditions)
+                                        key_type key,
+                                        const iov_type& req_validity,
+                                        RangeConditions& conditions)
 {
   size_t len = conditions.size();
   string fac = "XMLConditionsParser";
@@ -134,7 +134,7 @@ size_t ConditionsXmlLoader::load_source(const std::string& nam,
 }
 
 size_t ConditionsXmlLoader::load(key_type key,
-				 const iov_type& req_validity,
+                                 const iov_type& req_validity,
                                  RangeConditions& conditions)
 {
   size_t len = conditions.size();
@@ -146,9 +146,9 @@ size_t ConditionsXmlLoader::load(key_type key,
     const IOV* iov = condition->iov;
     if ( IOV::partial_match(req_validity,*iov) )  {
       if ( key == condition->hash )  {
-	conditions.push_back(condition);
-	m_buffer.erase(j);
-	return conditions.size()-len;
+        conditions.push_back(condition);
+        m_buffer.erase(j);
+        return conditions.size()-len;
       }
     }
   }
@@ -156,7 +156,7 @@ size_t ConditionsXmlLoader::load(key_type key,
 }
 
 size_t ConditionsXmlLoader::load_range(key_type key,
-				       const iov_type& req_validity,
+                                       const iov_type& req_validity,
                                        RangeConditions& conditions)
 {
   size_t len = conditions.size();
@@ -169,7 +169,7 @@ size_t ConditionsXmlLoader::load_range(key_type key,
     const IOV* iov = condition->iov;
     if ( IOV::partial_match(req_validity,*iov) )  {
       if ( key == condition->hash )  {
-	conditions.push_back(condition);
+        conditions.push_back(condition);
       }
     }
     keep.push_back(condition);
diff --git a/DDCore/include/DD4hep/ConditionDerived.h b/DDCore/include/DD4hep/ConditionDerived.h
index 470c88ccb..66c4c8d73 100644
--- a/DDCore/include/DD4hep/ConditionDerived.h
+++ b/DDCore/include/DD4hep/ConditionDerived.h
@@ -114,8 +114,19 @@ namespace DD4hep {
           return this->get<T>(key_value);
         }
       };
+    protected:
+      /// Reference count
+      int  m_refCount;
+      /// Standard destructor
+      ConditionUpdateCall() : m_refCount(1)  {                      }
       /// Standard destructor
       virtual ~ConditionUpdateCall();
+
+    public:
+      /// Add use count to the object
+      ConditionUpdateCall* addRef()   {  ++m_refCount;  return this;  }
+      /// Release object. May not be used any longer
+      void release()  {  if ( --m_refCount <= 0 ) delete this;        }
       /// Interface to client Callback in order to update the condition
       virtual Condition operator()(const ConditionKey& target, const Context& ctxt) = 0;
     };
@@ -130,31 +141,41 @@ namespace DD4hep {
      */
     class ConditionDependency    {
     protected:
-      /// Copy constructor
-      ConditionDependency(const ConditionDependency& c);
-      /// Assignment operator
-      ConditionDependency& operator=(const ConditionDependency& c);
+      /// Reference count
+      int                                m_refCount;
 
     public:
       typedef Geometry::DetElement       DetElement;
       /// Defintion of the depencency container
       typedef std::vector<ConditionKey>  Dependencies;
-      DetElement                 detector;
+      /// Reference to the target's detector element
+      DetElement                         detector;
       /// Key to the condition to be updated
-      ConditionKey              target;
+      ConditionKey                       target;
       /// Dependency keys this condition depends on
-      Dependencies               dependencies;
-      /// Reference to the update callback
-      dd4hep_ptr<ConditionUpdateCall>     callback;
+      Dependencies                       dependencies;
+      /// Reference to the update callback. No auto pointer. callback may be shared
+      ConditionUpdateCall*               callback;
 
+    protected:
+      /// Copy constructor
+      ConditionDependency(const ConditionDependency& c);
+      /// Assignment operator
+      ConditionDependency& operator=(const ConditionDependency& c);
+      /// Default destructor
+      virtual ~ConditionDependency();
+
+    public:
       /// Initializing constructor
       ConditionDependency(const ConditionKey& tar, const Dependencies deps, ConditionUpdateCall* call);
       /// Initializing constructor used by builder
       ConditionDependency(const ConditionKey& tar, ConditionUpdateCall* call);
       /// Default constructor
       ConditionDependency();
-      /// Default destructor
-      virtual ~ConditionDependency();
+      /// Add use count to the object
+      ConditionDependency* addRef()   {  ++m_refCount; return this;  }
+      /// Release object. May not be used any longer
+      void release()  {  if ( --m_refCount <= 0 ) delete this;      }
     };
 
     /// Condition dependency builder
@@ -164,16 +185,16 @@ namespace DD4hep {
      *  \ingroup DD4HEP_CONDITIONS
      */
     class DependencyBuilder  {
-    public:
+    protected:
       /// The created dependency
-      dd4hep_ptr<ConditionDependency> dependency;
+      ConditionDependency* m_dependency;
     public:
       /// Initializing constructor
       DependencyBuilder(const ConditionKey& target, ConditionUpdateCall* call);
       /// Default destructor
       virtual ~DependencyBuilder();
       /// Access underlying object directly
-      ConditionDependency* operator->()  {   return dependency.get();   }
+      ConditionDependency* operator->()            {   return m_dependency;   }
       /// Add a new dependency
       void add(const ConditionKey& source);
       /// Release the created dependency and take ownership.
diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h
index 3ffe85313..9605a5839 100644
--- a/DDCore/include/DD4hep/Conditions.h
+++ b/DDCore/include/DD4hep/Conditions.h
@@ -79,21 +79,22 @@ namespace DD4hep {
 
     public:
       enum StringFlags  {
-        WITH_IOV      = 1<<0,
-        WITH_ADDRESS  = 1<<1,
-        WITH_TYPE     = 1<<2,
-        WITH_COMMENT  = 1<<4,
-        WITH_DATATYPE = 1<<5,
-        WITH_DATA     = 1<<6,
-        NO_NAME       = 1<<20,
+        WITH_IOV         = 1<<0,
+        WITH_ADDRESS     = 1<<1,
+        WITH_TYPE        = 1<<2,
+        WITH_COMMENT     = 1<<4,
+        WITH_DATATYPE    = 1<<5,
+        WITH_DATA        = 1<<6,
+        NO_NAME          = 1<<20,
         NONE
       };
       enum ConditionState {
-        INACTIVE = 0,
-        ACTIVE   = 1<<0,
-        CHECKED  = 1<<2,
-        DERIVED  = 1<<3,
-        USER_FLAGS_FIRST = 1<<10
+        INACTIVE         = 0,
+        ACTIVE           = 1<<0,
+        CHECKED          = 1<<2,
+        DERIVED          = 1<<3,
+        USER_FLAGS_FIRST = 1<<10,
+        USER_FLAGS_LAST  = 1<<31
       };
 
       /// Abstract base for processing callbacks
@@ -117,7 +118,7 @@ namespace DD4hep {
       template <typename Q> Condition(const Handle<Q>& e)
         : Handle<Object>(e) {
       }
-      /// Initializing constructor
+      /// Initializing constructor for a pure, undecorated conditions object
       Condition(const std::string& name, const std::string& type);
       /// Assignment operator
       Condition& operator=(const Condition& c);
diff --git a/DDCore/include/DD4hep/Detector.h b/DDCore/include/DD4hep/Detector.h
index 74cd9e29a..b83945a54 100644
--- a/DDCore/include/DD4hep/Detector.h
+++ b/DDCore/include/DD4hep/Detector.h
@@ -335,10 +335,14 @@ namespace DD4hep {
       ///  Set the flag word encoding detector types ( ideally use DD4hep::DetType for encoding )
       DetElement& setTypeFlag(unsigned int types);
 
+      /// Access hash key of this detector element (Only valid once geometry is closed!)
+      unsigned int key()  const;
+      /// Access the hierarchical level of the detector element (Only valid once geometry is closed!)
+      int level()  const;
       /// Path of the detector element (not necessarily identical to placement path!)
-      std::string path() const;
+      const std::string& path() const;
       /// Access to the full path to the placed object
-      std::string placementPath() const;
+      const std::string& placementPath() const;
 
       /// Set all attributes in one go
       DetElement& setAttributes(const LCDD& lcdd, const Volume& volume, const std::string& region, const std::string& limits,
diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h
index f46eae0bb..2835e8a85 100644
--- a/DDCore/include/DD4hep/Handle.h
+++ b/DDCore/include/DD4hep/Handle.h
@@ -193,31 +193,18 @@ namespace DD4hep {
   template <typename T> inline void destroyHandle(T& h) {
     deletePtr(h.m_element);
   }
-  /// Helper to delete objects from heap and reset the handle  \ingroup DD4HEP_GEOMETRY
-  template <typename T> inline void releaseHandle(T& h) {
-    releasePtr(h.m_element);
-  }
   /// Functor to destroy handles and delete the cached object  \ingroup DD4HEP_GEOMETRY
   template <typename T> class DestroyHandle {
   public:
     void operator()(T p) const {  destroyHandle(p);    }
   };
-  /// Functor to destroy handles and delete the cached object  \ingroup DD4HEP_GEOMETRY
-  template <typename T> class ReleaseHandle {
-  public:
-    void operator()(T p) const {  releaseHandle(p);    }
-  };
   /// map Functor to destroy handles and delete the cached object  \ingroup DD4HEP_GEOMETRY
   template <typename M> class DestroyHandles {
   public:
     /// Container reference
     M& object;
-    /// Copy constructor allowed!
-    DestroyHandles(const DestroyHandles& c) : object(c.object) {}
     /// Initializing constructor
     DestroyHandles(M& m) : object(m) {                 }
-    /// Defautl destructor
-    ~DestroyHandles()                {                 }
     /// Action operator
     void operator()(const std::pair<typename M::key_type, typename M::mapped_type>& p) const
     {   DestroyHandle<typename M::mapped_type>()(p.second);    }
@@ -228,6 +215,32 @@ namespace DD4hep {
     m.clear();
   }
 
+  /// Helper to delete objects from heap and reset the handle  \ingroup DD4HEP_GEOMETRY
+  template <typename T> inline void releaseHandle(T& h) {
+    releasePtr(h.m_element);
+  }
+  /// Functor to destroy handles and delete the cached object  \ingroup DD4HEP_GEOMETRY
+  template <typename T> class ReleaseHandle {
+  public:
+    void operator()(T p) const {  releaseHandle(p);    }
+  };
+  /// map Functor to release handles  \ingroup DD4HEP_GEOMETRY
+  template <typename M> class ReleaseHandles {
+  public:
+    /// Container reference
+    M& object;
+    /// Initializing constructor
+    ReleaseHandles(M& m) : object(m) {                 }
+    /// Action operator
+    void operator()(const std::pair<typename M::key_type, typename M::mapped_type>& p) const
+    {   ReleaseHandle<typename M::mapped_type>()(p.second);    }
+  };
+  /// Functional created of map destruction functors
+  template <typename M> void releaseHandles(M& m)  {
+    for_each(m.begin(), m.end(), ReleaseHandles<M>(m));
+    m.clear();
+  }
+
   /// String conversions: boolean value to string  \ingroup DD4HEP_GEOMETRY
   std::string _toString(bool value);
   /// String conversions: integer value to string  \ingroup DD4HEP_GEOMETRY
diff --git a/DDCore/include/DD4hep/LCDDData.h b/DDCore/include/DD4hep/LCDDData.h
index af6179ea0..518f1ded6 100644
--- a/DDCore/include/DD4hep/LCDDData.h
+++ b/DDCore/include/DD4hep/LCDDData.h
@@ -98,23 +98,23 @@ namespace DD4hep {
       ObjectHandleMap m_display;
       ObjectHandleMap m_fields;
 
-      ObjectHandleMap m_motherVolumes;
+      ObjectHandleMap  m_motherVolumes;
 
       // GDML fields
-      ObjectHandleMap m_define;
-
-      DetElement m_world;
-      DetElement m_trackers;
-      Volume m_worldVol;
-      Volume m_trackingVol;
-
-      Material m_materialAir;
-      Material m_materialVacuum;
-      VisAttr m_invisibleVis;
-      OverlayedField m_field;
-      Header m_header;
+      ObjectHandleMap  m_define;
+
+      DetElement       m_world;
+      DetElement       m_trackers;
+      Volume           m_worldVol;
+      Volume           m_trackingVol;
+
+      Material         m_materialAir;
+      Material         m_materialVacuum;
+      VisAttr          m_invisibleVis;
+      OverlayedField   m_field;
+      Header           m_header;
       LCDD::Properties m_properties;
-      LCDDBuildType m_buildType;
+      LCDDBuildType    m_buildType;
 
       /// Definition of the extension type
       ObjectExtensions m_extensions;
diff --git a/DDCore/include/DD4hep/Primitives.h b/DDCore/include/DD4hep/Primitives.h
index 37801a006..0753aa293 100644
--- a/DDCore/include/DD4hep/Primitives.h
+++ b/DDCore/include/DD4hep/Primitives.h
@@ -269,47 +269,37 @@ namespace DD4hep {
   public:
     M& object;
     DestroyObjects(M& m) : object(m) {                    }
-    ~DestroyObjects()                { object.clear();    }
-    void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const {
-      DestroyObject<typename M::mapped_type>()(p.second);
-    }
+    void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const
+    {  DestroyObject<typename M::mapped_type>()(p.second);    }
     void operator()() const {
       if ( !object.empty() ) for_each(object.begin(),object.end(),(*this));
+      object.clear();
     }
   };
-  template <typename M> DestroyObjects<M> destroyObjects(M& m) {
-    return DestroyObjects<M>(m);
-  }
-  template <typename M> DestroyObjects<M> destroy2nd(M& m) {
-    return DestroyObjects<M>(m);
-  }
+  template <typename M> void destroyObjects(M& m)
+  {  DestroyObjects<M> del(m); del();                      }
+  template <typename M> DestroyObjects<M> destroy2nd(M& m)
+  {  DestroyObjects<M> del(m); del();                      }
 
   /// map Functor to delete objects from heap
   template <typename M> class DestroyFirst {
   public:
     M& object;
-    DestroyFirst(M& m)
-      : object(m) {
-    }
-    ~DestroyFirst() {
-      object.clear();
-    }
-    void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const {
-      DestroyObject<typename M::key_type>()(p.first);
-    }
+    DestroyFirst(M& m) : object(m) {   }
+    void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const
+    {  DestroyObject<typename M::key_type>()(p.first);     }
     void operator()() const {
       if ( !object.empty() ) for_each(object.begin(),object.end(),(*this));
+      object.clear();
     }
   };
-  template <typename M> DestroyFirst<M> destroyFirst(M& m) {
-    return DestroyFirst<M>(m);
-  }
-  template <typename M> DestroyFirst<M> destroy1st(M& m) {
-    return DestroyFirst<M>(m);
-  }
+  template <typename M> void destroyFirst(M& m)
+  {   DestroyFirst<M> del(m); del();           }
+  template <typename M> void destroy1st(M& m)
+  {   DestroyFirst<M> del(m); del();           }
 
   /// Helper to delete objects from heap and reset the pointer. Saves many many lines of code
-  template <typename T> inline void releasePtr(T*& p) {
+  template <typename T> inline void releasePtr(T& p) {
     if (0 != p)
       p->release();
     p = 0;
@@ -326,27 +316,22 @@ namespace DD4hep {
   template <typename M> class ReleaseObjects {
   public:
     M& object;
-    ReleaseObjects(M& m)
-      : object(m) {
-    }
-    ~ReleaseObjects() {
-      object.clear();
-    }
-    void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const {
-      ReleaseObject<typename M::mapped_type>()(p.second);
-    }
+    ReleaseObjects(M& m) : object(m) {    }
+    void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const
+    {  ReleaseObject<typename M::mapped_type>()(p.second);    }
     void operator()() const {
       if ( !object.empty() ) for_each(object.begin(),object.end(),(*this));
+      object.clear();
     }
   };
   template <typename M> ReleaseObject<typename M::value_type> releaseObject(M&) {
     return ReleaseObject<typename M::value_type>();
   }
-  template <typename M> ReleaseObjects<M> releaseObjects(M& m) {
-    return ReleaseObjects<M>(m);
+  template <typename M> void releaseObjects(M& m) {
+    ReleaseObjects<M> rel(m); rel();
   }
-  template <typename M> ReleaseObjects<M> release2nd(M& m) {
-    return ReleaseObjects<M>(m);
+  template <typename M> void release2nd(M& m) {
+    ReleaseObjects<M> rel(m); rel();
   }
 
   /// Functor to delete objects from heap and reset the pointer
diff --git a/DDCore/include/DD4hep/objects/ConditionsInterna.h b/DDCore/include/DD4hep/objects/ConditionsInterna.h
index 6bfa3d019..03df33e5c 100644
--- a/DDCore/include/DD4hep/objects/ConditionsInterna.h
+++ b/DDCore/include/DD4hep/objects/ConditionsInterna.h
@@ -91,13 +91,13 @@ namespace DD4hep {
       class ConditionObject : public NamedObject {
       public:
         /// Forward definition of the key type
-        typedef Condition::key_type key_type;
+        typedef Condition::key_type         key_type;
         /// Forward definition of the iov type
-        typedef Condition::iov_type iov_type;
+        typedef Condition::iov_type         iov_type;
         /// Forward definition of the object properties
-        typedef unsigned int BitMask;
+        typedef unsigned int                mask_type;
         /// Forward definition of the object mask manipulator
-        typedef ReferenceBitMask<BitMask> MaskManip;
+        typedef ReferenceBitMask<mask_type> MaskManip;
 
         /// Condition value (in string form)
         std::string     value;
@@ -116,7 +116,7 @@ namespace DD4hep {
         /// Hash value of the name
         key_type        hash;
         /// Flags
-        BitMask         flags;
+        mask_type       flags;
         /// Reference count
         int             refCount;
         /// Standard constructor
diff --git a/DDCore/include/DD4hep/objects/DetectorInterna.h b/DDCore/include/DD4hep/objects/DetectorInterna.h
index 04b90a83f..35a36bbaa 100644
--- a/DDCore/include/DD4hep/objects/DetectorInterna.h
+++ b/DDCore/include/DD4hep/objects/DetectorInterna.h
@@ -58,13 +58,13 @@ namespace DD4hep {
     class SensitiveDetectorObject: public NamedObject, public ObjectExtensions {
     public:
       unsigned int magic;
-      int verbose;
-      int combineHits;
-      double ecut;
-      Readout readout;
-      Region region;
-      LimitSet limits;
-      std::string hitsCollection;
+      int          verbose;
+      int          combineHits;
+      double       ecut;
+      Readout      readout;
+      Region       region;
+      LimitSet     limits;
+      std::string  hitsCollection;
 
       /// Default constructor
       SensitiveDetectorObject();
@@ -99,62 +99,66 @@ namespace DD4hep {
       typedef Alignments::Container                AlignmentsContainer;
 
       enum DetFlags {
-        HAVE_WORLD_TRAFO = 1<<0,
-        HAVE_PARENT_TRAFO = 1<<1,
-        HAVE_REFERENCE_TRAFO = 1<<2,
+        HAVE_WORLD_TRAFO        = 1<<0,
+        HAVE_PARENT_TRAFO       = 1<<1,
+        HAVE_REFERENCE_TRAFO    = 1<<2,
         HAVE_SENSITIVE_DETECTOR = 1<<29,
-        IS_TOP_LEVEL_DETECTOR = 1<<30,
-        HAVE_OTHER = 1<<31
+        IS_TOP_LEVEL_DETECTOR   = 1<<30,
+        HAVE_OTHER              = 1<<31
       };
 
       /// Magic number to ensure data integrity
-      unsigned int magic;
+      unsigned int        magic;
       /// Flag to remember internally calculated quatities
-      unsigned int flag;
+      unsigned int        flag;
       /// Unique integer identifier of the detector instance
-      int id;
+      int                 id;
       /// Flag to process hits
-      int combineHits;
+      int                 combineHits;
       /// Flag to encode detector types
-      unsigned int typeFlag;
+      unsigned int        typeFlag;
+      /// Hierarchical level within the detector description
+      int                 level;
+      /// Access hash key of this detector element (Only valid once geometry is closed!)
+      unsigned int        key;
       /// Full path to this detector element. May be invalid
-      std::string path;
+      std::string         path;
       /// The path to the placement of the detector element (if placed)
-      std::string placementPath;
+      std::string         placementPath;
 
       /// The subdetector placement corresponding to the ideal detector element's volume
-      PlacedVolume idealPlace;
+      PlacedVolume        idealPlace;
       /// The subdetector placement corresponding to the actual detector element's volume
-      PlacedVolume placement;
+      PlacedVolume        placement;
       /// The cached VolumeID of this subdetector element
       /**  Please note:
        *  These values are set when populating the volume manager.
        *  There are restrictions: e.g. only sensitive subdetectors are present.
        */
-      VolumeID volumeID;
+      VolumeID            volumeID;
       /// Reference to the parent element
-      World privateWorld;
+      World               privateWorld;
       /// Reference to the parent element
-      DetElement parent;
+      DetElement          parent;
       /// Reference element for stored transformations
-      DetElement reference;
+      DetElement          reference;
       /// The array of children
-      Children children;
+      Children            children;
       /// Placeholder for structure with update callbacks
-      UpdateCallbacks updateCalls;
+      UpdateCallbacks     updateCalls;
 
       //@{ Additional information set externally to facilitate the processing of event data */
       /// Basic ideal/nominal detector element alignment entry
-      Alignment nominal;
+      Alignment           nominal;
       /// Basic detector element alignment entry containing the survey data
-      Alignment survey;
+      Alignment           survey;
       /// The detector elements alignments access
       AlignmentsContainer alignments;
       /// The detector elements conditions access
       ConditionsContainer conditions;
 
       /// Global alignment data
-      Ref_t  global_alignment;
+      Ref_t               global_alignment;
 
       // To be removed!
       /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements
diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp
index 723296519..53fed76a5 100644
--- a/DDCore/src/ConditionDerived.cpp
+++ b/DDCore/src/ConditionDerived.cpp
@@ -14,6 +14,7 @@
 
 // Framework includes
 #include "DD4hep/Printout.h"
+#include "DD4hep/InstanceCount.h"
 #include "DD4hep/ConditionDerived.h"
 
 // C/C++ include files
@@ -33,25 +34,34 @@ ConditionResolver::~ConditionResolver()  {
 ConditionDependency::ConditionDependency(const ConditionKey& tar, 
                                          const Dependencies deps, 
                                          ConditionUpdateCall* call)
-  : target(tar), dependencies(deps), callback(call)
+  : m_refCount(0), target(tar), dependencies(deps), callback(call)
 {
+  InstanceCount::increment(this);
+  if ( callback ) callback->addRef();
 }
 
-/// Default constructor
+/// Initializing constructor
 ConditionDependency::ConditionDependency(const ConditionKey& tar, 
                                          ConditionUpdateCall* call)
-  : target(tar), callback(call)
+  : m_refCount(0), target(tar), callback(call)
 {
+  InstanceCount::increment(this);
+  if ( callback ) callback->addRef();
 }
 
-/// Initializing constructor
-ConditionDependency::ConditionDependency()   {
+/// Default constructor
+ConditionDependency::ConditionDependency()
+  : m_refCount(0), target(0), callback(0)
+{
+  InstanceCount::increment(this);
 }
 
 /// Copy constructor
 ConditionDependency::ConditionDependency(const ConditionDependency& c)
-  : target(c.target), dependencies(c.dependencies)
+  : m_refCount(0), target(c.target), dependencies(c.dependencies), callback(c.callback)
 {
+  InstanceCount::increment(this);
+  if ( callback ) callback->addRef();
   except("Dependency",
          "++ Condition: %s. Dependencies may not be assigned or copied!",
          target.name.c_str());
@@ -59,6 +69,8 @@ ConditionDependency::ConditionDependency(const ConditionDependency& c)
 
 /// Default destructor
 ConditionDependency::~ConditionDependency()  {
+  InstanceCount::decrement(this);
+  releasePtr(callback);
 }
 
 /// Assignment operator
@@ -71,19 +83,19 @@ ConditionDependency& ConditionDependency::operator=(const ConditionDependency& )
 
 /// Initializing constructor
 DependencyBuilder::DependencyBuilder(const ConditionKey& target, ConditionUpdateCall* call)
-  : dependency(new ConditionDependency(target,call))
+  : m_dependency(new ConditionDependency(target,call))
 {
 }
 
 /// Default destructor
 DependencyBuilder::~DependencyBuilder()   {
+  releasePtr(m_dependency);
 }
 
 /// Add a new dependency
 void DependencyBuilder::add(const ConditionKey& source)   {
-  ConditionDependency* dep = dependency.get();
-  if ( dep )   {
-    dep->dependencies.push_back(source);
+  if ( m_dependency )   {
+    m_dependency->dependencies.push_back(source);
     return;
   }
   except("Dependency","++ Invalid object. No further source may be added!");
@@ -91,10 +103,12 @@ void DependencyBuilder::add(const ConditionKey& source)   {
 
 /// Release the created dependency and take ownership.
 ConditionDependency* DependencyBuilder::release()   {
-  if ( dependency.get() )   {
-    return dependency.release();
+  if ( m_dependency )   {
+    ConditionDependency* tmp = m_dependency;
+    m_dependency = 0;
+    return tmp;
   }
   except("Dependency","++ Invalid object. Cannot access built objects!");
-  return dependency.release(); // Not necessary, but need to satisfy compiler
+  return m_dependency; // Not necessary, but need to satisfy compiler
 }
 
diff --git a/DDCore/src/Detector.cpp b/DDCore/src/Detector.cpp
index b70db92af..ec90438cd 100644
--- a/DDCore/src/Detector.cpp
+++ b/DDCore/src/Detector.cpp
@@ -24,6 +24,10 @@ using namespace std;
 using namespace DD4hep::Geometry;
 using DD4hep::Alignments::Alignment;
 
+namespace {
+  static string s_empty_string;
+}
+
 /// Clone constructor
 DetElement::DetElement(Object* det_data, const string& det_name, const string& det_type)
   : RefObject(det_data) {
@@ -70,7 +74,7 @@ void DetElement::removeAtUpdate(unsigned int typ, void* pointer)  const {
 }
 
 /// Access to the full path to the placed object
-string DetElement::placementPath() const {
+const string& DetElement::placementPath() const {
   Object* o = ptr();
   if ( o ) {
     if (o->placementPath.empty()) {
@@ -78,7 +82,7 @@ string DetElement::placementPath() const {
     }
     return o->placementPath;
   }
-  return "";
+  return s_empty_string;
 }
 
 /// Access detector type (structure, tracker, calorimeter, etc.).
@@ -93,7 +97,6 @@ DetElement& DetElement::setType(const string& typ) {
   return *this;
 }
 
-
 unsigned int DetElement::typeFlag() const {
   return m_element ? m_element->typeFlag :  0 ;
 }
@@ -105,16 +108,55 @@ DetElement& DetElement::setTypeFlag(unsigned int types) {
   return *this;
 }
 
-string DetElement::path() const {
+namespace {
+  static void make_path(DetElement::Object* o)   {
+    DetElement par = o->parent;
+    if ( par.isValid() )  {
+      o->path = par.path() + "/" + o->name;
+      if ( o->level < 0 ) o->level = par.level() + 1;
+    }
+    else {
+      o->path = "/" + o->name;
+      o->level = 0;
+    }
+    o->key = DD4hep::hash32(o->path);
+  }
+}
+
+/// Access hash key of this detector element (Only valid once geometry is closed!)
+unsigned int DetElement::key()  const   {
+  Object* o = ptr();
+  if ( o )  {
+    if ( o->key != 0 )
+      return o->key;
+    make_path(o);
+    return o->key;
+  }
+  return 0;
+}
+
+/// Access the hierarchical level of the detector element
+int DetElement::level()  const   {
+  Object* o = ptr();
+  if ( o )  {
+    if ( o->level >= 0 )
+      return o->level;
+    make_path(o);
+    return o->level;
+  }
+  return -1;
+}
+
+/// Access the full path of the detector element
+const string& DetElement::path() const {
   Object* o = ptr();
   if ( o ) {
-    if ( o->path.empty() ) {
-      DetElement par = o->parent;
-      o->path = par.isValid() ? (par.path() + "/") + name() : string("/") + name();
-    }
+    if ( !o->path.empty() )
+      return o->path;
+    make_path(o);
     return o->path;
   }
-  return "";
+  return s_empty_string;
 }
 
 int DetElement::id() const {
@@ -376,7 +418,7 @@ SensitiveDetector& SensitiveDetector::setType(const string& typ) {
 
 /// Access the type of the sensitive detector
 string SensitiveDetector::type() const {
-  return m_element ? m_element->GetTitle() : "";
+  return m_element ? m_element->GetTitle() : s_empty_string;
 }
 
 /// Assign the IDDescriptor reference
diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp
index 9b31f1958..a0ce8492b 100644
--- a/DDCore/src/DetectorInterna.cpp
+++ b/DDCore/src/DetectorInterna.cpp
@@ -63,7 +63,7 @@ SensitiveDetectorObject::~SensitiveDetectorObject() {
 /// Default constructor
 DetElementObject::DetElementObject()
   : NamedObject(), ObjectExtensions(typeid(DetElementObject)), magic(magic_word()),
-    flag(0), id(0), combineHits(0), typeFlag(0), path(), placementPath(),
+    flag(0), id(0), combineHits(0), typeFlag(0), level(-1), key(0), path(), placementPath(),
     idealPlace(), placement(), volumeID(0), parent(), reference(), children(),
     nominal(), survey(), alignments(), conditions(),
     worldTrafo(), parentTrafo(), referenceTrafo(0) {
@@ -74,7 +74,7 @@ DetElementObject::DetElementObject()
 /// Initializing constructor
 DetElementObject::DetElementObject(const std::string& nam, int ident)
   : NamedObject(), ObjectExtensions(typeid(DetElementObject)), magic(magic_word()),
-    flag(0), id(ident), combineHits(0), typeFlag(0), path(), placementPath(),
+    flag(0), id(ident), combineHits(0), typeFlag(0), level(-1), key(0), path(), placementPath(),
     idealPlace(), placement(), volumeID(0), parent(), reference(), children(),
     nominal(), survey(), alignments(), conditions(),
     worldTrafo(), parentTrafo(), referenceTrafo(0) {
@@ -87,9 +87,9 @@ DetElementObject::DetElementObject(const std::string& nam, int ident)
 DetElementObject::~DetElementObject() {
   destroyHandles(children);
   deletePtr (referenceTrafo);
-  if ( conditions.isValid() ) delete conditions.ptr();
+  destroyHandle (conditions);
   conditions = ConditionsContainer();
-  if ( alignments.isValid() ) delete alignments.ptr();
+  destroyHandle (alignments);
   alignments = AlignmentsContainer();
   placement.clear();
   idealPlace.clear();
@@ -101,9 +101,11 @@ DetElementObject::~DetElementObject() {
 /// Deep object copy to replicate DetElement trees e.g. for reflection
 DetElementObject* DetElementObject::clone(int new_id, int flg) const {
   DetElementObject* obj = new DetElementObject();
-  obj->id = new_id;
-  obj->typeFlag = typeFlag;
-  obj->flag = 0;
+  obj->id          = new_id;
+  obj->typeFlag    = typeFlag;
+  obj->flag        = 0;
+  obj->key         = 0;
+  obj->level       = -1;
   obj->combineHits = combineHits;
   obj->nominal     = Alignment();
   obj->survey      = Alignment();
@@ -114,7 +116,6 @@ DetElementObject* DetElementObject::clone(int new_id, int flg) const {
     obj->placement  = placement;
     obj->idealPlace = idealPlace;
     obj->placementPath = placementPath;
-    obj->path = path;
   }
   // This implicitly assumes that the children do not access the parent's extensions!
   obj->ObjectExtensions::clear();
diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp
index d62e5fd57..f412ed579 100644
--- a/DDCore/src/LCDDImp.cpp
+++ b/DDCore/src/LCDDImp.cpp
@@ -148,6 +148,7 @@ LCDDImp::LCDDImp() : LCDDData(), LCDDLoad(this), m_buildType(BUILD_NONE)
 LCDDImp::~LCDDImp() {
   if ( m_manager == gGeoManager ) gGeoManager = 0;
   destroyData(false);
+  m_extensions.clear();
   InstanceCount::decrement(this);
 }
 
diff --git a/DDCore/src/Objects.cpp b/DDCore/src/Objects.cpp
index 2113e9751..a23fb5758 100644
--- a/DDCore/src/Objects.cpp
+++ b/DDCore/src/Objects.cpp
@@ -249,7 +249,7 @@ VisAttr::VisAttr(const string& nam) {
   setLineStyle (SOLID);
   setDrawingStyle(SOLID);
   setShowDaughters(true);
-  setAlpha(0.1f);
+  setAlpha(0.9f);
 }
 
 /// Constructor to be used when creating a new entity
@@ -260,7 +260,7 @@ VisAttr::VisAttr(const char* nam) {
   setLineStyle (SOLID);
   setDrawingStyle(SOLID);
   setShowDaughters(true);
-  setAlpha(0.1f);
+  setAlpha(0.9f);
 }
 
 /// Get Flag to show/hide daughter elements
diff --git a/DDCore/src/VolumeManagerInterna.cpp b/DDCore/src/VolumeManagerInterna.cpp
index e8dc6c4c6..4fcdbd245 100644
--- a/DDCore/src/VolumeManagerInterna.cpp
+++ b/DDCore/src/VolumeManagerInterna.cpp
@@ -1,4 +1,4 @@
-// $Id: $
+// $Id:$
 //==========================================================================
 //  AIDA Detector description implementation for LCD
 //--------------------------------------------------------------------------
@@ -39,8 +39,7 @@ VolumeManagerObject::VolumeManagerObject()
 /// Default destructor
 VolumeManagerObject::~VolumeManagerObject() {
   /// Cleanup volume tree
-  for_each(volumes.begin(), volumes.end(), destroyObjects(volumes));
-  volumes.clear();
+  destroyObjects(volumes);
   /// Cleanup dependent managers
   destroyHandles(managers);
   managers.clear();
diff --git a/DDDB/src/DDDB2Objects.cpp b/DDDB/src/DDDB2Objects.cpp
index ce304e4aa..768b371a9 100644
--- a/DDDB/src/DDDB2Objects.cpp
+++ b/DDDB/src/DDDB2Objects.cpp
@@ -1028,7 +1028,7 @@ namespace DD4hep {
         context.print_detelem       = false;
         context.print_conditions    = false;
         context.print_vis           = false;
-        context.max_volume_depth    = 9;
+        context.max_volume_depth    = 11;
 
         CNV<dddb> cnv(lcdd,&context);
         cnv(make_pair(string("World"),context.geo));
diff --git a/DDDB/src/DDDBAlignmentTest.cpp b/DDDB/src/DDDBAlignmentTest.cpp
index 5002b764e..ed27c9214 100644
--- a/DDDB/src/DDDBAlignmentTest.cpp
+++ b/DDDB/src/DDDBAlignmentTest.cpp
@@ -34,7 +34,7 @@
 #include "DDCond/ConditionsInterna.h"
 #include "DDCond/ConditionsOperators.h"
 
-
+#include "DDDB/DDDBReader.h"
 #include "DDDB/DDDBConversion.h"
 #include "DDDB/DDDBConditionPrinter.h"
 
@@ -59,6 +59,43 @@ namespace  {
     typedef DDDB::ConditionPrinter           _Printer;
   };
 
+  struct UserData;
+  struct Entry {
+    UserData*            data;
+    DetElement::Object*  det;
+    DetElement::Object*  par;
+    ConditionDependency* dep;
+    int det_key, par_key, top;
+  };
+  struct UserData {
+    typedef std::map<std::string,size_t>       DetectorMap;
+    typedef std::map<unsigned int,size_t>      DetectorKeys;
+    typedef std::vector<Entry>                 Entries;
+    DetectorMap  detectors;
+    DetectorKeys keys;
+    Entries      entries;
+  };
+  struct _Oper : public ConditionsDependencyCollection::Functor {
+    void operator()(UserData& data, const Dependencies::value_type& e) const  {
+      const Dependency* dep = e.second.get();
+      DetElement det = dep->detector;
+      if ( det.isValid() )  {
+        Entry entry;
+        unsigned int key = det.key();
+        entry.data = &data;
+        entry.top  = 0;
+        entry.dep  = e.second.get();
+        entry.det  = det.ptr();
+        entry.par  = det.parent().ptr();
+        entry.det_key = key;
+        entry.par_key = det.parent().key();
+        data.detectors.insert(make_pair(det.path(),data.entries.size()));
+        data.keys.insert(make_pair(key,data.entries.size()));
+        data.entries.insert(data.entries.end(),entry);
+      }
+    }
+  };
+  
   /// Specialized conditions update callback for alignments
   /**
    *  Used by clients to update a condition.
@@ -67,109 +104,55 @@ namespace  {
    *  \version 1.0
    *  \ingroup DD4HEP_CONDITIONS
    */
-  class AlignmentUpdate1 : public ConditionUpdateCall, public AlignmentTypes  {
+  class AlignmentUpdate : public ConditionUpdateCall, public AlignmentTypes  {
   public:
-    AlignmentUpdate1()          {    }
-    virtual ~AlignmentUpdate1() {    }
+    AlignmentUpdate()   {    }
+    virtual ~AlignmentUpdate() {    }
     /// Interface to client Callback in order to update the condition
     virtual Condition operator()(const ConditionKey& key, const Context& context)  {
-      printout(INFO,"AlignmentUpdate1","++ Building dependent condition: %s",key.name.c_str());
       Condition    target(key.name,"Alignment");
       Data&        data  = target.bind<Data>();
       Condition    cond0 = context.condition(0);
       const Map&   src0  = cond0.get<Map>();
       const Param& par0  = src0.firstParam().second;
+      DetElement   det0  = context.dependency.detector;
+      printout(INFO,"AlignmentUpdate","++ Building dependent condition: %s Detector [%d]: %s ",
+               key.name.c_str(), det0.level(), det0.path().c_str());
       if ( par0.typeInfo() == typeid(Delta) )  {
         const Delta& delta = src0.first<Delta>();
         data.delta         = delta;
         data.flag          = Data::HAVE_NONE;
       }
       else  {
-        printout(INFO,"AlignmentUpdate1","++ Failed to access alignment-Delta from %s",
+        printout(INFO,"AlignmentUpdate","++ Failed to access alignment-Delta from %s",
                  cond0->value.c_str());
         _Printer()(cond0);
       }
+      data.detector = context.dependency.detector;
       //data.condition   = target;
       return target;
     }
   };
-  /// Specialized conditions update callback for alignments
-  /**
-   *  Used by clients to update a condition.
-   *
-   *  \author  M.Frank
-   *  \version 1.0
-   *  \ingroup DD4HEP_CONDITIONS
-   */
-  class AlignmentUpdate2 : public ConditionUpdateCall, public AlignmentTypes  {
-  public:
-    AlignmentUpdate2()          {    }
-    virtual ~AlignmentUpdate2() {    }
-    /// Interface to client Callback in order to update the condition
-    virtual Condition operator()(const ConditionKey& key, const Context& context)  {
-      printout(INFO,"AlignmentUpdate2","++ Building dependent condition: %s",key.name.c_str());
-      Condition     target(key.name,"Alignment");
-      Data&         data  = target.bind<Data>();
-      Condition     cond0 = context.condition(0);
-      const Map&    src0  = cond0.get<Map>();      
-      const Param&  par0  = src0.firstParam().second;
 
-      if ( par0.typeInfo() == typeid(Delta) )  {
-        const Delta& delta0 = src0.first<Delta>();
-        const Data&  delta1 = context.get<Data>(1);
-        data.delta          = delta0;
-        data.delta          = delta1.delta;
-        data.flag           = Data::HAVE_NONE;
-      }
-      else  {
-        printout(INFO,"AlignmentUpdate2","++ Failed to access alignment-Delta from %s",
-                 cond0->value.c_str());
-        _Printer()(cond0);
-      }
-      //data.condition   = target;
-      return target;
+  void __print(DetElement det,
+               UserData& data,
+               int level)
+  {
+    char fmt[128];
+    auto i=data.keys.find(det.key());
+    const char* has_alignment = i==data.keys.end() ? "NO " : "YES";
+    size_t siz =  i==data.keys.end() ? 0 : 1;
+    ::snprintf(fmt,sizeof(fmt),"%%d %%%ds %%p [%%d] %%s %%08X: %%s ",2*level);
+    printout(INFO,"Conditions",fmt,
+             det.level(), "", det.ptr(), siz, has_alignment,
+             det.key(), det.path().c_str());
+    const DetElement::Children& children = det.children();
+    for(auto c=children.begin(); c!=children.end(); ++c)    {
+      DetElement child = (*c).second;
+      __print(child, data, level+1);
     }
-  };
-  /// Specialized conditions update callback for alignments
-  /**
-   *  Used by clients to update a condition.
-   *
-   *  \author  M.Frank
-   *  \version 1.0
-   *  \ingroup DD4HEP_CONDITIONS
-   */
-  class AlignmentUpdate3 : public ConditionUpdateCall, public AlignmentTypes  {
-  public:
-    AlignmentUpdate3()          {    }
-    virtual ~AlignmentUpdate3() {    }
-    /// Interface to client Callback in order to update the condition
-    virtual Condition operator()(const ConditionKey& key, const Context& context)  {
-      printout(INFO,"AlignmentUpdate3","++ Building dependent condition: %s",key.name.c_str());
-      Condition    target(key.name,"Alignment");
-      Data&        data  = target.bind<Data>();
-      Condition    cond0 = context.condition(0);
-      const Map&   src0  = cond0.get<Map>();
-      const Param& par0  = src0.firstParam().second;
-
-      if ( par0.typeInfo() == typeid(Delta) )  {
-        const Delta& delta0 = src0.first<Delta>();
-        const Data&  delta1 = context.get<Data>(1);
-        const Data&  delta2 = context.get<Data>(2);
-        data.delta          = delta0;
-        data.delta          = delta1.delta;
-        data.delta          = delta2.delta;
-        data.flag           = Data::HAVE_NONE;
-      }
-      else  {
-        printout(INFO,"AlignmentUpdate2","++ Failed to access alignment-Delta from %s",
-                 cond0->value.c_str());
-        _Printer()(cond0);
-      }
-      //data.condition = target;
-      return target;
-    }
-  };
-
+  }
+  
   /// DDDB Conditions analyser to select alignments.
   /**
    *   \author  M.Frank
@@ -191,17 +174,16 @@ namespace  {
     } m_counters;
 
     /// Initializing constructor
-    AlignmentSelector(ConditionsAccess mgr) : m_manager(mgr) {
+    AlignmentSelector(ConditionsAccess mgr) : m_manager(mgr)    {
       Operators::collectAllConditions(mgr, m_allConditions);
     }
 
     virtual ~AlignmentSelector()   {
-      destroyObjects(m_allDependencies);
+      m_allDependencies.clear();
     }
 
     void addDependency(ConditionDependency* dependency)   {
-      const ConditionKey& key = dependency->target;
-      m_allDependencies.insert(make_pair(key.hash,dependency));
+      m_allDependencies.insert(dependency->target.hash, dependency);
     }
 
     RangeConditions findCond(const string& match)   {
@@ -225,7 +207,9 @@ namespace  {
       }
       return result;
     }
-    long collectDependencies(DetElement de, int level)  {
+
+    AlignmentUpdate* m_update;
+    long collectDependencies(DetElement de, AlignmentUpdate* update, int level)  {
       char fmt[64], text[256];
       DDDB::Catalog* cat = 0;
       DDDB::ConditionPrinter prt;
@@ -246,33 +230,14 @@ namespace  {
                    rc.empty() ? (cat->condition+"  !!!UNRESOLVED!!!").c_str() : cat->condition.c_str());
           if ( !rc.empty() )   {
             ConditionKey target1(cat->condition+"/derived_1");
-            ConditionKey target2(cat->condition+"/derived_2");
-            ConditionKey target3(cat->condition+"/derived_3");
-            DependencyBuilder build_1(target1, new AlignmentUpdate1());
-            DependencyBuilder build_2(target2, new AlignmentUpdate2());
-            DependencyBuilder build_3(target3, new AlignmentUpdate3());
-
+            DependencyBuilder build_1(target1, update->addRef());
             build_1->detector = de;
-            build_2->detector = de;
-            build_3->detector = de;
             for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic)   {
-              Condition cond = *ic;
-              ConditionKey       key(cond->value);
-              if ( cond->value.find("/dd/Conditions/Alignment/Velo/Detector10-01") != string::npos )  {
-                printout(INFO,m_name,fmt,"","Alignment--2:    ", cond->value.c_str());
-              }
+              Condition    cond = *ic;
+              ConditionKey key(cond->value);
               build_1.add(key);
-
-              build_2.add(key);
-              build_2.add(target1);
-
-              build_3.add(key);
-              build_3.add(target1);
-              build_3.add(target2);
             }
             addDependency(build_1.release());
-            addDependency(build_2.release());
-            addDependency(build_3.release());
           }
           ++m_counters.numAlignments;
         }
@@ -283,7 +248,7 @@ namespace  {
         ++m_counters.numNoCatalogs;
       }
       for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i)
-        collectDependencies((*i).second,level+1);
+        collectDependencies((*i).second, update, level+1);
       return 1;
     }
 
@@ -296,20 +261,55 @@ namespace  {
       printout(INFO,"Conditions",
                "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s",
                num_expired, iov.str().c_str());
+      
+      UserData data;
+      data.entries.reserve(dependencies.size());
+      dependencies.for_each(DependencyCollector<UserData,_Oper>(data,_Oper()));
+
+      string prev("-----");
+      for(auto i=data.detectors.begin(); i!=data.detectors.end(); ++i)  {
+        Entry& e = data.entries[(*i).second];
+        DetElement    det = e.det;
+        unsigned int  key = det.key();
+        const string& p   = (*i).first;
+        size_t idx = p.find(prev);
+        if ( idx == 0 )  {
+          //printout(INFO,"Conditions","***** %d %p %08X: %s ",
+          //         det.level(), det.ptr(), key, det.path().c_str());
+          continue;
+        }
+        prev = p;
+        printout(INFO,"Conditions","%d %p %08X: %s ",
+                 det.level(), det.ptr(), key, det.path().c_str());
+        e.top = 1;
+      }
+
+      printout(INFO,"Conditions","Working down the tree....");
+      for(auto i=data.detectors.begin(); i!=data.detectors.end(); ++i)  {
+        Entry& e = data.entries[(*i).second];
+        if ( e.top )  {
+          DetElement det = e.det;
+          printout(INFO,"Conditions","%d %p %08X: %s ",
+                   det.level(), det.ptr(), det.key(), det.path().c_str());
+          __print(det, data, 0);
+        }
+      }
       user_pool->clear();
       return 1;
     }
   };
 
   /// Plugin function
-  long dddb_derived_alignments(LCDD& lcdd, int , char** argv) {
-    long init_time = *(long*)argv[0];
+  long dddb_derived_alignments(LCDD& lcdd, int argc, char** argv) {
+    long int long init_time = argc>0 ? *(long*)argv[0] : 0;//DDDB::DDDBReader::makeTime(2016,4,1,12);
     ConditionsManager manager = ConditionsManager::from(lcdd);
     AlignmentSelector selector(manager);
-    int ret = selector.collectDependencies(lcdd.world(), 0);
+    AlignmentUpdate* update = new AlignmentUpdate();
+    int ret = selector.collectDependencies(lcdd.world(), update, 0);
     if ( ret == 1 )  {
       ret = selector.computeDependencies(init_time);
     }
+    delete update;
     return ret;
   }
 } /* End anonymous namespace  */
diff --git a/DDDB/src/DDDBConversion.cpp b/DDDB/src/DDDBConversion.cpp
index 92c4af429..9772a9f7b 100644
--- a/DDDB/src/DDDBConversion.cpp
+++ b/DDDB/src/DDDBConversion.cpp
@@ -50,31 +50,31 @@ namespace DD4hep  {
   /// Default destructor
   dddb::~dddb()   {
     // need to release heare all allocated resources.
-    releaseObjects(isotopes)();
-    releaseObjects(elements)();
-    releaseObjects(elementPaths)();
+    releaseObjects(isotopes);
+    releaseObjects(elements);
+    releaseObjects(elementPaths);
 
-    releaseObjects(materials)();
-    releaseObjects(materialPaths)();
+    releaseObjects(materials);
+    releaseObjects(materialPaths);
 
-    releaseObjects(shapes)();
+    releaseObjects(shapes);
 
-    releaseObjects(volumes)();
-    releaseObjects(volumePaths)();
+    releaseObjects(volumes);
+    releaseObjects(volumePaths);
 
-    releaseObjects(placements)();
-    releaseObjects(placementPaths)();
+    releaseObjects(placements);
+    releaseObjects(placementPaths);
 
-    releaseObjects(tabproperties)();
-    releaseObjects(tabpropertyPaths)();
+    releaseObjects(tabproperties);
+    releaseObjects(tabpropertyPaths);
 
     conditions.clear();
     conditionPaths.clear();
-    //releaseObjects(conditions)();
-    //releaseObjects(conditionPaths)();
-    releaseObjects(catalogs)();
-    releaseObjects(catalogPaths)();
-    releaseObjects(documents)();
+    //releaseObjects(conditions);
+    //releaseObjects(conditionPaths);
+    releaseObjects(catalogs);
+    releaseObjects(catalogPaths);
+    releaseObjects(documents);
     printout(DEBUG,"dddb","++ All intermediate objects deleted!");
     InstanceCount::decrement(this);
   }
diff --git a/DDDB/src/DDDBDerivedCondTest.cpp b/DDDB/src/DDDBDerivedCondTest.cpp
index aea3c4a4d..2047ded71 100644
--- a/DDDB/src/DDDBDerivedCondTest.cpp
+++ b/DDDB/src/DDDBDerivedCondTest.cpp
@@ -196,12 +196,11 @@ namespace  {
     }
 
     virtual ~ConditionsSelector()   {
-      destroyObjects(m_allDependencies);
+      m_allDependencies.clear();
     }
 
     void addDependency(ConditionDependency* dependency)   {
-      const ConditionKey& key = dependency->target;
-      m_allDependencies.insert(make_pair(key.hash,dependency));
+      m_allDependencies.insert(dependency->target.hash, dependency);
     }
 
     RangeConditions findCond(const string& match)   {
diff --git a/DDDB/src/DDDBExecutor.cpp b/DDDB/src/DDDBExecutor.cpp
index 9ccd832f2..ce956d869 100644
--- a/DDDB/src/DDDBExecutor.cpp
+++ b/DDDB/src/DDDBExecutor.cpp
@@ -146,10 +146,17 @@ static long load_xml_dddb(Geometry::LCDD& lcdd, int argc, char** argv) {
     /// Pre-Process Parameters
     if ( !params.empty() )    {
       const void* args[] = {0, params.c_str(), 0};
-      printout(INFO,"DDDBExecutor","++ Pre-processing parameters: %s",params.c_str());
+      printout(INFO,"DDDBExecutor","++ Processing parameters: %s",params.c_str());
       result = lcdd.apply("DDDB_Loader", 2, (char**)args);
       check_result(result);
-      printout(INFO,"DDDBExecutor","                         .... done");
+    }
+
+    /// Process visualization attributes. Must be present before converting the geometry!
+    if ( !attr.empty() )  {
+      const void* args[] = {attr.c_str(), 0};
+      printout(INFO,"DDDBExecutor","+++ Processing visualization attributes: %s", attr.c_str());
+      result = lcdd.apply("DD4hepXMLLoader", 1, (char**)args);
+      check_result(result);
     }
 
     /// Process XML
@@ -188,12 +195,6 @@ static long load_xml_dddb(Geometry::LCDD& lcdd, int argc, char** argv) {
         lcdd.apply(executors[i].c_str(), 0, 0);
     }
 
-    if ( !attr.empty() )  {
-      const void* args[] = {attr.c_str(), 0};
-      printout(INFO,"DDDBExecutor","+++ Processing attrs: %s", attr.c_str());
-      result = lcdd.apply("DD4hepXMLLoader", 1, (char**)args);
-      check_result(result);
-    }
     if ( dump )    {
       printout(INFO,"DDDBExecutor","------------------> Conditions dump:");
       lcdd.apply("DDDB_DetectorConditionDump", 0, 0);
diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp
index 68fd46944..0c6bcda77 100644
--- a/DDG4/plugins/Geant4EventReaderHepMC.cpp
+++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp
@@ -598,8 +598,8 @@ bool HepMC::EventStream::ok()  const   {
 }
 
 void HepMC::EventStream::clear()   {
-  releaseObjects(m_vertices)();
-  releaseObjects(m_particles)();
+  releaseObjects(m_vertices);
+  releaseObjects(m_particles);
 }
 
 bool HepMC::EventStream::read()   {
@@ -608,8 +608,8 @@ bool HepMC::EventStream::read()   {
   static int num_evt = 0;
   int num_line = 0, num_line_accepted = 0;
 
-  releaseObjects(vertices())();
-  releaseObjects(particles())();
+  releaseObjects(vertices());
+  releaseObjects(particles());
 
   ++num_evt;
   if ( num_evt == 998 )  {
@@ -720,8 +720,8 @@ bool HepMC::EventStream::read()   {
     continue;
   Skip:
     printout(WARNING,"HepMC::EventStream","+++ Skip event with ID: %d",this->header.id);
-    releaseObjects(vertices())();
-    releaseObjects(particles())();
+    releaseObjects(vertices());
+    releaseObjects(particles());
     read_until_event_end(instream);
     event_read = false;
     if ( instream.eof() ) return false;
@@ -730,6 +730,6 @@ bool HepMC::EventStream::read()   {
   if( not instream.good() ) return false;
  Done:
   fix_particles(info);
-  releaseObjects(vertices())();
+  releaseObjects(vertices());
   return true;
 }
diff --git a/DDG4/src/Geant4Kernel.cpp b/DDG4/src/Geant4Kernel.cpp
index 2d303ad6c..5e5b6fe29 100644
--- a/DDG4/src/Geant4Kernel.cpp
+++ b/DDG4/src/Geant4Kernel.cpp
@@ -118,10 +118,10 @@ Geant4Kernel::~Geant4Kernel() {
   if ( this == s_main_instance.get() )   {
     s_main_instance.release();
   }
-  destroyObjects(m_workers)();
+  destroyObjects(m_workers);
   if ( isMaster() )  {
-    releaseObjects(m_globalFilters)();
-    releaseObjects(m_globalActions)();
+    releaseObjects(m_globalFilters);
+    releaseObjects(m_globalActions);
   }
   destroyPhases();
   deletePtr(m_runManager);
@@ -307,8 +307,8 @@ int Geant4Kernel::terminate() {
     Geant4Exec::terminate(*this);
   }
   destroyPhases();
-  for_each(m_globalFilters.begin(), m_globalFilters.end(), releaseObjects(m_globalFilters));
-  for_each(m_globalActions.begin(), m_globalActions.end(), releaseObjects(m_globalActions));
+  releaseObjects(m_globalFilters);
+  releaseObjects(m_globalActions);
   if ( ptr == this )  {
     deletePtr  (m_runManager);
   }
@@ -445,5 +445,5 @@ bool Geant4Kernel::removePhase(const std::string& nam) {
 
 /// Destroy all phases. To be called only at shutdown
 void Geant4Kernel::destroyPhases() {
-  for_each(m_phases.begin(), m_phases.end(), destroyObjects(m_phases));
+  destroyObjects(m_phases);
 }
diff --git a/DDG4/src/Geant4Particle.cpp b/DDG4/src/Geant4Particle.cpp
index 3cd0405aa..217334f73 100644
--- a/DDG4/src/Geant4Particle.cpp
+++ b/DDG4/src/Geant4Particle.cpp
@@ -398,7 +398,7 @@ Geant4ParticleMap::~Geant4ParticleMap()    {
 
 /// Clear particle maps
 void Geant4ParticleMap::clear()    {
-  releaseObjects(particleMap)();
+  releaseObjects(particleMap);
   particleMap.clear();
   equivalentTracks.clear();
 }
diff --git a/DDG4/src/Geant4ParticleHandler.cpp b/DDG4/src/Geant4ParticleHandler.cpp
index 3d022eac7..bca44ea9f 100644
--- a/DDG4/src/Geant4ParticleHandler.cpp
+++ b/DDG4/src/Geant4ParticleHandler.cpp
@@ -104,7 +104,7 @@ bool Geant4ParticleHandler::adopt(Geant4Action* action)    {
 
 /// Clear particle maps
 void Geant4ParticleHandler::clear()  {
-  releaseObjects(m_particleMap)();
+  releaseObjects(m_particleMap);
   m_particleMap.clear();
   m_equivalentTracks.clear();
 }
diff --git a/DDG4/src/Geant4Primary.cpp b/DDG4/src/Geant4Primary.cpp
index 48c177c87..147ff886b 100644
--- a/DDG4/src/Geant4Primary.cpp
+++ b/DDG4/src/Geant4Primary.cpp
@@ -33,7 +33,7 @@ PrimaryExtension::~PrimaryExtension() {
 
 /// Default destructor
 Geant4PrimaryMap::~Geant4PrimaryMap()   {
-  releaseObjects(m_primaryMap)();
+  releaseObjects(m_primaryMap);
 }
 
 /// Add a new object pair (G4 primary particle, DDG4 particle) into the maps
@@ -73,8 +73,8 @@ Geant4PrimaryInteraction& Geant4PrimaryInteraction::operator=(const Geant4Primar
 
 /// Default destructor
 Geant4PrimaryInteraction::~Geant4PrimaryInteraction()   {
-  releaseObjects(vertices)();
-  releaseObjects(particles)();
+  releaseObjects(vertices);
+  releaseObjects(particles);
 }
 
 /// Access a new particle identifier within the interaction
@@ -120,7 +120,7 @@ Geant4PrimaryEvent& Geant4PrimaryEvent::operator=(const Geant4PrimaryEvent& c)
 
 /// Default destructor
 Geant4PrimaryEvent::~Geant4PrimaryEvent()   {
-  destroyObjects(m_interactions)();
+  destroyObjects(m_interactions);
 }
 
 /// Add a new interaction object to the event
diff --git a/DDG4/src/Geant4SensDetAction.cpp b/DDG4/src/Geant4SensDetAction.cpp
index 8d431d65c..4bcb41bf3 100644
--- a/DDG4/src/Geant4SensDetAction.cpp
+++ b/DDG4/src/Geant4SensDetAction.cpp
@@ -402,7 +402,7 @@ Geant4SensDetSequences::Geant4SensDetSequences() {
 
 /// Default destructor
 Geant4SensDetSequences::~Geant4SensDetSequences() {
-  for_each(m_sequences.begin(), m_sequences.end(), releaseObjects(m_sequences));
+  releaseObjects(m_sequences);
   m_sequences.clear();
 }
 
diff --git a/DDG4/src/Geant4UIMessenger.cpp b/DDG4/src/Geant4UIMessenger.cpp
index 44b872b44..b61f29781 100644
--- a/DDG4/src/Geant4UIMessenger.cpp
+++ b/DDG4/src/Geant4UIMessenger.cpp
@@ -55,8 +55,8 @@ Geant4UIMessenger::Geant4UIMessenger(const string& name, const string& path)
 
 /// Default destructor
 Geant4UIMessenger::~Geant4UIMessenger() {
-  for_each(m_propertyCmd.begin(), m_propertyCmd.end(), destroyFirst(m_propertyCmd));
-  for_each(m_actionCmd.begin(), m_actionCmd.end(), destroyFirst(m_actionCmd));
+  destroyFirst(m_propertyCmd);
+  destroyFirst(m_actionCmd);
 }
 
 /// Add a new callback structure
diff --git a/examples/DDDB/scripts/extract_dddb.sh b/examples/DDDB/scripts/extract_dddb.sh
index 85c4b0364..4008be383 100755
--- a/examples/DDDB/scripts/extract_dddb.sh
+++ b/examples/DDDB/scripts/extract_dddb.sh
@@ -68,7 +68,9 @@ if test ! -f ${source}; then
     dir=`dirname ${source}`;
     source=${dir}/data/${base};
 fi;
+#
 # Now do the installation
+#
 if test -d ${target}/DDDB; then
     if test "${clean}" = "YES";then
         rm -rf ${target}/DDDB;
@@ -78,10 +80,10 @@ if test -d ${target}/DDDB; then
     echo "DDDB database is already extracted to ${target}. Nothing to do.";
 elif test ! -f ${source}; then
     echo "DDDB database tar file ${source} is not present. [Installation FAILED]";
-    echo "Directory: /builds/CLICdp/DD4hep/examples/DDDB";
-    ls -laF /builds/CLICdp/DD4hep/examples/DDDB;
-    echo "Directory /builds/CLICdp/DD4hep/examples/DDDB/data";
-    ls -laF /builds/CLICdp/DD4hep/examples/DDDB/data;
+    #echo "Directory: /builds/CLICdp/DD4hep/examples/DDDB";
+    #ls -laF /builds/CLICdp/DD4hep/examples/DDDB;
+    #echo "Directory /builds/CLICdp/DD4hep/examples/DDDB/data";
+    #ls -laF /builds/CLICdp/DD4hep/examples/DDDB/data;
     exit 2;  # ENOENT
 else
     mkdir -p ${target}/DDDB;
diff --git a/examples/DDDB/scripts/run_dddb.sh b/examples/DDDB/scripts/run_dddb.sh
index b563e7f50..cf4779488 100755
--- a/examples/DDDB/scripts/run_dddb.sh
+++ b/examples/DDDB/scripts/run_dddb.sh
@@ -20,14 +20,14 @@ echo "|   Starting DDDB plugin executor....                               |";
 #echo "|                                                                   |";
 echo "+ ------------------------------------------------------------------+";
 #
-if test -n "$USER"; then
-    target=/tmp/$USER;
-else
+# Check for arguments:
+if test -z "${DDDB_DIR}"; then
     target=/tmp;
+    if test -n "$USER"; then
+        target=/tmp/$USER;
+    fi;
+    DDDB_DIR=${target}/DDDB;
 fi;
-#
-# Check for arguments:
-DDDB_DIR=${target}/DDDB;
 loader="-loader DDDB_FileReader";
 params="-params file:${DDDB_DIR}/Parameters.xml";
 input="-input file:${DDDB_DIR}/DDDB/lhcb.xml";
@@ -80,6 +80,7 @@ while [[ "$1" == -* ]]; do
 done;
 #
 #
-ARGS=`echo -plugin DDDB_Executor ${loader} ${params} ${input} ${config} ${exec} ${vis}`
-echo "Command: ${debug} `which geoPluginRun` $ARGS";
-${debug} `which geoPluginRun` ${ARGS};
+export DD4HEP_TRACE=ON;
+ARGS=`echo -plugin DDDB_Executor ${loader} ${params} ${input} ${config} ${exec} ${vis}`;
+echo "Command: ${debug} `which geoPluginRun` -destroy $ARGS";
+${debug} `which geoPluginRun` -destroy ${ARGS};
-- 
GitLab