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