Offline files disabled in online mode comletely. Problem with creation of Multi View...
[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_muon.C+");
68     gROOT->ProcessLine(".L geom_gentle_trd.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     
159     glv1->CurrentCamera().RotateRad(-0.4, 0.6);
160     glv2->CurrentCamera().Dolly(90, kFALSE, kFALSE);
161     glv3->CurrentCamera().Dolly(1700, kFALSE, kFALSE);
162     
163     AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");
164     gEve->FullRedraw3D();
165     gSystem->ProcessEvents();
166     gEve->Redraw3D(kTRUE);
167     
168     // set autoload by default
169     AliEveEventManager::GetMaster()->SetAutoLoad(true);
170 }
171
172 void alieve_online_on_new_event()
173 {
174     AliSysInfo::AddStamp("on_new_event_start");
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         // const TString pichost("aldaqacrs3");
214         const TString pichost(gEnv->GetValue("AliEve.imageDumpHost", "localhost"));
215         TTimeStamp now;
216         Double_t delta = now.AsDouble() - g_pic_prev.AsDouble();
217      
218         printf("Pre image dump: host='%s', delta=%f.\n",gSystem->HostName(), delta);
219      
220         AliSysInfo::AddStamp("on_new_event_pic");
221         // if (pichost == gSystem->HostName() && delta >= 30)
222         {
223           TString id;      id.Form("online-viz-%03d", g_pic_id);
224           TString pic(id); pic += ".png";
225      
226           printf("In image dump: file='%s'.\n", pic.Data());
227      
228           gEve->GetBrowser()->RaiseWindow();
229           gEve->FullRedraw3D();
230           gSystem->ProcessEvents();
231      
232           Int_t status;
233      
234           // create screenshots from OpenGL views
235           saveViews(pic.Data());
236      
237           // send screenshot to AMORE
238           cout<<"Sending:"<<TString::Format("SendImageToAmore %s %s %d",id.Data(), pic.Data(),AliEveEventManager::AssertESD()->GetRunNumber())<<endl;
239
240           status = gSystem->Exec(TString::Format("SendImageToAmore %s %s %d",
241                                                  id.Data(), pic.Data(),
242                                                  AliEveEventManager::AssertESD()->GetRunNumber()));
243      
244           printf("Post AMORE reg -- status=%d, run=%d.\n", status,
245                  AliEveEventManager::AssertESD()->GetRunNumber());
246      
247           if (++g_pic_id >= g_pic_max)
248             g_pic_id = 0;
249           g_pic_prev.Set();
250         }
251       }
252     AliSysInfo::AddStamp("on_new_event_end");
253 }
254
255 void alieve_init_import_macros()
256 {
257     // Put macros in the list of browsables, add a macro browser to
258     // top-level GUI.
259     
260   TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
261
262     if (gSystem->Getenv("ALICE_ROOT") != 0)
263     {
264         gInterpreter->AddIncludePath(Form("%s/MUON", gSystem->Getenv("ALICE_ROOT")));
265         gInterpreter->AddIncludePath(Form("%s/MUON/mapping", gSystem->Getenv("ALICE_ROOT")));
266         gSystem->ExpandPathName(macdir);
267     }
268     
269     
270     TFolder* f = gEve->GetMacroFolder();
271     void* dirhandle = gSystem->OpenDirectory(macdir.Data());
272     if (dirhandle != 0)
273     {
274         char* filename;
275         TPMERegexp re("\\.C$");
276         TObjArray names;
277         while ((filename = (char*)(gSystem->GetDirEntry(dirhandle))) != 0)
278         {
279             if (re.Match(filename))
280                 names.AddLast(new TObjString(filename));
281         }
282         names.Sort();
283         
284         for (Int_t ii=0; ii<names.GetEntries(); ++ii)
285         {
286             TObjString * si = (TObjString*) names.At(ii);
287             f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data())));
288         }
289     }
290     gSystem->FreeDirectory(dirhandle);
291     
292     gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
293     
294     {
295         TEveBrowser   *br = gEve->GetBrowser();
296         TGFileBrowser *fb = 0;
297         fb = br->GetFileBrowser();
298         fb->GotoDir(macdir);
299         {
300             br->StartEmbedding(0);
301             fb = br->MakeFileBrowser();
302             fb->BrowseObj(f);
303             fb->Show();
304             br->StopEmbedding();
305             br->SetTabTitle("Macros", 0);
306             br->SetTab(0, 0);
307         }
308     }
309 }