]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONMchViewApplication.cxx
In AliMUONSimpleClusterServer
[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 "AliMUONChamberPainter.h"
24 #include "AliMUONDEPainter.h"
25 #include "AliMUONPainterDataRegistry.h"
26 #include "AliMUONPainterDataSourceFrame.h"
27 #include "AliMUONPainterEnv.h"
28 #include "AliMUONPainterHelper.h"
29 #include "AliMUONPainterGroup.h"
30 #include "AliMUONPainterMasterFrame.h"
31 #include "AliMUONPainterMatrix.h"
32 #include "AliMUONPainterRegistry.h"
33 #include "AliMUONTrackerDataCompareDialog.h"
34 #include "AliMUONTrackerDataWrapper.h"
35 #include "AliMUONVTrackerData.h"
36 #include "AliMUONVTrackerDataMaker.h"
37 #include <Riostream.h>
38 #include <TCanvas.h>
39 #include <TEnv.h>
40 #include <TFile.h>
41 #include <TGClient.h>
42 #include <TGFileDialog.h>
43 #include <TGMenu.h>
44 #include <TGTab.h>
45 #include <TGTextView.h>
46 #include <TGrid.h>
47 #include <TKey.h>
48 #include <TList.h>
49 #include <TRegexp.h>
50 #include <TString.h>
51 #include <TSystem.h>
52
53 /// \class AliMUONMchViewApplication
54 ///
55 /// Main class for the mchview program
56 ///
57 ///\author Laurent Aphecetche, Subatech
58
59 /// \cond CLASSIMP
60 ClassImp(AliMUONMchViewApplication)
61 /// \endcond CLASSIMP
62
63 const Int_t AliMUONMchViewApplication::fgkFILESAVEAS(1);
64 const Int_t AliMUONMchViewApplication::fgkFILEOPEN(2);
65 const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
66 const Int_t AliMUONMchViewApplication::fgkFILEPRINTAS(4);
67 const Int_t AliMUONMchViewApplication::fgkABOUT(5);
68 const Int_t AliMUONMchViewApplication::fgkCOMPAREDATA(6);
69
70 const char* AliMUONMchViewApplication::fgkFileTypes[] = { 
71   "ROOT files",    "*.root", 
72   "All files",     "*", 
73   0,               0 }; 
74
75 //______________________________________________________________________________
76 AliMUONMchViewApplication::AliMUONMchViewApplication(const char* name,
77                                                      int* argc, char** argv,
78                                                      UInt_t w, UInt_t h,
79                                                      UInt_t ox, UInt_t oy) 
80 : TRint(name,argc,argv),
81   fMainFrame(0x0),
82   fPainterMasterFrameList(new TList),
83   fTabs(0x0)
84 {
85
86   /// ctor
87   /// (w,h) is the size in pixel (if 0,0 it will be computed as 70%,90% of display size)
88   /// (ox,oy) is the offset from the top-left of the display
89
90   if (!w | !h)
91   {
92     w = (UInt_t)(gClient->GetDisplayWidth()*0.7);
93     h = (UInt_t)(gClient->GetDisplayHeight()*0.9); 
94   }
95
96   fMainFrame = new TGMainFrame(gClient->GetRoot(),w,h);
97
98   CreateMenuBar(w);
99
100   const Int_t kbs = 2;
101   
102 //  h -= 60; // menubar
103   
104   fTabs = new TGTab(fMainFrame,w,h);
105   
106   TGCompositeFrame* t = fTabs->AddTab("Painter Master Frame");
107
108   fPainterMasterFrameList->SetOwner(kTRUE);
109   
110   
111   AliMUONPainterMasterFrame* pmf = new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2,
112                                                                  GenerateStartupMatrix());
113
114   fPainterMasterFrameList->Add(pmf);
115   
116   t->AddFrame(pmf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
117
118   t = fTabs->AddTab("Data Sources");
119   
120   AliMUONPainterDataSourceFrame* dsf = 
121     new AliMUONPainterDataSourceFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
122   
123   t->AddFrame(dsf,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
124   
125   fMainFrame->AddFrame(fTabs,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,0,0,0,0));
126
127   fMainFrame->SetWindowName("mchview - Visualization of MUON Tracker detector");
128
129   fMainFrame->MapSubwindows();
130   fMainFrame->Resize();
131   
132   pmf->Update();
133   
134   fMainFrame->MapWindow();
135   
136   fMainFrame->Connect("CloseWindow()","AliMUONMchViewApplication",this,"Terminate()");
137
138   fMainFrame->MoveResize(ox,oy, w, h); 
139   fMainFrame->SetWMPosition(ox, oy);
140   fMainFrame->SetWMSizeHints(w,h,w,h,0,0);
141   
142   cout << "***************************************************" << endl;
143   cout << "   Welcome to mchview" << endl;
144   cout << "   " << FullVersion() << endl;
145   cout << "***************************************************" << endl;
146   
147   // Trying to see if we're requested to draw something specific instead
148   // of the global view of all the chambers
149   
150   AliMUONVPainter* painter(0x0);
151   TObjArray args;
152   args.SetOwner(kTRUE);
153   
154   for ( int i = 1; i < argc[0]; ++i ) 
155   {
156     args.Add(new TObjString(argv[i]));
157   }
158   
159   for ( Int_t i = 0; i <= args.GetLast(); ++i ) 
160   {
161     TString a(static_cast<TObjString*>(args.At(i))->String());
162
163     AliMUONAttPainter att;
164     
165     att.SetPlane(kTRUE,kFALSE);
166     att.SetCathode(kFALSE,kFALSE);
167     att.SetViewPoint(kTRUE,kFALSE);
168         
169     if ( a == "--de" )
170     {
171       Int_t detElemId = static_cast<TObjString*>(args.At(i+1))->String().Atoi();
172       
173       painter = new AliMUONDEPainter(att,detElemId);
174       
175       painter->SetOutlined("*",kFALSE);      
176       painter->SetOutlined("BUSPATCH",kTRUE);
177
178       painter->SetLine(1,4,3);      
179       ++i;
180     }
181
182     if ( a == "--chamber" )
183     {
184       Int_t chamberId = static_cast<TObjString*>(args.At(i+1))->String().Atoi();
185       
186       painter = new AliMUONChamberPainter(att,chamberId-1);
187       
188       painter->SetOutlined("*",kFALSE);      
189       painter->SetOutlined("DE",kTRUE);
190       
191       painter->SetLine(1,4,3);      
192       ++i;
193     }
194     
195   }
196   
197   if ( painter ) 
198   {
199     pmf->ShiftClicked(painter,0x0);
200     
201     pmf->Update();
202   }
203       
204 }
205
206 //______________________________________________________________________________
207 AliMUONMchViewApplication::~AliMUONMchViewApplication()
208 {
209   /// dtor
210   delete fPainterMasterFrameList;
211 }
212
213 //_____________________________________________________________________________
214 AliMUONPainterMatrix*
215 AliMUONMchViewApplication::GenerateStartupMatrix()
216 {
217   /// Kind of bootstrap method to trigger the generation of all contours
218   
219   AliCodeTimerAuto("",0);
220   
221   AliMUONAttPainter att;
222   
223   att.SetViewPoint(kTRUE,kFALSE);
224   att.SetCathode(kFALSE,kFALSE);
225   att.SetPlane(kTRUE,kFALSE);
226
227   AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
228     
229   for ( Int_t i = 0; i < 10; ++i )
230   {
231     AliMUONVPainter* painter = new AliMUONChamberPainter(att,i);
232     
233     painter->SetResponder("Chamber");
234     
235     painter->SetOutlined("*",kFALSE);
236     
237     painter->SetOutlined("MANU",kTRUE);
238     
239     for ( Int_t j = 0; j < 3; ++j ) 
240     {
241       painter->SetLine(j,1,4-j);
242     }
243     
244     matrix->Adopt(painter);    
245   }
246   AliMUONPainterRegistry::Instance()->Register(matrix);
247   return matrix;
248 }
249
250 //______________________________________________________________________________
251 void
252 AliMUONMchViewApplication::CompareData()
253 {
254   /// Launch compare data dialog
255   TGTransientFrame* t = new AliMUONTrackerDataCompareDialog(gClient->GetRoot(),
256                                                             gClient->GetRoot(),
257                                                             400,400);
258
259   t->MapSubwindows();
260   t->Resize();
261   t->MapWindow();
262   t->CenterOnParent();
263   
264   // set names
265   
266   t->SetWindowName("mchview compare data tool");
267   t->SetIconName("mchview compare data tool");
268   
269   t->MapRaised();  
270 }
271
272 //______________________________________________________________________________
273 void
274 AliMUONMchViewApplication::CreateMenuBar(UInt_t w)
275 {
276   /// Create the application menu bar
277   
278   TGPopupMenu* file = new TGPopupMenu(gClient->GetRoot());
279   
280   file->AddEntry("&Open...",fgkFILEOPEN);
281   file->AddEntry("&Save As...",fgkFILESAVEAS);
282   file->AddEntry("&Print As...",fgkFILEPRINTAS);
283   file->AddEntry("&Exit",fgkFILEEXIT);
284   
285   TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
286   
287   TGPopupMenu* tools = new TGPopupMenu(gClient->GetRoot());
288   tools->AddEntry("&Compare data",fgkCOMPAREDATA);
289   
290   TGPopupMenu* about = new TGPopupMenu(gClient->GetRoot());  
291   about->AddEntry(FullVersion(),fgkABOUT);
292
293   file->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
294   about->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
295   tools->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
296   
297   bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
298   bar->AddPopup("&Tools",tools,new TGLayoutHints(kLHintsLeft|kLHintsTop));
299   bar->AddPopup("&About",about,new TGLayoutHints(kLHintsRight|kLHintsTop));
300   
301   fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
302   
303   AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
304 }
305
306 //______________________________________________________________________________
307 void
308 AliMUONMchViewApplication::HandleMenu(Int_t i)
309 {
310   /// Handle the click of one menu item
311
312   switch (i)
313     {
314     case fgkFILEEXIT:
315       Terminate(1);
316       break;
317     case fgkFILEOPEN:
318       Open();
319       break;
320     case fgkFILESAVEAS:
321       Save();
322       break;
323     case fgkFILEPRINTAS:
324       PrintAs();
325       break;
326     case fgkABOUT:
327       ReleaseNotes();
328       break;
329     case fgkCOMPAREDATA:
330       CompareData();
331       break;
332     default:
333       break;
334     }
335 }
336
337 //______________________________________________________________________________
338 void
339 AliMUONMchViewApplication::Open()
340 {
341   /// Open file dialog
342   
343   TGFileInfo fileInfo;
344   
345   fileInfo.fFileTypes = fgkFileTypes;
346   
347   delete[] fileInfo.fIniDir;
348   
349   AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
350   
351   fileInfo.fIniDir = StrDup(env->String("LastOpenDir","."));
352   
353   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
354                    kFDOpen,&fileInfo);
355
356   env->Set("LastOpenDir",fileInfo.fIniDir);
357   env->Save();  
358     
359   Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
360 }  
361
362 //______________________________________________________________________________
363 void
364 AliMUONMchViewApplication::Open(const char* filename)
365 {
366   /// Open a given file containing saved VTrackerDataMaker objects
367   
368   TString sfilename(gSystem->ExpandPathName(filename));
369   
370   if ( sfilename.Contains(TRegexp("^alien")) )
371   {
372     // insure we've initialized the grid...
373     if (!gGrid)
374     {
375       TGrid::Connect("alien://");
376     }
377   }
378   
379   TFile* f = TFile::Open(filename);
380   
381         ReadDir(*f);
382         
383         delete f;
384 }
385
386 //______________________________________________________________________________
387 void
388 AliMUONMchViewApplication::ReadDir(TDirectory& dir)
389 {
390   /// Read the given directory and import VTrackerData objects found
391   
392   TList* keys = dir.GetListOfKeys();
393   TIter next(keys);
394   
395   TKey* k;
396   
397   while ( ( k = static_cast<TKey*>(next()) ) )
398   {
399     TObject* object = k->ReadObj();
400
401                 if ( object->InheritsFrom("TDirectory") )
402                 {
403                         TDirectory* d = static_cast<TDirectory*>(object);
404                         ReadDir(*d);
405                         continue;
406                 }
407                 
408     if ( object->InheritsFrom("AliMUONVTrackerDataMaker") )
409     {
410       AliMUONVTrackerDataMaker* maker = dynamic_cast<AliMUONVTrackerDataMaker*>(object);
411       if ( maker ) 
412       {
413         AliMUONPainterDataRegistry::Instance()->Register(maker);
414       }
415     }
416     
417     if ( object->InheritsFrom("AliMUONVTrackerData") )
418     {
419       // this is for backward compatibility. Early versions of mchview 
420       // wrote VTrackerData objects, and not VTrackerDataMaker ones.
421       
422       AliMUONVTrackerData* data = dynamic_cast<AliMUONVTrackerData*>(object);
423       if ( data ) 
424       {
425         AliMUONVTrackerDataMaker* maker = new AliMUONTrackerDataWrapper(data);
426         AliMUONPainterDataRegistry::Instance()->Register(maker);
427       }
428     }
429   }
430   
431
432
433 //______________________________________________________________________________
434 void
435 AliMUONMchViewApplication::PrintAs()
436 {
437   /// Print as...
438   
439   TGFileInfo fileInfo;
440   
441   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
442                    kFDSave,&fileInfo);
443   
444   TIter next(fPainterMasterFrameList);
445   AliMUONPainterMasterFrame* pmf;
446   Bool_t first(kTRUE);
447   
448   while ( ( pmf = static_cast<AliMUONPainterMasterFrame*>(next()) ) )
449   {
450     pmf->SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)),
451                 first ? "RECREATE" : "UPDATE");
452     first = kFALSE;
453   }
454 }
455
456 //______________________________________________________________________________
457 void
458 AliMUONMchViewApplication::ReleaseNotes()
459 {
460   /// Display release notes
461   
462   UInt_t width = 600;
463   UInt_t height = 400;
464   
465   TGTransientFrame* t = new TGTransientFrame(gClient->GetRoot(),gClient->GetRoot(),width,height);
466   
467   TGTextView* rn = new TGTextView(t);
468
469   rn->AddLine("1.05");
470   rn->AddLine("");
471   rn->AddLine("Added the possibility to select an event range when reading raw data");
472   rn->AddLine("Usefull e.g. to look at a single suspect event...");
473   rn->AddLine("");
474   
475   rn->AddLine("1.04");
476   rn->AddLine("");
477   rn->AddLine("Changed the default OCDB to 2010 version");
478   rn->AddLine("");
479   
480   rn->AddLine("1.03");
481   rn->AddLine("");
482   rn->AddLine("Add Print buttons");
483   rn->AddLine("Add the automatic creation of often used canvases when using pedestal source");
484   // Internal reorganization to allow several independent tabs to be created to 
485   // show different master frames (not used yet). Important for the moment
486   // is the ability to create a PainterMatrix and pass it to the PainterMasterFrame
487   rn->AddLine("");
488   
489   rn->AddLine("1.02");
490   rn->AddLine("");
491   rn->AddLine("Internal change (merging of AliMUONTrackerACFDataMaker and AliMUONTrackerOCDBDataMaker into AliMUONTrackerConditionDataMaker)");
492   rn->AddLine("Added --ocdb option");
493   rn->AddLine("Corrected the display of the configuration");
494   rn->AddLine("Corrected the interpretation of the switches for the HV display");
495   rn->AddLine("");
496   
497   rn->AddLine("1.01");
498   rn->AddLine("");
499   rn->AddLine("Added the configuration as a possible OCDB data source");
500   rn->AddLine("");
501   
502   rn->AddLine("1.00");
503   rn->AddLine("");
504   rn->AddLine("Added the Status and StatusMap as a possible OCDB data source");
505   rn->AddLine("");
506   rn->AddLine("Added one (computed) dimension to the Gains data source = 1/a1/0.2 (mV/fC)");
507   rn->AddLine("");
508     
509   rn->AddLine("0.99a");
510   rn->AddLine("");
511   rn->AddLine("Added the --de and --chamber options");
512   rn->AddLine("");
513   
514   rn->AddLine("0.99");
515   rn->AddLine("");
516   rn->AddLine("The chamberid in the label (top right of panel) is now starting at 1 as in common usage");  
517   rn->AddLine("");
518   
519   rn->AddLine("0.98");
520   rn->AddLine("");
521   rn->AddLine("Added --asciimapping option");
522   rn->AddLine("");
523   
524   rn->AddLine("0.97");
525   rn->AddLine("");
526   rn->AddLine("Adding calibration option with Emelec (aka injection) gain");
527   rn->AddLine("");
528   
529   rn->AddLine("0.96a");
530   rn->AddLine("");
531   rn->AddLine("Internal reorganization of the contour computations, that lead to improved performance. ");
532   rn->AddLine("Improved enough to be able to remove completely the usage of the padstore.root file with precomputed contours.");
533   rn->AddLine("");
534   
535   rn->AddLine("0.96");
536   rn->AddLine("");
537   rn->AddLine("New features");
538   rn->AddLine("");
539   rn->AddLine("- Can now read raw data from memory (using the mem://@gdc: syntax)");
540   rn->AddLine("- Raw data decoder now automatically skips buspatches with parity errors");
541   rn->AddLine("");
542   
543   rn->AddLine("0.95");
544   rn->AddLine("");
545   rn->AddLine("New features");
546   rn->AddLine("");
547   rn->AddLine("- Can now read and display HV values from OCDB");
548   rn->AddLine("- New program option --geometry to force geometry of the window");
549   rn->AddLine("- Added possibility, in painters' context menu, to include or exclude part of the detector");
550   rn->AddLine("  (which will be used later on to communicate with LC2 which parts should be read out or not)");
551   rn->AddLine("");
552   rn->AddLine("Improvement");
553   rn->AddLine("");
554   rn->AddLine("- When displaying Gains, the quality information is now decoded");
555   rn->AddLine("");
556   
557   rn->AddLine("0.94");
558   rn->AddLine("");
559   rn->AddLine("New features");
560   rn->AddLine("");
561   rn->AddLine("Can now read ASCII calibration files produced by the DA");
562   rn->AddLine("");
563   
564   rn->AddLine("0.93");
565   rn->AddLine("");
566   rn->AddLine("New features");
567   rn->AddLine("");
568   rn->AddLine("- Adding a Lock button under the color slider to lock the range shown");
569   rn->AddLine("  when switching between views");
570   rn->AddLine("- Default display now shows bending plane (instead of cathode 0 before)");
571   rn->AddLine("- If pad is responder and there's some histo for that pad, ");
572   rn->AddLine("  clicking on it will display an histo");
573   rn->AddLine("- Right-click on a painter will now display several histogram options");
574   rn->AddLine("  (e.g. raw charge as before, but also simple distributions of mean");
575   rn->AddLine("  and sigma");
576   rn->AddLine("- In the Data Sources Tab, each data source can now be removed and saved");
577   rn->AddLine("- There's a new Tool menu which allow to produce a TrackerData from two others");
578   rn->AddLine("  in order to compare data.");
579   rn->AddLine("  - The --use option can now reference alien files");
580   rn->AddLine("");    
581   rn->AddLine("Bug fixes");
582   rn->AddLine("");    
583   rn->AddLine("- Can now read Capacitances from OCDB");
584     
585   rn->Resize(width,height);
586   
587   t->AddFrame(rn, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
588   
589   t->MapSubwindows();
590   t->Resize();
591   t->MapWindow();
592   t->CenterOnParent();
593     
594   // set names
595   
596   t->SetWindowName("mchview release notes");
597   t->SetIconName("mchview release notes");
598   
599 //  t->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
600 //              kMWMDecorMinimize | kMWMDecorMenu,
601 //              kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
602 //              kMWMFuncMinimize,
603 //              kMWMInputModeless);
604   
605   t->MapRaised();
606 //  gClient->WaitFor(t);
607 }
608
609 //______________________________________________________________________________
610 void
611 AliMUONMchViewApplication::Save()
612 {
613   /// Open "Save VTrackerData objects to file" dialog
614   
615   TGFileInfo fileInfo;
616   
617   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
618                    kFDSave,&fileInfo);
619   
620   Save(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
621 }  
622
623 //______________________________________________________________________________
624 void
625 AliMUONMchViewApplication::Save(const char* filename)
626 {
627   /// Save VTrackerDataMaker objects into file of given name
628   
629   AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
630
631   TFile f(filename,"RECREATE");
632   
633   for ( Int_t i = 0; i < reg->NumberOfDataMakers(); ++i )
634   {
635     AliMUONVTrackerDataMaker* maker = reg->DataMaker(i);
636     maker->Write();
637   }
638   
639   f.Close();
640 }