]>
Commit | Line | Data |
---|---|---|
0145e89a | 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 "AliMUONPainterDataSourceFrame.h" | |
19 | ||
8741815f | 20 | |
21 | #include "AliLog.h" | |
0145e89a | 22 | #include "AliMUONPainterDataSourceItem.h" |
23 | #include "AliMUONPainterEnv.h" | |
24 | #include "AliMUONPainterHelper.h" | |
25 | #include "AliMUONPainterRegistry.h" | |
8741815f | 26 | #include "AliMUONTrackerCalibratedDataMaker.h" |
0145e89a | 27 | #include "AliMUONTrackerOCDBDataMaker.h" |
28 | #include "AliMUONTrackerRawDataMaker.h" | |
0145e89a | 29 | #include "AliRawReaderDate.h" |
30 | #include "AliRawReaderRoot.h" | |
31 | #include <TGButton.h> | |
32 | #include <TGComboBox.h> | |
33 | #include <TGFileDialog.h> | |
34 | #include <TGNumberEntry.h> | |
35 | #include <TGTextEntry.h> | |
36 | #include <TGrid.h> | |
37 | #include <TObjArray.h> | |
38 | #include <TObjString.h> | |
39 | #include <TRegexp.h> | |
40 | #include <TString.h> | |
41 | #include <TSystem.h> | |
42 | ||
43 | ///\class AliMUONPainterDataSourceFrame | |
44 | /// | |
45 | /// A complete frame to select and display various data sources to | |
46 | /// be displayed : either raw data or OCDB data. | |
47 | /// Later on we might add digits and clusters for instance. | |
48 | /// | |
49 | ///\author Laurent Aphecetche, Subatech | |
50 | ||
51 | const char* AliMUONPainterDataSourceFrame::fgkNumberOfDataSourcesKey = "NumberOfDataSources"; | |
52 | const char* AliMUONPainterDataSourceFrame::fgkDataSourceURIKey = "DataSourceURI.%d"; | |
53 | ||
54 | ///\cond CLASSIMP | |
55 | ClassImp(AliMUONPainterDataSourceFrame) | |
56 | ///\endcond | |
57 | ||
58 | //_____________________________________________________________________________ | |
59 | AliMUONPainterDataSourceFrame::AliMUONPainterDataSourceFrame(const TGWindow* p, UInt_t w, UInt_t h) | |
60 | : TGCompositeFrame(p,w,h,kVerticalFrame), | |
61 | fRecentSourceSelector(new TGGroupFrame(p,"Recent sources",kHorizontalFrame)), | |
62 | fRawSelector(new TGGroupFrame(p,"Raw file URI",kHorizontalFrame)), | |
8741815f | 63 | fRawSelector2(new TGCompositeFrame(fRawSelector,w,h,kVerticalFrame)), |
64 | fRawSelector21(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)), | |
65 | fRawSelector22(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)), | |
66 | fRawSelector23(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)), | |
67 | fCalibrateButton(new TGCheckButton(fRawSelector22,"Calibrate")), | |
68 | fHistogramButton(new TGCheckButton(fRawSelector23,"Histogram")), | |
69 | fRawOCDBPath(new TGTextEntry(fRawSelector22,"")), | |
0145e89a | 70 | fOCDBSelector(new TGGroupFrame(p,"OCDB Path",kHorizontalFrame)), |
71 | fDataReaders(new TGGroupFrame(p,"Data sources")), | |
8741815f | 72 | fFilePath(new TGTextEntry(fRawSelector21,"")), |
0145e89a | 73 | fOCDBPath(new TGTextEntry(fOCDBSelector,"")), |
74 | fRunSelector(new TGNumberEntry(fOCDBSelector,0)), | |
75 | fOCDBTypes(new TGComboBox(fOCDBSelector)), | |
76 | fRecentSources(new TGComboBox(fRecentSourceSelector)), | |
77 | fItems(new TObjArray) | |
78 | { | |
79 | /// Ctor | |
80 | ||
81 | AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance(); | |
82 | ||
83 | reg->Connect("DataReaderWasRegistered(AliMUONVTrackerDataMaker*)", | |
84 | "AliMUONPainterDataSourceFrame", | |
85 | this, | |
86 | "DataReaderWasRegistered(AliMUONVTrackerDataMaker*)"); | |
87 | ||
88 | reg->Connect("DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)", | |
89 | "AliMUONPainterDataSourceFrame", | |
90 | this, | |
91 | "DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)"); | |
92 | ||
93 | fItems->SetOwner(kFALSE); | |
94 | ||
95 | /// Recent source selection | |
96 | ||
97 | AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env(); | |
98 | ||
99 | Int_t nsources = env->Integer(fgkNumberOfDataSourcesKey); | |
100 | ||
101 | for ( Int_t i = 0; i < nsources; ++i ) | |
102 | { | |
103 | AddRecentSource(env->String(Form(fgkDataSourceURIKey,i))); | |
104 | } | |
105 | ||
106 | fRecentSources->Resize(100,20); | |
107 | ||
108 | TGButton* createRecentButton = new TGTextButton(fRecentSourceSelector,"Create data source"); | |
109 | createRecentButton->Connect("Clicked()", | |
110 | "AliMUONPainterDataSourceFrame", | |
111 | this, | |
112 | "OpenRecentSource()"); | |
113 | ||
114 | fRecentSourceSelector->AddFrame(fRecentSources,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5)); | |
115 | fRecentSourceSelector->AddFrame(createRecentButton,new TGLayoutHints(kLHintsTop,5,5,5,5)); | |
116 | ||
117 | /// Raw file selection | |
118 | ||
8741815f | 119 | TGButton* openButton = new TGPictureButton(fRawSelector21, |
0145e89a | 120 | gClient->GetPicture("fileopen.xpm")); |
121 | openButton->SetToolTipText("Click to open file dialog"); | |
122 | ||
8741815f | 123 | fRawSelector2->AddFrame(fRawSelector21, new TGLayoutHints(kLHintsExpandX,5,5,5,5)); |
124 | fRawSelector2->AddFrame(fRawSelector22, new TGLayoutHints(kLHintsExpandX,5,5,5,5)); | |
125 | fRawSelector2->AddFrame(fRawSelector23, new TGLayoutHints(kLHintsExpandX,5,5,5,5)); | |
126 | ||
127 | fRawSelector21->AddFrame(openButton,new TGLayoutHints(kLHintsTop,5,5,5,5)); | |
128 | fRawSelector21->AddFrame(fFilePath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5)); | |
129 | ||
130 | fRawSelector22->AddFrame(fCalibrateButton, new TGLayoutHints(kLHintsTop,5,5,5,5)); | |
131 | fRawSelector22->AddFrame(fRawOCDBPath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5)); | |
132 | fRawOCDBPath->SetEnabled(kFALSE); | |
0145e89a | 133 | |
8741815f | 134 | fRawSelector23->AddFrame(fHistogramButton,new TGLayoutHints(kLHintsTop,5,5,5,5)); |
135 | ||
136 | TGButton* createRawButton = new TGTextButton(fRawSelector,"Create data source"); | |
0145e89a | 137 | |
8741815f | 138 | fRawSelector->AddFrame(fRawSelector2, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5)); |
139 | fRawSelector->AddFrame(createRawButton, new TGLayoutHints(kLHintsCenterY,5,5,5,5)); | |
140 | ||
141 | fCalibrateButton->Connect("Clicked()", | |
142 | "AliMUONPainterDataSourceFrame", | |
143 | this, | |
144 | "CalibrateButtonClicked()"); | |
145 | ||
0145e89a | 146 | openButton->Connect("Clicked()", |
147 | "AliMUONPainterDataSourceFrame", | |
148 | this, | |
149 | "OpenFileDialog()"); | |
150 | ||
151 | createRawButton->Connect("Clicked()", | |
152 | "AliMUONPainterDataSourceFrame", | |
153 | this, | |
154 | "CreateRawDataSource()"); | |
155 | ||
156 | /// OCDB selection | |
157 | ||
158 | fOCDBTypes->AddEntry("Pedestals",0); | |
159 | fOCDBTypes->AddEntry("Gains",1); | |
160 | fOCDBTypes->AddEntry("Capacitances",2); | |
161 | fOCDBTypes->Select(0); | |
162 | fOCDBTypes->Resize(100,20); | |
163 | ||
164 | TGButton* createOCDBButton = new TGTextButton(fOCDBSelector,"Create data source"); | |
165 | createOCDBButton->Connect("Clicked()", | |
166 | "AliMUONPainterDataSourceFrame", | |
167 | this, | |
168 | "CreateOCDBDataSource()"); | |
169 | ||
170 | ||
171 | fOCDBSelector->AddFrame(fOCDBPath,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5)); | |
172 | fOCDBSelector->AddFrame(fRunSelector,new TGLayoutHints(kLHintsTop,5,5,5,5)); | |
173 | fOCDBSelector->AddFrame(fOCDBTypes,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5)); | |
174 | fOCDBSelector->AddFrame(createOCDBButton,new TGLayoutHints(kLHintsTop,5,5,5,5)); | |
175 | ||
176 | AddFrame(fRecentSourceSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10)); | |
177 | ||
178 | AddFrame(fRawSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10)); | |
179 | ||
180 | AddFrame(fOCDBSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10)); | |
181 | ||
182 | AddFrame(fDataReaders, new TGLayoutHints(kLHintsExpandX,10,10,10,10)); | |
183 | ||
184 | } | |
185 | ||
186 | //_____________________________________________________________________________ | |
187 | AliMUONPainterDataSourceFrame::~AliMUONPainterDataSourceFrame() | |
188 | { | |
189 | /// dtor | |
190 | ||
191 | delete fItems; | |
192 | } | |
193 | ||
194 | //_____________________________________________________________________________ | |
195 | void | |
196 | AliMUONPainterDataSourceFrame::AddRecentSource(const char* name) | |
197 | { | |
198 | /// Add a source to the list of recently used sources | |
199 | ||
200 | TGListBox* lb = fRecentSources->GetListBox(); | |
201 | ||
202 | for ( Int_t i = 0; i < lb->GetNumberOfEntries(); ++i ) | |
203 | { | |
204 | TGTextLBEntry* t = (TGTextLBEntry*)lb->GetEntry(i); | |
205 | TString s(t->GetText()->GetString()); | |
206 | if ( s == name ) | |
207 | { | |
208 | return; | |
209 | } | |
210 | } | |
211 | ||
212 | fRecentSources->AddEntry(name,lb->GetNumberOfEntries()); | |
213 | fRecentSources->MapSubwindows(); | |
214 | fRecentSources->Layout(); | |
215 | } | |
216 | ||
8741815f | 217 | //_____________________________________________________________________________ |
218 | void | |
219 | AliMUONPainterDataSourceFrame::CalibrateButtonClicked() | |
220 | { | |
221 | /// Calibrate button was clicked. | |
222 | ||
223 | if ( fCalibrateButton->IsOn() ) | |
224 | { | |
225 | fRawOCDBPath->SetEnabled(kTRUE); | |
226 | fRawOCDBPath->SetFocus(); | |
227 | fHistogramButton->SetEnabled(kFALSE); | |
228 | } | |
229 | else | |
230 | { | |
231 | fRawOCDBPath->SetEnabled(kFALSE); | |
232 | fHistogramButton->SetEnabled(kTRUE); | |
233 | } | |
234 | } | |
235 | ||
0145e89a | 236 | //_____________________________________________________________________________ |
237 | void | |
238 | AliMUONPainterDataSourceFrame::CreateOCDBDataSource() | |
239 | { | |
240 | /// Create an OCDB data source (using information from the widgets) | |
241 | ||
242 | TString cdbPath = fOCDBPath->GetText(); | |
243 | Int_t runNumber = fRunSelector->GetIntNumber(); | |
244 | TGTextLBEntry* t = static_cast<TGTextLBEntry*>(fOCDBTypes->GetSelectedEntry()); | |
245 | TString type = t->GetText()->GetString(); | |
246 | ||
247 | CreateOCDBDataSource(cdbPath,runNumber,type); | |
248 | ||
249 | fOCDBPath->SetText(""); | |
250 | fRunSelector->SetNumber(0); | |
251 | } | |
252 | ||
253 | //_____________________________________________________________________________ | |
254 | void | |
255 | AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& uri) | |
256 | { | |
257 | /// Create an OCDB data source, given it's URI | |
258 | ||
259 | TObjArray* a = uri.Tokenize(";"); | |
260 | TString cdbPath = static_cast<TObjString*>(a->At(1))->String(); | |
261 | TString srun = static_cast<TObjString*>(a->At(2))->String(); | |
262 | TString type = static_cast<TObjString*>(a->At(3))->String(); | |
263 | ||
264 | CreateOCDBDataSource(cdbPath,atoi(srun.Data()),type); | |
265 | ||
266 | delete a; | |
267 | } | |
268 | ||
269 | //_____________________________________________________________________________ | |
270 | void | |
271 | AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& cdbPath, | |
272 | Int_t runNumber, | |
273 | const TString& type) | |
274 | { | |
275 | /// Create an OCDB data source for a given (path,runnumber,type) triplet | |
276 | ||
277 | AliMUONVTrackerDataMaker* reader = new AliMUONTrackerOCDBDataMaker(cdbPath.Data(), | |
278 | runNumber, | |
279 | type.Data()); | |
280 | ||
281 | if ( reader->IsValid() ) | |
282 | { | |
283 | AliMUONPainterRegistry::Instance()->Register(reader); | |
284 | ||
285 | AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env(); | |
286 | ||
287 | Int_t n = env->Integer(fgkNumberOfDataSourcesKey); | |
288 | ||
289 | env->Set(fgkNumberOfDataSourcesKey,n+1); | |
290 | ||
291 | TString ds(Form("OCDB;%s;%d;%s",cdbPath.Data(),runNumber,type.Data())); | |
292 | ||
293 | env->Set(Form(fgkDataSourceURIKey,n),ds.Data()); | |
294 | ||
295 | env->Save(); | |
296 | ||
297 | AddRecentSource(ds.Data()); | |
298 | } | |
299 | } | |
300 | ||
301 | //_____________________________________________________________________________ | |
302 | void | |
303 | AliMUONPainterDataSourceFrame::CreateRawDataSource() | |
304 | { | |
305 | /// Create a new raw data source (using info from the widgets) | |
306 | ||
307 | TString uri(gSystem->ExpandPathName(fFilePath->GetText())); | |
308 | ||
309 | if ( gSystem->AccessPathName(uri.Data()) ) | |
310 | { | |
311 | AliError(Form("File %s does not exist",uri.Data())); | |
312 | fFilePath->SetText(""); | |
313 | return; | |
314 | } | |
315 | ||
8741815f | 316 | uri = Form("%sRAW;%s;%s",( fHistogramButton->IsOn() ? "H":""),uri.Data(),fRawOCDBPath->GetText()); |
0145e89a | 317 | |
318 | if ( CreateRawDataSource(uri) ) | |
319 | { | |
320 | fFilePath->SetText(""); | |
321 | fRawOCDBPath->SetText(""); | |
322 | } | |
323 | } | |
324 | ||
325 | //_____________________________________________________________________________ | |
326 | Bool_t | |
327 | AliMUONPainterDataSourceFrame::CreateRawDataSource(const TString& uri) | |
328 | { | |
329 | /// Create a new raw data source, given its URI | |
330 | ||
331 | TString filename; | |
332 | TString ocdbPath; | |
333 | ||
334 | TObjArray* a = uri.Tokenize(";"); | |
335 | ||
336 | filename = static_cast<TObjString*>(a->At(1))->String(); | |
337 | ||
338 | if ( a->GetLast() > 1 ) | |
339 | { | |
340 | ocdbPath = static_cast<TObjString*>(a->At(2))->String(); | |
341 | } | |
342 | ||
343 | AliRawReader* rawReader = 0x0; | |
344 | ||
345 | if ( filename.Contains(TRegexp(".root$")) ) | |
346 | { | |
347 | AliDebug(1,"Using RawReaderRoot"); | |
348 | if ( filename.Contains(TRegexp("^alien")) ) | |
349 | { | |
350 | // insure we've initialized the grid... | |
351 | if (!gGrid) | |
352 | { | |
353 | TGrid::Connect("alien://"); | |
354 | } | |
355 | } | |
356 | ||
357 | rawReader = new AliRawReaderRoot(filename.Data()); | |
358 | } | |
035e7b9f | 359 | else if ( uri.Contains(TRegexp(".raw")) ) |
0145e89a | 360 | { |
361 | AliDebug(1,"Using RawReaderDate"); | |
362 | rawReader = new AliRawReaderDate(filename.Data()); | |
363 | } | |
364 | else | |
365 | { | |
366 | AliError(Form("Don't know how to open that file : %s\nURI=%s",filename.Data(),uri.Data())); | |
367 | return kFALSE; | |
368 | } | |
369 | ||
8741815f | 370 | AliMUONVTrackerDataMaker* reader(0x0); |
371 | Bool_t histogram(kFALSE); | |
372 | ||
373 | if ( ocdbPath.Length() > 0 ) | |
374 | { | |
375 | reader = new AliMUONTrackerCalibratedDataMaker(rawReader,ocdbPath.Data()); | |
376 | } | |
377 | else | |
378 | { | |
379 | if ( uri.Contains(TRegexp("^H")) ) histogram = kTRUE; | |
380 | reader = new AliMUONTrackerRawDataMaker(rawReader,histogram); | |
381 | } | |
0145e89a | 382 | |
383 | reader->SetSource(filename.Data()); | |
384 | ||
385 | AliMUONPainterRegistry::Instance()->Register(reader); | |
386 | ||
387 | AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env(); | |
388 | ||
389 | Int_t n = env->Integer(fgkNumberOfDataSourcesKey); | |
390 | ||
391 | env->Set(fgkNumberOfDataSourcesKey,n+1); | |
392 | ||
8741815f | 393 | TString ds(Form("%sRAW;%s;%s",(histogram ? "H":""),filename.Data(),ocdbPath.Data())); |
0145e89a | 394 | |
395 | env->Set(Form(fgkDataSourceURIKey,n),ds.Data()); | |
396 | ||
397 | AddRecentSource(ds.Data()); | |
398 | ||
399 | env->Save(); | |
400 | ||
401 | return kTRUE; | |
402 | } | |
403 | ||
404 | //_____________________________________________________________________________ | |
405 | void | |
406 | AliMUONPainterDataSourceFrame::DataReaderWasRegistered(AliMUONVTrackerDataMaker* reader) | |
407 | { | |
408 | /// Update ourselves as a new data reader was created | |
409 | ||
0145e89a | 410 | AliMUONPainterDataSourceItem* item = new AliMUONPainterDataSourceItem(fDataReaders,100,20,reader); |
411 | ||
412 | fDataReaders->AddFrame(item); | |
413 | ||
414 | fItems->Add(item); | |
415 | ||
416 | fDataReaders->MapSubwindows(); | |
417 | fDataReaders->Resize(); | |
418 | } | |
419 | ||
420 | //_____________________________________________________________________________ | |
421 | void | |
422 | AliMUONPainterDataSourceFrame::DataReaderWasUnregistered(AliMUONVTrackerDataMaker* reader) | |
423 | { | |
424 | /// Update ourselves as a new data reader was deleted | |
425 | ||
8741815f | 426 | // AliInfo(Form("%s",reader->GetName())); |
0145e89a | 427 | |
428 | } | |
429 | ||
430 | //_____________________________________________________________________________ | |
431 | void | |
432 | AliMUONPainterDataSourceFrame::OpenFileDialog() | |
433 | { | |
434 | /// Open a file dialog to select a file to be read | |
435 | ||
436 | TGFileInfo fileInfo; | |
437 | ||
438 | new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(), | |
439 | kFDOpen,&fileInfo); | |
440 | ||
441 | ||
442 | fFilePath->SetText(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename))); | |
443 | } | |
444 | ||
445 | ||
446 | //_____________________________________________________________________________ | |
447 | void | |
448 | AliMUONPainterDataSourceFrame::OpenRecentSource() | |
449 | { | |
450 | /// Open one source from the recently used ones | |
451 | ||
452 | TGTextLBEntry* t = (TGTextLBEntry*)fRecentSources->GetSelectedEntry(); | |
453 | ||
454 | TString uri(t->GetText()->GetString()); | |
455 | ||
8741815f | 456 | if ( uri.Contains(TRegexp("^RAW")) || uri.Contains(TRegexp("^HRAW")) ) |
0145e89a | 457 | { |
458 | CreateRawDataSource(uri); | |
459 | } | |
460 | else if ( uri.Contains(TRegexp("^OCDB")) ) | |
461 | { | |
462 | CreateOCDBDataSource(uri); | |
463 | } | |
464 | ||
465 | fRecentSources->Select(-1); | |
466 | } | |
467 |