5058a3f1d668b3507d294d397d313816b2500cb5
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveConfigManager.cxx
1 // $Id$
2 // Author: Matevz Tadel 2009
3
4 /**************************************************************************
5  * Copyright(c) 1998-2009, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliEveConfigManager.h"
11
12 #include <AliEveMultiView.h>
13 #include <TEveManager.h>
14 #include <TEveBrowser.h>
15 #include <TEveWindow.h>
16 #include <TGFileDialog.h>
17 #include <TGMenu.h>
18
19 #include "AliEveEventManager.h"
20 #include "AliEveMacroExecutor.h"
21 #include "AliEveMacroExecutorWindow.h"
22 #include "AliEveMacro.h"
23
24 //Storage Manager:
25 #ifdef ZMQ
26 #include "AliStorageAdministratorPanelListEvents.h"
27 #include "AliStorageAdministratorPanelMarkEvent.h"
28 #endif
29
30 class AliEveMacroExecutor;
31 class TEveProjectionManager;
32 class TEveGeoShape;
33 class TEveUtil;
34
35 #include <TSystem.h>
36 #include <TPRegexp.h>
37 #include <RVersion.h>
38
39 //______________________________________________________________________________
40 // Full description of AliEveConfigManager
41 //
42
43 ClassImp(AliEveConfigManager)
44
45 AliEveConfigManager* AliEveConfigManager::fgMaster = 0;
46
47 namespace
48 {
49  enum EAliEveMenu_e
50  {
51          kAEMDefault, kAEMScreen, kAEMProjector, kAEMNotransparency, kAEMTransparentDark, kAEMTransparentLight, kAEMTransparentMonoDark, kAEMTransparentMonoLight, kAEMGreen, kAEMBright, kAEMYellow, kAEMTpc, kAEMAll, kAEM3d, kAEMRphi, kAEMRhoz, kAEMAllhr, kAEM3dhr, kAEMRphihr, kAEMRhozhr, kAEMSavemacros, kAEMLoadmacros, kAEMSave, kAEMOpen, kAEMSetDefault, kAEMResiduals,  kAEMCuts, kAEMVectors, kAEMGui, kStorageListEvents, kStorageMarkEvent
52  };
53 }
54  
55 //______________________________________________________________________________
56 AliEveConfigManager* AliEveConfigManager::InitializeMaster()
57 {
58   // Get main instance.
59
60   static const TEveException kEH("AliEveConfigManager::InitializeMaster ");
61
62   if (fgMaster)
63     throw kEH + "Master already initialized.";
64
65   fgMaster = new AliEveConfigManager;
66   return fgMaster;
67 }
68
69 //______________________________________________________________________________
70 AliEveConfigManager* AliEveConfigManager::GetMaster()
71 {
72   // Get main instance.
73
74   static const TEveException kEH("AliEveConfigManager::GetMaster ");
75
76   if (!fgMaster)
77     throw kEH + "Master not initialized.";
78
79   return fgMaster;
80 }
81
82 //______________________________________________________________________________
83 AliEveConfigManager::AliEveConfigManager() :
84   TObject(),
85   fAnalysisPopup(0),
86   fAliEvePopup(0),
87   fAliEveGeometries(0),
88   fAliEvePictures(0),
89   fAliEvePicturesHR(0),
90   fAliEveDataSelection(0),
91   fAliEveVizDBs(0),
92   fLoadCheck(kFALSE)
93 {
94   // Constructor.
95   // Expected TEveManager is already initialized.
96
97
98   fAliEveGeometries = new TGPopupMenu(gClient->GetRoot());
99   fAliEveGeometries->AddEntry("&Default", kAEMDefault);
100   fAliEveGeometries->AddEntry("&Screen", kAEMScreen);
101   fAliEveGeometries->AddEntry("&Projector", kAEMProjector);
102
103   fAliEveGeometries->AddSeparator();
104
105   fAliEveGeometries->AddEntry("&Low transparency", kAEMNotransparency);
106
107   fAliEveGeometries->AddSeparator();
108
109   fAliEveGeometries->AddEntry("&Transparent screen", kAEMTransparentDark);
110   fAliEveGeometries->AddEntry("&Transparent projector", kAEMTransparentLight);
111   fAliEveGeometries->AddEntry("&Transparent mono dark", kAEMTransparentMonoDark);
112   fAliEveGeometries->AddEntry("&Transparent mono light", kAEMTransparentMonoLight);
113
114   fAliEveGeometries->AddSeparator();
115
116   fAliEveGeometries->AddEntry("&First collision setup", kAEMGreen);
117   fAliEveGeometries->AddEntry("&Bright", kAEMBright);
118
119   fAliEveGeometries->AddSeparator();
120
121   fAliEveGeometries->AddEntry("&TPC Yellow", kAEMYellow);
122   fAliEveGeometries->AddEntry("&TPC Blue", kAEMTpc);
123
124   fAliEveGeometries->AddSeparator();
125
126   fAliEvePictures = new TGPopupMenu(gClient->GetRoot());
127
128   fAliEvePictures->AddEntry("&Save all views", kAEMAll);
129   fAliEvePictures->AddEntry("&Save 3D View",   kAEM3d);
130   fAliEvePictures->AddEntry("&Save RPhi View", kAEMRphi);
131   fAliEvePictures->AddEntry("&Save RhoZ View", kAEMRhoz);
132
133   fAliEvePictures->AddSeparator();
134
135   fAliEvePicturesHR = new TGPopupMenu(gClient->GetRoot());
136
137   fAliEvePicturesHR->AddEntry("&Save all views HR", kAEMAllhr);
138   fAliEvePicturesHR->AddEntry("&Save 3D View HR",   kAEM3dhr);
139   fAliEvePicturesHR->AddEntry("&Save RPhi View HR", kAEMRphihr);
140   fAliEvePicturesHR->AddEntry("&Save RhoZ View HR", kAEMRhozhr);
141
142   fAliEvePicturesHR->AddSeparator();
143
144   fAliEveDataSelection = new TGPopupMenu(gClient->GetRoot());
145
146   fAliEveDataSelection->AddEntry("&Save Data Selection macros", kAEMSavemacros);
147   fAliEveDataSelection->AddEntry("&Load Data Selection macros",   kAEMLoadmacros);
148
149   fAliEveDataSelection->AddSeparator();
150
151   fAliEveVizDBs = new TGPopupMenu(gClient->GetRoot());
152
153   fAliEveVizDBs->AddEntry("&Save VizDB", kAEMSave);
154   fAliEveVizDBs->AddEntry("&Load VizDB", kAEMOpen);
155
156   fAliEveVizDBs->AddSeparator();
157
158   fAliEvePopup = new TGPopupMenu(gClient->GetRoot());
159   fAliEvePopup->AddEntry("&Set Default Settings", kAEMSetDefault);
160   fAliEvePopup->AddSeparator();
161   fAliEvePopup->AddPopup("&Geometries/VizDBs", fAliEveGeometries);
162   fAliEvePopup->AddSeparator();
163   fAliEvePopup->AddPopup("&Pictures", fAliEvePictures);
164   fAliEvePopup->AddSeparator();
165   fAliEvePopup->AddPopup("&PicturesHR", fAliEvePicturesHR);
166   fAliEvePopup->AddSeparator();
167   fAliEvePopup->AddPopup("&VizDBs",  fAliEveVizDBs);
168   fAliEvePopup->AddSeparator();
169   fAliEvePopup->AddPopup("&DataSelection", fAliEveDataSelection);
170   fAliEvePopup->AddSeparator();
171
172   fAnalysisPopup = new TGPopupMenu(gClient->GetRoot());  
173 //  fAnalysisPopup->AddEntry("&Residuals", kAEMResiduals);
174 //  fAnalysisPopup->AddSeparator();
175   fAnalysisPopup->AddEntry("&Cuts", kAEMCuts);
176   fAnalysisPopup->AddSeparator();
177   fAnalysisPopup->AddEntry("&Momentum vectors", kAEMVectors);
178   fAnalysisPopup->AddSeparator();
179 //  fAnalysisPopup->AddEntry("&Gui Mode", kAEMGui);
180 //  fAnalysisPopup->AddSeparator();
181
182   fAliEvePopup->Connect("Activated(Int_t)", "AliEveConfigManager",
183                         this, "AliEvePopupHandler(Int_t)");
184
185   fAnalysisPopup->Connect("Activated(Int_t)", "AliEveConfigManager",
186                         this, "AliEvePopupHandler(Int_t)");
187
188   //Storage Manager:
189   fStoragePopup = new TGPopupMenu(gClient->GetRoot());
190 #ifdef ZMQ
191   fStoragePopup->AddEntry("&List events",kStorageListEvents);
192   fStoragePopup->AddEntry("&Mark event",kStorageMarkEvent);
193 #endif
194
195   fStoragePopup->Connect("Activated(Int_t)","AliEveConfigManager",
196                          this, "AliEvePopupHandler(Int_t)");
197   
198   fLoadCheck = kFALSE;
199
200 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,25,4)
201   TGMenuBar *mBar = gEve->GetBrowser()->GetMenuBar();
202   mBar->AddPopup("&AliEve", fAliEvePopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
203   ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
204   mBar->AddPopup("&Tools", fAnalysisPopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
205     ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
206    mBar->AddPopup("&Storage Manager",fStoragePopup,new TGLayoutHints(kLHintsTop | kLHintsLeft,0,4,0,0));
207   
208   gEve->GetBrowser()->GetTopMenuFrame()->Layout();
209 #else
210   // Uber hack as TRootBrowser does not provede manu-bar getter.
211   TGFrameElement   *xxFE = (TGFrameElement*)   gEve->GetBrowser()->GetList()->First();
212   TGCompositeFrame *xxCF = (TGCompositeFrame*) xxFE->fFrame;
213   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
214   xxCF = (TGCompositeFrame*) xxFE->fFrame;
215   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
216   xxCF = (TGCompositeFrame*) xxFE->fFrame;
217   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
218   TGMenuBar *mBar = (TGMenuBar*) xxFE->fFrame;
219   mBar->AddPopup("&AliEve", fAliEvePopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
220   ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
221   mBar->AddPopup("&Tools", fAnalysisPopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
222   ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
223   mBar->AddPopup("&Storage Manager",fStoragePopup,new TGLayoutHints(kLHintsTop | kLHintsLeft,0,4,0,0));
224     ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
225 #endif
226 }
227
228 //==============================================================================
229
230 #include <iostream>
231 #include <fstream>
232 #include <string>
233 #include <sstream>
234
235 using namespace std;
236
237 namespace
238 {
239 const char *gMacroSaveAsTypes[] = {"CINT Macro", "*.C",
240                                    0, 0}; //for saving/loading macros
241
242 const char *gPictureSaveAsTypes[] = {"PNG Image", "*.png",
243                                    0, 0}; //for saving pictures
244
245 }
246
247 void AliEveConfigManager::ConnectEventManagerSignals()
248 {
249     AliEveEventManager *manager = AliEveEventManager::GetCurrent();
250     manager->Connect("StorageManagerOk()","AliEveConfigManager",this,"StorageManagerChangedState(=1)");
251     manager->Connect("StorageManagerDown()","AliEveConfigManager",this,"StorageManagerChangedState(=0)");
252 }
253
254 void AliEveConfigManager::AliEvePopupHandler(Int_t id)
255 {
256   // Handle user selections from AliEve popup.
257
258   static const TEveException kEH("AliEveConfigManager::AliEvePopupHandler ");
259
260   switch (id)
261   {
262
263     case kAEMDefault: //default geometry and VizDB
264     {
265       AliEveMultiView *mv = AliEveMultiView::Instance();
266
267       mv->DestroyAllGeometries(); //destroy RPhi and Rhoz geometries before putting new
268
269       gEve->LoadVizDB("geom_gentle_default.C", kTRUE, kTRUE); //loading geometry
270
271       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE); //loading VizDB
272
273       if(!gEve->GetViewers()->UseLightColorSet())
274         gEve->GetViewers()->SwitchColorSet(); //white background
275
276       gEve->FullRedraw3D();   
277       
278       break;
279     }
280
281     case kAEMScreen: //default geometry with black background
282     {
283       AliEveMultiView *mv = AliEveMultiView::Instance();
284
285       mv->DestroyAllGeometries();
286
287       gEve->LoadVizDB("geom_gentle_default.C", kTRUE, kTRUE);
288
289       gEve->LoadVizDB("VizDB_scan_screen.C", kTRUE, kTRUE);
290
291       if(gEve->GetViewers()->UseLightColorSet())
292         gEve->GetViewers()->SwitchColorSet();
293
294       gEve->FullRedraw3D();    
295
296       break;
297     }
298
299     case kAEMProjector: //default geometry with white background
300     {
301       AliEveMultiView *mv = AliEveMultiView::Instance();
302
303       mv->DestroyAllGeometries();
304
305       gEve->LoadVizDB("geom_gentle_projector.C", kTRUE, kTRUE);
306
307       gEve->LoadVizDB("VizDB_scan_projector.C", kTRUE, kTRUE);
308
309       if(!gEve->GetViewers()->UseLightColorSet())
310         gEve->GetViewers()->SwitchColorSet();
311
312       gEve->FullRedraw3D();    
313
314       break;
315     }
316
317     case kAEMNotransparency: //default geometry with low transparency (5%)
318     {
319       AliEveMultiView *mv = AliEveMultiView::Instance();
320
321       mv->DestroyAllGeometries();
322
323       gEve->LoadVizDB("geom_gentle_notransparency.C", kTRUE, kTRUE);
324
325       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
326
327       if(!gEve->GetViewers()->UseLightColorSet())
328         gEve->GetViewers()->SwitchColorSet();
329
330       gEve->FullRedraw3D();    
331
332       break;
333     }
334
335
336     case kAEMTransparentDark: //default geometry with black background, high transparency (80%)
337     {
338       AliEveMultiView *mv = AliEveMultiView::Instance();
339
340       mv->DestroyAllGeometries();
341
342       gEve->LoadVizDB("geom_gentle_transparent.C", kTRUE, kTRUE);
343
344       gEve->LoadVizDB("VizDB_scan_transparentdark.C", kTRUE, kTRUE);
345
346       if(gEve->GetViewers()->UseLightColorSet())
347         gEve->GetViewers()->SwitchColorSet();
348
349       gEve->FullRedraw3D();   
350
351       break;
352     }
353
354     case kAEMTransparentLight: //default geometry with white background, high transparency (80%)
355     {
356       AliEveMultiView *mv = AliEveMultiView::Instance();
357
358       mv->DestroyAllGeometries();
359
360       gEve->LoadVizDB("geom_gentle_transparent.C", kTRUE, kTRUE);
361
362       gEve->LoadVizDB("VizDB_scan_transparentlight.C", kTRUE, kTRUE);
363
364       if(!gEve->GetViewers()->UseLightColorSet())
365         gEve->GetViewers()->SwitchColorSet();
366
367       gEve->FullRedraw3D();    
368
369       break;
370     }
371
372     case kAEMTransparentMonoDark:
373     {
374       AliEveMultiView *mv = AliEveMultiView::Instance();
375
376       mv->DestroyAllGeometries();
377
378       gEve->LoadVizDB("geom_gentle_transparentdark.C", kTRUE, kTRUE);
379
380       gEve->LoadVizDB("VizDB_scan_transparentdark.C", kTRUE, kTRUE);
381
382       if(gEve->GetViewers()->UseLightColorSet())
383         gEve->GetViewers()->SwitchColorSet();
384
385       gEve->FullRedraw3D();   
386
387       break;
388     }
389
390     case kAEMTransparentMonoLight:
391     {
392       AliEveMultiView *mv = AliEveMultiView::Instance();
393
394       mv->DestroyAllGeometries();
395
396       gEve->LoadVizDB("geom_gentle_transparentlight.C", kTRUE, kTRUE);
397
398       gEve->LoadVizDB("VizDB_scan_transparentlight.C", kTRUE, kTRUE);
399
400       if(!gEve->GetViewers()->UseLightColorSet())
401         gEve->GetViewers()->SwitchColorSet();
402
403       gEve->FullRedraw3D();    
404
405       break;
406     }
407
408     case kAEMGreen:
409     {
410       AliEveMultiView *mv = AliEveMultiView::Instance();
411
412       mv->DestroyAllGeometries();
413
414       gEve->LoadVizDB("geom_gentle_green.C", kTRUE, kTRUE);
415
416       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
417
418       if(!gEve->GetViewers()->UseLightColorSet())
419         gEve->GetViewers()->SwitchColorSet();
420
421       gEve->FullRedraw3D();    
422
423       break;
424     }
425
426     case kAEMBright:
427     {
428       AliEveMultiView *mv = AliEveMultiView::Instance();
429
430       mv->DestroyAllGeometries();
431
432       gEve->LoadVizDB("geom_gentle_bright.C", kTRUE, kTRUE);
433
434       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
435
436       if(gEve->GetViewers()->UseLightColorSet())
437         gEve->GetViewers()->SwitchColorSet();
438
439       gEve->FullRedraw3D();
440
441       break;
442     }
443
444     case kAEMYellow:
445     {
446       AliEveMultiView *mv = AliEveMultiView::Instance();
447
448       mv->DestroyAllGeometries();
449
450       gEve->LoadVizDB("geom_gentle_yellow.C", kTRUE, kTRUE);
451
452       gEve->LoadVizDB("VizDB_scan_yellow.C", kTRUE, kTRUE);
453
454       if(!gEve->GetViewers()->UseLightColorSet())
455         gEve->GetViewers()->SwitchColorSet();
456
457       gEve->FullRedraw3D();    
458
459       break;
460     }
461
462     case kAEMTpc:
463     {
464       AliEveMultiView *mv = AliEveMultiView::Instance();
465
466       mv->DestroyAllGeometries();
467
468       gEve->LoadVizDB("geom_gentle_tpc.C", kTRUE, kTRUE);
469
470       gEve->LoadVizDB("VizDB_scan_tpc.C", kTRUE, kTRUE);
471
472       if(!gEve->GetViewers()->UseLightColorSet())
473         gEve->GetViewers()->SwitchColorSet();
474
475       gEve->FullRedraw3D();
476
477       break;
478     }
479
480     case kAEMAll: //saving pictures from all three viewers
481     {
482       
483      TGFileInfo fi;
484      fi.fFileTypes   = gPictureSaveAsTypes;
485      fi.fIniDir      = StrDup(""); // current directory
486      fi.fFileTypeIdx = 0;
487      fi.fOverwrite   = kTRUE;
488      new TGFileDialog(gClient->GetDefaultRoot(),
489      gEve->GetMainWindow(), kFDSave, &fi); // dialog 
490      if (!fi.fFilename) return;
491
492      TPMERegexp filere(".*/([^/]+$)");
493      if (filere.Match(fi.fFilename) != 2)
494      {
495        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
496        return;
497      }
498
499      TString file1(filere[1]);
500      TString file2(filere[1]);
501      TString file3(filere[1]);
502      
503      if (!file1.EndsWith(".png"))
504        file1 += "_3D.png"; // adding extensions
505        
506      if (!file2.EndsWith(".png"))
507        file2 += "_RPhi.png"; // adding extensions
508        
509      if (!file3.EndsWith(".png"))
510        file3 += "_RhoZ.png"; // adding extensions
511
512      gSystem->ChangeDirectory(fi.fIniDir);
513       
514      printf("Saving...\n");
515
516      TEveViewerList *viewers = gEve->GetViewers();
517      TEveElement::List_i i = viewers->BeginChildren();
518      i++;
519      TEveViewer* view3d = ((TEveViewer*)*i);
520      view3d->GetGLViewer()->SavePicture(file1); // saving pictures
521      i++;
522      TEveViewer* viewrphi = ((TEveViewer*)*i);
523      viewrphi->GetGLViewer()->SavePicture(file2); // saving pictures
524      i++;
525      TEveViewer* viewrhoz = ((TEveViewer*)*i);
526      viewrhoz->GetGLViewer()->SavePicture(file3); // saving pictures
527      
528      printf("Done.\n"); 
529       
530       break;
531     }
532     
533     case kAEM3d: // saving only 3d view
534     {
535       
536      TGFileInfo fi;
537      fi.fFileTypes   = gPictureSaveAsTypes;
538      fi.fIniDir      = StrDup(""); // current directory
539      fi.fFileTypeIdx = 0;
540      fi.fOverwrite   = kTRUE;
541      new TGFileDialog(gClient->GetDefaultRoot(),
542      gEve->GetMainWindow(), kFDSave, &fi);
543      if (!fi.fFilename) return;
544
545      TPMERegexp filere(".*/([^/]+$)");
546      if (filere.Match(fi.fFilename) != 2)
547      {
548        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
549        return;
550      }
551
552      TString file1(filere[1]);
553      
554      if (!file1.EndsWith(".png"))
555        file1 += ".png";
556
557      gSystem->ChangeDirectory(fi.fIniDir);
558       
559      printf("Saving...\n");
560
561      TEveViewerList *viewers = gEve->GetViewers();
562      TEveElement::List_i i = viewers->BeginChildren();
563      i++;
564      TEveViewer* view3d = ((TEveViewer*)*i);
565      view3d->GetGLViewer()->SavePicture(file1);
566      
567      printf("Done.\n"); 
568       
569       break;
570     }
571     
572      case kAEMRphi: // saving only RPhi view
573     {
574       
575      TGFileInfo fi;
576      fi.fFileTypes   = gPictureSaveAsTypes;
577      fi.fIniDir      = StrDup(""); // current directory
578      fi.fFileTypeIdx = 0;
579      fi.fOverwrite   = kTRUE;
580      new TGFileDialog(gClient->GetDefaultRoot(),
581      gEve->GetMainWindow(), kFDSave, &fi);
582      if (!fi.fFilename) return;
583
584      TPMERegexp filere(".*/([^/]+$)");
585      if (filere.Match(fi.fFilename) != 2)
586      {
587        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
588        return;
589      }
590
591      TString file1(filere[1]);
592      
593      if (!file1.EndsWith(".png"))
594        file1 += ".png";
595      
596      gSystem->ChangeDirectory(fi.fIniDir);
597       
598      printf("Saving...\n");
599
600      TEveViewerList *viewers = gEve->GetViewers();
601      TEveElement::List_i i = viewers->BeginChildren();
602      i++;
603      i++;
604      TEveViewer* viewrphi = ((TEveViewer*)*i);
605      viewrphi->GetGLViewer()->SavePicture(file1);
606      
607      printf("Done.\n"); 
608       
609       break;
610     }
611     
612      case kAEMRhoz: // saving only RhoZ view
613     {
614     
615      TGFileInfo fi;
616      fi.fFileTypes   = gPictureSaveAsTypes;
617      fi.fIniDir      = StrDup(""); // current directory
618      fi.fFileTypeIdx = 0;
619      fi.fOverwrite   = kTRUE;
620      new TGFileDialog(gClient->GetDefaultRoot(),
621      gEve->GetMainWindow(), kFDSave, &fi);
622      if (!fi.fFilename) return;
623
624      TPMERegexp filere(".*/([^/]+$)");
625      if (filere.Match(fi.fFilename) != 2)
626      {
627        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
628        return;
629      }
630
631      TString file1(filere[1]);
632        
633      if (!file1.EndsWith(".png"))
634        file1 += ".png";
635
636      gSystem->ChangeDirectory(fi.fIniDir);
637      
638      printf("Saving...\n");
639
640      TEveViewerList *viewers = gEve->GetViewers();
641      TEveElement::List_i i = viewers->BeginChildren();
642      i++;
643      i++;
644      i++;
645      TEveViewer* viewrhoz = ((TEveViewer*)*i);
646      viewrhoz->GetGLViewer()->SavePicture(file1);
647      
648      printf("Done.\n"); 
649       
650       break;
651     }
652
653     case kAEMAllhr: // saving all three views in high resolution
654     {
655       
656      TGFileInfo fi;
657      fi.fFileTypes   = gPictureSaveAsTypes;
658      fi.fIniDir      = StrDup(""); // current directory
659      fi.fFileTypeIdx = 0;
660      fi.fOverwrite   = kTRUE;
661      new TGFileDialog(gClient->GetDefaultRoot(),
662      gEve->GetMainWindow(), kFDSave, &fi);
663      if (!fi.fFilename) return;
664
665      TPMERegexp filere(".*/([^/]+$)");
666      if (filere.Match(fi.fFilename) != 2)
667      {
668        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
669        return;
670      }
671
672      TString file1(filere[1]);
673      TString file2(filere[1]);
674      TString file3(filere[1]);
675      
676      if (!file1.EndsWith(".png"))
677        file1 += "_3D.png";
678        
679      if (!file2.EndsWith(".png"))
680        file2 += "_RPhi.png";
681        
682      if (!file3.EndsWith(".png"))
683        file3 += "_RhoZ.png";
684
685      gSystem->ChangeDirectory(fi.fIniDir);
686       
687      printf("Saving...\n");
688
689      TEveViewerList *viewers = gEve->GetViewers();
690      TEveElement::List_i i = viewers->BeginChildren();
691      i++;
692      TEveViewer* view3d = ((TEveViewer*)*i);
693      view3d->GetGLViewer()->SavePictureScale(file1,6.0); // getting high resolution
694      i++;
695      TEveViewer* viewrphi = ((TEveViewer*)*i);
696      viewrphi->GetGLViewer()->SavePictureScale(file2,6.0);
697      i++;
698      TEveViewer* viewrhoz = ((TEveViewer*)*i);
699      viewrhoz->GetGLViewer()->SavePictureScale(file3,6.0);
700      
701      printf("Done.\n"); 
702       
703       break;
704     }
705     
706     case kAEM3dhr: // saving only 3d view in high resolution
707     {
708       
709      TGFileInfo fi;
710      fi.fFileTypes   = gPictureSaveAsTypes;
711      fi.fIniDir      = StrDup(""); // current directory
712      fi.fFileTypeIdx = 0;
713      fi.fOverwrite   = kTRUE;
714      new TGFileDialog(gClient->GetDefaultRoot(),
715      gEve->GetMainWindow(), kFDSave, &fi);
716      if (!fi.fFilename) return;
717
718      TPMERegexp filere(".*/([^/]+$)");
719      if (filere.Match(fi.fFilename) != 2)
720      {
721        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
722        return;
723      }
724
725      TString file1(filere[1]);
726      
727      if (!file1.EndsWith(".png"))
728        file1 += ".png";
729
730      gSystem->ChangeDirectory(fi.fIniDir);
731       
732      printf("Saving...\n");
733
734      TEveViewerList *viewers = gEve->GetViewers();
735      TEveElement::List_i i = viewers->BeginChildren();
736      i++;
737      TEveViewer* view3d = ((TEveViewer*)*i);
738      view3d->GetGLViewer()->SavePictureScale(file1,4.0);
739      
740      printf("Done.\n"); 
741       
742       break;
743     }
744     
745      case kAEMRphihr: // saving only RPhi view in high resolution
746     {
747       
748      TGFileInfo fi;
749      fi.fFileTypes   = gPictureSaveAsTypes;
750      fi.fIniDir      = StrDup(""); // current directory
751      fi.fFileTypeIdx = 0;
752      fi.fOverwrite   = kTRUE;
753      new TGFileDialog(gClient->GetDefaultRoot(),
754      gEve->GetMainWindow(), kFDSave, &fi);
755      if (!fi.fFilename) return;
756
757      TPMERegexp filere(".*/([^/]+$)");
758      if (filere.Match(fi.fFilename) != 2)
759      {
760        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
761        return;
762      }
763
764      TString file1(filere[1]);
765      
766      if (!file1.EndsWith(".png"))
767        file1 += ".png";
768      
769      gSystem->ChangeDirectory(fi.fIniDir);
770       
771      printf("Saving...\n");
772
773      TEveViewerList *viewers = gEve->GetViewers();
774      TEveElement::List_i i = viewers->BeginChildren();
775      i++;
776      i++;
777      TEveViewer* viewrphi = ((TEveViewer*)*i);
778      viewrphi->GetGLViewer()->SavePictureScale(file1,4.0);
779      
780      printf("Done.\n"); 
781       
782       break;
783     }
784     
785      case kAEMRhozhr: // saving only RhoZ view in high resolution
786     {
787     
788      TGFileInfo fi;
789      fi.fFileTypes   = gPictureSaveAsTypes;
790      fi.fIniDir      = StrDup(""); // current directory
791      fi.fFileTypeIdx = 0;
792      fi.fOverwrite   = kTRUE;
793      new TGFileDialog(gClient->GetDefaultRoot(),
794      gEve->GetMainWindow(), kFDSave, &fi);
795      if (!fi.fFilename) return;
796
797      TPMERegexp filere(".*/([^/]+$)");
798      if (filere.Match(fi.fFilename) != 2)
799      {
800        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
801        return;
802      }
803
804      TString file1(filere[1]);
805        
806      if (!file1.EndsWith(".png"))
807        file1 += ".png";
808
809      gSystem->ChangeDirectory(fi.fIniDir);
810      
811      printf("Saving...\n");
812
813      TEveViewerList *viewers = gEve->GetViewers();
814      TEveElement::List_i i = viewers->BeginChildren();
815      i++;
816      i++;
817      i++;
818      TEveViewer* viewrhoz = ((TEveViewer*)*i);
819      viewrhoz->GetGLViewer()->SavePictureScale(file1,4.0);
820      
821      printf("Done.\n"); 
822       
823       break;
824     }
825
826      case kAEMSavemacros:// Saving Data Selection macros
827     {
828
829       AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
830
831       exec->SaveAddedMacros();
832
833       break;
834     }
835  
836    case kAEMLoadmacros://Loading Data Selection macros
837     {
838
839       TEveBrowser *browser = gEve->GetBrowser();
840       browser->ShowCloseTab(kFALSE);
841
842       if(fLoadCheck)
843         browser->RemoveTab(TRootBrowser::kRight, 5);//remove the tab with previous DataSelection window
844       else
845         browser->RemoveTab(TRootBrowser::kRight, 2);
846
847
848       TGFileInfo fi;
849       fi.fFileTypes   = gMacroSaveAsTypes;
850       fi.fIniDir      = StrDup(""); // current directory
851       fi.fFileTypeIdx = 0;
852       fi.fOverwrite   = kTRUE;
853       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDOpen, &fi);//dialog
854       if (!fi.fFilename) return;
855
856       TPMERegexp filere(".*/([^/]+$)");
857       if (filere.Match(fi.fFilename) != 2)
858       {
859         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
860         return;
861       }
862       printf("Loading...\n");
863
864       TString file(filere[1]);
865       gSystem->ChangeDirectory(fi.fIniDir);
866
867       TEveUtil::Macro(file);//run macro
868
869       AliEveEventManager *eman = AliEveEventManager::GetMaster();//reload event (gEve->Refresh() crashes)
870       Int_t ev = eman->GetEventId();
871       eman->Close();
872       eman->Open();
873       eman->GotoEvent(ev);
874
875       printf("Done.\n");
876
877       fLoadCheck = kTRUE;
878
879       break;
880
881     }
882
883     case kAEMSave://saving VizDB
884     {
885       TGFileInfo fi;
886       fi.fFileTypes   = gMacroSaveAsTypes;
887       fi.fIniDir      = StrDup(""); // current directory
888       fi.fFileTypeIdx = 0;
889       fi.fOverwrite   = kTRUE;
890       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDSave, &fi);
891       if (!fi.fFilename) return;
892
893       TPMERegexp filere(".*/([^/]+$)");
894       if (filere.Match(fi.fFilename) != 2)
895       {
896         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
897         return;
898       }
899       printf("Saving...\n");
900
901       TString file(filere[1]);
902       if (!file.EndsWith(".C"))
903         file += ".C";
904       gSystem->ChangeDirectory(fi.fIniDir);
905       gEve->SaveVizDB(file);
906
907 //Last line "gEve->SaveVizDB(file);" gives macro with many unnecessary
908 //lines like "x038->SetMinPt(0);" tahat are not interpreted properly later
909
910       string text;
911       string all;
912
913       ifstream myfile1(file);
914       if(myfile1.is_open())
915         {
916         while(!myfile1.eof())
917           {
918             getline(myfile1,text);
919             TString check(text);
920             if(!(check.EndsWith("MinPt(0);")||check.EndsWith("MaxPt(0);")
921                ||check.EndsWith("LimPt(0);")||check.EndsWith("MinP(0);")
922                ||check.EndsWith("MaxP(0);")||check.EndsWith("LimP(0);")))
923               {
924               all += text; //Cut off unnecessary lines and bring everything together
925               all += "\n";
926               }
927           }
928         myfile1.close();
929         }
930
931       ofstream myfile2(file); //Replacing old file with the one without "bad" lines
932       myfile2 << all;
933       myfile2.close();
934
935       printf("Done.\n");
936       break;
937
938     }
939
940     case kAEMOpen://Opening VizDB
941     {
942       TGFileInfo fi;
943       fi.fFileTypes   = gMacroSaveAsTypes;
944       fi.fIniDir      = StrDup(""); // current directory
945       fi.fFileTypeIdx = 0;
946       fi.fOverwrite   = kTRUE;
947       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDOpen, &fi);
948       if (!fi.fFilename) return;
949
950       TPMERegexp filere(".*/([^/]+$)");
951       if (filere.Match(fi.fFilename) != 2)
952       {
953         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
954         return;
955       }
956       printf("Opening...\n");
957
958       TString file(filere[1]);
959
960       gSystem->ChangeDirectory(fi.fIniDir);
961
962       gEve->LoadVizDB(file, kTRUE, kTRUE);
963
964       gEve->Redraw3D(kTRUE);
965
966       printf("Done.\n");
967       break;
968
969     }
970
971     case kAEMSetDefault://Restore default settings
972     {
973
974       printf("Setting...\n");
975
976       TEveBrowser *browser = gEve->GetBrowser();
977       browser->ShowCloseTab(kFALSE);
978
979       if(fLoadCheck)
980         browser->RemoveTab(TRootBrowser::kRight, 5);//remove the tab with previous DataSelection window
981       else
982         browser->RemoveTab(TRootBrowser::kRight, 2);
983
984       TEveUtil::Macro("geom_gentle_default.C");
985       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
986       TEveUtil::Macro("DataSelection_init.C");
987
988       if(!gEve->GetViewers()->UseLightColorSet())
989         gEve->GetViewers()->SwitchColorSet(); //white background
990
991       AliEveEventManager *eman = AliEveEventManager::GetMaster();//reload event (gEve->Refresh() crashes)
992       Int_t ev = eman->GetEventId();
993       eman->Close();
994       eman->Open();
995       eman->GotoEvent(ev);
996
997       printf("Done.\n");
998
999       fLoadCheck = kTRUE;
1000
1001       gEve->Redraw3D(kTRUE);
1002
1003
1004     }
1005
1006 /*
1007     case kAEMResiduals:
1008     {
1009
1010       TEveUtil::Macro("make_residuals.C");
1011
1012       break;
1013
1014     }
1015 */
1016
1017     case kAEMCuts:
1018     {
1019
1020       TEveUtil::Macro("alieve_set_cuts.C");
1021
1022       break;
1023
1024     }
1025
1026     case kAEMVectors:
1027     {
1028
1029       TEveUtil::Macro("set_momentum_vectors.C");
1030
1031       break;
1032
1033     }
1034
1035 /*
1036     case kAEMGui:
1037     {
1038
1039       TEveUtil::Macro("alieve_gui_mode.C");
1040
1041       break;
1042
1043     }
1044 */
1045       case kStorageListEvents:
1046       {
1047 #ifdef ZMQ
1048           fListEventsWindow =
1049           AliStorageAdministratorPanelListEvents::GetInstance();
1050           
1051           fListEventsWindow->Connect("SelectedEvent()","AliEveConfigManager",this,"SetEventInEventManager()");
1052 #endif
1053           break;
1054           
1055       }
1056       case kStorageMarkEvent:
1057       {
1058 #ifdef ZMQ
1059           AliStorageAdministratorPanelMarkEvent *markEventWindow =
1060           AliStorageAdministratorPanelMarkEvent::GetInstance();
1061 #endif
1062           break;
1063       }
1064           
1065       default:
1066       {
1067           Warning(kEH, "Unknown menu entry.");
1068           break;
1069       }
1070   }
1071 }
1072
1073 void AliEveConfigManager::SetEventInEventManager()
1074 {
1075     AliEveEventManager *manager = AliEveEventManager::GetMaster();
1076     AliESDEvent *event = fListEventsWindow->GetSelectedEvent();
1077     
1078     if(event)
1079     {
1080             cout<<"SETTING EVENT IN ED"<<endl;
1081             //fListEventsWindow->onExit();
1082         manager->SetAutoLoad(kFALSE);
1083         manager->PrepareForNewEvent(event);
1084     }
1085 }
1086
1087 void AliEveConfigManager::StorageManagerChangedState(int state)
1088 {
1089     if (state == 0)// storage manager is down
1090     {
1091         fStoragePopup->DisableEntry(kStorageListEvents);
1092         fStoragePopup->DisableEntry(kStorageMarkEvent);
1093     }
1094     else if(state == 1)// storage manager is alive
1095     {
1096         fStoragePopup->EnableEntry(kStorageListEvents);
1097         fStoragePopup->EnableEntry(kStorageMarkEvent);
1098     }
1099 }
1100
1101