From 202d5329a3bf73ea9ce6b3fa2d51884188a20c1e Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Thu, 21 Feb 2013 09:09:53 +0000
Subject: [PATCH] Require strict checking for xml attribute existence

---
 .../CLICSiD/src/CylindricalBarrelCalorimeter_geo.cpp     | 5 ++++-
 .../CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp     | 8 +++++---
 DDExamples/CLICSiD/src/DiskTracker_geo.cpp               | 9 +++++++--
 DDExamples/CLICSiD/src/EcalBarrel_geo.cpp                | 5 ++++-
 DDExamples/CLICSiD/src/ForwardDetector_geo.cpp           | 5 ++++-
 DDExamples/CLICSiD/src/MultiLayerTracker_geo.cpp         | 9 +++++++--
 .../CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp      | 5 ++++-
 .../CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp      | 5 ++++-
 DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp           | 3 ++-
 DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp          | 3 ++-
 10 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/DDExamples/CLICSiD/src/CylindricalBarrelCalorimeter_geo.cpp b/DDExamples/CLICSiD/src/CylindricalBarrelCalorimeter_geo.cpp
index 298e6ef98..9f6bf3b5b 100644
--- a/DDExamples/CLICSiD/src/CylindricalBarrelCalorimeter_geo.cpp
+++ b/DDExamples/CLICSiD/src/CylindricalBarrelCalorimeter_geo.cpp
@@ -41,7 +41,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
 	Tube       slice_tube(r,router,z*2);
 	Volume     slice_vol (slice_name,slice_tube,slice_mat);
           
-	if ( x_slice.isSensitive() ) slice_vol.setSensitiveDetector(sens);
+	if ( x_slice.isSensitive() ) {
+	  sens.setType("calorimeter");
+	  slice_vol.setSensitiveDetector(sens);
+	}
 	r = router;
 	slice_vol.setAttributes(lcdd,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
 	// Instantiate physical volume
diff --git a/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp b/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp
index 02cab3aea..5d7fff3b0 100644
--- a/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp
+++ b/DDExamples/CLICSiD/src/CylindricalEndcapCalorimeter_geo.cpp
@@ -18,9 +18,9 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
   xml_dim_t  dim       = x_det.dimensions();
   Material   air       = lcdd.air();
   string     det_name  = x_det.nameStr();
+  bool       reflect   = x_det.reflect();
   Tube       envelope;
   Volume     envelopeVol(det_name,envelope,air);
-  bool       reflect   = x_det.reflect();
   double     zmin      = dim.inner_z();
   double     rmin      = dim.inner_r();
   double     rmax      = dim.outer_r();
@@ -45,8 +45,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
 	Material   slice_mat  = lcdd.material(x_slice.materialStr());
 	Volume     slice_vol (slice_name,Tube(rmin,rmax,w),slice_mat);
           
-	if ( x_slice.isSensitive() ) slice_vol.setSensitiveDetector(sens);
-          
+	if ( x_slice.isSensitive() )  {
+	  sens.setType("calorimeter");
+	  slice_vol.setSensitiveDetector(sens);
+	}
 	// Set attributes of slice
 	slice_vol.setAttributes(lcdd,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
 	layer_vol.placeVolume(slice_vol,Position(0,0,z-zlayer-layerWidth/2+w/2));
diff --git a/DDExamples/CLICSiD/src/DiskTracker_geo.cpp b/DDExamples/CLICSiD/src/DiskTracker_geo.cpp
index e582252e1..c75e004af 100644
--- a/DDExamples/CLICSiD/src/DiskTracker_geo.cpp
+++ b/DDExamples/CLICSiD/src/DiskTracker_geo.cpp
@@ -44,7 +44,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
       string s_nam = l_nam+_toString(s_num,"_slice%d");
       Volume s_vol(s_nam, Tube(rmin,rmax,thick), mat);
         
-      if ( x_slice.isSensitive() ) s_vol.setSensitiveDetector(sens);
+      if ( x_slice.isSensitive() ) {
+	sens.setType("tracker");
+	s_vol.setSensitiveDetector(sens);
+      }
       s_vol.setAttributes(lcdd,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
 
       PlacedVolume spv = l_vol.placeVolume(s_vol,Position(0,0,z-zmin-layerWidth/2+thick/2));
@@ -65,7 +68,9 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
       sdet.add(layerR.setPlacement(lpvR));
     }
   }
-  sdet.setCombineHits(x_det.attr<bool>(_A(combineHits)),sens);
+  if ( x_det.hasAttr(_A(combineHits)) ) {
+    sdet.setCombineHits(x_det.attr<bool>(_A(combineHits)),sens);
+  }
   return sdet;
 }
 
