GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4AnalysisConfiguration.cpp
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
15 
16 #include <QFileDialog>
17 #include <QCloseEvent>
18 
19 #include "TGo4ConfigStep.h"
20 #include "TGo4AnalysisStatus.h"
21 #include "TGo4AnalysisStepStatus.h"
22 #include "TGo4ServerProxy.h"
23 
24 
25 TGo4AnalysisConfiguration::TGo4AnalysisConfiguration(QWidget *parent, const char *name) :
26  QGo4Widget(parent, name)
27 {
28  setupUi(this);
29 
30  QObject::connect(SubmitPushButton, &QPushButton::pressed, this, &TGo4AnalysisConfiguration::SubmitConfiguration);
31  QObject::connect(AnalysisSaveConf, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::SaveConfiguration);
32  QObject::connect(LoadConfigFileName, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::FileDialog_ConfFile);
33  QObject::connect(LoadAutoSaveFileName, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::FileDialog_AutoSave);
34  QObject::connect(AutoSaveFileName, &QLineEdit::textChanged, this, &TGo4AnalysisConfiguration::LineEdit_AutoSaveFile);
35  QObject::connect(GetActiveConfigButton, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::RequestAnalysisStatus);
36  QObject::connect(CompLevel, QOverload<int>::of(&QSpinBox::valueChanged), this, &TGo4AnalysisConfiguration::SetCompressionLevel);
37  QObject::connect(AnalysisLoadConf, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::LoadConfiguration);
38  QObject::connect(AutoSaveInterval, QOverload<int>::of(&QSpinBox::valueChanged), this, &TGo4AnalysisConfiguration::SetAutoSaveInterval);
39  QObject::connect(AutoSaveOverwrite, &QCheckBox::toggled, this, &TGo4AnalysisConfiguration::SetAutoSaveOverwrite);
40  QObject::connect(SaveNowB, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::WriteAutoSave);
41  QObject::connect(AutoSaveEnable, &QCheckBox::toggled, this, &TGo4AnalysisConfiguration::EnableAutoSaveSlot);
42  QObject::connect(SubmitAndStartButton, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::SubmitAndStart);
43  QObject::connect(ClosePushButton, &QPushButton::clicked, this, &TGo4AnalysisConfiguration::CloseAnalysis);
44 
45  fSourcePath = ".";
46  fStorePath = ".";
47  fConfigPath = ".";
48  fAutoSavePath = ".";
49  fbTypingMode = true;
50  setCanDestroyWidget(false);
51 }
52 
53 
54 bool TGo4AnalysisConfiguration::IsAcceptDrag(const char *itemname, TClass *cl, int kind)
55 {
56  return false;
57 // if (!cl) return false;
58 // return cl->InheritsFrom(TGo4AnalysisStatus::Class());
59 }
60 
61 void TGo4AnalysisConfiguration::DropItem(const char *itemname, TClass *cl, int kind)
62 {
63 // if (!cl) return;
64 
65 // if (cl->InheritsFrom(TGo4AnalysisStatus::Class()))
66 // WorkWithStatus(itemname);
67 }
68 
69 void TGo4AnalysisConfiguration::linkedObjectUpdated(const char *linkname, TObject *obj)
70 {
71  if (strcmp(linkname,"Status") == 0) {
72  parentWidget()->raise();
73  parentWidget()->show();
74  if (parentWidget()->isMinimized()) parentWidget()->showNormal();
75  RefreshWidget();
76 
77  auto anl = GetLinkedCast<TGo4ServerProxy>("Analysis");
78  if (anl)
79  anl->RefreshNamesList();
80  }
81 }
82 
84 {
85  ShootCloseWidget(true);
86 }
87 
89 {
90  ResetWidget();
91 
92  if (!anal) {
93  ShootCloseWidget(true);
94  return;
95  }
96 
97  AddLink(anal->ParentSlot(), "Analysis");
98  AddLink(anal->SettingsSlot(), "Status");
99 
100  RefreshWidget();
101 }
102 
104 {
106 
107  QWidget *w = nullptr;
108  do {
109  w = TabSteps->currentWidget();
110  if (w) {
111  TabSteps->removeTab(TabSteps->indexOf(w));
112  delete w;
113  }
114  } while (w);
115 }
116 
118 {
119  auto status = GetLinkedCast<TGo4AnalysisStatus>("Status");
120  auto anl = GetLinkedCast<TGo4ServerProxy>("Analysis");
121 
122  if (!status || !anl) return;
123 
124  SubmitPushButton->setEnabled(anl->CanSubmitObjects());
125  SubmitAndStartButton->setEnabled(anl->CanSubmitObjects());
126 
127  fbTypingMode = false;
128 
129  QWidget *w = nullptr;
130  do {
131  w = TabSteps->currentWidget();
132  if (w) {
133  TabSteps->removeTab(TabSteps->indexOf(w));
134  delete w;
135  }
136  } while (w);
137 
138  for (int i = 0; i < status->GetNumberOfSteps(); i++) {
139  TGo4AnalysisStepStatus *stepstatus = status->GetStepStatus(i);
140  if (!stepstatus) continue;
141  QString StepName = stepstatus->GetName();
142  TGo4ConfigStep* NewStep = new TGo4ConfigStep(TabSteps, StepName.toLatin1().constData());
143  NewStep->SetStepStatus(this, stepstatus, status->GetNumberOfSteps() > 1 ? i : -1);
144  TabSteps->insertTab(i, NewStep, NewStep->GetTabTitle());
145  }
146 
147  TabSteps->setCurrentIndex(0);
148  TabSteps->adjustSize();
149 
150  SetAutoSaveConfig(status->GetAutoFileName(),
151  status->GetAutoSaveInterval(),
152  status->GetAutoSaveCompression(),
153  status->IsAutoSaveOn(),
154  status->IsAutoSaveOverwrite());
155 
156  SetAnalysisConfigFile(status->GetConfigFileName());
157 
158  parentWidget()->showNormal();
159  parentWidget()->adjustSize();
160 
161  fbTypingMode = true;
162 }
163 
165 {
166  if (number >= 0)
167  TabSteps->setTabText(number, step->GetTabTitle());
168 }
169 
170 
172 {
173  return fSourcePath;
174 }
175 
177 {
178  return fStorePath;
179 }
180 
182 {
183  fSourcePath = v;
184 }
185 
187 {
188  fStorePath = v;
189 }
190 
192 {
193  auto anl = GetLinkedCast<TGo4ServerProxy>("Analysis");
194  if (anl)
195  anl->RequestAnalysisSettings();
196 }
197 
199 {
200  QFileDialog fd(this,
201  "Select a configuration file",
202  fConfigPath,
203  " Configuration file (*.root)");
204  fd.setFileMode( QFileDialog::AnyFile);
205  if (fd.exec() != QDialog::Accepted) return;
206  QStringList flst = fd.selectedFiles();
207  QString fileName = flst.isEmpty() ? QString() : flst[0];
208  fConfigPath = fd.directory().path();
209  if(!fileName.endsWith(".root")) fileName.append(".root");
210  ConfigFileName->setText(fileName);
211 }
212 
214 {
215  QFileDialog fd( this,
216  "Select file name for autosaving",
218  "Auto Save File (*.root)");
219  fd.setFileMode(QFileDialog::AnyFile);
220  fd.setAcceptMode(QFileDialog::AcceptSave);
221  if (fd.exec() != QDialog::Accepted) return;
222 
223  QStringList flst = fd.selectedFiles();
224  if (flst.isEmpty()) return;
225 
226  QString fileName = flst[0];
227  fAutoSavePath = fd.directory().path();
228  if(!fileName.endsWith(".root")) fileName.append(".root");
229  AutoSaveFileName->setText(fileName);
231 }
232 
234 {
235  QString fname = AutoSaveFileName->text().trimmed();
236  auto status = GetLinkedCast<TGo4AnalysisStatus>("Status");
237  if (status && fbTypingMode)
238  status->SetAutoFileName(fname.toLatin1().constData());
239 }
240 
242 {
243  auto status = GetLinkedCast<TGo4AnalysisStatus>("Status");
244  if (status && fbTypingMode)
245  status->SetAutoSaveCompression(t);
246 }
247 
249 {
250  QString fname = ConfigFileName->text().trimmed();
251  auto anl = GetLinkedCast<TGo4ServerProxy>("Analysis");
252  if (anl)
253  anl->LoadConfigFile(fname.toLatin1().constData());
255 }
256 
258 {
259  QString fname = ConfigFileName->text().trimmed();
260  auto anl = GetLinkedCast<TGo4ServerProxy>("Analysis");
261  if (anl)
262  anl->SaveConfigFile(fname.toLatin1().constData());
263 }
264 
266 {
267  ServiceCall("SubmitAnalysisSettings");
268 }
269 
271 {
272  ServiceCall("SubmitStartAnalysis");
273  parentWidget()->hide();
274 }
275 
277 {
278  ServiceCall("CloseAnalysisSettings");
279 }
280 
282 {
283  auto status = GetLinkedCast<TGo4AnalysisStatus>("Status");
284  if (status && fbTypingMode)
285  status->SetAutoSaveInterval(t);
286 }
287 
289 {
290  auto status = GetLinkedCast<TGo4AnalysisStatus>("Status");
291  if (status && fbTypingMode)
292  status->SetAutoSaveOverwrite(overwrite);
293 }
294 
296 {
297  auto status = GetLinkedCast<TGo4AnalysisStatus>("Status");
298  auto anl = GetLinkedCast<TGo4ServerProxy>("Analysis");
299 
300  if (anl && status)
301  anl->WriteAutoSave(status->GetAutoFileName(),
302  status->GetAutoSaveCompression(),
303  status->IsAutoSaveOverwrite());
304 }
305 
307 {
308  auto status = GetLinkedCast<TGo4AnalysisStatus>("Status");
309  if (status && fbTypingMode)
310  status->SetAutoSaveOn(enabled);
311  AutoSaveInterval->setEnabled(enabled);
312 }
313 
315 {
316  return TabSteps->count();
317 }
318 
320 {
321  if ((n<0) || (n>=TabSteps->count())) return nullptr;
322  return dynamic_cast<TGo4ConfigStep*> (TabSteps->widget(n));
323 }
324 
326 {
327  for (int n = 0; n < GetNumSteps(); n++) {
328  TGo4ConfigStep *conf = GetStepConfig(n);
329  if (conf)
330  if (conf->GetStepName() == name)
331  return conf;
332  }
333  return nullptr;
334 }
335 
337  int interval,
338  int compression,
339  bool enabled,
340  bool overwrite)
341 {
342  AutoSaveFileName->setText(filename);
343  AutoSaveInterval->setValue(interval);
344  CompLevel->setValue(compression);
345 
346  AutoSaveOverwrite->setChecked(overwrite);
347  AutoSaveEnable->setChecked(enabled);
348 
349  AutoSaveInterval->setEnabled(enabled);
350 }
351 
353  int& interval,
354  int& compression,
355  bool& enabled,
356  bool& overwrite)
357 {
358  filename = AutoSaveFileName->text();
359  interval = AutoSaveInterval->value();
360  compression = CompLevel->value();
361 
362  overwrite = AutoSaveOverwrite->isChecked();
363  enabled = AutoSaveEnable->isChecked();
364 }
365 
367 {
368  ConfigFileName->setText(filename);
369 }
370 
372 {
373  filename = ConfigFileName->text();
374 }
375 
376 void TGo4AnalysisConfiguration::DisplayMbsMonitor(const QString& mbsname )
377 {
378  ServiceCall("DisplayMbsMonitor", (void *) mbsname.toLatin1().constData());
379 }
380 
382 {
383  e->ignore(); // destroying this would mix up the upper level management
384  QWidget *mdi = parentWidget();
385  if (mdi)
386  mdi->hide(); // instead of destroying, we just hide it when X is clicked. JAM
387 }
388 
virtual void ResetWidget()
Definition: QGo4Widget.cpp:52
virtual void SetStepStatus(TGo4AnalysisConfiguration *panel, TGo4AnalysisStepStatus *StepStatus, int number=-1)
virtual void LineEdit_AutoSaveFile(const QString &)
virtual void GetAnalysisConfigFile(QString &filename)
void linkedObjectUpdated(const char *linkname, TObject *obj) override
void ShootCloseWidget(bool closeparent=false)
Definition: QGo4Widget.cpp:70
virtual QString GetTabTitle()
virtual void SetAutoSaveConfig(QString filename, int interval, int compression, bool enbaled, bool overwrite)
TGo4ConfigStep * GetStepConfig(int n)
virtual void SetSourcePath(const QString &v)
virtual void SetAutoSaveOverwrite(bool overwrite)
void closeEvent(QCloseEvent *e) override
void linkedObjectRemoved(const char *linkname) override
void ServiceCall(const char *name, void *par=nullptr)
Definition: QGo4Widget.cpp:398
void setCanDestroyWidget(bool on=true)
Definition: QGo4Widget.h:201
void DropItem(const char *itemname, TClass *cl, int kind) override
TGo4AnalysisConfiguration(QWidget *parent=nullptr, const char *name=nullptr)
bool IsAcceptDrag(const char *itemname, TClass *cl, int kind) override
virtual void GetAutoSaveConfig(QString &filename, int &interval, int &compression, bool &enbaled, bool &overwrite)
TGo4Slot * SettingsSlot()
virtual QString GetStepName()
TGo4Slot * ParentSlot()
TGo4ConfigStep * FindStepConfig(QString name)
virtual void SetStorePath(const QString &v)
virtual void EnableAutoSaveSlot(bool disabled)
void AddLink(const char *itemname, const char *linkname)
Definition: QGo4Widget.cpp:117
virtual void WorkWithAnalysis(TGo4ServerProxy *anal)
virtual void DisplayMbsMonitor(const QString &mbsname)
virtual void SetAnalysisConfigFile(QString filename)
void ChangeTabTitle(TGo4ConfigStep *step, int number)