diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx index 0182c1ad2aa48048e5e532520cd97eed6d0501a7..2526d10a9759fa2907eda0584c3d922de7b1c435 100644 --- a/reco/L1/CbmL1.cxx +++ b/reco/L1/CbmL1.cxx @@ -843,7 +843,7 @@ InitStatus CbmL1::Init() // Step 4: initialize IDs of detectors active in tracking // TODO: temporary for tests, must be initialized somewhere in run_reco.C or similar (S.Zh.) fActiveTrackingDetectorIDs = {L1DetectorID::kMvd, L1DetectorID::kSts}; - //initMan->SetActiveDetectorIDs(fActiveTrackingDetectorIDs); + initMan->SetActiveDetectorIDs(fActiveTrackingDetectorIDs); constexpr double PI = 3.14159265358; // TODO: why cmath is not used? (S.Zh.) diff --git a/reco/L1/L1Algo/L1Assert.h b/reco/L1/L1Algo/L1Assert.h index d285846274741d84b841a92a96ff397a10a4889a..af23e3adabfa1c58fe2fd5a48336af18808a5585 100644 --- a/reco/L1/L1Algo/L1Assert.h +++ b/reco/L1/L1Algo/L1Assert.h @@ -12,12 +12,17 @@ /// and skip it otherwise. When L1ASSERT(LEVEL, COND) is called the COND expression is printed on the screen. /// When L1MASSERT(LEVEL, COND, MSG) is called, the MSG will be printed instead of expression /// +/// Assertion levels: +/// - 0: non-critical code (any kind of algorithm initialization checks, code, which is called once) +/// - 1: semi-critical code (may be called inside the L1 core, but a small number of times) +/// - 2: critical code (possibly called in large loops inside the algorithm) + #ifndef L1Assert_h #define L1Assert_h 1 #include "FairLogger.h" -#if defined(NDEBUG) || defined(L1_NO_ASSERT) +#if defined(NDEBUG) || defined(L1_NO_ASSERT) // TODO: Do we need to add FAST_CODE here? (S.Zharko) #define L1ASSERT(LEVEL, COND) #define L1MASSERT(LEVEL, COND, MSG) #else @@ -29,23 +34,19 @@ namespace L1Assert { - /// Assertion levels - /// 0 - - /// 1 - - /// 2 - - 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); + constexpr int kAssertionLevel {3}; - /// Specialization in case of IsAsserted = true, i.e. the assertion is made + /// Basic template function. Usage: place "level <= L1Assert::kAssertionLevel" as a template parameter template<bool IsAsserted> int DoAssertion(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)? + LOG(fatal) << '\n' + << " ***** Level " << level << " assertion failed: " << '\n' + << " ***** message/condition : " << msg << '\n' + << " ***** file: " << fileName << '\n' + << " ***** line: " << lineNo; + std::abort(); // keep it here, because sometimes LOG(fatal) does not work (for example, in your tester) } return 1; } diff --git a/reco/L1/L1Algo/L1BaseStationInfo.cxx b/reco/L1/L1Algo/L1BaseStationInfo.cxx index 648cb0fd32f06692b5cbb38ff3da68be1c7ebc37..678edac2d55042477ab2bf40e0d4bf3f1fcff1b5 100644 --- a/reco/L1/L1Algo/L1BaseStationInfo.cxx +++ b/reco/L1/L1Algo/L1BaseStationInfo.cxx @@ -17,6 +17,7 @@ #include <FairLogger.h> // L1Algo core +#include "L1Assert.h" #include "L1BaseStationInfo.h" #include "L1Def.h" #include "L1Parameters.h" @@ -137,13 +138,10 @@ void L1BaseStationInfo::Reset() // const L1Station& L1BaseStationInfo::GetL1Station() const { - bool isStationInitialized = fInitController.IsFinalized(); - if (!isStationInitialized) { - LOG(error) - << "L1BaseStationInfo::GetL1Station: attempt to get an L1Staion object from uninitialized L1BaseStation with " - << "stationID = " << fStationID << " and detectorID = " << static_cast<int>(fDetectorID); - assert((!isStationInitialized)); - } + std::stringstream aStream; + aStream << "L1BaseStationInfo::GetL1Station: attempt to get an L1Staion object from uninitialized L1BaseStation with " + << "stationID = " << fStationID << " and detectorID = " << static_cast<int>(fDetectorID); + L1MASSERT(0, fInitController.IsFinalized(), aStream.str().c_str()); return fL1Station; } @@ -209,14 +207,12 @@ void L1BaseStationInfo::SetFieldSlice(const std::function<void(const double (&xy return; } -#ifndef L1_NO_ASSERT // check for zero denominator - L1_ASSERT(fInitController.GetFlag(InitKey::keZ), + L1MASSERT(0, fInitController.GetFlag(InitKey::keZ), "Attempt to set magnetic field slice before setting z position of the station"); - L1_ASSERT(fInitController.GetFlag(InitKey::keXmax), + L1MASSERT(0, fInitController.GetFlag(InitKey::keXmax), "Attempt to set magnetic field slice before Xmax size of the station"); - L1_ASSERT(fInitController.GetFlag(InitKey::keYmax), + L1MASSERT(0, fInitController.GetFlag(InitKey::keYmax), "Attempt to set magnetic field slice before Ymax size of the station"); -#endif // TODO: Change names of variables according to convention (S.Zh.) constexpr int M = L1Parameters::kMaxFieldApproxPolynomialOrder; constexpr int N = L1Parameters::kMaxNFieldApproxCoefficients; @@ -332,9 +328,8 @@ void L1BaseStationInfo::SetFrontBackStripsGeometry(double frontPhi, double front // void L1BaseStationInfo::SetMaterial(double inThickness, double inRL) { -#ifndef L1_NO_ASSERT // check for zero denominator - L1_ASSERT(inRL, "Attempt of entering zero inRL (radiational length) value"); -#endif + L1MASSERT(0, inRL, "Attempt of entering zero inRL (radiational length) value"); + fL1Station.materialInfo.thick = inThickness; fL1Station.materialInfo.RL = inRL; fL1Station.materialInfo.RadThick = fL1Station.materialInfo.thick / fL1Station.materialInfo.RL; diff --git a/reco/L1/L1Algo/L1InitManager.cxx b/reco/L1/L1Algo/L1InitManager.cxx index 9a94d47a8bda5cf14a16486c3614413dc328a09a..99524ed8790e013f1c0d61a2cde584ea529531e7 100644 --- a/reco/L1/L1Algo/L1InitManager.cxx +++ b/reco/L1/L1Algo/L1InitManager.cxx @@ -9,9 +9,10 @@ ***********************************************************************************************************/ #include "L1InitManager.h" +#include "L1Assert.h" #include <algorithm> - +#include <sstream> //----------------------------------------------------------------------------------------------------------------------- // L1InitManager::L1InitManager(L1Parameters* pParameters) : fpParameters(pParameters) {} @@ -22,26 +23,17 @@ void L1InitManager::AddStation(const L1BaseStationInfo& inStation) { // Check if other fields were defined already // Active detector IDs - if (!fInitController.GetFlag(InitKey::keActiveDetectorIDs)) { - LOG(error) << "L1InitManager::AddStation: station initialization called before the active detectors set had been " - "initialized"; - assert((fInitController.GetFlag(InitKey::keActiveDetectorIDs))); - } + + L1MASSERT(0, fInitController.GetFlag(InitKey::keActiveDetectorIDs), + "Attempt to add a station info before the active detetors set had been initialized"); // Number of stations check - if (!fInitController.GetFlag(InitKey::keStationsNumberCrosscheck)) { - LOG(error) - << "L1InitManager::AddStation: station initialization called before the numbers of stations for each detector " - << "had been initialized"; - assert((fInitController.GetFlag(InitKey::keStationsNumberCrosscheck))); - } + L1MASSERT(0, fInitController.GetFlag(InitKey::keStationsNumberCrosscheck), + "Attempt to add a station info before the numbers of stations for each detector had been initialized"); // Field function - if (!fInitController.GetFlag(InitKey::keFieldFunction)) { - LOG(error) - << "L1InitManager::AddStation: station initialization called before the magnetic field function was intialized"; - assert((fInitController.GetFlag(InitKey::keFieldFunction))); - } + L1MASSERT(0, fInitController.GetFlag(InitKey::keFieldFunction), + "Attempt to add a station info before the magnetic field function had been intialized"); // Check activeness of this station type bool isDetectorActive = fActiveDetectorIDs.find(inStation.GetDetectorID()) != fActiveDetectorIDs.end(); @@ -49,28 +41,27 @@ void L1InitManager::AddStation(const L1BaseStationInfo& inStation) // initialize magnetic field slice L1BaseStationInfo inStationCopy = L1BaseStationInfo(inStation); // make a copy of station so it can be initialized inStationCopy.SetFieldSlice(fFieldFunction); - bool isStationInitialized = inStationCopy.GetInitController().IsFinalized(); - if (!isStationInitialized) { + // Check station init + { LOG(debug) << "L1InitManager::AddStation:(original) L1BaseStationInfo " << inStation.GetInitController().ToString(); LOG(debug) << "L1InitManager::AddStation:(copy) L1BaseStationInfo " << inStation.GetInitController().ToString(); - LOG(error) << "L1InitManager::AddStation: attempt to add incompletely initialized object with detectorID = " - << static_cast<int>(inStationCopy.GetDetectorID()) - << " and stationID = " << inStationCopy.GetStationID(); - assert((isStationInitialized)); + std::stringstream aStream; + aStream << "Attempt to add an incompletely initialized station info object (detectorID = " + << static_cast<int>(inStationCopy.GetDetectorID()) + << ", stationID = " << inStationCopy.GetStationID() << ")"; + L1MASSERT(0, inStationCopy.GetInitController().IsFinalized(), aStream.str().c_str()); } // insert the station in a set auto insertionResult = fStationsInfo.insert(std::move(inStationCopy)); - if (!insertionResult.second) { - LOG(error) << "L1InitManager::AddStation: attempt to insert a dublicating L1BaseStationInfo with StationID = " - << inStation.GetStationID() << " and DetectorID = " << static_cast<int>(inStation.GetDetectorID()) - << ":"; - LOG(error) << ">>> Already inserted L1BaseStationInfo object:"; - insertionResult.first->Print(); - LOG(error) << ">>> A dublicating L1BaseStationInfo object:"; - inStation.Print(); - assert((insertionResult.second)); + // Check insertion + { + std::stringstream aStream; + aStream << "Attempt to add a dublicating station info object (detectorID = " + << static_cast<int>(inStationCopy.GetDetectorID()) + << ", stationID = " << inStationCopy.GetStationID() << ")"; + L1MASSERT(0, insertionResult.second, aStream.str().c_str()); } } LOG(debug) << "L1InitManager: adding a station with stationID = " << inStation.GetStationID() @@ -107,18 +98,12 @@ void L1InitManager::InitTargetField(double zStep) } // Check for field function - if (!fInitController.GetFlag(InitKey::keFieldFunction)) { - LOG(error) << "L1InitManager::InitTargetField: attempt to initialze the field value and field region near " - << "target before initializing field function"; - assert((fInitController.GetFlag(InitKey::keFieldFunction))); - } + L1MASSERT(0, fInitController.GetFlag(InitKey::keFieldFunction), + "Attempt to initialze the field value and field region near target before initializing field function"); // Check for target defined - if (!fInitController.GetFlag(InitKey::keTargetPos)) { - LOG(error) << "L1InitManager::InitTargetField: attempt to initialize the field value and field region near " - << "target before the target position initialization"; - assert((fInitController.GetFlag(InitKey::keTargetPos))); - } + L1MASSERT(0, fInitController.GetFlag(InitKey::keTargetPos), + "Attempt to initialize the field value and field region near target before the target position initialization"); constexpr int nDimensions {3}; constexpr int nPointsNodal {3}; @@ -164,20 +149,17 @@ void L1InitManager::PrintStations(int verbosityLevel) const // void L1InitManager::PushBackCAIteration(const L1CAIteration& iteration) { - // TODO: probably some checks must be inserted here - if (!fInitController.GetFlag(InitKey::keCAIterationsNumberCrosscheck)) { - LOG(error) << "L1InitManager::PushBackCAIteration: attempt to push back a CA track finder iteration before the " - << "number of iterations was defined"; - assert((fInitController.GetFlag(InitKey::keCAIterationsNumberCrosscheck))); - } - //fCAIterationsContainer.push_back(iteration); + // TODO: probably some checks must be inserted here (S.Zharko) + L1MASSERT(0, fInitController.GetFlag(InitKey::keCAIterationsNumberCrosscheck), + "Attempt to push back a CA track finder iteration before the number of iterations was defined"); + L1Vector<L1CAIteration>& iterationsContainer = fpParameters->CAIterationsContainer(); iterationsContainer.push_back(iteration); } //----------------------------------------------------------------------------------------------------------------------- // -void L1InitManager::SetActiveDetectorIDs(const std::set<L1DetectorID>& detectorIDs) +void L1InitManager::SetActiveDetectorIDs(const L1DetectorIDSet_t& detectorIDs) { // TODO: To think about redifinition possibilities: should it be allowed or not? (S.Zh.) fActiveDetectorIDs = detectorIDs; @@ -256,22 +238,21 @@ void L1InitManager::TransferL1StationArray(std::array<L1Station, L1Parameters::k // // 1) Check, if all fields of this were initialized // - if (!fInitController.IsFinalized()) { - LOG(error) << "L1InitManager::TransferL1StationArray: attempt to pass L1Station array to L1Algo core before " - << "all necessary fields initialization"; - LOG(error) << "L1InitManager " << fInitController.ToString(); - assert((fInitController.IsFinalized())); + { + std::stringstream aStream; + aStream << "Attempt to pass L1Station array to L1Algo core before all necessary fields initialization\n" + << "L1InitManager " << fInitController.ToString(); + L1MASSERT(0, fInitController.IsFinalized(), aStream.str().c_str()); } - // // 2) Check, if destinationArraySize is enough for the transfer // - int nStationsTotal = this->GetStationsNumber(); - bool ifDestinationArraySizeOk = nStationsTotal <= static_cast<int>(destinationArray.size()); - if (!ifDestinationArraySizeOk) { - LOG(error) << "L1InitManager::TransferL1StationArray: destination array size (" << destinationArray.size() - << ") is smaller then actual number of active tracking stations (" << nStationsTotal << ")"; - assert((ifDestinationArraySizeOk)); + { + int nStationsTotal = this->GetStationsNumber(); + std::stringstream aStream; + aStream << "Destination array size (" << destinationArray.size() + << ") is smaller then the actual number of active tracking stations (" << nStationsTotal << ")"; + L1MASSERT(0, nStationsTotal <= static_cast<int>(destinationArray.size()), aStream.str().c_str()); } auto destinationArrayIterator = destinationArray.begin(); @@ -326,24 +307,21 @@ void L1InitManager::CheckStationsInfoInit() ifInitPassed = false; } } // loop over active detectors: end - - if (!ifInitPassed) { - LOG(error) << "L1InitManager::IsStationsInfo: initialization failed"; - assert((ifInitPassed)); - } - + L1MASSERT(0, ifInitPassed, "Station info initialization failed"); + // // 2) Check for maximum allowed number of stations // int nStationsTotal = GetStationsNumber(); if (nStationsTotal > L1Parameters::kMaxNstations) { - LOG(fatal) << "Actual total number of registered stations (" << nStationsTotal - << ") is larger then designed one (" << L1Parameters::kMaxNstations - << "). Please, select another set of active tracking detectors"; + std::stringstream aStream; + aStream << "Actual total number of registered stations (" << nStationsTotal + << ") is larger then designed one (" << L1Parameters::kMaxNstations + << "). Please, select another set of active tracking detectors"; // TODO: We have to provide an instruction of how to increase the kMaxNstations // number keeping the code consistent (S.Zharko) ifInitPassed = false; - assert((nStationsTotal <= L1Parameters::kMaxNstations)); + L1MASSERT(0, false, aStream.str().c_str()); } } fInitController.SetFlag(InitKey::keStationsInfo, ifInitPassed);