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