From e1583f36a7a5b0f6d7c1522085cd6e9f3fa513ab Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Thu, 3 Mar 2022 11:01:11 +0100 Subject: [PATCH] L1Algo core: featuring L1Assert --- reco/L1/L1Algo/L1Algo.h | 9 +++++++ reco/L1/L1Algo/L1Assert.h | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 reco/L1/L1Algo/L1Assert.h diff --git a/reco/L1/L1Algo/L1Algo.h b/reco/L1/L1Algo/L1Algo.h index 5f4077e342..670211ee1c 100644 --- a/reco/L1/L1Algo/L1Algo.h +++ b/reco/L1/L1Algo/L1Algo.h @@ -37,7 +37,16 @@ class L1AlgoDraw; //#define MERGE_CLONES +/********************************************************************************* + ************ TEMPORARY MACROS, SHOULD BE REMOVED (TODO!!, S. Zharko) *********** + * */ + #define FEATURING_L1ALGO_INIT 1 // If defined, new initialization will be used, if not - the old one +// Macro: 1 - new track finder loop, other - old track finder loop +#define FEATURING_L1ALGO_CATRACKFINDER_ITERATIONLOOP 1 + +/* * + *********************************************************************************/ #include <array> #include <iomanip> diff --git a/reco/L1/L1Algo/L1Assert.h b/reco/L1/L1Algo/L1Assert.h new file mode 100644 index 0000000000..aface5465a --- /dev/null +++ b/reco/L1/L1Algo/L1Assert.h @@ -0,0 +1,53 @@ +/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Sergey Gorbunov, Sergei Zharko [committer] */ + +/// @file L1Assert.h +/// @author Sergei Zharko +/// @date 22.02.2022 +/// @brief Level-defined assertion functionality +/// +/// This file provides level-dependent assertion mechanism. Two defined macros L1ASSERT(LEVEL, COND) +/// and L1MASSERT(LEVEL, COND, MSG), which will do the assertion for LEVEL >= L1Assert::kAssertionLevel +/// and skip it otherwise. When L1ASSERT(LEVEL, COND) is called the COND expression is printed on the screen. +/// When L + + + +#ifndef L1Assert_h +#define L1Assert_h 1 + +#include "FairLogger.h" + +#if defined(NDEBUG) || defined(L1_NO_ASSERT) +#define L1ASSERT(LEVEL, COND) +#define L1MASSERT(LEVEL, COND, MSG) +#else +#define L1ASSERT(LEVEL, COND) L1Assert::DoAssertion<(LEVEL) >= L1Assert::kAssertionLevel>((LEVEL), (COND), (#COND), __FILE__, __LINE__) +#define L1MASSERT(LEVEL, COND, MSG) L1Assert::DoAssertion<(LEVEL) >= L1Assert::kAssertionLevel>((LEVEL), (COND), (MSG), __FILE__, __LINE__) +#endif // defined(NDEBUG) || defined(L1_NO_ASSERT) + +namespace L1Assert { + constexpr int kAssertionLevel {1}; + + /// Basic template function. Usage: place "level >= L1Assert::kAssertionLevel" + template <bool IsAsserted> + int DoAssertion (int level, bool condition, const char* msg, const char* fileName, int lineNo); + + /// Specialization in case of IsAsserted = true, i.e. the assertion is made + template <> + int DoAssertion<true>(int level, bool condition, const char* msg, const char* fileName, int lineNo) + { + if (!condition) { + LOG(fatal) << "Level " << level << " assertion failed: " << msg << " (" << fileName << " : " << lineNo << ")\n"; + //std::abort(); // Do we need it with LOG(fatal)? + } + return 1; + } + + /// Specialization in case of IsAsserted = false, i.e. the assertion is not made + template <> + int DoAssertion<false>(int level, bool condition, const char* msg, const char* fileName, int lineNo) { return 0 }; +}; + +#endif // L1Assert_h -- GitLab