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