]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveBase/AliEveEventManagerEditor.cxx
e4b84b291579474334084606e30373e5cfe00129
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveEventManagerEditor.cxx
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"
12 #include "AliEveConfigManager.h"
13
14 #include <AliESDEvent.h>
15
16 #include <TVirtualPad.h>
17 #include "TColor.h"
18
19 #include <TEveGValuators.h>
20 #include <TGButton.h>
21 #include <TGTextView.h>
22 #include <TGLabel.h>
23
24 #include "Riostream.h"
25
26 #ifdef ZMQ
27 #include "AliStorageAdministratorPanelListEvents.h"
28 #include "AliStorageAdministratorPanelMarkEvent.h"
29 #endif
30
31 //______________________________________________________________________________
32 // GUI editor for AliEveEventManager.
33 //
34
35 using std::ofstream;
36 using std::ios;
37 using std::cout;
38 using std::endl;
39
40 ClassImp(AliEveEventManagerEditor)
41
42 //______________________________________________________________________________
43 AliEveEventManagerEditor::AliEveEventManagerEditor(const TGWindow *p, Int_t width, Int_t height,
44                                                    UInt_t options, Pixel_t back) :
45   TGedFrame(p, width, height, options | kVerticalFrame, back),
46   fM(0),
47   fDumpEventInfo(0),
48   fEventInfo(0)
49 {
50   // Constructor.
51
52   MakeTitle("AliEveEventManager");
53
54   {
55     TGHorizontalFrame* f = new TGHorizontalFrame(this);
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()");
63     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
64   }
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
71     fEventInfo = new TGTextView(f, 200, 300);
72     f->AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
73
74     AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
75   }
76 }
77
78 /******************************************************************************/
79
80 //______________________________________________________________________________
81 void AliEveEventManagerEditor::SetModel(TObject* obj)
82 {
83   // Set model object.
84
85   fM = static_cast<AliEveEventManager*>(obj);
86
87   fEventInfo->LoadBuffer(fM->GetEventInfoVertical());
88 }
89
90 /******************************************************************************/
91
92 //______________________________________________________________________________
93 void AliEveEventManagerEditor::DumpEventInfo()
94 {
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;
102
103   f.close();
104 }
105
106
107 //==============================================================================
108 // AliEveEventManagerWindow
109 //==============================================================================
110
111 //______________________________________________________________________________
112 //
113 // Horizontal GUI for AliEveEventManager, to be placed in the
114 // bottom part of ROOT browser.
115
116 ClassImp(AliEveEventManagerWindow)
117
118 AliEveEventManagerWindow::AliEveEventManagerWindow(AliEveEventManager* mgr) :
119   TGMainFrame(gClient->GetRoot(), 400, 100, kVerticalFrame),
120   fM            (mgr),
121   fFirstEvent   (0),
122   fPrevEvent    (0),
123   fNextEvent    (0),
124   fLastEvent    (0),
125   fRefresh      (0),
126   fEventId      (0),
127   fInfoLabel    (0),
128   fAutoLoad     (0),
129   fLoopMarked   (0),
130   fAutoLoadTime (0),
131   fTrigSel      (0),
132   fEventInfo    (0)
133 {
134   // Constructor.
135
136   const TString cls("AliEveEventManagerWindow");
137   TGTextButton *b = 0;
138   {
139     Int_t width = 50;
140
141     TGHorizontalFrame* f = new TGHorizontalFrame(this);
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()");
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));
152     fEventId->Connect("ValueSet(Long_t)", cls, this, "DoSetEvent()");
153     fInfoLabel = new TGLabel(f);
154     f->AddFrame(fInfoLabel, new TGLayoutHints(kLHintsNormal, 5, 10, 4, 0));
155
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()");
160     fMarkEvent = b = MkTxtButton(f, "Mark", width);
161     b->Connect("Clicked()", cls, this, "DoMarkEvent()");
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       
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
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       
185     fAutoLoadTime = new TEveGValuator(f, "Time: ", 110, 0);
186     f->AddFrame(fAutoLoadTime);
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()");
193
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()");
200
201     fStorageStatus = MkLabel(f,"Storage: Waiting",0,8,8);
202     fEventServerStatus = MkLabel(f,"Event Server: Waiting",0,10,10);
203       
204   }
205     
206   fEventInfo = new TGTextView(this, 400, 600);
207   AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
208
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)");
213
214   SetCleanup(kDeepCleanup);
215   Layout();
216   MapSubwindows();
217   MapWindow();
218 }
219
220 //______________________________________________________________________________
221 AliEveEventManagerWindow::~AliEveEventManagerWindow()
222 {
223   // Destructor.
224
225   fM->Disconnect("NewEventLoaded()", this);
226 }
227
228 //______________________________________________________________________________
229 void AliEveEventManagerWindow::DoFirstEvent()
230 {
231   // Load previous event
232   fM->GotoEvent(0);
233 }
234
235 //______________________________________________________________________________
236 void AliEveEventManagerWindow::DoPrevEvent()
237 {
238   // Load previous event
239   // fM->PrevEvent();
240   if (fM->IsOnlineMode()) {
241     fM->GotoEvent(1);
242   }
243   else {
244     fM->GotoEvent((Int_t) fEventId->GetNumber()-1);
245
246   }
247
248 }
249
250 //______________________________________________________________________________
251 void AliEveEventManagerWindow::DoNextEvent()
252 {
253   // Load next event
254   // fM->NextEvent();
255   if (fM->IsOnlineMode()) {
256       cout<<"next event, online node"<<endl;
257     fM->GotoEvent(2);
258   }
259   else {
260       cout<<"next event, offline mode"<<endl;
261     fM->GotoEvent((Int_t) fEventId->GetNumber()+1);
262   }
263 }
264
265 //______________________________________________________________________________
266 void AliEveEventManagerWindow::DoLastEvent()
267 {
268   // Load previous event
269   fM->GotoEvent(-1);
270 }
271
272 //______________________________________________________________________________
273 void AliEveEventManagerWindow::DoMarkEvent()
274 {
275   // Mark current event
276   fM->MarkCurrentEvent();
277 }
278
279 //______________________________________________________________________________
280 void AliEveEventManagerWindow::DoRestartReco()
281 {
282     // Kill reconstruction server
283     gSystem->Exec("ssh -n -f edis@pcald39fix \"killall alieventserver\"");
284 }
285
286 void AliEveEventManagerWindow::DoRestartManager()
287 {
288     // Kill storage manager
289     gSystem->Exec("ssh -n -f edis@pcald39fix \"killall alistorage\"");
290 }
291
292 //______________________________________________________________________________
293 void AliEveEventManagerWindow::DoSetEvent()
294 {
295   // Set current event
296   fM->GotoEvent((Int_t) fEventId->GetNumber());
297 }
298
299 //______________________________________________________________________________
300 void AliEveEventManagerWindow::DoRefresh()
301 {
302   // Refresh event status.
303
304   Int_t ev = fM->GetEventId();
305   fM->Close();
306   fM->Open();
307   fM->GotoEvent(ev);
308 }
309
310 //______________________________________________________________________________
311 void AliEveEventManagerWindow::DoSetAutoLoad()
312 {
313   // Set the auto-load flag
314
315   fM->SetAutoLoad(fAutoLoad->IsOn());
316   Update(fM->NewEventAvailable());
317 }
318
319 //______________________________________________________________________________
320 void AliEveEventManagerWindow::DoSetLoopMarked()
321 {
322     // Set the auto-load flag
323     fM->SetLoopMarked(fLoopMarked->IsOn());
324 //    Update(fM->NewEventAvailable());
325 }
326
327 //______________________________________________________________________________
328 void AliEveEventManagerWindow::DoSetAutoLoadTime()
329 {
330   // Set the auto-load time in seconds
331
332   fM->SetAutoLoadTime(fAutoLoadTime->GetValue());
333 }
334
335 //______________________________________________________________________________
336 void AliEveEventManagerWindow::DoSetTrigSel()
337 {
338   // Set the trigger selection
339
340   fM->SetTrigSel(fTrigSel->GetSelectedEntry()->EntryId());
341 }
342
343 //______________________________________________________________________________
344 void AliEveEventManagerWindow::Update(int state)
345 {
346
347   Bool_t autoLoad = fM->GetAutoLoad();
348   Bool_t extCtrl  = fM->IsUnderExternalControl();
349   Bool_t evNavOn  = !autoLoad && !extCtrl;
350
351 #ifdef ZMQ
352
353   AliESDEvent*  esd = fM->GetESD();
354   AliStorageAdministratorPanelListEvents* listEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
355   AliEveConfigManager *configManager = AliEveConfigManager::GetMaster();
356
357   if (!fM->IsOnlineMode()) {
358
359       listEventsTab->SetOfflineMode(kTRUE);
360
361       fFirstEvent->SetEnabled(!autoLoad);
362       fPrevEvent ->SetEnabled(!autoLoad);
363       fLastEvent ->SetEnabled(!autoLoad);
364       fNextEvent ->SetEnabled(!autoLoad);
365       fMarkEvent ->SetEnabled(kFALSE);
366
367       fInfoLabel->SetText(Form("/ %d", fM->GetMaxEventId()));
368
369   }
370   else if (1 == state && fStorageStatus->GetText()->Contains("DOWN")) {
371     fEventServerStatus->SetText("Event Server: OK");
372     fFirstEvent->SetEnabled(kFALSE);
373     fPrevEvent ->SetEnabled(kFALSE);
374     fLastEvent ->SetEnabled(!autoLoad);
375     fNextEvent ->SetEnabled(kFALSE);
376     fMarkEvent ->SetEnabled(kFALSE);
377     listEventsTab->SetOfflineMode(kTRUE);
378     fInfoLabel->SetText(Form("/ %d",fM->GetEventId()));
379   }
380   else if (0 == state && fStorageStatus->GetText()->Contains("DOWN")) {
381     fEventServerStatus->SetText("Event Server: Waiting");
382     fFirstEvent->SetEnabled(kFALSE);
383     fPrevEvent ->SetEnabled(kFALSE);
384     fLastEvent ->SetEnabled(!autoLoad);
385     fNextEvent ->SetEnabled(kFALSE);
386     fMarkEvent ->SetEnabled(kFALSE);
387     listEventsTab->SetOfflineMode(kTRUE);
388   }
389   else if (0 == state && fStorageStatus->GetText()->Contains("OK")) {
390     fEventServerStatus->SetText("Event Server: Waiting");
391     fFirstEvent->SetEnabled(!autoLoad);
392     fPrevEvent ->SetEnabled(!autoLoad);
393     fLastEvent ->SetEnabled(!autoLoad);
394     fNextEvent ->SetEnabled(!autoLoad);
395     fMarkEvent ->SetEnabled(kTRUE);
396     listEventsTab->SetOfflineMode(kFALSE);
397   }
398   else {
399     fEventServerStatus->SetText("Event Server: OK");
400     fFirstEvent->SetEnabled(!autoLoad);
401     fPrevEvent ->SetEnabled(!autoLoad);
402     fLastEvent ->SetEnabled(!autoLoad);
403     fNextEvent ->SetEnabled(!autoLoad);
404     fMarkEvent ->SetEnabled(kTRUE);
405     listEventsTab->SetOfflineMode(kFALSE);
406   }
407 #endif
408
409   if (1 == state) {
410     fRefresh   ->SetEnabled(evNavOn);
411
412     fEventId->SetNumber(fM->GetEventId());
413     fEventId->SetState(evNavOn);
414     // fInfoLabel->SetText(Form("/ %d", fM->GetMaxEventId()));
415
416     fAutoLoad->SetState(fM->GetAutoLoad() ? kButtonDown : kButtonUp);
417     fAutoLoadTime->SetValue(fM->GetAutoLoadTime());
418
419     // Loop over active trigger classes
420     if (fM->GetESD()) {
421       for(Int_t iTrig = 0; iTrig < AliESDRun::kNTriggerClasses; iTrig++) {
422         TString trigName = fM->GetESD()->GetESDRun()->GetTriggerClass(iTrig);
423         if (trigName.IsNull()) {
424           if (fTrigSel->GetListBox()->GetEntry(iTrig)) {
425             if (fTrigSel->GetSelected() == iTrig) fTrigSel->Select(-1);
426             fTrigSel->RemoveEntry(iTrig);
427           }
428           continue;
429         }
430         if (!fTrigSel->FindEntry(trigName.Data()))
431           fTrigSel->AddEntry(trigName.Data(),iTrig);
432       }
433     }
434     fTrigSel->SetEnabled(!evNavOn);
435
436     fEventInfo->LoadBuffer(fM->GetEventInfoHorizontal());
437
438     Layout();
439   }
440 }
441
442 void AliEveEventManagerWindow::StorageManagerChangedState(int state)
443 {
444 #ifdef ZMQ
445
446   Bool_t autoLoad = fM->GetAutoLoad();
447   AliStorageAdministratorPanelListEvents* listEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
448   AliEveConfigManager *configManager = AliEveConfigManager::GetMaster();
449
450   if (fM->IsOnlineMode()) {
451     if (state == 0)
452       {
453         fStorageStatus->SetText("Storage: DOWN");
454         fMarkEvent->SetEnabled(kFALSE);
455         fNextEvent->SetEnabled(kFALSE);
456         fLastEvent->SetEnabled(!autoLoad);
457         fPrevEvent->SetEnabled(kFALSE);
458         fFirstEvent->SetEnabled(kFALSE);
459         listEventsTab->SetOfflineMode(kTRUE);
460         fEventId->SetState(kFALSE);
461       }
462     else if(state == 1)
463       {
464         listEventsTab->SetOfflineMode(kFALSE);
465
466         fStorageStatus->SetText("Storage: OK");
467         fMarkEvent->SetEnabled(kTRUE);
468         fNextEvent->SetEnabled(!autoLoad);
469         fLastEvent->SetEnabled(!autoLoad);
470         fPrevEvent->SetEnabled(!autoLoad);
471         fFirstEvent->SetEnabled(!autoLoad);
472         fEventId->SetState(!autoLoad);
473       }
474   }
475 #endif
476 }
477
478 //------------------------------------------------------------------------------
479 // Protected methods
480 //------------------------------------------------------------------------------
481
482 //______________________________________________________________________________
483 TGTextButton* AliEveEventManagerWindow::MkTxtButton(TGCompositeFrame* p,
484                                                     const char* txt, Int_t width,
485                                                     Int_t lo, Int_t ro, Int_t to, Int_t bo)
486 {
487   // Create a standard button.
488   // If width is not zero, the fixed-width flag is set.
489
490   TGTextButton* b = new TGTextButton(p, txt);
491   if (width > 0) {
492     b->SetWidth(width);
493     b->ChangeOptions(b->GetOptions() | kFixedWidth);
494   }
495   p->AddFrame(b, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
496   return b;
497 }
498
499 //______________________________________________________________________________
500 TGLabel* AliEveEventManagerWindow::MkLabel(TGCompositeFrame* p,
501                                            const char* txt, Int_t width,
502                                            Int_t lo, Int_t ro, Int_t to, Int_t bo)
503 {
504   // Create a standard button.
505   // If width is not zero, the fixed-width flag is set.
506
507   TGLabel* l = new TGLabel(p, txt);
508   if (width > 0) {
509     l->SetWidth(width);
510     l->ChangeOptions(l->GetOptions() | kFixedWidth);
511   }
512   p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
513   return l;
514 }
515