From ad0d1034a914857a8e0a5ab42848a26f3f5fd6f6 Mon Sep 17 00:00:00 2001
From: Shaun Roe <shaun.roe@cern.ch>
Date: Thu, 30 May 2024 11:39:42 +0200
Subject: [PATCH] main-coverity-JetToolHelpers

main-coverity-JetToolHelpers
---
 .../JetToolHelpers/InputVariable.h            | 17 +++++-----
 .../JetToolHelpers/JetToolHelpers/VarTool.h   | 13 ++++---
 .../Jet/JetToolHelpers/Root/InputVariable.cpp |  5 +--
 .../Jet/JetToolHelpers/Root/VarTool.cpp       | 34 ++++++++-----------
 4 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/InputVariable.h b/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/InputVariable.h
index efa92f1598cb..284638bf451f 100644
--- a/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/InputVariable.h
+++ b/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/InputVariable.h
@@ -5,16 +5,17 @@
 #ifndef JETTOOLHELPERS_INPUTVARIABLE_H
 #define JETTOOLHELPERS_INPUTVARIABLE_H
 
-#include <cmath>
-#include <memory>
-#include <functional>
+
+#include "JetToolHelpers/JetContext.h" //used here
+#include "xAODJet/Jet.h" //used here
+#include "AthContainers/AuxElement.h" //member variable
+#include "JetAnalysisInterfaces/IInputVariable.h"//inheritance
+
+#include <memory> //std::unique_ptr
+#include <functional> //std::function
 #include <string>
-#include <optional>
+#include <stdexcept> //std::runtime_error
 
-#include "JetToolHelpers/JetContext.h"
-#include "xAODJet/Jet.h"
-#include "AthContainers/AuxElement.h"
-#include "JetAnalysisInterfaces/IInputVariable.h"
 
 namespace JetHelper {
 
diff --git a/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/VarTool.h b/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/VarTool.h
index 2d1d0d60c255..04290202d2d0 100644
--- a/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/VarTool.h
+++ b/Reconstruction/Jet/JetToolHelpers/JetToolHelpers/VarTool.h
@@ -5,19 +5,18 @@
 #ifndef JETTOOLHELPERS_VARTOOL_H
 #define JETTOOLHELPERS_VARTOOL_H
 
-#include <cmath>
-#include <memory>
-#include <functional>
-#include <string>
+
 
 #include "JetToolHelpers/JetContext.h"
 #include "JetToolHelpers/InputVariable.h"
 #include "xAODJet/Jet.h"
-#include "AthContainers/AuxElement.h"
-#include "AsgTools/AsgTool.h"
-#include "JetAnalysisInterfaces/IVarTool.h"
+#include "AsgTools/AsgTool.h" //inheritance
+#include "JetAnalysisInterfaces/IVarTool.h" //inheritance
 #include "AsgTools/PropertyWrapper.h"
 
+#include <memory> //unique_ptr
+#include <string>
+
 namespace JetHelper {
 
     /// Class VarTool
diff --git a/Reconstruction/Jet/JetToolHelpers/Root/InputVariable.cpp b/Reconstruction/Jet/JetToolHelpers/Root/InputVariable.cpp
index 6c2fe4a5f9a7..56b87dc140df 100644
--- a/Reconstruction/Jet/JetToolHelpers/Root/InputVariable.cpp
+++ b/Reconstruction/Jet/JetToolHelpers/Root/InputVariable.cpp
@@ -7,15 +7,16 @@
  *
  */
 
-#include <iostream>
 #include "JetToolHelpers/InputVariable.h"
+#include <cmath> //std::abs
+#include <iostream> //std::cerr
 
 namespace JetHelper{
 
 InputVariable::InputVariable(const std::string& name, std::function<float(const xAOD::Jet& jet, const JetContext& jc)> func):
 InputVariable(name)
 {
-    m_customFunction = func;
+    m_customFunction = std::move(func);
 }
 
 std::unique_ptr<InputVariable> InputVariable::createVariable(const std::string& name, const std::string& type, const bool isJetVar) {
diff --git a/Reconstruction/Jet/JetToolHelpers/Root/VarTool.cpp b/Reconstruction/Jet/JetToolHelpers/Root/VarTool.cpp
index f7fb944c3fa4..9a10c7df98ad 100644
--- a/Reconstruction/Jet/JetToolHelpers/Root/VarTool.cpp
+++ b/Reconstruction/Jet/JetToolHelpers/Root/VarTool.cpp
@@ -2,30 +2,24 @@
   Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 */
 
-#include <iostream>
-#include <fstream>
-#include <stdio.h>
 
 #include "JetToolHelpers/VarTool.h"
 
 namespace JetHelper {
-VarTool::VarTool(const std::string& name)
-     : asg::AsgTool(name)
-{
-}
-
-StatusCode VarTool::initialize()
-{
-
-  m_v = InputVariable::createVariable(m_name,m_type,m_isJetVar);
-  m_v->setScale(m_scale);
-
-  if (! bool(m_v) ) {
-	ATH_MSG_ERROR(" could not create Jet Variable "<< m_name << " type: "<< m_type );
-	return StatusCode::FAILURE; 
+  VarTool::VarTool(const std::string& name)
+       : asg::AsgTool(name)
+  {
+  }
+  
+  StatusCode VarTool::initialize()
+  {
+    m_v = InputVariable::createVariable(m_name,m_type,m_isJetVar);
+    if (not m_v ) {
+      ATH_MSG_ERROR(" could not create Jet Variable "<< m_name << " type: "<< m_type );
+      return StatusCode::FAILURE; 
+    }
+    m_v->setScale(m_scale);
+    return StatusCode::SUCCESS;
   }
-
-  return StatusCode::SUCCESS;
-}
 } //namespace JetHelper
 
-- 
GitLab