]>
Commit | Line | Data |
---|---|---|
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 | ||
19 | class Display | |
20 | { | |
21 | public: | |
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 | ||
193 | if (gAliEveEvent) delete gAliEveEvent; | |
194 | gAliEveEvent = new AliEveEventManager(dirName.Data(), 0); | |
195 | gEve->AddEvent(gAliEveEvent); | |
196 | ||
197 | if (refresh) Refresh(); | |
198 | } | |
199 | //____________________________________________________________________ | |
200 | /** Executed in response to hitting the "Load ..." button. */ | |
201 | void | |
202 | LoadFile() | |
203 | { | |
204 | fCb->SetButtonState("Load ...", 1); | |
205 | TGFileInfo fi; | |
206 | fi.fIniDir = StrDup(gSystem->pwd()); | |
207 | new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi); | |
208 | Setup(fi.fFilename, true); | |
209 | fCb->SetButtonState("Load ...", 0); | |
210 | } | |
211 | //____________________________________________________________________ | |
212 | /** Pop-up or down the selection menu */ | |
213 | void | |
214 | Select() | |
215 | { | |
216 | fSelect->Show(); | |
217 | fCb->SetButtonState("Select ...", 1); | |
218 | } | |
219 | //____________________________________________________________________ | |
220 | /** Enable a detector or type of display */ | |
221 | void | |
222 | Enable(const char* what) | |
223 | { | |
224 | TObject* o = fEnabled.FindObject(what); | |
225 | //TString n(what); | |
226 | // n.ToUpper(); | |
227 | std::cout << "Enable " << what << "?" << std::endl; | |
228 | if (o) { | |
229 | fEnabled.Remove(o); | |
230 | fSelect->SetButtonState(what, 0); | |
231 | delete o; | |
232 | } | |
233 | else { | |
234 | fEnabled.Add(new TObjString(what)); | |
235 | fSelect->SetButtonState(what, 1); | |
236 | } | |
237 | Refresh(); | |
238 | } | |
239 | //____________________________________________________________________ | |
240 | /** Pop-down the selection menu */ | |
241 | void | |
242 | HideSelect() | |
243 | { | |
244 | fCb->SetButtonState("Select ...", 0); | |
245 | fSelect->Hide(); | |
246 | } | |
247 | //____________________________________________________________________ | |
248 | /** Prepare for a new event */ | |
249 | void | |
250 | Prepare() | |
251 | { | |
252 | fHasHits = kFALSE; | |
253 | fHasDigits = kFALSE; | |
254 | fHasRaw = kFALSE; | |
255 | fHasESD = kFALSE; | |
256 | fHasTracks = kFALSE; | |
257 | } | |
258 | //____________________________________________________________________ | |
259 | /** Get the next event */ | |
260 | void | |
261 | NextEvent() | |
262 | { | |
263 | Prepare(); | |
264 | std::cout << "Getting next event, please wait ... " << std::flush; | |
265 | gROOT->Macro("event_next.C"); | |
266 | std::cout << "done" << std::endl; | |
267 | Refresh(); | |
268 | } | |
269 | //____________________________________________________________________ | |
270 | /** Get the previous event */ | |
271 | void | |
272 | PrevEvent() | |
273 | { | |
274 | Prepare(); | |
275 | std::cout << "Getting previous event, please wait ... " << std::flush; | |
276 | gROOT->Macro("event_prev.C"); | |
277 | std::cout << "done" << std::endl; | |
278 | Refresh(); | |
279 | } | |
280 | //____________________________________________________________________ | |
281 | /** Reload the current event */ | |
282 | void | |
283 | Reload() | |
284 | { | |
285 | Prepare(); | |
286 | Int_t event = gAliEveEvent->GetEventId(); | |
287 | std::cout << "Getting event " << event | |
288 | << ", please wait ... " << std::flush; | |
289 | gROOT->Macro(Form("event_goto.C(%d)", event)); | |
290 | std::cout << "done" << std::endl; | |
291 | Refresh(); | |
292 | } | |
293 | //__________________________________________________________________ | |
294 | /** Refresh the display of something | |
295 | @param enabled Whether this something is enabled or not | |
296 | @param has Whether we have already shown this data | |
297 | @param what What data to show */ | |
298 | void | |
299 | RefreshOne(Bool_t enabled, Bool_t& has, const char* what) | |
300 | { | |
301 | if (!enabled || has) return; | |
302 | std::cout << what << "..." << std::flush; | |
303 | TIter next(&fEnabled); | |
304 | TObject* o = 0; | |
305 | while ((o = next())) { | |
306 | TMacro* macro = gEve->GetMacro(Form("%s_%s", o->GetName(), what)); | |
307 | if (macro) macro->Exec(); | |
308 | } | |
309 | has = kTRUE; | |
310 | } | |
311 | ||
312 | //____________________________________________________________________ | |
313 | /** Refresh the display of the data */ | |
314 | void | |
315 | Refresh() | |
316 | { | |
317 | std::cout << "Drawing ... " << std::flush; | |
318 | RefreshOne(fEnableTracks, fHasTracks, "tracks"); | |
319 | RefreshOne(fEnableHits, fHasHits, "hits2"); | |
320 | RefreshOne(fEnableDigits, fHasDigits, "digits"); | |
321 | RefreshOne(fEnableRaw, fHasRaw, "raw"); | |
322 | RefreshOne(fEnableESD, fHasESD, "esd"); | |
323 | std::cout << "done" << std::endl; | |
324 | } | |
325 | //____________________________________________________________________ | |
326 | /** Toggle the diplay of some data */ | |
327 | void | |
328 | Toggle(Bool_t& what, const char* name) | |
329 | { | |
330 | what = !what; | |
331 | fCb->SetButtonState(name, what ? 1 : 0); | |
332 | if (!what) Reload(); | |
333 | Refresh(); | |
334 | } | |
335 | //____________________________________________________________________ | |
336 | /** Toggle the diplay the simulated hits */ | |
337 | void ToggleHits() { Toggle(fEnableHits, "Hits"); } | |
338 | //____________________________________________________________________ | |
339 | /** Toggle the diplay the simulated digits */ | |
340 | void ToggleDigits() { Toggle(fEnableDigits, "Digits"); } | |
341 | //____________________________________________________________________ | |
342 | /** Toggle the diplay the raw digits */ | |
343 | void ToggleRaw() { Toggle(fEnableRaw, "Raw"); } | |
344 | //____________________________________________________________________ | |
345 | /** Toggle the diplay the Event Summary Data */ | |
346 | void ToggleESD() { Toggle(fEnableESD, "ESD"); } | |
347 | //____________________________________________________________________ | |
348 | /** Toggle the diplay of tracks */ | |
349 | void ToggleTracks() { Toggle(fEnableTracks, "Tracks"); } | |
350 | //____________________________________________________________________ | |
351 | /** Pop-down both menues */ | |
352 | void Quit() | |
353 | { | |
354 | fCb->Hide(); | |
355 | fSelect->Hide(); | |
356 | fgInstance = 0; | |
357 | delete this; | |
358 | } | |
359 | //____________________________________________________________________ | |
360 | /** Get the static instance */ | |
361 | static Display* Instance() { | |
362 | if (!fgInstance) fgInstance = new Display(); | |
363 | return fgInstance; | |
364 | } | |
365 | protected: | |
366 | TControlBar* fCb; // Control bar | |
367 | TControlBar* fSelect; // Selection bar | |
368 | Bool_t fEnableHits; // Whether simulated hits are enabled | |
369 | Bool_t fEnableDigits; // Whether simulated digits are enabled | |
370 | Bool_t fEnableRaw; // Whehter raw data digits are enabled | |
371 | Bool_t fEnableESD; // Whehter Event Summary Data is enabled | |
372 | Bool_t fEnableTracks; // Whether tracks are shown | |
373 | Bool_t fHasHits; // Whether simulated hits are rendered | |
374 | Bool_t fHasDigits; // Whether simulated digits are rendered | |
375 | Bool_t fHasRaw; // Whether raw data digits are rendered | |
376 | Bool_t fHasESD; // Whether Event Summary Data is rendered | |
377 | Bool_t fHasTracks; // Whether tracks are rendered | |
378 | TList fEnabled; | |
379 | static Display* fgInstance; // Static singleton instance | |
380 | }; | |
381 | Display* Display::fgInstance = 0; | |
382 | ||
383 | ||
384 | //____________________________________________________________________ | |
385 | Display* display() | |
386 | { | |
387 | TGeoManager::Import("geometry.root"); | |
388 | ||
389 | Display* d = Display::Instance(); | |
390 | return d; | |
391 | ||
392 | } | |
393 | //____________________________________________________________________ | |
394 | // | |
395 | // EOF | |
396 | // |