From 6d015a2378052fbea11e9711a50b35002239f804 Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Tue, 22 Sep 2020 16:17:28 -0400 Subject: [PATCH] CaloUtils: Thread-safety cleanup. Clean up CaloTowerBuilderToolTestAlg, allowing it to be checked. --- Calorimeter/CaloUtils/CMakeLists.txt | 2 +- .../src/CaloTowerBuilderToolTestAlg.cxx | 39 ++----------------- .../src/CaloTowerBuilderToolTestAlg.h | 10 ++--- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/Calorimeter/CaloUtils/CMakeLists.txt b/Calorimeter/CaloUtils/CMakeLists.txt index 709f5a9381a..bcf8db8424f 100644 --- a/Calorimeter/CaloUtils/CMakeLists.txt +++ b/Calorimeter/CaloUtils/CMakeLists.txt @@ -12,7 +12,7 @@ atlas_add_library( CaloUtilsLib CaloUtils/*.h CaloUtils/*.icc src/*.h src/*.cxx PUBLIC_HEADERS CaloUtils PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} LINK_LIBRARIES AthenaBaseComps AthenaKernel CaloConditions CaloDetDescrLib CaloEvent CaloGeoHelpers CaloIdentifier CaloInterfaceLib CxxUtils FourMom GaudiKernel Navigation StoreGateLib xAODCaloEvent - PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${CLHEP_LIBRARIES} GeoModelInterfaces Identifier SGTools ) + PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${CLHEP_LIBRARIES} GeoModelInterfaces Identifier SGTools TestTools ) atlas_add_component( CaloUtils src/components/*.cxx LINK_LIBRARIES CaloUtilsLib ) diff --git a/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.cxx b/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.cxx index ea5bc10ca8d..d2365b7d6fc 100644 --- a/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.cxx +++ b/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.cxx @@ -1,8 +1,6 @@ /* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ - -// $Id$ /** * @file CaloTowerBuilderToolTestAlg.cxx * @author scott snyder <snyder@bnl.gov> @@ -12,9 +10,6 @@ #undef NDEBUG -//This is a test so no need to be thread safe -#include "CxxUtils/checker_macros.h" -ATLAS_NO_CHECK_FILE_THREAD_SAFETY; #include "CaloTowerBuilderToolTestAlg.h" #include "CaloUtils/CaloTowerBuilderTool.h" @@ -22,6 +17,7 @@ ATLAS_NO_CHECK_FILE_THREAD_SAFETY; #include "CaloEvent/CaloTowerContainer.h" #include "CaloDetDescr/CaloDetDescrManager.h" #include "AthenaKernel/errorcheck.h" +#include "TestTools/random.h" #include "CLHEP/Units/SystemOfUnits.h" #include <cstdlib> #include <iostream> @@ -35,34 +31,6 @@ using CLHEP::GeV; namespace { -// Dufus-quality RNG, using LCG. Constants from numerical recipies. -// I don't particularly care about RNG quality here, just about -// getting something that's reproducible. -#include <cstdint> -uint32_t seed = 1; -uint32_t rngmax = static_cast<uint32_t> (-1); -uint32_t rng() -{ - seed = (1664525*seed + 1013904223); - return seed; -} - -float randf (float rmax, float rmin = 0) -{ - return static_cast<float>(rng()) / rngmax * (rmax-rmin) + rmin; -} -int randi (int rmax, int rmin = 0) -{ - return static_cast<int> (randf(rmax, rmin)); -} - -struct RNG -{ - int operator() (int n) const { return randi (n); } -}; -//RNG stlrand; - - bool comp (double x1, double x2, double thresh = 1e-6) { double den = std::abs(x1) + std::abs(x2); @@ -82,7 +50,8 @@ CaloTowerBuilderToolTestAlg::CaloTowerBuilderToolTestAlg (const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm (name, pSvcLocator), - m_builder ("CaloTowerBuilderTool") + m_builder ("CaloTowerBuilderTool"), + m_seed (1) { } @@ -115,7 +84,7 @@ CaloTowerBuilderToolTestAlg::make_cells() for (const CaloDetDescrElement* dde : ddman->element_range (subcalo)) { - float energy = randf (100*GeV); + float energy = Athena_test::randf_seed (m_seed, 100*GeV); cells->push_back (new CaloCell (dde, energy, 0, 0, 0, CaloGain::LARMEDIUMGAIN) ); } diff --git a/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.h b/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.h index 1c6516f292b..59d909b11bd 100644 --- a/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.h +++ b/Calorimeter/CaloUtils/src/CaloTowerBuilderToolTestAlg.h @@ -1,10 +1,7 @@ // This file's extension implies that it's C, but it's really -*- C++ -*-. - /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ - -// $Id$ /** * @file CaloTowerBuilderToolTestAlg.h * @author scott snyder <snyder@bnl.gov> @@ -23,9 +20,10 @@ #include "CaloIdentifier/CaloCell_ID.h" #include "GaudiKernel/ToolHandle.h" #include <vector> +#include <cstdint> class CaloCellContainer; class CaloTowerContainer; -class ICaloTowerBuilderToolBase; +class ICaloTowerBuilderToolBase; class CaloTowerBuilderToolTestAlg @@ -61,6 +59,8 @@ private: ToolHandle<ICaloTowerBuilderToolBase> m_builder; std::vector<CaloCell_ID::SUBCALO> m_calos; CaloTowerSeg m_seg; + + uint32_t m_seed; }; -- GitLab