b9f74435bc115a0f391a1cb9a583341b1c2ce06c
[u/mrichter/AliRoot.git] / EVE / macros / alieve_online_new.C
1 /**************************************************************************
2  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
3  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
4  * full copyright notice.                                                 *
5  **************************************************************************/
6
7 class TEveProjectionManager;
8 class TEveGeoShape;
9 class TEveUtil;
10 class AliTriggerAnalysis;
11 class AliSysInfo;
12
13 TH2D* V0StateHistogram;
14
15 Bool_t gCenterProjectionsAtPrimaryVertex = kFALSE;
16
17 void alieve_online_new()
18 {
19     printf("alieve_online_init() ...\n");
20  
21  if (gSystem->Getenv("ALICE_ROOT") != 0)
22  {
23          gInterpreter->AddIncludePath(Form("%s/MUON", gSystem->Getenv("ALICE_ROOT")));
24          gInterpreter->AddIncludePath(Form("%s/MUON/mapping", gSystem->Getenv("ALICE_ROOT")));
25  }
26   
27    AliEveEventManager::SetCdbUri("local://$ALICE_ROOT/OCDB");
28   
29   Info("alieve_init", "Adding standard macros.");
30   TString  hack = gSystem->pwd(); // Problem with TGFileBrowser cding
31   alieve_init_import_macros();
32   gSystem->cd(hack);
33   
34   new AliEveEventManager("online", -1);
35   //AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event()");
36   gEve->AddEvent(AliEveEventManager::GetMaster());
37   
38   
39   TEveUtil::AssertMacro("VizDB_scan.C");
40   
41   gSystem->ProcessEvents();
42    
43   
44   
45  
46   
47   AliEveMacroExecutor *exec  = AliEveEventManager::GetMaster()->GetExecutor();
48   TEveBrowser         *browser = gEve->GetBrowser();
49   browser->ShowCloseTab(kFALSE);
50   
51
52   // Gentle-geom loading changes gGeoManager.
53   //TEveGeoManagerHolder mgrRestore;
54
55   AliEveMultiView *multiView = new AliEveMultiView(kTRUE);
56
57   TEveUtil::LoadMacro("geom_gentle.C");
58   multiView->InitGeomGentle(geom_gentle(),
59                              geom_gentle_rphi(), 
60                              geom_gentle_rhoz(),
61                              geom_gentle_rhoz());
62
63     //These macros crashes on mac os. To be checked
64     
65   //TEveUtil::LoadMacro("geom_gentle_trd.C");
66   //multiView->InitGeomGentleTrd(geom_gentle_trd());
67
68   //TEveUtil::LoadMacro("geom_gentle_muon.C");
69   //multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);
70
71   //============================================================================
72   // Standard macros to execute -- not all are enabled by default.
73   //============================================================================
74
75   
76    printf("============ Setting macro executor\n");
77
78   AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
79
80   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex",             "",                kTRUE));
81   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse",     "",                kTRUE));
82   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box",         "kFALSE, 3, 3, 3", kFALSE));
83   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_spd",         "",                kTRUE));
84   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_spd", "",                kTRUE));
85   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_spd",     "kFALSE, 3, 3, 3", kFALSE));
86   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_tpc",         "",                kFALSE));
87   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_tpc", "",                kFALSE));
88   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_tpc",     "kFALSE, 3, 3, 3", kFALSE));
89
90   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus ITS",   "its_clusters.C",   "its_clusters"));
91   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TPC",   "tpc_clusters.C",   "tpc_clusters"));
92   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TRD",   "trd_clusters.C",   "trd_clusters"));
93   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TOF",   "tof_clusters.C",   "tof_clusters"));
94   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus HMPID", "hmpid_clusters.C", "hmpid_clusters"));
95   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus MUON",  "muon_clusters.C",  "muon_clusters"));
96
97   
98   exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG EMCAL",   "emcal_digits.C",   "emcal_digits"));
99   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ITS",     "its_raw.C",     "its_raw"));
100   //  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TPC",     "tpc_raw.C",     "tpc_raw"));
101   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TOF",     "tof_raw.C",     "tof_raw"));
102   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW VZERO",   "vzero_raw.C",   "vzero_raw", "", kFALSE));
103   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ACORDE",  "acorde_raw.C",  "acorde_raw", "", kFALSE));
104   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW MUON",    "muon_raw.C",  "muon_raw"));
105   exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW FMD",     "fmd_raw.C",     "fmd_raw"));
106  
107
108   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks",             "", kFALSE));
109   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_MI",          "", kFALSE));
110   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track MUON", "esd_muon_tracks.C", "esd_muon_tracks",        "kTRUE,kFALSE", kTRUE));
111
112     
113     // these macros were leaking:
114   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_by_category", "", kTRUE));// just a little
115   exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC FMD",        "fmd_esd.C",           "fmd_esd",                "", kTRUE));//huge leak
116     //
117     
118     
119     
120   // ???
121   // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C", "trd_detectors",         "", kFALSE));
122   // trd_tracks disabled due to memory leaks
123
124   //----------------------------------------------------------------------------
125
126   slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
127   slot->StartEmbedding();
128   AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);
129   slot->StopEmbedding("DataSelection");
130   exewin->PopulateMacros();
131
132   //============================================================================
133   // Final GUI setup
134   //============================================================================
135
136   browser->GetTabRight()->SetTab(1);
137
138   browser->StartEmbedding(TRootBrowser::kBottom);
139   new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
140   browser->StopEmbedding("EventCtrl");
141
142   browser->MoveResize(0, 0, gClient->GetDisplayWidth(),
143                       gClient->GetDisplayHeight() - 32);
144
145   gEve->GetViewers()->SwitchColorSet();
146   gEve->FullRedraw3D(kTRUE);
147         gSystem->ProcessEvents();
148
149   TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();
150   TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();
151   TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();
152
153   glv1->CurrentCamera().RotateRad(-0.4, -1.8);
154   glv2->CurrentCamera().Dolly(450, kFALSE, kFALSE);
155   glv3->CurrentCamera().Dolly(1500, kFALSE, kFALSE);
156
157 //////
158   AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");
159    ///////
160   gEve->FullRedraw3D();
161   gSystem->ProcessEvents();
162   gEve->Redraw3D(kTRUE);
163
164   AliEveEventManager::GetMaster()->SetAutoLoad(true);
165 }
166
167
168 Int_t      g_pic_id  = 0;
169 Int_t      g_pic_max = 100;
170 TTimeStamp g_pic_prev(0, 0);
171
172 void alieve_online_on_new_event()
173 {
174         AliSysInfo::AddStamp("on_new_event_start");
175
176         Double_t x[3] = { 0, 0, 0 };
177
178         if (AliEveEventManager::HasESD())
179         {
180                 AliESDEvent* esd = AliEveEventManager::AssertESD();
181                 esd->GetPrimaryVertex()->GetXYZ(x);
182
183                 TTimeStamp ts(esd->GetTimeStamp());
184                 TString win_title("Eve Main Window -- Timestamp: ");
185                 win_title += ts.AsString("s");
186                 win_title += "; Event # in ESD file: ";
187                 win_title += esd->GetEventNumberInFile();
188                 gEve->GetBrowser()->SetWindowName(win_title);
189         }
190
191         TEveElement* top = gEve->GetCurrentEvent();
192
193         AliEveMultiView *mv = AliEveMultiView::Instance();
194
195         //mv->DestroyEventRPhi();
196         if (gCenterProjectionsAtPrimaryVertex)
197                 mv->SetCenterRPhi(x[0], x[1], x[2]);
198         mv->ImportEventRPhi(top);
199
200         //mv->DestroyEventRhoZ();
201         if (gCenterProjectionsAtPrimaryVertex)
202                 mv->SetCenterRhoZ(x[0], x[1], x[2]);
203         mv->ImportEventRhoZ(top);
204
205         if (gCenterProjectionsAtPrimaryVertex)
206                 mv->SetCenterMuon(x[0], x[1], x[2]);
207         mv->ImportEventMuon(top);
208  // Register image to amore.
209   // const TString pichost("aldaqacrs3");
210   const TString pichost(gEnv->GetValue("AliEve.imageDumpHost", "localhost"));
211   TTimeStamp now;
212   Double_t delta = now.AsDouble() - g_pic_prev.AsDouble();
213
214   printf("Pre image dump: host='%s', delta=%f.\n",
215          gSystem->HostName(), delta);
216
217   AliSysInfo::AddStamp("on_new_event_pic");
218   if (pichost == gSystem->HostName() && delta >= 30)
219   {
220     TString id;      id.Form("online-viz-%03d", g_pic_id);
221     TString pic(id); pic += ".png";
222
223     printf("In image dump: file='%s'.\n", pic.Data());
224
225     gEve->GetBrowser()->RaiseWindow();
226     gEve->FullRedraw3D();
227     gSystem->ProcessEvents();
228
229     Int_t status;
230
231     // create screenshots from OpenGL views
232     TEveUtil::LoadMacro("saveViews.C");
233     saveViews(pic.Data()); 
234
235     // send screenshot to AMORE
236     status = gSystem->Exec(TString::Format("SendImageToAmore %s %s %d",
237                           id.Data(), pic.Data(),
238                           AliEveEventManager::AssertESD()->GetRunNumber()));
239
240     printf("Post AMORE reg -- status=%d, run=%d.\n", status,
241            AliEveEventManager::AssertESD()->GetRunNumber());
242
243     if (++g_pic_id >= g_pic_max)
244       g_pic_id = 0;
245     g_pic_prev.Set();
246   }
247   AliSysInfo::AddStamp("on_new_event_end");
248 }
249
250 void alieve_init_import_macros()
251 {
252   // Put macros in the list of browsables, add a macro browser to
253   // top-level GUI.
254
255   TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
256   gSystem->ExpandPathName(macdir);
257
258   TFolder* f = gEve->GetMacroFolder();
259   void* dirhandle = gSystem->OpenDirectory(macdir.Data());
260   if (dirhandle != 0)
261   {
262     char* filename;
263     TPMERegexp re("\\.C$");
264     TObjArray names;
265     while ((filename = gSystem->GetDirEntry(dirhandle)) != 0)
266     {
267       if (re.Match(filename))
268         names.AddLast(new TObjString(filename));
269     }
270     names.Sort();
271
272     for (Int_t ii=0; ii<names.GetEntries(); ++ii)
273     {
274       TObjString * si = (TObjString*) names.At(ii);
275        f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data())));
276     }
277   }
278   gSystem->FreeDirectory(dirhandle);
279
280   gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
281
282   {
283     TEveBrowser   *br = gEve->GetBrowser();
284     TGFileBrowser *fb = 0;
285     fb = br->GetFileBrowser();
286     fb->GotoDir(macdir);
287     {
288       br->StartEmbedding(0);
289       fb = br->MakeFileBrowser();
290       fb->BrowseObj(f);
291       fb->Show();
292       br->StopEmbedding();
293       br->SetTabTitle("Macros", 0);
294       br->SetTab(0, 0);
295     }
296   }
297 }