Offline files disabled in online mode comletely. Problem with creation of Multi View...
[u/mrichter/AliRoot.git] / EVE / macros / alieve_online_new.C
CommitLineData
cb175407 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
bccf4634 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
32using namespace std;
33
cb175407 34class TEveProjectionManager;
35class TEveGeoShape;
36class TEveUtil;
37class AliTriggerAnalysis;
38class AliSysInfo;
39
bccf4634 40TH2D *V0StateHistogram;
cb175407 41Bool_t gCenterProjectionsAtPrimaryVertex = kFALSE;
42
13f4dce0 43Int_t g_pic_id = 0;
44Int_t g_pic_max = 100;
45TTimeStamp g_pic_prev(0, 0);
46
bccf4634 47void alieve_init_import_macros();
48
cb175407 49void alieve_online_new()
50{
13f4dce0 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
bccf4634 57 cout<<"Creating multiview...";
58 AliEveMultiView *multiView = new AliEveMultiView(kTRUE);
59 cout<<"created"<<endl;
572d0620 60
572d0620 61 Info("alieve_init", "Adding standard macros.");
62 TString hack = gSystem->pwd(); // Problem with TGFileBrowser cding
63 alieve_init_import_macros();
13f4dce0 64 gSystem->cd(Form("%s/../src/",gSystem->Getenv("ALICE_ROOT")));
bccf4634 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+");
13f4dce0 69 TEveUtil::LoadMacro("saveViews.C");
572d0620 70 gSystem->cd(hack);
5c7e574d 71 cout<<"Standard macros added"<<endl;
572d0620 72
bccf4634 73
572d0620 74 new AliEveEventManager("online", -1);
75 gEve->AddEvent(AliEveEventManager::GetMaster());
bccf4634 76 cout<<"Event manager created"<<endl;
572d0620 77
78 TEveUtil::AssertMacro("VizDB_scan.C");
79 gSystem->ProcessEvents();
bccf4634 80 cout<<"VizDB_scan loaded"<<endl;
13f4dce0 81 TEveBrowser *browser = gEve->GetBrowser();
572d0620 82 browser->ShowCloseTab(kFALSE);
bccf4634 83 cout<<"browser created"<<endl;
572d0620 84
572d0620 85 TEveUtil::LoadMacro("geom_gentle.C");
bccf4634 86 cout<<"geom gentle loaded"<<endl;
87
572d0620 88 multiView->InitGeomGentle(geom_gentle(),
89 geom_gentle_rphi(),
90 geom_gentle_rhoz(),
91 geom_gentle_rhoz());
bccf4634 92 cout<<"geom gentl inited"<<endl;
572d0620 93
13f4dce0 94 TEveUtil::LoadMacro("geom_gentle_trd.C");
95 multiView->InitGeomGentleTrd(geom_gentle_trd());
5c7e574d 96
13f4dce0 97 TEveUtil::LoadMacro("geom_gentle_muon.C");
98 multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);
5c7e574d 99
572d0620 100 //============================================================================
101 // Standard macros to execute -- not all are enabled by default.
102 //============================================================================
103
13f4dce0 104 printf("============ Setting macro executor ============\n");
572d0620 105
106 AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
bccf4634 107 printf("exec created\n");
108 /*
572d0620 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));
572d0620 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));
bccf4634 121 */
e339938c 122 // these macros were leaking:
bccf4634 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
e339938c 125 //
126
572d0620 127 // ???
128 // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C", "trd_detectors", "", kFALSE));
129 // trd_tracks disabled due to memory leaks
bccf4634 130 cout<<"macros added to exec"<<endl;
131
572d0620 132 //----------------------------------------------------------------------------
bccf4634 133 /* something is wrong here:
572d0620 134 slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
135 slot->StartEmbedding();
136 AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);
137 slot->StopEmbedding("DataSelection");
138 exewin->PopulateMacros();
bccf4634 139 */
572d0620 140 //============================================================================
141 // Final GUI setup
142 //============================================================================
143
572d0620 144 browser->GetTabRight()->SetTab(1);
145 browser->StartEmbedding(TRootBrowser::kBottom);
146 new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
147 browser->StopEmbedding("EventCtrl");
bccf4634 148
7dcdaa40 149 browser->MoveResize(0, 0, gClient->GetDisplayWidth(),gClient->GetDisplayHeight() - 32);
572d0620 150
572d0620 151 gEve->FullRedraw3D(kTRUE);
152 gSystem->ProcessEvents();
153
13f4dce0 154 // move and rotate sub-views
572d0620 155 TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();
156 TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();
157 TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();
158
13f4dce0 159 glv1->CurrentCamera().RotateRad(-0.4, 0.6);
160 glv2->CurrentCamera().Dolly(90, kFALSE, kFALSE);
161 glv3->CurrentCamera().Dolly(1700, kFALSE, kFALSE);
572d0620 162
163 AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");
164 gEve->FullRedraw3D();
165 gSystem->ProcessEvents();
166 gEve->Redraw3D(kTRUE);
167
13f4dce0 168 // set autoload by default
572d0620 169 AliEveEventManager::GetMaster()->SetAutoLoad(true);
cb175407 170}
171
cb175407 172void alieve_online_on_new_event()
173{
572d0620 174 AliSysInfo::AddStamp("on_new_event_start");
bccf4634 175
572d0620 176 if (AliEveEventManager::HasESD())
bccf4634 177 {
178 Double_t x[3] = { 0, 0, 0 };
179
572d0620 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);
572d0620 189
572d0620 190
bccf4634 191 TEveElement* top = gEve->GetCurrentEvent();
192
193 AliEveMultiView *mv = AliEveMultiView::Instance();
572d0620 194
bccf4634 195 mv->DestroyEventRPhi();
196 if (gCenterProjectionsAtPrimaryVertex){
197 mv->SetCenterRPhi(x[0], x[1], x[2]);
198 }
199 mv->ImportEventRPhi(top);
572d0620 200
bccf4634 201 mv->DestroyEventRhoZ();
202 if (gCenterProjectionsAtPrimaryVertex){
203 mv->SetCenterRhoZ(x[0], x[1], x[2]);
204 }
205 mv->ImportEventRhoZ(top);
572d0620 206
bccf4634 207 if (gCenterProjectionsAtPrimaryVertex)
208 mv->SetCenterMuon(x[0], x[1], x[2]);
209 mv->ImportEventMuon(top);
572d0620 210
f5e8dfd2 211
bccf4634 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();
572d0620 217
bccf4634 218 printf("Pre image dump: host='%s', delta=%f.\n",gSystem->HostName(), delta);
572d0620 219
bccf4634 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";
572d0620 225
bccf4634 226 printf("In image dump: file='%s'.\n", pic.Data());
572d0620 227
bccf4634 228 gEve->GetBrowser()->RaiseWindow();
229 gEve->FullRedraw3D();
230 gSystem->ProcessEvents();
572d0620 231
bccf4634 232 Int_t status;
572d0620 233
bccf4634 234 // create screenshots from OpenGL views
235 saveViews(pic.Data());
572d0620 236
bccf4634 237 // send screenshot to AMORE
238 cout<<"Sending:"<<TString::Format("SendImageToAmore %s %s %d",id.Data(), pic.Data(),AliEveEventManager::AssertESD()->GetRunNumber())<<endl;
f5e8dfd2 239
bccf4634 240 status = gSystem->Exec(TString::Format("SendImageToAmore %s %s %d",
241 id.Data(), pic.Data(),
242 AliEveEventManager::AssertESD()->GetRunNumber()));
572d0620 243
bccf4634 244 printf("Post AMORE reg -- status=%d, run=%d.\n", status,
245 AliEveEventManager::AssertESD()->GetRunNumber());
572d0620 246
bccf4634 247 if (++g_pic_id >= g_pic_max)
248 g_pic_id = 0;
249 g_pic_prev.Set();
250 }
251 }
572d0620 252 AliSysInfo::AddStamp("on_new_event_end");
cb175407 253}
254
255void alieve_init_import_macros()
256{
572d0620 257 // Put macros in the list of browsables, add a macro browser to
258 // top-level GUI.
259
bccf4634 260 TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
261
13f4dce0 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")));
bccf4634 266 gSystem->ExpandPathName(macdir);
13f4dce0 267 }
268
572d0620 269
270 TFolder* f = gEve->GetMacroFolder();
271 void* dirhandle = gSystem->OpenDirectory(macdir.Data());
272 if (dirhandle != 0)
cb175407 273 {
572d0620 274 char* filename;
275 TPMERegexp re("\\.C$");
276 TObjArray names;
bccf4634 277 while ((filename = (char*)(gSystem->GetDirEntry(dirhandle))) != 0)
572d0620 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 }
cb175407 289 }
572d0620 290 gSystem->FreeDirectory(dirhandle);
291
292 gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
293
cb175407 294 {
572d0620 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 }
cb175407 308 }
cb175407 309}