Missing macro's compilation added to alieve_online_new.C. Bug causing disappearing...
[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 #include "AliEveEventManager.h"
8 #include "AliEveEventManagerEditor.h"
9 #include "AliEveMultiView.h"
10 #include "AliEveMacroExecutor.h"
11 #include "AliEveMacro.h"
12 #include "AliSysInfo.h"
13
14 #include <TH2D.h>
15 #include <TTimeStamp.h>
16 #include <TROOT.h>
17 #include <TEveManager.h>
18 #include <TEveBrowser.h>
19 #include <TEveMacro.h>
20 #include <TGTab.h>
21 #include <TGFileBrowser.h>
22 #include <TInterpreter.h>
23 #include <TEnv.h>
24 #include <TPRegexp.h>
25 #include <TFolder.h>
26 #include <TSystem.h>
27 #include <TSystemDirectory.h>
28 #include <TList.h>
29
30 #include <iostream>
31
32 using namespace std;
33
34 class TEveProjectionManager;
35 class TEveGeoShape;
36 class TEveUtil;
37 class AliTriggerAnalysis;
38 class AliSysInfo;
39
40 TH2D *V0StateHistogram;
41 Bool_t gCenterProjectionsAtPrimaryVertex = kFALSE;
42
43 Int_t      g_pic_id  = 0;
44 Int_t      g_pic_max = 100;
45 TTimeStamp g_pic_prev(0, 0);
46
47 void alieve_init_import_macros();
48
49 void alieve_online_new()
50 {
51     // set OCDB path:
52     //AliEveEventManager::SetCdbUri("local://$ALICE_ROOT/OCDB"); // default OCDB from aliroot
53     //AliEveEventManager::SetCdbUri("local:///local/OCDB/2013"); // OCDB snapshot for particular run
54     AliEveEventManager::SetCdbUri("local:///local/cdb");         // current OCDB snapshot
55     //AliEveEventManager::SetCdbUri("raw://");                   // reading OCDB from alien
56     
57     cout<<"Creating multiview...";
58     AliEveMultiView *multiView = new AliEveMultiView(kTRUE);
59     cout<<"created"<<endl;
60     
61     Info("alieve_init", "Adding standard macros.");
62     TString  hack = gSystem->pwd(); // Problem with TGFileBrowser cding
63     alieve_init_import_macros();
64     gSystem->cd(Form("%s/../src/",gSystem->Getenv("ALICE_ROOT")));
65     gROOT->ProcessLine(".L saveViews.C+");
66     gROOT->ProcessLine(".L geom_gentle.C+");
67     gROOT->ProcessLine(".L geom_gentle_trd.C+");
68     gROOT->ProcessLine(".L geom_gentle_muon.C+");
69     TEveUtil::LoadMacro("saveViews.C");
70     gSystem->cd(hack);
71     cout<<"Standard macros added"<<endl;
72     
73
74     new AliEveEventManager("online", -1);
75     gEve->AddEvent(AliEveEventManager::GetMaster());
76     cout<<"Event manager created"<<endl;
77     
78     TEveUtil::AssertMacro("VizDB_scan.C");
79     gSystem->ProcessEvents();
80     cout<<"VizDB_scan loaded"<<endl;
81     TEveBrowser *browser = gEve->GetBrowser();
82     browser->ShowCloseTab(kFALSE);
83     cout<<"browser created"<<endl;
84     
85     TEveUtil::LoadMacro("geom_gentle.C");
86     cout<<"geom gentle loaded"<<endl;
87     
88     multiView->InitGeomGentle(geom_gentle(),
89                               geom_gentle_rphi(),
90                               geom_gentle_rhoz(),
91                               geom_gentle_rhoz());
92     cout<<"geom gentl inited"<<endl;
93     
94     TEveUtil::LoadMacro("geom_gentle_trd.C");
95     multiView->InitGeomGentleTrd(geom_gentle_trd());
96
97     TEveUtil::LoadMacro("geom_gentle_muon.C");
98     multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);
99  
100     //============================================================================
101     // Standard macros to execute -- not all are enabled by default.
102     //============================================================================
103     
104     printf("============ Setting macro executor ============\n");
105     
106     AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
107     printf("exec created\n");
108     /*
109     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex",             "",                kTRUE));
110     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse",     "",                kTRUE));
111     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box",         "kFALSE, 3, 3, 3", kFALSE));
112     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_spd",         "",                kTRUE));
113     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_spd", "",                kTRUE));
114     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_spd",     "kFALSE, 3, 3, 3", kFALSE));
115     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_tpc",         "",                kFALSE));
116     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_tpc", "",                kFALSE));
117     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_tpc",     "kFALSE, 3, 3, 3", kFALSE));
118     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks",             "", kFALSE));
119     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_MI",          "", kFALSE));
120     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track MUON", "esd_muon_tracks.C", "esd_muon_tracks",        "kTRUE,kFALSE", kTRUE));
121     */
122     // these macros were leaking:
123     exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track","esd_tracks.C",        "esd_tracks_by_category", "", kTRUE));// just a little
124     //exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC FMD",        "fmd_esd.C",           "fmd_esd",                "", kTRUE));//huge leak
125     //
126     
127     // ???
128     // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C", "trd_detectors",         "", kFALSE));
129     // trd_tracks disabled due to memory leaks
130     cout<<"macros added to exec"<<endl;
131
132     //----------------------------------------------------------------------------
133     /* something is wrong here:
134     slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
135     slot->StartEmbedding();
136     AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);
137     slot->StopEmbedding("DataSelection");
138     exewin->PopulateMacros();
139     */
140     //============================================================================
141     // Final GUI setup
142     //============================================================================
143     
144     browser->GetTabRight()->SetTab(1);
145     browser->StartEmbedding(TRootBrowser::kBottom);
146     new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
147     browser->StopEmbedding("EventCtrl");
148     
149     browser->MoveResize(0, 0, gClient->GetDisplayWidth(),gClient->GetDisplayHeight() - 32);
150     
151     gEve->FullRedraw3D(kTRUE);
152     gSystem->ProcessEvents();
153     
154     // move and rotate sub-views
155     TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();
156     TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();
157     TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();
158     TGLViewer *glv4 = multiView->GetMuonView()->GetGLViewer();
159     
160     glv1->CurrentCamera().RotateRad(-0.4, 0.6);
161     glv2->CurrentCamera().Dolly(90, kFALSE, kFALSE);
162     glv3->CurrentCamera().Dolly(2300, kFALSE, kFALSE);
163     glv4->CurrentCamera().Dolly(1, kFALSE, kFALSE);
164     
165     AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");
166     gEve->FullRedraw3D();
167     gSystem->ProcessEvents();
168     gEve->Redraw3D(kTRUE);
169     
170     // set autoload by default
171     AliEveEventManager::GetMaster()->SetAutoLoad(true);
172 }
173
174 void alieve_online_on_new_event()
175 {
176     if (AliEveEventManager::HasESD())
177       {
178         Double_t x[3] = { 0, 0, 0 };
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         }
199         mv->ImportEventRPhi(top);
200     
201         mv->DestroyEventRhoZ();
202         if (gCenterProjectionsAtPrimaryVertex){
203           mv->SetCenterRhoZ(x[0], x[1], x[2]);
204         }
205         mv->ImportEventRhoZ(top);
206     
207         if (gCenterProjectionsAtPrimaryVertex)
208           mv->SetCenterMuon(x[0], x[1], x[2]);
209         mv->ImportEventMuon(top);
210     
211         
212         // Register image to amore.
213           TString id;      id.Form("online-viz-%03d", g_pic_id);
214           TString pic(id); pic += ".png";
215      
216           //printf("In image dump: file='%s'.\n", pic.Data());
217      
218           gEve->GetBrowser()->RaiseWindow();
219           gEve->FullRedraw3D();
220           gSystem->ProcessEvents();
221  
222           // create screenshots from OpenGL views
223           saveViews(pic.Data());
224      
225           // send screenshot to AMORE
226           int status = gSystem->Exec(Form("SendImageToAmore %s %s %d",id.Data(),pic.Data(),esd->GetRunNumber()));
227             printf("Post AMORE reg -- status=%d, run=%d.\n", status, esd->GetRunNumber());
228      
229           if (++g_pic_id >= g_pic_max) g_pic_id = 0;
230           g_pic_prev.Set();
231       }
232 }
233
234 void alieve_init_import_macros()
235 {
236     // Put macros in the list of browsables, add a macro browser to
237     // top-level GUI.
238     
239   TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
240
241     if (gSystem->Getenv("ALICE_ROOT") != 0)
242     {
243         gInterpreter->AddIncludePath(Form("%s/MUON", gSystem->Getenv("ALICE_ROOT")));
244         gInterpreter->AddIncludePath(Form("%s/MUON/mapping", gSystem->Getenv("ALICE_ROOT")));
245         gSystem->ExpandPathName(macdir);
246     }
247     
248     
249     TFolder* f = gEve->GetMacroFolder();
250     void* dirhandle = gSystem->OpenDirectory(macdir.Data());
251     if (dirhandle != 0)
252     {
253         char* filename;
254         TPMERegexp re("\\.C$");
255         TObjArray names;
256         while ((filename = (char*)(gSystem->GetDirEntry(dirhandle))) != 0)
257         {
258             if (re.Match(filename))
259                 names.AddLast(new TObjString(filename));
260         }
261         names.Sort();
262         
263         for (Int_t ii=0; ii<names.GetEntries(); ++ii)
264         {
265             TObjString * si = (TObjString*) names.At(ii);
266             f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data())));
267         }
268     }
269     gSystem->FreeDirectory(dirhandle);
270     
271     gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
272     
273     {
274         TEveBrowser   *br = gEve->GetBrowser();
275         TGFileBrowser *fb = 0;
276         fb = br->GetFileBrowser();
277         fb->GotoDir(macdir);
278         {
279             br->StartEmbedding(0);
280             fb = br->MakeFileBrowser();
281             fb->BrowseObj(f);
282             fb->Show();
283             br->StopEmbedding();
284             br->SetTabTitle("Macros", 0);
285             br->SetTab(0, 0);
286         }
287     }
288 }