New split libs
[u/mrichter/AliRoot.git] / MONITOR / AliMonitorControl.cxx
CommitLineData
04fa961a 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// This class provides a graphical user interface for the monitor process //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24
25#include "AliMonitorControl.h"
26#include "AliMonitorHisto.h"
04fa961a 27#include <TGNumberEntry.h>
28#include <TGTextView.h>
29#include <TGMsgBox.h>
30#include <TSystem.h>
c4bd737c 31#include <TSocket.h>
32#include <TGFrame.h>
33#include <TGMenu.h>
34#include <TGButton.h>
35#include <TGLabel.h>
36#include <TGTextEntry.h>
37#include <TTimer.h>
46c62a26 38#include <TApplication.h>
c4bd737c 39#include "AliMonitorProcess.h"
04fa961a 40
41
42ClassImp(AliMonitorControl)
43
44
04fa961a 45
46//_____________________________________________________________________________
c4bd737c 47AliMonitorControl::AliMonitorBufferDlg::AliMonitorBufferDlg(Int_t& size,
48 TGFrame* main) :
04fa961a 49 AliMonitorDialog(main, 250, 80), fSize(size)
50{
51// create a dialog for setting the size of the buffer for monitor histos
52
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);
60
61 fSize = -1;
62
63 fMain->SetWindowName("Buffer Size");
64 fMain->MapSubwindows();
65 fMain->Layout();
66 gClient->WaitFor(fMain);
67}
68
69//_____________________________________________________________________________
c4bd737c 70AliMonitorControl::AliMonitorBufferDlg::~AliMonitorBufferDlg()
04fa961a 71{
72// clean up
73
74 delete fBufferLabel;
75 delete fBufferLayout;
76 delete fBufferEntry;
77}
78
79//_____________________________________________________________________________
c4bd737c 80void AliMonitorControl::AliMonitorBufferDlg::OnOkClicked()
04fa961a 81{
82 fSize = fBufferEntry->GetIntNumber();
83}
84
85
86//_____________________________________________________________________________
c4bd737c 87AliMonitorControl::AliMonitorClientsDlg::AliMonitorClientsDlg(TObjArray* clients,
88 TGFrame* main) :
04fa961a 89 AliMonitorDialog(main, 450, 300, kFALSE)
90{
91// create a dialog to display the list of clients
92
93 delete fFrameLayout;
94 fFrameLayout = new TGLayoutHints(kLHintsCenterX | kLHintsTop,
95 10, 10, 15, 15);
96 ((TGFrameElement*)(fMain->GetList()->First()))->fLayout = fFrameLayout;
97 fClientsLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
98 0, 0, 0, 0);
99 fClients = new TGTextView(fFrame, 420, 230);
100 fFrame->AddFrame(fClients, fClientsLayout);
101
102 char line[256];
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);
109
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);
117 }
118
119 fMain->SetWindowName("List of Clients");
120 fMain->MapSubwindows();
121 fMain->Layout();
122 gClient->WaitFor(fMain);
123}
124
125//_____________________________________________________________________________
c4bd737c 126AliMonitorControl::AliMonitorClientsDlg::~AliMonitorClientsDlg()
04fa961a 127{
128// clean up
129
130 delete fClientsLayout;
131 delete fClients;
132}
133
134
135// constants for menu entries
136enum {kMenuFileExit, kMenuFileAbort,
137 kMenuOptBuffer, kMenuOptClients,
138 kMenuHelpDoc, kMenuHelpAbout
139};
140
141
142//_____________________________________________________________________________
143AliMonitorControl::AliMonitorControl(AliMonitorProcess* process)
144{
145// initialize the monitoring control window
146
147 fMonitorProcess = process;
148
149
150 // colors
151 gClient->GetColorByName("lightblue", fColorStatus);
152 gClient->GetColorByName("green", fColorStart);
153 gClient->GetColorByName("red", fColorStop);
154
155 // main window
156 fMain = new TGMainFrame(gClient->GetRoot(), 380, 200);
157
158 // menu bar
159 fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
160 0, 0, 1, 1);
161 fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
162 fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
163
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)");
170
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)");
176
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)");
182
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);
187
188 fMain->AddFrame(fMenuBar, fMenuBarLayout);
189
190
191 // status frame
192 fFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
193 2, 2, 2, 2);
194 fFrame = new TGVerticalFrame(fMain, 0, 0, kChildFrame | kSunkenFrame);
195 fMain->AddFrame(fFrame, fFrameLayout);
196
197 fStatusLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 2, 2);
198 fStatusFrameLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2);
199
200
201 // run and event number
202 fStatus1Frame = new TGHorizontalFrame(fFrame, 0, 0);
203 fFrame->AddFrame(fStatus1Frame, fStatusFrameLayout);
204
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);
213
214 fEventNumberLabel = new TGLabel(fStatus1Frame,
215 " event:");
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);
223
224
225 // process status
226 fStatus2Frame = new TGHorizontalFrame(fFrame, 0, 0);
227 fFrame->AddFrame(fStatus2Frame, fStatusFrameLayout);
228
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);
237
238
239 // process status
240 fStatus3Frame = new TGHorizontalFrame(fFrame, 0, 0);
241 fFrame->AddFrame(fStatus3Frame, fStatusFrameLayout);
242
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);
251
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);
260
261
262 // buttons
263 fButtonFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsBottom,
264 50, 50, 10, 10);
265 fButtonFrame = new TGHorizontalFrame(fMain, 0, 0);
266 fMain->AddFrame(fButtonFrame, fButtonFrameLayout);
267
268 fButtonLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
269 2, 2, 2, 2);
270 fResetButton = new TGTextButton(fButtonFrame, " &Reset ", 1);
271 fResetButton->Connect("Clicked()", "AliMonitorControl", this, "DoReset()");
272 fButtonFrame->AddFrame(fResetButton, fButtonLayout);
273
274 fStartStopButton = new TGTextButton(fButtonFrame, " &Start ", 2);
275 fStartStopButton->SetBackgroundColor(0x00FF00);
276 fStartStopButton->Connect("Clicked()", "AliMonitorControl", this,
277 "DoStartStop()");
278 fButtonFrame->AddFrame(fStartStopButton, fButtonLayout);
279 fStartButtonStatus = kTRUE;
280
281
282 // main window
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();
290 fMain->Layout();
291 fMain->MapWindow();
292
293
294 fTerminating = kFALSE;
295
19fa3b1b 296 fTimer = new TTimer(this, 10, kTRUE);
04fa961a 297 fTimer->TurnOn();
298}
299
300//_____________________________________________________________________________
c4bd737c 301AliMonitorControl::AliMonitorControl(const AliMonitorControl& control) :
302 TObject(control)
303{
304 Fatal("AliMonitorControl", "copy constructor not implemented");
305}
306
307//_____________________________________________________________________________
308AliMonitorControl& AliMonitorControl::operator = (const AliMonitorControl&
309 /*control*/)
310{
311 Fatal("operator =", "assignment operator not implemented");
312 return *this;
313}
314
315//_____________________________________________________________________________
04fa961a 316AliMonitorControl::~AliMonitorControl()
317{
318// clean up
319
320 delete fMenuBarLayout;
321 delete fMenuBarItemLayout;
322 delete fMenuBarHelpLayout;
323 delete fMenuFile;
324 delete fMenuOptions;
325 delete fMenuHelp;
326 delete fMenuBar;
327
328 delete fFrameLayout;
329 delete fFrame;
330 delete fStatusLayout;
331 delete fStatusFrameLayout;
332
333 delete fStatus1Frame;
334 delete fRunNumberLabel;
335 delete fRunNumber;
336 delete fEventNumberLabel;
337 delete fEventNumber;
338
339 delete fStatus2Frame;
340 delete fStatusLabel;
341 delete fStatus;
342
343 delete fStatus3Frame;
344 delete fEventsLabel;
345 delete fEvents;
346 delete fClientsLabel;
347 delete fClients;
348
349 delete fButtonFrameLayout;
350 delete fButtonFrame;
351 delete fButtonLayout;
352 delete fResetButton;
353 delete fStartStopButton;
354
355 delete fTimer;
356}
357
358
359//_____________________________________________________________________________
360void AliMonitorControl::HandleMenu(Int_t id)
361{
362// called when a menu item was selected
363
364 switch (id) {
365
366 case kMenuFileExit: {
367 Int_t result;
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);
46c62a26 373 if (fMonitorProcess->IsStopped()) {
374 delete fMonitorProcess;
375 gApplication->Terminate(0);
376 }
04fa961a 377 fMonitorProcess->Stop();
378 fTerminating = kTRUE;
379 }
380 break;
381 }
382
383 case kMenuFileAbort:
384 exit(1);
385
386 case kMenuOptBuffer: {
387 Int_t size = AliMonitorHisto::GetNHistosMax();
388 new AliMonitorBufferDlg(size, fMain);
389 if (size < 0) break;
390 AliMonitorHisto::SetNHistosMax(size);
391 break;
392 }
393
394 case kMenuOptClients: {
395 new AliMonitorClientsDlg(fMonitorProcess->GetListOfClients(), fMain);
396 break;
397 }
398
399 case kMenuHelpAbout: {
400 Int_t result;
401 char text[256];
402 sprintf(text, "AliMonitorControl $Revision$\nrunning\n"
403 "AliMonitorProcess %s", AliMonitorProcess::GetRevision());
404 new TGMsgBox(gClient->GetRoot(), fMain,
405 "About", text, kMBIconAsterisk, kMBOk, &result);
406 break;
407 }
408
409 default: {
410 Int_t result;
411 new TGMsgBox(gClient->GetRoot(), fMain,
412 "AliMonitorControl", "not yet implemented",
413 kMBIconExclamation, kMBOk, &result);
414 }
415 }
416}
417
418//_____________________________________________________________________________
419void AliMonitorControl::DoReset()
420{
421// called when the reset button was clicked
422
423 Int_t result;
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();
429 }
430}
431
432//_____________________________________________________________________________
433void AliMonitorControl::DoStartStop()
434{
435// called when the start/stop button was clicked
436
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;
446 }
447
448 } else {
449 if (fMonitorProcess->GetStatus() != AliMonitorProcess::kStopped) {
450 fMonitorProcess->Stop();
451 }
452 }
453}
454
455
456
457//_____________________________________________________________________________
458Bool_t AliMonitorControl::HandleTimer(TTimer* timer)
459{
460// update the displayed information
461
462 timer->TurnOff();
46c62a26 463 if (fTerminating && fMonitorProcess->IsStopped()) {
464 delete fMonitorProcess;
465 gApplication->Terminate(0);
466 }
04fa961a 467 UpdateStatus();
468 gSystem->ProcessEvents();
469 timer->TurnOn();
19fa3b1b 470
04fa961a 471 return kFALSE;
472}
473
474
475//_____________________________________________________________________________
476void AliMonitorControl::UpdateStatus()
477{
478// update the displayed status information
479
480 char text[256];
481
482 if (fMonitorProcess->IsStopped()) {
483 fRunNumber->SetText("-");
484 fEventNumber->SetText("-/-/-");
485 fEvents->SetText("-");
486 fClients->SetText("-");
487
488 } else {
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);
499 }
500
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;
97d6eb66 515 case AliMonitorProcess::kRecHLT:
516 status = "running HLT reconstruction"; break;
04fa961a 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;
529 }
530
531 if (fMonitorProcess->WillStop()) {
532 sprintf(text, "stopping... (%s)", status);
533 } else {
534 sprintf(text, "%s", status);
535 }
536 if (strcmp(text, fStatus->GetText()) != 0) {
537 fStatus->SetText(text);
538 }
539
540 /*
541 if (fStartButtonStatus != fMonitorProcess->IsStopped()) {
542 fStartButtonStatus = fMonitorProcess->IsStopped();
543 if (fStartButtonStatus) {
544 fStartStopButton->SetBackgroundColor(fColorStart);
545 fStartStopButton->SetText(" &Start ");
546 } else {
547 fStartStopButton->SetBackgroundColor(fColorStop);
548 fStartStopButton->SetText(" &Stop ");
549 }
550 }
551 */
552}
553