From 4cd9beb07e74beb87befddb08aebc29e713d07e2 Mon Sep 17 00:00:00 2001
From: Astrid Munnich <astrid.muennich@cern.ch>
Date: Thu, 4 Oct 2012 13:07:49 +0000
Subject: [PATCH] added user segmentation, needs fix by Markus for data
 extension

---
 .../ILDExDet/include/VersatileDiskRowLayout.h |  4 +--
 .../include/VersatileDiskRowLayoutSeg.h       | 36 ++++++++++---------
 .../ILDExDet/src/VersatileDiskRowLayout.cpp   | 10 ++++--
 .../src/VersatileDiskRowLayoutSeg.cpp         | 12 ++++---
 4 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/DDExamples/ILDExDet/include/VersatileDiskRowLayout.h b/DDExamples/ILDExDet/include/VersatileDiskRowLayout.h
index 858d718fd..47aedebaa 100644
--- a/DDExamples/ILDExDet/include/VersatileDiskRowLayout.h
+++ b/DDExamples/ILDExDet/include/VersatileDiskRowLayout.h
@@ -21,10 +21,9 @@ namespace DD4hep {
    
     Geometry::DetElement                module;
     Geometry::VersatileDiskRowLayoutSeg pads;
+    Geometry::VersatileDiskRowLayoutData *padData;
     Geometry::Tube                      tube;
     
-    void getExtension();
-    
     /// Default empty constructor
     VersatileDiskRowLayout() : module(), pads(), tube() {}
 
@@ -34,6 +33,7 @@ namespace DD4hep {
     /// Standard extension constructor. det is the NEW detector element e.g. when reflecting a detector
     VersatileDiskRowLayout(const VersatileDiskRowLayout& c,const Geometry::DetElement& det);
 
+       
     /// Default destructor
     virtual ~VersatileDiskRowLayout() {}
 
diff --git a/DDExamples/ILDExDet/include/VersatileDiskRowLayoutSeg.h b/DDExamples/ILDExDet/include/VersatileDiskRowLayoutSeg.h
index 435521ab5..443068d8e 100644
--- a/DDExamples/ILDExDet/include/VersatileDiskRowLayoutSeg.h
+++ b/DDExamples/ILDExDet/include/VersatileDiskRowLayoutSeg.h
@@ -16,30 +16,32 @@ namespace DD4hep {
   
   namespace Geometry  {
     
-
+    struct Row{
+      int _rowNumber;
+      int _nPads ;
+      double _padPitch;
+      double _rowHeight;
+      double _offset;
+    };
+    
+    struct VersatileDiskRowLayoutData{
+      VersatileDiskRowLayoutData(){};
+      void addRow(int nPads, double padPitch, double rowHeight, double offset);
+      int setRMin(int rmin);
+      std::vector<Row> _rows ;
+      int _rMin;
+      int _nPads;
+    };
+    
     struct VersatileDiskRowLayoutSeg : public Segmentation  {
-      // public:
       /// Constructor to be used when reading the already parsed object
       template <typename Q> VersatileDiskRowLayoutSeg(const Handle<Q>& e) : Segmentation(e) {}
       /// Constructor to create a new segmentation object
       VersatileDiskRowLayoutSeg();
-      void addRow(int nPads, double padPitch, double rowHeight, double offset);
-      int setRMin(int rmin);
-
-      //protected:
-      struct Row{
-	int _rowNumber;
-	int _nPads ;
-	double _padPitch;
-	double _rowHeight;
-	double _offset;
-      };
+    };
+      
       
-      std::vector<Row> _rows ;
-      int _rMin;
-      int _nPads;
       
-    };
   }//Geometry
 }//DD4hep
 
diff --git a/DDExamples/ILDExDet/src/VersatileDiskRowLayout.cpp b/DDExamples/ILDExDet/src/VersatileDiskRowLayout.cpp
index 3261b65be..5bf0443e1 100644
--- a/DDExamples/ILDExDet/src/VersatileDiskRowLayout.cpp
+++ b/DDExamples/ILDExDet/src/VersatileDiskRowLayout.cpp
@@ -12,6 +12,7 @@
 #include "TGeoTube.h"
 #include <math.h>
 #include <iostream>
+#include <cmath>
 
 using namespace std;
 
@@ -23,6 +24,7 @@ namespace DD4hep {
   VersatileDiskRowLayout::VersatileDiskRowLayout(const Geometry::DetElement& d) : module(d) {
     pads = module.readout().segmentation();
     tube = module.volume().solid();
+    padData = pads.extension<VersatileDiskRowLayoutData>();
   }
   
   /// Standard extension constructor. det is the NEW detector element e.g. when reflecting a detector
@@ -31,22 +33,24 @@ namespace DD4hep {
   {
     pads = module.readout().segmentation();
     tube = module.volume().solid();
+    padData = pads.extension<VersatileDiskRowLayoutData>();
   }
 
+
   std::string VersatileDiskRowLayout::getPadType()const {
     return pads.type();
   }
  
   int VersatileDiskRowLayout::getNPads()const {
-    return pads._nPads;
+    return padData->_nPads;
   }
   
   int VersatileDiskRowLayout::getNRows()const {
-    return pads._rows.size();
+    return padData->_rows.size();
   }
 
   int VersatileDiskRowLayout::getNPadsInRow(int row)const {
-    return pads._rows[row]._nPads;
+    return padData->_rows[row]._nPads;
   }
   
   double VersatileDiskRowLayout::getRowHeight(int row)const {
diff --git a/DDExamples/ILDExDet/src/VersatileDiskRowLayoutSeg.cpp b/DDExamples/ILDExDet/src/VersatileDiskRowLayoutSeg.cpp
index 52ef27f70..ea695597b 100644
--- a/DDExamples/ILDExDet/src/VersatileDiskRowLayoutSeg.cpp
+++ b/DDExamples/ILDExDet/src/VersatileDiskRowLayoutSeg.cpp
@@ -20,7 +20,7 @@ using namespace DD4hep::Geometry;
 VersatileDiskRowLayoutSeg::VersatileDiskRowLayoutSeg() 
   : Segmentation("VersatileDiskRowLayoutSeg")   {}
 
-void VersatileDiskRowLayoutSeg::addRow(int nPads, double padPitch, double rowHeight, double offset)
+void VersatileDiskRowLayoutData::addRow(int nPads, double padPitch, double rowHeight, double offset)
 {
   Row new_row;
   new_row._nPads=nPads;
@@ -28,11 +28,11 @@ void VersatileDiskRowLayoutSeg::addRow(int nPads, double padPitch, double rowHei
   new_row._rowHeight=rowHeight;
   new_row._offset=offset;
   _rows.push_back(new_row);
-  std::cout<<"Added row: "<<nPads<<" "<<padPitch<<std::endl;
+  std::cout<<"Added row: "<<nPads<<" "<<new_row._nPads<<std::endl;
   _nPads+=nPads;
 }
     
-int  VersatileDiskRowLayoutSeg::setRMin(int rmin)
+int  VersatileDiskRowLayoutData::setRMin(int rmin)
 {
   _rMin=rmin;
 }
@@ -40,11 +40,13 @@ int  VersatileDiskRowLayoutSeg::setRMin(int rmin)
 //factory to fill object from compact xml
 static Ref_t create_VersatileDiskRowLayoutSeg(lcdd_t& /* lcdd */, const xml_h& e)  {
   VersatileDiskRowLayoutSeg obj;
-  if ( e.hasAttr(_A(rmin))   ) obj.setRMin(e.attr<int>(_A(rmin)));
+  VersatileDiskRowLayoutData *dataExt=new VersatileDiskRowLayoutData();
+  if ( e.hasAttr(_A(rmin))   ) dataExt->setRMin(e.attr<int>(_A(rmin)));
   //loop rows to fill VersatileDiskRowLayoutSeg
   for(xml_coll_t r(e,_X(row)); r; ++r)  {
-    obj.addRow(r.attr<int>(_A(nPads)),r.attr<double>(_A(padPitch)),r.attr<double>(_A(rowHeight)),r.attr<double>(_A(offset)));
+    dataExt->addRow(r.attr<int>(_A(nPads)),r.attr<double>(_A(padPitch)),r.attr<double>(_A(rowHeight)),r.attr<double>(_A(offset)));
    }
+  obj.setExtension<VersatileDiskRowLayoutData>(dataExt);
   return obj;
 }
 DECLARE_XMLELEMENT(VersatileDiskRowLayoutSeg,create_VersatileDiskRowLayoutSeg);
-- 
GitLab