1 #include <DatabaseUtils/GUI/DCSConfigEditorDisplay.h> 2 #include <DatabaseUtils/DAQConfig/GlobalNameSpec.h> 3 #include <DatabaseUtils/DAQConfig/NamedConfigUtils.h> 4 #include <NovaDAQUtilities/EnvVarCache.h> 5 #include <boost/shared_ptr.hpp> 6 #include <QtCore/QCoreApplication> 7 #include <QtCore/QProcess> 8 #include <QtGui/QVBoxLayout> 9 #include <QtGui/QInputDialog> 10 #include <QtGui/QMenu> 11 #include <QtGui/QMenuBar> 12 #include <QtGui/QMessageBox> 13 #include <QtGui/QProgressDialog> 14 #include <QtGui/QPushButton> 15 #include <QtGui/QFileDialog> 16 #include <boost/assign/std/vector.hpp> 17 #include <boost/filesystem.hpp> 27 DCSConfigEditorDisplay::
32 if (detectorString.length() == 0) {
33 detectorString =
"NOVADAQ_ENVIRONMENT_EnvVar_NeedsToBeSet";
40 QMenu* actionMenu = menuBar()->addMenu(
tr(
"&Action"));
41 QAction* genScriptAction =
42 actionMenu->addAction(
tr(
"&Generate Recipe Scripts"));
46 QAction* loadHVAndTempsAction =
47 actionMenu->addAction(
tr(
"&Load HV and Temperatures"));
53 std::vector<std::string> tableDefinitions;
55 "NovaDatabase/tables/DCS/DCSFEBEnableMasks.xml",
56 "NovaDatabase/tables/DCS/APDTemperatureSettings.xml",
57 "NovaDatabase/tables/DCS/APDHighVoltages.xml",
58 "NovaDatabase/tables/DCS/FEBDryAirChannels.xml",
59 "NovaDatabase/tables/DCS/EPICSAlarmThresholds.xml";
72 IDSpec::SLOWCONTROLS : IDSpec::DAQ));
75 tableDefinitions,
this);
86 QVBoxLayout* thisDisplayLayout =
new QVBoxLayout;
89 QWidget* tmpWidget =
new QWidget();
90 tmpWidget->setContentsMargins(0,5,0,0);
91 tmpWidget->setLayout(thisDisplayLayout);
93 setCentralWidget(tmpWidget);
106 QMessageBox confirmBox(
this);
108 std::string msgText =
"You are about to update PV scripts on ";
109 msgText.append(
"disk based on data in the \"");
110 msgText.append(dbString);
111 msgText.append(
"\" database.");
112 confirmBox.setText(msgText.c_str());
114 msgText =
"Are you sure that you want to re-generate ";
115 msgText.append(
"the PV settings scripts?");
116 confirmBox.setInformativeText(msgText.c_str());
118 confirmBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
119 confirmBox.setDefaultButton(QMessageBox::No);
120 int retCode = confirmBox.exec();
122 if (retCode != QMessageBox::Yes) {
return;}
126 QString responseText =
127 QInputDialog::getText(
this,
tr(
"Output directory"),
128 tr(
"Enter the output directory for the generated PV scripts:"),
131 if (! status) {
return;}
138 msgText.append(
" does not exist. Aborting script generation...");
139 QMessageBox::critical(
this,
"Invalid Output Directory", msgText.c_str());
144 QProgressDialog
progressBar(
"Generating scripts... Timeout at 100%",
"Close", 0, 10,
this);
145 progressBar.setWindowModality(Qt::WindowModal);
146 progressBar.setMinimumDuration(0);
147 progressBar.setValue(0);
148 QCoreApplication::processEvents(QEventLoop::AllEvents, 500);
152 boost::shared_ptr<QProcess> processPtr(
new QProcess(
this));
153 processPtr->start(cmd.c_str());
155 bool finished =
false;
156 QCoreApplication::processEvents(QEventLoop::AllEvents, 500);
157 if (processPtr->waitForStarted(8000)) {
158 progressBar.setValue(1);
159 QCoreApplication::processEvents(QEventLoop::AllEvents, 500);
161 if (processPtr->waitForFinished(8000)) {
165 progressBar.setValue(
idx < 9 ?
idx : 9);
166 QCoreApplication::processEvents(QEventLoop::AllEvents, 500);
169 progressBar.setValue(10);
170 QCoreApplication::processEvents(QEventLoop::AllEvents, 500);
174 processPtr->waitForFinished(5000);
177 std::string stdoutString(processPtr->readAllStandardOutput());
178 std::string stderrString(processPtr->readAllStandardError());
181 std::string msgText =
"The job to generated the PV ";
182 msgText.append(
"settings scripts completed ");
183 msgText.append(
"Press \"Show Details...\" to see output.");
185 outText.append(
"\n");
186 outText.append(stderrString);
187 QMessageBox resultBox(
this);
188 resultBox.setIcon(QMessageBox::Information);
189 resultBox.setWindowTitle(
"PV Script Result");
190 resultBox.setText(msgText.c_str());
191 resultBox.setDetailedText(outText.c_str());
196 std::string msgText =
"The job to generated the PV ";
197 msgText.append(
"settings scripts timed out. ");
198 msgText.append(
"Press \"Show Details...\" to see output.");
201 outText.append(
"\n");
202 outText.append(stderrString);
203 QMessageBox resultBox(
this);
204 resultBox.setIcon(QMessageBox::Warning);
205 resultBox.setWindowTitle(
"PV Script Result");
206 resultBox.setText(msgText.c_str());
207 resultBox.setDetailedText(outText.c_str());
240 if(detName==
"FarDet")
242 else if(detName==
"NDOS")
244 else if(detName==
"NearDet")
246 else if(detName==
"NDSBTest")
251 QFileDialog peddialog(
this);
252 peddialog.setViewMode(QFileDialog::Detail);
253 QString folderName = peddialog.getExistingDirectory(
this,
tr(
"Select HV/Temp Directory."),
255 QFileDialog::ShowDirsOnly|QFileDialog::DontUseNativeDialog);
256 if(folderName==
""){
return;}
260 QMessageBox confirmBox(
this);
262 std::ostringstream hvfebs;
263 std::ostringstream tempfebs;
268 std::string hvFileName = folderName.toUtf8().constData();
269 hvFileName.append(
"/hv_");
270 hvFileName.append(uniquestamp.string());
271 hvFileName.append(
".csv");
272 std::string tempFileName = folderName.toUtf8().constData();
273 tempFileName.append(
"/temp_");
274 tempFileName.append(uniquestamp.string());
275 tempFileName.append(
".csv");
278 std::ifstream hvFile(hvFileName.c_str());
279 count=
std::count(std::istreambuf_iterator<char>(hvFile),
280 std::istreambuf_iterator<char>(),
'\n');
283 std::ifstream tempFile(tempFileName.c_str());
284 count=
std::count(std::istreambuf_iterator<char>(tempFile),
285 std::istreambuf_iterator<char>(),
'\n');
288 std::string msgText =
"You are about to load voltages and temperatures from ";
289 msgText.append(folderName.toUtf8().constData());
290 msgText.append(
"\n\n Found voltage results from ");
291 msgText.append(hvfebs.str());
292 msgText.append(
" febs, temperature results from ");
293 msgText.append(tempfebs.str());
294 msgText.append(
" febs.");
295 confirmBox.setText(msgText.c_str());
297 msgText =
"Are you sure that you want to load these values? ";
298 confirmBox.setInformativeText(msgText.c_str());
299 confirmBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
300 confirmBox.setDefaultButton(QMessageBox::No);
301 int retCode = confirmBox.exec();
302 if (retCode != QMessageBox::Yes) {
return;}
307 QMessageBox loadBox(
this);
308 msgText =
"Do you want to override ALL existing exceptions underneath the defaults or append the results?";
309 loadBox.setText(msgText.c_str());
310 loadBox.addButton(
tr(
"Override"),QMessageBox::AcceptRole);
311 loadBox.addButton(
tr(
"Append"),QMessageBox::NoRole);
312 loadBox.addButton(QMessageBox::Cancel);
313 loadBox.setDefaultButton(QMessageBox::Cancel);
314 retCode = loadBox.exec();
317 std::string systemCommand =
"LoadAPDHighVoltagesAndTemps NovaDatabase/tables/DCS ";
318 if (retCode == QMessageBox::Cancel){
return;}
319 else if (retCode == QMessageBox::AcceptRole) {
321 tmpstring = folderName.toUtf8().constData();
322 tmpstring.append(
"/hvXXXXXX");
323 char *hvTmpName =
new char[tmpstring.length() + 1];
324 strcpy(hvTmpName, tmpstring.c_str());
326 tmpstring = folderName.toUtf8().constData();
327 tmpstring.append(
"/tempXXXXXX");
328 char *tempTmpName =
new char[tmpstring.length() + 1];
329 strcpy(tempTmpName, tmpstring.c_str());
333 mkstemp(tempTmpName);
335 FILE * hvFileTmp = fopen (hvTmpName,
"w");
336 FILE * tempFileTmp = fopen (tempTmpName,
"w");
341 fputs (
"1,default,-1,cold,1533,0,1,2,3,4\n", hvFileTmp);
342 fputs (
"1,default,-1,warm,2957,0,1,2,3,4\n", hvFileTmp);
343 fputs (
"1,default,-1,2000,0,1,2,3,4\n",tempFileTmp);
347 systemCommandtmp.append(systemCommand);
348 systemCommandtmp.append(hvTmpName);
349 systemCommandtmp.append(
" ");
350 systemCommandtmp.append(tempTmpName);
351 systemCommandtmp.append(
" ");
352 systemCommandtmp.append(configName);
353 system(systemCommandtmp.c_str());
367 systemCommand.append(hvFileName);
368 systemCommand.append(
" ");
369 systemCommand.append(tempFileName);
370 systemCommand.append(
" ");
371 systemCommand.append(configName);
373 system(systemCommand.c_str());
def progressBar(value, endvalue, docdb_id, bar_length=40)
system("rm -rf microbeam.root")
int64_t _currentGlobalConfigId
static EnvVarCache & getInstance()
bool _doReloadCurrentDataset(const dbutils::daqconfig::IDSpec &idSpec)
SettingsDisplay * _settingsDisplay
void updateNamedConfiguration(const dbutils::daqconfig::GlobalNameSpec &nameSpec)
void _addHelpMenu(std::string customText="")
def connect(endpoint="tcp://127.0.0.1:5555")
boost::shared_ptr< dbutils::daqconfig::GlobalNameSpec > _globalNameSpecPtr
virtual void reactToDataChange()
bool loadData(const dbutils::daqconfig::IDSpec &idSpec)
virtual void reactToDataSave()
TabbedSetOfTreeEditors * _editorSet
void reloadCurrentDataset()
std::string _pvScriptOutputDir
std::string getEnvVar(std::string name)
bool saveChanges(const dbutils::daqconfig::IDSpec &oldGlobalIdSpec, const dbutils::daqconfig::IDSpec &newGlobalIdSpec, const dbutils::daqconfig::GlobalNameSpec &newGlobalNameSpec)
void generateRecipeScripts()
bool _doLoadNewDataset(const dbutils::daqconfig::IDSpec &idSpec)
bool _doSaveChanges(const dbutils::daqconfig::IDSpec &oldIdSpec, const dbutils::daqconfig::IDSpec &newIdSpec, const dbutils::daqconfig::GlobalNameSpec &newNameSpec)
void isTopLevel(bool setting=true)