From bd50814cabe43e572adbec584467175eaa4bb8f4 Mon Sep 17 00:00:00 2001
From: Edward Brash <brash@jlab.org>
Date: Wed, 13 Nov 2013 14:00:23 -0500
Subject: [PATCH] Address some minor issues reported by cppcheck

These were related to a) scope of some variable declarations, and b) use
of pre-increment vs. post-increment of non-primitive types (this has a
slight performance hit due to the way that pre- vs. post-increment
operators are overloaded in C++.

Also cleaned up a few places where initialized variables were not being
used.
---
 src/THcAerogel.cxx           |  3 +--
 src/THcDC.cxx                | 37 ++++++++++++++++++------------------
 src/THcDetectorMap.cxx       |  5 +++--
 src/THcDriftChamberPlane.cxx |  2 +-
 src/THcHodoscope.cxx         |  2 +-
 src/THcParmList.cxx          |  5 +++--
 src/THcShower.cxx            |  7 +++----
 src/THcShowerCluster.h       | 16 ++++++++--------
 8 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/src/THcAerogel.cxx b/src/THcAerogel.cxx
index 4111a08..60f92df 100644
--- a/src/THcAerogel.cxx
+++ b/src/THcAerogel.cxx
@@ -76,8 +76,6 @@ THcAerogel::~THcAerogel()
 //_____________________________________________________________________________
 THaAnalysisObject::EStatus THcAerogel::Init( const TDatime& date )
 {
-  static const char* const here = "Init()";
-
   cout << "THcAerogel::Init " << GetName() << endl;
 
   // Should probably put this in ReadDatabase as we will know the
@@ -91,6 +89,7 @@ THaAnalysisObject::EStatus THcAerogel::Init( const TDatime& date )
   // Will need to determine which apparatus it belongs to and use the
   // appropriate detector ID in the FillMap call
   if( gHcDetectorMap->FillMap(fDetMap, "HAERO") < 0 ) {
+    static const char* const here = "Init()";
     Error( Here(here), "Error filling detectormap for %s.", 
 	     "HAERO");
       return kInitError;
diff --git a/src/THcDC.cxx b/src/THcDC.cxx
index 9015cf3..9f6cfda 100644
--- a/src/THcDC.cxx
+++ b/src/THcDC.cxx
@@ -157,8 +157,6 @@ THcDC::THcDC( ) :
 //_____________________________________________________________________________
 THaAnalysisObject::EStatus THcDC::Init( const TDatime& date )
 {
-  static const char* const here = "Init()";
-
   Setup(GetName(), GetTitle());	// Create the subdetectors here
   EffInit();
 
@@ -211,6 +209,7 @@ THaAnalysisObject::EStatus THcDC::Init( const TDatime& date )
   EngineDID[3] = '\0';
   
   if( gHcDetectorMap->FillMap(fDetMap, EngineDID) < 0 ) {
+    static const char* const here = "Init()";
     Error( Here(here), "Error filling detectormap for %s.", 
 	     EngineDID);
       return kInitError;
@@ -354,10 +353,10 @@ THcDC::~THcDC()
 
   // Delete the plane objects
   for (vector<THcDriftChamberPlane*>::iterator ip = fPlanes.begin();
-       ip != fPlanes.end(); ip++) delete *ip;
+       ip != fPlanes.end(); ++ip) delete *ip;
   // Delete the chamber objects
   for (vector<THcDriftChamber*>::iterator ip = fChambers.begin();
-       ip != fChambers.end(); ip++) delete *ip;
+       ip != fChambers.end(); ++ip) delete *ip;
 
   delete fDCTracks;
 }
@@ -723,20 +722,22 @@ void THcDC::TrackFit()
   // Number of ray parameters in focal plane.
   const Int_t raycoeffmap[]={4,5,2,3};
 
-  // Initialize residuals
-  // Need to make these member variables so they can be histogrammed
-  // Probably an array of vectors.
-  Double_t double_resolution[fNPlanes][fNDCTracks];
-  Double_t single_resolution[fNPlanes][fNDCTracks];
-  Double_t double_res[fNPlanes]; // For the good track
-
-  for(Int_t ip=0;ip<fNPlanes;ip++) {
-    double_res[ip] = 1000.0;
-    for(Int_t itrack=0;itrack<fNDCTracks;itrack++) {
-      double_resolution[ip][itrack] = 1000.0;
-      single_resolution[ip][itrack] = 1000.0;
-    }
-  }
+  // EJB_Note:  Why is this here?  It does not appear to be used anywhere ... commenting out for now.
+  //
+  //// Initialize residuals
+  //// Need to make these member variables so they can be histogrammed
+  //// Probably an array of vectors.
+  //Double_t double_resolution[fNPlanes][fNDCTracks];
+  //Double_t single_resolution[fNPlanes][fNDCTracks];
+  //Double_t double_res[fNPlanes]; // For the good track
+  //
+  // for(Int_t ip=0;ip<fNPlanes;ip++) {
+  //  double_res[ip] = 1000.0;
+  //  for(Int_t itrack=0;itrack<fNDCTracks;itrack++) {
+  //    double_resolution[ip][itrack] = 1000.0;
+  //    single_resolution[ip][itrack] = 1000.0;
+  //  }
+  // }
   
   Double_t dummychi2 = 1.0E4;
 
diff --git a/src/THcDetectorMap.cxx b/src/THcDetectorMap.cxx
index 24ba354..187c465 100644
--- a/src/THcDetectorMap.cxx
+++ b/src/THcDetectorMap.cxx
@@ -110,7 +110,8 @@ Int_t THcDetectorMap::FillMap(THaDetMap *detmap, const char *detectorname)
       }
     }
   }
