-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrahms_dialog.cpp
275 lines (225 loc) · 9.2 KB
/
brahms_dialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include "brahms_dialog.h"
#include "ui_brahms_dialog.h"
BRAHMS_dialog::BRAHMS_dialog(rootData *data, QWidget *parent) :
QDialog(parent),
ui(new Ui::BRAHMS_dialog)
{
ui->setupUi(this);
this->data = data;
connect(this->ui->open_ns, SIGNAL(clicked()), this, SLOT(getNamespace()));
connect(this->ui->open_path, SIGNAL(clicked()), this, SLOT(getPath()));
connect(this, SIGNAL(write_out_model(QString)), data, SLOT(export_model_xml(QString)));
connect(this->ui->launch_but, SIGNAL(clicked()), this, SLOT(runIt()));
// default Namespace
ui->text_ns->setText(qgetenv("HOME") + "/Namespace");
ui->text_path->setText(qgetenv("HOME") + "/SystemML");
}
BRAHMS_dialog::~BRAHMS_dialog()
{
delete ui;
}
void BRAHMS_dialog::getNamespace() {
QString dirName = QFileDialog::getExistingDirectory(this, "Choose the BRAHMS Namespace directory", qgetenv("HOME"));
this->ui->text_ns->setText(dirName);
}
void BRAHMS_dialog::getPath() {
QString dirName = QFileDialog::getExistingDirectory(this, "Choose the BRAHMS SystemML directory", qgetenv("HOME"));
this->ui->text_path->setText(dirName);
}
void BRAHMS_dialog::runIt() {
QDir lib_path(QApplication::applicationDirPath());
// find or make the working directory
if (!QDir(lib_path.absoluteFilePath("wd")).exists()) {
QDir().mkdir("wd");
}
QDir wk_dir = QDir(lib_path.absoluteFilePath("wd"));
QStringList filters;
filters.push_back("rep*");
QStringList entries = wk_dir.entryList(filters);
for (int i = 0; i < entries.size(); ++i) {
wk_dir.remove(entries[i]);
}
ui->progressBar->setValue(5);
this->ui->output->append("## BEGINNING... writing model...");
this->ui->output->repaint();
this->ui->progressBar->repaint();
// write out the model
emit write_out_model(wk_dir.absolutePath());
ui->progressBar->setValue(10);
this->ui->output->append("## done!\n");
this->ui->output->repaint();
this->ui->progressBar->repaint();
// set up the environment for the spawned processes
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("SYSTEMML_INSTALL_PATH", this->ui->text_path->text());
env.insert("PATH", qgetenv("PATH") + ":" + this->ui->text_path->text() + "/BRAHMS/bin");
// convert the model
QProcess convertor;
convertor.setWorkingDirectory(wk_dir.absolutePath());
convertor.setProcessEnvironment(env);
QStringList args;
args.push_back("model.xml");
args.push_back(this->ui->text_ns->text());
if (ui->recompile->isChecked() == true) {
args.push_back("true");
this->ui->output->append("## COMPILING COMPONENTS - this may take some time\n");
this->ui->output->repaint();
this->ui->progressBar->repaint();
}
else
args.push_back("false");
this->ui->output->append("## CONVERTING...");
this->ui->output->repaint();
this->ui->progressBar->repaint();
convertor.start("./convert_script", args);
bool success = convertor.waitForFinished(3000000);
this->ui->output->append("## done!\n");
this->ui->output->repaint();
this->ui->progressBar->repaint();
if (!success)
return;
if (success) {
this->ui->progressBar->setValue(25);
QByteArray output = convertor.readAllStandardError();
QString outputStringErr(output);
if (outputStringErr.size() > 0 && outputStringErr[0] != 'r') {
this->ui->output->append(outputStringErr);
this->ui->progressBar->setValue(0);
return;
}
output = convertor.readAllStandardOutput();
QString outputString(output);
this->ui->output->append(outputString);
}
// create sys-exe.xml ///////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
QFile exeFile( wk_dir.absoluteFilePath("sys-exe.xml") );
if (!exeFile.open( QIODevice::WriteOnly)) {
QMessageBox msgBox;
msgBox.setText("Error BRAHMS execution file - is there sufficient disk space?");
msgBox.exec();
return;
}
QDomDocument * doc = new QDomDocument;
QDomProcessingInstruction xmlDeclaration = doc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"ISO-8859-1\"");
doc->appendChild(xmlDeclaration);
QDomElement exe = doc->createElement("Execution");
exe.setAttribute("Version","1.0");
exe.setAttribute("AuthTool","SpineCreator BRAHMS Exporter");
exe.setAttribute("AuthToolVersion","TBC");
QDomElement title = doc->createElement("Title");
exe.appendChild(title);
QDomElement fileIn = doc->createElement("SystemFileIn");
QDomText fileInText = doc->createTextNode("sys.xml");
fileIn.appendChild(fileInText);
exe.appendChild(fileIn);
QDomElement fileOut = doc->createElement("SystemFileOut");
exe.appendChild(fileOut);
QDomElement repFile = doc->createElement("ReportFile");
QDomText repFileText = doc->createTextNode("rep-((VOICE)).xml");
repFile.appendChild(repFileText);
exe.appendChild(repFile);
QDomElement wd = doc->createElement("WorkingDirectory");
exe.appendChild(wd);
QDomElement exeStop = doc->createElement("ExecutionStop");
QDomText exeStopText = doc->createTextNode(QString::number(float(this->ui->duration->value())/1000.0));
exeStop.appendChild(exeStopText);
exe.appendChild(exeStop);
QDomElement seed = doc->createElement("Seed");
exe.appendChild(seed);
QDomElement logs = doc->createElement("Logs");
logs.setAttribute("Precision", "6");
logs.setAttribute("Encapsulated", "0");
logs.setAttribute("All", "0");
QString logString = ui->logText->text();
QStringList logStrings = logString.split(";");
for (int i = 0; i < logStrings.size(); ++i) {
if (i == 0 && logStrings[i] == "all")
{logs.setAttribute("All", "1");
break;}
QDomElement log = doc->createElement("Log");
QDomText logText = doc->createTextNode(logStrings[i].replace(" ", ""));
log.appendChild(logText);
logs.appendChild(log);
}
exe.appendChild(logs);
QDomElement voices = doc->createElement("Voices");
QDomElement voice = doc->createElement("Voice");
voices.appendChild(voice);
exe.appendChild(voices);
QDomElement aff = doc->createElement("Affinity");
exe.appendChild(aff);
QDomElement exePars = doc->createElement("ExecutionParameters");
QDomElement maxThread = doc->createElement("MaxThreadCount");
QDomText maxThreadText = doc->createTextNode("x4");// may not be the best value!
maxThread.appendChild(maxThreadText);
exePars.appendChild(maxThread);
exe.appendChild(exePars);
doc->appendChild(exe);
// write out to file
QTextStream tsFromFile( &exeFile );
tsFromFile << doc->toString();
// kill off the DOM document
delete doc;
exeFile.close();
ui->output->append("\n\nCreated BRAHMS execution file...\n");
ui->progressBar->setValue(50);
// run the model ////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// convert the model
QProcess brahms;
brahms.setWorkingDirectory(wk_dir.absolutePath());
brahms.setProcessEnvironment(env);
args.clear();
args.push_back("sys-exe.xml");
brahms.start("./brahms_launch", args);
success = brahms.waitForFinished(3000000);
if (!success)
{ QByteArray output = brahms.readAllStandardError();
QString outputStringErr(output);
if (outputStringErr.size() > 0) {
this->ui->output->append(outputStringErr);
this->ui->progressBar->setValue(0);
return;
}
this->ui->progressBar->setValue(0);
return;}
if (success) {
QByteArray output = brahms.readAllStandardError();
QString outputStringErr(output);
this->ui->output->append(outputStringErr);
this->ui->progressBar->setValue(75);
output = brahms.readAllStandardOutput();
QString outputString(output);
this->ui->output->append(outputString);
}
// fix the output file
QProcess fixer;
fixer.setWorkingDirectory(wk_dir.absolutePath());
QStringList args2;
args2.push_back("sys-exe.xml");
fixer.start("./fix_for_brahms", args2);
success = fixer.waitForFinished(300000);
if (!success)
{ QByteArray output = fixer.readAllStandardError();
QString outputStringErr(output);
if (outputStringErr.size() > 0) {
this->ui->output->append(outputStringErr);
this->ui->progressBar->setValue(0);
return;
}
this->ui->progressBar->setValue(0);
return;}
if (success) {
QByteArray output = fixer.readAllStandardError();
QString outputStringErr(output);
this->ui->output->append(outputStringErr);
this->ui->progressBar->setValue(75);
output = fixer.readAllStandardOutput();
QString outputString(output);
this->ui->output->append(outputString);
}
// gather the results ///////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// NOT DONE YET
}