]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONMchViewApplication.cxx
In AliMUONRawStreamTriggerHP:
[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,
73 Float_t wfraction,
74 Float_t hfraction)
75: TRint(name,argc,argv),
10eb3d17 76 fMainFrame(0x0),
77 fPainterMasterFrame(0x0)
90037e4e 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
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()");
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);
10eb3d17 134
135 cout << "***************************************************" << endl;
136 cout << " Welcome to mchview" << endl;
137 cout << " " << FullVersion() << endl;
138 cout << "***************************************************" << endl;
139
90037e4e 140}
141
142//______________________________________________________________________________
143AliMUONMchViewApplication::~AliMUONMchViewApplication()
144{
145 /// dtor
146}
147
49419555 148//______________________________________________________________________________
149void
150AliMUONMchViewApplication::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
90037e4e 171//______________________________________________________________________________
172void
173AliMUONMchViewApplication::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);
10eb3d17 181 file->AddEntry("&Print As...",fgkFILEPRINTAS);
90037e4e 182 file->AddEntry("&Exit",fgkFILEEXIT);
183
90037e4e 184 TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
185
49419555 186 TGPopupMenu* tools = new TGPopupMenu(gClient->GetRoot());
187 tools->AddEntry("&Compare data",fgkCOMPAREDATA);
188
10eb3d17 189 TGPopupMenu* about = new TGPopupMenu(gClient->GetRoot());
49419555 190 about->AddEntry(FullVersion(),fgkABOUT);
10eb3d17 191
49419555 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
90037e4e 196 bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
49419555 197 bar->AddPopup("&Tools",tools,new TGLayoutHints(kLHintsLeft|kLHintsTop));
10eb3d17 198 bar->AddPopup("&About",about,new TGLayoutHints(kLHintsRight|kLHintsTop));
90037e4e 199
200 fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
201
202 AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
203}
204
205//______________________________________________________________________________
206void
207AliMUONMchViewApplication::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;
10eb3d17 222 case fgkFILEPRINTAS:
223 PrintAs();
224 break;
49419555 225 case fgkABOUT:
226 ReleaseNotes();
227 break;
228 case fgkCOMPAREDATA:
229 CompareData();
230 break;
90037e4e 231 default:
232 break;
233 }
234}
235
236//______________________________________________________________________________
237void
238AliMUONMchViewApplication::Open()
239{
240 /// Open file dialog
241
242 TGFileInfo fileInfo;
243
10eb3d17 244 fileInfo.fFileTypes = fgkFileTypes;
245
49419555 246 delete[] fileInfo.fIniDir;
247
248 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
249
250 fileInfo.fIniDir = StrDup(env->String("LastOpenDir","."));
251
90037e4e 252 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
253 kFDOpen,&fileInfo);
49419555 254
255 env->Set("LastOpenDir",fileInfo.fIniDir);
256 env->Save();
257
90037e4e 258 Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
259}
260
261//______________________________________________________________________________
262void
263AliMUONMchViewApplication::Open(const char* filename)
264{
49419555 265 /// Open a given file containing saved VTrackerDataMaker objects
90037e4e 266
49419555 267 TString sfilename(gSystem->ExpandPathName(filename));
90037e4e 268
49419555 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();
90037e4e 281 TIter next(keys);
282
283 TKey* k;
284
285 while ( ( k = static_cast<TKey*>(next()) ) )
286 {
287 TObject* object = k->ReadObj();
49419555 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 }
90037e4e 297
298 if ( object->InheritsFrom("AliMUONVTrackerData") )
299 {
49419555 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);
90037e4e 304 if ( data )
305 {
49419555 306 AliMUONVTrackerDataMaker* maker = new AliMUONTrackerDataWrapper(data);
307 AliMUONPainterRegistry::Instance()->Register(maker);
90037e4e 308 }
309 }
310 }
49419555 311
312 delete f;
90037e4e 313}
314
315
10eb3d17 316//______________________________________________________________________________
317void
318AliMUONMchViewApplication::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
49419555 330//______________________________________________________________________________
331void
332AliMUONMchViewApplication::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
1286237e 343 rn->AddLine("0.94");
344 rn->AddLine("");
345 rn->AddLine("New features");
346 rn->AddLine("");
347 rn->AddLine("Can now read ASCII calibration files produced by the DA");
348 rn->AddLine("");
349
49419555 350 rn->AddLine("0.93");
351 rn->AddLine("");
352 rn->AddLine("New features");
353 rn->AddLine("");
354 rn->AddLine("- Adding a Lock button under the color slider to lock the range shown");
355 rn->AddLine(" when switching between views");
356 rn->AddLine("- Default display now shows bending plane (instead of cathode 0 before)");
357 rn->AddLine("- If pad is responder and there's some histo for that pad, ");
358 rn->AddLine(" clicking on it will display an histo");
359 rn->AddLine("- Right-click on a painter will now display several histogram options");
360 rn->AddLine(" (e.g. raw charge as before, but also simple distributions of mean");
361 rn->AddLine(" and sigma");
362 rn->AddLine("- In the Data Sources Tab, each data source can now be removed and saved");
363 rn->AddLine("- There's a new Tool menu which allow to produce a TrackerData from two others");
364 rn->AddLine(" in order to compare data.");
365 rn->AddLine(" - The --use option can now reference alien files");
366 rn->AddLine("");
367 rn->AddLine("Bug fixes");
368 rn->AddLine("");
369 rn->AddLine("- Can now read Capacitances from OCDB");
370
371 rn->Resize(width,height);
372
373 t->AddFrame(rn, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
374
375 t->MapSubwindows();
376 t->Resize();
377 t->MapWindow();
378 t->CenterOnParent();
379
380 // set names
381
382 t->SetWindowName("mchview release notes");
383 t->SetIconName("mchview release notes");
384
385// t->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
386// kMWMDecorMinimize | kMWMDecorMenu,
387// kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
388// kMWMFuncMinimize,
389// kMWMInputModeless);
390
391 t->MapRaised();
392// gClient->WaitFor(t);
393}
394
90037e4e 395//______________________________________________________________________________
396void
397AliMUONMchViewApplication::Save()
398{
399 /// Open "Save VTrackerData objects to file" dialog
400
401 TGFileInfo fileInfo;
402
403 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
404 kFDSave,&fileInfo);
405
406 Save(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
407}
408
409//______________________________________________________________________________
410void
411AliMUONMchViewApplication::Save(const char* filename)
412{
49419555 413 /// Save VTrackerDataMaker objects into file of given name
90037e4e 414
415 AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
416
417 TFile f(filename,"RECREATE");
418
49419555 419 for ( Int_t i = 0; i < reg->NumberOfDataMakers(); ++i )
90037e4e 420 {
49419555 421 AliMUONVTrackerDataMaker* maker = reg->DataMaker(i);
422 maker->Write();
90037e4e 423 }
424
425 f.Close();
426}