From 58318761537f380a9cc2527e69a0a61fce09137a Mon Sep 17 00:00:00 2001
From: scott snyder <sss@karma>
Date: Mon, 7 Sep 2020 11:04:05 -0400
Subject: [PATCH] PixelGeoModel: Fix cppcheck warnings.

 - Disable copy ctors/assignment for some classes that manage memory.
 - Pass class instances via const reference, not by value.
 - Prefer using an initialization list to initializing members
   in a ctor body.
 - Prefer preincrement to postincrement for iterators.
---
 .../PixelGeoModel/IBLParameterSvc.h           |  4 +-
 .../PixelGeoModel/src/GeoPixelLadder.h        |  2 +
 .../src/GeoPixelLadderServices.h              |  2 +
 .../PixelGeoModel/src/GeoPixelModule.h        |  2 +
 .../PixelGeoModel/src/GeoPixelServices.cxx    |  6 +-
 .../PixelGeoModel/src/GeoPixelServices.h      |  2 +
 .../PixelGeoModel/src/GeoPixelStaveRing.cxx   | 19 +++---
 .../PixelGeoModel/src/GeoPixelStaveRing.h     |  2 +-
 .../PixelGeoModel/src/PixelDetectorDC1DC2.h   |  8 +++
 .../PixelGeoModel/src/PixelLegacyManager.cxx  | 64 +++++++++----------
 10 files changed, 63 insertions(+), 48 deletions(-)

diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/IBLParameterSvc.h b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/IBLParameterSvc.h
index 2903a58153b3..fad9f407bf6a 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/IBLParameterSvc.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/PixelGeoModel/IBLParameterSvc.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -44,7 +44,7 @@ public:
     bool contains3D();
     bool containsDBM();
 
