]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONMchViewApplication.cxx
Removing useless include (Christoph)
[u/mrichter/AliRoot.git] / MUON / AliMUONMchViewApplication.cxx
1 #include "AliMUONMchViewApplication.h"
2
3 #include "AliCDBManager.h"
4 #include "AliCodeTimer.h"
5 #include "AliLog.h"
6 #include "AliMUONPainterDataSourceFrame.h"
7 #include "AliMUONPainterHelper.h"
8 #include "AliMUONPainterMasterFrame.h"
9 #include "AliMUONPainterRegistry.h"
10 #include "AliMUONVTrackerData.h"
11 #include <Riostream.h>
12 #include <TCanvas.h>
13 #include <TEnv.h>
14 #include <TFile.h>
15 #include <TGClient.h>
16 #include <TGFileDialog.h>
17 #include <TGMenu.h>
18 #include <TGTab.h>
19 #include <TKey.h>
20 #include <TList.h>
21 #include <TString.h>
22 #include <TSystem.h>
23
24 /// \class AliMUONMchViewApplication
25 ///
26 /// Main class for the mchview program
27 ///
28 ///\author Laurent Aphecetche, Subatech
29
30 /// \cond CLASSIMP
31 ClassImp(AliMUONMchViewApplication)
32 /// \endcond CLASSIMP
33
34 const Int_t AliMUONMchViewApplication::fgkFILESAVEAS(1);
35 const Int_t AliMUONMchViewApplication::fgkFILEOPEN(2);
36 const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
37 const Int_t AliMUONMchViewApplication::fgkFILEPRINTAS(4);
38
39 const char* AliMUONMchViewApplication::fgkFileTypes[] = { 
40   "ROOT files",    "*.root", 
41   "All files",     "*", 
42   0,               0 }; 
43
44 //______________________________________________________________________________
45 AliMUONMchViewApplication::AliMUONMchViewApplication(const char* name,
46                                                      int* argc, char** argv,
47                                                      Float_t wfraction,
48                                                      Float_t hfraction) 
49 : TRint(name,argc,argv),
50   fMainFrame(0x0),
51   fPainterMasterFrame(0x0)
52 {
53
54   /// ctor
55   /// wfraction,hfraction are the fractions of display width and height
56   /// we want to draw on
57   
58   UInt_t dw = gClient->GetDisplayWidth(); 
59   UInt_t dh = gClient->GetDisplayHeight(); 
60                    
61   UInt_t w = (UInt_t)(wfraction*dw);
62   UInt_t h = (UInt_t)(hfraction*dh);
63
64   fMainFrame = new TGMainFrame(gClient->GetRoot(),w,h);
65   
66   CreateMenuBar(w);
67
68   const Int_t kbs = 2;
69   
70 //  h -= 60; // menubar
71   
72   TGTab* tabs = new TGTab(fMainFrame,w,h);
73   
74   TGCompositeFrame* t = tabs->AddTab("Painter Master Frame");
75
76   fPainterMasterFrame =
77     new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
78   
79   t->AddFrame(fPainterMasterFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
80
81   t = tabs->AddTab("Data Sources");
82   
83   AliMUONPainterDataSourceFrame* dsf = 
84     new AliMUONPainterDataSourceFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
85   
86   t->AddFrame(dsf,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
87   
88   fMainFrame->AddFrame(tabs,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,0,0,0,0));
89
90   fMainFrame->SetWindowName("mchview - Visualization of MUON Tracker detector");
91
92   fMainFrame->MapSubwindows();
93   fMainFrame->Resize();
94   
95   fPainterMasterFrame->Update();
96   
97   fMainFrame->MapWindow();
98   
99   fMainFrame->Connect("CloseWindow()","AliMUONMchViewApplication",this,"Terminate()");
100   
101   UInt_t x = dw/2 - w/2;
102   UInt_t y = 0;
103   
104   fMainFrame->MoveResize(x, y, w, h); 
105   fMainFrame->SetWMPosition(x, y);
106   
107   fMainFrame->SetWMSizeHints(w,h,w,h,0,0);
108   
109   cout << "***************************************************" << endl;
110   cout << "   Welcome to mchview" << endl;
111   cout << "   " << FullVersion() << endl;
112   cout << "***************************************************" << endl;
113
114 }
115
116 //______________________________________________________________________________
117 AliMUONMchViewApplication::~AliMUONMchViewApplication()
118 {
119   /// dtor
120 }
121
122 //______________________________________________________________________________
123 void
124 AliMUONMchViewApplication::CreateMenuBar(UInt_t w)
125 {
126   /// Create the application menu bar
127   
128   TGPopupMenu* file = new TGPopupMenu(gClient->GetRoot());
129   
130   file->AddEntry("&Open...",fgkFILEOPEN);
131   file->AddEntry("&Save As...",fgkFILESAVEAS);
132   file->AddEntry("&Print As...",fgkFILEPRINTAS);
133   file->AddEntry("&Exit",fgkFILEEXIT);
134   
135   file->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
136   
137   TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
138   
139   TGPopupMenu* about = new TGPopupMenu(gClient->GetRoot());  
140   about->AddLabel(FullVersion());
141
142   bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
143   bar->AddPopup("&About",about,new TGLayoutHints(kLHintsRight|kLHintsTop));
144   
145
146   fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
147   
148   AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
149 }
150
151 //______________________________________________________________________________
152 void
153 AliMUONMchViewApplication::HandleMenu(Int_t i)
154 {
155   /// Handle the click of one menu item
156
157   switch (i)
158     {
159     case fgkFILEEXIT:
160       Terminate(1);
161       break;
162     case fgkFILEOPEN:
163       Open();
164       break;
165     case fgkFILESAVEAS:
166       Save();
167       break;
168     case fgkFILEPRINTAS:
169       PrintAs();
170       break;
171     default:
172       break;
173     }
174 }
175
176 //______________________________________________________________________________
177 void
178 AliMUONMchViewApplication::Open()
179 {
180   /// Open file dialog
181   
182   TGFileInfo fileInfo;
183   
184   fileInfo.fFileTypes = fgkFileTypes;
185   
186   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
187                    kFDOpen,&fileInfo);
188   
189   Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
190 }  
191
192 //______________________________________________________________________________
193 void
194 AliMUONMchViewApplication::Open(const char* filename)
195 {
196   /// Open a given file containing saved VTrackerData objects
197   
198   TFile f(filename);
199   
200   TList* keys = f.GetListOfKeys();
201   TIter next(keys);
202   
203   TKey* k;
204   
205   while ( ( k = static_cast<TKey*>(next()) ) )
206   {
207     TObject* object = k->ReadObj();
208     
209     if ( object->InheritsFrom("AliMUONVTrackerData") )
210     {
211       AliMUONVTrackerData* data = static_cast<AliMUONVTrackerData*>(object);
212       if ( data ) 
213       {
214         AliMUONPainterRegistry::Instance()->Register(data);
215       }
216     }
217   }
218
219
220
221 //______________________________________________________________________________
222 void
223 AliMUONMchViewApplication::PrintAs()
224 {
225   /// Print as...
226   
227   TGFileInfo fileInfo;
228   
229   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
230                    kFDSave,&fileInfo);
231   
232   fPainterMasterFrame->SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
233 }
234
235 //______________________________________________________________________________
236 void
237 AliMUONMchViewApplication::Save()
238 {
239   /// Open "Save VTrackerData objects to file" dialog
240   
241   TGFileInfo fileInfo;
242   
243   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
244                    kFDSave,&fileInfo);
245   
246   Save(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
247 }  
248
249 //______________________________________________________________________________
250 void
251 AliMUONMchViewApplication::Save(const char* filename)
252 {
253   /// Save VTrackerData objects into file of given name
254   
255   AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
256
257   TFile f(filename,"RECREATE");
258   
259   for ( Int_t i = 0; i < reg->NumberOfDataSources(); ++i )
260   {
261     AliMUONVTrackerData* data = reg->DataSource(i);
262     data->Write();
263   }
264   
265   f.Close();
266 }