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