diff --git a/algo/ca/core/pars/CaInitManager.cxx b/algo/ca/core/pars/CaInitManager.cxx index 21106d195c8ea11f7e1ae809c839a1d7496113d7..0a56fdc9caa866db86489fd4f43e931ff606e805 100644 --- a/algo/ca/core/pars/CaInitManager.cxx +++ b/algo/ca/core/pars/CaInitManager.cxx @@ -32,7 +32,9 @@ void InitManager::AddStation(const StationInitializer& inStation) { // TODO: SZh 15.08.2023: Replace L1MASSERT with throw logic_error if (!fInitController.GetFlag(EInitKey::kActiveDetectorIDs)) { - LOG(fatal) << "Attempt to add a station info before the active detectors set had been initialized"; + std::stringstream msg; + msg << "ca::InitManager: Attempt to add a station info before the active detectors set had been initialized"; + throw std::runtime_error(msg.str()); } // Check, if the detector subsystem for this station is active @@ -113,13 +115,13 @@ void InitManager::ClearCAIterations() bool InitManager::FormParametersContainer() { // Read configuration files - LOG(info) << "InitManager: reading parameter configuration ..."; + LOG(info) << "ca::InitManager: reading parameter configuration ..."; try { this->ReadInputConfigs(); - LOG(info) << "InitManager: reading parameter configuration ... \033[1;32mdone\033[0m"; + LOG(info) << "ca::InitManager: reading parameter configuration ... \033[1;32mdone\033[0m"; } catch (const std::runtime_error& err) { - LOG(error) << "InitManager: reading parameter configuration ... \033[1;31mfail\033[0m. Reason: " << err.what(); + LOG(error) << "ca::InitManager: reading parameter configuration ... \033[1;31mfail\033[0m. Reason: " << err.what(); return false; } @@ -134,7 +136,7 @@ bool InitManager::FormParametersContainer() this->CheckInit(); if (!fInitController.IsFinalized()) { - LOG(error) << "InitManager: Attempt to form parameters container before all necessary fields were initialized" + LOG(error) << "ca::InitManager: Attempt to form parameters container before all necessary fields were initialized" << fInitController.ToString(); return false; } @@ -166,7 +168,7 @@ bool InitManager::FormParametersContainer() fParameters.CheckConsistency(); } catch (const std::logic_error& err) { - LOG(error) << "InitManager: parameters container consistency check failed. Reason: " << err.what(); + LOG(error) << "ca::InitManager: parameters container consistency check failed. Reason: " << err.what(); return false; } @@ -178,7 +180,9 @@ bool InitManager::FormParametersContainer() int InitManager::GetNstationsActive() const { if (!fInitController.GetFlag(EInitKey::kStationLayoutInitialized)) { - LOG(fatal) << "InitManager: number of active stations cannot be accessed until the station layout is initialized"; + std::stringstream msg; + msg << "ca::InitManager: number of active stations cannot be accessed until the station layout is initialized"; + throw std::runtime_error(msg.str()); } return fParameters.GetNstationsActive(); } @@ -188,7 +192,9 @@ int InitManager::GetNstationsActive() const int InitManager::GetNstationsActive(EDetectorID detectorID) const { if (!fInitController.GetFlag(EInitKey::kStationLayoutInitialized)) { - LOG(fatal) << "InitManager: number of active stations cannot be accessed until the station layout is initialized"; + std::stringstream msg; + msg << "ca::InitManager: number of active stations cannot be accessed until the station layout is initialized"; + throw std::runtime_error(msg.str()); } return fParameters.GetNstationsActive(detectorID); } @@ -198,7 +204,9 @@ int InitManager::GetNstationsActive(EDetectorID detectorID) const int InitManager::GetNstationsGeometry() const { if (!fInitController.GetFlag(EInitKey::kStationLayoutInitialized)) { - LOG(fatal) << "InitManager: number of geometry stations cannot be accessed until the station layout is initialized"; + std::stringstream msg; + msg << "ca::InitManager: number of geometry stations cannot be accessed until the station layout is initialized"; + throw std::runtime_error(msg.str()); } return fParameters.GetNstationsGeometry(); } @@ -208,7 +216,9 @@ int InitManager::GetNstationsGeometry() const int InitManager::GetNstationsGeometry(EDetectorID detectorID) const { if (!fInitController.GetFlag(EInitKey::kStationLayoutInitialized)) { - LOG(fatal) << "InitManager: number of geometry stations cannot be accessed until the station layout is initialized"; + std::stringstream msg; + msg << "ca::InitManager: number of geometry stations cannot be accessed until the station layout is initialized"; + throw std::runtime_error(msg.str()); } return fParameters.GetNstationsGeometry(detectorID); } @@ -218,7 +228,9 @@ int InitManager::GetNstationsGeometry(EDetectorID detectorID) const std::vector<StationInitializer>& InitManager::GetStationInfo() { if (!fInitController.GetFlag(EInitKey::kStationLayoutInitialized)) { - LOG(fatal) << "InitManager: station info container cannot be accessed until the station layout is initialized"; + std::stringstream msg; + msg << "ca::InitManager: station info container cannot be accessed until the station layout is initialized"; + throw std::runtime_error(msg.str()); } return fvStationInfo; } @@ -263,20 +275,23 @@ void InitManager::InitStationLayout() void InitManager::InitTargetField(double zStep) { if (fInitController.GetFlag(EInitKey::kPrimaryVertexField)) { - LOG(warn) << "InitManager::InitTargetField: attempt to reinitialize the field value and field region " + LOG(warn) << "ca::InitManager::InitTargetField: attempt to reinitialize the field value and field region " << "near target. Ignore"; return; } // Check for field function if (!fInitController.GetFlag(EInitKey::kFieldFunction)) { - LOG(fatal) - << "Attempt to initialize the field value and field region near target before initializing field function"; + std::stringstream msg; + msg << "Attempt to initialize the field value and field region near target before initializing field function"; + throw std::runtime_error(msg.str()); } // Check for target defined if (!fInitController.GetFlag(EInitKey::kTargetPos)) { - LOG(fatal) << "Attempt to initialize the field value and field region near target before the target position" - << "initialization"; + std::stringstream msg; + msg << "Attempt to initialize the field value and field region near target before the target position" + << "initialization"; + throw std::runtime_error(msg.str()); } constexpr int nDimensions{3}; constexpr int nPointsNodal{3}; @@ -306,7 +321,9 @@ void InitManager::PushBackCAIteration(const Iteration& iteration) { // TODO: probably some checks must be inserted here (S.Zharko) if (!fInitController.GetFlag(EInitKey::kCAIterationsNumberCrosscheck)) { - LOG(fatal) << "Attempt to push back a CA track finder iteration before the number of iterations was defined"; + std::stringstream msg; + msg << "Attempt to push back a CA track finder iteration before the number of iterations was defined"; + throw std::runtime_error(msg.str()); } fParameters.fCAIterations.push_back(iteration); } @@ -332,7 +349,9 @@ void InitManager::ReadParametersObject(const std::string& fileName) // Open input binary file std::ifstream ifs(fileName, std::ios::binary); if (!ifs) { - LOG(fatal) << "InitManager: parameters data file \"" << clrs::GNb << fileName << clrs::CL << "\" was not found"; + std::stringstream msg; + msg << "ca::InitManager: parameters data file \"" << clrs::GNb << fileName << clrs::CL << "\" was not found"; + throw std::runtime_error(msg.str()); } // Get L1InputData object @@ -341,8 +360,10 @@ void InitManager::ReadParametersObject(const std::string& fileName) ia >> fParameters; } catch (const std::exception&) { - LOG(fatal) << "InitManager: parameters file \"" << clrs::GNb << fileName << clrs::CL - << "\" has incorrect data format or was corrupted"; + std::stringstream msg; + msg << "ca::InitManager: parameters file \"" << clrs::GNb << fileName << clrs::CL + << "\" has incorrect data format or was corrupted"; + throw std::runtime_error(msg.str()); } } @@ -353,7 +374,9 @@ void InitManager::ReadSearchWindows(const std::string& fileName) // Open input binary file std::ifstream ifs(fileName); if (!ifs) { - LOG(fatal) << "InitManager: search window file \"" << fileName << "\" was not found"; + std::stringstream msg; + msg << "ca::InitManager: search window file \"" << fileName << "\" was not found"; + throw std::runtime_error(msg.str()); } try { @@ -380,11 +403,16 @@ void InitManager::ReadSearchWindows(const std::string& fileName) fParameters.fSearchWindows[iTrackGrID * constants::size::MaxNstations + iStationID] = swBuffer; } if (errMsg.str().size()) { - LOG(fatal) << "InitManager: some errors occurred while reading search windows: " << errMsg.str(); + std::stringstream msg; + msg << "ca::InitManager: some errors occurred while reading search windows: " << errMsg.str(); + throw std::runtime_error(msg.str()); } } - catch (const std::exception&) { - LOG(fatal) << "InitManager: search windows file \"" << fileName << "\" has incorrect data format or was corrupted"; + catch (const std::exception& err) { + std::stringstream msg; + msg << "search windows file \"" << fileName << "\" has incorrect data format or was corrupted. "; + msg << "Exception catched: " << err.what(); + throw std::runtime_error(msg.str()); } fInitController.SetFlag(EInitKey::kSearchWindows, true); @@ -420,7 +448,7 @@ void InitManager::SetFieldFunction(const FieldFunction_t& fieldFunction) fInitController.SetFlag(EInitKey::kFieldFunction); } else { - LOG(warn) << "InitManager::SetFieldFunction: attempt to reinitialize the field function. Ignored"; + LOG(warn) << "ca::InitManager::SetFieldFunction: attempt to reinitialize the field function. Ignored"; } } @@ -429,7 +457,7 @@ void InitManager::SetFieldFunction(const FieldFunction_t& fieldFunction) void InitManager::SetGhostSuppression(int ghostSuppression) { if (fInitController.GetFlag(EInitKey::kGhostSuppression)) { - LOG(warn) << "InitManager::SetGhostSuppression: attempt of reinitializating the ghost suppresion flag. Ignore"; + LOG(warn) << "ca::InitManager::SetGhostSuppression: attempt of reinitializating the ghost suppresion flag. Ignore"; return; } fParameters.fGhostSuppression = ghostSuppression; @@ -441,7 +469,7 @@ void InitManager::SetGhostSuppression(int ghostSuppression) void InitManager::SetRandomSeed(unsigned int seed) { if (fInitController.GetFlag(EInitKey::kRandomSeed)) { - LOG(warn) << "InitManager::SetRandomSeed: attempt of reinitializating the random seed. Ignore"; + LOG(warn) << "ca::InitManager::SetRandomSeed: attempt of reinitializating the random seed. Ignore"; return; } fParameters.fRandomSeed = seed; @@ -453,7 +481,7 @@ void InitManager::SetRandomSeed(unsigned int seed) void InitManager::SetTargetPosition(double x, double y, double z) { if (fInitController.GetFlag(EInitKey::kTargetPos)) { - LOG(warn) << "InitManager::SetTargetPosition: attempt to reinitialize the target position. Ignore"; + LOG(warn) << "ca::InitManager::SetTargetPosition: attempt to reinitialize the target position. Ignore"; return; } @@ -474,15 +502,17 @@ Parameters<fvec>&& InitManager::TakeParameters() { return std::move(fParameters) // void InitManager::WriteParametersObject(const std::string& fileName) const { + using clrs::CL; + using clrs::GNb; // Open output binary file std::ofstream ofs(fileName, std::ios::binary); if (!ofs) { - LOG(error) << "InitManager: failed opening file \"" << clrs::GNb << fileName << clrs::CL - << "\" to write parameters object"; - return; + std::stringstream msg; + msg << "ca::InitManager: failed opening file \"" << GNb << fileName << CL << "\" to write parameters object"; + throw std::runtime_error(msg.str()); } - LOG(info) << "InitManager: writing CA parameters object to file \"" << clrs::GNb << fileName << '\"' << clrs::CL; + LOG(info) << "ca::InitManager: writing CA parameters object to file \"" << GNb << fileName << '\"' << CL; // Serialize L1Parameters object and write boost::archive::binary_oarchive oa(ofs); @@ -498,8 +528,8 @@ void InitManager::CheckCAIterationsInit() int nIterationsActual = fParameters.fCAIterations.size(); int nIterationsExpected = fCAIterationsNumberCrosscheck; if (nIterationsActual != nIterationsExpected) { - LOG(warn) << "InitManager::CheckCAIterations: incorrect number of iterations registered: " << nIterationsActual - << " of " << nIterationsExpected << " expected"; + LOG(warn) << "ca::InitManager::CheckCAIterations: incorrect number of iterations registered: " + << nIterationsActual << " of " << nIterationsExpected << " expected"; ifInitPassed = false; } } @@ -516,15 +546,18 @@ void InitManager::CheckStationsInfoInit() bool bStationsFinalized = std::all_of(fvStationInfo.begin(), fvStationInfo.end(), [](const auto& st) { return st.GetInitController().IsFinalized(); }); if (!bStationsFinalized) { - LOG(fatal) << "At least one of the StationInitializer objects is not finalized"; + std::stringstream msg; + msg << "ca::InitManager: At least one of the StationInitializer objects is not finalized"; } // (2) Check for maximum allowed number of stations if (fParameters.GetNstationsGeometry() > constants::size::MaxNstations) { - LOG(fatal) << "Actual total number of registered stations in geometry (" << fParameters.GetNstationsGeometry() - << ") is larger then possible (" << constants::size::MaxNstations - << "). Please, select another set of active tracking detectors or recompile the code with enlarged" - << " constants::size::MaxNstations value"; + std::stringstream msg; + msg << "Actual total number of registered stations in geometry (" << fParameters.GetNstationsGeometry() + << ") is larger then possible (" << constants::size::MaxNstations + << "). Please, select another set of active tracking detectors or recompile the code with enlarged" + << " constants::size::MaxNstations value"; + throw std::runtime_error(msg.str()); } } fInitController.SetFlag(EInitKey::kStationsInfo, ifInitPassed); diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx index 5c66cfaa0e23632c873f3eab05baaa3f7e15b8bb..a469919fc3667a34cbdce5dc3c1208279a579d0f 100644 --- a/reco/L1/CbmL1.cxx +++ b/reco/L1/CbmL1.cxx @@ -153,7 +153,7 @@ InitStatus CbmL1::ReInit() // --------------------------------------------------------------------------------------------------------------------- // InitStatus CbmL1::Init() -{ +try { if (fVerbose > 1) { char y[20] = " [0;33;44m"; // yellow char Y[20] = " [1;33;44m"; // yellow bold @@ -602,6 +602,10 @@ InitStatus CbmL1::Init() return kSUCCESS; } +catch (const std::exception& err) { + LOG(error) << "CbmL1: initialization failed. Reason: " << err.what(); + return kFATAL; +} void CbmL1::Reconstruct(CbmEvent* event) @@ -926,6 +930,11 @@ void CbmL1::DefineSTAPNames(const char* dirName) fSTAPDataDir = "."; } + // TODO: Clean-up the names and pathes + if (fSTAPDataDir.Length() == 0) { + fSTAPDataDir = "."; + } + LOG(info) << "CbmL1: STAP data root directory is \033[1;32m" << bfs::system_complete(fSTAPDataDir.Data()) << "\033[0m"; diff --git a/reco/L1/qa/CbmCaInputQaSetup.cxx b/reco/L1/qa/CbmCaInputQaSetup.cxx index e7e20bd8249ace10e9332a72b8d51112b5eeb72c..64d5f5e833e6432f64c6cc515c1812ded8376d92 100644 --- a/reco/L1/qa/CbmCaInputQaSetup.cxx +++ b/reco/L1/qa/CbmCaInputQaSetup.cxx @@ -272,7 +272,7 @@ try { LOG(error) << fName << ": initializing... \033[1;32mDone\033[0m"; return kSUCCESS; } -catch (const std::logic_error& e) { +catch (const std::exception& e) { LOG(error) << fName << ": initializing... \033[1;31mFailed\033[0m\nReason: " << e.what(); return kFATAL; } diff --git a/reco/L1/qa/CbmCaOutputQa.cxx b/reco/L1/qa/CbmCaOutputQa.cxx index 3ed877ccbb54e9a1aeccc09bc7e3df4d00a0aa5c..4c39ab72c0451bab603654e985bcbb7884f7c3b5 100644 --- a/reco/L1/qa/CbmCaOutputQa.cxx +++ b/reco/L1/qa/CbmCaOutputQa.cxx @@ -1027,8 +1027,13 @@ InitStatus OutputQa::InitTimeSlice() void OutputQa::ReadParameters(const char* filename) { ca::InitManager manager; - manager.ReadParametersObject(filename); - fpParameters = std::make_shared<ca::Parameters<ca::fvec>>(manager.TakeParameters()); + try { + manager.ReadParametersObject(filename); + fpParameters = std::make_shared<ca::Parameters<ca::fvec>>(manager.TakeParameters()); + } + catch (std::runtime_error& err) { + LOG(fatal) << err.what(); + } LOG(info) << '\n' << fpParameters->ToString(1); }