From 7940a1768a6802e225389ca283654aee78bbed30 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Thu, 1 Oct 2020 17:00:08 +0200
Subject: [PATCH] Fix to keep DetElement reference in the conditions dependency

---
 DDCond/src/plugins/ConditionsUserPool.cpp |  8 +++----
 DDCore/include/DD4hep/ConditionDerived.h  |  6 -----
 DDCore/include/DD4hep/config.h            |  8 +++----
 DDCore/src/ConditionDerived.cpp           | 28 ++---------------------
 DDCore/src/plugins/Compact2Objects.cpp    |  6 +++--
 5 files changed, 14 insertions(+), 42 deletions(-)

diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp
index 604107d4d..d98152a2a 100644
--- a/DDCond/src/plugins/ConditionsUserPool.cpp
+++ b/DDCond/src/plugins/ConditionsUserPool.cpp
@@ -244,12 +244,12 @@ template<typename MAPPING> inline bool
 ConditionsMappedUserPool<MAPPING>::i_insert(Condition::Object* o)   {
   int ret = m_conditions.emplace(o->hash,o).second;
   if ( flags&PRINT_INSERT )  {
-    printout(INFO,"UserPool","++ %s condition [%016llX]: %s [%s].",
-             ret ? "Successfully inserted" : "FAILED to insert", o->hash,
+    printout(INFO,"UserPool","++ %s condition [%016llX]"
 #if defined(DD4HEP_CONDITIONS_HAVE_NAME)
-             o->GetName(), o->GetTitle());
+             ": %s [%s].", ret ? "Successfully inserted" : "FAILED to insert",
+             o->hash, o->GetName(), o->GetTitle());
 #else
-    "", "");
+    , ret ? "Successfully inserted" : "FAILED to insert", o->hash);
 #endif
   }
   return ret;
