]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONMchViewApplication.cxx
mchview version 0.93
[u/mrichter/AliRoot.git] / MUON / AliMUONMchViewApplication.cxx
CommitLineData
90037e4e 1#include "AliMUONMchViewApplication.h"
2
3#include "AliCDBManager.h"
4#include "AliCodeTimer.h"
5#include "AliLog.h"
6#include "AliMUONPainterDataSourceFrame.h"
49419555 7#include "AliMUONPainterEnv.h"
90037e4e 8#include "AliMUONPainterHelper.h"
9#include "AliMUONPainterMasterFrame.h"
10#include "AliMUONPainterRegistry.h"
49419555 11#include "AliMUONTrackerDataCompareDialog.h"
12#include "AliMUONTrackerDataWrapper.h"
90037e4e 13#include "AliMUONVTrackerData.h"
49419555 14#include "AliMUONVTrackerDataMaker.h"
90037e4e 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>
49419555 23#include <TGTextView.h>
24#include <TGrid.h>
90037e4e 25#include <TKey.h>
26#include <TList.h>
49419555 27#include <TRegexp.h>
90037e4e 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
38ClassImp(AliMUONMchViewApplication)
39/// \endcond CLASSIMP
40
41const Int_t AliMUONMchViewApplication::fgkFILESAVEAS(1);
42const Int_t AliMUONMchViewApplication::fgkFILEOPEN(2);
43const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
10eb3d17 44const Int_t AliMUONMchViewApplication::fgkFILEPRINTAS(4);
49419555 45const Int_t AliMUONMchViewApplication::fgkABOUT(5);
46const Int_t AliMUONMchViewApplication::fgkCOMPAREDATA(6);
10eb3d17 47
48const char* AliMUONMchViewApplication::fgkFileTypes[] = {
49 "ROOT files", "*.root",
50 "All files", "*",
51 0, 0 };
90037e4e 52
53//______________________________________________________________________________
54AliMUONMchViewApplication::AliMUONMchViewApplication(const char* name,
55 int* argc, char** argv,
56 Float_t wfraction,
57 Float_t hfraction)
58: TRint(name,argc,argv),
10eb3d17 59 fMainFrame(0x0),
60 fPainterMasterFrame(0x0)
90037e4e 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
10eb3d17 85 fPainterMasterFrame =
90037e4e 86 new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
87
10eb3d17 88 t->AddFrame(fPainterMasterFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
90037e4e 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();
10eb3d17 103
104 fPainterMasterFrame->Update();
105
90037e4e 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);
10eb3d17 117
118 cout << "***************************************************" << endl;
119 cout << " Welcome to mchview" << endl;
120 cout << " " << FullVersion() << endl;
121 cout << "***************************************************" << endl;
122
90037e4e 123}
124
125//______________________________________________________________________________
126AliMUONMchViewApplication::~AliMUONMchViewApplication()
127{
128 /// dtor
129}
130
49419555 131//______________________________________________________________________________
132void
133AliMUONMchViewApplication::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
90037e4e 154//______________________________________________________________________________
155void
156AliMUONMchViewApplication::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);
10eb3d17 164 file->AddEntry("&Print As...",fgkFILEPRINTAS);
90037e4e 165 file->AddEntry("&Exit",fgkFILEEXIT);
166
90037e4e 167 TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
168
49419555 169 TGPopupMenu* tools = new TGPopupMenu(gClient->GetRoot());
170 tools->AddEntry("&Compare data",fgkCOMPAREDATA);
171
10eb3d17 172 TGPopupMenu* about = new TGPopupMenu(gClient->GetRoot());
49419555 173 about->AddEntry(FullVersion(),fgkABOUT);
10eb3d17 174
49419555 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
90037e4e 179 bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
49419555 180 bar->AddPopup("&Tools",tools,new TGLayoutHints(kLHintsLeft|kLHintsTop));
10eb3d17 181 bar->AddPopup("&About",about,new TGLayoutHints(kLHintsRight|kLHintsTop));
90037e4e 182
183 fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
184
185 AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
186}
187
188//______________________________________________________________________________
189void
190AliMUONMchViewApplication::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;
10eb3d17 205 case fgkFILEPRINTAS:
206 PrintAs();
207 break;
49419555 208 case fgkABOUT:
209 ReleaseNotes();
210 break;
211 case fgkCOMPAREDATA:
212 CompareData();
213 break;
90037e4e 214 default:
215 break;
216 }
217}
218
219//______________________________________________________________________________
220void
221AliMUONMchViewApplication::Open()
222{
223 /// Open file dialog
224
225 TGFileInfo fileInfo;
226
10eb3d17 227 fileInfo.fFileTypes = fgkFileTypes;
228
49419555 229 delete[] fileInfo.fIniDir;
230
231 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
232
233 fileInfo.fIniDir = StrDup(env->String("LastOpenDir","."));
234
90037e4e 235 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
236 kFDOpen,&fileInfo);
49419555 237
238 env->Set("LastOpenDir",fileInfo.fIniDir);
239 env->Save();
240
90037e4e 241 Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
242}
243
244//______________________________________________________________________________
245void
246AliMUONMchViewApplication::Open(const char* filename)
247{
49419555 248 /// Open a given file containing saved VTrackerDataMaker objects
90037e4e 249
49419555 250 TString sfilename(gSystem->ExpandPathName(filename));
90037e4e 251
49419555 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();
90037e4e 264 TIter next(keys);
265
266 TKey* k;
267
268 while ( ( k = static_cast<TKey*>(next()) ) )
269 {
270 TObject* object = k->ReadObj();
49419555 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 }
90037e4e 280
281 if ( object->InheritsFrom("AliMUONVTrackerData") )
282 {
49419555 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);
90037e4e 287 if ( data )
288 {
49419555 289 AliMUONVTrackerDataMaker* maker = new AliMUONTrackerDataWrapper(data);
290 AliMUONPainterRegistry::Instance()->Register(maker);
90037e4e 291 }
292 }
293 }
49419555 294
295 delete f;
90037e4e 296}
297
298
10eb3d17 299//______________________________________________________________________________
300void
301AliMUONMchViewApplication::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
49419555 313//______________________________________________________________________________
314void
315AliMUONMchViewApplication::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
90037e4e 371//______________________________________________________________________________
372void
373AliMUONMchViewApplication::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//______________________________________________________________________________
386void
387AliMUONMchViewApplication::Save(const char* filename)
388{
49419555 389 /// Save VTrackerDataMaker objects into file of given name
90037e4e 390
391 AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
392
393 TFile f(filename,"RECREATE");
394
49419555 395 for ( Int_t i = 0; i < reg->NumberOfDataMakers(); ++i )
90037e4e 396 {
49419555 397 AliMUONVTrackerDataMaker* maker = reg->DataMaker(i);
398 maker->Write();
90037e4e 399 }
400
401 f.Close();
402}