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)) /
|
((chrono::system_clock::now() - stime).count() / (size_t)pow(10, 6)) /
|
||||||
20;
|
20;
|
||||||
|
|
||||||
// First pass: create all models and link valve_pair models
|
// Pass 1: create model instances
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
const char* spec = binary_tele[i].tables[1];
|
const char* spec = binary_tele[i].tables[1];
|
||||||
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
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);
|
string key = string(binary_tele[i].item);
|
||||||
registry.getOrCreate(specStr, defaultVal, key);
|
registry.getOrCreate(specStr, defaultVal, key);
|
||||||
}
|
}
|
||||||
|
// Pass 2: link valve_pair models to action signals
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
const char* spec = binary_tele[i].tables[1];
|
const char* spec = binary_tele[i].tables[1];
|
||||||
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
||||||
@ -55,7 +56,7 @@ bool Generator::wtite_in_shm(int event_no) {
|
|||||||
model->linkPeers(registry);
|
model->linkPeers(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass: evaluate
|
// Pass 3: evaluate all models
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
const char* spec = binary_tele[i].tables[1];
|
const char* spec = binary_tele[i].tables[1];
|
||||||
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
string specStr = (spec != nullptr && strlen(spec) > 0) ? string(spec) : "";
|
||||||
|
|||||||
@ -17,7 +17,12 @@ int RNG::start() {
|
|||||||
logger_->Info() << "-------RNG::start-------" << std::endl;
|
logger_->Info() << "-------RNG::start-------" << std::endl;
|
||||||
con_mag_ = std::make_shared<ConnectionMag>();
|
con_mag_ = std::make_shared<ConnectionMag>();
|
||||||
con_mag_->dbLogin();
|
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 {
|
try {
|
||||||
auto module_name = name();
|
auto module_name = name();
|
||||||
RNG_server = new RNGICEI();
|
RNG_server = new RNGICEI();
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#pragma once
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -20,8 +20,7 @@ struct ReadCSV {
|
|||||||
string word;
|
string word;
|
||||||
using std::is_same_v;
|
using std::is_same_v;
|
||||||
if (!infile.is_open()) {
|
if (!infile.is_open()) {
|
||||||
std::cout << "Error: opening file fail" << std::endl;
|
throw std::runtime_error("Cannot open CSV file: " + file_dir);
|
||||||
std::exit(1);
|
|
||||||
}
|
}
|
||||||
while (std::getline(infile, line)) {
|
while (std::getline(infile, line)) {
|
||||||
std::istringstream sin;
|
std::istringstream sin;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user