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