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