]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveEventManagerEditor.cxx
Take the constant part out of the if statement
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveEventManagerEditor.cxx
CommitLineData
5655e9ce 1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#include "AliEveEventManagerEditor.h"
11#include "AliEveEventManager.h"
01ca7d6f 12#include "AliEveConfigManager.h"
5655e9ce 13
b3b7b8d3 14#include <AliESDEvent.h>
15
16#include <TVirtualPad.h>
5655e9ce 17#include "TColor.h"
18
319f3084 19#include <TEveGValuators.h>
20#include <TGButton.h>
21#include <TGTextView.h>
22#include <TGLabel.h>
5655e9ce 23
fa6aa785 24#include "Riostream.h"
25
01ca7d6f 26#ifdef ZMQ
27#include "AliStorageAdministratorPanelListEvents.h"
28#include "AliStorageAdministratorPanelMarkEvent.h"
29#endif
30
5655e9ce 31//______________________________________________________________________________
32// GUI editor for AliEveEventManager.
33//
34
f65f2d99 35using std::ofstream;
36using std::ios;
66f33767 37using std::cout;
38using std::endl;
39
5655e9ce 40ClassImp(AliEveEventManagerEditor)
41
42//______________________________________________________________________________
43AliEveEventManagerEditor::AliEveEventManagerEditor(const TGWindow *p, Int_t width, Int_t height,
80547f2d 44 UInt_t options, Pixel_t back) :
5655e9ce 45 TGedFrame(p, width, height, options | kVerticalFrame, back),
319f3084 46 fM(0),
fa6aa785 47 fDumpEventInfo(0),
319f3084 48 fEventInfo(0)
5655e9ce 49{
50 // Constructor.
51
52 MakeTitle("AliEveEventManager");
53
319f3084 54 {
55 TGHorizontalFrame* f = new TGHorizontalFrame(this);
fa6aa785 56 fDumpEventInfo = new TGTextButton(f, "Dump Event Info");
57 fDumpEventInfo->SetToolTipText("Append information about current event to event_info.txt file.");
58 fDumpEventInfo->SetWidth(120);
59 fDumpEventInfo->ChangeOptions(fDumpEventInfo->GetOptions() | kFixedWidth);
60 f->AddFrame(fDumpEventInfo, new TGLayoutHints(kLHintsNormal, 4,0,0,0));
61 fDumpEventInfo->Connect("Clicked()",
62 "AliEveEventManagerEditor", this, "DumpEventInfo()");
319f3084 63 AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
64 }
319f3084 65 {
66 TGVerticalFrame* f = new TGVerticalFrame(this);
67
68 TGLabel *eventInfoLabel = new TGLabel(f, "Event Information:");
69 f->AddFrame(eventInfoLabel, new TGLayoutHints(kLHintsNormal, 0,0,6,2));
70
ec835ab5 71 fEventInfo = new TGTextView(f, 200, 300);
319f3084 72 f->AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
73
74 AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
75 }
5655e9ce 76}
77
78/******************************************************************************/
79
80547f2d 80//______________________________________________________________________________
5655e9ce 81void AliEveEventManagerEditor::SetModel(TObject* obj)
82{
83 // Set model object.
84
04a6d27f 85 fM = static_cast<AliEveEventManager*>(obj);
5655e9ce 86
12365217 87 fEventInfo->LoadBuffer(fM->GetEventInfoVertical());
5655e9ce 88}
89
90/******************************************************************************/
91
319f3084 92//______________________________________________________________________________
fa6aa785 93void AliEveEventManagerEditor::DumpEventInfo()
319f3084 94{
fa6aa785 95 // Dump event-info into event_info.txt.
96 // The info is appended into the file.
97
98 ofstream f("event_info.txt", ios::out | ios::app);
99
100 f << "================================================================================\n\n";
101 f << fM->GetEventInfoHorizontal() << std::endl << std::endl;
ca49b003 102
fa6aa785 103 f.close();
ca49b003 104}
f76c9e9b 105
106
80547f2d 107//==============================================================================
f76c9e9b 108// AliEveEventManagerWindow
80547f2d 109//==============================================================================
f76c9e9b 110
111//______________________________________________________________________________
112//
113// Horizontal GUI for AliEveEventManager, to be placed in the
114// bottom part of ROOT browser.
115
116ClassImp(AliEveEventManagerWindow)
117
4d62585e 118AliEveEventManagerWindow::AliEveEventManagerWindow(AliEveEventManager* mgr) :
12365217 119 TGMainFrame(gClient->GetRoot(), 400, 100, kVerticalFrame),
4d62585e 120 fM (mgr),
80547f2d 121 fFirstEvent (0),
122 fPrevEvent (0),
123 fNextEvent (0),
124 fLastEvent (0),
125 fRefresh (0),
126 fEventId (0),
127 fInfoLabel (0),
128 fAutoLoad (0),
626a3158 129 fLoopMarked (0),
80547f2d 130 fAutoLoadTime (0),
969d3431 131 fTrigSel (0),
80547f2d 132 fEventInfo (0)
f76c9e9b 133{
134 // Constructor.
135
488869c1 136 const TString cls("AliEveEventManagerWindow");
80547f2d 137 TGTextButton *b = 0;
f76c9e9b 138 {
139 Int_t width = 50;
140
141 TGHorizontalFrame* f = new TGHorizontalFrame(this);
80547f2d 142 AddFrame(f, new TGLayoutHints(kLHintsExpandX, 0,0,2,2));
143
144 fFirstEvent = b = MkTxtButton(f, "First", width);
145 b->Connect("Clicked()", cls, this, "DoFirstEvent()");
146 fPrevEvent = b = MkTxtButton(f, "Prev", width);
147 b->Connect("Clicked()", cls, this, "DoPrevEvent()");
f76c9e9b 148
149 fEventId = new TGNumberEntry(f, 0, 5, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
150 TGNumberFormat::kNELLimitMinMax, 0, 10000);
151 f->AddFrame(fEventId, new TGLayoutHints(kLHintsNormal, 10, 5, 0, 0));
80547f2d 152 fEventId->Connect("ValueSet(Long_t)", cls, this, "DoSetEvent()");
f76c9e9b 153 fInfoLabel = new TGLabel(f);
154 f->AddFrame(fInfoLabel, new TGLayoutHints(kLHintsNormal, 5, 10, 4, 0));
155
80547f2d 156 fNextEvent = b = MkTxtButton(f, "Next", width);
157 b->Connect("Clicked()", cls, this, "DoNextEvent()");
158 fLastEvent = b = MkTxtButton(f, "Last", width);
159 b->Connect("Clicked()", cls, this, "DoLastEvent()");
164d3d29 160 fMarkEvent = b = MkTxtButton(f, "Mark", width);
161 b->Connect("Clicked()", cls, this, "DoMarkEvent()");
7f97b015 162 fRestartReco = b = MkTxtButton(f, "Restart reco", 2*width);
163 b->Connect("Clicked()", cls, this, "DoRestartReco()");
164 fRestartManager = b = MkTxtButton(f, "Restart manager", 2*width);
165 b->Connect("Clicked()", cls, this, "DoRestartManager()");
166
167
80547f2d 168 MkLabel(f, "||", 0, 8, 8);
169
170 fRefresh = b = MkTxtButton(f, "Refresh", width + 8);
171 b->Connect("Clicked()",cls, this, "DoRefresh()");
172
173 MkLabel(f, "||", 0, 8, 8);
174
175 fAutoLoad = new TGCheckButton(f, "Autoload");
176 f->AddFrame(fAutoLoad, new TGLayoutHints(kLHintsLeft, 0, 4, 3, 0));
177 fAutoLoad->SetToolTipText("Automatic event loading.");
178 fAutoLoad->Connect("Toggled(Bool_t)", cls, this, "DoSetAutoLoad()");
179
626a3158 180 fLoopMarked = new TGCheckButton(f, "Loop Marked");
181 f->AddFrame(fLoopMarked, new TGLayoutHints(kLHintsLeft, 0, 4, 3, 0));
182 fLoopMarked->SetToolTipText("Automatic marked events loading.");
183 fLoopMarked->Connect("Toggled(Bool_t)", cls, this, "DoSetLoopMarked()");
184
80547f2d 185 fAutoLoadTime = new TEveGValuator(f, "Time: ", 110, 0);
ecb84424 186 f->AddFrame(fAutoLoadTime);
80547f2d 187 fAutoLoadTime->SetShowSlider(kFALSE);
188 fAutoLoadTime->SetNELength(4);
189 fAutoLoadTime->Build();
190 fAutoLoadTime->SetLimits(0, 1000);
191 fAutoLoadTime->SetToolTip("Automatic event loading time in seconds.");
192 fAutoLoadTime->Connect("ValueSet(Double_t)", cls, this, "DoSetAutoLoadTime()");
ecb84424 193
969d3431 194 fTrigSel = new TGComboBox(f);
195 fTrigSel->Resize(4*width,b->GetDefaultHeight());
196 fTrigSel->AddEntry("No trigger selection",-1);
197 fTrigSel->Select(-1,kFALSE);
198 f->AddFrame(fTrigSel, new TGLayoutHints(kLHintsNormal, 10, 5, 0, 0));
199 fTrigSel->Connect("Selected(char*)", cls, this, "DoSetTrigSel()");
12365217 200
0790c3e6 201 fStorageStatus = MkLabel(f,"Storage: Waiting",0,8,8);
01ca7d6f 202 fEventServerStatus = MkLabel(f,"Event Server: Waiting",0,10,10);
0790c3e6 203
204 }
205
80547f2d 206 fEventInfo = new TGTextView(this, 400, 600);
207 AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
208
01ca7d6f 209 fM->Connect("NewEventLoaded()", cls, this, "Update(=1)");
210 fM->Connect("NoEventLoaded()", cls, this, "Update(=0)");
211 fM->Connect("StorageManagerOk()",cls,this,"StorageManagerChangedState(=1)");
212 fM->Connect("StorageManagerDown()",cls,this,"StorageManagerChangedState(=0)");
f76c9e9b 213
214 SetCleanup(kDeepCleanup);
215 Layout();
216 MapSubwindows();
217 MapWindow();
218}
219
220//______________________________________________________________________________
221AliEveEventManagerWindow::~AliEveEventManagerWindow()
222{
223 // Destructor.
224
4d62585e 225 fM->Disconnect("NewEventLoaded()", this);
f76c9e9b 226}
227
228//______________________________________________________________________________
229void AliEveEventManagerWindow::DoFirstEvent()
230{
231 // Load previous event
4d62585e 232 fM->GotoEvent(0);
f76c9e9b 233}
234
235//______________________________________________________________________________
236void AliEveEventManagerWindow::DoPrevEvent()
237{
238 // Load previous event
a410aca4 239 // fM->PrevEvent();
01ca7d6f 240 if (fM->IsOnlineMode()) {
241 fM->GotoEvent(1);
242 }
243 else {
244 fM->GotoEvent((Int_t) fEventId->GetNumber()-1);
245
246 }
a410aca4 247
f76c9e9b 248}
249
250//______________________________________________________________________________
251void AliEveEventManagerWindow::DoNextEvent()
252{
253 // Load next event
a410aca4 254 // fM->NextEvent();
01ca7d6f 255 if (fM->IsOnlineMode()) {
7f97b015 256 cout<<"next event, online node"<<endl;
01ca7d6f 257 fM->GotoEvent(2);
258 }
259 else {
7f97b015 260 cout<<"next event, offline mode"<<endl;
01ca7d6f 261 fM->GotoEvent((Int_t) fEventId->GetNumber()+1);
262 }
f76c9e9b 263}
264
265//______________________________________________________________________________
266void AliEveEventManagerWindow::DoLastEvent()
267{
268 // Load previous event
4d62585e 269 fM->GotoEvent(-1);
f76c9e9b 270}
271
164d3d29 272//______________________________________________________________________________
273void AliEveEventManagerWindow::DoMarkEvent()
274{
275 // Mark current event
276 fM->MarkCurrentEvent();
277}
278
7f97b015 279//______________________________________________________________________________
280void AliEveEventManagerWindow::DoRestartReco()
281{
572d0620 282 ifstream configFile (GetConfigFilePath());
283 string username,hostname;
284
285 if (configFile.is_open())
286 {
287 string line;
288 int from,to;
289 while(configFile.good())
290 {
291 getline(configFile,line);
292 from = line.find("\"")+1;
293 to = line.find_last_of("\"");
294 if(line.find("EVENT_SERVER=")==0)
295 {
296 hostname=line.substr(from,to-from);
297 }
298 else if(line.find("EVENT_SERVER_USER=")==0)
299 {
300 username=line.substr(from,to-from);
301 }
302 }
303 if(configFile.eof()){configFile.clear();}
304 configFile.close();
305 }
306 else{cout<<"Event Manager Editor -- Unable to open config file"<<endl;}
307
7f97b015 308 // Kill reconstruction server
572d0620 309 gSystem->Exec(Form("ssh -n -f %s@%s \"killall alieventserver\"",username.c_str(),hostname.c_str()));
7f97b015 310}
311
312void AliEveEventManagerWindow::DoRestartManager()
313{
572d0620 314 ifstream configFile (GetConfigFilePath());
315 string username,hostname;
316
317 if (configFile.is_open())
318 {
319 string line;
320 int from,to;
321 while(configFile.good())
322 {
323 getline(configFile,line);
324 from = line.find("\"")+1;
325 to = line.find_last_of("\"");
326 if(line.find("STORAGE_SERVER=")==0)
327 {
328 hostname=line.substr(from,to-from);
329 }
330 else if(line.find("STORAGE_SERVER_USER=")==0)
331 {
332 username=line.substr(from,to-from);
333 }
334 }
335 if(configFile.eof()){configFile.clear();}
336 configFile.close();
337 }
338 else{cout<<"Event Manager Editor -- Unable to open config file"<<endl;}
339
340
7f97b015 341 // Kill storage manager
572d0620 342 gSystem->Exec(Form("ssh -n -f %s@%s \"killall alistorage\"",username.c_str(),hostname.c_str()));
7f97b015 343}
344
f76c9e9b 345//______________________________________________________________________________
346void AliEveEventManagerWindow::DoSetEvent()
347{
348 // Set current event
4d62585e 349 fM->GotoEvent((Int_t) fEventId->GetNumber());
f76c9e9b 350}
351
80547f2d 352//______________________________________________________________________________
353void AliEveEventManagerWindow::DoRefresh()
354{
355 // Refresh event status.
356
4d62585e 357 Int_t ev = fM->GetEventId();
358 fM->Close();
359 fM->Open();
360 fM->GotoEvent(ev);
80547f2d 361}
362
363//______________________________________________________________________________
364void AliEveEventManagerWindow::DoSetAutoLoad()
365{
366 // Set the auto-load flag
367
4d62585e 368 fM->SetAutoLoad(fAutoLoad->IsOn());
01ca7d6f 369 Update(fM->NewEventAvailable());
80547f2d 370}
371
626a3158 372//______________________________________________________________________________
373void AliEveEventManagerWindow::DoSetLoopMarked()
374{
375 // Set the auto-load flag
376 fM->SetLoopMarked(fLoopMarked->IsOn());
377// Update(fM->NewEventAvailable());
378}
379
80547f2d 380//______________________________________________________________________________
381void AliEveEventManagerWindow::DoSetAutoLoadTime()
382{
383 // Set the auto-load time in seconds
384
4d62585e 385 fM->SetAutoLoadTime(fAutoLoadTime->GetValue());
80547f2d 386}
387
969d3431 388//______________________________________________________________________________
389void AliEveEventManagerWindow::DoSetTrigSel()
390{
391 // Set the trigger selection
392
393 fM->SetTrigSel(fTrigSel->GetSelectedEntry()->EntryId());
394}
395
f76c9e9b 396//______________________________________________________________________________
01ca7d6f 397void AliEveEventManagerWindow::Update(int state)
f76c9e9b 398{
f76c9e9b 399
4d62585e 400 Bool_t autoLoad = fM->GetAutoLoad();
401 Bool_t extCtrl = fM->IsUnderExternalControl();
80547f2d 402 Bool_t evNavOn = !autoLoad && !extCtrl;
403
e6194cd4 404#ifdef ZMQ
405
406 AliESDEvent* esd = fM->GetESD();
407 AliStorageAdministratorPanelListEvents* listEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
408 AliEveConfigManager *configManager = AliEveConfigManager::GetMaster();
409
01ca7d6f 410 if (!fM->IsOnlineMode()) {
411
412 listEventsTab->SetOfflineMode(kTRUE);
01ca7d6f 413
414 fFirstEvent->SetEnabled(!autoLoad);
415 fPrevEvent ->SetEnabled(!autoLoad);
416 fLastEvent ->SetEnabled(!autoLoad);
417 fNextEvent ->SetEnabled(!autoLoad);
418 fMarkEvent ->SetEnabled(kFALSE);
419
420 fInfoLabel->SetText(Form("/ %d", fM->GetMaxEventId()));
421
422 }
423 else if (1 == state && fStorageStatus->GetText()->Contains("DOWN")) {
424 fEventServerStatus->SetText("Event Server: OK");
425 fFirstEvent->SetEnabled(kFALSE);
426 fPrevEvent ->SetEnabled(kFALSE);
427 fLastEvent ->SetEnabled(!autoLoad);
428 fNextEvent ->SetEnabled(kFALSE);
429 fMarkEvent ->SetEnabled(kFALSE);
430 listEventsTab->SetOfflineMode(kTRUE);
431 fInfoLabel->SetText(Form("/ %d",fM->GetEventId()));
432 }
433 else if (0 == state && fStorageStatus->GetText()->Contains("DOWN")) {
434 fEventServerStatus->SetText("Event Server: Waiting");
435 fFirstEvent->SetEnabled(kFALSE);
436 fPrevEvent ->SetEnabled(kFALSE);
437 fLastEvent ->SetEnabled(!autoLoad);
438 fNextEvent ->SetEnabled(kFALSE);
439 fMarkEvent ->SetEnabled(kFALSE);
440 listEventsTab->SetOfflineMode(kTRUE);
441 }
442 else if (0 == state && fStorageStatus->GetText()->Contains("OK")) {
443 fEventServerStatus->SetText("Event Server: Waiting");
444 fFirstEvent->SetEnabled(!autoLoad);
445 fPrevEvent ->SetEnabled(!autoLoad);
446 fLastEvent ->SetEnabled(!autoLoad);
447 fNextEvent ->SetEnabled(!autoLoad);
448 fMarkEvent ->SetEnabled(kTRUE);
449 listEventsTab->SetOfflineMode(kFALSE);
450 }
451 else {
452 fEventServerStatus->SetText("Event Server: OK");
453 fFirstEvent->SetEnabled(!autoLoad);
454 fPrevEvent ->SetEnabled(!autoLoad);
455 fLastEvent ->SetEnabled(!autoLoad);
456 fNextEvent ->SetEnabled(!autoLoad);
457 fMarkEvent ->SetEnabled(kTRUE);
458 listEventsTab->SetOfflineMode(kFALSE);
459 }
e6194cd4 460#endif
01ca7d6f 461
462 if (1 == state) {
463 fRefresh ->SetEnabled(evNavOn);
464
465 fEventId->SetNumber(fM->GetEventId());
466 fEventId->SetState(evNavOn);
467 // fInfoLabel->SetText(Form("/ %d", fM->GetMaxEventId()));
468
469 fAutoLoad->SetState(fM->GetAutoLoad() ? kButtonDown : kButtonUp);
470 fAutoLoadTime->SetValue(fM->GetAutoLoadTime());
471
472 // Loop over active trigger classes
473 if (fM->GetESD()) {
474 for(Int_t iTrig = 0; iTrig < AliESDRun::kNTriggerClasses; iTrig++) {
475 TString trigName = fM->GetESD()->GetESDRun()->GetTriggerClass(iTrig);
476 if (trigName.IsNull()) {
477 if (fTrigSel->GetListBox()->GetEntry(iTrig)) {
478 if (fTrigSel->GetSelected() == iTrig) fTrigSel->Select(-1);
479 fTrigSel->RemoveEntry(iTrig);
480 }
481 continue;
969d3431 482 }
01ca7d6f 483 if (!fTrigSel->FindEntry(trigName.Data()))
484 fTrigSel->AddEntry(trigName.Data(),iTrig);
969d3431 485 }
969d3431 486 }
01ca7d6f 487 fTrigSel->SetEnabled(!evNavOn);
969d3431 488
efaef546 489// fEventInfo->LoadBuffer(fM->GetEventInfoHorizontal());
12365217 490
01ca7d6f 491 Layout();
492 }
f76c9e9b 493}
80547f2d 494
0790c3e6 495void AliEveEventManagerWindow::StorageManagerChangedState(int state)
496{
e6194cd4 497#ifdef ZMQ
498
01ca7d6f 499 Bool_t autoLoad = fM->GetAutoLoad();
500 AliStorageAdministratorPanelListEvents* listEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
501 AliEveConfigManager *configManager = AliEveConfigManager::GetMaster();
502
503 if (fM->IsOnlineMode()) {
0790c3e6 504 if (state == 0)
01ca7d6f 505 {
0790c3e6 506 fStorageStatus->SetText("Storage: DOWN");
01ca7d6f 507 fMarkEvent->SetEnabled(kFALSE);
508 fNextEvent->SetEnabled(kFALSE);
509 fLastEvent->SetEnabled(!autoLoad);
510 fPrevEvent->SetEnabled(kFALSE);
511 fFirstEvent->SetEnabled(kFALSE);
512 listEventsTab->SetOfflineMode(kTRUE);
01ca7d6f 513 fEventId->SetState(kFALSE);
514 }
0790c3e6 515 else if(state == 1)
01ca7d6f 516 {
517 listEventsTab->SetOfflineMode(kFALSE);
518
0790c3e6 519 fStorageStatus->SetText("Storage: OK");
01ca7d6f 520 fMarkEvent->SetEnabled(kTRUE);
521 fNextEvent->SetEnabled(!autoLoad);
522 fLastEvent->SetEnabled(!autoLoad);
523 fPrevEvent->SetEnabled(!autoLoad);
524 fFirstEvent->SetEnabled(!autoLoad);
525 fEventId->SetState(!autoLoad);
526 }
527 }
e6194cd4 528#endif
0790c3e6 529}
530
80547f2d 531//------------------------------------------------------------------------------
532// Protected methods
533//------------------------------------------------------------------------------
534
535//______________________________________________________________________________
536TGTextButton* AliEveEventManagerWindow::MkTxtButton(TGCompositeFrame* p,
537 const char* txt, Int_t width,
538 Int_t lo, Int_t ro, Int_t to, Int_t bo)
539{
540 // Create a standard button.
541 // If width is not zero, the fixed-width flag is set.
542
543 TGTextButton* b = new TGTextButton(p, txt);
544 if (width > 0) {
545 b->SetWidth(width);
546 b->ChangeOptions(b->GetOptions() | kFixedWidth);
547 }
548 p->AddFrame(b, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
549 return b;
550}
551
552//______________________________________________________________________________
553TGLabel* AliEveEventManagerWindow::MkLabel(TGCompositeFrame* p,
554 const char* txt, Int_t width,
555 Int_t lo, Int_t ro, Int_t to, Int_t bo)
556{
557 // Create a standard button.
558 // If width is not zero, the fixed-width flag is set.
559
560 TGLabel* l = new TGLabel(p, txt);
561 if (width > 0) {
562 l->SetWidth(width);
563 l->ChangeOptions(l->GetOptions() | kFixedWidth);
564 }
565 p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
566 return l;
567}
ecb84424 568