diff --git a/DDExamples/CLICSiD/src/EcalBarrel_geo.cpp b/DDExamples/CLICSiD/src/EcalBarrel_geo.cpp
index 9b5366896..fe1a2f23e 100644
--- a/DDExamples/CLICSiD/src/EcalBarrel_geo.cpp
+++ b/DDExamples/CLICSiD/src/EcalBarrel_geo.cpp
@@ -99,7 +99,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
 	  Volume     s_vol(det_name+"_"+l_name+"_"+s_name,s_box,lcdd.material(x_slice.materialStr()));
           DetElement slice(layer,s_name,det_id);
 
-          if ( x_slice.isSensitive() ) s_vol.setSensitiveDetector(sens);
+          if ( x_slice.isSensitive() ) {
+	    sens.setType("calorimeter");
+	    s_vol.setSensitiveDetector(sens);
+	  }
           slice.setAttributes(lcdd,s_vol,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
 
           // Slice placement.
diff --git a/DDExamples/CLICSiD/src/ForwardDetector_geo.cpp b/DDExamples/CLICSiD/src/ForwardDetector_geo.cpp
index 2148b3c6f..4d2652b10 100644
--- a/DDExamples/CLICSiD/src/ForwardDetector_geo.cpp
+++ b/DDExamples/CLICSiD/src/ForwardDetector_geo.cpp
@@ -122,7 +122,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
 	// Slice LV.
 	Volume sliceVol(det_name+"_"+layer_nam+"_"+slice_nam, sliceSubtraction2, slice_mat);
 
-	if ( x_slice.isSensitive() ) sliceVol.setSensitiveDetector(sens);
+	if ( x_slice.isSensitive() ) {
+	  sens.setType("tracker");
+	  sliceVol.setSensitiveDetector(sens);
+	}
 	// Set attributes of slice
 	slice.setAttributes(lcdd, sliceVol, x_slice.regionStr(), x_slice.limitsStr(), x_slice.visStr());
 
diff --git a/DDExamples/CLICSiD/src/MultiLayerTracker_geo.cpp b/DDExamples/CLICSiD/src/MultiLayerTracker_geo.cpp
index e95ffb3df..b0de7e053 100644
--- a/DDExamples/CLICSiD/src/MultiLayerTracker_geo.cpp
+++ b/DDExamples/CLICSiD/src/MultiLayerTracker_geo.cpp
@@ -41,7 +41,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
       Volume s_vol(s_name, s_tub, mat);
 
       r += thickness;
-      if ( x_slice.isSensitive() ) s_vol.setSensitiveDetector(sens);
+      if ( x_slice.isSensitive() ) {
+	sens.setType("tracker");
+	s_vol.setSensitiveDetector(sens);
+      }
       // Set Attributes
       s_vol.setAttributes(lcdd,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
       PlacedVolume spv = l_vol.placeVolume(s_vol,IdentityPos());
@@ -56,7 +59,9 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
     lpv.addPhysVolID("system",sdet.id()).addPhysVolID(_X(barrel),0);
     layer.setPlacement(lpv);
   }
-  sdet.setCombineHits(x_det.attr<bool>(_A(combineHits)),sens);
+  if ( x_det.hasAttr(_A(combineHits)) ) {
+    sdet.setCombineHits(x_det.attr<bool>(_A(combineHits)),sens);
+  }
   return sdet;
 }
 
