fix: address code review issues
- read_csv.hpp: replace std::exit(1) with std::runtime_error throw - read_csv.hpp: remove duplicate #pragma once - RNG.cc: wrap JSON load in try-catch to prevent crash on missing config - Generator.cc: fix comments to reflect actual 3-pass structure
This commit is contained in:
parent
d9b4ee8eb3
commit
5ee17627e9
@ -38,7 +38,7 @@ bool Generator::wtite_in_shm(int event_no) {
|
||||
((chrono::system_clock::now() - stime).count() / (size_t)pow(10, 6)) /
|
||||
20;
|
||||
|
||||
// First pass: create all models and link valve_pair models
|
||||
// Pass 1: create model instances
|
||||
for (int i = 0; i < size; i++) {
|
||||
const char* spec = binary_tele[i].tables[1];
|
||||
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
||||
@ -46,6 +46,7 @@ bool Generator::wtite_in_shm(int event_no) {
|
||||
string key = string(binary_tele[i].item);
|
||||
registry.getOrCreate(specStr, defaultVal, key);
|
||||
}
|
||||
// Pass 2: link valve_pair models to action signals
|
||||
for (int i = 0; i < size; i++) {
|
||||
const char* spec = binary_tele[i].tables[1];
|
||||
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
||||
@ -55,7 +56,7 @@ bool Generator::wtite_in_shm(int event_no) {
|
||||
model->linkPeers(registry);
|
||||
}
|
||||
|
||||
// Second pass: evaluate
|
||||
// Pass 3: evaluate all models
|
||||
for (int i = 0; i < size; i++) {
|
||||
const char* spec = binary_tele[i].tables[1];
|
||||
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
||||
|
||||
@ -17,7 +17,12 @@ int RNG::start() {
|
||||
logger_->Info() << "-------RNG::start-------" << std::endl;
|
||||
con_mag_ = std::make_shared<ConnectionMag>();
|
||||
con_mag_->dbLogin();
|
||||
ModelRegistry::instance().loadModels("/users/dsc/code/TestProject/RNG/json/rng_models.json");
|
||||
try {
|
||||
ModelRegistry::instance().loadModels("/users/dsc/code/TestProject/RNG/json/rng_models.json");
|
||||
} catch (const std::exception& e) {
|
||||
logger_->Error() << "Failed to load rng_models.json: " << e.what() << endl;
|
||||
return (-1);
|
||||
}
|
||||
try {
|
||||
auto module_name = name();
|
||||
RNG_server = new RNGICEI();
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
@ -20,8 +20,7 @@ struct ReadCSV {
|
||||
string word;
|
||||
using std::is_same_v;
|
||||
if (!infile.is_open()) {
|
||||
std::cout << "Error: opening file fail" << std::endl;
|
||||
std::exit(1);
|
||||
throw std::runtime_error("Cannot open CSV file: " + file_dir);
|
||||
}
|
||||
while (std::getline(infile, line)) {
|
||||
std::istringstream sin;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user