From 919706085866d332e3303b4a552046e63d0e2fc6 Mon Sep 17 00:00:00 2001 From: Rafal Bielski Date: Fri, 20 Aug 2021 16:30:57 +0200 Subject: [PATCH] Make slicing and narrowing casts explicit Make the following implicit slicing and narrowing into explicit: ``` L1TopoEvent/Root/GenericTOB.cxx:30:4: warning: slicing object from type 'JetTOB' to 'BaseTOB' discards 48 bytes of state [cppcoreguidelines-slicing] BaseTOB(jet) ^ L1TopoEvent/Root/GenericTOB.cxx:30:4: warning: slicing object from type 'JetTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:30:4: warning: slicing object from type 'JetTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:44:4: warning: slicing object from type 'jTauTOB' to 'BaseTOB' discards 40 bytes of state [cppcoreguidelines-slicing] BaseTOB(tau) ^ L1TopoEvent/Root/GenericTOB.cxx:44:4: warning: slicing object from type 'jTauTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:44:4: warning: slicing object from type 'jTauTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:47:12: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] , m_phi(tau.phi()) ^ L1TopoEvent/Root/GenericTOB.cxx:56:4: warning: slicing object from type 'jLargeRJetTOB' to 'BaseTOB' discards 40 bytes of state [cppcoreguidelines-slicing] BaseTOB(jet) ^ L1TopoEvent/Root/GenericTOB.cxx:56:4: warning: slicing object from type 'jLargeRJetTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:56:4: warning: slicing object from type 'jLargeRJetTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:59:12: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] , m_phi(jet.phi()) ^ L1TopoEvent/Root/GenericTOB.cxx:68:4: warning: slicing object from type 'jJetTOB' to 'BaseTOB' discards 40 bytes of state [cppcoreguidelines-slicing] BaseTOB(jet) ^ L1TopoEvent/Root/GenericTOB.cxx:68:4: warning: slicing object from type 'jJetTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:68:4: warning: slicing object from type 'jJetTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:71:12: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] , m_phi(jet.phi()) ^ L1TopoEvent/Root/GenericTOB.cxx:80:4: warning: slicing object from type 'ClusterTOB' to 'BaseTOB' discards 44 bytes of state [cppcoreguidelines-slicing] BaseTOB(cluster) ^ L1TopoEvent/Root/GenericTOB.cxx:80:4: warning: slicing object from type 'ClusterTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:80:4: warning: slicing object from type 'ClusterTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:92:4: warning: slicing object from type 'eEmTOB' to 'BaseTOB' discards 56 bytes of state [cppcoreguidelines-slicing] BaseTOB(eem) ^ L1TopoEvent/Root/GenericTOB.cxx:92:4: warning: slicing object from type 'eEmTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:92:4: warning: slicing object from type 'eEmTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:95:12: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] , m_phi(eem.phi()) ^ L1TopoEvent/Root/GenericTOB.cxx:107:4: warning: slicing object from type 'eTauTOB' to 'BaseTOB' discards 56 bytes of state [cppcoreguidelines-slicing] BaseTOB(etau) ^ L1TopoEvent/Root/GenericTOB.cxx:107:4: warning: slicing object from type 'eTauTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:107:4: warning: slicing object from type 'eTauTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:110:12: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] , m_phi(etau.phi()) ^ L1TopoEvent/Root/GenericTOB.cxx:122:4: warning: slicing object from type 'MuonTOB' to 'BaseTOB' discards 80 bytes of state [cppcoreguidelines-slicing] BaseTOB(muon) ^ L1TopoEvent/Root/GenericTOB.cxx:122:4: warning: slicing object from type 'MuonTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:122:4: warning: slicing object from type 'MuonTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:139:4: warning: slicing object from type 'LateMuonTOB' to 'BaseTOB' discards 40 bytes of state [cppcoreguidelines-slicing] BaseTOB(lateMuon) ^ L1TopoEvent/Root/GenericTOB.cxx:139:4: warning: slicing object from type 'LateMuonTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:139:4: warning: slicing object from type 'LateMuonTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:151:4: warning: slicing object from type 'MuonNextBCTOB' to 'BaseTOB' discards 40 bytes of state [cppcoreguidelines-slicing] BaseTOB(muonNextBC) ^ L1TopoEvent/Root/GenericTOB.cxx:151:4: warning: slicing object from type 'MuonNextBCTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:151:4: warning: slicing object from type 'MuonNextBCTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:165:4: warning: slicing object from type 'MetTOB' to 'BaseTOB' discards 40 bytes of state [cppcoreguidelines-slicing] BaseTOB(met) ^ L1TopoEvent/Root/GenericTOB.cxx:165:4: warning: slicing object from type 'MetTOB' to 'BaseTOB' discards override 'print' [cppcoreguidelines-slicing] L1TopoEvent/Root/GenericTOB.cxx:165:4: warning: slicing object from type 'MetTOB' to 'BaseTOB' discards override 'tobType' [cppcoreguidelines-slicing] L1TopoEvent/Root/MuonTOB.cxx:26:13: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] , m_phi( sizeCheck(phi, nBitsPhi()) ) ^ /workspaces/build/../athena/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/JetTOB.h:36:46: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] int energy(JetSize js ) const { return js==JS1?m_Et1:m_Et2; } ^ /workspaces/build/../athena/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/JetTOB.h:37:42: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] int Et(JetSize js ) const { return js==JS1?m_Et1:m_Et2; } ``` --- .../L1Topo/L1TopoEvent/L1TopoEvent/BaseTOB.h | 2 ++ .../L1Topo/L1TopoEvent/L1TopoEvent/JetTOB.h | 4 +-- .../L1Topo/L1TopoEvent/Root/GenericTOB.cxx | 32 +++++++++---------- .../L1Topo/L1TopoEvent/Root/MuonTOB.cxx | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/BaseTOB.h b/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/BaseTOB.h index 4e51896cc7e..43506526155 100644 --- a/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/BaseTOB.h +++ b/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/BaseTOB.h @@ -19,6 +19,8 @@ namespace TCS { uint32_t roiWord() const { return m_roiWord; } + const std::string& tobName() const { return m_tobName; } + static size_t instances() { return 0; } protected: diff --git a/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/JetTOB.h b/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/JetTOB.h index 66e4b946740..f05206d2038 100644 --- a/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/JetTOB.h +++ b/Trigger/TrigT1/L1Topo/L1TopoEvent/L1TopoEvent/JetTOB.h @@ -33,8 +33,8 @@ namespace TCS { virtual ~JetTOB(); // accessors - int energy(JetSize js ) const { return js==JS1?m_Et1:m_Et2; } - int Et(JetSize js ) const { return js==JS1?m_Et1:m_Et2; } + int energy(JetSize js ) const { return static_cast(js==JS1?m_Et1:m_Et2); } + int Et(JetSize js ) const { return static_cast(js==JS1?m_Et1:m_Et2); } // accessors unsigned int Et1() const { return m_Et1; } diff --git a/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/GenericTOB.cxx b/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/GenericTOB.cxx index bfd62675894..23757d67cea 100644 --- a/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/GenericTOB.cxx +++ b/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/GenericTOB.cxx @@ -27,7 +27,7 @@ TCS::GenericTOB::GenericTOB(const GenericTOB & other) = default; // constructor from jet TCS::GenericTOB::GenericTOB(const JetTOB & jet, JetTOB::JetSize jetSize) : - BaseTOB(jet) + BaseTOB(jet.roiWord(), jet.tobName()) , m_Et(jet.Et(jetSize)) , m_EtNarrow(jet.EtNarrow()) , m_EtWide(jet.EtWide()) @@ -41,10 +41,10 @@ TCS::GenericTOB::GenericTOB(const JetTOB & jet, JetTOB::JetSize jetSize) : // constructor from small R jet TCS::GenericTOB::GenericTOB(const jTauTOB & tau) : - BaseTOB(tau) + BaseTOB(tau.roiWord(), tau.tobName()) , m_Et(tau.Et()) , m_eta(tau.eta()) - , m_phi(tau.phi()) + , m_phi(static_cast(tau.phi())) , m_EtDouble(tau.EtDouble()) , m_etaDouble(tau.etaDouble()) , m_phiDouble(tau.phiDouble()) @@ -53,10 +53,10 @@ TCS::GenericTOB::GenericTOB(const jTauTOB & tau) : // constructor from large R jet TCS::GenericTOB::GenericTOB(const jLargeRJetTOB & jet) : - BaseTOB(jet) + BaseTOB(jet.roiWord(), jet.tobName()) , m_Et(jet.Et()) , m_eta(jet.eta()) - , m_phi(jet.phi()) + , m_phi(static_cast(jet.phi())) , m_EtDouble(jet.EtDouble()) , m_etaDouble(jet.etaDouble()) , m_phiDouble(jet.phiDouble()) @@ -65,10 +65,10 @@ TCS::GenericTOB::GenericTOB(const jLargeRJetTOB & jet) : // constructor from small R jet TCS::GenericTOB::GenericTOB(const jJetTOB & jet) : - BaseTOB(jet) + BaseTOB(jet.roiWord(), jet.tobName()) , m_Et(jet.Et()) , m_eta(jet.eta()) - , m_phi(jet.phi()) + , m_phi(static_cast(jet.phi())) , m_EtDouble(jet.EtDouble()) , m_etaDouble(jet.etaDouble()) , m_phiDouble(jet.phiDouble()) @@ -77,7 +77,7 @@ TCS::GenericTOB::GenericTOB(const jJetTOB & jet) : // constructor from cluster TCS::GenericTOB::GenericTOB(const ClusterTOB & cluster) : - BaseTOB(cluster) + BaseTOB(cluster.roiWord(), cluster.tobName()) , m_Et(cluster.Et()) , m_eta(cluster.eta()) , m_phi(cluster.phi()) @@ -89,10 +89,10 @@ TCS::GenericTOB::GenericTOB(const ClusterTOB & cluster) : // constructor from eEm TCS::GenericTOB::GenericTOB(const eEmTOB & eem) : - BaseTOB(eem) + BaseTOB(eem.roiWord(), eem.tobName()) , m_Et(eem.Et()) , m_eta(eem.eta()) - , m_phi(eem.phi()) + , m_phi(static_cast(eem.phi())) , m_EtDouble(eem.EtDouble()) , m_etaDouble(eem.etaDouble()) , m_phiDouble(eem.phiDouble()) @@ -104,10 +104,10 @@ TCS::GenericTOB::GenericTOB(const eEmTOB & eem) : // constructor from eTau TCS::GenericTOB::GenericTOB(const eTauTOB & etau) : - BaseTOB(etau) + BaseTOB(etau.roiWord(), etau.tobName()) , m_Et(etau.Et()) , m_eta(etau.eta()) - , m_phi(etau.phi()) + , m_phi(static_cast(etau.phi())) , m_EtDouble(etau.EtDouble()) , m_etaDouble(etau.etaDouble()) , m_phiDouble(etau.phiDouble()) @@ -119,7 +119,7 @@ TCS::GenericTOB::GenericTOB(const eTauTOB & etau) : // constructor from muon TCS::GenericTOB::GenericTOB(const MuonTOB & muon) : - BaseTOB(muon) + BaseTOB(muon.roiWord(), muon.tobName()) , m_Et(muon.Et()) , m_eta(muon.eta()) , m_phi(muon.phi()) @@ -136,7 +136,7 @@ TCS::GenericTOB::GenericTOB(const MuonTOB & muon) : // constructor for latemuon TCS::GenericTOB::GenericTOB(const LateMuonTOB & lateMuon) : - BaseTOB(lateMuon) + BaseTOB(lateMuon.roiWord(), lateMuon.tobName()) , m_Et(lateMuon.Et()) , m_eta(lateMuon.eta()) , m_phi(lateMuon.phi()) @@ -148,7 +148,7 @@ TCS::GenericTOB::GenericTOB(const LateMuonTOB & lateMuon) : // constructor for muonNextBC TCS::GenericTOB::GenericTOB(const MuonNextBCTOB & muonNextBC) : - BaseTOB(muonNextBC) + BaseTOB(muonNextBC.roiWord(), muonNextBC.tobName()) , m_Et(muonNextBC.Et()) , m_eta(muonNextBC.eta()) , m_phi(muonNextBC.phi()) @@ -162,7 +162,7 @@ TCS::GenericTOB::GenericTOB(const MuonNextBCTOB & muonNextBC) : // constr from met TCS::GenericTOB::GenericTOB(const MetTOB & met) : - BaseTOB(met) + BaseTOB(met.roiWord(), met.tobName()) , m_Et(met.Et()) , m_Ex(met.Ex()) , m_Ey(met.Ey()) diff --git a/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/MuonTOB.cxx b/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/MuonTOB.cxx index 1bf669bf89e..a3114a25a4d 100644 --- a/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/MuonTOB.cxx +++ b/Trigger/TrigT1/L1Topo/L1TopoEvent/Root/MuonTOB.cxx @@ -23,7 +23,7 @@ TCS::MuonTOB::MuonTOB(unsigned int et, unsigned int isolation, int eta, unsigned , m_Et( sizeCheck(et, nBitsEt()) ) , m_isolation( sizeCheck( isolation, nBitsIsolation()) ) , m_eta( sizeCheck(eta, nBitsEta()) ) - , m_phi( sizeCheck(phi, nBitsPhi()) ) + , m_phi( static_cast(sizeCheck(phi, nBitsPhi())) ) {} // copy constructor -- GitLab