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), fSize(size)
52 // create a dialog for setting the size of the buffer for monitor histos
54 fBufferLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2);
55 fBufferLabel = new TGLabel(fFrame, "size of histogram buffer:");
56 fFrame->AddFrame(fBufferLabel, fBufferLayout);
57 fBufferEntry = new TGNumberEntry(fFrame, size, 2, -1,
58 TGNumberFormat::kNESInteger);
59 fBufferEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 1, 99);
60 fFrame->AddFrame(fBufferEntry, fBufferLayout);
64 fMain->SetWindowName("Buffer Size");
65 fMain->MapSubwindows();
67 gClient->WaitFor(fMain);
70 //_____________________________________________________________________________
71 AliMonitorControl::AliMonitorBufferDlg::~AliMonitorBufferDlg()
80 //_____________________________________________________________________________
81 void AliMonitorControl::AliMonitorBufferDlg::OnOkClicked()
83 fSize = fBufferEntry->GetIntNumber();
87 //_____________________________________________________________________________
88 AliMonitorControl::AliMonitorClientsDlg::AliMonitorClientsDlg(TObjArray* clients,
90 AliMonitorDialog(main, 450, 300, kFALSE)
92 // create a dialog to display the list of clients
95 fFrameLayout = new TGLayoutHints(kLHintsCenterX | kLHintsTop,
97 ((TGFrameElement*)(fMain->GetList()->First()))->fLayout = fFrameLayout;
98 fClientsLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
100 fClients = new TGTextView(fFrame, 420, 230);
101 fFrame->AddFrame(fClients, fClientsLayout);
104 const char* format = "%-30s%-20s%-8d";
105 sprintf(line, format, "name", "address", 0);
106 strncpy(&line[50], "port", 4);
107 fClients->AddLine(line);
108 for (Int_t i = 0; i < (Int_t) strlen(line); i++) line[i] = '-';
109 fClients->AddLine(line);
111 for (Int_t iClient = 0; iClient < clients->GetEntriesFast(); iClient++) {
112 TSocket* socket = (TSocket*) clients->At(iClient);
113 if (!socket) continue;
114 TInetAddress adr = socket->GetInetAddress();
115 sprintf(line, format,
116 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
117 fClients->AddLine(line);
120 fMain->SetWindowName("List of Clients");
121 fMain->MapSubwindows();
123 gClient->WaitFor(fMain);
126 //_____________________________________________________________________________
127 AliMonitorControl::AliMonitorClientsDlg::~AliMonitorClientsDlg()
131 delete fClientsLayout;
136 // constants for menu entries
137 enum {kMenuFileExit, kMenuFileAbort,
138 kMenuOptBuffer, kMenuOptClients,
139 kMenuHelpDoc, kMenuHelpAbout
143 //_____________________________________________________________________________
144 AliMonitorControl::AliMonitorControl(AliMonitorProcess* process)
146 // initialize the monitoring control window
148 fMonitorProcess = process;
152 gClient->GetColorByName("lightblue", fColorStatus);
153 gClient->GetColorByName("green", fColorStart);
154 gClient->GetColorByName("red", fColorStop);
157 fMain = new TGMainFrame(gClient->GetRoot(), 380, 200);
160 fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
162 fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
163 fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
165 fMenuFile = new TGPopupMenu(gClient->GetRoot());
166 fMenuFile->AddEntry("E&xit", kMenuFileExit);
167 fMenuFile->AddEntry("&Abort", kMenuFileAbort);
168 fMenuFile->DisableEntry(kMenuFileAbort);
169 fMenuFile->Connect("Activated(Int_t)", "AliMonitorControl", this,
170 "HandleMenu(Int_t)");
172 fMenuOptions = new TGPopupMenu(gClient->GetRoot());
173 fMenuOptions->AddEntry("&Histogram buffer...", kMenuOptBuffer);
174 fMenuOptions->AddEntry("List of &Clients...", kMenuOptClients);
175 fMenuOptions->Connect("Activated(Int_t)", "AliMonitorControl", this,
176 "HandleMenu(Int_t)");
178 fMenuHelp = new TGPopupMenu(gClient->GetRoot());
179 fMenuHelp->AddEntry("&Documentation...", kMenuHelpDoc);
180 fMenuHelp->AddEntry("A&bout...", kMenuHelpAbout);
181 fMenuHelp->Connect("Activated(Int_t)", "AliMonitorControl", this,
182 "HandleMenu(Int_t)");
184 fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
185 fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
186 fMenuBar->AddPopup("&Options", fMenuOptions, fMenuBarItemLayout);
187 fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
189 fMain->AddFrame(fMenuBar, fMenuBarLayout);
193 fFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
195 fFrame = new TGVerticalFrame(fMain, 0, 0, kChildFrame | kSunkenFrame);
196 fMain->AddFrame(fFrame, fFrameLayout);
198 fStatusLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 2, 2);
199 fStatusFrameLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2);
202 // run and event number
203 fStatus1Frame = new TGHorizontalFrame(fFrame, 0, 0);
204 fFrame->AddFrame(fStatus1Frame, fStatusFrameLayout);
206 fRunNumberLabel = new TGLabel(fStatus1Frame, "current run:");
207 fStatus1Frame->AddFrame(fRunNumberLabel, fStatusLayout);
208 fRunNumber = new TGTextEntry(fStatus1Frame, "-");
209 fRunNumber->Resize(60, fRunNumber->GetDefaultHeight());
210 fRunNumber->SetAlignment(kTextRight);
211 fRunNumber->SetEnabled(kFALSE);
212 fRunNumber->SetBackgroundColor(fColorStatus);
213 fStatus1Frame->AddFrame(fRunNumber, fStatusLayout);
215 fEventNumberLabel = new TGLabel(fStatus1Frame,
217 fStatus1Frame->AddFrame(fEventNumberLabel, fStatusLayout);
218 fEventNumber = new TGTextEntry(fStatus1Frame, "-/-/-");
219 fEventNumber->Resize(100, fEventNumber->GetDefaultHeight());
220 fEventNumber->SetAlignment(kTextRight);
221 fEventNumber->SetEnabled(kFALSE);
222 fEventNumber->SetBackgroundColor(fColorStatus);
223 fStatus1Frame->AddFrame(fEventNumber, fStatusLayout);
227 fStatus2Frame = new TGHorizontalFrame(fFrame, 0, 0);
228 fFrame->AddFrame(fStatus2Frame, fStatusFrameLayout);
230 fStatusLabel = new TGLabel(fStatus2Frame, "current status:");
231 fStatus2Frame->AddFrame(fStatusLabel, fStatusLayout);
232 fStatus = new TGTextEntry(fStatus2Frame, "stopped");
233 fStatus->Resize(250, fStatus->GetDefaultHeight());
234 fStatus->SetAlignment(kTextLeft);
235 fStatus->SetEnabled(kFALSE);
236 fStatus->SetBackgroundColor(fColorStatus);
237 fStatus2Frame->AddFrame(fStatus, fStatusLayout);
241 fStatus3Frame = new TGHorizontalFrame(fFrame, 0, 0);
242 fFrame->AddFrame(fStatus3Frame, fStatusFrameLayout);
244 fEventsLabel = new TGLabel(fStatus3Frame, "monitored events:");
245 fStatus3Frame->AddFrame(fEventsLabel, fStatusLayout);
246 fEvents = new TGTextEntry(fStatus3Frame, "-");
247 fEvents->Resize(60, fEvents->GetDefaultHeight());
248 fEvents->SetAlignment(kTextRight);
249 fEvents->SetEnabled(kFALSE);
250 fEvents->SetBackgroundColor(fColorStatus);
251 fStatus3Frame->AddFrame(fEvents, fStatusLayout);
253 fClientsLabel = new TGLabel(fStatus3Frame, " number of clients:");
254 fStatus3Frame->AddFrame(fClientsLabel, fStatusLayout);
255 fClients = new TGTextEntry(fStatus3Frame, "-");
256 fClients->Resize(40, fClients->GetDefaultHeight());
257 fClients->SetAlignment(kTextRight);
258 fClients->SetEnabled(kFALSE);
259 fClients->SetBackgroundColor(fColorStatus);
260 fStatus3Frame->AddFrame(fClients, fStatusLayout);
264 fButtonFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsBottom,
266 fButtonFrame = new TGHorizontalFrame(fMain, 0, 0);
267 fMain->AddFrame(fButtonFrame, fButtonFrameLayout);
269 fButtonLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
271 fResetButton = new TGTextButton(fButtonFrame, " &Reset ", 1);
272 fResetButton->Connect("Clicked()", "AliMonitorControl", this, "DoReset()");
273 fButtonFrame->AddFrame(fResetButton, fButtonLayout);
275 fStartStopButton = new TGTextButton(fButtonFrame, " &Start ", 2);
276 fStartStopButton->SetBackgroundColor(0x00FF00);
277 fStartStopButton->Connect("Clicked()", "AliMonitorControl", this,
279 fButtonFrame->AddFrame(fStartStopButton, fButtonLayout);
280 fStartButtonStatus = kTRUE;
284 fMain->SetWindowName("Monitor Process Control");
285 fMain->DontCallClose();
286 fMain->SetWMSize(fMain->GetWidth(), fMain->GetHeight());
287 fMain->SetWMSizeHints(fMain->GetWidth(), fMain->GetHeight(),
288 fMain->GetWidth(), fMain->GetHeight(), 0, 0);
289 fMain->SetWMPosition(100, 100);
290 fMain->MapSubwindows();
295 fTerminating = kFALSE;
297 fTimer = new TTimer(this, 10, kTRUE);
301 //_____________________________________________________________________________
302 AliMonitorControl::AliMonitorControl(const AliMonitorControl& control) :
305 AliFatal("copy constructor not implemented");
308 //_____________________________________________________________________________
309 AliMonitorControl& AliMonitorControl::operator = (const AliMonitorControl&
312 AliFatal("assignment operator not implemented");
316 //_____________________________________________________________________________
317 AliMonitorControl::~AliMonitorControl()
321 delete fMenuBarLayout;
322 delete fMenuBarItemLayout;
323 delete fMenuBarHelpLayout;
331 delete fStatusLayout;
332 delete fStatusFrameLayout;
334 delete fStatus1Frame;
335 delete fRunNumberLabel;
337 delete fEventNumberLabel;
340 delete fStatus2Frame;
344 delete fStatus3Frame;
347 delete fClientsLabel;
350 delete fButtonFrameLayout;
352 delete fButtonLayout;
354 delete fStartStopButton;
360 //_____________________________________________________________________________
361 void AliMonitorControl::HandleMenu(Int_t id)
363 // called when a menu item was selected
367 case kMenuFileExit: {
369 new TGMsgBox(gClient->GetRoot(), fMain, "Exit",
370 "Do you really want to terminate the monitor process?",
371 kMBIconQuestion, kMBYes | kMBNo, &result);
372 if (result == kMBYes) {
373 fMenuFile->EnableEntry(kMenuFileAbort);
374 if (fMonitorProcess->IsStopped()) {
375 delete fMonitorProcess;
376 gApplication->Terminate(0);
378 fMonitorProcess->Stop();
379 fTerminating = kTRUE;
387 case kMenuOptBuffer: {
388 Int_t size = AliMonitorHisto::GetNHistosMax();
389 new AliMonitorBufferDlg(size, fMain);
391 AliMonitorHisto::SetNHistosMax(size);
395 case kMenuOptClients: {
396 new AliMonitorClientsDlg(fMonitorProcess->GetListOfClients(), fMain);
400 case kMenuHelpAbout: {
403 sprintf(text, "AliMonitorControl $Revision$\nrunning\n"
404 "AliMonitorProcess %s", AliMonitorProcess::GetRevision());
405 new TGMsgBox(gClient->GetRoot(), fMain,
406 "About", text, kMBIconAsterisk, kMBOk, &result);
412 new TGMsgBox(gClient->GetRoot(), fMain,
413 "AliMonitorControl", "not yet implemented",
414 kMBIconExclamation, kMBOk, &result);
419 //_____________________________________________________________________________
420 void AliMonitorControl::DoReset()
422 // called when the reset button was clicked
425 new TGMsgBox(gClient->GetRoot(), fMain, "Reset",
426 "Do you really want to reset the monitor histograms?",
427 kMBIconQuestion, kMBYes | kMBNo, &result);
428 if (result == kMBYes) {
429 fMonitorProcess->Reset();
433 //_____________________________________________________________________________
434 void AliMonitorControl::DoStartStop()
436 // called when the start/stop button was clicked
438 if (fStartButtonStatus) {
439 if (fMonitorProcess->GetStatus() == AliMonitorProcess::kStopped) {
440 fStartStopButton->SetBackgroundColor(fColorStop);
441 fStartStopButton->SetText(" &Stop ");
442 fStartButtonStatus = kFALSE;
443 fMonitorProcess->Run();
444 fStartStopButton->SetBackgroundColor(fColorStart);
445 fStartStopButton->SetText(" &Start ");
446 fStartButtonStatus = kTRUE;
450 if (fMonitorProcess->GetStatus() != AliMonitorProcess::kStopped) {
451 fMonitorProcess->Stop();
458 //_____________________________________________________________________________
459 Bool_t AliMonitorControl::HandleTimer(TTimer* timer)
461 // update the displayed information
464 if (fTerminating && fMonitorProcess->IsStopped()) {
465 delete fMonitorProcess;
466 gApplication->Terminate(0);
469 gSystem->ProcessEvents();
476 //_____________________________________________________________________________
477 void AliMonitorControl::UpdateStatus()
479 // update the displayed status information
483 if (fMonitorProcess->IsStopped()) {
484 fRunNumber->SetText("-");
485 fEventNumber->SetText("-/-/-");
486 fEvents->SetText("-");
487 fClients->SetText("-");
490 sprintf(text, "%d", fMonitorProcess->GetRunNumber());
491 fRunNumber->SetText(text);
492 sprintf(text, "%d/%d/%d", fMonitorProcess->GetEventPeriodNumber(),
493 fMonitorProcess->GetEventOrbitNumber(),
494 fMonitorProcess->GetEventBunchNumber());
495 fEventNumber->SetText(text);
496 sprintf(text, "%d", fMonitorProcess->GetNumberOfEvents());
497 fEvents->SetText(text);
498 sprintf(text, "%d", fMonitorProcess->GetNumberOfClients());
499 fClients->SetText(text);
502 const char* status = NULL;
503 switch (fMonitorProcess->GetStatus()) {
504 case AliMonitorProcess::kStopped:
505 status = "stopped"; break;
506 case AliMonitorProcess::kWaiting:
507 status = "waiting for new data"; break;
508 case AliMonitorProcess::kReading:
509 status = "reading raw data"; break;
510 case AliMonitorProcess::kRecTPC:
511 status = "running TPC reconstruction"; break;
512 case AliMonitorProcess::kRecITS:
513 status = "running ITS reconstruction"; break;
514 case AliMonitorProcess::kRecV0s:
515 status = "running V0 reconstruction"; break;
516 case AliMonitorProcess::kRecHLT:
517 status = "running HLT reconstruction"; break;
518 case AliMonitorProcess::kFilling:
519 status = "filling monitor histograms"; break;
520 case AliMonitorProcess::kUpdating:
521 status = "updating monitor histograms"; break;
522 case AliMonitorProcess::kWriting:
523 status = "writing monitor histograms"; break;
524 case AliMonitorProcess::kResetting:
525 status = "resetting monitor histograms"; break;
526 case AliMonitorProcess::kConnecting:
527 status = "checking for new clients"; break;
528 case AliMonitorProcess::kBroadcasting:
529 status = "broadcasting monitor histograms"; break;
532 if (fMonitorProcess->WillStop()) {
533 sprintf(text, "stopping... (%s)", status);
535 sprintf(text, "%s", status);
537 if (strcmp(text, fStatus->GetText()) != 0) {
538 fStatus->SetText(text);
542 if (fStartButtonStatus != fMonitorProcess->IsStopped()) {
543 fStartButtonStatus = fMonitorProcess->IsStopped();
544 if (fStartButtonStatus) {
545 fStartStopButton->SetBackgroundColor(fColorStart);
546 fStartStopButton->SetText(" &Start ");
548 fStartStopButton->SetBackgroundColor(fColorStop);
549 fStartStopButton->SetText(" &Stop ");