]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveBase/AliEveEventManagerEditor.cxx
Coverity
[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
13 #include <AliESDEvent.h>
14
15 #include <TVirtualPad.h>
16 #include "TColor.h"
17
18 #include <TEveGValuators.h>
19 #include <TGButton.h>
20 #include <TGTextView.h>
21 #include <TGLabel.h>
22
23 #include "Riostream.h"
24
25 //______________________________________________________________________________
26 // GUI editor for AliEveEventManager.
27 //
28
29 ClassImp(AliEveEventManagerEditor)
30
31 //______________________________________________________________________________
32 AliEveEventManagerEditor::AliEveEventManagerEditor(const TGWindow *p, Int_t width, Int_t height,
33                                                    UInt_t options, Pixel_t back) :
34   TGedFrame(p, width, height, options | kVerticalFrame, back),
35   fM(0),
36   fDumpEventInfo(0),
37   fEventInfo(0)
38 {
39   // Constructor.
40
41   MakeTitle("AliEveEventManager");
42
43   {
44     TGHorizontalFrame* f = new TGHorizontalFrame(this);
45     fDumpEventInfo = new TGTextButton(f, "Dump Event Info");
46     fDumpEventInfo->SetToolTipText("Append information about current event to event_info.txt file.");
47     fDumpEventInfo->SetWidth(120);
48     fDumpEventInfo->ChangeOptions(fDumpEventInfo->GetOptions() | kFixedWidth);
49     f->AddFrame(fDumpEventInfo, new TGLayoutHints(kLHintsNormal, 4,0,0,0));
50     fDumpEventInfo->Connect("Clicked()",
51                         "AliEveEventManagerEditor", this, "DumpEventInfo()");
52     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
53   }
54   {
55     TGVerticalFrame* f = new TGVerticalFrame(this);
56
57     TGLabel *eventInfoLabel = new TGLabel(f, "Event Information:");
58     f->AddFrame(eventInfoLabel, new TGLayoutHints(kLHintsNormal, 0,0,6,2));
59
60     fEventInfo = new TGTextView(f, 200, 300);
61     f->AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
62
63     AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
64   }
65 }
66
67 /******************************************************************************/
68
69 //______________________________________________________________________________
70 void AliEveEventManagerEditor::SetModel(TObject* obj)
71 {
72   // Set model object.
73
74   fM = dynamic_cast<AliEveEventManager*>(obj);
75
76   fEventInfo->LoadBuffer(fM->GetEventInfoVertical());
77 }
78
79 /******************************************************************************/
80
81 //______________________________________________________________________________
82 void AliEveEventManagerEditor::DumpEventInfo()
83 {
84   // Dump event-info into event_info.txt.
85   // The info is appended into the file.
86
87   ofstream f("event_info.txt", ios::out | ios::app);
88
89   f << "================================================================================\n\n";
90   f << fM->GetEventInfoHorizontal() << std::endl << std::endl;
91
92   f.close();
93 }
94
95
96 //==============================================================================
97 // AliEveEventManagerWindow
98 //==============================================================================
99
100 //______________________________________________________________________________
101 //
102 // Horizontal GUI for AliEveEventManager, to be placed in the
103 // bottom part of ROOT browser.
104
105 ClassImp(AliEveEventManagerWindow)
106
107 AliEveEventManagerWindow::AliEveEventManagerWindow(AliEveEventManager* mgr) :
108   TGMainFrame(gClient->GetRoot(), 400, 100, kVerticalFrame),
109   fM            (mgr),
110   fFirstEvent   (0),
111   fPrevEvent    (0),
112   fNextEvent    (0),
113   fLastEvent    (0),
114   fRefresh      (0),
115   fEventId      (0),
116   fInfoLabel    (0),
117   fAutoLoad     (0),
118   fAutoLoadTime (0),
119   fTrigSel      (0),
120   fEventInfo    (0)
121 {
122   // Constructor.
123
124   const TString cls("AliEveEventManagerWindow");
125   TGTextButton *b = 0;
126   {
127     Int_t width = 50;
128
129     TGHorizontalFrame* f = new TGHorizontalFrame(this);
130     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 0,0,2,2));
131
132     fFirstEvent = b = MkTxtButton(f, "First", width);
133     b->Connect("Clicked()", cls, this, "DoFirstEvent()");
134     fPrevEvent = b = MkTxtButton(f, "Prev", width);
135     b->Connect("Clicked()", cls, this, "DoPrevEvent()");
136
137     fEventId = new TGNumberEntry(f, 0, 5, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
138                                  TGNumberFormat::kNELLimitMinMax, 0, 10000);
139     f->AddFrame(fEventId, new TGLayoutHints(kLHintsNormal, 10, 5, 0, 0));
140     fEventId->Connect("ValueSet(Long_t)", cls, this, "DoSetEvent()");
141     fInfoLabel = new TGLabel(f);
142     f->AddFrame(fInfoLabel, new TGLayoutHints(kLHintsNormal, 5, 10, 4, 0));
143
144     fNextEvent = b = MkTxtButton(f, "Next", width);
145     b->Connect("Clicked()", cls, this, "DoNextEvent()");
146     fLastEvent = b = MkTxtButton(f, "Last", width);
147     b->Connect("Clicked()", cls, this, "DoLastEvent()");
148
149     MkLabel(f, "||", 0, 8, 8);
150
151     fRefresh = b = MkTxtButton(f, "Refresh", width + 8);
152     b->Connect("Clicked()",cls, this, "DoRefresh()");
153
154     MkLabel(f, "||", 0, 8, 8);
155
156     fAutoLoad = new TGCheckButton(f, "Autoload");
157     f->AddFrame(fAutoLoad, new TGLayoutHints(kLHintsLeft, 0, 4, 3, 0));
158     fAutoLoad->SetToolTipText("Automatic event loading.");
159     fAutoLoad->Connect("Toggled(Bool_t)", cls, this, "DoSetAutoLoad()");
160
161     fAutoLoadTime = new TEveGValuator(f, "Time: ", 110, 0);
162     f->AddFrame(fAutoLoadTime);
163     fAutoLoadTime->SetShowSlider(kFALSE);
164     fAutoLoadTime->SetNELength(4);
165     fAutoLoadTime->Build();
166     fAutoLoadTime->SetLimits(0, 1000);
167     fAutoLoadTime->SetToolTip("Automatic event loading time in seconds.");
168     fAutoLoadTime->Connect("ValueSet(Double_t)", cls, this, "DoSetAutoLoadTime()");
169
170     fTrigSel = new TGComboBox(f);
171     fTrigSel->Resize(4*width,b->GetDefaultHeight());
172     fTrigSel->AddEntry("No trigger selection",-1);
173     fTrigSel->Select(-1,kFALSE);
174     f->AddFrame(fTrigSel, new TGLayoutHints(kLHintsNormal, 10, 5, 0, 0));
175     fTrigSel->Connect("Selected(char*)", cls, this, "DoSetTrigSel()");
176   }
177
178   fEventInfo = new TGTextView(this, 400, 600);
179   AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
180
181   fM->Connect("NewEventLoaded()", cls, this, "Update()");
182
183   SetCleanup(kDeepCleanup);
184   Layout();
185   MapSubwindows();
186   MapWindow();
187 }
188
189 //______________________________________________________________________________
190 AliEveEventManagerWindow::~AliEveEventManagerWindow()
191 {
192   // Destructor.
193
194   fM->Disconnect("NewEventLoaded()", this);
195 }
196
197 //______________________________________________________________________________
198 void AliEveEventManagerWindow::DoFirstEvent()
199 {
200   // Load previous event
201   fM->GotoEvent(0);
202 }
203
204 //______________________________________________________________________________
205 void AliEveEventManagerWindow::DoPrevEvent()
206 {
207   // Load previous event
208   fM->PrevEvent();
209 }
210
211 //______________________________________________________________________________
212 void AliEveEventManagerWindow::DoNextEvent()
213 {
214   // Load next event
215   fM->NextEvent();
216 }
217
218 //______________________________________________________________________________
219 void AliEveEventManagerWindow::DoLastEvent()
220 {
221   // Load previous event
222   fM->GotoEvent(-1);
223 }
224
225 //______________________________________________________________________________
226 void AliEveEventManagerWindow::DoSetEvent()
227 {
228   // Set current event
229   fM->GotoEvent((Int_t) fEventId->GetNumber());
230 }
231
232 //______________________________________________________________________________
233 void AliEveEventManagerWindow::DoRefresh()
234 {
235   // Refresh event status.
236
237   Int_t ev = fM->GetEventId();
238   fM->Close();
239   fM->Open();
240   fM->GotoEvent(ev);
241 }
242
243 //______________________________________________________________________________
244 void AliEveEventManagerWindow::DoSetAutoLoad()
245 {
246   // Set the auto-load flag
247
248   fM->SetAutoLoad(fAutoLoad->IsOn());
249   Update();
250 }
251
252 //______________________________________________________________________________
253 void AliEveEventManagerWindow::DoSetAutoLoadTime()
254 {
255   // Set the auto-load time in seconds
256
257   fM->SetAutoLoadTime(fAutoLoadTime->GetValue());
258 }
259
260 //______________________________________________________________________________
261 void AliEveEventManagerWindow::DoSetTrigSel()
262 {
263   // Set the trigger selection
264
265   fM->SetTrigSel(fTrigSel->GetSelectedEntry()->EntryId());
266 }
267
268 //______________________________________________________________________________
269 void AliEveEventManagerWindow::Update()
270 {
271   // Update current event, number of available events, list of active triggers
272
273   Bool_t autoLoad = fM->GetAutoLoad();
274   Bool_t extCtrl  = fM->IsUnderExternalControl();
275   Bool_t evNavOn  = !autoLoad && !extCtrl;
276
277   fFirstEvent->SetEnabled(evNavOn);
278   fPrevEvent ->SetEnabled(evNavOn);
279   fLastEvent ->SetEnabled(evNavOn);
280   fNextEvent ->SetEnabled(!autoLoad);
281   fRefresh   ->SetEnabled(evNavOn);
282
283   fEventId->SetNumber(fM->GetEventId());
284   fEventId->SetState(evNavOn);
285   fInfoLabel->SetText(Form("/ %d", fM->GetMaxEventId()));
286
287   fAutoLoad->SetState(fM->GetAutoLoad() ? kButtonDown : kButtonUp);
288   fAutoLoadTime->SetValue(fM->GetAutoLoadTime());
289
290   // Loop over active trigger classes
291   if (fM->GetESD()) {
292     for(Int_t iTrig = 0; iTrig < AliESDRun::kNTriggerClasses; iTrig++) {
293       TString trigName = fM->GetESD()->GetESDRun()->GetTriggerClass(iTrig);
294       if (trigName.IsNull()) {
295         if (fTrigSel->GetListBox()->GetEntry(iTrig)) {
296           if (fTrigSel->GetSelected() == iTrig) fTrigSel->Select(-1);
297           fTrigSel->RemoveEntry(iTrig);
298         }
299         continue;
300       }
301       if (!fTrigSel->FindEntry(trigName.Data()))
302         fTrigSel->AddEntry(trigName.Data(),iTrig);
303     }
304   }
305   fTrigSel->SetEnabled(!evNavOn);
306
307   fEventInfo->LoadBuffer(fM->GetEventInfoHorizontal());
308
309   Layout();
310 }
311
312 //------------------------------------------------------------------------------
313 // Protected methods
314 //------------------------------------------------------------------------------
315
316 //______________________________________________________________________________
317 TGTextButton* AliEveEventManagerWindow::MkTxtButton(TGCompositeFrame* p,
318                                                     const char* txt, Int_t width,
319                                                     Int_t lo, Int_t ro, Int_t to, Int_t bo)
320 {
321   // Create a standard button.
322   // If width is not zero, the fixed-width flag is set.
323
324   TGTextButton* b = new TGTextButton(p, txt);
325   if (width > 0) {
326     b->SetWidth(width);
327     b->ChangeOptions(b->GetOptions() | kFixedWidth);
328   }
329   p->AddFrame(b, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
330   return b;
331 }
332
333 //______________________________________________________________________________
334 TGLabel* AliEveEventManagerWindow::MkLabel(TGCompositeFrame* p,
335                                            const char* txt, Int_t width,
336                                            Int_t lo, Int_t ro, Int_t to, Int_t bo)
337 {
338   // Create a standard button.
339   // If width is not zero, the fixed-width flag is set.
340
341   TGLabel* l = new TGLabel(p, txt);
342   if (width > 0) {
343     l->SetWidth(width);
344     l->ChangeOptions(l->GetOptions() | kFixedWidth);
345   }
346   p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
347   return l;
348 }
349