From 79c22475fb52660e890ea0fe58e24b2002ef8c7f Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Thu, 8 Oct 2020 14:24:06 -0400 Subject: [PATCH] TileRecUtils: Enable thread-safety checking. Enable thread-safety checking. Fix resulting warnings. --- .../TileRecUtils/ATLAS_CHECK_THREAD_SAFETY | 1 + .../TileRecUtils/TileCorrelation.h | 19 ++---- .../TileRecUtils/TileRawChannelBuilder.h | 9 ++- .../TileRawChannelBuilderOpt2FilterLookup.h | 10 +++- .../TileRecUtils/src/TileCorrelation.cxx | 6 +- .../src/TileRawChannelBuilder.cxx | 58 +++++++++---------- .../src/TileRawChannelBuilderOpt2Filter.cxx | 3 +- .../TileRecUtils/src/TileRawChannelMaker.cxx | 4 +- .../src/TileRawCorrelatedNoise.cxx | 13 +++-- 9 files changed, 59 insertions(+), 64 deletions(-) create mode 100644 TileCalorimeter/TileRecUtils/TileRecUtils/ATLAS_CHECK_THREAD_SAFETY diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/ATLAS_CHECK_THREAD_SAFETY b/TileCalorimeter/TileRecUtils/TileRecUtils/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 00000000000..a463031defd --- /dev/null +++ b/TileCalorimeter/TileRecUtils/TileRecUtils/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +TileCalorimeter/TileRecUtils diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileCorrelation.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileCorrelation.h index aaeb3367dca..5882129a45b 100644 --- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileCorrelation.h +++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileCorrelation.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ //************************************************************************************* @@ -15,7 +15,8 @@ // ************************************************************************************ -#include "AthenaKernel/MsgStreamMember.h" +#include "AthenaBaseComps/AthMessaging.h" +#include "AthenaKernel/getMessageSvc.h" class TileHWID; @@ -24,8 +25,9 @@ class TileHWID; #include <fstream> -class TileCorrelation { - +class TileCorrelation + : public AthMessaging +{ public: TileCorrelation(); ~TileCorrelation(); @@ -54,10 +56,6 @@ class TileCorrelation { void buildPulseShape(std::vector<double> &pulseShape, std::vector<double> &pulseShapeY, std::vector<double> &pulseShapeT, int dignum); - /// Log a message using the Athena controlled logging system - MsgStream& msg( MSG::Level lvl ) const { return m_msg << lvl; } - /// Check whether the logging system is active at the provided verbosity level - bool msgLvl( MSG::Level lvl ) const { return m_msg.get().level() <= lvl; } private: //double SS(9,9); @@ -80,11 +78,6 @@ class TileCorrelation { double m_S11[4][64][48][2][9]; double m_S12[4][64][48][2][9]; double m_S22[4][64][48][2][9]; - - // const TileInfo *m_tileInfo; - - /// Private message stream member - mutable Athena::MsgStreamMember m_msg; }; diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h index bf972da9f99..880ae1c3401 100644 --- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h +++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h @@ -132,7 +132,7 @@ class TileRawChannelBuilder: public AthAlgTool { static const char* BadPatternName(float ped); - static void resetDrawer(); + void resetDrawer(); void resetOverflows(void); Overflows_t& getOverflowedChannels(void); std::string getTileRawChannelContainerID(void); @@ -226,10 +226,9 @@ class TileRawChannelBuilder: public AthAlgTool { static const int MAX_CHANNELS = 48; static const int MAX_DMUS = 16; - static int s_error[MAX_CHANNELS]; - static int s_dmuerr[MAX_DMUS]; - static int s_lastDrawer; - static bool s_badDrawer; + int m_error[MAX_CHANNELS]; + int m_lastDrawer = -1; + bool m_badDrawer = false; bool m_notUpgradeCabling; diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderOpt2FilterLookup.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderOpt2FilterLookup.h index a1380655626..10d58794dcb 100644 --- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderOpt2FilterLookup.h +++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderOpt2FilterLookup.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef TILERECUTILS_TILERAWCHANNELBUILDEROPT2FILTERLOOKUP_H @@ -15,6 +15,9 @@ // 25-jul-2007 ////////////////////////////////////////////////////////////////////// +namespace TileRawChannelBuilderOpt2 { + +const unsigned short lookup[2401]={ 0x000e, 0x8000, 0x4000, 0x2aab, 0x2000, 0x199a, 0x1555, 0x1249, 0x1000, 0x0e39, 0x0ccd, @@ -256,6 +259,9 @@ unsigned short lookup[2401]={ 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, -0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e }; +0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e, 0x000e }; + +} // namespace TileRawChannelBuilderOpt2 + #endif diff --git a/TileCalorimeter/TileRecUtils/src/TileCorrelation.cxx b/TileCalorimeter/TileRecUtils/src/TileCorrelation.cxx index d190eb56099..19216632e48 100644 --- a/TileCalorimeter/TileRecUtils/src/TileCorrelation.cxx +++ b/TileCalorimeter/TileRecUtils/src/TileCorrelation.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ //////////////////////////////////////// @@ -35,7 +35,8 @@ //////////////////////////////////////// TileCorrelation::TileCorrelation() - : m_SS() + : AthMessaging (Athena::getMessageSvc(), "TileCorrelation") + , m_SS() , m_S() , m_R() , m_corr() @@ -52,7 +53,6 @@ TileCorrelation::TileCorrelation() , m_S11() , m_S12() , m_S22() - , m_msg("TileCorrelation") { } diff --git a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx index 76f01e7108f..e97efe737f7 100644 --- a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx +++ b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx @@ -25,15 +25,10 @@ const InterfaceID& TileRawChannelBuilder::interfaceID() { return IID_ITileRawChannelBuilder; } -int TileRawChannelBuilder::s_error[MAX_CHANNELS] = {0}; -int TileRawChannelBuilder::s_dmuerr[MAX_DMUS] = {0}; -int TileRawChannelBuilder::s_lastDrawer = -1; -bool TileRawChannelBuilder::s_badDrawer = false; - void TileRawChannelBuilder::resetDrawer() { - s_lastDrawer = -1; - s_badDrawer = false; + m_lastDrawer = -1; + m_badDrawer = false; } void TileRawChannelBuilder::resetOverflows() { @@ -76,8 +71,7 @@ TileRawChannelBuilder::TileRawChannelBuilder(const std::string& type , m_tileInfo(nullptr) { resetDrawer(); - memset(s_error, 0, sizeof(s_error)); - memset(s_dmuerr, 0, sizeof(s_dmuerr)); + memset(m_error, 0, sizeof(m_error)); declareProperty("calibrateEnergy", m_calibrateEnergy = false); declareProperty("correctTime", m_correctTime = false); @@ -291,28 +285,28 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, int ros = (frag >> 8); int drawer = (frag & 0xff); - s_lastDrawer = frag; + m_lastDrawer = frag; - memset(s_error, 0, sizeof(s_error)); - memset(s_dmuerr, 0, sizeof(s_dmuerr)); + memset(m_error, 0, sizeof(m_error)); + int dmuerr[MAX_DMUS] = {0}; int nch = 0; bool bigain = DQstatus->isBiGain(); if (!bigain) { // in bigain runs we don't have DQ status fragment for (int ch = 0; ch < MAX_CHANNELS; ch += 3) { if (!DQstatus->isAdcDQgood(ros, drawer, ch, 0)) { - s_error[ch + 2] = s_error[ch + 1] = s_error[ch] = -3; - s_dmuerr[ch / 3] = 3; + m_error[ch + 2] = m_error[ch + 1] = m_error[ch] = -3; + dmuerr[ch / 3] = 3; nch += 3; } } } if (nch == MAX_CHANNELS) { // all bad - nothing to do - s_badDrawer = true; + m_badDrawer = true; ATH_MSG_VERBOSE( "Drawer 0x" << MSG::hex << frag << MSG::dec << " is bad - skipping bad patterns check " ); return; } else { - s_badDrawer = false; + m_badDrawer = false; ATH_MSG_VERBOSE( "Drawer 0x" << MSG::hex << frag << MSG::dec << " looking for bad patterns in digits" ); } @@ -330,7 +324,7 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, int channel = m_tileHWID->channel(adcId); int gain = m_tileHWID->adc(adcId); - if (s_error[channel]) { + if (m_error[channel]) { ATH_MSG_VERBOSE( "BadCh " << ros << "/" << drawer << "/" << channel @@ -342,9 +336,9 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, if (err) { - s_error[channel] = err; + m_error[channel] = err; if (err > -5) { - ++s_dmuerr[channel / 3]; + ++dmuerr[channel / 3]; ++nchbad[channel / 24]; } @@ -374,7 +368,7 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, } else { if (mindig < 0.01) err += 1; if (maxdig > m_ADCmaxMinusEps) err += 2; - if (err) s_error[channel] = err - 10; + if (err) m_error[channel] = err - 10; } } } @@ -385,11 +379,11 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, int ndmubad[2] = { 0, 0 }; int dmu = 0; for (; dmu < MAX_DMUS / 2; ++dmu) { // first half - if (s_dmuerr[dmu] > 1) + if (dmuerr[dmu] > 1) ++ndmubad[0]; // count DMUs with at least two bad channels } for (; dmu < MAX_DMUS; ++dmu) { // second half - if (s_dmuerr[dmu] > 1) + if (dmuerr[dmu] > 1) ++ndmubad[1]; // count DMUs with at least two bad channels } @@ -412,16 +406,16 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, if (printall) { msg(MSG::VERBOSE) << "nDMuErr "; for (int d = 0; d < MAX_DMUS; ++d) { - msg(MSG::VERBOSE) << " " << s_dmuerr[d]; + msg(MSG::VERBOSE) << " " << dmuerr[d]; } msg(MSG::VERBOSE) << " total " << ndmubad[p] << " errors" << endmsg; msg(MSG::VERBOSE) << "ChErr "; int ch = 0; while (ch < MAX_CHANNELS) { - msg(MSG::VERBOSE) << " " << s_error[ch++]; - msg(MSG::VERBOSE) << " " << s_error[ch++]; - msg(MSG::VERBOSE) << " " << s_error[ch++]; + msg(MSG::VERBOSE) << " " << m_error[ch++]; + msg(MSG::VERBOSE) << " " << m_error[ch++]; + msg(MSG::VERBOSE) << " " << m_error[ch++]; msg(MSG::VERBOSE) << " "; } @@ -433,8 +427,8 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, int ch = (p) ? MAX_CHANNELS / 2 : 0; int chmax = (p) ? MAX_CHANNELS : MAX_CHANNELS / 2; for (; ch < chmax; ++ch) { - if (s_error[ch] == 0 || s_error[ch] < -5) { // channel was good before - s_error[ch] = -4; + if (m_error[ch] == 0 || m_error[ch] < -5) { // channel was good before + m_error[ch] = -4; } } } @@ -443,7 +437,7 @@ void TileRawChannelBuilder::fill_drawer_errors(const EventContext& ctx, } const char * TileRawChannelBuilder::BadPatternName(float ped) { - static const char * errname[25] = { + static const char * const errname[25] = { "-10 - good signal", "-9 - underflow", "-8 - overflow", @@ -482,7 +476,7 @@ StatusCode TileRawChannelBuilder::build(const TileDigitsCollection* coll) int frag = coll->identify(); // make sure that error array is up-to-date - if (frag != s_lastDrawer && m_notUpgradeCabling) { + if (frag != m_lastDrawer && m_notUpgradeCabling) { fill_drawer_errors(ctx, coll); } @@ -496,13 +490,13 @@ StatusCode TileRawChannelBuilder::build(const TileDigitsCollection* coll) if (m_notUpgradeCabling) { - int err = s_error[m_tileHWID->channel(rch->adc_HWID())]; + int err = m_error[m_tileHWID->channel(rch->adc_HWID())]; if (err) { if (err == -8 || err == -7) m_overflows.push_back(std::make_pair(rch, (*digitItr))); float ped = rch->pedestal() + 100000 + 10000 * err; rch->setPedestal(ped); - if (msgLvl(MSG::VERBOSE) && !s_badDrawer) { + if (msgLvl(MSG::VERBOSE) && !m_badDrawer) { if (err < -5) { msg(MSG::VERBOSE) << "BadCh " << m_tileHWID->to_string(rch->adc_HWID()) << " warning = " << BadPatternName(ped) << endmsg; diff --git a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx index 5ef745a88fa..de60aaa50c6 100644 --- a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx +++ b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ @@ -636,6 +636,7 @@ double TileRawChannelBuilderOpt2Filter::compute(int ros, int drawer, int channel } if (m_emulateDsp) { + using TileRawChannelBuilderOpt2::lookup; round = 1 << (ascale - 2); short e2Dsp = (unsigned short) ((dspEnergy + round) >> (ascale - 1)); size_t OptInd = abs(e2Dsp); diff --git a/TileCalorimeter/TileRecUtils/src/TileRawChannelMaker.cxx b/TileCalorimeter/TileRecUtils/src/TileRawChannelMaker.cxx index 192a4114af8..6a88ab6f4d3 100644 --- a/TileCalorimeter/TileRecUtils/src/TileRawChannelMaker.cxx +++ b/TileCalorimeter/TileRecUtils/src/TileRawChannelMaker.cxx @@ -94,11 +94,9 @@ StatusCode TileRawChannelMaker::execute() { // create RawChannel Containers for all sub-algs for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) { ATH_CHECK( rawChannelBuilder->createContainer() ); + rawChannelBuilder->resetDrawer(); } - //make sure that we clean memory about errors in a drawer - TileRawChannelBuilder::resetDrawer(); - // clean memory about overflows if (m_fitOverflow) { for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) { diff --git a/TileCalorimeter/TileRecUtils/src/TileRawCorrelatedNoise.cxx b/TileCalorimeter/TileRecUtils/src/TileRawCorrelatedNoise.cxx index 9ebe87b255e..e051276bb16 100644 --- a/TileCalorimeter/TileRecUtils/src/TileRawCorrelatedNoise.cxx +++ b/TileCalorimeter/TileRecUtils/src/TileRawCorrelatedNoise.cxx @@ -101,6 +101,7 @@ StatusCode TileRawCorrelatedNoise::initialize() { const char* TOKENS = { " \t\n" }; // read Matrix int dima = 48; + char* saveptr = nullptr; for (int line = 0; line < dima; line++) { if (fgets(buff, sizeof(buff), alpha_file) != NULL) { ATH_MSG_DEBUG( "line " << line << " is " << buff ); @@ -110,9 +111,9 @@ StatusCode TileRawCorrelatedNoise::initialize() { // read value int error = 0; if (column == 0) { - if ((word = strtok(buff, TOKENS)) == NULL) error = 1; + if ((word = strtok_r(buff, TOKENS, &saveptr)) == NULL) error = 1; } else { - if ((word = strtok(NULL, TOKENS)) == NULL) error = 1; + if ((word = strtok_r(NULL, TOKENS, &saveptr)) == NULL) error = 1; } double pippo; @@ -181,6 +182,7 @@ StatusCode TileRawCorrelatedNoise::initialize() { const char* TOKENS = { " \t\n" }; // read Vector int dima = 48; + char* saveptr = nullptr; for (int line = 0; line < dima; line++) { if (fgets(buff, sizeof(buff), mean_file) != NULL) { ATH_MSG_DEBUG( "line " << line << " is " << buff ); @@ -190,9 +192,9 @@ StatusCode TileRawCorrelatedNoise::initialize() { // read value int error = 0; if (Sample == 0) { - if ((word = strtok(buff, TOKENS)) == NULL) error = 1; + if ((word = strtok_r(buff, TOKENS, &saveptr)) == NULL) error = 1; } else { - if ((word = strtok(NULL, TOKENS)) == NULL) error = 1; + if ((word = strtok_r(NULL, TOKENS, &saveptr)) == NULL) error = 1; } double pippo; if (error) @@ -271,7 +273,8 @@ StatusCode TileRawCorrelatedNoise::initialize() { if (*buff == '!' || *buff == '*') continue; // read value double pippo; - if ((word = strtok(buff, TOKENS)) == NULL) pippo = 0; + char* saveptr = nullptr; + if ((word = strtok_r(buff, TOKENS, &saveptr)) == NULL) pippo = 0; else pippo = atof(word); // read value ATH_MSG_VERBOSE ( "elem is " << pippo ); -- GitLab