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