Skip to content
Snippets Groups Projects
Commit 4ddf341b authored by Sergei Zharko's avatar Sergei Zharko
Browse files

L1Assert introduced

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