]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONMchViewApplication.cxx
- Adding svn properties svn:keywords, svn:eol-style if missing
[u/mrichter/AliRoot.git] / MUON / AliMUONMchViewApplication.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 // $Id$
17
18 #include "AliMUONMchViewApplication.h"
19
20 #include "AliCDBManager.h"
21 #include "AliCodeTimer.h"
22 #include "AliLog.h"
23 #include "AliMUONPainterDataSourceFrame.h"
24 #include "AliMUONPainterEnv.h"
25 #include "AliMUONPainterHelper.h"
26 #include "AliMUONPainterMasterFrame.h"
27 #include "AliMUONPainterRegistry.h"
28 #include "AliMUONTrackerDataCompareDialog.h"
29 #include "AliMUONTrackerDataWrapper.h"
30 #include "AliMUONVTrackerData.h"
31 #include "AliMUONVTrackerDataMaker.h"
32 #include <Riostream.h>
33 #include <TCanvas.h>
34 #include <TEnv.h>
35 #include <TFile.h>
36 #include <TGClient.h>
37 #include <TGFileDialog.h>
38 #include <TGMenu.h>
39 #include <TGTab.h>
40 #include <TGTextView.h>
41 #include <TGrid.h>
42 #include <TKey.h>
43 #include <TList.h>
44 #include <TRegexp.h>
45 #include <TString.h>
46 #include <TSystem.h>
47
48 /// \class AliMUONMchViewApplication
49 ///
50 /// Main class for the mchview program
51 ///
52 ///\author Laurent Aphecetche, Subatech
53
54 /// \cond CLASSIMP
55 ClassImp(AliMUONMchViewApplication)
56 /// \endcond CLASSIMP
57
58 const Int_t AliMUONMchViewApplication::fgkFILESAVEAS(1);
59 const Int_t AliMUONMchViewApplication::fgkFILEOPEN(2);
60 const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
61 const Int_t AliMUONMchViewApplication::fgkFILEPRINTAS(4);
62 const Int_t AliMUONMchViewApplication::fgkABOUT(5);
63 const Int_t AliMUONMchViewApplication::fgkCOMPAREDATA(6);
64
65 const char* AliMUONMchViewApplication::fgkFileTypes[] = { 
66   "ROOT files",    "*.root", 
67   "All files",     "*", 
68   0,               0 }; 
69
70 //______________________________________________________________________________
71 AliMUONMchViewApplication::AliMUONMchViewApplication(const char* name,
72                                                      int* argc, char** argv,
73                                                      Float_t wfraction,
74                                                      Float_t hfraction) 
75 : TRint(name,argc,argv),
76   fMainFrame(0x0),
77   fPainterMasterFrame(0x0)
78 {
79
80   /// ctor
81   /// wfraction,hfraction are the fractions of display width and height
82   /// we want to draw on
83   
84   UInt_t dw = gClient->GetDisplayWidth(); 
85   UInt_t dh = gClient->GetDisplayHeight(); 
86                    
87   UInt_t w = (UInt_t)(wfraction*dw);
88   UInt_t h = (UInt_t)(hfraction*dh);
89
90   fMainFrame = new TGMainFrame(gClient->GetRoot(),w,h);
91   
92   CreateMenuBar(w);
93
94   const Int_t kbs = 2;
95   
96 //  h -= 60; // menubar
97   
98   TGTab* tabs = new TGTab(fMainFrame,w,h);
99   
100   TGCompositeFrame* t = tabs->AddTab("Painter Master Frame");
101
102   fPainterMasterFrame =
103     new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
104   
105   t->AddFrame(fPainterMasterFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
106
107   t = tabs->AddTab("Data Sources");
108   
109   AliMUONPainterDataSourceFrame* dsf = 
110     new AliMUONPainterDataSourceFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
111   
112   t->AddFrame(dsf,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
113   
114   fMainFrame->AddFrame(tabs,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,0,0,0,0));
115
116   fMainFrame->SetWindowName("mchview - Visualization of MUON Tracker detector");
117
118   fMainFrame->MapSubwindows();
119   fMainFrame->Resize();
120   
121   fPainterMasterFrame->Update();
122   
123   fMainFrame->MapWindow();
124   
125   fMainFrame->Connect("CloseWindow()","AliMUONMchViewApplication",this,"Terminate()");
126   
127   UInt_t x = dw/2 - w/2;
128   UInt_t y = 0;
129   
130   fMainFrame->MoveResize(x, y, w, h); 
131   fMainFrame->SetWMPosition(x, y);
132   
133   fMainFrame->SetWMSizeHints(w,h,w,h,0,0);
134   
135   cout << "***************************************************" << endl;
136   cout << "   Welcome to mchview" << endl;
137   cout << "   " << FullVersion() << endl;
138   cout << "***************************************************" << endl;
139
140 }
141
142 //______________________________________________________________________________
143 AliMUONMchViewApplication::~AliMUONMchViewApplication()
144 {
145   /// dtor
146 }
147
148 //______________________________________________________________________________
149 void
150 AliMUONMchViewApplication::CompareData()
151 {
152   /// Launch compare data dialog
153   TGTransientFrame* t = new AliMUONTrackerDataCompareDialog(gClient->GetRoot(),
154                                                             gClient->GetRoot(),
155                                                             400,400);
156
157   t->MapSubwindows();
158   t->Resize();
159   t->MapWindow();
160   t->CenterOnParent();
161   
162   // set names
163   
164   t->SetWindowName("mchview compare data tool");
165   t->SetIconName("mchview compare data tool");
166   
167   t->MapRaised();
168   
169 }
170
171 //______________________________________________________________________________
172 void
173 AliMUONMchViewApplication::CreateMenuBar(UInt_t w)
174 {
175   /// Create the application menu bar
176   
177   TGPopupMenu* file = new TGPopupMenu(gClient->GetRoot());
178   
179   file->AddEntry("&Open...",fgkFILEOPEN);
180   file->AddEntry("&Save As...",fgkFILESAVEAS);
181   file->AddEntry("&Print As...",fgkFILEPRINTAS);
182   file->AddEntry("&Exit",fgkFILEEXIT);
183   
184   TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
185   
186   TGPopupMenu* tools = new TGPopupMenu(gClient->GetRoot());
187   tools->AddEntry("&Compare data",fgkCOMPAREDATA);
188   
189   TGPopupMenu* about = new TGPopupMenu(gClient->GetRoot());  
190   about->AddEntry(FullVersion(),fgkABOUT);
191
192   file->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
193   about->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
194   tools->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
195   
196   bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
197   bar->AddPopup("&Tools",tools,new TGLayoutHints(kLHintsLeft|kLHintsTop));
198   bar->AddPopup("&About",about,new TGLayoutHints(kLHintsRight|kLHintsTop));
199   
200   fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
201   
202   AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
203 }
204
205 //______________________________________________________________________________
206 void
207 AliMUONMchViewApplication::HandleMenu(Int_t i)
208 {
209   /// Handle the click of one menu item
210
211   switch (i)
212     {
213     case fgkFILEEXIT:
214       Terminate(1);
215       break;
216     case fgkFILEOPEN:
217       Open();
218       break;
219     case fgkFILESAVEAS:
220       Save();
221       break;
222     case fgkFILEPRINTAS:
223       PrintAs();
224       break;
225     case fgkABOUT:
226       ReleaseNotes();
227       break;
228     case fgkCOMPAREDATA:
229       CompareData();
230       break;
231     default:
232       break;
233     }
234 }
235
236 //______________________________________________________________________________
237 void
238 AliMUONMchViewApplication::Open()
239 {
240   /// Open file dialog
241   
242   TGFileInfo fileInfo;
243   
244   fileInfo.fFileTypes = fgkFileTypes;
245   
246   delete[] fileInfo.fIniDir;
247   
248   AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
249   
250   fileInfo.fIniDir = StrDup(env->String("LastOpenDir","."));
251   
252   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
253                    kFDOpen,&fileInfo);
254
255   env->Set("LastOpenDir",fileInfo.fIniDir);
256   env->Save();  
257     
258   Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
259 }  
260
261 //______________________________________________________________________________
262 void
263 AliMUONMchViewApplication::Open(const char* filename)
264 {
265   /// Open a given file containing saved VTrackerDataMaker objects
266   
267   TString sfilename(gSystem->ExpandPathName(filename));
268   
269   if ( sfilename.Contains(TRegexp("^alien")) )
270   {
271     // insure we've initialized the grid...
272     if (!gGrid)
273     {
274       TGrid::Connect("alien://");
275     }
276   }
277   
278   TFile* f = TFile::Open(filename);
279   
280   TList* keys = f->GetListOfKeys();
281   TIter next(keys);
282   
283   TKey* k;
284   
285   while ( ( k = static_cast<TKey*>(next()) ) )
286   {
287     TObject* object = k->ReadObj();
288
289     if ( object->InheritsFrom("AliMUONVTrackerDataMaker") )
290     {
291       AliMUONVTrackerDataMaker* maker = dynamic_cast<AliMUONVTrackerDataMaker*>(object);
292       if ( maker ) 
293       {
294         AliMUONPainterRegistry::Instance()->Register(maker);
295       }
296     }
297     
298     if ( object->InheritsFrom("AliMUONVTrackerData") )
299     {
300       // this is for backward compatibility. Early versions of mchview 
301       // wrote VTrackerData objects, and not VTrackerDataMaker ones.
302       
303       AliMUONVTrackerData* data = dynamic_cast<AliMUONVTrackerData*>(object);
304       if ( data ) 
305       {
306         AliMUONVTrackerDataMaker* maker = new AliMUONTrackerDataWrapper(data);
307         AliMUONPainterRegistry::Instance()->Register(maker);
308       }
309     }
310   }
311   
312   delete f;
313
314
315
316 //______________________________________________________________________________
317 void
318 AliMUONMchViewApplication::PrintAs()
319 {
320   /// Print as...
321   
322   TGFileInfo fileInfo;
323   
324   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
325                    kFDSave,&fileInfo);
326   
327   fPainterMasterFrame->SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
328 }
329
330 //______________________________________________________________________________
331 void
332 AliMUONMchViewApplication::ReleaseNotes()
333 {
334   /// Display release notes
335   
336   UInt_t width = 600;
337   UInt_t height = 400;
338   
339   TGTransientFrame* t = new TGTransientFrame(gClient->GetRoot(),gClient->GetRoot(),width,height);
340   
341   TGTextView* rn = new TGTextView(t);
342   
343   rn->AddLine("0.93");
344   rn->AddLine("");
345   rn->AddLine("New features");
346   rn->AddLine("");
347   rn->AddLine("- Adding a Lock button under the color slider to lock the range shown");
348   rn->AddLine("  when switching between views");
349   rn->AddLine("- Default display now shows bending plane (instead of cathode 0 before)");
350   rn->AddLine("- If pad is responder and there's some histo for that pad, ");
351   rn->AddLine("  clicking on it will display an histo");
352   rn->AddLine("- Right-click on a painter will now display several histogram options");
353   rn->AddLine("  (e.g. raw charge as before, but also simple distributions of mean");
354   rn->AddLine("  and sigma");
355   rn->AddLine("- In the Data Sources Tab, each data source can now be removed and saved");
356   rn->AddLine("- There's a new Tool menu which allow to produce a TrackerData from two others");
357   rn->AddLine("  in order to compare data.");
358   rn->AddLine("  - The --use option can now reference alien files");
359   rn->AddLine("");    
360   rn->AddLine("Bug fixes");
361   rn->AddLine("");    
362   rn->AddLine("- Can now read Capacitances from OCDB");
363     
364   rn->Resize(width,height);
365   
366   t->AddFrame(rn, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
367   
368   t->MapSubwindows();
369   t->Resize();
370   t->MapWindow();
371   t->CenterOnParent();
372     
373   // set names
374   
375   t->SetWindowName("mchview release notes");
376   t->SetIconName("mchview release notes");
377   
378 //  t->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
379 //              kMWMDecorMinimize | kMWMDecorMenu,
380 //              kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
381 //              kMWMFuncMinimize,
382 //              kMWMInputModeless);
383   
384   t->MapRaised();
385 //  gClient->WaitFor(t);
386 }
387
388 //______________________________________________________________________________
389 void
390 AliMUONMchViewApplication::Save()
391 {
392   /// Open "Save VTrackerData objects to file" dialog
393   
394   TGFileInfo fileInfo;
395   
396   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
397                    kFDSave,&fileInfo);
398   
399   Save(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
400 }  
401
402 //______________________________________________________________________________
403 void
404 AliMUONMchViewApplication::Save(const char* filename)
405 {
406   /// Save VTrackerDataMaker objects into file of given name
407   
408   AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
409
410   TFile f(filename,"RECREATE");
411   
412   for ( Int_t i = 0; i < reg->NumberOfDataMakers(); ++i )
413   {
414     AliMUONVTrackerDataMaker* maker = reg->DataMaker(i);
415     maker->Write();
416   }
417   
418   f.Close();
419 }