small changes in configuration scripts for storage manager
[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
24 #include <STEER/ESD/AliESDEvent.h>
25 #include <STEER/ESD/AliESDRun.h>
26 #include <STEER/STEER/AliGRPObject.h>
27 #include <STEER/CDB/AliCDBEntry.h>
28 #include <STEER/CDB/AliCDBManager.h>
29 #include <RAW/AliRawReader.h>
30 #include <RAW/AliRawEventHeaderBase.h>
31 #include <EVE/EveBase/AliEveEventManager.h>
32
33 TString getEventInfo();
34
35 /***********Save all OpenGL views into one picture
36         compositeImgFileName - save final image to this file    
37   showLiveBar - whether to show the LIVE bar, useful when not online (using offline)
38         width - of the collage image
39         height -of the collage image
40 */
41 void saveViews(const char* compositeImgFileName="views.png", Bool_t showLiveBar=kTRUE, Int_t width = 1440, Int_t height= 900)
42 {
43         Info("saveViews.C", "saving views to [%s]", compositeImgFileName);
44
45         Int_t heightInfoBar = 65; // hold height of the Information bar
46         
47         TASImage* compositeImg=0; // this holds the final image
48         TASImage* tempImg=0; // temporary used for loading images
49         
50         TEveViewerList* viewers = gEve->GetViewers();
51         Int_t Nviewers = viewers->NumChildren()-2; // remark: 3D view is counted twice
52                 
53         compositeImg = new TASImage(width, height);
54                 
55         // 3D View size 
56         Int_t width3DView = TMath::FloorNint((float)Nviewers*width/(float)(Nviewers+1)); // the width of the 3D view
57         Int_t height3DView= height-heightInfoBar; // the height of the 3D view
58         Float_t aspectRatio = (float)width3DView/(float)height3DView; // 3D View aspect ratio
59                 
60         // Children View Size
61         Int_t heightChildView = TMath::FloorNint((float)height3DView/(float)Nviewers);
62         Int_t widthChildView  = TMath::FloorNint(aspectRatio*heightChildView); // has the same aspect ratio as the 3D view
63         
64         int index=0; // iteration counter
65         int x = width3DView; // x position of the child view
66         int y = 0;// y position of the child view
67         TString viewFilename; // save view to this file
68         for(TEveElement::List_i i = (++viewers->BeginChildren()); i != viewers->EndChildren(); i++){ // NB: this skips the first children (first 3D View)
69                 TEveViewer* view = ((TEveViewer*)*i);
70                 viewFilename = Form("view-%d.png", index);
71
72     // Save OpenGL views in files
73     if(index==0){
74                         view->GetGLViewer()->SavePictureUsingFBO(viewFilename, width3DView, height3DView);
75                 }
76                 else {
77                         view->GetGLViewer()->SavePictureUsingFBO(viewFilename, widthChildView, heightChildView);
78                 }
79                 
80                 tempImg = new TASImage(viewFilename);
81                 
82                 // copy view image in the composite image
83                 if(index==0){
84                         tempImg->CopyArea(compositeImg, 0,0, width3DView, height3DView);
85                 }
86                 else {
87                         tempImg->CopyArea(compositeImg, 0,0, widthChildView, heightChildView, x,y);
88                     
89     // draw a border around child views
90     compositeImg->DrawRectangle(x,y, widthChildView, heightChildView, "#C0C0C0");
91     }
92     
93     /*
94      final touches inside loop
95     */
96     delete tempImg;
97     if(index>0) // skip 3D View
98         y+=heightChildView;
99         
100     index++;
101    }
102    
103         // Create a glow (bloom) effect
104         tempImg = (TASImage*)compositeImg->Clone("tempImg");
105         tempImg->Blur(10.0,10.0);
106         compositeImg->Merge(tempImg, "lighten");
107         delete tempImg; tempImg = 0;
108
109  
110  // show LIVE bar
111  if(showLiveBar){
112         TTimeStamp ts;
113         TString tNow = ts.AsString("s"); // display date & time
114  
115         compositeImg->Gradient( 90, "#EAEAEA #D2D2D2 #FFFFFF", 0, 75, 0, 239, 95);
116         compositeImg->Gradient( 90, "#D6D6D6 #242424 #000000", 0, 155, 60, 152, 26);
117         compositeImg->BeginPaint();
118         compositeImg->DrawRectangle(50,0, 264, 94);
119         compositeImg->DrawText(162, 6, "LIVE", 70, "#FF2D00", "FreeSansBold.otf");
120         compositeImg->DrawText(162, 65, tNow, 16, "#FFFFFF", "arial.ttf");
121         compositeImg->EndPaint();
122         //include ALICE Logo
123         tempImg = new TASImage( Form("%s/picts/2012-Jul-04-4_Color_Logo_small_CB.png", gSystem->Getenv("ALICE_ROOT")) );
124         tempImg->Scale(64,86);
125         //tempImg->CopyArea(compositeImg, 0,0, 236, 319, 59, 4);
126         compositeImg->Merge(tempImg, "alphablend", 82, 4);
127         delete tempImg; tempImg = 0;
128         }
129         
130         // show Information bar
131         TString stringInfo;
132         stringInfo = getEventInfo();
133         compositeImg->Gradient( 90, "#1B58BF #1D5CDF #0194FF", 0, 0, height-heightInfoBar, width, heightInfoBar);
134         compositeImg->BeginPaint();
135         compositeImg->DrawText(10, height-heightInfoBar+15, stringInfo, 28, "#FFFFFF", "FreeSansBold.otf");
136         compositeImg->EndPaint();
137                 
138         
139         // write composite image to disk
140         compositeImg->CopyArea(compositeImg, 0,0, width, height);
141         compositeImg->WriteImage(compositeImgFileName);
142         
143         delete compositeImg;
144         
145         return;
146 }
147
148 // This function retrieves a string containing some information regarding the current event
149 TString getEventInfo()
150 {
151         // For general public please show as less or technical information as possible
152
153         TString rawInfo, esdInfo;
154
155   if (!AliEveEventManager::HasRawReader())
156   {
157     rawInfo = "";
158   }
159   else
160   {
161         AliRawReader* rawReader = AliEveEventManager::AssertRawReader();
162                 if(!rawReader) return "";
163                 rawInfo.Form("Run: %d  Event#: %d (%s)",
164                 rawReader->GetRunNumber(),
165                 AliEveEventManager::CurrentEventId(),
166                 AliRawEventHeaderBase::GetTypeName(rawReader->GetType())
167                 );
168                 
169          return rawInfo;
170   }
171
172   if (!AliEveEventManager::HasESD())
173   {
174     esdInfo = "";
175   }
176   else
177   {
178                 AliESDEvent* esd =  AliEveEventManager::AssertESD();
179
180                 esdInfo.Form("Colliding: %s Run: %d  Event: %d (%s)",
181                 esd->GetESDRun()->GetBeamType(),
182                 esd->GetRunNumber(),
183                 AliEveEventManager::CurrentEventId(),
184                              "PHYSICS_EVENT"
185                              /*AliRawEventHeaderBase::GetTypeName(esd->GetEventType())*/
186                 );
187   }
188
189   return esdInfo;
190 }