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 <TGNumberEntry.h>
28 #include <TGTextView.h>
36 #include <TGTextEntry.h>
38 #include <TApplication.h>
39 #include "AliMonitorProcess.h"
42 ClassImp(AliMonitorControl)
46 //_____________________________________________________________________________
47 AliMonitorControl::AliMonitorBufferDlg::AliMonitorBufferDlg(Int_t& size,
49 AliMonitorDialog(main, 250, 80), fSize(size)
51 // create a dialog for setting the size of the buffer for monitor histos
53 fBufferLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2);
54 fBufferLabel = new TGLabel(fFrame, "size of histogram buffer:");
55 fFrame->AddFrame(fBufferLabel, fBufferLayout);
56 fBufferEntry = new TGNumberEntry(fFrame, size, 2, -1,
57 TGNumberFormat::kNESInteger);
58 fBufferEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 1, 99);
59 fFrame->AddFrame(fBufferEntry, fBufferLayout);
63 fMain->SetWindowName("Buffer Size");
64 fMain->MapSubwindows();
66 gClient->WaitFor(fMain);
69 //_____________________________________________________________________________
70 AliMonitorControl::AliMonitorBufferDlg::~AliMonitorBufferDlg()
79 //_____________________________________________________________________________
80 void AliMonitorControl::AliMonitorBufferDlg::OnOkClicked()
82 fSize = fBufferEntry->GetIntNumber();
86 //_____________________________________________________________________________
87 AliMonitorControl::AliMonitorClientsDlg::AliMonitorClientsDlg(TObjArray* clients,
89 AliMonitorDialog(main, 450, 300, kFALSE)
91 // create a dialog to display the list of clients
94 fFrameLayout = new TGLayoutHints(kLHintsCenterX | kLHintsTop,
96 ((TGFrameElement*)(fMain->GetList()->First()))->fLayout = fFrameLayout;
97 fClientsLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
99 fClients = new TGTextView(fFrame, 420, 230);
100 fFrame->AddFrame(fClients, fClientsLayout);
103 const char* format = "%-30s%-20s%-8d";
104 sprintf(line, format, "name", "address", 0);
105 strncpy(&line[50], "port", 4);
106 fClients->AddLine(line);
107 for (Int_t i = 0; i < (Int_t) strlen(line); i++) line[i] = '-';
108 fClients->AddLine(line);
110 for (Int_t iClient = 0; iClient < clients->GetEntriesFast(); iClient++) {
111 TSocket* socket = (TSocket*) clients->At(iClient);
112 if (!socket) continue;
113 TInetAddress adr = socket->GetInetAddress();
114 sprintf(line, format,
115 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
116 fClients->AddLine(line);
119 fMain->SetWindowName("List of Clients");
120 fMain->MapSubwindows();
122 gClient->WaitFor(fMain);
125 //_____________________________________________________________________________
126 AliMonitorControl::AliMonitorClientsDlg::~AliMonitorClientsDlg()
130 delete fClientsLayout;
135 // constants for menu entries
136 enum {kMenuFileExit, kMenuFileAbort,
137 kMenuOptBuffer, kMenuOptClients,
138 kMenuHelpDoc, kMenuHelpAbout
142 //_____________________________________________________________________________
143 AliMonitorControl::AliMonitorControl(AliMonitorProcess* process)
145 // initialize the monitoring control window
147 fMonitorProcess = process;
151 gClient->GetColorByName("lightblue", fColorStatus);
152 gClient->GetColorByName("green", fColorStart);
153 gClient->GetColorByName("red", fColorStop);
156 fMain = new TGMainFrame(gClient->GetRoot(), 380, 200);
159 fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
161 fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
162 fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
164 fMenuFile = new TGPopupMenu(gClient->GetRoot());
165 fMenuFile->AddEntry("E&xit", kMenuFileExit);
166 fMenuFile->AddEntry("&Abort", kMenuFileAbort);
167 fMenuFile->DisableEntry(kMenuFileAbort);
168 fMenuFile->Connect("Activated(Int_t)", "AliMonitorControl", this,
169 "HandleMenu(Int_t)");
171 fMenuOptions = new TGPopupMenu(gClient->GetRoot());
172 fMenuOptions->AddEntry("&Histogram buffer...", kMenuOptBuffer);
173 fMenuOptions->AddEntry("List of &Clients...", kMenuOptClients);
174 fMenuOptions->Connect("Activated(Int_t)", "AliMonitorControl", this,
175 "HandleMenu(Int_t)");
177 fMenuHelp = new TGPopupMenu(gClient->GetRoot());
178 fMenuHelp->AddEntry("&Documentation...", kMenuHelpDoc);
179 fMenuHelp->AddEntry("A&bout...", kMenuHelpAbout);
180 fMenuHelp->Connect("Activated(Int_t)", "AliMonitorControl", this,
181 "HandleMenu(Int_t)");
183 fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
184 fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
185 fMenuBar->AddPopup("&Options", fMenuOptions, fMenuBarItemLayout);
186 fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
188 fMain->AddFrame(fMenuBar, fMenuBarLayout);
192 fFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
194 fFrame = new TGVerticalFrame(fMain, 0, 0, kChildFrame | kSunkenFrame);
195 fMain->AddFrame(fFrame, fFrameLayout);
197 fStatusLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 2, 2);
198 fStatusFrameLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2);
201 // run and event number
202 fStatus1Frame = new TGHorizontalFrame(fFrame, 0, 0);
203 fFrame->AddFrame(fStatus1Frame, fStatusFrameLayout);
205 fRunNumberLabel = new TGLabel(fStatus1Frame, "current run:");
206 fStatus1Frame->AddFrame(fRunNumberLabel, fStatusLayout);
207 fRunNumber = new TGTextEntry(fStatus1Frame, "-");
208 fRunNumber->Resize(60, fRunNumber->GetDefaultHeight());
209 fRunNumber->SetAlignment(kTextRight);
210 fRunNumber->SetEnabled(kFALSE);
211 fRunNumber->SetBackgroundColor(fColorStatus);
212 fStatus1Frame->AddFrame(fRunNumber, fStatusLayout);
214 fEventNumberLabel = new TGLabel(fStatus1Frame,
216 fStatus1Frame->AddFrame(fEventNumberLabel, fStatusLayout);
217 fEventNumber = new TGTextEntry(fStatus1Frame, "-/-/-");
218 fEventNumber->Resize(100, fEventNumber->GetDefaultHeight());
219 fEventNumber->SetAlignment(kTextRight);
220 fEventNumber->SetEnabled(kFALSE);
221 fEventNumber->SetBackgroundColor(fColorStatus);
222 fStatus1Frame->AddFrame(fEventNumber, fStatusLayout);
226 fStatus2Frame = new TGHorizontalFrame(fFrame, 0, 0);
227 fFrame->AddFrame(fStatus2Frame, fStatusFrameLayout);
229 fStatusLabel = new TGLabel(fStatus2Frame, "current status:");
230 fStatus2Frame->AddFrame(fStatusLabel, fStatusLayout);
231 fStatus = new TGTextEntry(fStatus2Frame, "stopped");
232 fStatus->Resize(250, fStatus->GetDefaultHeight());
233 fStatus->SetAlignment(kTextLeft);
234 fStatus->SetEnabled(kFALSE);
235 fStatus->SetBackgroundColor(fColorStatus);
236 fStatus2Frame->AddFrame(fStatus, fStatusLayout);
240 fStatus3Frame = new TGHorizontalFrame(fFrame, 0, 0);
241 fFrame->AddFrame(fStatus3Frame, fStatusFrameLayout);
243 fEventsLabel = new TGLabel(fStatus3Frame, "monitored events:");
244 fStatus3Frame->AddFrame(fEventsLabel, fStatusLayout);
245 fEvents = new TGTextEntry(fStatus3Frame, "-");
246 fEvents->Resize(60, fEvents->GetDefaultHeight());
247 fEvents->SetAlignment(kTextRight);
248 fEvents->SetEnabled(kFALSE);
249 fEvents->SetBackgroundColor(fColorStatus);
250 fStatus3Frame->AddFrame(fEvents, fStatusLayout);
252 fClientsLabel = new TGLabel(fStatus3Frame, " number of clients:");
253 fStatus3Frame->AddFrame(fClientsLabel, fStatusLayout);
254 fClients = new TGTextEntry(fStatus3Frame, "-");
255 fClients->Resize(40, fClients->GetDefaultHeight());
256 fClients->SetAlignment(kTextRight);
257 fClients->SetEnabled(kFALSE);
258 fClients->SetBackgroundColor(fColorStatus);
259 fStatus3Frame->AddFrame(fClients, fStatusLayout);
263 fButtonFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsBottom,
265 fButtonFrame = new TGHorizontalFrame(fMain, 0, 0);
266 fMain->AddFrame(fButtonFrame, fButtonFrameLayout);
268 fButtonLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
270 fResetButton = new TGTextButton(fButtonFrame, " &Reset ", 1);
271 fResetButton->Connect("Clicked()", "AliMonitorControl", this, "DoReset()");
272 fButtonFrame->AddFrame(fResetButton, fButtonLayout);
274 fStartStopButton = new TGTextButton(fButtonFrame, " &Start ", 2);
275 fStartStopButton->SetBackgroundColor(0x00FF00);
276 fStartStopButton->Connect("Clicked()", "AliMonitorControl", this,
278 fButtonFrame->AddFrame(fStartStopButton, fButtonLayout);
279 fStartButtonStatus = kTRUE;
283 fMain->SetWindowName("Monitor Process Control");
284 fMain->DontCallClose();
285 fMain->SetWMSize(fMain->GetWidth(), fMain->GetHeight());
286 fMain->SetWMSizeHints(fMain->GetWidth(), fMain->GetHeight(),
287 fMain->GetWidth(), fMain->GetHeight(), 0, 0);
288 fMain->SetWMPosition(100, 100);
289 fMain->MapSubwindows();
294 fTerminating = kFALSE;
296 fTimer = new TTimer(this, 10, kTRUE);
300 //_____________________________________________________________________________
301 AliMonitorControl::AliMonitorControl(const AliMonitorControl& control) :
304 Fatal("AliMonitorControl", "copy constructor not implemented");
307 //_____________________________________________________________________________
308 AliMonitorControl& AliMonitorControl::operator = (const AliMonitorControl&
311 Fatal("operator =", "assignment operator not implemented");
315 //_____________________________________________________________________________
316 AliMonitorControl::~AliMonitorControl()
320 delete fMenuBarLayout;
321 delete fMenuBarItemLayout;
322 delete fMenuBarHelpLayout;
330 delete fStatusLayout;
331 delete fStatusFrameLayout;
333 delete fStatus1Frame;
334 delete fRunNumberLabel;
336 delete fEventNumberLabel;
339 delete fStatus2Frame;
343 delete fStatus3Frame;
346 delete fClientsLabel;
349 delete fButtonFrameLayout;
351 delete fButtonLayout;
353 delete fStartStopButton;
359 //_____________________________________________________________________________
360 void AliMonitorControl::HandleMenu(Int_t id)
362 // called when a menu item was selected
366 case kMenuFileExit: {
368 new TGMsgBox(gClient->GetRoot(), fMain, "Exit",
369 "Do you really want to terminate the monitor process?",
370 kMBIconQuestion, kMBYes | kMBNo, &result);
371 if (result == kMBYes) {
372 fMenuFile->EnableEntry(kMenuFileAbort);
373 if (fMonitorProcess->IsStopped()) {
374 delete fMonitorProcess;
375 gApplication->Terminate(0);
377 fMonitorProcess->Stop();
378 fTerminating = kTRUE;
386 case kMenuOptBuffer: {
387 Int_t size = AliMonitorHisto::GetNHistosMax();
388 new AliMonitorBufferDlg(size, fMain);
390 AliMonitorHisto::SetNHistosMax(size);
394 case kMenuOptClients: {
395 new AliMonitorClientsDlg(fMonitorProcess->GetListOfClients(), fMain);
399 case kMenuHelpAbout: {
402 sprintf(text, "AliMonitorControl $Revision$\nrunning\n"
403 "AliMonitorProcess %s", AliMonitorProcess::GetRevision());
404 new TGMsgBox(gClient->GetRoot(), fMain,
405 "About", text, kMBIconAsterisk, kMBOk, &result);
411 new TGMsgBox(gClient->GetRoot(), fMain,
412 "AliMonitorControl", "not yet implemented",
413 kMBIconExclamation, kMBOk, &result);
418 //_____________________________________________________________________________
419 void AliMonitorControl::DoReset()
421 // called when the reset button was clicked
424 new TGMsgBox(gClient->GetRoot(), fMain, "Reset",
425 "Do you really want to reset the monitor histograms?",
426 kMBIconQuestion, kMBYes | kMBNo, &result);
427 if (result == kMBYes) {
428 fMonitorProcess->Reset();
432 //_____________________________________________________________________________
433 void AliMonitorControl::DoStartStop()
435 // called when the start/stop button was clicked
437 if (fStartButtonStatus) {
438 if (fMonitorProcess->GetStatus() == AliMonitorProcess::kStopped) {
439 fStartStopButton->SetBackgroundColor(fColorStop);
440 fStartStopButton->SetText(" &Stop ");
441 fStartButtonStatus = kFALSE;
442 fMonitorProcess->Run();
443 fStartStopButton->SetBackgroundColor(fColorStart);
444 fStartStopButton->SetText(" &Start ");
445 fStartButtonStatus = kTRUE;
449 if (fMonitorProcess->GetStatus() != AliMonitorProcess::kStopped) {
450 fMonitorProcess->Stop();
457 //_____________________________________________________________________________
458 Bool_t AliMonitorControl::HandleTimer(TTimer* timer)
460 // update the displayed information
463 if (fTerminating && fMonitorProcess->IsStopped()) {
464 delete fMonitorProcess;
465 gApplication->Terminate(0);
468 gSystem->ProcessEvents();
475 //_____________________________________________________________________________
476 void AliMonitorControl::UpdateStatus()
478 // update the displayed status information
482 if (fMonitorProcess->IsStopped()) {
483 fRunNumber->SetText("-");
484 fEventNumber->SetText("-/-/-");
485 fEvents->SetText("-");
486 fClients->SetText("-");
489 sprintf(text, "%d", fMonitorProcess->GetRunNumber());
490 fRunNumber->SetText(text);
491 sprintf(text, "%d/%d/%d", fMonitorProcess->GetEventPeriodNumber(),
492 fMonitorProcess->GetEventOrbitNumber(),
493 fMonitorProcess->GetEventBunchNumber());
494 fEventNumber->SetText(text);
495 sprintf(text, "%d", fMonitorProcess->GetNumberOfEvents());
496 fEvents->SetText(text);
497 sprintf(text, "%d", fMonitorProcess->GetNumberOfClients());
498 fClients->SetText(text);
501 const char* status = NULL;
502 switch (fMonitorProcess->GetStatus()) {
503 case AliMonitorProcess::kStopped:
504 status = "stopped"; break;
505 case AliMonitorProcess::kWaiting:
506 status = "waiting for new data"; break;
507 case AliMonitorProcess::kReading:
508 status = "reading raw data"; break;
509 case AliMonitorProcess::kRecTPC:
510 status = "running TPC reconstruction"; break;
511 case AliMonitorProcess::kRecITS:
512 status = "running ITS reconstruction"; break;
513 case AliMonitorProcess::kRecV0s:
514 status = "running V0 reconstruction"; break;
515 case AliMonitorProcess::kRecHLT:
516 status = "running HLT reconstruction"; break;
517 case AliMonitorProcess::kFilling:
518 status = "filling monitor histograms"; break;
519 case AliMonitorProcess::kUpdating:
520 status = "updating monitor histograms"; break;
521 case AliMonitorProcess::kWriting:
522 status = "writing monitor histograms"; break;
523 case AliMonitorProcess::kResetting:
524 status = "resetting monitor histograms"; break;
525 case AliMonitorProcess::kConnecting:
526 status = "checking for new clients"; break;
527 case AliMonitorProcess::kBroadcasting:
528 status = "broadcasting monitor histograms"; break;
531 if (fMonitorProcess->WillStop()) {
532 sprintf(text, "stopping... (%s)", status);
534 sprintf(text, "%s", status);
536 if (strcmp(text, fStatus->GetText()) != 0) {
537 fStatus->SetText(text);
541 if (fStartButtonStatus != fMonitorProcess->IsStopped()) {
542 fStartButtonStatus = fMonitorProcess->IsStopped();
543 if (fStartButtonStatus) {
544 fStartStopButton->SetBackgroundColor(fColorStart);
545 fStartStopButton->SetText(" &Start ");
547 fStartStopButton->SetBackgroundColor(fColorStop);
548 fStartStopButton->SetText(" &Stop ");