From bba0832807750dcc95cca0fcb679a930c049a445 Mon Sep 17 00:00:00 2001 From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de> Date: Tue, 30 Jan 2024 12:58:50 +0000 Subject: [PATCH] online: Replace L_(fatal) with FatalError exception. --- algo/base/Exceptions.h | 31 ++++++++++++++++----------- algo/detectors/bmon/ReadoutConfig.cxx | 7 +++--- algo/detectors/sts/HitfinderChain.cxx | 31 ++++++++++----------------- algo/detectors/tof/ReadoutConfig.cxx | 18 +++++++--------- reco/app/cbmreco/main.cxx | 17 +++++++-------- 5 files changed, 49 insertions(+), 55 deletions(-) diff --git a/algo/base/Exceptions.h b/algo/base/Exceptions.h index a5ab73ee02..7246d24c70 100644 --- a/algo/base/Exceptions.h +++ b/algo/base/Exceptions.h @@ -11,22 +11,27 @@ namespace cbm::algo { - /** - * @brief Base class for exceptions. - * - * @note Should not be thrown directly. Use one of the derived classes instead. - */ - struct Exception : std::runtime_error { - template<typename... Args> - Exception(std::string_view fmt, Args&&... args) : std::runtime_error(fmt::format(fmt, std::forward<Args>(args)...)) - { - } - }; + + namespace detail + { + /** + * @brief Base class for exceptions. + * + * @note Should not be thrown directly. Use one of the derived classes instead. + */ + struct Exception : std::runtime_error { + template<typename... Args> + Exception(std::string_view fmt, Args&&... args) + : std::runtime_error(fmt::format(fmt, std::forward<Args>(args)...)) + { + } + }; + } // namespace detail /** * @brief Indicates an unrecoverable error. Should tear down the process. */ - struct FatalError : Exception { + struct FatalError : detail::Exception { using Exception::Exception; }; @@ -34,7 +39,7 @@ namespace cbm::algo * Indicates an error during timeslice processing. Timeslice will be discarded. * Processing can continue with new timeslice. */ - struct ProcessingError : Exception { + struct ProcessingError : detail::Exception { using Exception::Exception; }; diff --git a/algo/detectors/bmon/ReadoutConfig.cxx b/algo/detectors/bmon/ReadoutConfig.cxx index b8a14ef97b..a7f37185b2 100644 --- a/algo/detectors/bmon/ReadoutConfig.cxx +++ b/algo/detectors/bmon/ReadoutConfig.cxx @@ -4,12 +4,13 @@ #include "ReadoutConfig.h" -#include "AlgoFairloggerCompat.h" #include "CbmTofAddress.h" +#include "Exceptions.h" #include "gDpbMessv100.h" #include <bitset> #include <iomanip> +#include <log.hpp> #include <fmt/format.h> @@ -128,11 +129,11 @@ namespace cbm::algo::bmon break; } default: { - LOG(error) << "Invalid Bmon Type specifier for GBTx " << std::setw(2) << uGbtx << ": " << rpcType[uGbtx]; + L_(error) << "Invalid Bmon Type specifier for GBTx " << std::setw(2) << uGbtx << ": " << rpcType[uGbtx]; } } // switch (rpcType[uGbtx]) if ((int32_t)(uCh - uCh0) != numFebsPerComp * numAsicsPerFeb * numChanPerAsic / 2) { - LOG(fatal) << "Bmon mapping error for Gbtx " << uGbtx << ", diff = " << uCh - uCh0; + throw FatalError("Bmon mapping error for Gbtx {}, diff = {}", uGbtx, uCh - uCh0); } } } diff --git a/algo/detectors/sts/HitfinderChain.cxx b/algo/detectors/sts/HitfinderChain.cxx index a3b3849206..906877f4f0 100644 --- a/algo/detectors/sts/HitfinderChain.cxx +++ b/algo/detectors/sts/HitfinderChain.cxx @@ -719,16 +719,14 @@ void sts::HitfinderChain::EnsureDigiOffsets(DigiMap& digi) // Front for (size_t m = 0; m < nModules * 2; m++) { if (digiOffset[m] != offset) { - L_(fatal) << "Module " << m << ": Digi offset mismatch: " << digiOffset[m] << " != " << offset; - std::abort(); + throw FatalError("Module {}: Digi offset mismatch: {} != {}", m, digiOffset[m], offset); } size_t nDigis = digi.nDigisPerModule[m]; offset += nDigis; } if (offset != digiOffset[2 * nModules]) { - L_(fatal) << "Digi offset mismatch: " << digiOffset[2 * nModules] << " != " << offset; - std::abort(); + throw FatalError("Digi offset mismatch: {} != {}", digiOffset[2 * nModules], offset); } } @@ -763,8 +761,7 @@ void sts::HitfinderChain::EnsureDigisSorted() } if (!isSorted) { - L_(fatal) << "Digis are not sorted"; - std::abort(); + throw FatalError("Digis are not sorted"); } } @@ -785,8 +782,7 @@ void sts::HitfinderChain::EnsureChannelOffsets(gsl::span<u32> channelOffsetsByMo if (nDigis == 0) continue; if (channelOffsets[0] != 0) { - L_(fatal) << "Module " << m << ": First channel offset is not 0"; - std::abort(); + throw FatalError("Module {}: First channel offset is not 0", m); } int chan = digis[0].GetChannel(); @@ -805,9 +801,8 @@ void sts::HitfinderChain::EnsureChannelOffsets(gsl::span<u32> channelOffsetsByMo for (int i = 0; i < nChannels; i++) { if (channelOffsets[i] != expectedChannelOffsets[i]) { - L_(fatal) << "Module " << m << ": Channel offset for channel " << i << " is " << channelOffsets[i] - << " but should be " << expectedChannelOffsets[i]; - std::abort(); + throw FatalError("Module {}: Channel offset for channel {} is {} but should be {}", m, i, channelOffsets[i], + expectedChannelOffsets[i]); } } } @@ -823,13 +818,11 @@ void sts::HitfinderChain::EnsureClustersSane(gsl::span<ClusterIdx> hClusterIdx, if (nClusters == 0) continue; if (nClusters < 0) { - L_(fatal) << "Module " << m << " has negative number of clusters " << nClusters; - std::abort(); + throw FatalError("Module {} has negative number of clusters {}", m, nClusters); } if (size_t(nClusters) > fHitfinder.maxClustersPerModule) { - L_(fatal) << "Module " << m << " has " << nClusters << " clusters, but only " << fHitfinder.maxClustersPerModule - << " are allowed"; - std::abort(); + throw FatalError("Module {} has {} clusters, but only {} are allowed", m, nClusters, + fHitfinder.maxClustersPerModule); } auto* clusterIdx = &hClusterIdx[m * fHitfinder.maxClustersPerModule]; @@ -838,13 +831,11 @@ void sts::HitfinderChain::EnsureClustersSane(gsl::span<ClusterIdx> hClusterIdx, auto& cidx = clusterIdx[i]; if (int(cidx.fIdx) < 0 || size_t(cidx.fIdx) >= fHitfinder.maxClustersPerModule) { - L_(fatal) << "Cluster " << i << " of module " << m << " has invalid index " << cidx.fIdx; - std::abort(); + throw FatalError("Cluster {} of module {} has invalid index {}", i, m, cidx.fIdx); } if (cidx.fTime == 0xFFFFFFFF) { - L_(fatal) << "Cluster " << i << " of module " << m << " has invalid time " << cidx.fTime; - std::abort(); + throw FatalError("Cluster {} of module has invalid time {}", i, m, cidx.fTime); } } } diff --git a/algo/detectors/tof/ReadoutConfig.cxx b/algo/detectors/tof/ReadoutConfig.cxx index 1429b00c9a..ebda65c42f 100644 --- a/algo/detectors/tof/ReadoutConfig.cxx +++ b/algo/detectors/tof/ReadoutConfig.cxx @@ -4,12 +4,13 @@ #include "ReadoutConfig.h" -#include "AlgoFairloggerCompat.h" #include "CbmTofAddress.h" +#include "Exceptions.h" #include "gDpbMessv100.h" #include <bitset> #include <iomanip> +#include <log.hpp> using namespace std; @@ -99,9 +100,8 @@ namespace cbm::algo::tof else if (elink < numElinksPerComp) return elink2Asic[elink % numElinksPerCrob] + numElinksPerCrob * (elink / numElinksPerCrob); else { - LOG(fatal) << "CbmMcbm2018TofPar::ElinkIdxToGet4Idx => Index out of bound, " << elink << " vs " - << static_cast<uint32_t>(numElinksPerComp) << ", returning crazy value!"; - return -1; + throw FatalError("CbmMcbm2018TofPar::ElinkIdxToGet4Idx => Index out of bound, {} vs {}, returning crazy value!", + elink, static_cast<uint32_t>(numElinksPerComp)); } } // ------------------------------------------------------------------------- @@ -113,9 +113,8 @@ namespace cbm::algo::tof if (channelInFee < numChanPerFeb) return asic2PadI[channelInFee]; else { - LOG(fatal) << "CbmMcbm2018TofPar::Get4ChanToPadiChan => Index out of bound, " << channelInFee << " vs " - << static_cast<uint32_t>(numChanPerFeb) << ", returning crazy value!"; - return -1; + throw FatalError("CbmMcbm2018TofPar::Get4ChanToPadiChan => Index out of bound, {} vs {}, returning crazy value!", + channelInFee, static_cast<uint32_t>(numChanPerFeb)); } } // ------------------------------------------------------------------------- @@ -180,12 +179,11 @@ namespace cbm::algo::tof break; } default: { - LOG(error) << "Invalid Tof Type specifier for GBTx " << std::setw(2) << uGbtx << ": " << rpcType[uGbtx]; + L_(error) << "Invalid Tof Type specifier for GBTx " << std::setw(2) << uGbtx << ": " << rpcType[uGbtx]; } } // switch (rpcType[uGbtx]) if ((int32_t)(uCh - uCh0) != numFebsPerComp * numAsicsPerFeb * numChanPerAsic / 2) { - LOG(fatal) << "Tof mapping error for Gbtx " << uGbtx << ", diff = " << uCh - uCh0 << ", type " - << rpcType[uGbtx]; + throw FatalError("Tof mapping error for Gbtx {}, diff = {}, type {}", uGbtx, uCh - uCh0, rpcType[uGbtx]); } } // for (UInt_t uGbtx = 0; uGbtx < numCrob; ++uGbtx) } diff --git a/reco/app/cbmreco/main.cxx b/reco/app/cbmreco/main.cxx index 351a893907..b175d7d798 100644 --- a/reco/app/cbmreco/main.cxx +++ b/reco/app/cbmreco/main.cxx @@ -1,7 +1,14 @@ /* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main SPDX-License-Identifier: GPL-3.0-only Authors: Felix Weiglhofer [committer] */ +#include "BuildInfo.h" #include "CbmDigiEvent.h" +#include "Exceptions.h" +#include "Options.h" +#include "Reco.h" +#include "RecoResultsInputArchive.h" +#include "RecoResultsOutputArchive.h" +#include "compat/OpenMP.h" #include <TimesliceAutoSource.hpp> @@ -10,14 +17,6 @@ #include <xpu/host.h> -#include "BuildInfo.h" -#include "Exceptions.h" -#include "Options.h" -#include "Reco.h" -#include "RecoResultsInputArchive.h" -#include "RecoResultsOutputArchive.h" -#include "compat/OpenMP.h" - using namespace cbm::algo; std::shared_ptr<StorableRecoResults> makeStorableRecoResults(const fles::Timeslice& ts, const RecoResults& results) @@ -44,7 +43,7 @@ std::shared_ptr<StorableRecoResults> makeStorableRecoResults(const fles::Timesli bool dumpArchive(const Options& opts) { // Limit the number of events per timeslice to dump to avoid spamming the log - constexpr size_t DumpEventsPerTS = 10; + constexpr size_t DumpEventsPerTS = 10; constexpr size_t DumpHitsPerSensor = 2; constexpr size_t DumpTracksPerTS = 10; -- GitLab