DAQConfigEditorDisplay.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/GUI/DAQConfigEditorDisplay.h>
2 #include <DatabaseUtils/GUI/CustomTabBehaviors.h>
3 #include <DatabaseUtils/GUI/TabbedSetOfTreeEditors.h>
4 #include <DatabaseUtils/GUI/TabbedSetOfTableEditors.h>
5 #include <DatabaseUtils/DAQConfig/GlobalNameSpec.h>
6 #include <DatabaseUtils/DAQConfig/NamedConfigUtils.h>
7 #include <NovaDAQUtilities/EnvVarCache.h>
8 #include <QtCore/QCoreApplication>
9 #include <QtCore/QProcess>
10 #include <QtGui/QVBoxLayout>
11 #include <QtGui/QInputDialog>
12 #include <QtGui/QMenu>
13 #include <QtGui/QMenuBar>
14 #include <QtGui/QMessageBox>
15 #include <QtGui/QProgressDialog>
16 #include <QtGui/QFileDialog>
17 #include <boost/assign/std/vector.hpp> // for 'operator+=()'
18 #include <boost/filesystem.hpp> // for directory parsing
19 #include <algorithm>
20 #include <sstream>
21 #include <iomanip>
22 #include <locale>
23 
24 using namespace boost::assign; // bring 'operator+=()' into scope
25 using namespace dbutils::daqconfig;
26 
27 namespace dbutils {
28 namespace gui {
29 
30 DAQConfigEditorDisplay::
31 DAQConfigEditorDisplay(QWidget *parent) : BasicEditorDisplay(parent)
32 {
33  std::string detectorString =
34  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
35  if (detectorString.length() == 0) {
36  detectorString = "NOVADAQ_ENVIRONMENT_EnvVar_NeedsToBeSet";
37  }
38 
39  // Menu option to call the scripts that
40  // loads the threshold and masks generated in pedestal runner
41  QMenu* actionMenu = menuBar()->addMenu(tr("&Action"));
42  QAction* genScriptAction =
43  actionMenu->addAction(tr("&Load Thresholds and Masks"));
44  QObject::connect(genScriptAction, SIGNAL(triggered()),
45  this, SLOT(loadThresholdsAndMasks()));
46  QAction* addInitialRowAction =
47  actionMenu->addAction(tr("&Add Initial Row To Displayed Table"));
48  QObject::connect(addInitialRowAction, SIGNAL(triggered()),
49  this, SLOT(addInitialRow()));
50 
51  _addHelpMenu();
52 
53 
54 
56  reset(new GlobalNameSpec("InitialGlobalConfig", "DCS",
57  detectorString));
59  if (! NamedConfigUtils::getGlobalConfigId((*_globalNameSpecPtr),
61  std::cerr << "Error fetching globalConfigId." << std::endl;
62  }
63 // IDSpec idSpec(_currentGlobalConfigId, IDSpec::GLOBAL,
64 // (_globalNameSpecPtr->isSlowControlsConfiguration() ?
65 // IDSpec::SLOWCONTROLS : IDSpec::DAQ));
66 
67  std::vector<std::string> tableDefinitions;
68  _tabWidget = new CustomTabWidget(this);
69  _tabWidget->isTopLevel(true);
70  QObject::connect(_tabWidget, SIGNAL(aChangeWasMade()),
71  this, SLOT(reactToDataChange()));
72  QObject::connect(_tabWidget, SIGNAL(dataWasSaved()),
73  this, SLOT(reactToDataSave()));
74 
75  // DCM Connections
76  tableDefinitions.clear();
77  tableDefinitions +=
78  "NovaDatabase/tables/DAQConfig/DCMApplicationConnectParameters.xml";
79 
80  TabbedSetOfTreeEditors* editorSet =
81  new TabbedSetOfTreeEditors("DCMApplication", "connections",
82  tableDefinitions,this);
83  //editorSet->loadData(idSpec);
84  _tabWidget->addTab(editorSet, "DCM Connection");
85 
86  // DDT Connect
87  tableDefinitions.clear();
88  tableDefinitions +=
89  "NovaDatabase/tables/DAQConfig/DDTManagerConnectParameters.xml";
90 
91  editorSet =
92  new TabbedSetOfTreeEditors("DDTManager", "connections",
93  tableDefinitions, this);
94  //editorSet->loadData(idSpec);
95  _tabWidget->addTab(editorSet, "DDT Manager");
96 
97 
98  // DCM Hardware
99  tableDefinitions.clear();
100  tableDefinitions +=
101  "NovaDatabase/tables/DAQConfig/FEBEnableMasks.xml",
102  "NovaDatabase/tables/DAQConfig/PixelEnableMasks.xml",
103  "NovaDatabase/tables/DAQConfig/PixelThresholds.xml",
104  "NovaDatabase/tables/DAQConfig/DCMFPGAFirmwareLocations.xml",
105  "NovaDatabase/tables/DAQConfig/FEBFPGAFirmwareLocations.xml",
106  "NovaDatabase/tables/DAQConfig/DCMApplicationParameters.xml",
107  "NovaDatabase/tables/DAQConfig/TimingSystemSettings.xml",
108  "NovaDatabase/tables/DAQConfig/DCMDataDevParameters.xml",
109  "NovaDatabase/tables/DAQConfig/DCMFPGAParameters.xml",
110  "NovaDatabase/tables/DAQConfig/ASICRegisterSettings.xml",
111  "NovaDatabase/tables/DAQConfig/DSODataRegulatorSettings.xml",
112  "NovaDatabase/tables/DAQConfig/FEBPulserParameters.xml",
113  "NovaDatabase/tables/DAQConfig/PixelOffsets.xml",
114  "NovaDatabase/tables/DAQConfig/DCMSystemParameters.xml";
115 
116  editorSet =
117  new TabbedSetOfTreeEditors("DCMApplication", "hardware",
118  tableDefinitions,this);
119  //editorSet->loadData(idSpec);
120  _tabWidget->addTab(editorSet, "DCM Hardware");
121 
122  // DCM Run
123  tableDefinitions.clear();
124  tableDefinitions +=
125  "NovaDatabase/tables/DAQConfig/DCMApplicationRunParameters.xml",
126  "NovaDatabase/tables/DAQConfig/DCMDataDevRunParameters.xml",
127  "NovaDatabase/tables/DAQConfig/DCMSystemRunParameters.xml";
128 
129  editorSet =
130  new TabbedSetOfTreeEditors("DCMApplication", "run",
131  tableDefinitions,this);
132  //editorSet->loadData(idSpec);
133  _tabWidget->addTab(editorSet, "DCM Run");
134 
135  // DaqMonitor Run
136  tableDefinitions.clear();
137  tableDefinitions +=
138  "NovaDatabase/tables/DAQConfig/DaqMonitorRunParameters.xml";
139 
140  editorSet =
141  new TabbedSetOfTreeEditors("DaqMonitor", "run",
142  tableDefinitions,this);
143  //editorSet->loadData(idSpec);
144  _tabWidget->addTab(editorSet, "DaqMonitor Run");
145 
146  // BNEVB Run
147  tableDefinitions.clear();
148  tableDefinitions +=
149  "NovaDatabase/tables/DAQConfig/BNEVBRunParameters.xml";
150 
151  editorSet =
152  new TabbedSetOfTreeEditors("BufferNodeEVB", "run",
153  tableDefinitions, this);
154  //editorSet->loadData(idSpec);
155  _tabWidget->addTab(editorSet, "BNEVB Run");
156 
157  // GT Run
158  tableDefinitions.clear();
159  tableDefinitions +=
160  "NovaDatabase/tables/DAQConfig/CalibrationTriggers.xml",
161  "NovaDatabase/tables/DAQConfig/SpillTriggers.xml",
162  "NovaDatabase/tables/DAQConfig/DataDrivenTriggers.xml",
163  "NovaDatabase/tables/DAQConfig/DAQStatusTriggers.xml",
164  "NovaDatabase/tables/DAQConfig/ExternalTriggers.xml",
165  "NovaDatabase/tables/DAQConfig/ManualTriggers.xml",
166  "NovaDatabase/tables/DAQConfig/SNEWSTriggers.xml",
167  "NovaDatabase/tables/DAQConfig/SuperNovaTrigger.xml",
168  "NovaDatabase/tables/DAQConfig/SuperNovaFilter.xml",
169  "NovaDatabase/tables/DAQConfig/GlobalThrottle.xml",
170  "NovaDatabase/tables/DAQConfig/DDTThrottle.xml",
171  "NovaDatabase/tables/DAQConfig/SNEWSPipe.xml",
172  "NovaDatabase/tables/DAQConfig/GTQueue.xml",
173  "NovaDatabase/tables/DAQConfig/GTGeneral.xml",
174  "NovaDatabase/tables/DAQConfig/TriggerOffsets.xml";
175 
176  TabbedSetOfTableEditors* editorSet2 =
177  new TabbedSetOfTableEditors("GlobalTrigger", "run",
178  tableDefinitions,this);
179  //editorSet2->loadData(idSpec);
180  _tabWidget->addTab(editorSet2, "Global Trigger Run");
181 
182  // DL Run
183  tableDefinitions.clear();
184  tableDefinitions +=
185  "NovaDatabase/tables/DAQConfig/DataLoggerStreams.xml",
186  "NovaDatabase/tables/DAQConfig/DataLoggerSystemParameters.xml";
187 
188  editorSet2 =
189  new TabbedSetOfTableEditors("DataLogger", "run",
190  tableDefinitions,this);
191  //editorSet2->loadData(idSpec);
192  _tabWidget->addTab(editorSet2, "Data Logger Run");
193 
194 
196  this->show();
197  loadNewDataset();
198 // _settingsDisplay->updateNamedConfiguration(*_globalNameSpecPtr);
199 
200  QVBoxLayout* thisDisplayLayout = new QVBoxLayout;
201  thisDisplayLayout->addWidget(_tabWidget);
202  thisDisplayLayout->addWidget(_settingsDisplay);
203  QWidget* tmpWidget = new QWidget();
204  tmpWidget->setContentsMargins(0,5,0,0);
205  tmpWidget->setLayout(thisDisplayLayout);
206 
207  setCentralWidget(tmpWidget);
208 
209 }
210 
212 {
213  return _tabWidget->hasChanges();
214 }
215 
218 {
219  return _tabWidget->loadData(idSpec);
220 }
221 
224 {
225  return _tabWidget->loadData(idSpec);
226 }
227 
230  const dbutils::daqconfig::IDSpec& newIdSpec,
231  const dbutils::daqconfig::GlobalNameSpec& newNameSpec)
232 {
233  return _tabWidget->saveChanges(oldIdSpec, newIdSpec, newNameSpec);
234 }
235 
237 {
239 }
240 
242  {
243  ///////////////////////////////////
244  // Prompt for location of the csv
245  std::string detName=_globalNameSpecPtr->getDetectorName();
246  std::string detDir;
247  std::string pedDir ="";
248  // novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_PEDESTAL_DIR");
249  if(pedDir == "")
250  {
251  std::string stdConfigFile = "/nova/config/" + detName + "/pedestals/PedestalConfiguration_Standard_" + detName+ ".xml";
252  std::ifstream in(stdConfigFile.c_str());
254  if(in.is_open()) {
255  while(getline(in, line)) {
256  size_t pos = line.find("<dataDir>");
257  if(pos != std::string::npos && pos < line.size()) {
258  pedDir = line.substr(pos + 9, line.find("</dataDir>") - pos - 9);
259  break;
260  }
261  }
262  }
263  }
264 
265  if(pedDir != "")
266  detDir = pedDir + "/PedestalData/PedScans";
267  else
268  detDir = "/";
269 
270  QFileDialog peddialog(this);
271  peddialog.setViewMode(QFileDialog::Detail);
272  QString folderName = peddialog.getExistingDirectory(this, tr("Select Pedestal Directory."),
273  detDir.c_str(),
274  QFileDialog::ShowDirsOnly|QFileDialog::DontUseNativeDialog);
275  if(folderName==""){return;}
276 
277  /////////////////////////////////
278  // DB load confirmation box
279  QMessageBox confirmBox(this);
280  int count;
281  std::ostringstream pixels;
282  std::ostringstream febs;
283  std::ostringstream dcms;
284 
285  boost::filesystem::path p(folderName.toUtf8().constData());
286  boost::filesystem::path uniquestamp = p.filename();
287 
288  std::string threshFileName = folderName.toUtf8().constData();
289  threshFileName.append("/thresholds_");
290  threshFileName.append(uniquestamp.string());
291  threshFileName.append(".csv");
292  std::string pixelFileName = folderName.toUtf8().constData();
293  pixelFileName.append("/pixelmask_");
294  pixelFileName.append(uniquestamp.string());
295  pixelFileName.append(".csv");
296  std::string febFileName = folderName.toUtf8().constData();
297  febFileName.append("/febmask_");
298  febFileName.append(uniquestamp.string());
299  febFileName.append(".csv");
300 
301 
302  std::ifstream threshFile(threshFileName.c_str());
303  count=std::count(std::istreambuf_iterator<char>(threshFile),
304  std::istreambuf_iterator<char>(), '\n');
305  pixels << count;
306 
307  std::ifstream pixelFile(pixelFileName.c_str());
308  count=std::count(std::istreambuf_iterator<char>(pixelFile),
309  std::istreambuf_iterator<char>(), '\n');
310  febs << count;
311 
312  std::ifstream febFile(febFileName.c_str());
313  count=std::count(std::istreambuf_iterator<char>(febFile),
314  std::istreambuf_iterator<char>(), '\n');
315  dcms << count;
316 
317  std::string msgText = "You are about to load threholds and masks from ";
318  msgText.append(folderName.toUtf8().constData());
319  msgText.append("\n\n Found results from ");
320  msgText.append(pixels.str());
321  msgText.append(" pixels, ");
322  msgText.append(febs.str());
323  msgText.append(" febs and ");
324  msgText.append(dcms.str());
325  msgText.append(" dcms.");
326  confirmBox.setText(msgText.c_str());
327 
328  msgText = "Are you sure that you want to load these values? ";
329  confirmBox.setInformativeText(msgText.c_str());
330  confirmBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
331  confirmBox.setDefaultButton(QMessageBox::No);
332  int retCode = confirmBox.exec();
333  if (retCode != QMessageBox::Yes) {return;}
334 
335  //////////
336  // Ask if user want to overide all setting in the config or simply append
337  // apply proper defualts if they want to override
338  QMessageBox loadBox(this);
339  msgText = "Do you want to override ALL existing exceptions underneath the defaults or append the results?";
340  loadBox.setText(msgText.c_str());
341  loadBox.addButton(tr("Override"),QMessageBox::AcceptRole);
342  loadBox.addButton(tr("Append"),QMessageBox::NoRole);
343  loadBox.addButton(QMessageBox::Cancel);
344  loadBox.setDefaultButton(QMessageBox::Cancel);
345  retCode = loadBox.exec();
346  std::string configName = _globalNameSpecPtr->getConfigName();
347  std::string systemCommand = "LoadEnableMasksAndThresholds NovaDatabase/tables/DAQConfig ";
348  if (retCode == QMessageBox::Cancel){return;}
349  else if (retCode == QMessageBox::AcceptRole) {
350  std::string tmpstring;
351  tmpstring = folderName.toUtf8().constData();
352  tmpstring.append("/febXXXXXX");
353  char *febTmpName = new char[tmpstring.length() + 1];
354  strcpy(febTmpName, tmpstring.c_str()); // Get temp name
355 
356  tmpstring = folderName.toUtf8().constData();
357  tmpstring.append("/pixelXXXXXX");
358  char *pixelTmpName = new char[tmpstring.length() + 1]; // Get temp name
359  strcpy(pixelTmpName, tmpstring.c_str()); // Get temp name
360 
361  tmpstring =folderName.toUtf8().constData();
362  tmpstring.append("/thresholdXXXXXX");
363  char *threshTmpName = new char[tmpstring.length() + 1]; // Get temp name
364  strcpy(threshTmpName, tmpstring.c_str()); // Get temp name
365 
366  mkstemp(febTmpName);
367  mkstemp(pixelTmpName);
368  mkstemp(threshTmpName);
369  FILE * febFileTmp = fopen (febTmpName, "w");
370  FILE * pixelFileTmp = fopen (pixelTmpName, "w");
371  FILE * threshFileTmp = fopen (threshTmpName, "w");
372 
373  std::string systemCommandtmp = "";
374 
375  //defaults
376  fputs ("1,default,0,0,1,2,3,4\n", febFileTmp);
377  fputs ("1,default,-1,0,0,1,2,3,4\n",pixelFileTmp);
378  fputs ("1,default,-1,-1,200,0,1,2,3,4\n",threshFileTmp);
379  fclose(febFileTmp);
380  fclose(pixelFileTmp);
381  fclose(threshFileTmp);
382  systemCommandtmp.append(systemCommand);
383  systemCommandtmp.append(febTmpName);
384  systemCommandtmp.append(" ");
385  systemCommandtmp.append(pixelTmpName);
386  systemCommandtmp.append(" ");
387  systemCommandtmp.append(threshTmpName);
388  systemCommandtmp.append(" ");
389  systemCommandtmp.append(configName);
390  system(systemCommandtmp.c_str());
391 
392  remove(febTmpName);
393  remove(pixelTmpName);
394  remove(threshTmpName);
395  }
396 
397  /////////////////////////////////
398  // Prompt user with status ans load into the database
399  //#Output the database environment
400  //echo
401  //echo 'Loading into' $NOVADBNAME 'on' $NOVADBHOST 'at port' $NOVADBPORT '....'
402 
403  //#Load the Thesholds and Masks
404 
405  systemCommand.append(febFileName);
406  systemCommand.append(" ");
407  systemCommand.append(pixelFileName);
408  systemCommand.append(" ");
409  systemCommand.append(threshFileName);
410  systemCommand.append(" ");
411  systemCommand.append(configName);
412  system(systemCommand.c_str());
413 
414  ///////////////////////////////
415  //Refresh the editor
417 
418 } // end of loadThresholdsAndMasks
419 
420 } // end of namespace gui
421 } // end of namespace dbutils
422 
system("rm -rf microbeam.root")
const char * p
Definition: xmltok.h:285
static EnvVarCache & getInstance()
Definition: EnvVarCache.cpp:12
OStream cerr
Definition: OStream.cxx:7
void isTopLevel(bool setting=true)
bool saveChanges(const dbutils::daqconfig::IDSpec &oldGlobalIdSpec, const dbutils::daqconfig::IDSpec &newGlobalIdSpec, const dbutils::daqconfig::GlobalNameSpec &newGlobalNameSpec)
void _addHelpMenu(std::string customText="")
def connect(endpoint="tcp://127.0.0.1:5555")
Definition: g4zmq.py:15
fclose(fg1)
bool _doSaveChanges(const dbutils::daqconfig::IDSpec &oldIdSpec, const dbutils::daqconfig::IDSpec &newIdSpec, const dbutils::daqconfig::GlobalNameSpec &newNameSpec)
boost::shared_ptr< dbutils::daqconfig::GlobalNameSpec > _globalNameSpecPtr
bool loadData(const dbutils::daqconfig::IDSpec &idSpec)
bool _doLoadNewDataset(const dbutils::daqconfig::IDSpec &idSpec)
const std::string path
Definition: plot_BEN.C:43
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
ifstream in
Definition: comparison.C:7
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
bool _doReloadCurrentDataset(const dbutils::daqconfig::IDSpec &idSpec)
detName
Definition: mkDefs.py:106
int addTab(QWidget *page, const QString &label)