Update master to aliroot
[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 #ifdef ZMQ
190     gEve->GetBrowser()->StartEmbedding(0);
191     AliStorageAdministratorPanelListEvents* fListEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
192     gEve->GetBrowser()->StopEmbedding("List");
193     
194     fListEventsTab->Connect("SelectedEvent()","AliEveConfigManager",this,"SetEventInEventManager()");
195 #endif
196   
197   fLoadCheck = kFALSE;
198
199 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,25,4)
200   TGMenuBar *mBar = gEve->GetBrowser()->GetMenuBar();
201   mBar->AddPopup("&AliEve", fAliEvePopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
202   ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
203   mBar->AddPopup("&Tools", fAnalysisPopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
204     ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
205   
206   gEve->GetBrowser()->GetTopMenuFrame()->Layout();
207 #else
208   // Uber hack as TRootBrowser does not provede manu-bar getter.
209   TGFrameElement   *xxFE = (TGFrameElement*)   gEve->GetBrowser()->GetList()->First();
210   TGCompositeFrame *xxCF = (TGCompositeFrame*) xxFE->fFrame;
211   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
212   xxCF = (TGCompositeFrame*) xxFE->fFrame;
213   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
214   xxCF = (TGCompositeFrame*) xxFE->fFrame;
215   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
216   TGMenuBar *mBar = (TGMenuBar*) xxFE->fFrame;
217   mBar->AddPopup("&AliEve", fAliEvePopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
218   ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
219   mBar->AddPopup("&Tools", fAnalysisPopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
220   ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
221   mBar->AddPopup("&Storage Manager",fStoragePopup,new TGLayoutHints(kLHintsTop | kLHintsLeft,0,4,0,0));
222     ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
223 #endif
224 }
225
226 //==============================================================================
227
228 #include <iostream>
229 #include <fstream>
230 #include <string>
231 #include <sstream>
232
233 using namespace std;
234
235 namespace
236 {
237 const char *gMacroSaveAsTypes[] = {"CINT Macro", "*.C",
238                                    0, 0}; //for saving/loading macros
239
240 const char *gPictureSaveAsTypes[] = {"PNG Image", "*.png",
241                                    0, 0}; //for saving pictures
242
243 }
244
245 void AliEveConfigManager::ConnectEventManagerSignals()
246 {
247     AliEveEventManager *manager = AliEveEventManager::GetCurrent();
248     manager->Connect("StorageManagerOk()","AliEveConfigManager",this,"StorageManagerChangedState(=1)");
249     manager->Connect("StorageManagerDown()","AliEveConfigManager",this,"StorageManagerChangedState(=0)");
250 }
251
252 void AliEveConfigManager::AliEvePopupHandler(Int_t id)
253 {
254   // Handle user selections from AliEve popup.
255
256   static const TEveException kEH("AliEveConfigManager::AliEvePopupHandler ");
257
258   switch (id)
259   {
260
261     case kAEMDefault: //default geometry and VizDB
262     {
263       AliEveMultiView *mv = AliEveMultiView::Instance();
264
265       mv->DestroyAllGeometries(); //destroy RPhi and Rhoz geometries before putting new
266
267       gEve->LoadVizDB("geom_gentle_default.C", kTRUE, kTRUE); //loading geometry
268
269       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE); //loading VizDB
270
271       if(!gEve->GetViewers()->UseLightColorSet())
272         gEve->GetViewers()->SwitchColorSet(); //white background
273
274       gEve->FullRedraw3D();   
275       
276       break;
277     }
278
279     case kAEMScreen: //default geometry with black background
280     {
281       AliEveMultiView *mv = AliEveMultiView::Instance();
282
283       mv->DestroyAllGeometries();
284
285       gEve->LoadVizDB("geom_gentle_default.C", kTRUE, kTRUE);
286
287       gEve->LoadVizDB("VizDB_scan_screen.C", kTRUE, kTRUE);
288
289       if(gEve->GetViewers()->UseLightColorSet())
290         gEve->GetViewers()->SwitchColorSet();
291
292       gEve->FullRedraw3D();    
293
294       break;
295     }
296
297     case kAEMProjector: //default geometry with white background
298     {
299       AliEveMultiView *mv = AliEveMultiView::Instance();
300
301       mv->DestroyAllGeometries();
302
303       gEve->LoadVizDB("geom_gentle_projector.C", kTRUE, kTRUE);
304
305       gEve->LoadVizDB("VizDB_scan_projector.C", kTRUE, kTRUE);
306
307       if(!gEve->GetViewers()->UseLightColorSet())
308         gEve->GetViewers()->SwitchColorSet();
309
310       gEve->FullRedraw3D();    
311
312       break;
313     }
314
315     case kAEMNotransparency: //default geometry with low transparency (5%)
316     {
317       AliEveMultiView *mv = AliEveMultiView::Instance();
318
319       mv->DestroyAllGeometries();
320
321       gEve->LoadVizDB("geom_gentle_notransparency.C", kTRUE, kTRUE);
322
323       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
324
325       if(!gEve->GetViewers()->UseLightColorSet())
326         gEve->GetViewers()->SwitchColorSet();
327
328       gEve->FullRedraw3D();    
329
330       break;
331     }
332
333
334     case kAEMTransparentDark: //default geometry with black background, high transparency (80%)
335     {
336       AliEveMultiView *mv = AliEveMultiView::Instance();
337
338       mv->DestroyAllGeometries();
339
340       gEve->LoadVizDB("geom_gentle_transparent.C", kTRUE, kTRUE);
341
342       gEve->LoadVizDB("VizDB_scan_transparentdark.C", kTRUE, kTRUE);
343
344       if(gEve->GetViewers()->UseLightColorSet())
345         gEve->GetViewers()->SwitchColorSet();
346
347       gEve->FullRedraw3D();   
348
349       break;
350     }
351
352     case kAEMTransparentLight: //default geometry with white background, high transparency (80%)
353     {
354       AliEveMultiView *mv = AliEveMultiView::Instance();
355
356       mv->DestroyAllGeometries();
357
358       gEve->LoadVizDB("geom_gentle_transparent.C", kTRUE, kTRUE);
359
360       gEve->LoadVizDB("VizDB_scan_transparentlight.C", kTRUE, kTRUE);
361
362       if(!gEve->GetViewers()->UseLightColorSet())
363         gEve->GetViewers()->SwitchColorSet();
364
365       gEve->FullRedraw3D();    
366
367       break;
368     }
369
370     case kAEMTransparentMonoDark:
371     {
372       AliEveMultiView *mv = AliEveMultiView::Instance();
373
374       mv->DestroyAllGeometries();
375
376       gEve->LoadVizDB("geom_gentle_transparentdark.C", kTRUE, kTRUE);
377
378       gEve->LoadVizDB("VizDB_scan_transparentdark.C", kTRUE, kTRUE);
379
380       if(gEve->GetViewers()->UseLightColorSet())
381         gEve->GetViewers()->SwitchColorSet();
382
383       gEve->FullRedraw3D();   
384
385       break;
386     }
387
388     case kAEMTransparentMonoLight:
389     {
390       AliEveMultiView *mv = AliEveMultiView::Instance();
391
392       mv->DestroyAllGeometries();
393
394       gEve->LoadVizDB("geom_gentle_transparentlight.C", kTRUE, kTRUE);
395
396       gEve->LoadVizDB("VizDB_scan_transparentlight.C", kTRUE, kTRUE);
397
398       if(!gEve->GetViewers()->UseLightColorSet())
399         gEve->GetViewers()->SwitchColorSet();
400
401       gEve->FullRedraw3D();    
402
403       break;
404     }
405
406     case kAEMGreen:
407     {
408       AliEveMultiView *mv = AliEveMultiView::Instance();
409
410       mv->DestroyAllGeometries();
411
412       gEve->LoadVizDB("geom_gentle_green.C", kTRUE, kTRUE);
413
414       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
415
416       if(!gEve->GetViewers()->UseLightColorSet())
417         gEve->GetViewers()->SwitchColorSet();
418
419       gEve->FullRedraw3D();    
420
421       break;
422     }
423
424     case kAEMBright:
425     {
426       AliEveMultiView *mv = AliEveMultiView::Instance();
427
428       mv->DestroyAllGeometries();
429
430       gEve->LoadVizDB("geom_gentle_bright.C", kTRUE, kTRUE);
431
432       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
433
434       if(gEve->GetViewers()->UseLightColorSet())
435         gEve->GetViewers()->SwitchColorSet();
436
437       gEve->FullRedraw3D();
438
439       break;
440     }
441
442     case kAEMYellow:
443     {
444       AliEveMultiView *mv = AliEveMultiView::Instance();
445
446       mv->DestroyAllGeometries();
447
448       gEve->LoadVizDB("geom_gentle_yellow.C", kTRUE, kTRUE);
449
450       gEve->LoadVizDB("VizDB_scan_yellow.C", kTRUE, kTRUE);
451
452       if(!gEve->GetViewers()->UseLightColorSet())
453         gEve->GetViewers()->SwitchColorSet();
454
455       gEve->FullRedraw3D();    
456
457       break;
458     }
459
460     case kAEMTpc:
461     {
462       AliEveMultiView *mv = AliEveMultiView::Instance();
463
464       mv->DestroyAllGeometries();
465
466       gEve->LoadVizDB("geom_gentle_tpc.C", kTRUE, kTRUE);
467
468       gEve->LoadVizDB("VizDB_scan_tpc.C", kTRUE, kTRUE);
469
470       if(!gEve->GetViewers()->UseLightColorSet())
471         gEve->GetViewers()->SwitchColorSet();
472
473       gEve->FullRedraw3D();
474
475       break;
476     }
477
478     case kAEMAll: //saving pictures from all three viewers
479     {
480       
481      TGFileInfo fi;
482      fi.fFileTypes   = gPictureSaveAsTypes;
483      fi.fIniDir      = StrDup(""); // current directory
484      fi.fFileTypeIdx = 0;
485      fi.fOverwrite   = kTRUE;
486      new TGFileDialog(gClient->GetDefaultRoot(),
487      gEve->GetMainWindow(), kFDSave, &fi); // dialog 
488      if (!fi.fFilename) return;
489
490      TPMERegexp filere(".*/([^/]+$)");
491      if (filere.Match(fi.fFilename) != 2)
492      {
493        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
494        return;
495      }
496
497      TString file1(filere[1]);
498      TString file2(filere[1]);
499      TString file3(filere[1]);
500      
501      if (!file1.EndsWith(".png"))
502        file1 += "_3D.png"; // adding extensions
503        
504      if (!file2.EndsWith(".png"))
505        file2 += "_RPhi.png"; // adding extensions
506        
507      if (!file3.EndsWith(".png"))
508        file3 += "_RhoZ.png"; // adding extensions
509
510      gSystem->ChangeDirectory(fi.fIniDir);
511       
512      printf("Saving...\n");
513
514      TEveViewerList *viewers = gEve->GetViewers();
515      TEveElement::List_i i = viewers->BeginChildren();
516      i++;
517      TEveViewer* view3d = ((TEveViewer*)*i);
518      view3d->GetGLViewer()->SavePicture(file1); // saving pictures
519      i++;
520      TEveViewer* viewrphi = ((TEveViewer*)*i);
521      viewrphi->GetGLViewer()->SavePicture(file2); // saving pictures
522      i++;
523      TEveViewer* viewrhoz = ((TEveViewer*)*i);
524      viewrhoz->GetGLViewer()->SavePicture(file3); // saving pictures
525      
526      printf("Done.\n"); 
527       
528       break;
529     }
530     
531     case kAEM3d: // saving only 3d view
532     {
533       
534      TGFileInfo fi;
535      fi.fFileTypes   = gPictureSaveAsTypes;
536      fi.fIniDir      = StrDup(""); // current directory
537      fi.fFileTypeIdx = 0;
538      fi.fOverwrite   = kTRUE;
539      new TGFileDialog(gClient->GetDefaultRoot(),
540      gEve->GetMainWindow(), kFDSave, &fi);
541      if (!fi.fFilename) return;
542
543      TPMERegexp filere(".*/([^/]+$)");
544      if (filere.Match(fi.fFilename) != 2)
545      {
546        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
547        return;
548      }
549
550      TString file1(filere[1]);
551      
552      if (!file1.EndsWith(".png"))
553        file1 += ".png";
554
555      gSystem->ChangeDirectory(fi.fIniDir);
556       
557      printf("Saving...\n");
558
559      TEveViewerList *viewers = gEve->GetViewers();
560      TEveElement::List_i i = viewers->BeginChildren();
561      i++;
562      TEveViewer* view3d = ((TEveViewer*)*i);
563      view3d->GetGLViewer()->SavePicture(file1);
564      
565      printf("Done.\n"); 
566       
567       break;
568     }
569     
570      case kAEMRphi: // saving only RPhi view
571     {
572       
573      TGFileInfo fi;
574      fi.fFileTypes   = gPictureSaveAsTypes;
575      fi.fIniDir      = StrDup(""); // current directory
576      fi.fFileTypeIdx = 0;
577      fi.fOverwrite   = kTRUE;
578      new TGFileDialog(gClient->GetDefaultRoot(),
579      gEve->GetMainWindow(), kFDSave, &fi);
580      if (!fi.fFilename) return;
581
582      TPMERegexp filere(".*/([^/]+$)");
583      if (filere.Match(fi.fFilename) != 2)
584      {
585        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
586        return;
587      }
588
589      TString file1(filere[1]);
590      
591      if (!file1.EndsWith(".png"))
592        file1 += ".png";
593      
594      gSystem->ChangeDirectory(fi.fIniDir);
595       
596      printf("Saving...\n");
597
598      TEveViewerList *viewers = gEve->GetViewers();
599      TEveElement::List_i i = viewers->BeginChildren();
600      i++;
601      i++;
602      TEveViewer* viewrphi = ((TEveViewer*)*i);
603      viewrphi->GetGLViewer()->SavePicture(file1);
604      
605      printf("Done.\n"); 
606       
607       break;
608     }
609     
610      case kAEMRhoz: // saving only RhoZ view
611     {
612     
613      TGFileInfo fi;
614      fi.fFileTypes   = gPictureSaveAsTypes;
615      fi.fIniDir      = StrDup(""); // current directory
616      fi.fFileTypeIdx = 0;
617      fi.fOverwrite   = kTRUE;
618      new TGFileDialog(gClient->GetDefaultRoot(),
619      gEve->GetMainWindow(), kFDSave, &fi);
620      if (!fi.fFilename) return;
621
622      TPMERegexp filere(".*/([^/]+$)");
623      if (filere.Match(fi.fFilename) != 2)
624      {
625        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
626        return;
627      }
628
629      TString file1(filere[1]);
630        
631      if (!file1.EndsWith(".png"))
632        file1 += ".png";
633
634      gSystem->ChangeDirectory(fi.fIniDir);
635      
636      printf("Saving...\n");
637
638      TEveViewerList *viewers = gEve->GetViewers();
639      TEveElement::List_i i = viewers->BeginChildren();
640      i++;
641      i++;
642      i++;
643      TEveViewer* viewrhoz = ((TEveViewer*)*i);
644      viewrhoz->GetGLViewer()->SavePicture(file1);
645      
646      printf("Done.\n"); 
647       
648       break;
649     }
650
651     case kAEMAllhr: // saving all three views in high resolution
652     {
653       
654      TGFileInfo fi;
655      fi.fFileTypes   = gPictureSaveAsTypes;
656      fi.fIniDir      = StrDup(""); // current directory
657      fi.fFileTypeIdx = 0;
658      fi.fOverwrite   = kTRUE;
659      new TGFileDialog(gClient->GetDefaultRoot(),
660      gEve->GetMainWindow(), kFDSave, &fi);
661      if (!fi.fFilename) return;
662
663      TPMERegexp filere(".*/([^/]+$)");
664      if (filere.Match(fi.fFilename) != 2)
665      {
666        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
667        return;
668      }
669
670      TString file1(filere[1]);
671      TString file2(filere[1]);
672      TString file3(filere[1]);
673      
674      if (!file1.EndsWith(".png"))
675        file1 += "_3D.png";
676        
677      if (!file2.EndsWith(".png"))
678        file2 += "_RPhi.png";
679        
680      if (!file3.EndsWith(".png"))
681        file3 += "_RhoZ.png";
682
683      gSystem->ChangeDirectory(fi.fIniDir);
684       
685      printf("Saving...\n");
686
687      TEveViewerList *viewers = gEve->GetViewers();
688      TEveElement::List_i i = viewers->BeginChildren();
689      i++;
690      TEveViewer* view3d = ((TEveViewer*)*i);
691      view3d->GetGLViewer()->SavePictureScale(file1,6.0); // getting high resolution
692      i++;
693      TEveViewer* viewrphi = ((TEveViewer*)*i);
694      viewrphi->GetGLViewer()->SavePictureScale(file2,6.0);
695      i++;
696      TEveViewer* viewrhoz = ((TEveViewer*)*i);
697      viewrhoz->GetGLViewer()->SavePictureScale(file3,6.0);
698      
699      printf("Done.\n"); 
700       
701       break;
702     }
703     
704     case kAEM3dhr: // saving only 3d view in high resolution
705     {
706       
707      TGFileInfo fi;
708      fi.fFileTypes   = gPictureSaveAsTypes;
709      fi.fIniDir      = StrDup(""); // current directory
710      fi.fFileTypeIdx = 0;
711      fi.fOverwrite   = kTRUE;
712      new TGFileDialog(gClient->GetDefaultRoot(),
713      gEve->GetMainWindow(), kFDSave, &fi);
714      if (!fi.fFilename) return;
715
716      TPMERegexp filere(".*/([^/]+$)");
717      if (filere.Match(fi.fFilename) != 2)
718      {
719        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
720        return;
721      }
722
723      TString file1(filere[1]);
724      
725      if (!file1.EndsWith(".png"))
726        file1 += ".png";
727
728      gSystem->ChangeDirectory(fi.fIniDir);
729       
730      printf("Saving...\n");
731
732      TEveViewerList *viewers = gEve->GetViewers();
733      TEveElement::List_i i = viewers->BeginChildren();
734      i++;
735      TEveViewer* view3d = ((TEveViewer*)*i);
736      view3d->GetGLViewer()->SavePictureScale(file1,4.0);
737      
738      printf("Done.\n"); 
739       
740       break;
741     }
742     
743      case kAEMRphihr: // saving only RPhi view in high resolution
744     {
745       
746      TGFileInfo fi;
747      fi.fFileTypes   = gPictureSaveAsTypes;
748      fi.fIniDir      = StrDup(""); // current directory
749      fi.fFileTypeIdx = 0;
750      fi.fOverwrite   = kTRUE;
751      new TGFileDialog(gClient->GetDefaultRoot(),
752      gEve->GetMainWindow(), kFDSave, &fi);
753      if (!fi.fFilename) return;
754
755      TPMERegexp filere(".*/([^/]+$)");
756      if (filere.Match(fi.fFilename) != 2)
757      {
758        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
759        return;
760      }
761
762      TString file1(filere[1]);
763      
764      if (!file1.EndsWith(".png"))
765        file1 += ".png";
766      
767      gSystem->ChangeDirectory(fi.fIniDir);
768       
769      printf("Saving...\n");
770
771      TEveViewerList *viewers = gEve->GetViewers();
772      TEveElement::List_i i = viewers->BeginChildren();
773      i++;
774      i++;
775      TEveViewer* viewrphi = ((TEveViewer*)*i);
776      viewrphi->GetGLViewer()->SavePictureScale(file1,4.0);
777      
778      printf("Done.\n"); 
779       
780       break;
781     }
782     
783      case kAEMRhozhr: // saving only RhoZ view in high resolution
784     {
785     
786      TGFileInfo fi;
787      fi.fFileTypes   = gPictureSaveAsTypes;
788      fi.fIniDir      = StrDup(""); // current directory
789      fi.fFileTypeIdx = 0;
790      fi.fOverwrite   = kTRUE;
791      new TGFileDialog(gClient->GetDefaultRoot(),
792      gEve->GetMainWindow(), kFDSave, &fi);
793      if (!fi.fFilename) return;
794
795      TPMERegexp filere(".*/([^/]+$)");
796      if (filere.Match(fi.fFilename) != 2)
797      {
798        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
799        return;
800      }
801
802      TString file1(filere[1]);
803        
804      if (!file1.EndsWith(".png"))
805        file1 += ".png";
806
807      gSystem->ChangeDirectory(fi.fIniDir);
808      
809      printf("Saving...\n");
810
811      TEveViewerList *viewers = gEve->GetViewers();
812      TEveElement::List_i i = viewers->BeginChildren();
813      i++;
814      i++;
815      i++;
816      TEveViewer* viewrhoz = ((TEveViewer*)*i);
817      viewrhoz->GetGLViewer()->SavePictureScale(file1,4.0);
818      
819      printf("Done.\n"); 
820       
821       break;
822     }
823
824      case kAEMSavemacros:// Saving Data Selection macros
825     {
826
827       AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
828
829       exec->SaveAddedMacros();
830
831       break;
832     }
833  
834    case kAEMLoadmacros://Loading Data Selection macros
835     {
836
837       TEveBrowser *browser = gEve->GetBrowser();
838       browser->ShowCloseTab(kFALSE);
839
840       if(fLoadCheck)
841         browser->RemoveTab(TRootBrowser::kRight, 5);//remove the tab with previous DataSelection window
842       else
843         browser->RemoveTab(TRootBrowser::kRight, 2);
844
845
846       TGFileInfo fi;
847       fi.fFileTypes   = gMacroSaveAsTypes;
848       fi.fIniDir      = StrDup(""); // current directory
849       fi.fFileTypeIdx = 0;
850       fi.fOverwrite   = kTRUE;
851       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDOpen, &fi);//dialog
852       if (!fi.fFilename) return;
853
854       TPMERegexp filere(".*/([^/]+$)");
855       if (filere.Match(fi.fFilename) != 2)
856       {
857         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
858         return;
859       }
860       printf("Loading...\n");
861
862       TString file(filere[1]);
863       gSystem->ChangeDirectory(fi.fIniDir);
864
865       TEveUtil::Macro(file);//run macro
866
867       AliEveEventManager *eman = AliEveEventManager::GetMaster();//reload event (gEve->Refresh() crashes)
868       Int_t ev = eman->GetEventId();
869       eman->Close();
870       eman->Open();
871       eman->GotoEvent(ev);
872
873       printf("Done.\n");
874
875       fLoadCheck = kTRUE;
876
877       break;
878
879     }
880
881     case kAEMSave://saving VizDB
882     {
883       TGFileInfo fi;
884       fi.fFileTypes   = gMacroSaveAsTypes;
885       fi.fIniDir      = StrDup(""); // current directory
886       fi.fFileTypeIdx = 0;
887       fi.fOverwrite   = kTRUE;
888       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDSave, &fi);
889       if (!fi.fFilename) return;
890
891       TPMERegexp filere(".*/([^/]+$)");
892       if (filere.Match(fi.fFilename) != 2)
893       {
894         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
895         return;
896       }
897       printf("Saving...\n");
898
899       TString file(filere[1]);
900       if (!file.EndsWith(".C"))
901         file += ".C";
902       gSystem->ChangeDirectory(fi.fIniDir);
903       gEve->SaveVizDB(file);
904
905 //Last line "gEve->SaveVizDB(file);" gives macro with many unnecessary
906 //lines like "x038->SetMinPt(0);" tahat are not interpreted properly later
907
908       string text;
909       string all;
910
911       ifstream myfile1(file);
912       if(myfile1.is_open())
913         {
914         while(!myfile1.eof())
915           {
916             getline(myfile1,text);
917             TString check(text);
918             if(!(check.EndsWith("MinPt(0);")||check.EndsWith("MaxPt(0);")
919                ||check.EndsWith("LimPt(0);")||check.EndsWith("MinP(0);")
920                ||check.EndsWith("MaxP(0);")||check.EndsWith("LimP(0);")))
921               {
922               all += text; //Cut off unnecessary lines and bring everything together
923               all += "\n";
924               }
925           }
926         myfile1.close();
927         }
928
929       ofstream myfile2(file); //Replacing old file with the one without "bad" lines
930       myfile2 << all;
931       myfile2.close();
932
933       printf("Done.\n");
934       break;
935
936     }
937
938     case kAEMOpen://Opening VizDB
939     {
940       TGFileInfo fi;
941       fi.fFileTypes   = gMacroSaveAsTypes;
942       fi.fIniDir      = StrDup(""); // current directory
943       fi.fFileTypeIdx = 0;
944       fi.fOverwrite   = kTRUE;
945       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDOpen, &fi);
946       if (!fi.fFilename) return;
947
948       TPMERegexp filere(".*/([^/]+$)");
949       if (filere.Match(fi.fFilename) != 2)
950       {
951         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
952         return;
953       }
954       printf("Opening...\n");
955
956       TString file(filere[1]);
957
958       gSystem->ChangeDirectory(fi.fIniDir);
959
960       gEve->LoadVizDB(file, kTRUE, kTRUE);
961
962       gEve->Redraw3D(kTRUE);
963
964       printf("Done.\n");
965       break;
966
967     }
968
969     case kAEMSetDefault://Restore default settings
970     {
971
972       printf("Setting...\n");
973
974       TEveBrowser *browser = gEve->GetBrowser();
975       browser->ShowCloseTab(kFALSE);
976
977       if(fLoadCheck)
978         browser->RemoveTab(TRootBrowser::kRight, 5);//remove the tab with previous DataSelection window
979       else
980         browser->RemoveTab(TRootBrowser::kRight, 2);
981
982       TEveUtil::Macro("geom_gentle_default.C");
983       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
984       TEveUtil::Macro("DataSelection_init.C");
985
986       if(!gEve->GetViewers()->UseLightColorSet())
987         gEve->GetViewers()->SwitchColorSet(); //white background
988
989       AliEveEventManager *eman = AliEveEventManager::GetMaster();//reload event (gEve->Refresh() crashes)
990       Int_t ev = eman->GetEventId();
991       eman->Close();
992       eman->Open();
993       eman->GotoEvent(ev);
994
995       printf("Done.\n");
996
997       fLoadCheck = kTRUE;
998
999       gEve->Redraw3D(kTRUE);
1000
1001
1002     }
1003
1004 /*
1005     case kAEMResiduals:
1006     {
1007
1008       TEveUtil::Macro("make_residuals.C");
1009
1010       break;
1011
1012     }
1013 */
1014
1015     case kAEMCuts:
1016     {
1017
1018       TEveUtil::Macro("alieve_set_cuts.C");
1019
1020       break;
1021
1022     }
1023
1024     case kAEMVectors:
1025     {
1026
1027       TEveUtil::Macro("set_momentum_vectors.C");
1028
1029       break;
1030
1031     }
1032
1033 /*
1034     case kAEMGui:
1035     {
1036
1037       TEveUtil::Macro("alieve_gui_mode.C");
1038
1039       break;
1040
1041     }
1042 */
1043           /*
1044       case kStorageListEvents:
1045       {
1046 #ifdef ZMQ
1047           fListEventsWindow =
1048           AliStorageAdministratorPanelListEvents::GetInstance();
1049           
1050           fListEventsWindow->Connect("SelectedEvent()","AliEveConfigManager",this,"SetEventInEventManager()");
1051 #endif
1052           break;
1053           
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 #ifdef ZMQ
1076
1077     AliEveEventManager *manager = AliEveEventManager::GetMaster();
1078     AliStorageAdministratorPanelListEvents* fListEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
1079     AliESDEvent *event = fListEventsTab->GetSelectedEvent();
1080     
1081     if(event)
1082     {
1083             cout<<"SETTING EVENT IN ED"<<endl;
1084             //fListEventsWindow->onExit();
1085         manager->SetAutoLoad(kFALSE);
1086         manager->PrepareForNewEvent(event);
1087     }
1088 #endif
1089 }
1090
1091 void AliEveConfigManager::StorageManagerChangedState(int state)
1092 {
1093 #ifdef ZMQ
1094     AliEveEventManager *manager = AliEveEventManager::GetMaster();
1095     AliStorageAdministratorPanelListEvents* listEventsTab = AliStorageAdministratorPanelListEvents::GetInstance();
1096     
1097     if (manager->IsOnlineMode()) {
1098         if (state == 0)// storage manager is down
1099         {
1100             listEventsTab->SetOfflineMode(kTRUE);
1101         }
1102         else if(state == 1)// storage manager is alive
1103         {
1104             listEventsTab->SetOfflineMode(kFALSE);
1105         }
1106     }
1107 #endif
1108 }
1109
1110