GSI Object Oriented Online Offline (Go4)  GO4-5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4CommandLine.cpp
Go to the documentation of this file.
1 // $Id: TGo4CommandLine.cpp 1803 2015-11-20 09:15:02Z adamczew $
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 für 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 
14 #include "TGo4CommandLine.h"
15 
16 #include "Riostream.h"
17 #include "TROOT.h"
18 
19 #include <QFileDialog>
20 
21 #include "TGo4Log.h"
22 #include "TGo4QSettings.h"
23 #include "TGo4MacroDialog.h"
24 
25 TGo4CommandLine::TGo4CommandLine(QWidget *parent, const char* name) :
26  QGo4Widget(parent, name),fbPythonBound(false)
27 {
28  setupUi(this);
29  LoadHistory();
30 }
31 
32 
34 {
35  QFileDialog fd( this, "Select ROOT macro to execute in GUI", QString(),
36  "ROOT macro (*.C *.c);;Go4 hotstart script (*.hotstart);;Python script(*.py)");
37  fd.setFileMode( QFileDialog::ExistingFile);
38 
39  if (fd.exec() != QDialog::Accepted) return;
40 
41  QStringList flst = fd.selectedFiles();
42  if (flst.isEmpty()) return;
43  bool iscint = fd.selectedNameFilter().contains(".C") || fd.selectedNameFilter().contains(".c");
44  bool ishot = fd.selectedNameFilter().contains(".hotstart");
45  bool ispyth = fd.selectedNameFilter().contains(".py");
46 
47  QString cmd;
48  if (iscint)
49  {
50  cmd = QString(".x ") + flst[0];
51  }
52  else if (ispyth)
53  {
54  cmd = QString("$") + flst[0];
55  }
56  else if (ishot)
57  {
58  cmd = flst[0];
59  }
60  else
61  {
62  std::cout << "TGo4CommandLine NEVER COME HERE - unknown file type!\n-" << std::endl;
63  return;
64  }
65 
66  int index=InputLine->findText(cmd);
67  if(index<0)
68  {
69  InputLine->insertItem(-1,cmd);
70  index=InputLine->findText(cmd);
71  }
72  //std::cout <<"inserted item "<< cmd.toLatin1().constData() << std::endl;
73  InputLine->setCurrentIndex(index);
74 
75 }
76 
78 {
80 }
81 
82 
84 {
85  const char pyprompt = '$';
86  QString pyinitfile="python/go4init.py"; // JAM put this to settings later?
87  QString str = InputLine->currentText();
88  if (str.length() == 0)
89  return;
90 
91  if (str.contains("help") || str.contains(".go4h"))
92  {
93  PrintHelp();
94  }
95  else if (str.contains(".hotstart") && !str.contains(".x"))
96  {
97  StatusMessage(QString("Executing hotstart script: ") + str);
98  StartHotstart(str.toLatin1().constData());
99  }
100  else
101  {
102  // process cint line, check if python or not:
103  if (str.contains(pyprompt))
104  {
105  // Python support as initiated by Sven Augustin, MPI Heidelberg
106  str.remove(0, str.indexOf(pyprompt) + 1);
107  StatusMessage(QString("Executing Python script: ") + str);
108  str = "TPython::LoadMacro(\"" + str + "\")";
109  if (!fbPythonBound)
110  {
111  QString go4sys=TGo4Log::GO4SYS();
112  str.prepend("TPython::LoadMacro(\"" + go4sys + pyinitfile +"\");");
113  str.prepend("TPython::Bind(TGo4AbstractInterface::Instance(), \"go4\");");
114  fbPythonBound = kTRUE;
115  }
116 
117  }
118  else
119  {
120  StatusMessage(QString("Executing command: ") + str);
121  }
122  gROOT->ProcessLineSync(str.toLatin1().constData());
123  }
124  go4sett->setCommandsHistoryGUI(InputLine->getHistory(50));
125 }
126 
128 {
129 // read command history from settings:
130  QStringList histlist = go4sett->getCommandsHistoryGUI();
131  InputLine->addItems(histlist);
132 // prepared pre-loading of system macros:
133  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/corrhistos.C").Data()));
134  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/hishisto.C").Data()));
135  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/addhistos.C").Data()));
136  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/divhistos.C").Data()));
137  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/profileX.C").Data()));
138  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/profileY.C").Data()));
139  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/projectionX.C").Data()));
140  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/projectionY.C").Data()));
141  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/rebin.C").Data()));
142  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/scalex.C").Data()));
143  gROOT->ProcessLineSync(Form(".L %s", TGo4Log::subGO4SYS("macros/fft.C").Data()));
144 
145 }
146 
147 
149 {
150  TGo4MacroDialog md;
151  if (md.exec() != QDialog::Accepted) return;
152  InputLine->insertItem(0, md.getCommand());
153  InputLine->setCurrentIndex(0);
154 }
155 
156 
158 {
159  std::cout <<"\n--- Go4 GUI command line short help --- " << std::endl;
160  std::cout <<"- execute any command by pressing RETURN (Enter key)" << std::endl;
161  std::cout <<"--" << std::endl;
162  std::cout <<"- use '.h' for help concerning ROOT commands" << std::endl;
163  std::cout <<"--" << std::endl;
164  std::cout <<"- use 'go4->...' to access TGo4AbstractInterface for gui commands" << std::endl;
165  std::cout <<"--" << std::endl;
166  std::cout <<"- Some useful Go4 GUI command functions:" << std::endl;
167 
168  std::cout <<"\t- TObject* go4->GetObject(const char* itemname);"<< std::endl;
169  std::cout <<"\t\t: get browser object by full pathname. " << std::endl;
170  std::cout <<"\t- TString go4->FindItem(const char* name); " << std::endl;
171  std::cout <<"\t\t: get full pathname of browser object by name " << std::endl;
172  std::cout <<"\t- TString go4->SaveToMemory(const char* path, TObject* obj, Bool_t ownership = kFALSE);"<< std::endl;
173  std::cout <<"\t\t: Put object obj into workspace memory under subfolder path. Returns full item pathname. " << std::endl;
174  std::cout <<"\t- ViewPanelHandle go4->StartViewPanel()"<< std::endl;
175  std::cout <<"\t\t: Open new Go4 viewpanel with default size. Returns handle of new panel." << std::endl;
176  std::cout <<"\t- Bool_t go4->DrawItem(const char* itemname, ViewPanelHandle panel = 0, const char* drawopt = 0);"<< std::endl;
177  std::cout <<"\t\t: Draw object of full name itemname onto viewpanel panel. Will open new viewpanel if panel not specified. \n\t ROOT drawoption may be set. " << std::endl;
178  std::cout <<"\t- go4->OpenFile(const char* fname)" << std::endl;
179  std::cout <<"\t\t: open ROOT file of fname in Go4 browser " << std::endl;
180  std::cout <<"\t- go4->LaunchAnalysis()" << std::endl;
181  std::cout <<"\t\t: Start Go4 analysis process with previous set up " << std::endl;
182  std::cout <<"--" << std::endl;
183  std::cout <<"---- Please: note the Go4 helpwindow with TGo4AbstractInterface full method documentation!" << std::endl;
184  std::cout <<"---- see example scripts at $GO4SYS/macros !" << std::endl;
185  std::cout <<"---- visit our website at: \t http://go4.gsi.de !" << std::endl;
186  std::cout <<"------ " << std::endl;
187  HelpWindow("docs/Go4Reference.pdf", "Show Go4 Reference manual...");
188 }
void StartHotstart(const char *filename)
Definition: QGo4Widget.cpp:339
TGo4CommandLine(QWidget *parent=0, const char *name=0)
virtual void ExecuteSlot()
virtual void LoadHistory()
virtual void FileSearchDialog()
const QString & getCommand()
void StatusMessage(const QString &message)
Definition: QGo4Widget.cpp:244
virtual void PrintHelp()
TGo4QSettings * go4sett
virtual void PredefinedDialog()
void HelpWindow(const char *filename, const char *msg=0)
Definition: QGo4Widget.cpp:334
virtual void enterPressedSlot()
QStringList getCommandsHistoryGUI()
static TString subGO4SYS(const char *subdir)
Definition: TGo4Log.cxx:192
static const char * GO4SYS()
Definition: TGo4Log.cxx:158
void setCommandsHistoryGUI(const QStringList &commands)