2894625728c9bfcb6db1a7fd938c0f4c29472a85
[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 Bool_t gCenterProjectionsAtPrimaryVertex = kFALSE;
15
16 Int_t      g_pic_id  = 0;
17 Int_t      g_pic_max = 100;
18 TTimeStamp g_pic_prev(0, 0);
19
20 void alieve_online_new()
21 {
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     
28     
29     Info("alieve_init", "Adding standard macros.");
30     TString  hack = gSystem->pwd(); // Problem with TGFileBrowser cding
31     alieve_init_import_macros();
32     gSystem->cd(Form("%s/../src/",gSystem->Getenv("ALICE_ROOT")));
33     gROOT->ProcessLine(".L saveViews.C++");
34     TEveUtil::LoadMacro("saveViews.C");
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     
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     gROOT->ProcessLine(".L geom_gentle_trd.C++");
54     TEveUtil::LoadMacro("geom_gentle_trd.C");
55     multiView->InitGeomGentleTrd(geom_gentle_trd());
56     
57     gROOT->ProcessLine(".L geom_gentle_muon.C++");
58     TEveUtil::LoadMacro("geom_gentle_muon.C");
59     multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);
60     
61     
62     //============================================================================
63     // Standard macros to execute -- not all are enabled by default.
64     //============================================================================
65     
66     printf("============ Setting macro executor ============\n");
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));
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     
83     // these macros were leaking:
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
86     //
87     
88     // ???
89     // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C", "trd_detectors",         "", kFALSE));
90     // trd_tracks disabled due to memory leaks
91     
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     
104     browser->GetTabRight()->SetTab(1);
105     browser->StartEmbedding(TRootBrowser::kBottom);
106     new AliEveEventManagerWindow(AliEveEventManager::GetMaster());
107     browser->StopEmbedding("EventCtrl");
108  
109     browser->MoveResize(0, 0, gClient->GetDisplayWidth(),gClient->GetDisplayHeight() - 32);
110     
111     gEve->FullRedraw3D(kTRUE);
112     gSystem->ProcessEvents();
113     
114     // move and rotate sub-views
115     TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();
116     TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();
117     TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();
118     
119     glv1->CurrentCamera().RotateRad(-0.4, 0.6);
120     glv2->CurrentCamera().Dolly(90, kFALSE, kFALSE);
121     glv3->CurrentCamera().Dolly(1700, kFALSE, kFALSE);
122     
123     AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");
124     gEve->FullRedraw3D();
125     gSystem->ProcessEvents();
126     gEve->Redraw3D(kTRUE);
127     
128     // set autoload by default
129     AliEveEventManager::GetMaster()->SetAutoLoad(true);
130 }
131
132 void alieve_online_on_new_event()
133 {
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     
169     
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      
176      printf("Pre image dump: host='%s', delta=%f.\n",gSystem->HostName(), delta);
177      
178      AliSysInfo::AddStamp("on_new_event_pic");
179      // if (pichost == gSystem->HostName() && delta >= 30)
180      {
181        TString id;      id.Form("online-viz-%03d", g_pic_id);
182        TString pic(id); pic += ".png";
183      
184        printf("In image dump: file='%s'.\n", pic.Data());
185      
186        gEve->GetBrowser()->RaiseWindow();
187        gEve->FullRedraw3D();
188        gSystem->ProcessEvents();
189      
190        Int_t status;
191      
192        // create screenshots from OpenGL views
193        saveViews(pic.Data());
194      
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()));
201      
202        printf("Post AMORE reg -- status=%d, run=%d.\n", status,
203               AliEveEventManager::AssertESD()->GetRunNumber());
204      
205        if (++g_pic_id >= g_pic_max)
206          g_pic_id = 0;
207        g_pic_prev.Set();
208      }
209     AliSysInfo::AddStamp("on_new_event_end");
210 }
211
212 void alieve_init_import_macros()
213 {
214     // Put macros in the list of browsables, add a macro browser to
215     // top-level GUI.
216     
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     
225     
226     TFolder* f = gEve->GetMacroFolder();
227     void* dirhandle = gSystem->OpenDirectory(macdir.Data());
228     if (dirhandle != 0)
229     {
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         }
245     }
246     gSystem->FreeDirectory(dirhandle);
247     
248     gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
249     
250     {
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         }
264     }
265 }