]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONMchViewApplication.cxx
Bug fix (selection of RawReaderDate from Yuri was not correct)
[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"
7#include "AliMUONPainterHelper.h"
8#include "AliMUONPainterMasterFrame.h"
9#include "AliMUONPainterRegistry.h"
10#include "AliMUONVTrackerData.h"
11#include <Riostream.h>
12#include <TCanvas.h>
13#include <TEnv.h>
14#include <TFile.h>
15#include <TGClient.h>
16#include <TGFileDialog.h>
17#include <TGMenu.h>
18#include <TGTab.h>
19#include <TKey.h>
20#include <TList.h>
21#include <TString.h>
22#include <TSystem.h>
23
24/// \class AliMUONMchViewApplication
25///
26/// Main class for the mchview program
27///
28///\author Laurent Aphecetche, Subatech
29
30/// \cond CLASSIMP
31ClassImp(AliMUONMchViewApplication)
32/// \endcond CLASSIMP
33
34const Int_t AliMUONMchViewApplication::fgkFILESAVEAS(1);
35const Int_t AliMUONMchViewApplication::fgkFILEOPEN(2);
36const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
37
38//______________________________________________________________________________
39AliMUONMchViewApplication::AliMUONMchViewApplication(const char* name,
40 int* argc, char** argv,
41 Float_t wfraction,
42 Float_t hfraction)
43: TRint(name,argc,argv),
44 fMainFrame(0x0)
45{
46
47 /// ctor
48 /// wfraction,hfraction are the fractions of display width and height
49 /// we want to draw on
50
51 UInt_t dw = gClient->GetDisplayWidth();
52 UInt_t dh = gClient->GetDisplayHeight();
53
54 UInt_t w = (UInt_t)(wfraction*dw);
55 UInt_t h = (UInt_t)(hfraction*dh);
56
57 fMainFrame = new TGMainFrame(gClient->GetRoot(),w,h);
58
59 CreateMenuBar(w);
60
61 const Int_t kbs = 2;
62
63// h -= 60; // menubar
64
65 TGTab* tabs = new TGTab(fMainFrame,w,h);
66
67 TGCompositeFrame* t = tabs->AddTab("Painter Master Frame");
68
69 AliMUONPainterMasterFrame* pf =
70 new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
71
72 t->AddFrame(pf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
73
74 t = tabs->AddTab("Data Sources");
75
76 AliMUONPainterDataSourceFrame* dsf =
77 new AliMUONPainterDataSourceFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
78
79 t->AddFrame(dsf,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
80
81 fMainFrame->AddFrame(tabs,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,0,0,0,0));
82
83 fMainFrame->SetWindowName("mchview - Visualization of MUON Tracker detector");
84
85 fMainFrame->MapSubwindows();
86 fMainFrame->Resize();
87 fMainFrame->MapWindow();
88
89 fMainFrame->Connect("CloseWindow()","AliMUONMchViewApplication",this,"Terminate()");
90
91 UInt_t x = dw/2 - w/2;
92 UInt_t y = 0;
93
94 fMainFrame->MoveResize(x, y, w, h);
95 fMainFrame->SetWMPosition(x, y);
96
97 fMainFrame->SetWMSizeHints(w,h,w,h,0,0);
98}
99
100//______________________________________________________________________________
101AliMUONMchViewApplication::~AliMUONMchViewApplication()
102{
103 /// dtor
104}
105
106//______________________________________________________________________________
107void
108AliMUONMchViewApplication::CreateMenuBar(UInt_t w)
109{
110 /// Create the application menu bar
111
112 TGPopupMenu* file = new TGPopupMenu(gClient->GetRoot());
113
114 file->AddEntry("&Open...",fgkFILEOPEN);
115 file->AddEntry("&Save As...",fgkFILESAVEAS);
116 file->AddEntry("&Exit",fgkFILEEXIT);
117
118 file->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
119
120 TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
121
122 bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
123
124 fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
125
126 AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
127}
128
129//______________________________________________________________________________
130void
131AliMUONMchViewApplication::HandleMenu(Int_t i)
132{
133 /// Handle the click of one menu item
134
135 switch (i)
136 {
137 case fgkFILEEXIT:
138 Terminate(1);
139 break;
140 case fgkFILEOPEN:
141 Open();
142 break;
143 case fgkFILESAVEAS:
144 Save();
145 break;
146 default:
147 break;
148 }
149}
150
151//______________________________________________________________________________
152void
153AliMUONMchViewApplication::Open()
154{
155 /// Open file dialog
156
157 TGFileInfo fileInfo;
158
159 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
160 kFDOpen,&fileInfo);
161
162 Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
163}
164
165//______________________________________________________________________________
166void
167AliMUONMchViewApplication::Open(const char* filename)
168{
169 /// Open a given file containing saved VTrackerData objects
170
171 TFile f(filename);
172
173 TList* keys = f.GetListOfKeys();
174 TIter next(keys);
175
176 TKey* k;
177
178 while ( ( k = static_cast<TKey*>(next()) ) )
179 {
180 TObject* object = k->ReadObj();
181
182 if ( object->InheritsFrom("AliMUONVTrackerData") )
183 {
184 AliMUONVTrackerData* data = static_cast<AliMUONVTrackerData*>(object);
185 if ( data )
186 {
187 AliMUONPainterRegistry::Instance()->Register(data);
188 }
189 }
190 }
191}
192
193
194//______________________________________________________________________________
195void
196AliMUONMchViewApplication::Save()
197{
198 /// Open "Save VTrackerData objects to file" dialog
199
200 TGFileInfo fileInfo;
201
202 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
203 kFDSave,&fileInfo);
204
205 Save(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
206}
207
208//______________________________________________________________________________
209void
210AliMUONMchViewApplication::Save(const char* filename)
211{
212 /// Save VTrackerData objects into file of given name
213
214 AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
215
216 TFile f(filename,"RECREATE");
217
218 for ( Int_t i = 0; i < reg->NumberOfDataSources(); ++i )
219 {
220 AliMUONVTrackerData* data = reg->DataSource(i);
221 data->Write();
222 }
223
224 f.Close();
225}