00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4Interface.h"
00015
00016 #include "TROOT.h"
00017 #include "TSystem.h"
00018 #include "TInterpreter.h"
00019 #include "TCanvas.h"
00020 #include "TStopwatch.h"
00021 #include "TTimer.h"
00022
00023 #include "TGo4AnalysisStatus.h"
00024 #include "TGo4AnalysisStepStatus.h"
00025
00026 #include "TGo4EventStoreParameter.h"
00027 #include "TGo4EventSourceParameter.h"
00028 #include "TGo4UserSourceParameter.h"
00029 #include "TGo4RevServParameter.h"
00030 #include "TGo4FileStoreParameter.h"
00031 #include "TGo4BackStoreParameter.h"
00032 #include "TGo4FileSourceParameter.h"
00033 #include "TGo4MbsFileParameter.h"
00034 #include "TGo4MbsStreamParameter.h"
00035 #include "TGo4MbsTransportParameter.h"
00036 #include "TGo4MbsEventServerParameter.h"
00037 #include "TGo4MbsRandomParameter.h"
00038
00039 #include "TGo4ObjectManager.h"
00040 #include "TGo4BrowserProxy.h"
00041 #include "TGo4AnalysisProxy.h"
00042 #include "TGo4RootBrowserProxy.h"
00043
00044 TGo4Interface::TGo4Interface() :
00045 TGo4AbstractInterface(),
00046 fRootBrowser(0),
00047 fOMDataPath(),
00048 fOMBrowserPath(),
00049 fOMEditorsPath(),
00050 fCmdFinished(kTRUE),
00051 fCmdTimer(0),
00052 fWaitCounter(0)
00053 {
00054
00055 TGo4ObjectManager* om =
00056 new TGo4ObjectManager("GUI_OM","Gui object manager");
00057 fOMDataPath = "data";
00058 fOMBrowserPath = "gui";
00059 fOMEditorsPath = "editors";
00060
00061
00062 om->MakeFolder(fOMDataPath.Data());
00063
00064
00065 TGo4BrowserProxy* br =
00066 new TGo4BrowserProxy(fOMDataPath.Data(), fOMEditorsPath.Data(), kTRUE);
00067 om->AddProxy("", br, fOMBrowserPath.Data(), "Place for gui slots");
00068 br->CreateMemoryFolder();
00069
00070
00071 fRootBrowser = new TGo4RootBrowserProxy(br);
00072 om->AddProxy("", fRootBrowser, fOMEditorsPath.Data(), "Proxy for ROOT browser");
00073 om->AddLink(br->BrowserTopSlot(), fOMEditorsPath.Data(), "Go4Browser", "Link to Go4 browser");
00074
00075 Initialize(om, br);
00076 }
00077
00078 TGo4Interface::~TGo4Interface()
00079 {
00080 DisconnectAnalysis();
00081 delete fCmdTimer;
00082 fCmdTimer = 0;
00083
00084 Int_t timecnt = 50;
00085 while (timecnt-->0) {
00086 if (Analysis()==0) break;
00087 gSystem->ProcessEvents();
00088 gSystem->Sleep(100);
00089 }
00090
00091 TGo4ObjectManager* om = OM();
00092 delete om;
00093 }
00094
00095 void TGo4Interface::ProcessEvents(Int_t timeout)
00096 {
00097 Wait(timeout<=0 ? 0 : timeout*0.001);
00098 }
00099
00100 void TGo4Interface::Wait(double tm_sec)
00101 {
00102 TStopwatch watch;
00103
00104 Double_t spenttime = 0.;
00105 Bool_t first = kTRUE;
00106
00107 do {
00108 watch.Start();
00109 if (first) first = kFALSE;
00110 else gSystem->Sleep(50);
00111 gSystem->ProcessEvents();
00112 watch.Stop();
00113 spenttime += watch.RealTime();
00114 } while (spenttime <= tm_sec);
00115 }
00116
00117 void TGo4Interface::Message(const char* msg)
00118 {
00119 if (fRootBrowser)
00120 fRootBrowser->Message("Message","msg",5000);
00121 }
00122
00123 void TGo4Interface::LaunchAnalysis()
00124 {
00125
00126
00127 }
00128
00129 TGo4AnalysisProxy* TGo4Interface::AddAnalysisProxy(Bool_t isserver)
00130 {
00131 const char* analisysitem = "Analysis";
00132
00133 TGo4Slot* analslot = Browser()->DataSlot(analisysitem);
00134
00135 if (analslot==0) {
00136 TGo4AnalysisProxy* anal = new TGo4AnalysisProxy(isserver);
00137 OM()->AddProxy(fOMDataPath.Data(), anal, analisysitem, "Analysis proxy");
00138 analslot = Browser()->DataSlot(analisysitem);
00139 anal->SetDefaultReceiver(OM(), TString("gui/") + analisysitem + "/");
00140 }
00141
00142 TGo4AnalysisProxy* anal = (analslot==0) ? 0 :
00143 dynamic_cast<TGo4AnalysisProxy*> (analslot->GetProxy());
00144
00145 if (anal!=0)
00146 anal->SetAnalysisReady(kFALSE);
00147
00148 if ((anal!=0) && (fRootBrowser!=0)) {
00149 OM()->AddLink(anal->RatemeterSlot(), fOMEditorsPath.Data(), "AnalRateMeter", "Analysis ratemeter");
00150 OM()->AddLink(anal->LoginfoSlot(), fOMEditorsPath.Data(), "AnalLoginfo", "Analysis loginfo");
00151 }
00152
00153 return anal;
00154 }
00155
00156
00157 void TGo4Interface::LaunchAnalysis(const char* ClientName,
00158 const char* ClientDir,
00159 const char* ClientExec,
00160 const char* ClientNode,
00161 Int_t ShellMode,
00162 Int_t TermMode,
00163 Int_t ExeMode,
00164 const char* UserArgs)
00165 {
00166 TString launchcmd, killcmd;
00167
00168 TGo4AnalysisProxy* anal = AddAnalysisProxy(kFALSE);
00169 if (anal==0) return;
00170
00171 anal->LaunchAsClient(launchcmd, killcmd,
00172 (ShellMode==2),
00173 TermMode==2 ? 2 : 3,
00174 ClientName,
00175 ClientNode,
00176 ClientDir,
00177 ClientExec,
00178 ExeMode,
00179 UserArgs);
00180
00181 gSystem->ProcessEvents();
00182
00183 ProcessEvents(200);
00184 }
00185
00186 void TGo4Interface::ConnectAnalysis(const char* ServerNode,
00187 Int_t ServerPort,
00188 Int_t ControllerMode,
00189 const char* password)
00190 {
00191 TGo4AnalysisProxy* anal = Analysis();
00192 if (anal==0) anal = AddAnalysisProxy(kTRUE);
00193
00194 if (anal==0) return;
00195
00196 anal->ConnectToServer(ServerNode,
00197 ServerPort,
00198 ControllerMode,
00199 password);
00200
00201 if (ControllerMode>0)
00202 anal->RequestAnalysisSettings();
00203
00204
00205 ProcessEvents(200);
00206 }
00207
00208 void TGo4Interface::WaitAnalysis(Int_t delay_sec)
00209 {
00210 if (IsHotStart()) {
00211 fWaitCounter = delay_sec*100;
00212 return;
00213 }
00214
00215 TGo4AnalysisProxy* anal = Analysis();
00216 if (anal==0) {
00217 Error("WaitAnalysis","Analysis not found");
00218 return;
00219 }
00220
00221 delay_sec*=10;
00222
00223 while (delay_sec-->0) {
00224 gSystem->ProcessEvents();
00225 gSystem->Sleep(100);
00226 gSystem->ProcessEvents();
00227 if (anal->IsAnalysisReady())
00228 return;
00229 }
00230 }
00231
00232 void TGo4Interface::DisconnectAnalysis()
00233 {
00234 TGo4AnalysisProxy* anal = Analysis();
00235 if (anal==0) return;
00236
00237 Browser()->ToggleMonitoring(0);
00238
00239 anal->DisconnectAnalysis(5, kFALSE);
00240
00241 ProcessEvents(200);
00242 }
00243
00244 void TGo4Interface::ShutdownAnalysis()
00245 {
00246 TGo4AnalysisProxy* anal = Analysis();
00247 if (anal==0) return;
00248
00249 Browser()->ToggleMonitoring(0);
00250
00251 bool realshutdown = anal->IsAnalysisServer() &&
00252 anal->IsConnected() &&
00253 anal->IsAdministrator();
00254
00255 anal->DisconnectAnalysis(30, realshutdown);
00256 }
00257
00258 void TGo4Interface::SubmitAnalysisConfig(int tmout)
00259 {
00260 TGo4AnalysisProxy* anal = Analysis();
00261 if (anal==0) return;
00262
00263 anal->SubmitAnalysisSettings();
00264 anal->RefreshNamesList();
00265
00266 Int_t delay_sec = tmout > 0 ? tmout : 20;
00267 while (delay_sec-->0) {
00268 gSystem->ProcessEvents();
00269 gSystem->Sleep(1000);
00270 gSystem->ProcessEvents();
00271 if (anal->IsAnalysisSettingsReady())
00272 if (anal->NamesListReceived()) return;
00273 }
00274 }
00275
00276 void TGo4Interface::StartAnalysis()
00277 {
00278 TGo4AnalysisProxy* anal = Analysis();
00279 if (anal==0) return;
00280
00281 anal->StartAnalysis();
00282 anal->RefreshNamesList();
00283 anal->DelayedRefreshNamesList(4);
00284
00285 gSystem->ProcessEvents();
00286 gSystem->Sleep(500);
00287 gSystem->ProcessEvents();
00288 }
00289
00290 void TGo4Interface::StopAnalysis()
00291 {
00292 TGo4AnalysisProxy* anal = Analysis();
00293 if (anal==0) return;
00294
00295 anal->StopAnalysis();
00296
00297 gSystem->ProcessEvents();
00298 gSystem->Sleep(1000);
00299 gSystem->ProcessEvents();
00300 }
00301
00302 void TGo4Interface::RefreshNamesList(int tmout)
00303 {
00304 TGo4AnalysisProxy* anal = Analysis();
00305 if (anal==0) return;
00306
00307 anal->RefreshNamesList();
00308
00309 Int_t delay_sec = tmout > 0 ? tmout : 10;
00310 while (delay_sec-->0) {
00311 gSystem->ProcessEvents();
00312 gSystem->Sleep(1000);
00313 gSystem->ProcessEvents();
00314 if (anal->NamesListReceived()) return;
00315 }
00316 }
00317
00318
00319 TGo4AnalysisStatus* TGo4Interface::GetAnalStatus()
00320 {
00321 TGo4AnalysisProxy* anal = Analysis();
00322 if (anal==0) return 0;
00323 if (anal->SettingsSlot()==0) return 0;
00324
00325 return dynamic_cast<TGo4AnalysisStatus*>
00326 (anal->SettingsSlot()->GetAssignedObject());
00327 }
00328
00329 void TGo4Interface::AnalysisAutoSave(const char* filename,
00330 Int_t interval,
00331 Int_t compression,
00332 Bool_t enabled,
00333 Bool_t overwrite)
00334 {
00335 TGo4AnalysisStatus* status = GetAnalStatus();
00336 if (status==0) return;
00337
00338 status->SetAutoFileName(filename);
00339 status->SetAutoSaveInterval(interval);
00340 status->SetAutoSaveCompression(compression);
00341 status->SetAutoSaveOn(enabled);
00342 status->SetAutoSaveOverwrite(overwrite);
00343 }
00344
00345 void TGo4Interface::AnalysisConfigName(const char* filename)
00346 {
00347 TGo4AnalysisStatus* status = GetAnalStatus();
00348 if (status!=0)
00349 status->SetConfigFileName(filename);
00350 }
00351
00352 TGo4AnalysisStepStatus* TGo4Interface::GetStepStatus(const char* stepname)
00353 {
00354 TGo4AnalysisStatus* status = GetAnalStatus();
00355 return status==0 ? 0 : status->GetStepStatus(stepname);
00356 }
00357
00358 void TGo4Interface::ConfigStep(const char* stepname,
00359 Bool_t enableprocess,
00360 Bool_t enablesource,
00361 Bool_t enablestore)
00362 {
00363 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00364 if (step==0) return;
00365
00366 step->SetSourceEnabled(enablesource);
00367 step->SetStoreEnabled(enablestore);
00368 step->SetProcessEnabled(enableprocess);
00369 }
00370
00371 void TGo4Interface::StepFileSource(const char* stepname,
00372 const char* sourcename,
00373 int timeout)
00374 {
00375 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00376 if (step==0) return;
00377
00378 TGo4FileSourceParameter par(sourcename);
00379 par.SetTimeout(timeout);
00380 step->SetSourcePar(&par);
00381 }
00382
00383 void TGo4Interface::StepMbsFileSource(const char* stepname,
00384 const char* sourcename,
00385 int timeout,
00386 const char* TagFile,
00387 int start,
00388 int stop,
00389 int interval)
00390 {
00391 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00392 if (step==0) return;
00393
00394 TGo4MbsFileParameter par(sourcename);
00395 par.SetTimeout(timeout);
00396
00397 if(TagFile==0) par.SetTagName("GO4-NOLMDTAG");
00398 else par.SetTagName(TagFile);
00399 par.SetStartEvent(start);
00400 par.SetStopEvent(stop);
00401 par.SetEventInterval(interval);
00402 step->SetSourcePar(&par);
00403 }
00404
00405 void TGo4Interface::StepMbsStreamSource(const char* stepname,
00406 const char* sourcename,
00407 int timeout,
00408 int start,
00409 int stop,
00410 int interval)
00411 {
00412 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00413 if (step==0) return;
00414
00415 TGo4MbsStreamParameter par(sourcename);
00416 par.SetTimeout(timeout);
00417 par.SetStartEvent(start);
00418 par.SetStopEvent(stop);
00419 par.SetEventInterval(interval);
00420 step->SetSourcePar(&par);
00421 }
00422
00423 void TGo4Interface::StepMbsTransportSource(const char* stepname,
00424 const char* sourcename,
00425 int timeout,
00426 int start,
00427 int stop,
00428 int interval)
00429 {
00430 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00431 if (step==0) return;
00432
00433 TGo4MbsTransportParameter par(sourcename);
00434 par.SetTimeout(timeout);
00435 par.SetStartEvent(start);
00436 par.SetStopEvent(stop);
00437 par.SetEventInterval(interval);
00438 step->SetSourcePar(&par);
00439 }
00440
00441 void TGo4Interface::StepMbsEventServerSource(const char* stepname,
00442 const char* sourcename,
00443 int timeout,
00444 int start,
00445 int stop,
00446 int interval)
00447 {
00448 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00449 if (step==0) return;
00450
00451 TGo4MbsEventServerParameter par(sourcename);
00452 par.SetTimeout(timeout);
00453 par.SetStartEvent(start);
00454 par.SetStopEvent(stop);
00455 par.SetEventInterval(interval);
00456 step->SetSourcePar(&par);
00457 }
00458
00459 void TGo4Interface::StepMbsRevServSource(const char* stepname,
00460 const char* sourcename,
00461 int timeout,
00462 int port,
00463 int start,
00464 int stop,
00465 int interval)
00466 {
00467 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00468 if (step==0) return;
00469
00470 TGo4RevServParameter par(sourcename);
00471 par.SetTimeout(timeout);
00472 par.SetPort(port);
00473 par.SetStartEvent(start);
00474 par.SetStopEvent(stop);
00475 par.SetEventInterval(interval);
00476 step->SetSourcePar(&par);
00477 }
00478
00479 void TGo4Interface::StepRandomSource(const char* stepname,
00480 const char* sourcename,
00481 int timeout)
00482 {
00483 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00484 if (step==0) return;
00485
00486 TGo4MbsRandomParameter par(sourcename);
00487 par.SetTimeout(timeout);
00488 step->SetSourcePar(&par);
00489 }
00490
00491 void TGo4Interface::StepUserSource(const char* stepname,
00492 const char* sourcename,
00493 int timeout,
00494 int port,
00495 const char* expr)
00496 {
00497 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00498 if (step==0) return;
00499
00500 TGo4UserSourceParameter par(sourcename);
00501 par.SetTimeout(timeout);
00502 par.SetPort(port);
00503 par.SetExpression(expr);
00504 step->SetSourcePar(&par);
00505 }
00506
00507 void TGo4Interface::StepFileStore(const char* stepname,
00508 const char* storename,
00509 bool overwrite,
00510 int bufsize,
00511 int splitlevel,
00512 int compression)
00513 {
00514 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00515 if (step==0) return;
00516
00517 TGo4FileStoreParameter par(storename);
00518 par.SetOverwriteMode(overwrite);
00519 par.SetBufsize(bufsize);
00520 par.SetSplitlevel(splitlevel);
00521 par.SetCompression(compression);
00522 step->SetStorePar(&par);
00523 }
00524
00525 void TGo4Interface::StepBackStore(const char* stepname,
00526 const char* storename,
00527 int bufsize,
00528 int splitlevel)
00529 {
00530 TGo4AnalysisStepStatus* step = GetStepStatus(stepname);
00531 if (step==0) return;
00532
00533 TGo4BackStoreParameter par(storename);
00534 par.SetBufsize(bufsize);
00535 par.SetSplitlevel(splitlevel);
00536 step->SetStorePar(&par);
00537 }
00538
00539 ViewPanelHandle TGo4Interface::StartViewPanel()
00540 {
00541 return StartViewPanel(10,10, 500, 300, 1, 0);
00542 }
00543
00544 ViewPanelHandle TGo4Interface::StartViewPanel(int x, int y, int width, int height, int mode, TGo4Picture* pic)
00545 {
00546 static Int_t cancounter = 0;
00547
00548 TString cname = "Panel";
00549 cname+=cancounter++;
00550
00551 TCanvas* c = new TCanvas(cname.Data(), TString("Drawing of ") + cname, width, height);
00552
00553 fRootBrowser->DrawPicture("", pic, c);
00554
00555 c->Update();
00556
00557 return (ViewPanelHandle) c;
00558 }
00559
00560 TString TGo4Interface::GetViewPanelName(ViewPanelHandle handle)
00561 {
00562 TCanvas* c = (TCanvas*) handle;
00563 return TString(c ? c->GetName() : "");
00564 }
00565
00566 ViewPanelHandle TGo4Interface::FindViewPanel(const char* name)
00567 {
00568 return (ViewPanelHandle) gROOT->GetListOfCanvases()->FindObject(name);
00569 }
00570
00571 Bool_t TGo4Interface::SetViewPanelName(ViewPanelHandle handle, const char* newname)
00572 {
00573 TCanvas* c = (TCanvas*) handle;
00574 if ((c==0) || (newname==0) || (strlen(newname)==0)) return kFALSE;
00575
00576 if (gROOT->GetListOfCanvases()->FindObject(newname)) {
00577 Message(Form("Canvas with name %s already exists",newname));
00578 return kFALSE;
00579 }
00580
00581 c->SetName(newname);
00582
00583 c->Update();
00584
00585 return kTRUE;
00586 }
00587
00588 ViewPanelHandle TGo4Interface::GetActiveViewPanel()
00589 {
00590 if (gPad==0) return 0;
00591 return (ViewPanelHandle) gPad->GetCanvas();
00592 }
00593
00594 void TGo4Interface::RedrawPanel(ViewPanelHandle handle)
00595 {
00596 TCanvas* c = (TCanvas*) handle;
00597 if (c!=0) {
00598 c->Modified();
00599 c->Update();
00600 }
00601 }
00602
00603 void TGo4Interface::DivideViewPanel(ViewPanelHandle handle, Int_t numX, Int_t numY)
00604 {
00605 TCanvas* c = (TCanvas*) handle;
00606 if (c!=0) c->Divide(numX, numY);
00607 }
00608
00609 TPad* TGo4Interface::SelectPad(ViewPanelHandle handle, Int_t number)
00610 {
00611 TCanvas* c = (TCanvas*) handle;
00612 if (c!=0) return (TPad*) c->cd(number);
00613 return 0;
00614 }
00615
00616 Bool_t TGo4Interface::DrawItem(const char* itemname, ViewPanelHandle handle, const char* drawopt)
00617 {
00618 if (handle==0) handle = StartViewPanel();
00619
00620 TObject* obj = GetObject(itemname, 5000);
00621
00622 if (obj!=0) obj->Draw(drawopt);
00623
00624 return obj!=0;
00625 }
00626
00627 void TGo4Interface::RedrawItem(const char* itemname)
00628 {
00629 TGo4AbstractInterface::RedrawItem(itemname);
00630
00631 TIter next(gROOT->GetListOfCanvases());
00632 TPad* pad = 0;
00633 while ((pad = (TPad*) next()) != 0) {
00634 pad->Modified();
00635
00636 TVirtualPad* subpad = 0;
00637 Int_t number = 0;
00638 while ((subpad = pad->GetPad(number++))!=0)
00639 subpad->Modified();
00640
00641 pad->Update();
00642 }
00643 }
00644
00645 Bool_t TGo4Interface::HandleTimer(TTimer* timer)
00646 {
00647
00648 if (!IsHotStart()) return kTRUE;
00649
00650 if (timer!=fCmdTimer) return kFALSE;
00651
00652
00653
00654
00655 if (fWaitCounter>0) {
00656 fWaitCounter--;
00657 TGo4AnalysisProxy* anal = Analysis();
00658 if (anal && anal->IsAnalysisReady())
00659 fWaitCounter = 0;
00660 else
00661 if (fWaitCounter<2) FreeHotStartCmds();
00662 } else
00663 ProcessHotStart();
00664
00665 if (IsHotStart()) fCmdTimer->Start(10, kTRUE);
00666 return kTRUE;
00667 }
00668
00669
00670 void TGo4Interface::HotStart(const char* filename)
00671 {
00672 if ((filename==0) || (strlen(filename)==0)) return;
00673
00674 FreeHotStartCmds();
00675
00676 fCmdFinished = kTRUE;
00677
00678 if (!LoadHotStart(filename)) return;
00679
00680 if (fCmdTimer==0)
00681 fCmdTimer = new TTimer(this, 10, kTRUE);
00682
00683 fCmdTimer->Start(10, kTRUE);
00684 }
00685
00686 void TGo4Interface::ProcessHotStart()
00687 {
00688 if (!fCmdFinished) {
00689 Error("ProcessHotStart","Internal problem");
00690 return;
00691 }
00692
00693 const char* nextcmd = NextHotStartCmd();
00694
00695 if ((nextcmd==0) || !IsHotStart()) return;
00696
00697 Int_t error = 0;
00698 fCmdFinished = kFALSE;
00699 gROOT->ProcessLineSync(nextcmd, &error);
00700 fCmdFinished = kTRUE;
00701
00702 if (error!=0)
00703 Error("ProcessHotStart", "ProcessLine(\"%s\") error %d", nextcmd, error);
00704 }