From e5516db7c30bcb3303af31a0e496ee6d85f077ab Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Tue, 15 Oct 2019 16:48:54 +0200 Subject: [PATCH] TileEvent: Fix cppcheck warnings. cppcheck warnings: - Pass large objects by const ref, not by value. - Prefer to initialize members in an initialization list. - Suppress false positives stemming from the union used for calo cell quality. --- .../TileEvent/TileEvent/TileCell.h | 16 +++++++-- .../TileEvent/TileEvent/TileRawData.h | 8 ++--- TileCalorimeter/TileEvent/src/TileCell.cxx | 5 ++- TileCalorimeter/TileEvent/src/TileRawData.cxx | 34 ++++++++----------- TileCalorimeter/TileEvent/src/TileSimData.cxx | 4 +-- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/TileCalorimeter/TileEvent/TileEvent/TileCell.h b/TileCalorimeter/TileEvent/TileEvent/TileCell.h index 605b9160724..245042fa0ed 100755 --- a/TileCalorimeter/TileEvent/TileEvent/TileCell.h +++ b/TileCalorimeter/TileEvent/TileEvent/TileCell.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ //*************************************************************************** @@ -16,7 +16,7 @@ // leakage corrections. Time represents when the feature extraction thinks // the deposit occured, in nanoseconds, relative to the trigger. It ought // to be zero for good hits. -// Quality is an 32-bits integer number, which is split in 4 unsinged chars +// Quality is an 32-bits integer number, which is split in 4 unsigned chars // m_tileQual[4] like this: // m_tileQual[0] and m_tileQual[1] are unsigned quality from TileRawChannel for first and second PMT // m_tileQual[2] and m_tileQual[3] contains special bits for first and second PMT respectively: @@ -167,14 +167,19 @@ public: /** @brief set quality of first PMT */ void setQual1 (unsigned char qual) { m_tileQual[0] = qual; } /** @brief set quality of second PMT */ + // cppcheck-suppress objectIndex void setQual2 (unsigned char qual) { m_tileQual[1] = qual; } /** @brief set quality bits of first PMT */ + // cppcheck-suppress objectIndex void setQbit1 (unsigned char qbit) { m_tileQual[2] = qbit; } /** @brief set quality bits of second PMT */ + // cppcheck-suppress objectIndex void setQbit2 (unsigned char qbit) { m_tileQual[3] = qbit; } /** @brief set quality and quality bits of first PMT */ + // cppcheck-suppress objectIndex void setQual1 (unsigned char qual, unsigned char qbit) { m_tileQual[0] = qual; m_tileQual[2] = qbit; } /** @brief set quality and quality bits of second PMT */ + // cppcheck-suppress objectIndex void setQual2 (unsigned char qual, unsigned char qbit) { m_tileQual[1] = qual; m_tileQual[3] = qbit; } /** all get methods */ @@ -197,14 +202,19 @@ public: /** @brief get quality of first PMT (data member) */ virtual uint8_t qual1 (void) const { return m_tileQual[0]; } /** @brief get quality of second PMT (data member) */ + // cppcheck-suppress objectIndex virtual uint8_t qual2 (void) const { return m_tileQual[1]; } /** @brief get quality bits of first PMT (data member) */ + // cppcheck-suppress objectIndex virtual uint8_t qbit1 (void) const { return m_tileQual[2]; } /** @brief get quality bits of second PMT (data member) */ + // cppcheck-suppress objectIndex virtual uint8_t qbit2 (void) const { return m_tileQual[3]; } /** @brief check if first PMT is in bad channel list and masked */ + // cppcheck-suppress objectIndex virtual bool badch1 (void) const { return ((m_tileQual[2]&TileCell::MASK_BADCH) != 0); } /** @brief check if second PMT is in bad channel list and masked */ + // cppcheck-suppress objectIndex virtual bool badch2 (void) const { return ((m_tileQual[3]&TileCell::MASK_BADCH) != 0); } /** @brief check if whole cell is bad (i.e. no energy measurement at all in this cell) */ virtual bool badcell (void) const { return (badch1() & badch2()); } @@ -253,7 +263,9 @@ void TileCell::setEnergy_nonvirt(float e1, float e2, int gain1, int gain2) inline void TileCell::setQuality_nonvirt(unsigned char qual, unsigned char qbit, int pmt) { + // cppcheck-suppress objectIndex m_tileQual[0+pmt] = qual; + // cppcheck-suppress objectIndex m_tileQual[2+pmt] = qbit; } diff --git a/TileCalorimeter/TileEvent/TileEvent/TileRawData.h b/TileCalorimeter/TileEvent/TileEvent/TileRawData.h index 1c4dc0099a2..bebd056fa42 100755 --- a/TileCalorimeter/TileEvent/TileEvent/TileRawData.h +++ b/TileCalorimeter/TileEvent/TileEvent/TileRawData.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ //*************************************************************************** @@ -66,15 +66,15 @@ public: // Can be used in a cast operation : (std::string) TileRawData virtual operator std::string() const; - static void print_to_stream ( const std::vector<float> val, + static void print_to_stream ( const std::vector<float>& val, const std::string & label, std::ostringstream & text); - static void print_to_stream ( const std::vector<double> val, + static void print_to_stream ( const std::vector<double>& val, const std::string & label, std::ostringstream & text); - static void print_to_stream ( const std::vector<uint32_t> val, + static void print_to_stream ( const std::vector<uint32_t>& val, const std::string & label, std::ostringstream & text); private: diff --git a/TileCalorimeter/TileEvent/src/TileCell.cxx b/TileCalorimeter/TileEvent/src/TileCell.cxx index db7d1087530..8cd8fa5f4fb 100755 --- a/TileCalorimeter/TileEvent/src/TileCell.cxx +++ b/TileCalorimeter/TileEvent/src/TileCell.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ //***************************************************************************** @@ -72,8 +72,11 @@ TileCell::TileCell(const CaloDetDescrElement* const & caloDDE, , m_timeDiff((time1-time2)/2.) { m_tileQual[0] = std::min(255,abs(qual1)); + // cppcheck-suppress objectIndex m_tileQual[1] = std::min(255,abs(qual2)); + // cppcheck-suppress objectIndex m_tileQual[2] = (qbit1 & 0xFF); + // cppcheck-suppress objectIndex m_tileQual[3] = (qbit2 & 0xFF); } diff --git a/TileCalorimeter/TileEvent/src/TileRawData.cxx b/TileCalorimeter/TileEvent/src/TileRawData.cxx index 1a529ae8f8c..061f3d3121f 100755 --- a/TileCalorimeter/TileEvent/src/TileRawData.cxx +++ b/TileCalorimeter/TileEvent/src/TileRawData.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ //***************************************************************************** @@ -32,8 +32,8 @@ TileCablingService * s_cabling = TileCablingService::getInstance(); TileRawData::TileRawData( const Identifier& id ) + : m_adc_hwid (s_cabling->s2h_adc_id(id)) { - m_adc_hwid = s_cabling->s2h_adc_id(id); } void TileRawData::print() const @@ -76,40 +76,34 @@ int TileRawData::frag_ID(void) const { return s_cabling->frag(m_adc_hwid); } -void TileRawData::print_to_stream ( const std::vector<float> val, +void TileRawData::print_to_stream ( const std::vector<float>& val, const std::string & label, std::ostringstream & text) { text << label; - - std::vector<float>::const_iterator it1=val.begin(); - std::vector<float>::const_iterator it2=val.end(); - - for ( ; it1!=it2; ++it1) text << " " << (*it1); + for (float v : val) { + text << " " << v; + } } -void TileRawData::print_to_stream ( const std::vector<double> val, +void TileRawData::print_to_stream ( const std::vector<double>& val, const std::string & label, std::ostringstream & text) { text << label; - - std::vector<double>::const_iterator it1=val.begin(); - std::vector<double>::const_iterator it2=val.end(); - - for ( ; it1!=it2; ++it1) text << " " << (*it1); + for (double v : val) { + text << " " << v; + } } -void TileRawData::print_to_stream ( const std::vector<uint32_t> val, +void TileRawData::print_to_stream ( const std::vector<uint32_t>& val, const std::string & label, std::ostringstream & text) { text << label; - - std::vector<uint32_t>::const_iterator it1=val.begin(); - std::vector<uint32_t>::const_iterator it2=val.end(); - - for ( ; it1!=it2; ++it1) text << " " << (*it1); + for (uint32_t v : val) { + text << " " << v; + } } diff --git a/TileCalorimeter/TileEvent/src/TileSimData.cxx b/TileCalorimeter/TileEvent/src/TileSimData.cxx index ff7f15f1feb..57caa20da65 100755 --- a/TileCalorimeter/TileEvent/src/TileSimData.cxx +++ b/TileCalorimeter/TileEvent/src/TileSimData.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ //***************************************************************************** @@ -34,8 +34,8 @@ TileSimData::TileSimData( const Identifier& id ) : m_pmt_id( id ) } TileSimData::TileSimData( const HWIdentifier& HWid ) + : m_pmt_id (s_cabling->h2s_pmt_id(HWid)) { - m_pmt_id = s_cabling->h2s_pmt_id(HWid); } void TileSimData::print() const -- GitLab