← Documentation
ADS-IDAC Engine 5.0.0
BranchEndState.cpp
Go to the documentation of this file.
1// BranchEndState.cpp: implementation of the BranchEndState class.
2//
4#if defined(_WIN32)
5#include <direct.h>
6#include <boost/serialization/export.hpp>
7#else
8#include <sys/stat.h>
9#include <sys/types.h>
10#endif
11
12#include "BranchEndState.h"
13#include "../Scheduler/Scheduler.h"
14#include "BranchRecord.h"
15#include <filesystem>
16#include "../Global/SimulationContext.h"
17#include "../Global/CheckedIO.h"
18#include <boost/archive/binary_oarchive.hpp>
19#include <boost/archive/binary_iarchive.hpp>
20BOOST_CLASS_EXPORT_IMPLEMENT(BranchEndState)
21using namespace std;
22
23namespace fs = std::filesystem;
24
25
27// Construction/Destruction
29
31{
36}
37
39{
40
41}
51 // char numtext[10];
52 string full_file_name;
53 int num_subfolder, size_of_subfolder;
54//
55 full_file_name = g_sim.SScheduler.getESDirectory();
56 if(r5pars_.tsimmode == static_cast<int>(ConsoleMode::Console)){
57 size_of_subfolder = g_sim.Branch_center.getSizeOfSubFolder();
58 full_file_name += "ESFolder_";
59 num_subfolder = ID_this_end_state / size_of_subfolder;
60 // itoa(num_subfolder, numtext, 10);
61 full_file_name += to_string(num_subfolder);
62 fs::create_directories(full_file_name);
63 full_file_name += "//ZESNode_";
64 }
65 else{
66 full_file_name += "ZESNode_";
67 }
68 // itoa(ID_this_end_state, numtext, 10);
69 full_file_name += to_string(ID_this_end_state);
70 full_file_name += ".txt";
71 g_sim.SScheduler.setFileNameES(full_file_name);
72 ofstream fout(full_file_name.c_str(), ios::out);
73 fout << "ES_" << ID_this_end_state << ' ' << this->getTimeAtWhichThisEventHappen() << ' ' << ID_this_end_state << ' ' << ID_of_the_mother_branch
74 << " 0 3096 0 " << this->getProbability()
75 << "\nConsequence " << static_cast<int>(type_of_consequence) << '\n'
76 << '"' << consequence_description << '"';
77 checked_close(fout, full_file_name);
78}
80 fout << static_cast<int>(type_of_consequence) << ' ' << ID_this_end_state << ' ' << ID_of_the_mother_branch << ' ' << consequence_description << '\n';
81 this->saveTimeToFile(fout);
82 this->saveProbabilityToFile(fout);
83}
85 { int tc; fin >> tc; type_of_consequence = static_cast<Consequence>(tc); }
87 this->retrieveTimeFromFile(fin);
89}
95 this->copyTime(_bes);
96 this->copyProbability(_bes);
97}
98
100 ifstream fin;
101 double time, probability;
102 string str;
103 int num;
104 char ch = ' ';
105 fin.open(strFileName.c_str(), ios::in);
106 fin >> str
107 >> time
109 >> num >> num >> num >> num
110 >> probability
111 >> str;
112 { int tc; fin >> tc; type_of_consequence = static_cast<Consequence>(tc); }
114 this->setProbability(probability);
115
116 while (ch != '"' && !fin.eof()){
117 fin.get(ch);}
118 if(ch == '"') consequence_description = ch;
119 do{
120 fin.get(ch);
122 }while(ch != '"' && !fin.eof());
123 fin.close();
124}
Central dynamic event tree data structure: the branch clusters, the end states and the forks that are...
bool checked_close(std::ofstream &ofs, const std::string &path)
Flush and close an output stream and report a failed write.
Definition: CheckedIO.h:19
Consequence
Definition: SimConstants.h:27
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
The end state (ES node) that terminates one sequence of the DET.
virtual ~BranchEndState()
std::string consequence_description
void saveInfoToFile()
Writes this end state as an ES node file, overwriting any existing file.
void setIDOfThisEndState(int)
Sets the end state ID. It is also the sequence ID used in the ZESNode file name.
Consequence type_of_consequence
void copyBranchEndState(BranchEndState &)
Copies every field, including the Time and Probability parts.
Consequence getTypeOfConsequence()
void setTypeOfConsequence(Consequence)
int getIDOfTheMotherBranch()
void saveBranchEndStateToFile(std::ofstream &)
Writes the end state to a text restart stream as <consequence as int> <id> <mother branch id> <descri...
int ID_of_the_mother_branch
void setConsequenceDescription(std::string)
void setIDOfTheMotherBranch(int)
Sets the ID of the branch (PE node) this end state hangs from.
void retrieveBranchEndStateFromFile(std::ifstream &)
Reads the layout written by saveBranchEndStateToFile. The description is read with >>,...
std::string getConsequenceDescription()
BranchEndState()
Constructs an end state with consequence Consequence::NoKB, both IDs sim::None and the description "N...
int getSizeOfSubFolder()
double getProbability()
Definition: Probability.cpp:27
void copyProbability(Probability &)
Definition: Probability.cpp:28
double probability
Definition: Probability.h:56
void setProbability(double)
Definition: Probability.cpp:26
void saveProbabilityToFile(std::ofstream &)
Definition: Probability.cpp:34
void retrieveProbabilityFromFile(std::ifstream &)
Definition: Probability.cpp:39
std::string getESDirectory()
Definition: Scheduler.cpp:601
void setFileNameES(std::string)
Definition: Scheduler.cpp:954
double getTimeAtWhichThisEventHappen() const
Definition: Timp.cpp:26
void saveTimeToFile(std::ofstream &)
Definition: Timp.cpp:32
void setTimeAtWhichThisEventHappen(double)
Definition: Timp.cpp:28
void copyTime(Time &)
Definition: Timp.cpp:30
void retrieveTimeFromFile(std::ifstream &)
Definition: Timp.cpp:36
struct @0 r5pars_
constexpr int None
Definition: SimConstants.h:75
Scheduler SScheduler
Simulation scheduling, parses CLI options.
BranchRecord Branch_center
Dynamic event tree state.