6#include <boost/serialization/export.hpp>
13#include "../Branch/BranchRecord.h"
14#include "../Scheduler/Scheduler.h"
18#include <boost/archive/binary_oarchive.hpp>
19#include <boost/archive/binary_iarchive.hpp>
22namespace fs = std::filesystem;
42 auto kpu_pt = make_unique<KeyParameterHistoryUnit>();
55 string full_file_name, full_file_name_diagnosis, full_file_name_PIF;
56 int num_subfolder, size_of_subfolder, es_id;
57 int num_column, num_row, num_column_diagnosis, num_column_PIF;
63 full_file_name = strKPSDir;
64 full_file_name +=
"KPSFolder_";
65 num_subfolder = es_id / size_of_subfolder;
67 full_file_name += to_string(num_subfolder);
68 fs::create_directories(full_file_name);
69 full_file_name_diagnosis = full_file_name;
70 full_file_name_PIF= full_file_name;
72 full_file_name +=
"/ZKPS_";
73 full_file_name_diagnosis +=
"/ZDIA_";
74 full_file_name_PIF +=
"/ZPIF_";
78 full_file_name += to_string(es_id);
79 full_file_name +=
".txt";
80 full_file_name_diagnosis += to_string(es_id);
81 full_file_name_diagnosis +=
".txt";
82 full_file_name_PIF += to_string(es_id);
83 full_file_name_PIF +=
".txt";
87 num_column = (*kps_history_itr)->getNumOfData();
88 num_column_diagnosis = (*kps_history_itr)->getDiagnosisNumOfData();
89 num_column_PIF = (*kps_history_itr)->getPIFNumOfData();
93 ofstream fout(full_file_name.c_str(), ios::out);
95 fout << num_column <<
'\t' << num_row <<
'\n';
96 (*kps_history_itr)->outputLabelToFile(fout);
97 (*kps_history_itr)->outputUnitToFile(fout);
98 for(kps_history_itr = this->
kps_history.begin(); kps_history_itr != this->kps_history.end(); kps_history_itr++){
99 (*kps_history_itr)->outputAllDataToFile(fout);
104 ofstream fout1(full_file_name_diagnosis.c_str(), ios::out);
105 fout1 << num_column_diagnosis <<
'\t' << num_row <<
'\n';
109 (*kps_history_itr)->outputDiagnosisLabelToFile(fout1);
110 (*kps_history_itr)->outputDiagnosisUnitToFile(fout1);
111 for(kps_history_itr = this->
kps_history.begin(); kps_history_itr != this->kps_history.end(); kps_history_itr++){
112 (*kps_history_itr)->outputAllDiagnosisDataToFile(fout1);
117 ofstream fout2(full_file_name_PIF.c_str(), ios::out);
118 fout2 << num_column_PIF <<
'\t' << num_row <<
'\n';
120 (*kps_history_itr)->outputPIFLabelToFile(fout2);
121 (*kps_history_itr)->outputPIFUnitToFile(fout2);
122 for(kps_history_itr = this->
kps_history.begin(); kps_history_itr != this->kps_history.end(); kps_history_itr++){
123 (*kps_history_itr)->outputAllPIFDataToFile(fout2);
130 string full_file_name;
143 auto ptr = make_unique<KeyParameterHistoryUnit>();
144 ptr->copyKeyParameterHistoryUnit(*src);
151 fout <<
"KeyParameterHistory\n" << num <<
'\n';
152 for(i = 0; i < num; i++){
153 kps_history.at(i)->saveKeyParameterHistoryUnitToFile(fout);
160 if (str !=
"KeyParameterHistory"){
161 ofstream fout(
"err messages.txt", ios::app);
162 cout <<
"KeyParameterHistory::retrieveKeyParameterHistoryFromFile retrieval error in previous function" << endl;
163 fout <<
r5pars_.timesno <<
" KeyParameterHistory::retrieveKeyParameterHistoryFromFile retrieval error in previous function\n";
170 for(i = 0; i < num; i++){
171 auto ptr = make_unique<KeyParameterHistoryUnit>();
172 ptr->retrieveKeyParameterHistoryUnitFromFile(fin);
bool checked_close(std::ofstream &ofs, const std::string &path)
Flush and close an output stream and report a failed write.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Single struct holding all mutable simulation state.
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
int getIDOfRecentGeneratedES()
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
void outputHistoryToFile()
void clearKeyParameterHistory()
std::vector< std::unique_ptr< KeyParameterHistoryUnit > > kps_history
void saveKeyParameterHistoryToFile(std::ofstream &)
void copyKeyParameterHistory(KeyParameterHistory &)
void retrieveKeyParameterHistoryFromFile(std::ifstream &)
virtual ~KeyParameterHistory()
std::string getKPSDirectory()
Scheduler SScheduler
Simulation scheduling, parses CLI options.
BranchRecord Branch_center
Dynamic event tree state.