Missing macro's compilation added to alieve_online_new.C. Bug causing disappearing...
[u/mrichter/AliRoot.git] / EVE / macros / saveViews.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 // Author: Mihai Niculescu 2013
7
8
9 /*
10  * This script creates a collage containing all OpenGL views from a running AliEve
11  *
12  * Given Collage size (width, height), the size for all OpenGL
13  * views are computed using the same aspect ratio (width/height) as the main 3D View
14  */
15
16 #include <TASImage.h>
17 #include <TGLViewer.h>
18 #include <TEveViewer.h>
19 #include <TEveManager.h>
20 #include <TMath.h>
21 #include <TSystem.h>
22 #include <TTimeStamp.h>
23 #include <TEveElement.h>
24 #include <TIterator.h>
25 #include <TList.h>
26 #include <TROOT.h>
27
28 #include <STEER/ESD/AliESDEvent.h>
29 #include <STEER/ESD/AliESDRun.h>
30 #include <STEER/STEER/AliGRPObject.h>
31 #include <STEER/CDB/AliCDBEntry.h>
32 #include <STEER/CDB/AliCDBManager.h>
33 #include <RAW/RAWDatarec/AliRawReader.h>
34 #include <RAW/RAWDatabase/AliRawEventHeaderBase.h>
35 #include <EVE/EveBase/AliEveEventManager.h>
36
37 TString getEventInfo();
38
39 /***********Save all OpenGL views into one picture
40         compositeImgFileName - save final image to this file
41  showLiveBar - whether to show the LIVE bar, useful when not online (using offline)
42         width - of the collage image
43         height -of the collage image
44  */
45 void saveViews(const char* compositeImgFileName="views.png", Bool_t showLiveBar=kTRUE, Int_t width = 1440, Int_t height= 900)
46 {
47     Info("saveViews.C", "saving views to [%s]", compositeImgFileName);
48     
49     Int_t heightInfoBar = 65; // hold height of the Information bar
50     
51     TASImage* compositeImg=0; // this holds the final image
52     TASImage* tempImg=0; // temporary used for loading images
53     
54     TEveViewerList* viewers = gEve->GetViewers();
55     Int_t Nviewers = viewers->NumChildren()-2; // remark: 3D view is counted twice
56     
57     compositeImg = new TASImage(width, height);
58     
59     // 3D View size
60     Int_t width3DView = TMath::FloorNint((float)Nviewers*width/(float)(Nviewers+1)); // the width of the 3D view
61     Int_t height3DView= height-heightInfoBar; // the height of the 3D view
62     Float_t aspectRatio = (float)width3DView/(float)height3DView; // 3D View aspect ratio
63     
64     // Children View Size
65     Int_t heightChildView = TMath::FloorNint((float)height3DView/(float)Nviewers);
66     Int_t widthChildView  = TMath::FloorNint(aspectRatio*heightChildView); // has the same aspect ratio as the 3D view
67     
68     int index=0; // iteration counter
69     int x = width3DView; // x position of the child view
70     int y = 0;// y position of the child view
71     TString viewFilename; // save view to this file
72     
73     for(TEveElement::List_i i = (++viewers->BeginChildren()); i != viewers->EndChildren(); i++)
74     { // NB: this skips the first children (first 3D View)
75         TEveViewer* view = ((TEveViewer*)*i);
76         viewFilename = Form("view-%d.png", index);
77         
78         // Save OpenGL views in files
79         if(index==0){
80             view->GetGLViewer()->SavePictureUsingBB(viewFilename);//, width3DView, height3DView);
81         }
82         else {
83             view->GetGLViewer()->SavePictureUsingBB(viewFilename);//, widthChildView, heightChildView);
84         }
85         
86         tempImg = new TASImage(viewFilename);
87         
88         // copy view image in the composite image
89         if(index==0){
90             if(tempImg->GetWidth()>width3DView)
91             {
92                 tempImg->Crop((tempImg->GetWidth()-width3DView)/2,
93                                0,width3DView,height3DView);
94             }
95             if(tempImg->GetHeight()>height3DView)
96             {
97                 tempImg->Crop(0,(tempImg->GetHeight()-height3DView)/2,
98                               width3DView,height3DView);
99             }
100             
101             tempImg->CopyArea(compositeImg, 0,0, width3DView, height3DView);
102         }
103         else {
104             tempImg->Crop((tempImg->GetWidth()-widthChildView)/2,
105                           (tempImg->GetHeight()-heightChildView)/2,
106                           widthChildView,heightChildView);
107             tempImg->CopyArea(compositeImg, 0,0, widthChildView, heightChildView, x,y);
108             
109             // draw a border around child views
110             compositeImg->DrawRectangle(x,y, widthChildView, heightChildView, "#C0C0C0");
111         }
112         
113         /*
114          final touches inside loop
115          */
116         delete tempImg;
117         if(index>0) // skip 3D View
118             y+=heightChildView;
119         
120         index++;
121     }
122     
123     // Create a glow (bloom) effect
124     tempImg = (TASImage*)compositeImg->Clone("tempImg");
125     tempImg->Blur(10.0,10.0);
126     compositeImg->Merge(tempImg, "lighten");
127     delete tempImg; tempImg = 0;
128     
129     
130     // show LIVE bar
131     if(showLiveBar){
132         TTimeStamp ts;
133         TString tNow = ts.AsString("s"); // display date & time
134         
135         compositeImg->Gradient( 90, "#EAEAEA #D2D2D2 #FFFFFF", 0, 75, 0, 239, 95);
136         compositeImg->Gradient( 90, "#D6D6D6 #242424 #000000", 0, 155, 60, 152, 26);
137         compositeImg->BeginPaint();
138         compositeImg->DrawRectangle(50,0, 264, 94);
139         compositeImg->DrawText(162, 6, "LIVE", 70, "#FF2D00", "FreeSansBold.otf");
140         compositeImg->DrawText(162, 65, tNow, 16, "#FFFFFF", "arial.ttf");
141         compositeImg->EndPaint();
142         //include ALICE Logo
143         tempImg = new TASImage( Form("%s/../src/picts/alice_logo_2009_blue_80x80.png", gSystem->Getenv("ALICE_ROOT")) );
144         tempImg->Scale(64,64);
145         //tempImg->CopyArea(compositeImg, 0,0, 236, 319, 59, 4);
146         compositeImg->Merge(tempImg, "alphablend", 82, 4);
147         delete tempImg; tempImg = 0;
148     }
149     
150     // show Information bar
151     
152     AliESDEvent* esd =  AliEveEventManager::AssertESD();
153     ULong64_t triggerMask = esd->GetTriggerMask();
154     ULong64_t triggerMaskNext50 = esd->GetTriggerMaskNext50();
155     ULong64_t mask = 0b000001;
156     
157     TString triggerClasses1 = "";
158     TString triggerClasses2 = "";
159     TString triggerClasses3 = "";
160     int sw=0;
161     for(int i=0;i<50;i++)
162     {
163         if(mask&triggerMask)
164         {
165             if(strcmp(esd->GetESDRun()->GetTriggerClass(i),"")){
166                 if (sw==0)
167                 {
168                     triggerClasses1 += esd->GetESDRun()->GetTriggerClass(i);
169                     triggerClasses1 += "   ";
170                     sw=1;
171                 }
172                 else if(sw==1)
173                 {
174                     triggerClasses2 += esd->GetESDRun()->GetTriggerClass(i);
175                     triggerClasses2 += "   ";
176                     sw=2;
177                 }
178                 else if(sw==2)
179                 {
180                     triggerClasses3 += esd->GetESDRun()->GetTriggerClass(i);
181                     triggerClasses3 += "   ";
182                     sw=0;
183                 }
184             }
185         }
186         if(mask&triggerMaskNext50)
187         {
188             if(strcmp(esd->GetESDRun()->GetTriggerClass(i+50),""))
189             {
190                 if (sw==0)
191                 {
192                     triggerClasses1 += esd->GetESDRun()->GetTriggerClass(i+50);
193                     triggerClasses1 += "   ";
194                     sw=1;
195                 }
196                 else if(sw==1)
197                 {
198                     triggerClasses2 += esd->GetESDRun()->GetTriggerClass(i+50);
199                     triggerClasses2 += "   ";
200                     sw=2;
201                 }
202                 else if(sw==2)
203                 {
204                     triggerClasses3 += esd->GetESDRun()->GetTriggerClass(i+50);
205                     triggerClasses3 += "   ";
206                     sw=0;
207                 }
208             }
209         }
210         mask = mask<<1;
211     }
212     
213     TString stringInfo;
214     stringInfo = getEventInfo();
215     compositeImg->Gradient( 90, "#1B58BF #1D5CDF #0194FF", 0, 0, height-heightInfoBar, width, heightInfoBar);
216     compositeImg->BeginPaint();
217     compositeImg->DrawText(10, height-heightInfoBar+15, stringInfo, 28, "#FFFFFF", "FreeSansBold.otf");
218     compositeImg->DrawText(750, height-heightInfoBar+4,triggerClasses1, 16, "#FFFFFF", "FreeSansBold.otf");
219     compositeImg->DrawText(750, height-heightInfoBar+24,triggerClasses2, 16, "#FFFFFF", "FreeSansBold.otf");
220     compositeImg->DrawText(750, height-heightInfoBar+44,triggerClasses3, 16, "#FFFFFF", "FreeSansBold.otf");
221     compositeImg->EndPaint();
222     
223     
224     // write composite image to disk
225     compositeImg->CopyArea(compositeImg, 0,0, width, height);
226     compositeImg->WriteImage(compositeImgFileName);
227     
228     delete compositeImg;
229     
230     return;
231 }
232
233 // This function retrieves a string containing some information regarding the current event
234 TString getEventInfo()
235 {
236     // For general public please show as less or technical information as possible
237     
238     TString rawInfo, esdInfo;
239     
240     if (!AliEveEventManager::HasRawReader())
241     {
242         rawInfo = "";
243     }
244     else
245     {
246         AliRawReader* rawReader = AliEveEventManager::AssertRawReader();
247         if(!rawReader) return "";
248         rawInfo.Form("Run: %d  Event#: %d (%s)",
249                      rawReader->GetRunNumber(),
250                      AliEveEventManager::CurrentEventId(),
251                      AliRawEventHeaderBase::GetTypeName(rawReader->GetType())
252                      );
253         
254         return rawInfo;
255     }
256     
257     if (!AliEveEventManager::HasESD())
258     {
259         esdInfo = "";
260     }
261     else
262     {
263         AliESDEvent* esd =  AliEveEventManager::AssertESD();
264        
265         
266         
267         esdInfo.Form("Colliding: %s Run: %d  Event: %d (%s)",
268                      esd->GetESDRun()->GetBeamType(),
269                      esd->GetRunNumber(),
270                      esd->GetEventNumberInFile(),
271                      AliRawEventHeaderBase::GetTypeName(esd->GetEventType())
272                      );
273     }
274     
275     return esdInfo;
276 }