]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveBase/AliEveEventManagerEditor.cxx
Update master to aliroot
[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::ifstream;
36 using std::ofstream;
37 using std::ios;
38 using std::cout;
39 using std::endl;
40 using std::string;
41
42 ClassImp(AliEveEventManagerEditor)
43
44 //______________________________________________________________________________
45 AliEveEventManagerEditor::AliEveEventManagerEditor(const TGWindow *p, Int_t width, Int_t height,
46                                                    UInt_t options, Pixel_t back) :
47   TGedFrame(p, width, height, options | kVerticalFrame, back),
48   fM(0),
49   fDumpEventInfo(0),
50   fEventInfo(0)
51 {
52   // Constructor.
53
54   MakeTitle("AliEveEventManager");
55
56   {
57     TGHorizontalFrame* f = new TGHorizontalFrame(this);
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()");
65     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
66   }
67   {
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
73     fEventInfo = new TGTextView(f, 200, 300);
74     f->AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
75
76     AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
77   }
78 }
79
80 /******************************************************************************/
81
82 //______________________________________________________________________________
83 void AliEveEventManagerEditor::SetModel(TObject* obj)
84 {
85   // Set model object.
86
87   fM = static_cast<AliEveEventManager*>(obj);
88
89   fEventInfo->LoadBuffer(fM->GetEventInfoVertical());
90 }
91
92 /******************************************************************************/
93
94 //______________________________________________________________________________
95 void AliEveEventManagerEditor::DumpEventInfo()
96 {
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;
104
105   f.close();
106 }
107
108
109 //==============================================================================
110 // AliEveEventManagerWindow
111 //==============================================================================
112
113 //______________________________________________________________________________
114 //
115 // Horizontal GUI for AliEveEventManager, to be placed in the
116 // bottom part of ROOT browser.
117
118 ClassImp(AliEveEventManagerWindow)
119
120 AliEveEventManagerWindow::AliEveEventManagerWindow(AliEveEventManager* mgr) :
121   TGMainFrame(gClient->GetRoot(), 400, 100, kVerticalFrame),
122   fM            (mgr),
123   fFirstEvent   (0),
124   fPrevEvent    (0),
125   fNextEvent    (0),
126   fLastEvent    (0),
127   fRefresh      (0),
128   fEventId      (0),
129   fInfoLabel    (0),
130   fAutoLoad     (0),
131   fLoopMarked   (0),
132   fAutoLoadTime (0),
133   fTrigSel      (0),
134   fEventInfo    (0)
135 {
136   // Constructor.
137
138   const TString cls("AliEveEventManagerWindow");
139   TGTextButton *b = 0;
140   {
141     Int_t width = 50;
142
143     TGHorizontalFrame* f = new TGHorizontalFrame(this);
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()");
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));
154     fEventId->Connect("ValueSet(Long_t)", cls, this, "DoSetEvent()");
155     fInfoLabel = new TGLabel(f);
156     f->AddFrame(fInfoLabel, new TGLayoutHints(kLHintsNormal, 5, 10, 4, 0));
157
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()");
162     fMarkEvent = b = MkTxtButton(f, "Mark", width);
163     b->Connect("Clicked()", cls, this, "DoMarkEvent()");
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       
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
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       
187     fAutoLoadTime = new TEveGValuator(f, "Time: ", 110, 0);
188     f->AddFrame(fAutoLoadTime);
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()");
195
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()");
202
203     fStorageStatus = MkLabel(f,"Storage: Waiting",0,8,8);
204     fEventServerStatus = MkLabel(f,"Event Server: Waiting",0,10,10);
205       
206   }
207     
208   fEventInfo = new TGTextView(this, 400, 600);
209   AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
210
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)");
215
216   SetCleanup(kDeepCleanup);
217   Layout();
218   MapSubwindows();
219   MapWindow();
220 }
221
222 //______________________________________________________________________________
223 AliEveEventManagerWindow::~AliEveEventManagerWindow()
224 {
225   // Destructor.
226
227   fM->Disconnect("NewEventLoaded()", this);
228 }
229
230 //______________________________________________________________________________
231 void AliEveEventManagerWindow::DoFirstEvent()
232 {
233   // Load previous event
234   fM->GotoEvent(0);
235 }
236
237 //______________________________________________________________________________
238 void AliEveEventManagerWindow::DoPrevEvent()
239 {
240   // Load previous event
241   // fM->PrevEvent();
242   if (fM->IsOnlineMode()) {
243     fM->GotoEvent(1);
244   }
245   else {
246     fM->GotoEvent((Int_t) fEventId->GetNumber()-1);
247
248   }
249
250 }
251
252 //______________________________________________________________________________
253 void AliEveEventManagerWindow::DoNextEvent()
254 {
255   // Load next event
256   // fM->NextEvent();
257   if (fM->IsOnlineMode()) {
258       cout<<"next event, online node"<<endl;
259     fM->GotoEvent(2);
260   }
261   else {
262       cout<<"next event, offline mode"<<endl;
263     fM->GotoEvent((Int_t) fEventId->GetNumber()+1);
264   }
265 }
266
267 //______________________________________________________________________________
268 void AliEveEventManagerWindow::DoLastEvent()
269 {
270   // Load previous event
271   fM->GotoEvent(-1);
272 }
273
274 //______________________________________________________________________________
275 void AliEveEventManagerWindow::DoMarkEvent()
276 {
277   // Mark current event
278   fM->MarkCurrentEvent();
279 }
280
281 //______________________________________________________________________________
282 void AliEveEventManagerWindow::DoRestartReco()
283 {
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
310     // Kill reconstruction server
311     gSystem->Exec(Form("ssh -n -f %s@%s \"killall alieventserver\"",username.c_str(),hostname.c_str()));
312 }
313
314 void AliEveEventManagerWindow::DoRestartManager()
315 {
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     
343     // Kill storage manager
344     gSystem->Exec(Form("ssh -n -f %s@%s \"killall alistorage\"",username.c_str(),hostname.c_str()));
345 }
346
347 //______________________________________________________________________________
348 void AliEveEventManagerWindow::DoSetEvent()
349 {
350   // Set current event
351   fM->GotoEvent((Int_t) fEventId->GetNumber());
352 }
353
354 //______________________________________________________________________________
355 void AliEveEventManagerWindow::DoRefresh()
356 {
357   // Refresh event status.
358
359   Int_t ev = fM->GetEventId();
360   fM->Close();
361   fM->Open();
362   fM->GotoEvent(ev);
363 }
364
365 //______________________________________________________________________________
366 void AliEveEventManagerWindow::DoSetAutoLoad()
367 {
368   // Set the auto-load flag
369
370   fM->SetAutoLoad(fAutoLoad->IsOn());
371   Update(fM->NewEventAvailable());
372 }
373
374 //______________________________________________________________________________
375 void AliEveEventManagerWindow::DoSetLoopMarked()
376 {
377     // Set the auto-load flag
378     fM->SetLoopMarked(fLoopMarked->IsOn());
379 //    Update(fM->NewEventAvailable());
380 }
381
382 //______________________________________________________________________________
383 void AliEveEventManagerWindow::DoSetAutoLoadTime()
384 {
385   // Set the auto-load time in seconds
386
387   fM->SetAutoLoadTime(fAutoLoadTime->GetValue());
388 }
389
390 //______________________________________________________________________________
391 void AliEveEventManagerWindow::DoSetTrigSel()
392 {
393   // Set the trigger selection
394
395   fM->SetTrigSel(fTrigSel->GetSelectedEntry()->EntryId());
396 }
397
398 //______________________________________________________________________________
399 void AliEveEventManagerWindow::Update(int state)
400 {
401
402   Bool_t autoLoad = fM->GetAutoLoad();
403 //  Bool_t extCtrl  = fM->IsUnderExternalControl();
404     Bool_t evNavOn  = !autoLoad;// && !extCtrl;
405
406 #ifdef ZMQ
407
408   AliESDEvent*  esd = fM->GetESD();
409   AliStorageAdministratorPanelListEvents* listEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
410   AliEveConfigManager *configManager = AliEveConfigManager::GetMaster();
411
412   if (!fM->IsOnlineMode()) {
413
414       listEventsTab->SetOfflineMode(kTRUE);
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   }
462 #endif
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;
484         }
485         if (!fTrigSel->FindEntry(trigName.Data()))
486           fTrigSel->AddEntry(trigName.Data(),iTrig);
487       }
488     }
489     fTrigSel->SetEnabled(!evNavOn);
490
491 //    fEventInfo->LoadBuffer(fM->GetEventInfoHorizontal());
492
493     Layout();
494   }
495 }
496
497 void AliEveEventManagerWindow::StorageManagerChangedState(int state)
498 {
499 #ifdef ZMQ
500
501   Bool_t autoLoad = fM->GetAutoLoad();
502   AliStorageAdministratorPanelListEvents* listEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
503   AliEveConfigManager *configManager = AliEveConfigManager::GetMaster();
504
505   if (fM->IsOnlineMode()) {
506     if (state == 0)
507       {
508         fStorageStatus->SetText("Storage: DOWN");
509         fMarkEvent->SetEnabled(kFALSE);
510         fNextEvent->SetEnabled(kFALSE);
511         fLastEvent->SetEnabled(!autoLoad);
512         fPrevEvent->SetEnabled(kFALSE);
513         fFirstEvent->SetEnabled(kFALSE);
514         listEventsTab->SetOfflineMode(kTRUE);
515         fEventId->SetState(kFALSE);
516       }
517     else if(state == 1)
518       {
519         listEventsTab->SetOfflineMode(kFALSE);
520
521         fStorageStatus->SetText("Storage: OK");
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   }
530 #endif
531 }
532
533 //------------------------------------------------------------------------------
534 // Protected methods
535 //------------------------------------------------------------------------------
536
537 //______________________________________________________________________________
538 TGTextButton* 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 //______________________________________________________________________________
555 TGLabel* 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 }
570