From c60fbf39c034ea919087f5afb50e76d0c5372803 Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Mon, 7 Sep 2020 23:29:18 -0400 Subject: [PATCH] InDetServMatGeoModel: Fix cppcheck warnings. - Pass class instances by const reference, not by value. - Prefer preincrement to postincrement for iterators. --- .../InDetServMatGeometryManager.h | 12 ++++++------ .../InDetServMatGeoModel/ServiceMaterial.h | 8 ++++---- .../InDetServMatGeoModel/ServicesTracker.h | 4 ++-- .../InDetServMatGeoModel/StaveServices.h | 4 ++-- .../src/InDetServMatBuilderToolSLHC.cxx | 4 ++-- .../src/InDetServMatGeometryManager.cxx | 12 ++++++------ .../InDetDetDescr/InDetServMatGeoModel/src/Route.cxx | 6 +++--- .../InDetServMatGeoModel/src/ServiceVolume.cxx | 4 ++-- .../InDetServMatGeoModel/src/ServicesTracker.cxx | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/InDetServMatGeometryManager.h b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/InDetServMatGeometryManager.h index 8a8be6ec4382..81260af058f9 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/InDetServMatGeometryManager.h +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/InDetServMatGeometryManager.h @@ -143,11 +143,11 @@ public: double sctInnerSupport() const; // Pixel support tubes dimensions: specify name from simple services table - double SupportTubeRMin(std::string name) const; - double SupportTubeRMax(std::string name) const; - double SupportTubeZMin(std::string name) const; - double SupportTubeZMax(std::string name) const; - int SupportTubeExists(std::string name) const; + double SupportTubeRMin(const std::string& name) const; + double SupportTubeRMax(const std::string& name) const; + double SupportTubeZMin(const std::string& name) const; + double SupportTubeZMax(const std::string& name) const; + int SupportTubeExists(const std::string& name) const; private: // Record sets @@ -188,7 +188,7 @@ private: InDetMaterialManager * m_matMgr; // index of named support tube in m_InDetSimpleServices table, -1 if not found. Could be cached for speed. - int SupportTubeIndex(std::string name) const; + int SupportTubeIndex(const std::string& name) const; }; diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServiceMaterial.h b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServiceMaterial.h index 3ce60a9862b0..13558191a933 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServiceMaterial.h +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServiceMaterial.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef ServiceMaterial_H @@ -19,8 +19,8 @@ public: If the weight is zero it will be taken from the material DB */ struct Entry { - Entry( std::string nam, int num, bool lin) : name(nam), number(num), linear(lin), weight(1) {} - Entry( std::string nam, int num, bool lin, double w) : name(nam), number(num), linear(lin), weight(w) {} + Entry( const std::string& nam, int num, bool lin) : name(nam), number(num), linear(lin), weight(1) {} + Entry( const std::string& nam, int num, bool lin, double w) : name(nam), number(num), linear(lin), weight(w) {} std::string name; int number; @@ -55,7 +55,7 @@ public: //ServiceMaterial operator*( double len) const {return ServiceMaterial( name(), len*linearWeight(), m_components);} void multiply( int factor) { - for ( std::vector< Entry>::iterator i=m_components.begin(); i!=m_components.end(); i++) { + for ( std::vector< Entry>::iterator i=m_components.begin(); i!=m_components.end(); ++i) { i->number *= factor; } } diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServicesTracker.h b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServicesTracker.h index 5921cf4e04db..df278561272f 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServicesTracker.h +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/ServicesTracker.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef ServicesTracker_H @@ -46,7 +46,7 @@ public: const std::vector<ServiceVolume*>& serviceVolumes() const {return m_volumes;} // Called by Routing - void setServiceVolumes( const std::vector<ServiceVolume*> vc) {m_volumes=vc;} + void setServiceVolumes( const std::vector<ServiceVolume*>& vc) {m_volumes=vc;} // methods called by Builder void constructBarrelLayer( double radius, double zHalfLength, diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/StaveServices.h b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/StaveServices.h index f02284511a0a..9ff9794853ab 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/StaveServices.h +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/InDetServMatGeoModel/StaveServices.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef StaveServices_H @@ -17,7 +17,7 @@ class StaveServices { public: StaveServices( DetType::Type type, DetType::Part part, int layer, - int nhv, int ndcs, int ndata, std::vector<int> lvGauge) : + int nhv, int ndcs, int ndata, const std::vector<int>& lvGauge) : m_type( type), m_part(part), m_layer(layer), m_numHV(nhv), m_numDCS( ndcs), m_numData( ndata), m_lvGauge( lvGauge) {} diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatBuilderToolSLHC.cxx b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatBuilderToolSLHC.cxx index 311a0fbeb142..2d3a9a1208ba 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatBuilderToolSLHC.cxx +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatBuilderToolSLHC.cxx @@ -161,7 +161,7 @@ void InDetServMatBuilderToolSLHC::build() fixMissingMaterials(); typedef std::vector<ServiceVolume*>::const_iterator iter; - for (iter i=tracker->serviceVolumes().begin(); i!=tracker->serviceVolumes().end(); i++) { + for (iter i=tracker->serviceVolumes().begin(); i!=tracker->serviceVolumes().end(); ++i) { /* msg(MSG::INFO) << "Calling ServiceVolume->dump() for the " << n++ << "th time" << endmsg; (**i).dump(); // for DEBUG only @@ -219,7 +219,7 @@ void InDetServMatBuilderToolSLHC::addServiceVolume( const ServiceVolume& vol) param->setZmax(vol.zMax()); param->setZsymm(true); for (std::vector<ServiceMaterial>::const_iterator ism=vol.materials().begin(); ism!=vol.materials().end(); ++ism) { - for ( ServiceMaterial::EntryIter ient= ism->components().begin(); ient!=ism->components().end(); ient++) { + for ( ServiceMaterial::EntryIter ient= ism->components().begin(); ient!=ism->components().end(); ++ient) { /* msg(MSG::INFO) << "Inside components loop, comp = " << ient->name << " number " << ient->number diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatGeometryManager.cxx b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatGeometryManager.cxx index 33ba286ac6fe..a76cac7e98ba 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatGeometryManager.cxx +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/InDetServMatGeometryManager.cxx @@ -105,7 +105,7 @@ bool InDetServMatGeometryManager::buildServices() const return false; } -int InDetServMatGeometryManager::SupportTubeIndex(std::string name) const +int InDetServMatGeometryManager::SupportTubeIndex(const std::string& name) const { for (unsigned int i = 0; i < db()->getTableSize(m_InDetSimpleServices); i++) { @@ -114,35 +114,35 @@ int InDetServMatGeometryManager::SupportTubeIndex(std::string name) const return -1; } -double InDetServMatGeometryManager::SupportTubeRMin(std::string name) const +double InDetServMatGeometryManager::SupportTubeRMin(const std::string& name) const { int ind = SupportTubeIndex(name); if (ind >= 0) return db()->getDouble(m_InDetSimpleServices, "RMIN", ind); return 0; } -double InDetServMatGeometryManager::SupportTubeRMax(std::string name) const +double InDetServMatGeometryManager::SupportTubeRMax(const std::string& name) const { int ind = SupportTubeIndex(name); if (ind >= 0) return db()->getDouble(m_InDetSimpleServices, "RMAX", ind); return 0; } -double InDetServMatGeometryManager::SupportTubeZMin(std::string name) const +double InDetServMatGeometryManager::SupportTubeZMin(const std::string& name) const { int ind = SupportTubeIndex(name); if (ind >= 0) return db()->getDouble(m_InDetSimpleServices, "ZMIN", ind); return 0; } -double InDetServMatGeometryManager::SupportTubeZMax(std::string name) const +double InDetServMatGeometryManager::SupportTubeZMax(const std::string& name) const { int ind = SupportTubeIndex(name); if (ind >= 0) return db()->getDouble(m_InDetSimpleServices, "ZMAX", ind); return 0; } -int InDetServMatGeometryManager::SupportTubeExists(std::string name) const +int InDetServMatGeometryManager::SupportTubeExists(const std::string& name) const { if (SupportTubeIndex(name) != -1) return 1; return 0; diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/Route.cxx b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/Route.cxx index c1845c111405..29a3e3886426 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/Route.cxx +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/Route.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "InDetServMatGeoModel/Route.h" @@ -21,7 +21,7 @@ ServiceVolume* Route::entryVolume( double pos, bool ascending, Athena::MsgStream // else { //should iterate to find exit volume if ( ascending) { - for (VolumeContainer::const_iterator i=volumes().begin(); i!=volumes().end(); i++) { + for (VolumeContainer::const_iterator i=volumes().begin(); i!=volumes().end(); ++i) { msg << MSG::DEBUG << "Comparing " << pos << " and " << (**i).position() << endmsg; @@ -57,7 +57,7 @@ ServiceVolume* Route::exitVolume( bool ascending, Athena::MsgStreamMember& msg) // returns the volume closest to the exit point, coming from the given direction if (volumes().empty()) return 0; if ( ascending) { - for (VolumeContainer::const_iterator i=volumes().begin(); i!=volumes().end(); i++) { + for (VolumeContainer::const_iterator i=volumes().begin(); i!=volumes().end(); ++i) { if ((**i).contains(exit())) return *i; else { msg << MSG::DEBUG << "volume at pos " << (**i).radius() diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServiceVolume.cxx b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServiceVolume.cxx index 9b96b7a7738f..217c35c64b07 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServiceVolume.cxx +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServiceVolume.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "InDetServMatGeoModel/ServiceVolume.h" @@ -23,7 +23,7 @@ void ServiceVolume::dump( bool dumpMaterial) const if ( dumpMaterial && !materials().empty()) { for (std::vector<ServiceMaterial>::const_iterator i=materials().begin(); i!=materials().end(); ++i) { cout << " service material " << i->name() << " has the following components" << endl; - for ( ServiceMaterial::EntryIter ient= i->components().begin(); ient!=i->components().end(); ient++) { + for ( ServiceMaterial::EntryIter ient= i->components().begin(); ient!=i->components().end(); ++ient) { cout << ient->name << " linear? " << ient->linear << " number " << ient->number << " l/w " << ient->weight diff --git a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServicesTracker.cxx b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServicesTracker.cxx index f3427457dead..f43b215dd256 100644 --- a/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServicesTracker.cxx +++ b/InnerDetector/InDetDetDescr/InDetServMatGeoModel/src/ServicesTracker.cxx @@ -85,7 +85,7 @@ void ServicesTracker::finaliseServices() std::map<const ServicesLayer*, ServiceMaterial> layerMaterial; // cache the layer services typedef std::vector<ServiceVolume*>::iterator VolumeIter; - for (VolumeIter iv=m_volumes.begin(); iv!=m_volumes.end(); iv++) { + for (VolumeIter iv=m_volumes.begin(); iv!=m_volumes.end(); ++iv) { std::vector<ServiceMaterial> result; // = (**iv).materials(); // preserve already present mat. (EOS) if ((**iv).isEOS()) addEosMaterial(**iv, result); -- GitLab