1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class provides a graphical user interface for the monitor process //
22 ///////////////////////////////////////////////////////////////////////////////
25 #include "AliMonitorControl.h"
26 #include "AliMonitorHisto.h"
27 #include "AliMonitorDialog.h"
28 #include <TGNumberEntry.h>
29 #include <TGTextView.h>
35 ClassImp(AliMonitorControl)
38 //_____________________________________________________________________________
39 class AliMonitorBufferDlg : public AliMonitorDialog {
42 AliMonitorBufferDlg(Int_t& size, TGFrame* main);
43 virtual ~AliMonitorBufferDlg();
45 virtual void OnOkClicked();
48 TGLayoutHints* fBufferLayout;
49 TGLabel* fBufferLabel;
50 TGNumberEntry* fBufferEntry;
56 //_____________________________________________________________________________
57 AliMonitorBufferDlg::AliMonitorBufferDlg(Int_t& size, TGFrame* main) :
58 AliMonitorDialog(main, 250, 80), fSize(size)
60 // create a dialog for setting the size of the buffer for monitor histos
62 fBufferLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2);
63 fBufferLabel = new TGLabel(fFrame, "size of histogram buffer:");
64 fFrame->AddFrame(fBufferLabel, fBufferLayout);
65 fBufferEntry = new TGNumberEntry(fFrame, size, 2, -1,
66 TGNumberFormat::kNESInteger);
67 fBufferEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 1, 99);
68 fFrame->AddFrame(fBufferEntry, fBufferLayout);
72 fMain->SetWindowName("Buffer Size");
73 fMain->MapSubwindows();
75 gClient->WaitFor(fMain);
78 //_____________________________________________________________________________
79 AliMonitorBufferDlg::~AliMonitorBufferDlg()
88 //_____________________________________________________________________________
89 void AliMonitorBufferDlg::OnOkClicked()
91 fSize = fBufferEntry->GetIntNumber();
95 //_____________________________________________________________________________
96 class AliMonitorClientsDlg : public AliMonitorDialog {
99 AliMonitorClientsDlg(TObjArray* clients, TGFrame* main);
100 virtual ~AliMonitorClientsDlg();
103 TGLayoutHints* fClientsLayout;
104 TGTextView* fClients;
108 //_____________________________________________________________________________
109 AliMonitorClientsDlg::AliMonitorClientsDlg(TObjArray* clients, TGFrame* main) :
110 AliMonitorDialog(main, 450, 300, kFALSE)
112 // create a dialog to display the list of clients
115 fFrameLayout = new TGLayoutHints(kLHintsCenterX | kLHintsTop,
117 ((TGFrameElement*)(fMain->GetList()->First()))->fLayout = fFrameLayout;
118 fClientsLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
120 fClients = new TGTextView(fFrame, 420, 230);
121 fFrame->AddFrame(fClients, fClientsLayout);
124 const char* format = "%-30s%-20s%-8d";
125 sprintf(line, format, "name", "address", 0);
126 strncpy(&line[50], "port", 4);
127 fClients->AddLine(line);
128 for (Int_t i = 0; i < (Int_t) strlen(line); i++) line[i] = '-';
129 fClients->AddLine(line);
131 for (Int_t iClient = 0; iClient < clients->GetEntriesFast(); iClient++) {
132 TSocket* socket = (TSocket*) clients->At(iClient);
133 if (!socket) continue;
134 TInetAddress adr = socket->GetInetAddress();
135 sprintf(line, format,
136 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
137 fClients->AddLine(line);
140 fMain->SetWindowName("List of Clients");
141 fMain->MapSubwindows();
143 gClient->WaitFor(fMain);
146 //_____________________________________________________________________________
147 AliMonitorClientsDlg::~AliMonitorClientsDlg()
151 delete fClientsLayout;
156 // constants for menu entries
157 enum {kMenuFileExit, kMenuFileAbort,
158 kMenuOptBuffer, kMenuOptClients,
159 kMenuHelpDoc, kMenuHelpAbout
163 //_____________________________________________________________________________
164 AliMonitorControl::AliMonitorControl(AliMonitorProcess* process)
166 // initialize the monitoring control window
168 fMonitorProcess = process;
172 gClient->GetColorByName("lightblue", fColorStatus);
173 gClient->GetColorByName("green", fColorStart);
174 gClient->GetColorByName("red", fColorStop);
177 fMain = new TGMainFrame(gClient->GetRoot(), 380, 200);
180 fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
182 fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
183 fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
185 fMenuFile = new TGPopupMenu(gClient->GetRoot());
186 fMenuFile->AddEntry("E&xit", kMenuFileExit);
187 fMenuFile->AddEntry("&Abort", kMenuFileAbort);
188 fMenuFile->DisableEntry(kMenuFileAbort);
189 fMenuFile->Connect("Activated(Int_t)", "AliMonitorControl", this,
190 "HandleMenu(Int_t)");
192 fMenuOptions = new TGPopupMenu(gClient->GetRoot());
193 fMenuOptions->AddEntry("&Histogram buffer...", kMenuOptBuffer);
194 fMenuOptions->AddEntry("List of &Clients...", kMenuOptClients);
195 fMenuOptions->Connect("Activated(Int_t)", "AliMonitorControl", this,
196 "HandleMenu(Int_t)");
198 fMenuHelp = new TGPopupMenu(gClient->GetRoot());
199 fMenuHelp->AddEntry("&Documentation...", kMenuHelpDoc);
200 fMenuHelp->AddEntry("A&bout...", kMenuHelpAbout);
201 fMenuHelp->Connect("Activated(Int_t)", "AliMonitorControl", this,
202 "HandleMenu(Int_t)");
204 fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
205 fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
206 fMenuBar->AddPopup("&Options", fMenuOptions, fMenuBarItemLayout);
207 fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
209 fMain->AddFrame(fMenuBar, fMenuBarLayout);
213 fFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
215 fFrame = new TGVerticalFrame(fMain, 0, 0, kChildFrame | kSunkenFrame);
216 fMain->AddFrame(fFrame, fFrameLayout);
218 fStatusLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 2, 2);
219 fStatusFrameLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2);
222 // run and event number
223 fStatus1Frame = new TGHorizontalFrame(fFrame, 0, 0);
224 fFrame->AddFrame(fStatus1Frame, fStatusFrameLayout);
226 fRunNumberLabel = new TGLabel(fStatus1Frame, "current run:");
227 fStatus1Frame->AddFrame(fRunNumberLabel, fStatusLayout);
228 fRunNumber = new TGTextEntry(fStatus1Frame, "-");
229 fRunNumber->Resize(60, fRunNumber->GetDefaultHeight());
230 fRunNumber->SetAlignment(kTextRight);
231 fRunNumber->SetEnabled(kFALSE);
232 fRunNumber->SetBackgroundColor(fColorStatus);
233 fStatus1Frame->AddFrame(fRunNumber, fStatusLayout);
235 fEventNumberLabel = new TGLabel(fStatus1Frame,
237 fStatus1Frame->AddFrame(fEventNumberLabel, fStatusLayout);
238 fEventNumber = new TGTextEntry(fStatus1Frame, "-/-/-");
239 fEventNumber->Resize(100, fEventNumber->GetDefaultHeight());
240 fEventNumber->SetAlignment(kTextRight);
241 fEventNumber->SetEnabled(kFALSE);
242 fEventNumber->SetBackgroundColor(fColorStatus);
243 fStatus1Frame->AddFrame(fEventNumber, fStatusLayout);
247 fStatus2Frame = new TGHorizontalFrame(fFrame, 0, 0);
248 fFrame->AddFrame(fStatus2Frame, fStatusFrameLayout);
250 fStatusLabel = new TGLabel(fStatus2Frame, "current status:");
251 fStatus2Frame->AddFrame(fStatusLabel, fStatusLayout);
252 fStatus = new TGTextEntry(fStatus2Frame, "stopped");
253 fStatus->Resize(250, fStatus->GetDefaultHeight());
254 fStatus->SetAlignment(kTextLeft);
255 fStatus->SetEnabled(kFALSE);
256 fStatus->SetBackgroundColor(fColorStatus);
257 fStatus2Frame->AddFrame(fStatus, fStatusLayout);
261 fStatus3Frame = new TGHorizontalFrame(fFrame, 0, 0);
262 fFrame->AddFrame(fStatus3Frame, fStatusFrameLayout);
264 fEventsLabel = new TGLabel(fStatus3Frame, "monitored events:");
265 fStatus3Frame->AddFrame(fEventsLabel, fStatusLayout);
266 fEvents = new TGTextEntry(fStatus3Frame, "-");
267 fEvents->Resize(60, fEvents->GetDefaultHeight());
268 fEvents->SetAlignment(kTextRight);
269 fEvents->SetEnabled(kFALSE);
270 fEvents->SetBackgroundColor(fColorStatus);
271 fStatus3Frame->AddFrame(fEvents, fStatusLayout);
273 fClientsLabel = new TGLabel(fStatus3Frame, " number of clients:");
274 fStatus3Frame->AddFrame(fClientsLabel, fStatusLayout);
275 fClients = new TGTextEntry(fStatus3Frame, "-");
276 fClients->Resize(40, fClients->GetDefaultHeight());
277 fClients->SetAlignment(kTextRight);
278 fClients->SetEnabled(kFALSE);
279 fClients->SetBackgroundColor(fColorStatus);
280 fStatus3Frame->AddFrame(fClients, fStatusLayout);
284 fButtonFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsBottom,
286 fButtonFrame = new TGHorizontalFrame(fMain, 0, 0);
287 fMain->AddFrame(fButtonFrame, fButtonFrameLayout);
289 fButtonLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
291 fResetButton = new TGTextButton(fButtonFrame, " &Reset ", 1);
292 fResetButton->Connect("Clicked()", "AliMonitorControl", this, "DoReset()");
293 fButtonFrame->AddFrame(fResetButton, fButtonLayout);
295 fStartStopButton = new TGTextButton(fButtonFrame, " &Start ", 2);
296 fStartStopButton->SetBackgroundColor(0x00FF00);
297 fStartStopButton->Connect("Clicked()", "AliMonitorControl", this,
299 fButtonFrame->AddFrame(fStartStopButton, fButtonLayout);
300 fStartButtonStatus = kTRUE;
304 fMain->SetWindowName("Monitor Process Control");
305 fMain->DontCallClose();
306 fMain->SetWMSize(fMain->GetWidth(), fMain->GetHeight());
307 fMain->SetWMSizeHints(fMain->GetWidth(), fMain->GetHeight(),
308 fMain->GetWidth(), fMain->GetHeight(), 0, 0);
309 fMain->SetWMPosition(100, 100);
310 fMain->MapSubwindows();
315 fTerminating = kFALSE;
317 fTimer = new TTimer(this, 100, kFALSE);
321 //_____________________________________________________________________________
322 AliMonitorControl::~AliMonitorControl()
326 delete fMenuBarLayout;
327 delete fMenuBarItemLayout;
328 delete fMenuBarHelpLayout;
336 delete fStatusLayout;
337 delete fStatusFrameLayout;
339 delete fStatus1Frame;
340 delete fRunNumberLabel;
342 delete fEventNumberLabel;
345 delete fStatus2Frame;
349 delete fStatus3Frame;
352 delete fClientsLabel;
355 delete fButtonFrameLayout;
357 delete fButtonLayout;
359 delete fStartStopButton;
365 //_____________________________________________________________________________
366 void AliMonitorControl::HandleMenu(Int_t id)
368 // called when a menu item was selected
372 case kMenuFileExit: {
374 new TGMsgBox(gClient->GetRoot(), fMain, "Exit",
375 "Do you really want to terminate the monitor process?",
376 kMBIconQuestion, kMBYes | kMBNo, &result);
377 if (result == kMBYes) {
378 fMenuFile->EnableEntry(kMenuFileAbort);
379 if (fMonitorProcess->IsStopped()) exit(0);
380 fMonitorProcess->Stop();
381 fTerminating = kTRUE;
389 case kMenuOptBuffer: {
390 Int_t size = AliMonitorHisto::GetNHistosMax();
391 new AliMonitorBufferDlg(size, fMain);
393 AliMonitorHisto::SetNHistosMax(size);
397 case kMenuOptClients: {
398 new AliMonitorClientsDlg(fMonitorProcess->GetListOfClients(), fMain);
402 case kMenuHelpAbout: {
405 sprintf(text, "AliMonitorControl $Revision$\nrunning\n"
406 "AliMonitorProcess %s", AliMonitorProcess::GetRevision());
407 new TGMsgBox(gClient->GetRoot(), fMain,
408 "About", text, kMBIconAsterisk, kMBOk, &result);
414 new TGMsgBox(gClient->GetRoot(), fMain,
415 "AliMonitorControl", "not yet implemented",
416 kMBIconExclamation, kMBOk, &result);
421 //_____________________________________________________________________________
422 void AliMonitorControl::DoReset()
424 // called when the reset button was clicked
427 new TGMsgBox(gClient->GetRoot(), fMain, "Reset",
428 "Do you really want to reset the monitor histograms?",
429 kMBIconQuestion, kMBYes | kMBNo, &result);
430 if (result == kMBYes) {
431 fMonitorProcess->Reset();
435 //_____________________________________________________________________________
436 void AliMonitorControl::DoStartStop()
438 // called when the start/stop button was clicked
440 if (fStartButtonStatus) {
441 if (fMonitorProcess->GetStatus() == AliMonitorProcess::kStopped) {
442 fStartStopButton->SetBackgroundColor(fColorStop);
443 fStartStopButton->SetText(" &Stop ");
444 fStartButtonStatus = kFALSE;
445 fMonitorProcess->Run();
446 fStartStopButton->SetBackgroundColor(fColorStart);
447 fStartStopButton->SetText(" &Start ");
448 fStartButtonStatus = kTRUE;
452 if (fMonitorProcess->GetStatus() != AliMonitorProcess::kStopped) {
453 fMonitorProcess->Stop();
460 //_____________________________________________________________________________
461 Bool_t AliMonitorControl::HandleTimer(TTimer* timer)
463 // update the displayed information
466 if (fTerminating && fMonitorProcess->IsStopped()) exit(0);
468 gSystem->ProcessEvents();
474 //_____________________________________________________________________________
475 void AliMonitorControl::UpdateStatus()
477 // update the displayed status information
481 if (fMonitorProcess->IsStopped()) {
482 fRunNumber->SetText("-");
483 fEventNumber->SetText("-/-/-");
484 fEvents->SetText("-");
485 fClients->SetText("-");
488 sprintf(text, "%d", fMonitorProcess->GetRunNumber());
489 fRunNumber->SetText(text);
490 sprintf(text, "%d/%d/%d", fMonitorProcess->GetEventPeriodNumber(),
491 fMonitorProcess->GetEventOrbitNumber(),
492 fMonitorProcess->GetEventBunchNumber());
493 fEventNumber->SetText(text);
494 sprintf(text, "%d", fMonitorProcess->GetNumberOfEvents());
495 fEvents->SetText(text);
496 sprintf(text, "%d", fMonitorProcess->GetNumberOfClients());
497 fClients->SetText(text);
500 const char* status = NULL;
501 switch (fMonitorProcess->GetStatus()) {
502 case AliMonitorProcess::kStopped:
503 status = "stopped"; break;
504 case AliMonitorProcess::kWaiting:
505 status = "waiting for new data"; break;
506 case AliMonitorProcess::kReading:
507 status = "reading raw data"; break;
508 case AliMonitorProcess::kRecTPC:
509 status = "running TPC reconstruction"; break;
510 case AliMonitorProcess::kRecITS:
511 status = "running ITS reconstruction"; break;
512 case AliMonitorProcess::kRecV0s:
513 status = "running V0 reconstruction"; break;
514 case AliMonitorProcess::kFilling:
515 status = "filling monitor histograms"; break;
516 case AliMonitorProcess::kUpdating:
517 status = "updating monitor histograms"; break;
518 case AliMonitorProcess::kWriting:
519 status = "writing monitor histograms"; break;
520 case AliMonitorProcess::kResetting:
521 status = "resetting monitor histograms"; break;
522 case AliMonitorProcess::kConnecting:
523 status = "checking for new clients"; break;
524 case AliMonitorProcess::kBroadcasting:
525 status = "broadcasting monitor histograms"; break;
528 if (fMonitorProcess->WillStop()) {
529 sprintf(text, "stopping... (%s)", status);
531 sprintf(text, "%s", status);
533 if (strcmp(text, fStatus->GetText()) != 0) {
534 fStatus->SetText(text);
538 if (fStartButtonStatus != fMonitorProcess->IsStopped()) {
539 fStartButtonStatus = fMonitorProcess->IsStopped();
540 if (fStartButtonStatus) {
541 fStartStopButton->SetBackgroundColor(fColorStart);
542 fStartStopButton->SetText(" &Start ");
544 fStartStopButton->SetBackgroundColor(fColorStop);
545 fStartStopButton->SetText(" &Stop ");