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"
28 #include <TGNumberEntry.h>
29 #include <TGTextView.h>
37 #include <TGTextEntry.h>
39 #include <TApplication.h>
40 #include "AliMonitorProcess.h"
43 ClassImp(AliMonitorControl)
47 //_____________________________________________________________________________
48 AliMonitorControl::AliMonitorBufferDlg::AliMonitorBufferDlg(Int_t& size,
50 AliMonitorDialog(main, 250, 80),
51 fBufferLayout(new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2)),
52 fBufferLabel(new TGLabel(fFrame, "size of histogram buffer:")),
53 fBufferEntry(new TGNumberEntry(fFrame, size, 2, -1,
54 TGNumberFormat::kNESInteger)),
57 // create a dialog for setting the size of the buffer for monitor histos
59 fFrame->AddFrame(fBufferLabel, fBufferLayout);
60 fBufferEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 1, 99);
61 fFrame->AddFrame(fBufferEntry, fBufferLayout);
65 fMain->SetWindowName("Buffer Size");
66 fMain->MapSubwindows();
68 gClient->WaitFor(fMain);
71 //_____________________________________________________________________________
72 AliMonitorControl::AliMonitorBufferDlg::~AliMonitorBufferDlg()
81 //_____________________________________________________________________________
82 void AliMonitorControl::AliMonitorBufferDlg::OnOkClicked()
84 fSize = fBufferEntry->GetIntNumber();
88 //_____________________________________________________________________________
89 AliMonitorControl::AliMonitorClientsDlg::AliMonitorClientsDlg(TObjArray* clients,
91 AliMonitorDialog(main, 450, 300, kFALSE),
92 fClientsLayout(new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
94 fClients(new TGTextView(fFrame, 420, 230))
96 // create a dialog to display the list of clients
99 fFrameLayout = new TGLayoutHints(kLHintsCenterX | kLHintsTop,
101 ((TGFrameElement*)(fMain->GetList()->First()))->fLayout = fFrameLayout;
102 fFrame->AddFrame(fClients, fClientsLayout);
105 const char* format = "%-30s%-20s%-8d";
106 sprintf(line, format, "name", "address", 0);
107 strncpy(&line[50], "port", 4);
108 fClients->AddLine(line);
109 for (Int_t i = 0; i < (Int_t) strlen(line); i++) line[i] = '-';
110 fClients->AddLine(line);
112 for (Int_t iClient = 0; iClient < clients->GetEntriesFast(); iClient++) {
113 TSocket* socket = (TSocket*) clients->At(iClient);
114 if (!socket) continue;
115 TInetAddress adr = socket->GetInetAddress();
116 sprintf(line, format,
117 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
118 fClients->AddLine(line);
121 fMain->SetWindowName("List of Clients");
122 fMain->MapSubwindows();
124 gClient->WaitFor(fMain);
127 //_____________________________________________________________________________
128 AliMonitorControl::AliMonitorClientsDlg::~AliMonitorClientsDlg()
132 delete fClientsLayout;
137 // constants for menu entries
138 enum {kMenuFileExit, kMenuFileAbort,
139 kMenuOptBuffer, kMenuOptClients,
140 kMenuHelpDoc, kMenuHelpAbout
144 //_____________________________________________________________________________
145 AliMonitorControl::AliMonitorControl(AliMonitorProcess* process):
148 fMonitorProcess(process),
152 fMain(new TGMainFrame(gClient->GetRoot(), 380, 200)),
153 fMenuBarLayout(new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1)),
154 fMenuBarItemLayout(new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)),
155 fMenuBarHelpLayout(new TGLayoutHints(kLHintsTop | kLHintsRight)),
156 fMenuFile(new TGPopupMenu(gClient->GetRoot())),
157 fMenuOptions(new TGPopupMenu(gClient->GetRoot())),
158 fMenuHelp(new TGPopupMenu(gClient->GetRoot())),
159 fMenuBar(new TGMenuBar(fMain, 1, 1, kHorizontalFrame)),
160 fFrameLayout(new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2)),
161 fFrame(new TGVerticalFrame(fMain, 0, 0, kChildFrame | kSunkenFrame)),
162 fStatusLayout(new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 2, 2)),
163 fStatusFrameLayout(new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2)),
164 fStatus1Frame(new TGHorizontalFrame(fFrame, 0, 0)),
165 fRunNumberLabel(new TGLabel(fStatus1Frame, "current run:")),
166 fRunNumber(new TGTextEntry(fStatus1Frame, "-")),
167 fEventNumberLabel(new TGLabel(fStatus1Frame," event:")),
168 fEventNumber(new TGTextEntry(fStatus1Frame, "-/-/-")),
169 fStatus2Frame(new TGHorizontalFrame(fFrame, 0, 0)),
170 fStatusLabel(new TGLabel(fStatus2Frame, "current status:")),
171 fStatus(new TGTextEntry(fStatus2Frame, "stopped")),
172 fStatus3Frame(new TGHorizontalFrame(fFrame, 0, 0)),
173 fEventsLabel(new TGLabel(fStatus3Frame, "monitored events:")),
174 fEvents(new TGTextEntry(fStatus3Frame, "-")),
175 fClientsLabel(new TGLabel(fStatus3Frame, " number of clients:")),
176 fClients(new TGTextEntry(fStatus3Frame, "-")),
177 fButtonFrameLayout(new TGLayoutHints(kLHintsExpandX | kLHintsBottom, 50, 50, 10, 10)),
178 fButtonFrame(new TGHorizontalFrame(fMain, 0, 0)),
179 fButtonLayout(new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2, 2, 2, 2)),
180 fResetButton(new TGTextButton(fButtonFrame, " &Reset ", 1)),
181 fStartStopButton(new TGTextButton(fButtonFrame, " &Start ", 2)),
182 fStartButtonStatus(kTRUE),
183 fTerminating(kFALSE),
184 fTimer(new TTimer(this, 10, kTRUE))
187 // initialize the monitoring control window
192 gClient->GetColorByName("lightblue", fColorStatus);
193 gClient->GetColorByName("green", fColorStart);
194 gClient->GetColorByName("red", fColorStop);
196 fMenuFile->AddEntry("E&xit", kMenuFileExit);
197 fMenuFile->AddEntry("&Abort", kMenuFileAbort);
198 fMenuFile->DisableEntry(kMenuFileAbort);
199 fMenuFile->Connect("Activated(Int_t)", "AliMonitorControl", this,
200 "HandleMenu(Int_t)");
202 fMenuOptions->AddEntry("&Histogram buffer...", kMenuOptBuffer);
203 fMenuOptions->AddEntry("List of &Clients...", kMenuOptClients);
204 fMenuOptions->Connect("Activated(Int_t)", "AliMonitorControl", this,
205 "HandleMenu(Int_t)");
207 fMenuHelp->AddEntry("&Documentation...", kMenuHelpDoc);
208 fMenuHelp->AddEntry("A&bout...", kMenuHelpAbout);
209 fMenuHelp->Connect("Activated(Int_t)", "AliMonitorControl", this,
210 "HandleMenu(Int_t)");
212 fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
213 fMenuBar->AddPopup("&Options", fMenuOptions, fMenuBarItemLayout);
214 fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
216 fMain->AddFrame(fMenuBar, fMenuBarLayout);
220 fMain->AddFrame(fFrame, fFrameLayout);
222 // run and event number
223 fFrame->AddFrame(fStatus1Frame, fStatusFrameLayout);
225 fStatus1Frame->AddFrame(fRunNumberLabel, fStatusLayout);
226 fRunNumber->Resize(60, fRunNumber->GetDefaultHeight());
227 fRunNumber->SetAlignment(kTextRight);
228 fRunNumber->SetEnabled(kFALSE);
229 fRunNumber->SetBackgroundColor(fColorStatus);
230 fStatus1Frame->AddFrame(fRunNumber, fStatusLayout);
232 fStatus1Frame->AddFrame(fEventNumberLabel, fStatusLayout);
233 fEventNumber->Resize(100, fEventNumber->GetDefaultHeight());
234 fEventNumber->SetAlignment(kTextRight);
235 fEventNumber->SetEnabled(kFALSE);
236 fEventNumber->SetBackgroundColor(fColorStatus);
237 fStatus1Frame->AddFrame(fEventNumber, fStatusLayout);
241 fFrame->AddFrame(fStatus2Frame, fStatusFrameLayout);
243 fStatus2Frame->AddFrame(fStatusLabel, fStatusLayout);
244 fStatus->Resize(250, fStatus->GetDefaultHeight());
245 fStatus->SetAlignment(kTextLeft);
246 fStatus->SetEnabled(kFALSE);
247 fStatus->SetBackgroundColor(fColorStatus);
248 fStatus2Frame->AddFrame(fStatus, fStatusLayout);
252 fFrame->AddFrame(fStatus3Frame, fStatusFrameLayout);
254 fStatus3Frame->AddFrame(fEventsLabel, fStatusLayout);
255 fEvents->Resize(60, fEvents->GetDefaultHeight());
256 fEvents->SetAlignment(kTextRight);
257 fEvents->SetEnabled(kFALSE);
258 fEvents->SetBackgroundColor(fColorStatus);
259 fStatus3Frame->AddFrame(fEvents, fStatusLayout);
261 fStatus3Frame->AddFrame(fClientsLabel, fStatusLayout);
262 fClients->Resize(40, fClients->GetDefaultHeight());
263 fClients->SetAlignment(kTextRight);
264 fClients->SetEnabled(kFALSE);
265 fClients->SetBackgroundColor(fColorStatus);
266 fStatus3Frame->AddFrame(fClients, fStatusLayout);
270 fMain->AddFrame(fButtonFrame, fButtonFrameLayout);
272 fResetButton->Connect("Clicked()", "AliMonitorControl", this, "DoReset()");
273 fButtonFrame->AddFrame(fResetButton, fButtonLayout);
275 fStartStopButton->SetBackgroundColor(0x00FF00);
276 fStartStopButton->Connect("Clicked()", "AliMonitorControl", this,
278 fButtonFrame->AddFrame(fStartStopButton, fButtonLayout);
282 fMain->SetWindowName("Monitor Process Control");
283 fMain->DontCallClose();
284 fMain->SetWMSize(fMain->GetWidth(), fMain->GetHeight());
285 fMain->SetWMSizeHints(fMain->GetWidth(), fMain->GetHeight(),
286 fMain->GetWidth(), fMain->GetHeight(), 0, 0);
287 fMain->SetWMPosition(100, 100);
288 fMain->MapSubwindows();
296 //_____________________________________________________________________________
297 AliMonitorControl::~AliMonitorControl()
301 delete fMenuBarLayout;
302 delete fMenuBarItemLayout;
303 delete fMenuBarHelpLayout;
311 delete fStatusLayout;
312 delete fStatusFrameLayout;
314 delete fStatus1Frame;
315 delete fRunNumberLabel;
317 delete fEventNumberLabel;
320 delete fStatus2Frame;
324 delete fStatus3Frame;
327 delete fClientsLabel;
330 delete fButtonFrameLayout;
332 delete fButtonLayout;
334 delete fStartStopButton;
340 //_____________________________________________________________________________
341 void AliMonitorControl::HandleMenu(Int_t id)
343 // called when a menu item was selected
347 case kMenuFileExit: {
349 new TGMsgBox(gClient->GetRoot(), fMain, "Exit",
350 "Do you really want to terminate the monitor process?",
351 kMBIconQuestion, kMBYes | kMBNo, &result);
352 if (result == kMBYes) {
353 fMenuFile->EnableEntry(kMenuFileAbort);
354 if (fMonitorProcess->IsStopped()) {
355 delete fMonitorProcess;
356 gApplication->Terminate(0);
358 fMonitorProcess->Stop();
359 fTerminating = kTRUE;
367 case kMenuOptBuffer: {
368 Int_t size = AliMonitorHisto::GetNHistosMax();
369 new AliMonitorBufferDlg(size, fMain);
371 AliMonitorHisto::SetNHistosMax(size);
375 case kMenuOptClients: {
376 new AliMonitorClientsDlg(fMonitorProcess->GetListOfClients(), fMain);
380 case kMenuHelpAbout: {
383 sprintf(text, "AliMonitorControl $Revision$\nrunning\n"
384 "AliMonitorProcess %s", AliMonitorProcess::GetRevision());
385 new TGMsgBox(gClient->GetRoot(), fMain,
386 "About", text, kMBIconAsterisk, kMBOk, &result);
392 new TGMsgBox(gClient->GetRoot(), fMain,
393 "AliMonitorControl", "not yet implemented",
394 kMBIconExclamation, kMBOk, &result);
399 //_____________________________________________________________________________
400 void AliMonitorControl::DoReset()
402 // called when the reset button was clicked
405 new TGMsgBox(gClient->GetRoot(), fMain, "Reset",
406 "Do you really want to reset the monitor histograms?",
407 kMBIconQuestion, kMBYes | kMBNo, &result);
408 if (result == kMBYes) {
409 fMonitorProcess->Reset();
413 //_____________________________________________________________________________
414 void AliMonitorControl::DoStartStop()
416 // called when the start/stop button was clicked
418 if (fStartButtonStatus) {
419 if (fMonitorProcess->GetStatus() == AliMonitorProcess::kStopped) {
420 fStartStopButton->SetBackgroundColor(fColorStop);
421 fStartStopButton->SetText(" &Stop ");
422 fStartButtonStatus = kFALSE;
423 fMonitorProcess->Run();
424 fStartStopButton->SetBackgroundColor(fColorStart);
425 fStartStopButton->SetText(" &Start ");
426 fStartButtonStatus = kTRUE;
430 if (fMonitorProcess->GetStatus() != AliMonitorProcess::kStopped) {
431 fMonitorProcess->Stop();
438 //_____________________________________________________________________________
439 Bool_t AliMonitorControl::HandleTimer(TTimer* timer)
441 // update the displayed information
444 if (fTerminating && fMonitorProcess->IsStopped()) {
445 delete fMonitorProcess;
446 gApplication->Terminate(0);
449 gSystem->ProcessEvents();
456 //_____________________________________________________________________________
457 void AliMonitorControl::UpdateStatus()
459 // update the displayed status information
463 if (fMonitorProcess->IsStopped()) {
464 fRunNumber->SetText("-");
465 fEventNumber->SetText("-/-/-");
466 fEvents->SetText("-");
467 fClients->SetText("-");
470 sprintf(text, "%d", fMonitorProcess->GetRunNumber());
471 fRunNumber->SetText(text);
472 sprintf(text, "%d/%d/%d", fMonitorProcess->GetEventPeriodNumber(),
473 fMonitorProcess->GetEventOrbitNumber(),
474 fMonitorProcess->GetEventBunchNumber());
475 fEventNumber->SetText(text);
476 sprintf(text, "%d", fMonitorProcess->GetNumberOfEvents());
477 fEvents->SetText(text);
478 sprintf(text, "%d", fMonitorProcess->GetNumberOfClients());
479 fClients->SetText(text);
482 const char* status = NULL;
483 switch (fMonitorProcess->GetStatus()) {
484 case AliMonitorProcess::kStopped:
485 status = "stopped"; break;
486 case AliMonitorProcess::kWaiting:
487 status = "waiting for new data"; break;
488 case AliMonitorProcess::kReading:
489 status = "reading raw data"; break;
490 case AliMonitorProcess::kRecTPC:
491 status = "running TPC reconstruction"; break;
492 case AliMonitorProcess::kRecITS:
493 status = "running ITS reconstruction"; break;
494 case AliMonitorProcess::kRecV0s:
495 status = "running V0 reconstruction"; break;
496 case AliMonitorProcess::kRecHLT:
497 status = "running HLT reconstruction"; break;
498 case AliMonitorProcess::kFilling:
499 status = "filling monitor histograms"; break;
500 case AliMonitorProcess::kUpdating:
501 status = "updating monitor histograms"; break;
502 case AliMonitorProcess::kWriting:
503 status = "writing monitor histograms"; break;
504 case AliMonitorProcess::kResetting:
505 status = "resetting monitor histograms"; break;
506 case AliMonitorProcess::kConnecting:
507 status = "checking for new clients"; break;
508 case AliMonitorProcess::kBroadcasting:
509 status = "broadcasting monitor histograms"; break;
512 if (fMonitorProcess->WillStop()) {
513 sprintf(text, "stopping... (%s)", status);
515 sprintf(text, "%s", status);
517 if (strcmp(text, fStatus->GetText()) != 0) {
518 fStatus->SetText(text);
522 if (fStartButtonStatus != fMonitorProcess->IsStopped()) {
523 fStartButtonStatus = fMonitorProcess->IsStopped();
524 if (fStartButtonStatus) {
525 fStartStopButton->SetBackgroundColor(fColorStart);
526 fStartStopButton->SetText(" &Start ");
528 fStartStopButton->SetBackgroundColor(fColorStop);
529 fStartStopButton->SetText(" &Stop ");