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