diff --git a/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp b/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp
index 3c8bc4d6f..f9df0ac95 100644
--- a/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp
+++ b/DDExamples/CLICSiD/src/PolyhedraBarrelCalorimeter2_geo.cpp
@@ -124,7 +124,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
 	// Slice volume & box
 	Volume slice_vol(slice_name,Box(layer_dim_x,detZ/2,slice_thickness),slice_material);
 
-	if ( x_slice.isSensitive() ) slice_vol.setSensitiveDetector(sens);
+	if ( x_slice.isSensitive() ) {
+	  sens.setType("calorimeter");
+	  slice_vol.setSensitiveDetector(sens);
+	}
 	// Set region, limitset, and vis.
 	slice_vol.setAttributes(lcdd,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
 	// slice PlacedVolume
diff --git a/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp b/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp
index dc6d55406..92b05c089 100644
--- a/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp
+++ b/DDExamples/CLICSiD/src/PolyhedraEndcapCalorimeter2_geo.cpp
@@ -48,7 +48,10 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
       Material   s_mat   = lcdd.material(x_slice.materialStr());
       Volume     s_vol(s_name,PolyhedraRegular(numsides,rmin,rmax,s_thick),s_mat);
         
-      if ( x_slice.isSensitive() ) s_vol.setSensitiveDetector(sens);
+      if ( x_slice.isSensitive() )  {
+	sens.setType("calorimeter");
+	s_vol.setSensitiveDetector(sens);
+      }
       s_vol.setVisAttributes(lcdd.visAttributes(x_slice.visStr()));
       sliceZ += s_thick/2;
       PlacedVolume s_phv = l_vol.placeVolume(s_vol,Position(0,0,sliceZ));
diff --git a/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp b/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp
index fea62cf01..33ea5747e 100644
--- a/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp
+++ b/DDExamples/CLICSiD/src/SiTrackerBarrel_geo.cpp
@@ -25,7 +25,7 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
     xml_comp_t x_mod  = mi;
     xml_comp_t m_env  = x_mod.child(_X(module_envelope));
     string     m_nam  = x_mod.nameStr();
-    Volume     m_vol(m_nam,Box(m_env.width(),m_env.length(),m_env.thickness()),air);
+    Volume     m_vol(det_name+"_"+m_nam,Box(m_env.width(),m_env.length(),m_env.thickness()),air);
     DetElement m_elt(sdet, m_nam, det_id);
     int        ncomponents = 0, sensor_number = 0;
 
@@ -54,6 +54,7 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
 	c_phv = m_vol.placeVolume(c_vol);
       }
       if ( x_comp.isSensitive() ) {
+	sens.setType("tracker");
 	c_phv.addPhysVolID(_X(sensor),sensor_number++);
 	c_vol.setSensitiveDetector(sens);
       }
diff --git a/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp b/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp
index 48ce8a1e7..5d5a72210 100644
--- a/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp
+++ b/DDExamples/CLICSiD/src/SiTrackerEndcap2_geo.cpp
@@ -20,7 +20,7 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
   Material    vacuum    = lcdd.vacuum();
   int         det_id    = x_det.id();
   string      det_name  = x_det.nameStr();
-  bool        reflect   = x_det.reflect();
+  bool        reflect   = x_det.reflect(false);
   DetElement  sdet       (det_name,det_id);
   Volume      motherVol = lcdd.trackingVolume();
   int         m_id=0, c_id=0, n_sensor=0;
@@ -54,6 +54,7 @@ static Ref_t create_detector(LCDD& lcdd, const xml_h& e, SensitiveDetector& sens
       PlacedVolume phv = m_volume.placeVolume(vol,Position(0,posY+c_thick/2,0));
       phv.addPhysVolID(_X(component),c_id);
       if ( c.isSensitive() ) {
+	sens.setType("tracker");
 	sdet.check(n_sensor > 1,"SiTrackerEndcap2::fromCompact: "+c_name+" Max of 2 modules allowed!");
 	phv.addPhysVolID("sensor",c_id);
 	vol.setSensitiveDetector(sens);
-- 
GitLab