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