saveViews extended to print trigger classes, displaying of logo fixed. Cleanup of...
[u/mrichter/AliRoot.git] / EVE / macros / saveViews.C
CommitLineData
80f037d8 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 **************************************************************************/
13f4dce0 6// Author: Mihai Niculescu 2013
7
8
9/*
bab9ba53 10 * This script creates a collage containing all OpenGL views from a running AliEve
80f037d8 11 *
13f4dce0 12 * Given Collage size (width, height), the size for all OpenGL
80f037d8 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>
13f4dce0 23#include <TEveElement.h>
24#include <TIterator.h>
25#include <TList.h>
26#include <TROOT.h>
80f037d8 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>
13f4dce0 33#include <RAW/RAWDatarec/AliRawReader.h>
34#include <RAW/RAWDatabase/AliRawEventHeaderBase.h>
80f037d8 35#include <EVE/EveBase/AliEveEventManager.h>
36
37TString getEventInfo();
38
bab9ba53 39/***********Save all OpenGL views into one picture
13f4dce0 40 compositeImgFileName - save final image to this file
41 showLiveBar - whether to show the LIVE bar, useful when not online (using offline)
bab9ba53 42 width - of the collage image
43 height -of the collage image
13f4dce0 44 */
bab9ba53 45void saveViews(const char* compositeImgFileName="views.png", Bool_t showLiveBar=kTRUE, Int_t width = 1440, Int_t height= 900)
80f037d8 46{
13f4dce0 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()->SavePictureUsingFBO(viewFilename, width3DView, height3DView);
81 }
82 else {
83 view->GetGLViewer()->SavePictureUsingFBO(viewFilename, widthChildView, heightChildView);
84 }
85
86 tempImg = new TASImage(viewFilename);
87
88 // copy view image in the composite image
89 if(index==0){
90 tempImg->CopyArea(compositeImg, 0,0, width3DView, height3DView);
91 }
92 else {
93 tempImg->CopyArea(compositeImg, 0,0, widthChildView, heightChildView, x,y);
94
95 // draw a border around child views
96 compositeImg->DrawRectangle(x,y, widthChildView, heightChildView, "#C0C0C0");
97 }
98
99 /*
100 final touches inside loop
101 */
102 delete tempImg;
103 if(index>0) // skip 3D View
104 y+=heightChildView;
105
106 index++;
80f037d8 107 }
108
13f4dce0 109 // Create a glow (bloom) effect
110 tempImg = (TASImage*)compositeImg->Clone("tempImg");
111 tempImg->Blur(10.0,10.0);
112 compositeImg->Merge(tempImg, "lighten");
113 delete tempImg; tempImg = 0;
114
115
116 // show LIVE bar
117 if(showLiveBar){
118 TTimeStamp ts;
119 TString tNow = ts.AsString("s"); // display date & time
120
121 compositeImg->Gradient( 90, "#EAEAEA #D2D2D2 #FFFFFF", 0, 75, 0, 239, 95);
122 compositeImg->Gradient( 90, "#D6D6D6 #242424 #000000", 0, 155, 60, 152, 26);
123 compositeImg->BeginPaint();
124 compositeImg->DrawRectangle(50,0, 264, 94);
125 compositeImg->DrawText(162, 6, "LIVE", 70, "#FF2D00", "FreeSansBold.otf");
126 compositeImg->DrawText(162, 65, tNow, 16, "#FFFFFF", "arial.ttf");
127 compositeImg->EndPaint();
128 //include ALICE Logo
b686c9db 129 tempImg = new TASImage( Form("%s/../src/picts/alice_logo_2009_blue_80x80.png", gSystem->Getenv("ALICE_ROOT")) );
130 tempImg->Scale(64,64);
13f4dce0 131 //tempImg->CopyArea(compositeImg, 0,0, 236, 319, 59, 4);
132 compositeImg->Merge(tempImg, "alphablend", 82, 4);
133 delete tempImg; tempImg = 0;
134 }
135
136 // show Information bar
b686c9db 137
138 AliESDEvent* esd = AliEveEventManager::AssertESD();
139 TString triggerClasses1 = "";
140 TString triggerClasses2 = "";
141 bool sw=false;
142 for(int i=0;i<100;i++)
143 {
144 if(strcmp(esd->GetESDRun()->GetTriggerClass(i),"")){
145 if (sw)
146 {
147 triggerClasses1 += esd->GetESDRun()->GetTriggerClass(i);
148 triggerClasses1 += " ";
149 sw=false;
150 }
151 else
152 {
153 triggerClasses2 += esd->GetESDRun()->GetTriggerClass(i);
154 triggerClasses2 += " ";
155 sw=true;
156 }
157 }
158 }
159
13f4dce0 160 TString stringInfo;
161 stringInfo = getEventInfo();
162 compositeImg->Gradient( 90, "#1B58BF #1D5CDF #0194FF", 0, 0, height-heightInfoBar, width, heightInfoBar);
163 compositeImg->BeginPaint();
164 compositeImg->DrawText(10, height-heightInfoBar+15, stringInfo, 28, "#FFFFFF", "FreeSansBold.otf");
b686c9db 165 compositeImg->DrawText(700, height-heightInfoBar+15,triggerClasses1, 18, "#FFFFFF", "FreeSansBold.otf");
166 compositeImg->DrawText(700, height-heightInfoBar+35,triggerClasses2, 18, "#FFFFFF", "FreeSansBold.otf");
13f4dce0 167 compositeImg->EndPaint();
168
169
170 // write composite image to disk
171 compositeImg->CopyArea(compositeImg, 0,0, width, height);
172 compositeImg->WriteImage(compositeImgFileName);
173
174 delete compositeImg;
175
176 return;
80f037d8 177}
178
bab9ba53 179// This function retrieves a string containing some information regarding the current event
80f037d8 180TString getEventInfo()
181{
13f4dce0 182 // For general public please show as less or technical information as possible
183
184 TString rawInfo, esdInfo;
185
186 if (!AliEveEventManager::HasRawReader())
187 {
188 rawInfo = "";
189 }
190 else
191 {
192 AliRawReader* rawReader = AliEveEventManager::AssertRawReader();
193 if(!rawReader) return "";
194 rawInfo.Form("Run: %d Event#: %d (%s)",
195 rawReader->GetRunNumber(),
196 AliEveEventManager::CurrentEventId(),
197 AliRawEventHeaderBase::GetTypeName(rawReader->GetType())
198 );
199
200 return rawInfo;
201 }
202
203 if (!AliEveEventManager::HasESD())
204 {
205 esdInfo = "";
206 }
207 else
208 {
209 AliESDEvent* esd = AliEveEventManager::AssertESD();
b686c9db 210
211
13f4dce0 212
213 esdInfo.Form("Colliding: %s Run: %d Event: %d (%s)",
214 esd->GetESDRun()->GetBeamType(),
215 esd->GetRunNumber(),
216 AliEveEventManager::CurrentEventId(),
b686c9db 217 AliRawEventHeaderBase::GetTypeName(esd->GetEventType())
13f4dce0 218 );
219 }
220
221 return esdInfo;
80f037d8 222}