-  if(mlist.size() <= 0) {
+//  if(mlist.size() <= 0) {
+  if(mlist.empty()) {
     return(-1);
   }
   Functor f;
@@ -172,13 +173,13 @@ Int_t THcDetectorMap::FillMap(THaDetMap *detmap, const char *detectorname)
 
 void THcDetectorMap::Load(const char *fname)
 {
-  static const char* const here = "THcDetectorMap::Load";
   static const char* const whtspc = " \t";
 
   ifstream ifile;
 
   ifile.open(fname);
   if(!ifile.is_open()) {
+    static const char* const here = "THcDetectorMap::Load";
     Error(here, "error opening detector map file %s",fname);
     return;			// Need a success/failure argument?
   }
diff --git a/src/THcDriftChamberPlane.cxx b/src/THcDriftChamberPlane.cxx
index 4bdf51b..a4be700 100644
--- a/src/THcDriftChamberPlane.cxx
+++ b/src/THcDriftChamberPlane.cxx
@@ -83,7 +83,6 @@ Int_t THcDriftChamberPlane::ReadDatabase( const TDatime& date )
 
   // See what file it looks for
   
-  static const char* const here = "ReadDatabase()";
   char prefix[2];
   Int_t NumDriftMapBins;
   Double_t DriftMapFirstBin;
@@ -210,6 +209,7 @@ Int_t THcDriftChamberPlane::ReadDatabase( const TDatime& date )
   const char* nm = "hod";
   if(  !app || 
       !(fglHod = dynamic_cast<THcHodoscope*>(app->GetDetector(nm))) ) {
+    static const char* const here = "ReadDatabase()";
     Warning(Here(here),"Hodoscope \"%s\" not found. "
 	    "Event-by-event time offsets will NOT be used!!",nm);
   }
diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx
index 7b75dbe..a0e10ef 100644
--- a/src/THcHodoscope.cxx
+++ b/src/THcHodoscope.cxx
@@ -134,7 +134,6 @@ void THcHodoscope::SetApparatus( THaApparatus* app )
 //_____________________________________________________________________________
 THaAnalysisObject::EStatus THcHodoscope::Init( const TDatime& date )
 {
-  static const char* const here = "Init()";
   cout << "In THcHodoscope::Init()" << endl;
   Setup(GetName(), GetTitle());
 
@@ -166,6 +165,7 @@ THaAnalysisObject::EStatus THcHodoscope::Init( const TDatime& date )
   // Will need to determine which apparatus it belongs to and use the
   // appropriate detector ID in the FillMap call
   if( gHcDetectorMap->FillMap(fDetMap, "HSCIN") < 0 ) {
+    static const char* const here = "Init()";
     Error( Here(here), "Error filling detectormap for %s.", 
 	     "HSCIN");
       return kInitError;
diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx
index dd41698..d75c690 100644
--- a/src/THcParmList.cxx
+++ b/src/THcParmList.cxx
@@ -43,7 +43,6 @@ inline static bool IsComment( const string& s, string::size_type pos )
 void THcParmList::Load( const char* fname, Int_t RunNumber )
 {
 
-  static const char* const here   = "THcParmList::LoadFromFile";
   static const char* const whtspc = " \t";
 
   ifstream ifiles[100];		// Should use stack instead
@@ -56,6 +55,7 @@ void THcParmList::Load( const char* fname, Int_t RunNumber )
   }
 
   if(!nfiles) {
+    static const char* const here   = "THcParmList::LoadFromFile";
     Error (here, "error opening parameter file %s",fname);
     return;			// Need a success argument returned
   }
@@ -76,7 +76,8 @@ void THcParmList::Load( const char* fname, Int_t RunNumber )
 
   while(nfiles) {
     string current_comment("");
-    string existing_comment("");
+    // EJB_Note:  existing_comment is never used.
+    // string existing_comment("");
     string::size_type start, pos = 0;
 
     if(!getline(ifiles[nfiles-1],line)) {
diff --git a/src/THcShower.cxx b/src/THcShower.cxx
index 161d782..21c956e 100644
--- a/src/THcShower.cxx
+++ b/src/THcShower.cxx
@@ -105,8 +105,6 @@ void THcShower::Setup(const char* name, const char* description)
 //_____________________________________________________________________________
 THaAnalysisObject::EStatus THcShower::Init( const TDatime& date )
 {
-  static const char* const here = "Init()";
-
   cout << "THcShower::Init " << GetName() << endl;
   Setup(GetName(), GetTitle());
 
@@ -129,6 +127,7 @@ THaAnalysisObject::EStatus THcShower::Init( const TDatime& date )
   EngineDID[0] = toupper(GetApparatus()->GetName()[0]);
 
   if( gHcDetectorMap->FillMap(fDetMap, EngineDID) < 0 ) {
+    static const char* const here = "Init()";
     Error( Here(here), "Error filling detectormap for %s.", 
 	     EngineDID);
       return kInitError;
@@ -667,8 +666,8 @@ Int_t THcShower::CoarseProcess( TClonesArray& tracks)
 	   //<< endl;
 
       for (UInt_t j=0; j!=(*cluster).clSize(); j++) {
-	THcShowerHit* hit = (*cluster).ClusteredHit(j);
-	//cout << "  hit #" << j << ":  "; (*hit).show();
+       	//THcShowerHit* hit = (*cluster).ClusteredHit(j);
+       	//cout << "  hit #" << j << ":  "; (*hit).show();
       }
 
     }
diff --git a/src/THcShowerCluster.h b/src/THcShowerCluster.h
index 23d1e0d..f716e73 100644
--- a/src/THcShowerCluster.h
+++ b/src/THcShowerCluster.h
@@ -18,7 +18,7 @@ class THcShowerCluster : THcShowerHitList {
 
   ~THcShowerCluster() {
     for (THcShowerHitIt i = THcShowerHitList::begin();
-    	 i != THcShowerHitList::end(); i++) {
+    	 i != THcShowerHitList::end(); ++i) {
       delete *i;
       *i = 0;
     }
@@ -51,7 +51,7 @@ class THcShowerCluster : THcShowerHitList {
     Double_t x_sum=0.;
     Double_t Etot=0.;
     for (THcShowerHitIt it=THcShowerHitList::begin();
-	 it!=THcShowerHitList::end(); it++) {
+	 it!=THcShowerHitList::end(); ++it) {
       x_sum += (*it)->hitX() * (*it)->hitE();
       Etot += (*it)->hitE();
     }
@@ -68,7 +68,7 @@ class THcShowerCluster : THcShowerHitList {
     Double_t z_sum=0.;
     Double_t Etot=0.;
     for (THcShowerHitIt it=THcShowerHitList::begin();
-	 it!=THcShowerHitList::end(); it++) {
+	 it!=THcShowerHitList::end(); ++it) {
       z_sum += (*it)->hitZ() * (*it)->hitE();
       Etot += (*it)->hitE();
     }
@@ -82,7 +82,7 @@ class THcShowerCluster : THcShowerHitList {
     //    cout << "In ECl:" << endl;
     Double_t Etot=0.;
     for (THcShowerHitIt it=THcShowerHitList::begin();
-	 it!=THcShowerHitList::end(); it++) {
+	 it!=THcShowerHitList::end(); ++it) {
       Etot += (*it)->hitE();
     }
     return Etot;
@@ -93,7 +93,7 @@ class THcShowerCluster : THcShowerHitList {
   Double_t clEpr() {
     Double_t Epr=0.;
     for (THcShowerHitIt it=THcShowerHitList::begin();
-	 it!=THcShowerHitList::end(); it++) {
+	 it!=THcShowerHitList::end(); ++it) {
       if ((*it)->hitColumn() == 0) {
 	Epr += (*it)->hitE();
       }
@@ -116,7 +116,7 @@ class THcShowerCluster : THcShowerHitList {
 
     Double_t Eplane=0.;
     for (THcShowerHitIt it=THcShowerHitList::begin();
-	 it!=THcShowerHitList::end(); it++) {
+	 it!=THcShowerHitList::end(); ++it) {
 
       if ((*it)->hitColumn() == iplane) 
 
@@ -163,7 +163,7 @@ class THcShowerClusterList : private THcShClusterList {
 
   ~THcShowerClusterList() {
     for (THcShClusterIt i = THcShClusterList::begin();
-    	 i != THcShClusterList::end(); i++) {
+    	 i != THcShClusterList::end(); ++i) {
       delete *i;
       *i = 0;
     }
@@ -206,7 +206,7 @@ void ClusterHits(THcShowerHitList HitList) {
 
       clustered = false;
 
-      for (THcShowerHitIt i=HitList.begin(); i!=HitList.end(); i++) {
+      for (THcShowerHitIt i=HitList.begin(); i!=HitList.end(); ++i) {
 
 	for (UInt_t k=0; k!=(*cluster).clSize(); k++) {
 
-- 
GitLab