-    std::string setStringParameters(const std::string param,std::string paramName) {
+    std::string setStringParameters(const std::string& param,const std::string& paramName) {
         if (m_IBLpresent) {
 	      if (m_disableAllClusterSplitting && paramName=="clusterSplitter") return "";
         }
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadder.h b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadder.h
index 1c76a6bb9174..4acb8503d8d2 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadder.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadder.h
@@ -16,6 +16,8 @@ class GeoPixelLadder : public GeoVPixelFactory {
                  PixelGeometryManager* mgr,
                  GeoPixelSiCrystal& theSensor,
 		 GeoPixelStaveSupport * staveSupport);
+  GeoPixelLadder (const GeoPixelLadder&) = delete;
+  GeoPixelLadder& operator= (const GeoPixelLadder&) = delete;
 	virtual ~GeoPixelLadder();
   virtual GeoVPhysVol* Build() override;
   double thickness() const {return m_thickness;}
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadderServices.h b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadderServices.h
index c41b8a0b7bcd..9df24017125d 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadderServices.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelLadderServices.h
@@ -16,6 +16,8 @@ class GeoPixelLadderServices : public GeoVPixelFactory {
  public:
   GeoPixelLadderServices(InDetDD::PixelDetectorManager* ddmgr,
                          PixelGeometryManager* mgr ,int ladderType);
+  GeoPixelLadderServices (const GeoPixelLadderServices&) = delete;
+  GeoPixelLadderServices& operator= (const GeoPixelLadderServices&) = delete;
   virtual ~GeoPixelLadderServices();
   virtual GeoVPhysVol* Build() override;
   const GeoTrf::Vector3D & envelopeCornerA1() {return  m_envelopeCornerA1;}
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelModule.h b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelModule.h
index 61ab39540ffe..b49fd621fd09 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelModule.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelModule.h
@@ -15,6 +15,8 @@ class GeoPixelModule : public GeoVPixelFactory {
   GeoPixelModule(InDetDD::PixelDetectorManager* ddmgr,
                  PixelGeometryManager* mgr,
                  GeoPixelSiCrystal &theSensor);
+  GeoPixelModule (const GeoPixelModule&) = delete;
+  GeoPixelModule& operator= (const GeoPixelModule&) = delete;
   virtual ~GeoPixelModule();
   virtual GeoVPhysVol* Build() override;
   double Thickness();
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.cxx b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.cxx
index 1fc2a31482f6..ca78c00469db 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.cxx
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.cxx
@@ -211,7 +211,7 @@ GeoPixelServices::GeoPixelServices(InDetDD::PixelDetectorManager* ddmgr,
     std::vector<const InDetDD::ServiceVolume *> servicesOther;
     double safety=0.001*Gaudi::Units::mm;
 
-    for(std::vector<const InDetDD::ServiceVolume *>::const_iterator it=services.begin(); it!=services.end(); it++)
+    for(std::vector<const InDetDD::ServiceVolume *>::const_iterator it=services.begin(); it!=services.end(); ++it)
       {
 	const std::string volName=(*it)->volName();
 	if(volName.find("BarrelStrip")!=std::string::npos){
@@ -384,7 +384,9 @@ void GeoPixelServices::initializeOld(const std::string & a)
     param.setVolName(m_gmt_mgr->PixelServiceName(a, ii));
 
     double zShift=0.;           // the famous IBL Z shift
-    int iShiftIndex = m_gmt_mgr->PixelServiceShift(a, ii); 
+    int iShiftIndex = m_gmt_mgr->PixelServiceShift(a, ii);
+    // FIXME: The magic number 100 here should be explained...
+    // cppcheck-suppress negativeContainerIndex
     if(iShiftIndex>0) zShift=m_layerShift[iShiftIndex-100];
     param.setZShift(zShift);
 
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.h b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.h
index 403525a02faf..fc14e61cbd0e 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelServices.h
@@ -18,6 +18,8 @@ class GeoPixelServices : public GeoVPixelFactory {
 public:
   GeoPixelServices(InDetDD::PixelDetectorManager* ddmgr,
                    PixelGeometryManager* mgr, InDetDD::Zone * envelopeZone = 0);
+  GeoPixelServices (const GeoPixelServices&) = delete;
+  GeoPixelServices& operator= (const GeoPixelServices&) = delete;
   ~GeoPixelServices();
   virtual GeoVPhysVol* Build() override;
   void initialize(const std::string &);
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.cxx b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.cxx
index 69563f514db1..5448e1c9d715 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.cxx
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.cxx
@@ -25,19 +25,18 @@ using namespace std;
 
 GeoPixelStaveRing::GeoPixelStaveRing(InDetDD::PixelDetectorManager* ddmgr,
                                      PixelGeometryManager* mgr)
-  : GeoVPixelFactory (ddmgr, mgr)
+  : GeoVPixelFactory (ddmgr, mgr),
+    m_physVol (nullptr),
+    m_zPosition (0),
+    m_innerRadius (0),
+    m_outerRadius (0),
+    m_ringPosition ("AC"),
+    m_ringName ("staveRing")
 {
-  m_ringName="staveRing";
-  m_ringPosition="AC";
-  
-  m_zPosition =0;
-  m_innerRadius = 0.;
-  m_outerRadius = 0.;
-
-  m_physVol = 0;
 }
 
-GeoVPhysVol* GeoPixelStaveRing::SetParametersAndBuild(std::string ringName, std::string ringPos)
+GeoVPhysVol* GeoPixelStaveRing::SetParametersAndBuild(const std::string& ringName,
+                                                      const std::string& ringPos)
 {
   m_ringName=ringName;
   m_ringPosition=ringPos;
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.h b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.h
index 91804ec4981a..74edff8c7777 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/GeoPixelStaveRing.h
@@ -14,7 +14,7 @@ public:
                     PixelGeometryManager* mgr);
   virtual GeoVPhysVol* Build() override;
 
-  GeoVPhysVol* SetParametersAndBuild(std::string,std::string);
+  GeoVPhysVol* SetParametersAndBuild(const std::string&,const std::string&);
   double GetPositionAlongZAxis() const { return m_zPosition; }
 
   double GetInnerRadius() const { return m_innerRadius; }
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorDC1DC2.h b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorDC1DC2.h
index 3cdd5449e3ad..fe48702e33a5 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorDC1DC2.h
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelDetectorDC1DC2.h
@@ -120,6 +120,8 @@ class GeoPixelDisk : public GeoVPixelFactory {
  public:
   GeoPixelDisk(InDetDD::PixelDetectorManager* ddmgr,
                PixelGeometryManager* mgr);
+  GeoPixelDisk (const GeoPixelDisk&) = delete;
+  GeoPixelDisk& operator= (const GeoPixelDisk&) = delete;
   virtual ~GeoPixelDisk();
   virtual GeoVPhysVol* Build() override;
   double Thickness();
@@ -161,6 +163,8 @@ class GeoPixelECCable : public GeoVPixelFactory {
  public:
   GeoPixelECCable(InDetDD::PixelDetectorManager* ddmgr,
                   PixelGeometryManager* mgr);
+  GeoPixelECCable (const GeoPixelECCable&) = delete;
+  GeoPixelECCable& operator= (const GeoPixelECCable&) = delete;
   virtual GeoVPhysVol* Build() override;
   virtual ~GeoPixelECCable();
  private:
@@ -215,6 +219,8 @@ class GeoPixelLadder : public GeoVPixelFactory {
   GeoPixelLadder(InDetDD::PixelDetectorManager* ddmgr,
                  PixelGeometryManager* mgr,
                  GeoPixelSiCrystal& theSensor);
+  GeoPixelLadder (const GeoPixelLadder&) = delete;
+  GeoPixelLadder& operator= (const GeoPixelLadder&) = delete;
   virtual ~GeoPixelLadder();
   virtual GeoVPhysVol* Build() override;
   double Thickness();
@@ -260,6 +266,8 @@ class GeoPixelModule : public GeoVPixelFactory {
   GeoPixelModule(InDetDD::PixelDetectorManager* ddmgr,
                  PixelGeometryManager* mgr,
                  GeoPixelSiCrystal &theSensor);
+  GeoPixelModule (const GeoPixelModule&) = delete;
+  GeoPixelModule& operator= (const GeoPixelModule&) = delete;
   virtual ~GeoPixelModule();
   virtual GeoVPhysVol* Build() override;
   double Thickness();
diff --git a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelLegacyManager.cxx b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelLegacyManager.cxx
index 9e19a15c0924..a7c86c55f203 100644
--- a/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelLegacyManager.cxx
+++ b/InnerDetector/InDetDetDescr/PixelGeoModel/src/PixelLegacyManager.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 
@@ -21,43 +21,41 @@ PixelLegacyManager::PixelLegacyManager(IRDBAccessSvc * rdbSvc,
 				       const std::string & detectorKey, 
 				       const std::string & detectorNode)
   :
+    // These are for the new description of the Pixel Frame
+    m_pfba (rdbSvc->getRecordsetPtr("PFBA",     detectorKey, detectorNode)),
+    m_pbba (rdbSvc->getRecordsetPtr("PBBA",     detectorKey, detectorNode)),
+    m_ptba (rdbSvc->getRecordsetPtr("PTBA",     detectorKey, detectorNode)),
+    m_pfec (rdbSvc->getRecordsetPtr("PFEC",     detectorKey, detectorNode)),
+    m_pbec (rdbSvc->getRecordsetPtr("PBEC",     detectorKey, detectorNode)),
+    m_ptec (rdbSvc->getRecordsetPtr("PTEC",     detectorKey, detectorNode)),
+    m_pecn (rdbSvc->getRecordsetPtr("PECN",     detectorKey, detectorNode)),
+    m_pecf (rdbSvc->getRecordsetPtr("PECF",     detectorKey, detectorNode)),
+    m_pecb (rdbSvc->getRecordsetPtr("PECB",     detectorKey, detectorNode)),
+    m_pect (rdbSvc->getRecordsetPtr("PECT",     detectorKey, detectorNode)),
+
+    // These are for the design
+    m_pxbi (rdbSvc->getRecordsetPtr("PXBI",     detectorKey, detectorNode)),
+    m_pdch (rdbSvc->getRecordsetPtr("PDCH",     detectorKey, detectorNode)),
+    m_pxbd (rdbSvc->getRecordsetPtr("PXBD",     detectorKey, detectorNode)),
+
+    // These are (r a detailed description of the ladders and services on ladde),
+    m_ptla (rdbSvc->getRecordsetPtr("PTLA",     detectorKey, detectorNode)),
+    m_pctr (rdbSvc->getRecordsetPtr("PCTR",     detectorKey, detectorNode)),
+    m_pftr (rdbSvc->getRecordsetPtr("PFTR",     detectorKey, detectorNode)),
+    m_pttr (rdbSvc->getRecordsetPtr("PTTR",     detectorKey, detectorNode)),
+    m_pome (rdbSvc->getRecordsetPtr("POME",     detectorKey, detectorNode)),
+    m_poti (rdbSvc->getRecordsetPtr("POTI",     detectorKey, detectorNode)),
+    m_pobi (rdbSvc->getRecordsetPtr("POBI",     detectorKey, detectorNode)),
+    m_poai (rdbSvc->getRecordsetPtr("POAI",     detectorKey, detectorNode)),
+    m_poci (rdbSvc->getRecordsetPtr("POCI",     detectorKey, detectorNode)),
+    m_posi (rdbSvc->getRecordsetPtr("POSI",     detectorKey, detectorNode)),
+    m_pccf (rdbSvc->getRecordsetPtr("PCCF",     detectorKey, detectorNode)),
+    m_pcff (rdbSvc->getRecordsetPtr("PCFF",     detectorKey, detectorNode)),
     m_BarrelInSFrame(false),
     m_EndcapInSFrame(false),
     m_EndConeSFrame(false),
     m_dc1Geometry(false)
 {
-
-  // These are for the new description of the Pixel Frame
-  m_pfba = rdbSvc->getRecordsetPtr("PFBA",     detectorKey, detectorNode);
-  m_pbba = rdbSvc->getRecordsetPtr("PBBA",     detectorKey, detectorNode);
-  m_ptba = rdbSvc->getRecordsetPtr("PTBA",     detectorKey, detectorNode);
-  m_pfec = rdbSvc->getRecordsetPtr("PFEC",     detectorKey, detectorNode);
-  m_pbec = rdbSvc->getRecordsetPtr("PBEC",     detectorKey, detectorNode);
-  m_ptec = rdbSvc->getRecordsetPtr("PTEC",     detectorKey, detectorNode);
-  m_pecn = rdbSvc->getRecordsetPtr("PECN",     detectorKey, detectorNode);
-  m_pecf = rdbSvc->getRecordsetPtr("PECF",     detectorKey, detectorNode);
-  m_pecb = rdbSvc->getRecordsetPtr("PECB",     detectorKey, detectorNode);
-  m_pect = rdbSvc->getRecordsetPtr("PECT",     detectorKey, detectorNode);
-
-  // These are for the design
-  m_pxbi = rdbSvc->getRecordsetPtr("PXBI",     detectorKey, detectorNode);
-  m_pdch = rdbSvc->getRecordsetPtr("PDCH",     detectorKey, detectorNode);
-  m_pxbd = rdbSvc->getRecordsetPtr("PXBD",     detectorKey, detectorNode);
-
-  // These are for a detailed description of the ladders and services on ladder
-  m_ptla = rdbSvc->getRecordsetPtr("PTLA",     detectorKey, detectorNode);
-  m_pctr = rdbSvc->getRecordsetPtr("PCTR",     detectorKey, detectorNode);
-  m_pftr = rdbSvc->getRecordsetPtr("PFTR",     detectorKey, detectorNode);
-  m_pttr = rdbSvc->getRecordsetPtr("PTTR",     detectorKey, detectorNode);
-  m_pome = rdbSvc->getRecordsetPtr("POME",     detectorKey, detectorNode);
-  m_poti = rdbSvc->getRecordsetPtr("POTI",     detectorKey, detectorNode);
-  m_pobi = rdbSvc->getRecordsetPtr("POBI",     detectorKey, detectorNode);
-  m_poai = rdbSvc->getRecordsetPtr("POAI",     detectorKey, detectorNode);
-  m_poci = rdbSvc->getRecordsetPtr("POCI",     detectorKey, detectorNode);
-  m_posi = rdbSvc->getRecordsetPtr("POSI",     detectorKey, detectorNode);
-  m_pccf = rdbSvc->getRecordsetPtr("PCCF",     detectorKey, detectorNode);
-  m_pcff = rdbSvc->getRecordsetPtr("PCFF",     detectorKey, detectorNode);
-
 }
 
 
-- 
GitLab