00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4Script.h"
00015
00016 #include <stdlib.h>
00017 #include <stdio.h>
00018
00019 #include "TString.h"
00020 #include "TROOT.h"
00021 #include "TSystem.h"
00022 #include "TInterpreter.h"
00023 #include "TPad.h"
00024 #include "TCanvas.h"
00025 #include "TStopwatch.h"
00026
00027 #include "TGo4QSettings.h"
00028 #include "TGo4BrowserProxy.h"
00029 #include "TGo4AnalysisProxy.h"
00030 #include "TGo4DirProxy.h"
00031 #include "TGo4HServProxy.h"
00032 #include "TGo4DabcProxy.h"
00033 #include "TGo4Iter.h"
00034 #include "TGo4Log.h"
00035
00036 #include "TGo4AnalysisConfiguration.h"
00037 #include "TGo4ConfigStep.h"
00038 #include "TGo4AnalysisWindow.h"
00039 #include "TGo4MdiArea.h"
00040 #include "TGo4Picture.h"
00041 #include "TGo4ViewPanel.h"
00042 #include "TGo4MainWindow.h"
00043 #include "TGo4Slot.h"
00044
00045 #include <QMdiSubWindow>
00046
00047 TGo4Script* TGo4Script::ScriptInstance()
00048 {
00049 return dynamic_cast<TGo4Script*> (Instance());
00050 }
00051
00052 TGo4Script::TGo4Script(TGo4MainWindow* mainwin) :
00053 TGo4AbstractInterface(),
00054 fiWaitForGUIReaction(0),
00055 fiWaitCounter(0),
00056 fStrBuf(),
00057 fMainWin(mainwin),
00058 fErrorFlag(kFALSE)
00059 {
00060 if (mainwin!=0)
00061 Initialize(mainwin->OM(), mainwin->Browser());
00062 }
00063
00064 TGo4Script::~TGo4Script()
00065 {
00066 }
00067
00068
00069 Bool_t TGo4Script::StartScriptExecution(const char* fname)
00070 {
00071 if ((fname==0) || (strlen(fname)==0)) return kFALSE;
00072
00073 FinishExecution();
00074
00075 if (!LoadHotStart(fname)) return kFALSE;
00076
00077 fiWaitForGUIReaction = 0;
00078 fiWaitCounter = getCounts(0.1);
00079
00080 doOutput("Start hostart script execution");
00081
00082 return kTRUE;
00083 }
00084
00085 Int_t TGo4Script::getCounts(Double_t tm)
00086 {
00087 return int(tm*1000./DelayMillisec());
00088 }
00089
00090 void TGo4Script::doOutput(const char* str)
00091 {
00092 if (fMainWin!=0)
00093 fMainWin->StatusMessage(str);
00094 }
00095
00096 Bool_t TGo4Script::ContinueExecution()
00097 {
00098 if ((fMainWin==0) || !IsHotStart()) return kFALSE;
00099
00100 switch (execGUICommands()) {
00101 case 0:
00102 return kFALSE;
00103 case 1:
00104 fiWaitForGUIReaction = 0;
00105 fiWaitCounter = 0;
00106 break;
00107 case 2:
00108 fiWaitCounter--;
00109 return kTRUE;
00110 }
00111
00112 const char* nextcmd = NextHotStartCmd();
00113 if (nextcmd==0) return kFALSE;
00114
00115 Int_t error = 0;
00116 gROOT->ProcessLineSync(nextcmd, &error);
00117
00118 if (error!=0) {
00119 doOutput(Form("Error = %d. CMD: %s", error, nextcmd));
00120 return kFALSE;
00121 }
00122
00123 return kTRUE;
00124 }
00125
00126 void TGo4Script::FinishExecution()
00127 {
00128 FreeHotStartCmds();
00129 fErrorFlag = kFALSE;
00130 fiWaitForGUIReaction = 0;
00131 fiWaitCounter = 0;
00132 }
00133
00134 Bool_t TGo4Script::IsWaitSomething()
00135 {
00136 return fiWaitCounter>0;
00137 }
00138
00139 void TGo4Script::DoPostProcessing()
00140 {
00141
00142 if (IsHotStart()) return;
00143
00144
00145 if (fErrorFlag || (fMainWin==0)) return;
00146
00147 TStopwatch watch;
00148
00149 Int_t loopnumbers = 0;
00150 Double_t spenttime = 0;
00151
00152 do {
00153
00154 loopnumbers++;
00155 Bool_t first = kTRUE;
00156
00157 do {
00158 watch.Start();
00159 if (first) first = kFALSE;
00160 else gSystem->Sleep(DelayMillisec());
00161 fMainWin->ProcessQtEvents();
00162 watch.Stop();
00163 spenttime += watch.RealTime();
00164 } while (spenttime < loopnumbers*0.001*DelayMillisec());
00165
00166 switch (execGUICommands()) {
00167 case 0:
00168 fiWaitForGUIReaction = 0;
00169 fiWaitCounter = 0;
00170 fErrorFlag = kTRUE;
00171 return;
00172 case 1:
00173 fiWaitForGUIReaction = 0;
00174 fiWaitCounter = 0;
00175 return;
00176 case 2:
00177 fiWaitCounter--;
00178 }
00179 } while (loopnumbers < 1000000);
00180 }
00181
00182 void TGo4Script::ProcessEvents(Int_t timeout)
00183 {
00184 Wait(timeout <= 0 ? 0 : timeout*0.001);
00185 }
00186
00187 Int_t TGo4Script::execGUICommands()
00188 {
00189 switch (fiWaitForGUIReaction) {
00190 case 0:
00191 return 1;
00192
00193 case 1: {
00194 TGo4AnalysisProxy* anal = Analysis();
00195
00196 if((anal!=0) && anal->IsAnalysisReady()) {
00197 doOutput("// Disconnect old analysis first");
00198 fMainWin->DisconnectAnalysisSlot(false);
00199 fiWaitForGUIReaction = 3;
00200 fiWaitCounter = getCounts(10.);
00201 return 2;
00202 }
00203
00204 fMainWin->LaunchClientSlot(false);
00205
00206 doOutput("// Start analysis client");
00207
00208
00209 fiWaitForGUIReaction = 2;
00210 fiWaitCounter = getCounts(5.);
00211
00212 return 2;
00213 }
00214
00215 case 2: {
00216 TGo4AnalysisProxy* anal = Analysis();
00217 if ((anal!=0) && anal->IsAnalysisReady()) return 1;
00218 return (fiWaitCounter<2) ? 1 : 2;
00219 }
00220
00221 case 3: {
00222 TGo4AnalysisProxy* anal = Analysis();
00223 if((anal==0) || !anal->IsAnalysisReady()) {
00224 fiWaitForGUIReaction = 4;
00225 fiWaitCounter = getCounts(5.);
00226 return 2;
00227 }
00228 return (fiWaitCounter<2) ? 0 : 2;
00229 }
00230
00231 case 4: {
00232 if (fiWaitCounter<5)
00233 fiWaitForGUIReaction = 1;
00234 return 2;
00235 }
00236
00237 case 5: {
00238 TGo4AnalysisProxy* anal = Analysis();
00239 if (anal==0) return 0;
00240 if (anal->IsAnalysisReady()) return 1;
00241 return (fiWaitCounter<2) ? 0 : 2;
00242 }
00243
00244 case 10: {
00245 TGo4AnalysisProxy* anal = Analysis();
00246 if ((anal!=0) && anal->IsAnalysisSettingsReady()) {
00247 fiWaitForGUIReaction = 11;
00248
00249 return 2;
00250 }
00251 return (fiWaitCounter<2) ? 0 : 2;
00252 }
00253
00254 case 11: {
00255 TGo4AnalysisProxy* anal = Analysis();
00256 if ((anal!=0) && anal->NamesListReceived()) return 1;
00257 return (fiWaitCounter<2) ? 0 : 2;
00258 }
00259
00260 case 12: {
00261 TGo4AnalysisProxy* anal = Analysis();
00262 if (anal==0) return 1;
00263 return (fiWaitCounter<2) ? 0 : 2;
00264 }
00265
00266 case 15: {
00267 fMainWin->ConnectServerSlot(false, fStrBuf.Data());
00268
00269
00270 fiWaitForGUIReaction = 2;
00271 fiWaitCounter = getCounts(5.);
00272
00273 return 2;
00274 }
00275
00276 case 111: {
00277 return (fiWaitCounter<2) ? 1 : 2;
00278 }
00279 }
00280
00281 return 2;
00282 }
00283
00284
00285
00286 void TGo4Script::Wait(double tm_sec)
00287 {
00288 fiWaitForGUIReaction = 111;
00289 fiWaitCounter = getCounts(tm_sec);
00290 if (fiWaitCounter<0) fiWaitCounter = 1;
00291
00292 DoPostProcessing();
00293 }
00294
00295
00296 void TGo4Script::Message(const char* msg)
00297 {
00298 if (fMainWin!=0)
00299 fMainWin->StatusMessage(msg);
00300 }
00301
00302
00303 void TGo4Script::HotStart(const char* filename)
00304 {
00305 fMainWin->HotStart(filename);
00306 }
00307
00308 void TGo4Script::LaunchAnalysis()
00309 {
00310 fiWaitForGUIReaction = 1;
00311 fiWaitCounter = getCounts(1.);
00312
00313 DoPostProcessing();
00314 }
00315
00316 void TGo4Script::LaunchAnalysis(const char* ClientName,
00317 const char* ClientDir,
00318 const char* ClientExec,
00319 const char* ClientNode,
00320 Int_t ShellMode,
00321 Int_t TermMode,
00322 Int_t ExeMode,
00323 const char* UserArgs)
00324 {
00325 go4sett->setClientName(ClientName);
00326 go4sett->setClientDir(ClientDir);
00327 go4sett->setClientExeMode(ExeMode);
00328 go4sett->setClientExec(ClientExec);
00329 go4sett->setClientArgs(UserArgs);
00330 go4sett->setClientNode(ClientNode);
00331 go4sett->setClientShellMode(ShellMode);
00332 go4sett->setClientTermMode(TermMode);
00333 LaunchAnalysis();
00334 }
00335
00336 void TGo4Script::ConnectAnalysis(const char* ServerNode,
00337 Int_t ServerPort,
00338 Int_t ControllerMode,
00339 const char* password)
00340 {
00341 go4sett->setClientNode(ServerNode);
00342 go4sett->setClientPort(ServerPort);
00343 go4sett->setClientControllerMode(ControllerMode);
00344 go4sett->setClientDefaultPass((password==0) || (*password==0));
00345 fiWaitForGUIReaction = 15;
00346 fStrBuf = password;
00347 fiWaitCounter = getCounts(1.);
00348
00349 DoPostProcessing();
00350 }
00351
00352 void TGo4Script::WaitAnalysis(Int_t delay_sec)
00353 {
00354 fiWaitForGUIReaction = 5;
00355 fiWaitCounter = getCounts(delay_sec);
00356
00357 DoPostProcessing();
00358 }
00359
00360 void TGo4Script::DisconnectAnalysis()
00361 {
00362 fMainWin->DisconnectAnalysisSlot(false);
00363
00364 fiWaitForGUIReaction = 12;
00365 fiWaitCounter = getCounts(20.);
00366
00367 DoPostProcessing();
00368 }
00369
00370 void TGo4Script::ShutdownAnalysis()
00371 {
00372 fMainWin->ShutdownAnalysisSlot(false);
00373
00374 fiWaitForGUIReaction = 12;
00375 fiWaitCounter = getCounts(20.);
00376
00377 DoPostProcessing();
00378 }
00379
00380 void TGo4Script::SubmitAnalysisConfig(int tmout)
00381 {
00382 fMainWin->SubmitAnalysisSettings();
00383
00384 fiWaitForGUIReaction = 10;
00385 fiWaitCounter = getCounts(tmout);
00386
00387 DoPostProcessing();
00388 }
00389
00390 void TGo4Script::StartAnalysis()
00391 {
00392 fMainWin->StartAnalysisSlot();
00393 Wait(1.);
00394 }
00395
00396 void TGo4Script::StopAnalysis()
00397 {
00398 fMainWin->StopAnalysisSlot();
00399 Wait(2.);
00400 }
00401
00402 void TGo4Script::RefreshNamesList(int tmout)
00403 {
00404 TGo4AnalysisProxy* anal = Analysis();
00405 if (anal!=0) {
00406 anal->RefreshNamesList();
00407 fiWaitForGUIReaction = 11;
00408 fiWaitCounter = getCounts(tmout > 0 ? tmout : 10);
00409 }
00410
00411 DoPostProcessing();
00412 }
00413
00414 void TGo4Script::SetAnalysisTerminalMode(int mode)
00415 {
00416 TGo4AnalysisWindow* gui_ = fMainWin->FindAnalysisWindow();
00417 QWidget* gui = gui_ ? gui_->parentWidget() : 0;
00418 if (gui==0) return;
00419
00420 if (mode<0) gui->hide(); else
00421 if (mode==0) gui->showMinimized(); else
00422 gui->showNormal();
00423 }
00424
00425 void TGo4Script::SetAnalysisConfigMode(int mode)
00426 {
00427 TGo4AnalysisConfiguration* gui_ = fMainWin->FindAnalysisConfiguration();
00428 QWidget* gui = gui_ ? gui_->parentWidget() : 0;
00429 if (gui==0) return;
00430
00431 if (mode<0) gui->hide(); else
00432 if (mode==0) gui->showMinimized(); else
00433 gui->showNormal();
00434 }
00435
00436 void TGo4Script::AnalysisAutoSave(const char* filename,
00437 Int_t interval,
00438 Int_t compression,
00439 Bool_t enabled,
00440 Bool_t overwrite)
00441 {
00442 TGo4AnalysisConfiguration* gui = fMainWin->FindAnalysisConfiguration();
00443 if(gui!=0)
00444 gui->SetAutoSaveConfig(filename, interval, compression, enabled, overwrite);
00445 }
00446
00447 void TGo4Script::AnalysisConfigName(const char* filename)
00448 {
00449 TGo4AnalysisConfiguration* gui = fMainWin->FindAnalysisConfiguration();
00450 if(gui!=0)
00451 gui->SetAnalysisConfigFile(filename);
00452 }
00453
00454 TGo4ConfigStep* TGo4Script::GetStepGUI(const char* stepname)
00455 {
00456 TGo4AnalysisConfiguration* gui = fMainWin->FindAnalysisConfiguration();
00457
00458 return gui==0 ? 0 : gui->FindStepConfig(stepname);
00459 }
00460
00461 void TGo4Script::ConfigStep(const char* stepname,
00462 Bool_t enableprocess,
00463 Bool_t enablesource,
00464 Bool_t enablestore)
00465 {
00466 TGo4ConfigStep* step = GetStepGUI(stepname);
00467 if (step)
00468 step->SetStepControl(enableprocess, enablesource, enablestore);
00469 }
00470
00471 void TGo4Script::StepFileSource(const char* stepname,
00472 const char* sourcename,
00473 int timeout)
00474 {
00475 TGo4ConfigStep* step = GetStepGUI(stepname);
00476 if (step) {
00477 step->SetFileSource();
00478 step->SetSourceWidgets(sourcename, timeout);
00479 }
00480 }
00481
00482 void TGo4Script::StepMbsFileSource(const char* stepname,
00483 const char* sourcename,
00484 int timeout,
00485 const char* TagFile,
00486 int start,
00487 int stop,
00488 int interval)
00489 {
00490 TGo4ConfigStep* step = GetStepGUI(stepname);
00491 if (step) {
00492 step->SetMbsFileSource(TagFile);
00493 step->SetSourceWidgets(sourcename, timeout);
00494 step->SetMbsSourceWidgets(start, stop, interval);
00495 }
00496 }
00497
00498 void TGo4Script::StepMbsStreamSource(const char* stepname,
00499 const char* sourcename,
00500 int timeout,
00501 int start,
00502 int stop,
00503 int interval)
00504 {
00505 TGo4ConfigStep* step = GetStepGUI(stepname);
00506 if (step) {
00507 step->SetMbsStreamSource();
00508 step->SetSourceWidgets(sourcename, timeout);
00509 step->SetMbsSourceWidgets(start, stop, interval);
00510 }
00511 }
00512
00513 void TGo4Script::StepMbsTransportSource(const char* stepname,
00514 const char* sourcename,
00515 int timeout,
00516 int start,
00517 int stop,
00518 int interval)
00519 {
00520 TGo4ConfigStep* step = GetStepGUI(stepname);
00521 if (step) {
00522 step->SetMbsTransportSource();
00523 step->SetSourceWidgets(sourcename, timeout);
00524 step->SetMbsSourceWidgets(start, stop, interval);
00525 }
00526 }
00527
00528 void TGo4Script::StepMbsEventServerSource(const char* stepname,
00529 const char* sourcename,
00530 int timeout,
00531 int start,
00532 int stop,
00533 int interval)
00534 {
00535 TGo4ConfigStep* step = GetStepGUI(stepname);
00536 if (step) {
00537 step->SetMbsEventServerSource();
00538 step->SetSourceWidgets(sourcename, timeout);
00539 step->SetMbsSourceWidgets(start, stop, interval);
00540 }
00541 }
00542
00543 void TGo4Script::StepMbsRevServSource(const char* stepname,
00544 const char* sourcename,
00545 int timeout,
00546 int port,
00547 int start,
00548 int stop,
00549 int interval)
00550 {
00551 TGo4ConfigStep* step = GetStepGUI(stepname);
00552 if (step) {
00553 step->SetMbsRevServSource(port);
00554 step->SetSourceWidgets(sourcename, timeout);
00555 step->SetMbsSourceWidgets(start, stop, interval, port);
00556 }
00557 }
00558
00559 void TGo4Script::StepMbsSelection(const char* stepname,
00560 int start,
00561 int stop,
00562 int interval)
00563 {
00564 TGo4ConfigStep* step = GetStepGUI(stepname);
00565 if (step)
00566 step->SetMbsSourceWidgets(start, stop, interval);
00567 }
00568
00569 void TGo4Script::StepRandomSource(const char* stepname,
00570 const char* sourcename,
00571 int timeout)
00572 {
00573 TGo4ConfigStep* step = GetStepGUI(stepname);
00574 if (step) {
00575 step->SetRandomSource();
00576 step->SetSourceWidgets(sourcename, timeout);
00577 }
00578 }
00579
00580 void TGo4Script::StepMbsPort(const char* stepname,
00581 int port)
00582 {
00583 TGo4ConfigStep* step = GetStepGUI(stepname);
00584 if (step) step->SetMbsPort(port);
00585 }
00586
00587 void TGo4Script::StepMbsRetryCnt(const char* stepname,
00588 int cnt)
00589 {
00590 TGo4ConfigStep* step = GetStepGUI(stepname);
00591 if (step) step->SetMbsRetryCnt(cnt);
00592 }
00593
00594 void TGo4Script::StepUserSource(const char* stepname,
00595 const char* sourcename,
00596 int timeout,
00597 int port,
00598 const char* expr)
00599 {
00600 TGo4ConfigStep* step = GetStepGUI(stepname);
00601 if (step) {
00602 step->SetUserSource(port, expr);
00603 step->SetSourceWidgets(sourcename, timeout);
00604 }
00605 }
00606
00607 void TGo4Script::StepFileStore(const char* stepname,
00608 const char* storename,
00609 bool overwrite,
00610 int bufsize,
00611 int splitlevel,
00612 int compression)
00613 {
00614 TGo4ConfigStep* step = GetStepGUI(stepname);
00615 if (step)
00616 step->SetFileStore(storename, overwrite, bufsize, splitlevel, compression);
00617 }
00618
00619 void TGo4Script::StepBackStore(const char* stepname,
00620 const char* storename,
00621 int bufsize,
00622 int splitlevel)
00623 {
00624 TGo4ConfigStep* step = GetStepGUI(stepname);
00625 if (step)
00626 step->SetBackStore(storename, bufsize, splitlevel);
00627 }
00628
00629 void TGo4Script::SetMainWindowState(int qtversion, const char* val)
00630 {
00631 if (qtversion==4)
00632 fMainWin->restoreState(QByteArray::fromHex(val));
00633 }
00634
00635 void TGo4Script::SetMainWindowGeometry(int qtversion, const char* val)
00636 {
00637 if (qtversion==4)
00638 fMainWin->restoreGeometry(QByteArray::fromHex(val));
00639 }
00640
00641 ViewPanelHandle TGo4Script::StartViewPanel()
00642 {
00643 return fMainWin->MakeNewPanel(1);
00644 }
00645
00646 ViewPanelHandle TGo4Script::StartViewPanel(int x, int y, int width, int height, int mode, TGo4Picture* pic)
00647 {
00648 TGo4ViewPanel* panel = fMainWin->MakeNewPanel(1);
00649 if (panel==0) return 0;
00650
00651 if (mode==0) panel->showMinimized(); else
00652 if (mode==2) panel->showMaximized(); else {
00653 panel->showNormal();
00654 panel->parentWidget()->move(QPoint(x,y));
00655 panel->parentWidget()->resize(QSize(width, height));
00656 }
00657
00658 if (pic!=0) {
00659 panel->ProcessPictureRedraw("", panel->GetCanvas(), pic);
00660 if (TString(DefaultPicTitle()) != pic->GetTitle())
00661 panel->SetFreezedTitle(pic->GetTitle());
00662
00663 panel->ShootRepaintTimer();
00664 }
00665
00666 return (ViewPanelHandle) panel;
00667 }
00668
00669 TString TGo4Script::GetViewPanelName(ViewPanelHandle handle)
00670 {
00671 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00672 if (panel==0) return TString();
00673 return TString(panel->objectName().toLatin1().constData());
00674 }
00675
00676 ViewPanelHandle TGo4Script::FindViewPanel(const char* name)
00677 {
00678 return (ViewPanelHandle) fMainWin->FindViewPanel(name);
00679 }
00680
00681 Bool_t TGo4Script::SetViewPanelName(ViewPanelHandle handle, const char* newname)
00682 {
00683 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00684 if ((handle==0) || (newname==0) || (strlen(newname)==0)) return kFALSE;
00685
00686 if (fMainWin->FindViewPanel(newname)) {
00687 Message(Form("Viewpanel with name %s already exists",newname));
00688 return kFALSE;
00689 }
00690
00691 panel->SetPanelName(newname);
00692
00693 panel->UpdatePanelCaption();
00694
00695 return kTRUE;
00696 }
00697
00698 ViewPanelHandle TGo4Script::GetActiveViewPanel()
00699 {
00700 return (ViewPanelHandle) TGo4MdiArea::Instance()->GetActivePanel();
00701 }
00702
00703 void TGo4Script::RedrawPanel(ViewPanelHandle handle)
00704 {
00705 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00706 if (panel!=0) panel->RedrawPanel(panel->GetCanvas(), true);
00707 }
00708
00709 void TGo4Script::DivideViewPanel(ViewPanelHandle handle, Int_t numX, Int_t numY)
00710 {
00711 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00712 if (panel!=0) panel->Divide(numX, numY);
00713 }
00714
00715 TPad* TGo4Script::SelectPad(ViewPanelHandle handle, Int_t number)
00716 {
00717 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00718 if (panel!=0) {
00719 TPad* pad = panel->GetSubPad(0, number, false);
00720 if (pad==0) pad = panel->GetCanvas();
00721 panel->SetActivePad(pad);
00722 ProcessEvents();
00723 return pad;
00724 }
00725 return 0;
00726 }
00727
00728 TGo4Picture* TGo4Script::GetPadOptions(ViewPanelHandle handle, Int_t padnumber)
00729 {
00730 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00731 if (panel==0) return 0;
00732
00733 TPad* pad = panel->GetSubPad(0, padnumber, false);
00734 if (pad==0) pad = panel->GetCanvas();
00735 return panel->GetPadOptions(pad);
00736 }
00737
00738 void TGo4Script::SetSuperimpose(ViewPanelHandle handle, Bool_t on)
00739 {
00740 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00741 if (panel!=0) panel->SetPadSuperImpose(panel->GetActivePad(), on);
00742 }
00743
00744 Bool_t TGo4Script::DrawItem(const char* itemname, ViewPanelHandle handle, const char* drawopt)
00745 {
00746 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00747
00748 panel = fMainWin->DisplayBrowserItem(itemname, panel, 0, true, -1, drawopt);
00749
00750 if (panel!=0) ProcessEvents();
00751
00752 return (panel!=0);
00753 }
00754
00755 const char* TGo4Script::GetDrawnItemName(ViewPanelHandle handle, int cnt)
00756 {
00757 TGo4ViewPanel* panel = (TGo4ViewPanel*) handle;
00758
00759 return panel ? panel->GetDrawItemName(cnt) : 0;
00760 }
00761
00762
00763
00764
00765
00766 void TGo4Script::ProduceScript(const char* filename, TGo4MainWindow* main)
00767 {
00768 TGo4AnalysisConfiguration* confgui = main->FindAnalysisConfiguration();
00769
00770 TGo4AnalysisWindow* termgui = main->FindAnalysisWindow();
00771
00772 TGo4BrowserProxy* br = main->Browser();
00773
00774 TGo4AnalysisProxy* anal = br->FindAnalysis();
00775
00776 std::ofstream fs(filename);
00777
00778 fs << "// Automatically generated startup script" << std::endl;
00779 fs << "// Do not change it!" << std::endl << std::endl;
00780
00781 fs << "go4->SetMainWindowState(4,\"" << main->saveState().toHex().data() << "\");" << std::endl;
00782
00783 fs << "go4->SetMainWindowGeometry(4,\"" << main->saveGeometry().toHex().data() << "\");" << std::endl;
00784
00785 ProduceLoadLibs(fs);
00786
00787 TObjArray prlist;
00788 br->MakeFilesList(&prlist);
00789 for(Int_t n=0;n<=prlist.GetLast();n++) {
00790 TGo4DirProxy* pr = (TGo4DirProxy*) prlist.At(n);
00791 fs << "go4->OpenFile(\"" << pr->GetFileName() << "\");" << std::endl;
00792 }
00793
00794 prlist.Clear();
00795 br->MakeHServerList(&prlist);
00796 for(Int_t n=0;n<=prlist.GetLast();n++) {
00797 TGo4HServProxy* pr = (TGo4HServProxy*) prlist.At(n);
00798 fs << "go4->ConnectHServer(\""
00799 << pr->GetServerName() << "\", "
00800 << pr->GetPortNumber() << ", \""
00801 << pr->GetBaseName() << "\", \""
00802 << pr->GetUserPass() << "\", \""
00803 << pr->GetFilter() << "\");" << std::endl;
00804 }
00805
00806 prlist.Clear();
00807 br->MakeDabcList(&prlist);
00808 for(Int_t n=0;n<=prlist.GetLast();n++) {
00809 TGo4DabcProxy* pr = (TGo4DabcProxy*) prlist.At(n);
00810 fs << "go4->ConnectDabc(\"" << pr->GetServerName() << "\");" << std::endl;
00811 }
00812
00813 fs << std::endl;
00814
00815 if ((anal!=0) && anal->IsAnalysisReady() && !anal->IsAnalysisServer()) {
00816
00817 fs << "go4->LaunchAnalysis(\"" << go4sett->getClientName().toLatin1().constData() << "\", \""
00818 << go4sett->getClientDir().toLatin1().constData() << "\", \""
00819 << go4sett->getClientExec().toLatin1().constData() << "\", \""
00820 << go4sett->getClientNode().toLatin1().constData() << "\", ";
00821
00822 if (go4sett->getClientShellMode() == Go4_rsh) fs << "Go4_rsh, "; else
00823 if (go4sett->getClientShellMode() == Go4_ssh) fs << "Go4_ssh, "; else fs << "Go4_sh, ";
00824
00825 if (go4sett->getClientTermMode() == Go4_xterm) fs << "Go4_xtrem, "; else
00826 if (go4sett->getClientTermMode() == Go4_konsole) fs << "Go4_konsole, "; else fs << "Go4_qt, ";
00827
00828 if (go4sett->getClientExeMode() == Go4_lib) fs << "Go4_lib"; else fs << "Go4_exe";
00829
00830
00831
00832
00833 if (go4sett->getClientArgs().length()>0)
00834 fs << ", \"" << go4sett->getClientArgs().toLatin1().constData() << "\"";
00835 fs << ");" << std::endl;
00836
00837 fs << "go4->WaitAnalysis(300);" << std::endl << std::endl;
00838
00839 if (confgui==0) return;
00840 fs << "// configuration of analysis" << std::endl;
00841
00842 QString fname;
00843 int interval, compression;
00844 bool asenabled, asoverwrite;
00845
00846 confgui->GetAutoSaveConfig(fname, interval, compression, asenabled, asoverwrite);
00847 fs << "go4->AnalysisAutoSave(\"" << fname.toLatin1().constData() << "\", "
00848 << interval << ", "
00849 << compression << ", "
00850 << (asenabled ? "kTRUE" : "kFALSE") << ", "
00851 << (asoverwrite ? "kTRUE" : "kFALSE") << ");" << std::endl;
00852
00853 confgui->GetAnalysisConfigFile(fname);
00854 fs << "go4->AnalysisConfigName(\"" << fname.toLatin1().constData() << "\");" << std::endl << std::endl;
00855
00856 for(int nstep=0;nstep<confgui->GetNumSteps();nstep++) {
00857 TGo4ConfigStep* stepconf = confgui->GetStepConfig(nstep);
00858 fs << "// step " << stepconf->GetStepName().toLatin1().constData() << std::endl;
00859
00860 bool process, source, store;
00861 stepconf->GetStepControl(process, source, store);
00862 fs << "go4->ConfigStep(\"" << stepconf->GetStepName().toLatin1().constData() << "\", "
00863 << (process ? "kTRUE" : "kFALSE") << ", "
00864 << (source ? "kTRUE" : "kFALSE") << ", "
00865 << (store ? "kTRUE" : "kFALSE") << ");" << std::endl;
00866
00867 QString srcname;
00868 int timeout(0), start(0), stop(0), interval(0), nport(0), nretry(0);
00869 int nsrc = stepconf->GetSourceSetup(srcname, timeout, start, stop, interval, nport, nretry);
00870
00871 TString srcargs;
00872 srcargs.Form("(\"%s\", \"%s\", %d", stepconf->GetStepName().toLatin1().constData(), srcname.toLatin1().constData(), timeout);
00873
00874 switch(nsrc) {
00875 case 0:
00876 fs << "go4->StepFileSource" << srcargs;
00877 break;
00878 case 1: {
00879 QString TagFile;
00880 stepconf->GetMbsFileSource(TagFile);
00881 fs << "go4->StepMbsFileSource" << srcargs << ", \""
00882 << TagFile.toLatin1().constData() << "\"";
00883 break;
00884 }
00885 case 2:
00886 fs << "go4->StepMbsStreamSource" << srcargs;
00887 break;
00888 case 3:
00889 fs << "go4->StepMbsTransportSource" << srcargs;
00890 break;
00891 case 4:
00892 fs << "go4->StepMbsEventServerSource" << srcargs;
00893 break;
00894 case 5:
00895 fs << "go4->StepMbsRevServSource" << srcargs;
00896 break;
00897 case 6:
00898 fs << "go4->StepRandomSource" << srcargs;
00899 break;
00900 case 7: {
00901 int port;
00902 QString expr;
00903 stepconf->GetUserSource(port, expr);
00904 fs << "go4->StepUserSource" << srcargs << ", " << port << ", \""
00905 << expr.toLatin1().constData() << "\"";
00906 break;
00907 }
00908
00909 }
00910 fs << ");" << std::endl;
00911
00912 if ((start!=0) || (stop!=0) || (interval>1)) {
00913 srcargs.Form("(\"%s\", %d, %d ,%d)",stepconf->GetStepName().toLatin1().constData(), start, stop, interval);
00914 fs << "go4->StepMbsSelection" << srcargs << ";" << std::endl;
00915 }
00916
00917 if (nport>0) {
00918 srcargs.Form("(\"%s\", %d)",stepconf->GetStepName().toLatin1().constData(), nport);
00919 fs << "go4->StepMbsPort" << srcargs << ";" << std::endl;
00920 }
00921
00922 if (nretry>0) {
00923 srcargs.Form("(\"%s\", %d)",stepconf->GetStepName().toLatin1().constData(), nretry);
00924 fs << "go4->StepMbsRetryCnt" << srcargs << ";" << std::endl;
00925 }
00926
00927 QString storename;
00928 int nstore = stepconf->GetStoreSetup(storename);
00929 switch(nstore) {
00930 case 0: {
00931 bool overwrite;
00932 int bufsize, splitlevel, compression;
00933 stepconf->GetFileStore(overwrite, bufsize, splitlevel, compression);
00934 fs << "go4->StepFileStore(\"" << stepconf->GetStepName().toLatin1().constData() << "\", \""
00935 << storename.toLatin1().constData() << "\", "
00936 << (overwrite ? "kTRUE" : "kFALSE") << ", "
00937 << bufsize << ", "
00938 << splitlevel << ", "
00939 << compression << ");" << std::endl;
00940 break;
00941 }
00942
00943 case 1: {
00944 int bufsize, splitlevel;
00945 stepconf->GetBackStore(bufsize, splitlevel);
00946 fs << "go4->StepBackStore(\"" << stepconf->GetStepName().toLatin1().constData() << "\", \""
00947 << storename.toLatin1().constData() << "\", "
00948 << bufsize << ", "
00949 << splitlevel << ");" << std::endl;
00950 break;
00951 }
00952 }
00953
00954 fs << std::endl;
00955 }
00956
00957 if ((anal!=0) && anal->IsAnalysisSettingsReady())
00958 fs << "go4->SubmitAnalysisConfig(20);" << std::endl << std::endl;
00959
00960 int mode = 1;
00961 QWidget* mdi = confgui ? confgui->parentWidget() : 0;
00962 if (mdi!=0) {
00963 if (mdi->isHidden()) mode = -1; else
00964 if (mdi->isMinimized()) mode = 0;
00965 }
00966 fs << "go4->SetAnalysisConfigMode(" << mode << ");" << std::endl;
00967
00968 mode = 1;
00969 mdi = termgui ? termgui->parentWidget() : 0;
00970 if (mdi!=0) {
00971 if (mdi->isHidden()) mode = -1; else
00972 if (mdi->isMinimized()) mode = 0;
00973 }
00974 fs << "go4->SetAnalysisTerminalMode(" << mode << ");" << std::endl << std::endl;
00975
00976 } else
00977 if ((anal!=0) && anal->IsAnalysisReady() && anal->IsAnalysisServer()) {
00978 fs << "go4->ConnectAnalysis(\""
00979 << go4sett->getClientNode().toLatin1().constData() << "\", "
00980 << go4sett->getClientPort() << ", "
00981 << go4sett->getClientControllerMode() << ", ";
00982 if (go4sett->getClientDefaultPass())
00983 fs << "0);" << std::endl;
00984 else
00985 fs << "\"" << main->LastTypedPassword() << "\");" << std::endl;
00986 fs << "go4->WaitAnalysis(10);" << std::endl << std::endl;
00987 } else {
00988 fs << "go4->DisconnectAnalysis();" << std::endl;
00989 }
00990
00991 if ((anal!=0) && anal->IsAnalysisRunning() && !anal->IsAnalysisServer()) {
00992 fs << "go4->StartAnalysis();" << std::endl;
00993 fs << std::endl;
00994 fs << "// this is possibility to get extra histograms from analysis" << std::endl;
00995 fs << "// which are create shortly after analysis is started" << std::endl;
00996 fs << "go4->Wait(1);" << std::endl;
00997 fs << "go4->RefreshNamesList();" << std::endl;
00998 }
00999
01000 int npanel=0;
01001
01002 QList<QMdiSubWindow *> windows = TGo4MdiArea::Instance()->subWindowList();
01003 for (int i=0; i<windows.count(); ++i ) {
01004 TGo4ViewPanel* panel = dynamic_cast<TGo4ViewPanel*> (windows.at(i)->widget());
01005 if (panel==0) continue;
01006
01007 TString picname = TString::Format("pic%d", ++npanel);
01008 TGo4Picture pic(picname.Data(), DefaultPicTitle());
01009
01010 panel->MakePictureForPad(&pic, panel->GetCanvas(), true);
01011
01012 fs << std::endl;
01013
01014 pic.SavePrimitive(fs,"");
01015
01016 QWidget* mdi = panel->parentWidget();
01017
01018 QPoint pos = mdi->pos();
01019 mdi->mapToParent(pos);
01020 QSize size = mdi->size();
01021
01022 const char* mode = "Go4_normal";
01023 if (mdi->isHidden()) mode = "Go4_hidden"; else
01024 if (mdi->isMinimized()) mode = "Go4_minimized"; else
01025 if (mdi->isMaximized()) mode = "Go4_maximized";
01026
01027 fs << "go4->StartViewPanel("
01028 << pos.x() << ", "
01029 << pos.y() << ", "
01030 << size.width() << ", "
01031 << size.height() << ", "
01032 << mode << ", " << picname << ");" << std::endl;
01033
01034 fs << "delete " << picname << ";" << std::endl;
01035 }
01036
01037 fs << std::endl;
01038
01039
01040
01041 TGo4Iter iter(br->BrowserTopSlot(), kFALSE);
01042 Bool_t goinside = kTRUE;
01043
01044 while (iter.next(goinside)) {
01045 TGo4Slot* subslot = iter.getslot();
01046 goinside = kTRUE;
01047
01048 if (br->ItemKind(subslot)==TGo4Access::kndFolder) {
01049
01050 Int_t ncheck(0), ncount(0);
01051 TGo4Iter subiter(subslot, kTRUE);
01052 while (subiter.next()) {
01053 TGo4Slot* subsubslot = subiter.getslot();
01054 if (br->ItemKind(subsubslot)!=TGo4Access::kndObject) continue;
01055 ncount++;
01056 if (!br->IsItemMonitored(subsubslot)) ncheck++;
01057 else break;
01058 }
01059 goinside = (ncount==0) || (ncheck!=ncount);
01060 } else
01061 goinside = br->IsItemMonitored(subslot);
01062
01063 if (!goinside) {
01064 TString sbuf;
01065 if (br->BrowserItemName(subslot, sbuf))
01066 fs << "go4->MonitorItem(\"" << sbuf << "\", kFALSE);" << std::endl;
01067 }
01068
01069 }
01070
01071 Int_t mperiod = br->MonitoringPeriod();
01072 if (mperiod>0)
01073 fs << "go4->StartMonitoring(" << mperiod/1000 << ");" << std::endl;
01074 }