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