diff --git a/DDCore/include/DD4hep/ConditionDerived.h b/DDCore/include/DD4hep/ConditionDerived.h
index 4993b68aa..a0818bb6c 100644
--- a/DDCore/include/DD4hep/ConditionDerived.h
+++ b/DDCore/include/DD4hep/ConditionDerived.h
@@ -316,10 +316,8 @@ namespace dd4hep {
       int                                  m_refCount {0};
 
     public:
-#ifdef DD4HEP_CONDITIONS_DEBUG
       /// Reference to the target's detector element
       DetElement                           detector;
-#endif
       /// Key to the condition to be updated
       ConditionKey                         target {0};
       /// Dependency keys this condition depends on
@@ -336,14 +334,10 @@ namespace dd4hep {
       virtual ~ConditionDependency();
 
     public:
-      /// Initializing constructor used by builder
-      ConditionDependency(Condition::key_type key, std::shared_ptr<ConditionUpdateCall> call);
       /// Initializing constructor used by builder
       ConditionDependency(DetElement de, const std::string& item, std::shared_ptr<ConditionUpdateCall> call);
       /// Initializing constructor used by builder
       ConditionDependency(DetElement de, Condition::itemkey_type item_key, std::shared_ptr<ConditionUpdateCall> call);
-      /// Initializing constructor used by builder
-      ConditionDependency(Condition::detkey_type det_key, Condition::itemkey_type item_key, std::shared_ptr<ConditionUpdateCall> call);
       /// Default constructor
       ConditionDependency();
       /// Access the dependency key
diff --git a/DDCore/include/DD4hep/config.h b/DDCore/include/DD4hep/config.h
index c7b6c3610..e549bc7c5 100644
--- a/DDCore/include/DD4hep/config.h
+++ b/DDCore/include/DD4hep/config.h
@@ -23,14 +23,14 @@
 #define DD4HEP_CONDITIONS_DEBUG     1
 #endif
 
-#if !defined(DD4HEP_CONDITIONS_DEBUG)
+#if defined(DD4HEP_CONDITIONS_DEBUG)
+/// Enable flag to store conditions names to keys (needs some support from user code!)
+#define DD4HEP_CONDITIONS_HAVE_NAME 1
+#else
 /// Enable this if you want to minimize the footprint of conditions
 #define DD4HEP_MINIMAL_CONDITIONS   1
 #endif
 
-/// Enable flag to store conditions names to keys (needs some support from user code!)
-#define DD4HEP_CONDITIONS_HAVE_NAME 1
-
 /// Valid implementations of the Gaudi plugin service are 1 and 2
 #define DD4HEP_PLUGINSVC_VERSION    2
 
diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp
index d1ac19fa8..59b877205 100644
--- a/DDCore/src/ConditionDerived.cpp
+++ b/DDCore/src/ConditionDerived.cpp
@@ -131,32 +131,11 @@ void ConditionUpdateContext::accessFailure(const ConditionKey& key_value)  const
 #endif
 }
 
-/// Initializing constructor
-ConditionDependency::ConditionDependency(Condition::key_type  key,
-                                         std::shared_ptr<ConditionUpdateCall> call)
-  : m_refCount(0), target(key), callback(std::move(call))
-{
-  InstanceCount::increment(this);
-}
-
-/// Initializing constructor
-ConditionDependency::ConditionDependency(Condition::detkey_type det_key,
-                                         Condition::itemkey_type item_key,
-                                         std::shared_ptr<ConditionUpdateCall> call)
-  : m_refCount(0), target(det_key, item_key), callback(std::move(call))
-{
-  InstanceCount::increment(this);
-}
-
 /// Initializing constructor
 ConditionDependency::ConditionDependency(DetElement              de,
                                          Condition::itemkey_type item_key,
                                          std::shared_ptr<ConditionUpdateCall> call)
-  : m_refCount(0), 
-#ifdef DD4HEP_CONDITIONS_DEBUG
-  detector(de),
-#endif
-  target(de, item_key), callback(std::move(call))
+  : m_refCount(0), detector(de), target(de, item_key), callback(std::move(call))
 {
   InstanceCount::increment(this);
 }
@@ -166,10 +145,7 @@ ConditionDependency::ConditionDependency(DetElement de,
                                          const std::string&   item, 
                                          std::shared_ptr<ConditionUpdateCall> call)
   : 
-#ifdef DD4HEP_CONDITIONS_DEBUG
-  detector(de),
-#endif
-  target(de, item), callback(std::move(call))
+  detector(de), target(de, item), callback(std::move(call))
 {
   InstanceCount::increment(this);
 }
diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp
index 4cc038079..ac8d6948c 100644
--- a/DDCore/src/plugins/Compact2Objects.cpp
+++ b/DDCore/src/plugins/Compact2Objects.cpp
@@ -1517,11 +1517,13 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,17,0)
   /// These two must be parsed early, because they are needed by the detector constructors
   xml_coll_t(compact, _U(properties)).for_each(_U(constant), Converter<PropertyConstant>(description));
-  xml_coll_t(compact, _U(properties)).for_each(_U(matrix), Converter<PropertyTable>(description));
+  xml_coll_t(compact, _U(properties)).for_each(_U(matrix),   Converter<PropertyTable>(description));
+  xml_coll_t(compact, _U(properties)).for_each(_U(plugin),   Converter<Plugin> (description));
   xml_coll_t(compact, _U(surfaces)).for_each(_U(opticalsurface), Converter<OpticalSurface>(description));
 #endif
-  xml_coll_t(compact, _U(materials)).for_each(_U(element), Converter<Atom>(description));
+  xml_coll_t(compact, _U(materials)).for_each(_U(element),  Converter<Atom>(description));
   xml_coll_t(compact, _U(materials)).for_each(_U(material), Converter<Material>(description));
+  xml_coll_t(compact, _U(materials)).for_each(_U(plugin),   Converter<Plugin> (description));
   
   xml_coll_t(compact, _U(display)).for_each(_U(include), Converter<DetElementInclude>(description));
   xml_coll_t(compact, _U(display)).for_each(_U(vis), Converter<VisAttr>(description));
-- 
GitLab