AliEveEventManager
[u/mrichter/AliRoot.git] / EVE / macros / display.C
CommitLineData
274799f3 1#ifndef __CINT__
2# include <TGFileDialog.h>
3# include <TGFileBrowser.h>
4# include <TControlBar.h>
5# include <TString.h>
6# include <TSystem.h>
7# include <TROOT.h>
8# include <TEveManager.h>
9# include <TSystemDirectory.h>
10# include <TEveMacro.h>
11# include <TEveBrowser.h>
12# include <TFolder.h>
13# include <TList.h>
14# include <TApplication.h>
15# include "aliroot/EVE/EveBase/AliEveEventManager.h"
16# include <iostream>
17#endif
18
19class Display
20{
21public:
22 //____________________________________________________________________
23 /** Constructor
24 @param file File or directory to read data from */
25 Display(const char* file="./")
26 : fCb(0),
27 fEnableHits(kFALSE),
28 fEnableDigits(kFALSE),
29 fEnableRaw(kFALSE),
30 fEnableESD(kFALSE),
31 fHasHits(kFALSE),
32 fHasDigits(kFALSE),
33 fHasRaw(kFALSE),
34 fHasESD(kFALSE)
35 {
36 AliEveEventManager::SetCdbUri("local://$ALICE_ROOT");
37 LoadMacros();
38 Setup(file, false);
39 SetupSelect();
40 SetupControl();
41 }
42 //____________________________________________________________________
43 /** Setup the control bar */
44 void SetupControl()
45 {
46 fCb = new TControlBar("vertical", "EVE Controls");
47 const char* buts[] = { "Load ...",
48 "Select ...",
49 "Next event",
50 "Previous event",
51 "Hits",
52 "Digits",
53 "Raw",
54 "ESD",
55 "Tracks",
56 "Quit",
57 0 };
58 const char* meths[] = { "LoadFile",
59 "Select",
60 "NextEvent",
61 "PrevEvent",
62 "ToggleHits",
63 "ToggleDigits",
64 "ToggleRaw",
65 "ToggleESD",
66 "ToggleTracks",
67 "Quit",
68 0 };
69 const char* hints[] = { "Specify input" ,
70 "Select which detectors to show",
71 "Get next event",
72 "Get previous event",
73 "Toggle display of hits",
74 "Toggle display of simulated digits",
75 "Toggle display of raw digits",
76 "Toggle display of event summary data",
77 "Toggle display of tracks",
78 "Quit",
79 0 };
80
81 char** but = const_cast<char**>(buts);
82 char** meth = const_cast<char**>(meths);
83 char** hint = const_cast<char**>(hints);
84 while (*but) {
85 fCb->AddButton(*but, Form("Display::Instance()->%s()", *meth), *hint);
86 but++;
87 meth++;
88 hint++;
89 }
90 fCb->Show();
91 }
92 //____________________________________________________________________
93 /** Setup the selection bar */
94 void SetupSelect()
95 {
96 fSelect = new TControlBar("vertical", "Detector selection");
97 char* dets[] = { "emcal",
98 "fmd",
99 "its",
100 "pmd",
101 "t0",
102 "tof",
103 "tpc",
104 "trd",
105 "vzero",
106 "kine",
107 "esd",
108 0 };
109 char** det = dets;
110 while (*det) {
111 // TString cmd(Form("Display::Instance()->Enable(\"%s\")", *det));
112 // TString help(Form("Enable display of %s data", name.Data()));
113 fSelect->AddButton(*det,
114 Form("Display::Instance()->Enable(\"%s\")", *det),
115 Form("Enable display of %s data", *det));
116 det++;
117 }
118 std::cout << "Adding \"Hide\" to select" << std::endl;
119 fSelect->AddButton("Hide", "Display::Instance()->HideSelect()",
120 "Hide the detector selection menu");
121 }
122 //____________________________________________________________________
123 /** Load macros used by EVE */
124 void LoadMacros()
125 {
126 std::cout << "Loading macros ... " << std::flush;
127 TString savdir(gSystem->pwd());
128 TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
129 gSystem->ExpandPathName(macdir);
130
131 TFolder* f = gEve->GetMacroFolder();
132 TSystemDirectory* dir = new TSystemDirectory(macdir.Data(),
133 macdir.Data());
134 TList* files = dir->GetListOfFiles();
135 files->Sort();
136 TIter next(files);
137 TSystemFile* file = 0;
138 while ((file = static_cast<TSystemFile*>(next()))) {
139 if (file->IsDirectory()) continue;
140 TString name(gSystem->ConcatFileName(macdir.Data(),file->GetName()));
141 if (!name.EndsWith(".C")) continue;
142 f->Add(new TEveMacro(name.Data()));
143 }
144
145 gROOT->GetListOfBrowsables()->Add(dir);
146
147 {
148 TEveBrowser* b = gEve->GetBrowser();
149 TGFileBrowser* fb = b->GetFileBrowser();
150 fb->GotoDir(macdir);
151 {
152 b->StartEmbedding(0);
153 fb = b->MakeFileBrowser();
154 fb->BrowseObj(f);
155 fb->Show();
156 b->StopEmbedding(0);
157 b->SetTabTitle("Macros", 0);
158 b->SetTab(0,0);
159 }
160 }
161 gSystem->cd(savdir);
162 std::cout << "done" << std::endl;
163 }
164 //____________________________________________________________________
165 /** Set-up load location, etc.
166 @param file File or directory to read data from
167 @param refresh Force a refresh */
168 void Setup(const char* file, bool refresh)
169 {
170 TString fileName(gSystem->BaseName(file));
171 TString dirName(gSystem->DirName(file));
172
173 if (fileName.Contains("ESD")) {
174 std::cout << "Adding ESD file " << fileName << std::endl;
175 AliEveEventManager::SetESDFileName(fileName.Data());
176 }
177 else if (fileName.EndsWith(".root") || fileName.EndsWith(".raw")) {
178 std::cout << "Adding raw file " << fileName << std::endl;
179 AliEveEventManager::SetRawFileName(fileName.Data());
180 }
181 else if (fileName.IsNull()) {
182 std::cout << "No file given!" << std::endl;
183 // std::cout << "Adding raw directory " << dirName.Data() << std::endl;
184 // AliEveEventManager::SetRawFileName(dirName.Data());
185 }
186 else {
187 std::cerr << "Don't know how to deal with '" << fileName << "'"
188 << std::endl;
189 return;
190 }
191 std::cout << "Opening " << fileName << " (" << dirName << ")" << std::endl;
192
4d62585e 193 if (AliEveEventManager::GetMaster()) delete AliEveEventManager::GetMaster();
ba5d58f2 194 TString eventName("Event"); // CINT has trouble with direct "Event".
195 AliEveEventManager::GetMaster() = new AliEveEventManager(eventName, dirName, 0);
4d62585e 196 gEve->AddEvent(AliEveEventManager::GetMaster());
274799f3 197
198 if (refresh) Refresh();
199 }
200 //____________________________________________________________________
201 /** Executed in response to hitting the "Load ..." button. */
202 void
203 LoadFile()
204 {
205 fCb->SetButtonState("Load ...", 1);
206 TGFileInfo fi;
207 fi.fIniDir = StrDup(gSystem->pwd());
208 new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
209 Setup(fi.fFilename, true);
210 fCb->SetButtonState("Load ...", 0);
211 }
212 //____________________________________________________________________
213 /** Pop-up or down the selection menu */
214 void
215 Select()
216 {
217 fSelect->Show();
218 fCb->SetButtonState("Select ...", 1);
219 }
220 //____________________________________________________________________
221 /** Enable a detector or type of display */
222 void
223 Enable(const char* what)
224 {
225 TObject* o = fEnabled.FindObject(what);
226 //TString n(what);
227 // n.ToUpper();
228 std::cout << "Enable " << what << "?" << std::endl;
229 if (o) {
230 fEnabled.Remove(o);
231 fSelect->SetButtonState(what, 0);
232 delete o;
233 }
234 else {
235 fEnabled.Add(new TObjString(what));
236 fSelect->SetButtonState(what, 1);
237 }
238 Refresh();
239 }
240 //____________________________________________________________________
241 /** Pop-down the selection menu */
242 void
243 HideSelect()
244 {
245 fCb->SetButtonState("Select ...", 0);
246 fSelect->Hide();
247 }
248 //____________________________________________________________________
249 /** Prepare for a new event */
250 void
251 Prepare()
252 {
253 fHasHits = kFALSE;
254 fHasDigits = kFALSE;
255 fHasRaw = kFALSE;
256 fHasESD = kFALSE;
257 fHasTracks = kFALSE;
258 }
259 //____________________________________________________________________
260 /** Get the next event */
261 void
262 NextEvent()
263 {
264 Prepare();
265 std::cout << "Getting next event, please wait ... " << std::flush;
266 gROOT->Macro("event_next.C");
267 std::cout << "done" << std::endl;
268 Refresh();
269 }
270 //____________________________________________________________________
271 /** Get the previous event */
272 void
273 PrevEvent()
274 {
275 Prepare();
276 std::cout << "Getting previous event, please wait ... " << std::flush;
277 gROOT->Macro("event_prev.C");
278 std::cout << "done" << std::endl;
279 Refresh();
280 }
281 //____________________________________________________________________
282 /** Reload the current event */
283 void
284 Reload()
285 {
286 Prepare();
4d62585e 287 Int_t event = AliEveEventManager::GetMaster()->GetEventId();
274799f3 288 std::cout << "Getting event " << event
289 << ", please wait ... " << std::flush;
290 gROOT->Macro(Form("event_goto.C(%d)", event));
291 std::cout << "done" << std::endl;
292 Refresh();
293 }
294 //__________________________________________________________________
295 /** Refresh the display of something
296 @param enabled Whether this something is enabled or not
297 @param has Whether we have already shown this data
298 @param what What data to show */
299 void
300 RefreshOne(Bool_t enabled, Bool_t& has, const char* what)
301 {
302 if (!enabled || has) return;
303 std::cout << what << "..." << std::flush;
304 TIter next(&fEnabled);
305 TObject* o = 0;
306 while ((o = next())) {
307 TMacro* macro = gEve->GetMacro(Form("%s_%s", o->GetName(), what));
308 if (macro) macro->Exec();
309 }
310 has = kTRUE;
311 }
312
313 //____________________________________________________________________
314 /** Refresh the display of the data */
315 void
316 Refresh()
317 {
318 std::cout << "Drawing ... " << std::flush;
319 RefreshOne(fEnableTracks, fHasTracks, "tracks");
320 RefreshOne(fEnableHits, fHasHits, "hits2");
321 RefreshOne(fEnableDigits, fHasDigits, "digits");
322 RefreshOne(fEnableRaw, fHasRaw, "raw");
323 RefreshOne(fEnableESD, fHasESD, "esd");
324 std::cout << "done" << std::endl;
325 }
326 //____________________________________________________________________
327 /** Toggle the diplay of some data */
328 void
329 Toggle(Bool_t& what, const char* name)
330 {
331 what = !what;
332 fCb->SetButtonState(name, what ? 1 : 0);
333 if (!what) Reload();
334 Refresh();
335 }
336 //____________________________________________________________________
337 /** Toggle the diplay the simulated hits */
338 void ToggleHits() { Toggle(fEnableHits, "Hits"); }
339 //____________________________________________________________________
340 /** Toggle the diplay the simulated digits */
341 void ToggleDigits() { Toggle(fEnableDigits, "Digits"); }
342 //____________________________________________________________________
343 /** Toggle the diplay the raw digits */
344 void ToggleRaw() { Toggle(fEnableRaw, "Raw"); }
345 //____________________________________________________________________
346 /** Toggle the diplay the Event Summary Data */
347 void ToggleESD() { Toggle(fEnableESD, "ESD"); }
348 //____________________________________________________________________
349 /** Toggle the diplay of tracks */
350 void ToggleTracks() { Toggle(fEnableTracks, "Tracks"); }
351 //____________________________________________________________________
352 /** Pop-down both menues */
353 void Quit()
354 {
355 fCb->Hide();
356 fSelect->Hide();
357 fgInstance = 0;
358 delete this;
359 }
360 //____________________________________________________________________
361 /** Get the static instance */
362 static Display* Instance() {
363 if (!fgInstance) fgInstance = new Display();
364 return fgInstance;
365 }
366protected:
367 TControlBar* fCb; // Control bar
368 TControlBar* fSelect; // Selection bar
369 Bool_t fEnableHits; // Whether simulated hits are enabled
370 Bool_t fEnableDigits; // Whether simulated digits are enabled
371 Bool_t fEnableRaw; // Whehter raw data digits are enabled
372 Bool_t fEnableESD; // Whehter Event Summary Data is enabled
373 Bool_t fEnableTracks; // Whether tracks are shown
374 Bool_t fHasHits; // Whether simulated hits are rendered
375 Bool_t fHasDigits; // Whether simulated digits are rendered
376 Bool_t fHasRaw; // Whether raw data digits are rendered
377 Bool_t fHasESD; // Whether Event Summary Data is rendered
378 Bool_t fHasTracks; // Whether tracks are rendered
379 TList fEnabled;
380 static Display* fgInstance; // Static singleton instance
381};
382Display* Display::fgInstance = 0;
383
384
385//____________________________________________________________________
386Display* display()
387{
388 TGeoManager::Import("geometry.root");
389
390 Display* d = Display::Instance();
391 return d;
392
393}
394//____________________________________________________________________
395//
396// EOF
397//