From 9c14bf22d20c508d7ad2b90ca04f34080f49a85c Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Wed, 1 Apr 2015 12:32:06 +0000
Subject: [PATCH] 1st. trial to fix system ID problem

---
 DDCore/include/DD4hep/Memory.h              |  8 +++-
 DDDetectors/src/SubdetectorAssembly_geo.cpp | 45 ++++++++-------------
 2 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/DDCore/include/DD4hep/Memory.h b/DDCore/include/DD4hep/Memory.h
index 511802878..175cee294 100644
--- a/DDCore/include/DD4hep/Memory.h
+++ b/DDCore/include/DD4hep/Memory.h
@@ -36,7 +36,9 @@ namespace DD4hep  {
   : public std::auto_ptr<T>  {
  public:
     typedef std::auto_ptr<T> base_t;
-    void swap(base_t& c) { *this = c; c.release(); }
+    void swap(base_t& c) {
+      this->base_t::operator=(base_t(c.release()));
+    }
 #endif
     /// Default Constructor.
     dd4hep_ptr() : base_t() {}
@@ -46,7 +48,9 @@ namespace DD4hep  {
     dd4hep_ptr(base_t& c) : base_t(c) {}
     /// Assignment operator
     dd4hep_ptr& operator=(base_t& c) {
-      this->swap(c);
+      if ( this != &c )  {
+	this->swap(c);
+      }
       return *this;
     }
   };
diff --git a/DDDetectors/src/SubdetectorAssembly_geo.cpp b/DDDetectors/src/SubdetectorAssembly_geo.cpp
index e15f5225c..c8d30e68e 100644
--- a/DDDetectors/src/SubdetectorAssembly_geo.cpp
+++ b/DDDetectors/src/SubdetectorAssembly_geo.cpp
@@ -20,10 +20,10 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, Ref_t)  {
   DetElement sdet(det_name, x_det.id());
   Volume     vol;
 
-  bool useRot = false ;
-  bool usePos = false ; 
-  Position    pos ;
-  RotationZYX rot ;
+  bool useRot = false;
+  bool usePos = false; 
+  Position    pos;
+  RotationZYX rot;
 
   if ( x_det.hasChild(_U(shape)) )  {
     xml_comp_t x_shape = x_det.child(_U(shape));
@@ -32,14 +32,14 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, Ref_t)  {
     Material   mat   = lcdd.material(x_shape.materialStr());
     printout(DEBUG,det_name,"+++ Creating detector assembly with shape of type:%s",type.c_str());
     vol = Volume(det_name,solid,mat);
-    
-    if( x_shape.hasChild( _U(position) ) ) {
-      usePos = true ;
-      pos = Position(   x_shape.position().x() , x_shape.position().y(),   x_shape.position().z()    ) ;
+
+    usePos = x_shape.hasChild(_U(position));
+    useRot = x_shape.hasChild(_U(rotation));
+    if( usePos ) {
+      pos = Position(x_shape.position().x(), x_shape.position().y(), x_shape.position().z());
     }
-    if( x_shape.hasChild( _U(rotation) ) ) {
-      useRot = true ;
-      rot = RotationZYX(   x_shape.rotation().x() , x_shape.rotation().y(),   x_shape.rotation().z()    ) ;
+    if( useRot ) {
+      rot = RotationZYX(x_shape.rotation().x(), x_shape.rotation().y(), x_shape.rotation().z());
     }
   }
   else  {
@@ -55,30 +55,19 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, Ref_t)  {
 
   vol.setAttributes(lcdd,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
 
-  Volume mother = lcdd.pickMotherVolume(sdet) ;
-  PlacedVolume pv ;
-
+  Volume mother = lcdd.pickMotherVolume(sdet);
+  PlacedVolume pv;
   if( useRot && usePos ){
-
-    pv =  mother.placeVolume( vol , Transform3D( rot, pos )  ) ;
-
+    pv =  mother.placeVolume(vol, Transform3D(rot, pos));
   } else if( useRot ){
-
-    pv =  mother.placeVolume( vol , rot  ) ;
-
+    pv =  mother.placeVolume(vol, rot);
   } else if( usePos ){
-
-    pv =  mother.placeVolume( vol , pos  ) ;
-
+    pv =  mother.placeVolume(vol, pos);
   } else {
-
-    pv = mother.placeVolume( vol );
+    pv = mother.placeVolume(vol);
   }
 
-  pv.addPhysVolID("system", sdet.id() );
-  
   sdet.setPlacement(pv);
-  
   return sdet;
 }
 
-- 
GitLab