From 261cdc40b2fbfa925bcc9634cf4cefc1827f65ae Mon Sep 17 00:00:00 2001
From: scott snyder <sss@karma>
Date: Fri, 15 Apr 2022 10:50:32 -0400
Subject: [PATCH] TruthHelper: Fix cppcheck warnings.

Pass containers by const reference, not by value.
Avoid postincrement of iterator instances.
---
 .../GenAnalysisTools/TruthHelper/TruthHelper/NCutter.h      | 4 ++--
 Generators/GenAnalysisTools/TruthHelper/src/GenAccessIO.cxx | 2 +-
 Generators/GenAnalysisTools/TruthHelper/src/NCutter.cxx     | 6 +++---
 Generators/GenAnalysisTools/TruthHelper/src/PileUpType.cxx  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Generators/GenAnalysisTools/TruthHelper/TruthHelper/NCutter.h b/Generators/GenAnalysisTools/TruthHelper/TruthHelper/NCutter.h
index d776c71e8d29..1362be153c33 100644
--- a/Generators/GenAnalysisTools/TruthHelper/TruthHelper/NCutter.h
+++ b/Generators/GenAnalysisTools/TruthHelper/TruthHelper/NCutter.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef HEPMCHELPER_NCUTTER_H
@@ -21,7 +21,7 @@ namespace TruthHelper {
       m_selectors.push_back( new GenAll() );
     }
 
-    NCutter(const std::vector<GenIMCselector*> selectors) {
+    NCutter(const std::vector<GenIMCselector*>& selectors) {
       std::vector<GenIMCselector*>::const_iterator i = selectors.begin();
       for (; i != selectors.end(); ++i) {
         m_selectors.push_back((*i)->create());
diff --git a/Generators/GenAnalysisTools/TruthHelper/src/GenAccessIO.cxx b/Generators/GenAnalysisTools/TruthHelper/src/GenAccessIO.cxx
index a4587e14b25d..86c2245cc4ae 100644
--- a/Generators/GenAnalysisTools/TruthHelper/src/GenAccessIO.cxx
+++ b/Generators/GenAnalysisTools/TruthHelper/src/GenAccessIO.cxx
@@ -35,7 +35,7 @@ namespace TruthHelper {
     }
     const McEventCollection& mcColl = *firstMEC;
     int icount = 0;
-    for ( ; firstMEC!= lastMEC; firstMEC++) icount++;
+    for ( ; firstMEC!= lastMEC; ++firstMEC) icount++;
     log << MSG::DEBUG << "Number of McEventCollections=  "<< icount << endmsg;
 
     // If there is more than one then do the retrieve with the key
diff --git a/Generators/GenAnalysisTools/TruthHelper/src/NCutter.cxx b/Generators/GenAnalysisTools/TruthHelper/src/NCutter.cxx
index dd9b0c310996..0a9fd6395f05 100644
--- a/Generators/GenAnalysisTools/TruthHelper/src/NCutter.cxx
+++ b/Generators/GenAnalysisTools/TruthHelper/src/NCutter.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "TruthHelper/NCutter.h"
@@ -10,8 +10,8 @@ namespace TruthHelper {
 
 
   bool NCutter::operator()(HepMC::ConstGenParticlePtr p ) const {
-    for (std::vector<GenIMCselector*>::const_iterator i = m_selectors.begin(); i != m_selectors.end(); i++) {
-      if ( !(*i)->operator()(p) ) return false;
+    for (const GenIMCselector* i : m_selectors) {
+      if ( !i->operator()(p) ) return false;
     }
     return true;
   }
diff --git a/Generators/GenAnalysisTools/TruthHelper/src/PileUpType.cxx b/Generators/GenAnalysisTools/TruthHelper/src/PileUpType.cxx
index 2ff8c2f01f8f..4230e7629fbf 100644
--- a/Generators/GenAnalysisTools/TruthHelper/src/PileUpType.cxx
+++ b/Generators/GenAnalysisTools/TruthHelper/src/PileUpType.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "TruthHelper/PileUpType.h"
@@ -20,7 +20,7 @@ McEventCollection::const_iterator PileUpType::in_time_minimum_bias_event_begin()
    McEventCollection::const_iterator ibegin = m_particleList->begin();
    McEventCollection::const_iterator iend = m_particleList->end();
    if ( (ibegin!=iend) && (m_particleList->size()>1) ) {
-     ibegin++;
+     ++ibegin;
      return ibegin;
    }
    else return iend;
-- 
GitLab