Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4GUI/TGo4AnalysisWindow.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4AnalysisWindow.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TSystem.h"
00021 
00022 #include "qtextbrowser.h"
00023 #include "qmime.h"
00024 #include "qdragobject.h"
00025 #include "qlayout.h"
00026 #include "qtooltip.h"
00027 #include "qwhatsthis.h"
00028 #include "qimage.h"
00029 #include "qpixmap.h"
00030 #include "qtimer.h"
00031 #include "qlabel.h"
00032 #include "qcombobox.h"
00033 #include "qfiledialog.h"
00034 #include "qmessagebox.h"
00035 #include "qstatusbar.h"
00036 #include "qprocess.h"
00037 #include "qtextedit.h"
00038 #include "qpushbutton.h"
00039 #include "qtoolbutton.h"
00040 
00041 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00042 #include "Go4CommandsTaskHandler/TGo4ComExecLine.h"
00043 #include "TGo4RemoteBrowserSlots.h"
00044 #include "TGo4MainWindow.h"
00045 #include "TGo4AnalysisStatusMonitor.h"
00046 #include "TGo4QSettings.h"
00047 
00048 class QComandsHistory : public QComboBox {
00049    public:
00050       QComandsHistory(QWidget* w, const char* name);
00051 
00052       bool EnterPressed() const { return fiEnterPressed == 1; }
00053       void ResetEnterPressed() { fiEnterPressed = -1; }
00054       void SetEnterPressed(int val){fiEnterPressed=val;}
00055    protected:
00056       virtual void keyPressEvent(QKeyEvent* e);
00057       int fiEnterPressed;
00058 };
00059 
00060 
00061 QComandsHistory::QComandsHistory(QWidget* w, const char* name) :
00062     QComboBox(TRUE, w, name) {
00063    setMaxCount(50);
00064    setInsertionPolicy(AtTop);
00065    setDuplicatesEnabled(FALSE);
00066    setAutoCompletion(TRUE);
00067    fiEnterPressed = 0;
00068 }
00069 
00070 void QComandsHistory::keyPressEvent(QKeyEvent* e) {
00071    if (e->key()==Qt::Key_Return) {
00072      fiEnterPressed = (fiEnterPressed+1) % 2;
00073    }
00074    QComboBox::keyPressEvent(e);
00075 }
00076 
00077 
00078 // **********************************************************
00079 
00080 
00081 
00082 
00083 /*
00084  *  Constructs a TGo4AnalysisWindow which is a child of 'parent', with the
00085  *  name 'name' and widget flags set to 'f'.
00086  */
00087 TGo4AnalysisWindow::TGo4AnalysisWindow( QWidget* parent, const char* name,  WFlags fl )
00088     : QWidget( parent, name, fl )
00089 {
00090     fxTGo4GUIRegistry=TGo4GUIRegistry::Instance();
00091     if ( !name )
00092    setName( "TGo4AnalysisWindow" );
00093     resize( 700, 400 ); // 564, 418
00094     setCaption( trUtf8( "Analysis Terminal" ) );
00095     setIcon( TGo4MainWindow::uic_load_pixmap( "go4logo2" ) );
00096     TGo4AnalysisWindowLayout = new QGridLayout( this, 1, 1, 11, 6, "TGo4AnalysisWindowLayout");
00097     fxOutput = new QTextEdit( this, "output" );
00098     fxOutput->setUndoRedoEnabled(FALSE);
00099     fxOutput->setAutoFormatting(QTextEdit::AutoNone);
00100     fxOutput->setWordWrap(QTextEdit::NoWrap);
00101     fxOutput->setReadOnly(TRUE);
00102     TGo4AnalysisWindowLayout->addWidget( fxOutput, 0, 0 );
00103 
00104     fiMaxOuputSize = 100000;
00105     ReadHistorySize();
00106 
00107     UpdateTimer = new QTimer(this);
00108     connect(UpdateTimer, SIGNAL(timeout()), this, SLOT(updateTerminalOutput()));
00109     UpdateTimer->start(100, TRUE);
00110     outputBuffer = "";
00111 
00112 
00113 //    RemoteMacro =new QLineEdit(this);
00114 //      connect( RemoteMacro, SIGNAL(returnPressed()),   this, SLOT(ExeRemMacro()) );
00115 
00116     fxCmdHist = new QComandsHistory(this, "commandslist");
00117     QToolTip::add(fxCmdHist, trUtf8( "CINT command for analysis process. Note: '@' means 'TGo4Analysis::Instance()->' ." ) );
00118     connect(fxCmdHist, SIGNAL(activated(const QString&)),  this, SLOT(HistActivated(const QString&)));
00119 
00120 
00121     QHBoxLayout *box1=new QHBoxLayout(TGo4AnalysisWindowLayout);
00122     QLabel *info=new QLabel(this);
00123     info->setText("Press enter to execute.");
00124     MacroSearch = new QToolButton( this, "MacroSearch" );
00125     MacroSearch->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, MacroSearch->sizePolicy().hasHeightForWidth() ) );
00126     MacroSearch->setMinimumSize( QSize( 30, 25 ) );
00127     MacroSearch->setMaximumSize( QSize( 30, 25 ) );
00128     MacroSearch->setPixmap( QPixmap::fromMimeSource( "" ) );
00129     MacroSearch->setIconSet( QIconSet( QPixmap::fromMimeSource( "findfile.png" ) ) );
00130     QToolTip::add(MacroSearch, trUtf8( "Search root macro on disk." ) );
00131     box1->addWidget(info, 1);
00132 //   box1->addWidget(RemoteMacro);
00133     box1->addWidget(fxCmdHist, 3);
00134     box1->addWidget(MacroSearch,1);
00135 //   TGo4AnalysisWindowLayout->addWidget(info, 2, 0 );
00136 
00138     QHBoxLayout *box2=new QHBoxLayout(TGo4AnalysisWindowLayout);
00139     KillProcess= new QToolButton(this,"KillProcess");
00140     //KillProcess->setText("Kill analysis");
00141 
00142     KillProcess->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, KillProcess->sizePolicy().hasHeightForWidth() ) );
00143     KillProcess->setMinimumSize( QSize( 30, 25 ) );
00144     KillProcess->setMaximumSize( QSize( 30, 25 ) );
00145     KillProcess->setPixmap( QPixmap::fromMimeSource( "" ) );
00146     KillProcess->setIconSet( QIconSet( QPixmap::fromMimeSource( "killanal.png" ) ) );
00147     QToolTip::add( KillProcess, trUtf8( "Apply Ctrl+C in the analysis terminal." ) );
00148 
00149 
00150 
00151 //   TGo4AnalysisWindowLayout->addWidget(KillProcess, 3, 0 );
00152     ClearButton = new QToolButton( this, "ClearButton" );
00153     ClearButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, ClearButton->sizePolicy().hasHeightForWidth() ) );
00154     ClearButton->setMinimumSize( QSize( 30, 25 ) );
00155     ClearButton->setMaximumSize( QSize( 30, 25 ) );
00156     ClearButton->setPixmap( QPixmap::fromMimeSource( "" ) );
00157     ClearButton->setIconSet( QIconSet( QPixmap::fromMimeSource( "clear.png" ) ) );
00158     QToolTip::add(ClearButton, trUtf8( "Clear Terminal Window." ) );
00159 
00160     PrintHistoButton = new QToolButton( this, "PrintHistoButton" );
00161     PrintHistoButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, PrintHistoButton->sizePolicy().hasHeightForWidth() ) );
00162     PrintHistoButton->setMinimumSize( QSize( 30, 25 ) );
00163     PrintHistoButton->setMaximumSize( QSize( 30, 25 ) );
00164     PrintHistoButton->setPixmap( QPixmap::fromMimeSource( "" ) );
00165     PrintHistoButton->setIconSet( QIconSet( QPixmap::fromMimeSource( "hislist.png" ) ) );
00166     QToolTip::add(PrintHistoButton, trUtf8( "Print list of all histograms." ) );
00167 
00168     PrintConnyButton = new QToolButton( this, "PrintConnyButton" );
00169     PrintConnyButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, PrintConnyButton->sizePolicy().hasHeightForWidth() ) );
00170     PrintConnyButton->setMinimumSize( QSize( 30, 25 ) );
00171     PrintConnyButton->setMaximumSize( QSize( 30, 25 ) );
00172     PrintConnyButton->setPixmap( QPixmap::fromMimeSource( "" ) );
00173     PrintConnyButton->setIconSet( QIconSet( QPixmap::fromMimeSource( "condlist.png" ) ) );
00174     QToolTip::add(PrintConnyButton, trUtf8( "Print list of all conditions." ) );
00175 
00176 
00177     PrintEventButton = new QToolButton( this, "PrintEventButton" );
00178     PrintEventButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, PrintEventButton->sizePolicy().hasHeightForWidth() ) );
00179     PrintEventButton->setMinimumSize( QSize( 30, 25 ) );
00180     PrintEventButton->setMaximumSize( QSize( 30, 25 ) );
00181     PrintEventButton->setPixmap( QPixmap::fromMimeSource( "" ) );
00182     PrintEventButton->setIconSet( QIconSet( QPixmap::fromMimeSource( "zoom.png" ) ) );
00183     QToolTip::add(PrintEventButton, trUtf8( "Start Event Inspection panel" ) );
00184 
00185 
00186     QSpacerItem *sp=new QSpacerItem(1,1);
00187 
00188    box2->addWidget(KillProcess);
00189    box2->addItem(sp);
00190    box2->addWidget(ClearButton,1);
00191    box2->addWidget(PrintHistoButton,1);
00192    box2->addWidget(PrintConnyButton,1);
00193    box2->addWidget(PrintEventButton,1);
00194 
00195     proc = new QProcess();
00196 
00197 
00198     connect( proc, SIGNAL(readyReadStdout()),   this, SLOT(readFromStdout()) );
00199      connect( proc, SIGNAL(readyReadStderr()),   this, SLOT(readFromStderr()) );
00200      connect( proc, SIGNAL(processExited()),    this, SLOT(scrollToTop()) );
00201    connect (KillProcess, SIGNAL(clicked()), this, SLOT(RequestTerminate()));
00202    connect (MacroSearch, SIGNAL(clicked()), this, SLOT(FileDialog_Macro()));
00203    connect (ClearButton, SIGNAL(clicked()), this, SLOT(clearOutput()));
00204    connect (PrintHistoButton, SIGNAL(clicked()), this, SLOT(PrintHistograms()));
00205    connect (PrintConnyButton, SIGNAL(clicked()), this, SLOT(PrintConditions()));
00206    connect (PrintEventButton, SIGNAL(clicked()), this, SLOT(PrintEvent()));
00207 
00208 
00209     Killproc = new QProcess();
00210    //connect( Killproc, SIGNAL(readyReadStdout()),   this, SLOT(readFromStdout()) );
00211 }
00212 
00213 void TGo4AnalysisWindow::ReadHistorySize() {
00214   TGo4QSettings settings;
00215   fiMaxOuputSize = settings.readNumEntry(TGo4QSettings::GetSettingsName()+"/AnalisysTerminal/HistorySize", 100000);
00216 }
00217 
00218 void TGo4AnalysisWindow::updateTerminalOutput() {
00219     unsigned int buflen = outputBuffer.length();
00220 
00221     if (fiMaxOuputSize>0) {
00222 
00223       // size remaining after cut of text
00224       unsigned int cutlength = fiMaxOuputSize / 2;
00225 
00226       if (buflen > 0) {
00227          unsigned int outlen = fxOutput->length();
00228          if (buflen + outlen < fiMaxOuputSize)
00229            fxOutput->append(outputBuffer);
00230          else
00231          if (buflen>=cutlength) {
00232             outputBuffer.remove(0, buflen-cutlength);
00233             fxOutput->setText(outputBuffer);
00234             fxOutput->moveCursor(QTextEdit::MoveEnd, FALSE);
00235          } else {
00236            QString curr = fxOutput->text();
00237            curr.remove(0, cutlength - buflen);
00238            curr+=outputBuffer;
00239            fxOutput->setText(curr);
00240            fxOutput->moveCursor(QTextEdit::MoveEnd, FALSE);
00241          }
00242       }
00243     } else
00244       if (buflen>0)
00245          fxOutput->append(outputBuffer);
00246 
00247     outputBuffer = "";
00248     UpdateTimer->start(100, TRUE);
00249 }
00250 
00251 void TGo4AnalysisWindow::readFromStdout()
00252 {
00253    QString buf = proc->readStdout();
00254     outputBuffer.append(buf);
00255 //   outputBuffer.append(proc->readStdout());
00256 }
00257 
00258 
00259 void TGo4AnalysisWindow::readFromStderr()
00260 {
00261     QString buf = proc->readStderr();
00262     outputBuffer.append(buf);
00263 //   outputBuffer.append(proc->readStderr());
00264 }
00265 
00266 
00267 void TGo4AnalysisWindow::scrollToTop()
00268 {
00269     fxOutput->setContentsPos( 0, 0 );
00270 }
00271 
00272 /*
00273  *  Destroys the object and frees any allocated resources
00274  */
00275 TGo4AnalysisWindow::~TGo4AnalysisWindow()
00276 {
00277 
00278 }
00279 void TGo4AnalysisWindow::StartAnalysisShell(const char* text)
00280 {
00281 //    cout << "TGo4AnalysisWindow  " << text << endl;
00282     QString Com = text;
00283     QString SEP=" ";
00284     QStringList ComList = QStringList::split(SEP,Com);
00285     proc->setArguments(ComList);
00286     if ( !proc->start() ) {
00287       // error handling
00288       cout << "Fatal error Could not start the Analysis" << endl;
00289     }
00290 }
00291 
00292 void TGo4AnalysisWindow::RequestTerminate()
00293 {
00294 
00295      switch( QMessageBox::information( this, "Analysis Terminal",
00296         "Really Kill Analysis Process?",
00297          QMessageBox::Yes | QMessageBox::Default,// Enter == button 0
00298          QMessageBox::No | QMessageBox::Escape // Escape == button 1
00299          ) )
00300     {
00301     case QMessageBox::Yes: // Yes clicked or Alt+Y pressed or Enter pressed.
00302         Terminate();
00303         break;
00304     case QMessageBox::No: // No clicked or Alt+N pressed
00305 
00306         break;
00307     default: // Cancel clicked or Alt+C pressed or Escape pressed
00308 
00309         break;
00310     } //switch
00311 
00312 }
00313 
00314 void TGo4AnalysisWindow::Terminate()
00315 {
00316     TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00317     QString ProcId;
00318     QString Com= "killall ";
00319     Com.append(fxTGo4GUIRegistry->GetClientProgram());
00320        
00321     // check here if analysis runs on our node or remote
00322     QString myhost=gSystem->HostName(); // find out where we are
00323     QString anahost=fxTGo4GUIRegistry->GetClientNode();  
00324 
00325     fbLocalClient = (anahost==myhost) || (anahost=="localhost");
00326 
00327     if(fbLocalClient) {
00328        proc->tryTerminate();
00329        if(proc->isRunning()){
00330       //      "Process is still running wait 5 seconds and then we will kill it " << endl;
00331            QTimer::singleShot(5000, proc, SLOT( kill() ) );
00332        }
00333        if (proc->isRunning()) proc->kill();              
00334     } else {
00335        Com.prepend(" ");
00336        Com.prepend(fxTGo4GUIRegistry->GetClientNode());
00337        Com.prepend(" ");
00338        Com.prepend(fxTGo4GUIRegistry->GetClientShell());
00339     }       
00340 
00341     TGo4AnalysisStatusMonitor * ratemeter = mw->AnalysisStatusSlot();
00342     ratemeter->SetRate(0);// 
00343     ratemeter->SetDateString("Disconnected.");
00344 
00345     mw->AnalysisConfigAppearance(0);
00346        
00347     QString mess="Killing analysis client with: "+Com;
00348     cout << mess << endl;
00349     mw->StatusMessage(mess);
00350     QString SEP=" ";
00351     QStringList ComList = QStringList::split(SEP,Com);
00352     Killproc->setArguments(ComList);
00353     if ( !Killproc->start() ) {     
00354        cerr << "Fatal error Could not kill the Analysis" << endl;
00355        return;
00356     }
00357     TGo4RemoteBrowserSlots *fxRemote= (TGo4RemoteBrowserSlots *)fxTGo4GUIRegistry->GetSlotClass("TGo4RemoteBrowserSlots");
00358     if (fxRemote) fxRemote->ClearBrowser();
00359 
00360     mw->statusBar()->message(mess);
00361 }
00362 
00363 
00364 void TGo4AnalysisWindow::clearOutput()
00365 {
00366    fxOutput->clear();
00367 }
00368 
00369 
00370 void TGo4AnalysisWindow::HistActivated(const QString& str) {
00371    if (fxCmdHist->EnterPressed() && (str!="")) {
00372       fxCmdHist->ResetEnterPressed();
00373       int pos = -1;
00374       for (int i=0;i<fxCmdHist->count();i++)
00375         if (fxCmdHist->text(i)=="") pos = i;
00376 
00377       if (pos>0) fxCmdHist->removeItem(pos);
00378       if (pos!=0) fxCmdHist->insertItem("", 0);
00379 
00380       if (fxCmdHist->currentItem()!=0)
00381         fxCmdHist->setCurrentItem(0);
00382 
00383       TGo4ComExecLine *com= new TGo4ComExecLine();
00384       com->SetLine(str.data());
00385       fxTGo4GUIRegistry->SubmitCommand(com);
00386 //      cout << "Command executed " << str << endl;
00387    }
00388 }
00389 
00390 void TGo4AnalysisWindow::FileDialog_Macro()
00391 {
00392  QString macroName;
00393  QString command=".x ";
00394     QFileDialog* fd = new QFileDialog( this, "search macro", true);
00395     QString fdCaption = "Select ROOT macro for analysis task";
00396     fd->setCaption(fdCaption);
00397     fd->setMode( QFileDialog::ExistingFile);
00398     fd->setName( "Select/Enter  root macro");
00399     fd->setFilter( "CINT Macro  (*.C)" );
00400 
00401     if ( fd->exec() == QDialog::Accepted )
00402        {
00403           macroName = fd->selectedFile();
00404           if(!macroName.endsWith(".C")) macroName.append(".C");
00405           command.append(macroName);
00406           fxCmdHist->insertItem(command,0);
00407           //HistActivated(command);
00408        }
00409    delete fd;
00410 }
00411 
00412 void TGo4AnalysisWindow::PrintHistograms()
00413 {
00414  const QString com="@PrintHistograms()";
00415  fxCmdHist->insertItem(com,0);
00416  fxCmdHist->SetEnterPressed(1);
00417  HistActivated(com);
00418  fxCmdHist->SetEnterPressed(0);
00419 
00420 }
00421 
00422 void TGo4AnalysisWindow::PrintConditions()
00423 {
00424  const QString com="@PrintConditions()";
00425  fxCmdHist->insertItem(com,0);
00426  fxCmdHist->SetEnterPressed(1);
00427  HistActivated(com);
00428  fxCmdHist->SetEnterPressed(0);
00429 }
00430 
00431 void TGo4AnalysisWindow::PrintEvent()
00432 {
00433  TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00434  mw->EventInfoSlot();
00435 }
00436 
00437 QString TGo4AnalysisWindow::terminalOutputText() {
00438    return fxOutput->text();
00439 }
00440 
00441 
00442 
00443 
00444 
00445 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:59 2005 for Go4-v2.10-5 by doxygen1.2.15