Smaller timeout (C.Cheshkov)
[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"
27#include "AliMonitorDialog.h"
28#include <TGNumberEntry.h>
29#include <TGTextView.h>
30#include <TGMsgBox.h>
31#include <TSystem.h>
32#include <TROOT.h>
33
34
35ClassImp(AliMonitorControl)
36
37
38//_____________________________________________________________________________
39class AliMonitorBufferDlg : public AliMonitorDialog {
40
41public:
42 AliMonitorBufferDlg(Int_t& size, TGFrame* main);
43 virtual ~AliMonitorBufferDlg();
44
45 virtual void OnOkClicked();
46
47private:
48 TGLayoutHints* fBufferLayout;
49 TGLabel* fBufferLabel;
50 TGNumberEntry* fBufferEntry;
51
52 Int_t& fSize;
53};
54
55
56//_____________________________________________________________________________
57AliMonitorBufferDlg::AliMonitorBufferDlg(Int_t& size, TGFrame* main) :
58 AliMonitorDialog(main, 250, 80), fSize(size)
59{
60// create a dialog for setting the size of the buffer for monitor histos
61
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);
69
70 fSize = -1;
71
72 fMain->SetWindowName("Buffer Size");
73 fMain->MapSubwindows();
74 fMain->Layout();
75 gClient->WaitFor(fMain);
76}
77
78//_____________________________________________________________________________
79AliMonitorBufferDlg::~AliMonitorBufferDlg()
80{
81// clean up
82
83 delete fBufferLabel;
84 delete fBufferLayout;
85 delete fBufferEntry;
86}
87
88//_____________________________________________________________________________
89void AliMonitorBufferDlg::OnOkClicked()
90{
91 fSize = fBufferEntry->GetIntNumber();
92}
93
94
95//_____________________________________________________________________________
96class AliMonitorClientsDlg : public AliMonitorDialog {
97
98public:
99 AliMonitorClientsDlg(TObjArray* clients, TGFrame* main);
100 virtual ~AliMonitorClientsDlg();
101
102private:
103 TGLayoutHints* fClientsLayout;
104 TGTextView* fClients;
105};
106
107
108//_____________________________________________________________________________
109AliMonitorClientsDlg::AliMonitorClientsDlg(TObjArray* clients, TGFrame* main) :
110 AliMonitorDialog(main, 450, 300, kFALSE)
111{
112// create a dialog to display the list of clients
113
114 delete fFrameLayout;
115 fFrameLayout = new TGLayoutHints(kLHintsCenterX | kLHintsTop,
116 10, 10, 15, 15);
117 ((TGFrameElement*)(fMain->GetList()->First()))->fLayout = fFrameLayout;
118 fClientsLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
119 0, 0, 0, 0);
120 fClients = new TGTextView(fFrame, 420, 230);
121 fFrame->AddFrame(fClients, fClientsLayout);
122
123 char line[256];
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);
130
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);
138 }
139
140 fMain->SetWindowName("List of Clients");
141 fMain->MapSubwindows();
142 fMain->Layout();
143 gClient->WaitFor(fMain);
144}
145
146//_____________________________________________________________________________
147AliMonitorClientsDlg::~AliMonitorClientsDlg()
148{
149// clean up
150
151 delete fClientsLayout;
152 delete fClients;
153}
154
155
156// constants for menu entries
157enum {kMenuFileExit, kMenuFileAbort,
158 kMenuOptBuffer, kMenuOptClients,
159 kMenuHelpDoc, kMenuHelpAbout
160};
161
162
163//_____________________________________________________________________________
164AliMonitorControl::AliMonitorControl(AliMonitorProcess* process)
165{
166// initialize the monitoring control window
167
168 fMonitorProcess = process;
169
170
171 // colors
172 gClient->GetColorByName("lightblue", fColorStatus);
173 gClient->GetColorByName("green", fColorStart);
174 gClient->GetColorByName("red", fColorStop);
175
176 // main window
177 fMain = new TGMainFrame(gClient->GetRoot(), 380, 200);
178
179 // menu bar
180 fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
181 0, 0, 1, 1);
182 fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
183 fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
184
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)");
191
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)");
197
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)");
203
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);
208
209 fMain->AddFrame(fMenuBar, fMenuBarLayout);
210
211
212 // status frame
213 fFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
214 2, 2, 2, 2);
215 fFrame = new TGVerticalFrame(fMain, 0, 0, kChildFrame | kSunkenFrame);
216 fMain->AddFrame(fFrame, fFrameLayout);
217
218 fStatusLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 2, 2);
219 fStatusFrameLayout = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2);
220
221
222 // run and event number
223 fStatus1Frame = new TGHorizontalFrame(fFrame, 0, 0);
224 fFrame->AddFrame(fStatus1Frame, fStatusFrameLayout);
225
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);
234
235 fEventNumberLabel = new TGLabel(fStatus1Frame,
236 " event:");
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);
244
245
246 // process status
247 fStatus2Frame = new TGHorizontalFrame(fFrame, 0, 0);
248 fFrame->AddFrame(fStatus2Frame, fStatusFrameLayout);
249
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);
258
259
260 // process status
261 fStatus3Frame = new TGHorizontalFrame(fFrame, 0, 0);
262 fFrame->AddFrame(fStatus3Frame, fStatusFrameLayout);
263
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);
272
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);
281
282
283 // buttons
284 fButtonFrameLayout = new TGLayoutHints(kLHintsExpandX | kLHintsBottom,
285 50, 50, 10, 10);
286 fButtonFrame = new TGHorizontalFrame(fMain, 0, 0);
287 fMain->AddFrame(fButtonFrame, fButtonFrameLayout);
288
289 fButtonLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
290 2, 2, 2, 2);
291 fResetButton = new TGTextButton(fButtonFrame, " &Reset ", 1);
292 fResetButton->Connect("Clicked()", "AliMonitorControl", this, "DoReset()");
293 fButtonFrame->AddFrame(fResetButton, fButtonLayout);
294
295 fStartStopButton = new TGTextButton(fButtonFrame, " &Start ", 2);
296 fStartStopButton->SetBackgroundColor(0x00FF00);
297 fStartStopButton->Connect("Clicked()", "AliMonitorControl", this,
298 "DoStartStop()");
299 fButtonFrame->AddFrame(fStartStopButton, fButtonLayout);
300 fStartButtonStatus = kTRUE;
301
302
303 // main window
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();
311 fMain->Layout();
312 fMain->MapWindow();
313
314
315 fTerminating = kFALSE;
316
19fa3b1b 317 fTimer = new TTimer(this, 10, kTRUE);
04fa961a 318 fTimer->TurnOn();
319}
320
321//_____________________________________________________________________________
322AliMonitorControl::~AliMonitorControl()
323{
324// clean up
325
326 delete fMenuBarLayout;
327 delete fMenuBarItemLayout;
328 delete fMenuBarHelpLayout;
329 delete fMenuFile;
330 delete fMenuOptions;
331 delete fMenuHelp;
332 delete fMenuBar;
333
334 delete fFrameLayout;
335 delete fFrame;
336 delete fStatusLayout;
337 delete fStatusFrameLayout;
338
339 delete fStatus1Frame;
340 delete fRunNumberLabel;
341 delete fRunNumber;
342 delete fEventNumberLabel;
343 delete fEventNumber;
344
345 delete fStatus2Frame;
346 delete fStatusLabel;
347 delete fStatus;
348
349 delete fStatus3Frame;
350 delete fEventsLabel;
351 delete fEvents;
352 delete fClientsLabel;
353 delete fClients;
354
355 delete fButtonFrameLayout;
356 delete fButtonFrame;
357 delete fButtonLayout;
358 delete fResetButton;
359 delete fStartStopButton;
360
361 delete fTimer;
362}
363
364
365//_____________________________________________________________________________
366void AliMonitorControl::HandleMenu(Int_t id)
367{
368// called when a menu item was selected
369
370 switch (id) {
371
372 case kMenuFileExit: {
373 Int_t result;
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;
382 }
383 break;
384 }
385
386 case kMenuFileAbort:
387 exit(1);
388
389 case kMenuOptBuffer: {
390 Int_t size = AliMonitorHisto::GetNHistosMax();
391 new AliMonitorBufferDlg(size, fMain);
392 if (size < 0) break;
393 AliMonitorHisto::SetNHistosMax(size);
394 break;
395 }
396
397 case kMenuOptClients: {
398 new AliMonitorClientsDlg(fMonitorProcess->GetListOfClients(), fMain);
399 break;
400 }
401
402 case kMenuHelpAbout: {
403 Int_t result;
404 char text[256];
405 sprintf(text, "AliMonitorControl $Revision$\nrunning\n"
406 "AliMonitorProcess %s", AliMonitorProcess::GetRevision());
407 new TGMsgBox(gClient->GetRoot(), fMain,
408 "About", text, kMBIconAsterisk, kMBOk, &result);
409 break;
410 }
411
412 default: {
413 Int_t result;
414 new TGMsgBox(gClient->GetRoot(), fMain,
415 "AliMonitorControl", "not yet implemented",
416 kMBIconExclamation, kMBOk, &result);
417 }
418 }
419}
420
421//_____________________________________________________________________________
422void AliMonitorControl::DoReset()
423{
424// called when the reset button was clicked
425
426 Int_t result;
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();
432 }
433}
434
435//_____________________________________________________________________________
436void AliMonitorControl::DoStartStop()
437{
438// called when the start/stop button was clicked
439
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;
449 }
450
451 } else {
452 if (fMonitorProcess->GetStatus() != AliMonitorProcess::kStopped) {
453 fMonitorProcess->Stop();
454 }
455 }
456}
457
458
459
460//_____________________________________________________________________________
461Bool_t AliMonitorControl::HandleTimer(TTimer* timer)
462{
463// update the displayed information
464
465 timer->TurnOff();
466 if (fTerminating && fMonitorProcess->IsStopped()) exit(0);
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