Adding a tool to mchview to compare alignments (Philippe P. ; Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterDataSourceFrame.cxx
CommitLineData
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
b09247a2 18#include <cstdlib>
0145e89a 19#include "AliMUONPainterDataSourceFrame.h"
20
8741815f 21#include "AliLog.h"
9f4473f2 22#include "AliCDBEntry.h"
23#include "AliCDBManager.h"
fcabdc0c 24#include "AliMUONChamberPainter.h"
25#include "AliMUONMchViewApplication.h"
26#include "AliMUONPainterDataRegistry.h"
0145e89a 27#include "AliMUONPainterDataSourceItem.h"
28#include "AliMUONPainterEnv.h"
29#include "AliMUONPainterHelper.h"
fcabdc0c 30#include "AliMUONPainterMatrix.h"
31#include "AliMUONPainterRegistry.h"
a0dc65b4 32#include "AliMUONRecoParam.h"
ca913045 33#include "AliMUONTrackerConditionDataMaker.h"
b6f591ae 34#include "AliMUONTrackerDataMaker.h"
0b376ef1 35#include "AliRawReader.h"
fcabdc0c 36#include <TCanvas.h>
0145e89a 37#include <TGButton.h>
38#include <TGComboBox.h>
39#include <TGFileDialog.h>
40#include <TGNumberEntry.h>
41#include <TGTextEntry.h>
42#include <TGrid.h>
43#include <TObjArray.h>
44#include <TObjString.h>
fcabdc0c 45#include <TMath.h>
0145e89a 46#include <TRegexp.h>
47#include <TString.h>
48#include <TSystem.h>
49
50///\class AliMUONPainterDataSourceFrame
51///
52/// A complete frame to select and display various data sources to
53/// be displayed : either raw data or OCDB data.
54/// Later on we might add digits and clusters for instance.
55///
56///\author Laurent Aphecetche, Subatech
57
58const char* AliMUONPainterDataSourceFrame::fgkNumberOfDataSourcesKey = "NumberOfDataSources";
59const char* AliMUONPainterDataSourceFrame::fgkDataSourceURIKey = "DataSourceURI.%d";
60
61///\cond CLASSIMP
62ClassImp(AliMUONPainterDataSourceFrame)
63///\endcond
64
65//_____________________________________________________________________________
66AliMUONPainterDataSourceFrame::AliMUONPainterDataSourceFrame(const TGWindow* p, UInt_t w, UInt_t h)
67: TGCompositeFrame(p,w,h,kVerticalFrame),
10eb3d17 68 fRecentSourceSelector(new TGGroupFrame(this,"Recent sources",kHorizontalFrame)),
69 fRawSelector(new TGGroupFrame(this,"Raw file URI",kHorizontalFrame)),
8741815f 70 fRawSelector2(new TGCompositeFrame(fRawSelector,w,h,kVerticalFrame)),
71 fRawSelector21(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
72 fRawSelector22(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
9f4473f2 73 fRawSelector24(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
8741815f 74 fRawSelector23(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
66cdf5b3 75 fCalibrateNoGain(new TGCheckButton(fRawSelector22,"Ped sub")),
76 fCalibrateGainConstantCapa(new TGCheckButton(fRawSelector22,"Ped sub+gain (capa cste)")),
77 fCalibrateGain(new TGCheckButton(fRawSelector22,"Full calib (Ped sub+gain w/ capa)")),
78 fCalibrateEmelecGain(new TGCheckButton(fRawSelector22,"Full calib (Ped sub+inj gain w/ capa)")),
8741815f 79 fHistogramButton(new TGCheckButton(fRawSelector23,"Histogram")),
10eb3d17 80 fHistoMin(new TGNumberEntry(fRawSelector23,0)),
81 fHistoMax(new TGNumberEntry(fRawSelector23,4096)),
a679753e 82 fEventRangeButton(new TGCheckButton(fRawSelector23,"Event range")),
83 fEventMin(new TGNumberEntry(fRawSelector23,-1,10)),
84 fEventMax(new TGNumberEntry(fRawSelector23,-1,10)),
301ca128 85 fRawOCDBPath(new TGTextEntry(fRawSelector24,"alien://folder=/alice/data/2012/OCDB")),
10eb3d17 86 fOCDBSelector(new TGGroupFrame(this,"OCDB Path",kHorizontalFrame)),
87 fDataReaders(new TGGroupFrame(this,"Data sources")),
8741815f 88 fFilePath(new TGTextEntry(fRawSelector21,"")),
301ca128 89 fOCDBPath(new TGTextEntry(fOCDBSelector,"alien://folder=/alice/data/2012/OCDB")),
a679753e 90 fRunSelector(new TGNumberEntry(fOCDBSelector,0,10)),
0145e89a 91 fOCDBTypes(new TGComboBox(fOCDBSelector)),
92 fRecentSources(new TGComboBox(fRecentSourceSelector)),
1286237e 93 fItems(new TObjArray),
94 fACFSelector(new TGGroupFrame(this,"ASCII Calib File",kHorizontalFrame)),
95 fACFPath(new TGTextEntry(fACFSelector,"")),
96 fACFTypes(new TGComboBox(fACFSelector))
0145e89a 97{
98 /// Ctor
99
8f0acce4 100 AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
0145e89a 101
49419555 102 reg->Connect("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",
0145e89a 103 "AliMUONPainterDataSourceFrame",
104 this,
49419555 105 "DataMakerWasRegistered(AliMUONVTrackerDataMaker*)");
0145e89a 106
49419555 107 reg->Connect("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",
0145e89a 108 "AliMUONPainterDataSourceFrame",
109 this,
49419555 110 "DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)");
0145e89a 111
112 fItems->SetOwner(kFALSE);
113
114 /// Recent source selection
115
116 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
117
118 Int_t nsources = env->Integer(fgkNumberOfDataSourcesKey);
119
120 for ( Int_t i = 0; i < nsources; ++i )
121 {
122 AddRecentSource(env->String(Form(fgkDataSourceURIKey,i)));
123 }
124
125 fRecentSources->Resize(100,20);
126
127 TGButton* createRecentButton = new TGTextButton(fRecentSourceSelector,"Create data source");
128 createRecentButton->Connect("Clicked()",
129 "AliMUONPainterDataSourceFrame",
130 this,
131 "OpenRecentSource()");
132
133 fRecentSourceSelector->AddFrame(fRecentSources,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
134 fRecentSourceSelector->AddFrame(createRecentButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
1286237e 135
0145e89a 136 /// Raw file selection
137
8741815f 138 TGButton* openButton = new TGPictureButton(fRawSelector21,
0145e89a 139 gClient->GetPicture("fileopen.xpm"));
140 openButton->SetToolTipText("Click to open file dialog");
141
8741815f 142 fRawSelector2->AddFrame(fRawSelector21, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
143 fRawSelector2->AddFrame(fRawSelector22, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
9f4473f2 144 fRawSelector2->AddFrame(fRawSelector24, new TGLayoutHints(kLHintsTop,5,5,5,5));
8741815f 145 fRawSelector2->AddFrame(fRawSelector23, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
146
147 fRawSelector21->AddFrame(openButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
148 fRawSelector21->AddFrame(fFilePath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
149
10eb3d17 150 fRawSelector22->AddFrame(fCalibrateNoGain, new TGLayoutHints(kLHintsTop,5,5,5,5));
151 fRawSelector22->AddFrame(fCalibrateGainConstantCapa, new TGLayoutHints(kLHintsTop,5,5,5,5));
152 fRawSelector22->AddFrame(fCalibrateGain, new TGLayoutHints(kLHintsTop,5,5,5,5));
66cdf5b3 153 fRawSelector22->AddFrame(fCalibrateEmelecGain, new TGLayoutHints(kLHintsTop,5,5,5,5));
9f4473f2 154
155 fRawSelector24->AddFrame(fRawOCDBPath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
8741815f 156 fRawOCDBPath->SetEnabled(kFALSE);
0145e89a 157
a679753e 158 fRawSelector23->AddFrame(fHistogramButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
10eb3d17 159 fHistogramButton->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"HistogramButtonClicked()");
10eb3d17 160 fHistoMin->SetState(kFALSE);
a679753e 161 fHistoMax->SetState(kFALSE);
10eb3d17 162 fRawSelector23->AddFrame(fHistoMin,new TGLayoutHints(kLHintsTop,5,5,5,5));
163 fRawSelector23->AddFrame(fHistoMax,new TGLayoutHints(kLHintsTop,5,5,5,5));
164
a679753e 165
166 fRawSelector23->AddFrame(fEventRangeButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
167 fEventRangeButton->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"EventRangeButtonClicked()");
168 fEventMin->SetState(kFALSE);
169 fEventMax->SetState(kFALSE);
170
171 fEventMin->SetFormat(TGNumberFormat::kNESInteger);
172 fEventMax->SetFormat(TGNumberFormat::kNESInteger);
173
174 fRawSelector23->AddFrame(fEventMin,new TGLayoutHints(kLHintsTop,5,5,5,5));
175 fRawSelector23->AddFrame(fEventMax,new TGLayoutHints(kLHintsTop,5,5,5,5));
176
8741815f 177 TGButton* createRawButton = new TGTextButton(fRawSelector,"Create data source");
0145e89a 178
8741815f 179 fRawSelector->AddFrame(fRawSelector2, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
180 fRawSelector->AddFrame(createRawButton, new TGLayoutHints(kLHintsCenterY,5,5,5,5));
181
10eb3d17 182 fCalibrateNoGain->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"CalibrateButtonClicked()");
183 fCalibrateGainConstantCapa->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"CalibrateButtonClicked()");
184 fCalibrateGain->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"CalibrateButtonClicked()");
66cdf5b3 185 fCalibrateEmelecGain->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"CalibrateButtonClicked()");
8741815f 186
0145e89a 187 openButton->Connect("Clicked()",
188 "AliMUONPainterDataSourceFrame",
189 this,
190 "OpenFileDialog()");
191
192 createRawButton->Connect("Clicked()",
193 "AliMUONPainterDataSourceFrame",
194 this,
195 "CreateRawDataSource()");
196
197 /// OCDB selection
198
ca913045 199 fOCDBTypes->AddEntry("Config",7);
200 fOCDBTypes->AddEntry("Occupancy",4);
201 fOCDBTypes->AddEntry("HV",3);
7eafe398 202 fOCDBTypes->AddEntry("Pedestals",0);
203 fOCDBTypes->AddEntry("Gains",1);
fef32488 204 fOCDBTypes->AddEntry("StatusMap",5);
205 fOCDBTypes->AddEntry("Status",6);
ca913045 206 fOCDBTypes->AddEntry("Capacitances",2);
6ebcde15 207 fOCDBTypes->AddEntry("RejectList",8);
7eafe398 208 fOCDBTypes->Select(0);
a679753e 209 fOCDBTypes->Resize(80,20);
0145e89a 210
211 TGButton* createOCDBButton = new TGTextButton(fOCDBSelector,"Create data source");
212 createOCDBButton->Connect("Clicked()",
213 "AliMUONPainterDataSourceFrame",
214 this,
215 "CreateOCDBDataSource()");
949b9833 216
217 const char* ocdbToolTip = "Use URL style for either alien or local OCDB (foo://bar). For example :\n"
218 "alien://folder=/alice/data.../OCDB\n"
219 "or\nlocal:///home/user/aliroot (mind the 3 slashes there !)";
220
221 fRawOCDBPath->SetToolTipText(ocdbToolTip);
222 fOCDBPath->SetToolTipText(ocdbToolTip);
223
0145e89a 224 fOCDBSelector->AddFrame(fOCDBPath,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
225 fOCDBSelector->AddFrame(fRunSelector,new TGLayoutHints(kLHintsTop,5,5,5,5));
226 fOCDBSelector->AddFrame(fOCDBTypes,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
227 fOCDBSelector->AddFrame(createOCDBButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
1286237e 228
229
230 /// ASCII calibration file selection
231
232 TGButton* openButtonACF = new TGPictureButton(fACFSelector,
233 gClient->GetPicture("fileopen.xpm"));
234 openButtonACF->SetToolTipText("Click to open file dialog");
ca913045 235
236 fACFTypes->AddEntry("Config",7);
7eafe398 237 fACFTypes->AddEntry("Occupancy",4);
ca913045 238 fACFTypes->AddEntry("Pedestals",0);
239 fACFTypes->AddEntry("Gains",1);
240 fACFTypes->AddEntry("Capacitances",2);
241 fACFTypes->Select(0);
242 fACFTypes->Resize(100,20);
1286237e 243
244 fACFSelector->AddFrame(openButtonACF,new TGLayoutHints(kLHintsTop,5,5,5,5));
245 fACFSelector->AddFrame(fACFPath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
246 fACFSelector->AddFrame(fACFTypes,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
247
248 TGButton* createACFButton = new TGTextButton(fACFSelector,"Create data source");
249 createACFButton->Connect("Clicked()",
250 "AliMUONPainterDataSourceFrame",
251 this,
252 "CreateACFDataSource()");
253
254 openButtonACF->Connect("Clicked()",
255 "AliMUONPainterDataSourceFrame",
256 this,
257 "OpenFileDialogACF()");
258
259 fACFSelector->AddFrame(createACFButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
0145e89a 260
261 AddFrame(fRecentSourceSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
262
263 AddFrame(fRawSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
264
265 AddFrame(fOCDBSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
266
1286237e 267 AddFrame(fACFSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
268
0145e89a 269 AddFrame(fDataReaders, new TGLayoutHints(kLHintsExpandX,10,10,10,10));
270
271}
272
273//_____________________________________________________________________________
274AliMUONPainterDataSourceFrame::~AliMUONPainterDataSourceFrame()
275{
276 /// dtor
277
278 delete fItems;
279}
280
281//_____________________________________________________________________________
282void
283AliMUONPainterDataSourceFrame::AddRecentSource(const char* name)
284{
285 /// Add a source to the list of recently used sources
286
287 TGListBox* lb = fRecentSources->GetListBox();
288
289 for ( Int_t i = 0; i < lb->GetNumberOfEntries(); ++i )
290 {
291 TGTextLBEntry* t = (TGTextLBEntry*)lb->GetEntry(i);
292 TString s(t->GetText()->GetString());
293 if ( s == name )
294 {
295 return;
296 }
297 }
298
299 fRecentSources->AddEntry(name,lb->GetNumberOfEntries());
300 fRecentSources->MapSubwindows();
301 fRecentSources->Layout();
302}
303
304//_____________________________________________________________________________
305void
8741815f 306AliMUONPainterDataSourceFrame::CalibrateButtonClicked()
307{
308 /// Calibrate button was clicked.
309
10eb3d17 310 if ( fCalibrateNoGain->IsOn() ||
311 fCalibrateGainConstantCapa->IsOn() ||
66cdf5b3 312 fCalibrateGain->IsOn() ||
313 fCalibrateEmelecGain->IsOn() )
8741815f 314 {
315 fRawOCDBPath->SetEnabled(kTRUE);
316 fRawOCDBPath->SetFocus();
8741815f 317 }
318 else
319 {
320 fRawOCDBPath->SetEnabled(kFALSE);
10eb3d17 321 }
322}
323
324//_____________________________________________________________________________
325void
326AliMUONPainterDataSourceFrame::HistogramButtonClicked()
327{
328 /// Histogram button was clicked.
329
330 if ( fHistogramButton->IsOn() )
331 {
332 fHistoMin->SetState(kTRUE);
333 fHistoMax->SetState(kTRUE);
334 }
335 else
336 {
337 fHistoMin->SetState(kFALSE);
338 fHistoMax->SetState(kFALSE);
8741815f 339 }
340}
341
342//_____________________________________________________________________________
343void
a679753e 344AliMUONPainterDataSourceFrame::EventRangeButtonClicked()
345{
346 /// EventRange button was clicked.
347
348 if ( fEventRangeButton->IsOn() )
349 {
350 fEventMin->SetState(kTRUE);
351 fEventMax->SetState(kTRUE);
352 }
353 else
354 {
355 fEventMin->SetIntNumber(-1);
356 fEventMax->SetIntNumber(-1);
357 fEventMin->SetState(kFALSE);
358 fEventMax->SetState(kFALSE);
359 }
360}
361
362//_____________________________________________________________________________
363void
1286237e 364AliMUONPainterDataSourceFrame::CreateACFDataSource()
365{
366 /// Create an ACF data source (using information from the widgets)
367
368 TString acfPath = fACFPath->GetText();
369 TGTextLBEntry* t = static_cast<TGTextLBEntry*>(fACFTypes->GetSelectedEntry());
370 TString type = t->GetText()->GetString();
371
372 CreateACFDataSource(acfPath,type);
373
374 fACFPath->SetText("");
375}
376
377
378//_____________________________________________________________________________
379void
0145e89a 380AliMUONPainterDataSourceFrame::CreateOCDBDataSource()
381{
382 /// Create an OCDB data source (using information from the widgets)
383
384 TString cdbPath = fOCDBPath->GetText();
385 Int_t runNumber = fRunSelector->GetIntNumber();
386 TGTextLBEntry* t = static_cast<TGTextLBEntry*>(fOCDBTypes->GetSelectedEntry());
387 TString type = t->GetText()->GetString();
388
bd9314b2 389 CreateOCDBDataSource(cdbPath,runNumber,type);
0145e89a 390}
391
392//_____________________________________________________________________________
393void
1286237e 394AliMUONPainterDataSourceFrame::CreateACFDataSource(const TString& uri)
395{
396 /// Create an ACF data source, given it's URI
397
398 TObjArray* a = uri.Tokenize(";");
399 TString acfPath = static_cast<TObjString*>(a->At(1))->String();
400 TString type = static_cast<TObjString*>(a->At(2))->String();
401
402 CreateACFDataSource(acfPath,type);
403
404 delete a;
405}
406
407
408//_____________________________________________________________________________
409void
0145e89a 410AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& uri)
411{
412 /// Create an OCDB data source, given it's URI
413
414 TObjArray* a = uri.Tokenize(";");
415 TString cdbPath = static_cast<TObjString*>(a->At(1))->String();
416 TString srun = static_cast<TObjString*>(a->At(2))->String();
417 TString type = static_cast<TObjString*>(a->At(3))->String();
418
419 CreateOCDBDataSource(cdbPath,atoi(srun.Data()),type);
420
421 delete a;
422}
423
424//_____________________________________________________________________________
425void
fcabdc0c 426AliMUONPainterDataSourceFrame::RegisterDataSource(AliMUONVTrackerDataMaker* reader,
427 const char* dsName)
1286237e 428{
fcabdc0c 429 /// Register a new data source
430
431 if ( reader && reader->IsValid() )
1286237e 432 {
fcabdc0c 433 AliMUONMchViewApplication* app = dynamic_cast<AliMUONMchViewApplication*>(gApplication);
434 if (!app)
435 {
436 AliError("Could not cast application to the expected type ! CHECK THAT !");
437 }
438
8f0acce4 439 AliMUONPainterDataRegistry::Instance()->Register(reader);
1286237e 440
441 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
442
443 Int_t n = env->Integer(fgkNumberOfDataSourcesKey);
444
445 env->Set(fgkNumberOfDataSourcesKey,n+1);
446
fcabdc0c 447 env->Set(Form(fgkDataSourceURIKey,n),dsName);
1286237e 448
449 env->Save();
450
fcabdc0c 451 AddRecentSource(dsName);
452
453 if ( app )
454 {
455
456 TString name(dsName);
457 name.ToUpper();
458
459 if ( name.Contains("PED") )
460 {
461 CreatePedestalCanvases(reader->Data());
462 }
463 }
464 }
465}
466
467//_____________________________________________________________________________
468void
469AliMUONPainterDataSourceFrame::CreatePedestalCanvases(AliMUONVTrackerData* data,
470 Double_t pedMin, Double_t pedMax,
471 Double_t sigmaMin, Double_t sigmaMax)
472{
473 /// Create 4 canvases with the pedestals contained in data
474 /// to show mean and sigma, for bending and non bending, with given limits
475
476 TList matrices;
477
478 AliMUONAttPainter att[2];
479
480 att[0].SetViewPoint(kTRUE,kFALSE);
481 att[0].SetCathode(kFALSE,kFALSE);
482 att[0].SetPlane(kTRUE,kFALSE);
483
484 att[1].SetViewPoint(kTRUE,kFALSE);
485 att[1].SetCathode(kFALSE,kFALSE);
486 att[1].SetPlane(kFALSE,kTRUE);
487
488 for ( Int_t iatt = 0; iatt < 2; ++iatt )
489 {
490 matrices.Add(CreateFullTracker(data,0,pedMin,pedMax,att[iatt]));
491 matrices.Add(CreateFullTracker(data,1,sigmaMin,sigmaMax,att[iatt]));
492 }
493
494 TIter next(&matrices);
495 AliMUONPainterMatrix* matrix;
496
497 Int_t w = TMath::Nint(gClient->GetDisplayWidth()*0.9);
498 Int_t h = TMath::Nint(gClient->GetDisplayHeight()*0.9);
499
500 Int_t x[] = { 0, 0, 20 + w/2, 20 + w/2 };
501 Int_t y[] = { 0, h/2+30, 0, h/2+30 };
502
503 Int_t i(0);
504
505 while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next())) )
506 {
507 TCanvas* c = matrix->CreateCanvas(x[i],y[i],w/2,h/2);
508 c->Draw();
509 c->SaveAs(Form("%s.png",c->GetName()));
510 ++i;
511 }
512}
513
514//_____________________________________________________________________________
515AliMUONPainterMatrix*
516AliMUONPainterDataSourceFrame::CreateFullTracker(AliMUONVTrackerData* data,
517 Int_t dim,
518 Double_t xmin, Double_t xmax,
519 const AliMUONAttPainter& att)
520{
521 /// Generate, draw and register a matrix of 10 painters to show all the tracker
522 /// chambers
523
524 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
525
526 for ( Int_t ichamber = 0; ichamber < 10; ++ichamber )
527 {
528 AliMUONVPainter* painter = new AliMUONChamberPainter(att,ichamber);
529
530 painter->SetResponder("BUSPATCH");
531
532 painter->SetOutlined("*",kFALSE);
533
534 matrix->Adopt(painter);
1286237e 535 }
536
fcabdc0c 537 matrix->SetData("MANU",data,dim);
538 matrix->SetDataRange(xmin,xmax);
539
540 AliMUONPainterRegistry::Instance()->Register(matrix);
541
542 return matrix;
543}
544
545
546//_____________________________________________________________________________
547void
548AliMUONPainterDataSourceFrame::CreateACFDataSource(const TString& acfPath, const TString& type)
549{
550 /// Create an ACF data source for a given (path,type)
551
552 AliMUONVTrackerDataMaker* reader = new AliMUONTrackerConditionDataMaker(acfPath.Data(),
553 type.Data());
554
555 RegisterDataSource(reader,Form("ACF;%s;%s",acfPath.Data(),type.Data()));
1286237e 556}
557
558//_____________________________________________________________________________
559void
0145e89a 560AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& cdbPath,
561 Int_t runNumber,
562 const TString& type)
563{
564 /// Create an OCDB data source for a given (path,runnumber,type) triplet
565
ca913045 566 AliMUONVTrackerDataMaker* reader = new AliMUONTrackerConditionDataMaker(runNumber,
567 cdbPath.Data(),
568 type.Data());
0145e89a 569
fcabdc0c 570 RegisterDataSource(reader,Form("OCDB;%s;%d;%s",cdbPath.Data(),runNumber,type.Data()));
0145e89a 571}
572
573//_____________________________________________________________________________
574void
575AliMUONPainterDataSourceFrame::CreateRawDataSource()
576{
577 /// Create a new raw data source (using info from the widgets)
578
579 TString uri(gSystem->ExpandPathName(fFilePath->GetText()));
b6f591ae 580
581 TString name("RAW");
582 Bool_t fromMemory(kFALSE);
0145e89a 583
b6f591ae 584 if ( uri.Contains(TRegexp("^mem")) )
0145e89a 585 {
b6f591ae 586 fromMemory = kTRUE;
587 }
588 else
589 {
590 if ( gSystem->AccessPathName(uri.Data()) )
591 {
592 AliError(Form("File %s does not exist",uri.Data()));
593 fFilePath->SetText("");
594 return;
595 }
0145e89a 596 }
597
10eb3d17 598 TString calibMode("");
10eb3d17 599
600 if ( fCalibrateGain->IsOn() )
601 {
602 calibMode = "GAIN";
603 name = "CALC";
604 }
605
606 if ( fCalibrateGainConstantCapa->IsOn() )
607 {
608 calibMode = "GAINCONSTANTCAPA";
609 name = "CALG";
610 }
66cdf5b3 611
612 if ( fCalibrateEmelecGain->IsOn() )
613 {
614 calibMode = "INJECTIONGAIN";
615 name = "CALE";
616 }
10eb3d17 617
618 if ( fCalibrateNoGain->IsOn() )
619 {
620 calibMode = "NOGAIN";
621 name = "CALZ";
622 }
623
a679753e 624 uri = Form("%s%s%s;%s;%s;%s;%s;%s;%s;%s",
10eb3d17 625 ( fHistogramButton->IsOn() ? "H":""),
b6f591ae 626 ( fromMemory ? "M" : ""),
10eb3d17 627 name.Data(),uri.Data(),
628 ( strlen(fRawOCDBPath->GetText()) > 0 ? fRawOCDBPath->GetText() : " "),
629 ( calibMode.Length() > 0 ? calibMode.Data() : " "),
630 Form("%e",fHistoMin->GetNumber()),
a679753e 631 Form("%e",fHistoMax->GetNumber()),
632 Form("%d",(Int_t)(fEventMin->GetIntNumber())),
633 Form("%d",(Int_t)(fEventMax->GetIntNumber())));
0145e89a 634
635 if ( CreateRawDataSource(uri) )
636 {
637 fFilePath->SetText("");
638 fRawOCDBPath->SetText("");
639 }
640}
641
642//_____________________________________________________________________________
643Bool_t
644AliMUONPainterDataSourceFrame::CreateRawDataSource(const TString& uri)
645{
646 /// Create a new raw data source, given its URI
647
648 TString filename;
649 TString ocdbPath;
10eb3d17 650 TString calibMode;
651 TString sxmin("0.0");
652 TString sxmax("4096.0");
a679753e 653 TString emin("-1");
654 TString emax("-1");
0145e89a 655
656 TObjArray* a = uri.Tokenize(";");
657
658 filename = static_cast<TObjString*>(a->At(1))->String();
659
660 if ( a->GetLast() > 1 )
661 {
662 ocdbPath = static_cast<TObjString*>(a->At(2))->String();
10eb3d17 663 if ( ocdbPath == " " ) ocdbPath = "";
664 }
665
666 if ( a->GetLast() > 2 )
667 {
668 calibMode = static_cast<TObjString*>(a->At(3))->String();
669 if ( calibMode == " " ) calibMode = "";
670 }
671
672 if ( a->GetLast() > 3 )
673 {
674 sxmin = static_cast<TObjString*>(a->At(4))->String();
675 }
676
677 if ( a->GetLast() > 4 )
678 {
679 sxmax = static_cast<TObjString*>(a->At(5))->String();
0145e89a 680 }
681
a679753e 682 if ( a->GetLast() > 5 )
683 {
684 emin = static_cast<TObjString*>(a->At(6))->String();
685 }
686
687 if ( a->GetLast() > 6 )
688 {
689 emax = static_cast<TObjString*>(a->At(7))->String();
690 }
691
0145e89a 692 AliRawReader* rawReader = 0x0;
693
0b376ef1 694 if ( filename.Contains(TRegexp("^alien")) )
0145e89a 695 {
0b376ef1 696 // insure we've initialized the grid...
697 if (!gGrid)
0145e89a 698 {
0b376ef1 699 TGrid::Connect("alien://");
0145e89a 700 }
0145e89a 701 }
0b376ef1 702
703 rawReader = AliRawReader::Create(filename.Data());
704
705 if (!rawReader)
0145e89a 706 {
0b376ef1 707 AliError(Form("Could not open file %s",filename.Data()));
708 fFilePath->SetText("");
709 return kFALSE;
0145e89a 710 }
0b376ef1 711
10eb3d17 712 /// Basic test to see if the file is correct
9f4473f2 713 /// and to get run numbre
714 Int_t runNumber(-1);
10eb3d17 715 Bool_t ok = rawReader->NextEvent();
716 if (!ok)
0145e89a 717 {
9f4473f2 718 AliError(Form("File %s does not seem to be a raw data file",filename.Data()));
10eb3d17 719 fFilePath->SetText("");
0145e89a 720 return kFALSE;
721 }
9f4473f2 722 else
723 {
724 runNumber = rawReader->GetRunNumber();
725 }
726
10eb3d17 727 rawReader->RewindEvents();
728
8741815f 729 AliMUONVTrackerDataMaker* reader(0x0);
730 Bool_t histogram(kFALSE);
731
10eb3d17 732 if ( uri.Contains(TRegexp("^H")) ) histogram = kTRUE;
733
8741815f 734 if ( ocdbPath.Length() > 0 )
735 {
9f4473f2 736
737 AliMUONRecoParam* recoParam(0x0);
a0dc65b4 738
9f4473f2 739 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam",runNumber);
740 if (e)
741 {
742 TObject* o = e->GetObject();
743 if ( o->IsA() == TObjArray::Class() )
744 {
5ebd79a8 745 TIter next(static_cast<TObjArray*>(o));
9f4473f2 746 AliMUONRecoParam* p;
747 while ( ( p = static_cast<AliMUONRecoParam*>(next()) ))
748 {
749 if ( p->IsDefault()) recoParam = p;
750 }
751 }
752 else
753 {
754 recoParam = static_cast<AliMUONRecoParam*>(o);
755 }
756 }
a0dc65b4 757
b6f591ae 758 reader = new AliMUONTrackerDataMaker(recoParam,
759 rawReader,
760 ocdbPath.Data(),
761 calibMode.Data(),
762 histogram,
763 sxmin.Atof(),
764 sxmax.Atof());
8741815f 765 }
766 else
767 {
b6f591ae 768 reader = new AliMUONTrackerDataMaker(rawReader,histogram);
8741815f 769 }
fcabdc0c 770
a679753e 771 reader->SetEventRange(emin.Atoi(),emax.Atoi());
772
0145e89a 773 reader->SetSource(filename.Data());
0145e89a 774
a679753e 775 TString dsName(uri);
776
777 if ( emin.Atoi() <= emax.Atoi() )
778 {
779 // we have an event range
780 if ( emin.Atoi() == emax.Atoi())
781 {
782 dsName += Form("[%d]",emin.Atoi());
783 }
784 else
785 {
786 dsName += Form("[%d,%d]",emin.Atoi(),emax.Atoi());
787 }
788 }
789
790 RegisterDataSource(reader,dsName.Data());
fcabdc0c 791
0145e89a 792 return kTRUE;
793}
794
795//_____________________________________________________________________________
796void
49419555 797AliMUONPainterDataSourceFrame::DataMakerWasRegistered(AliMUONVTrackerDataMaker* reader)
0145e89a 798{
799 /// Update ourselves as a new data reader was created
800
0145e89a 801 AliMUONPainterDataSourceItem* item = new AliMUONPainterDataSourceItem(fDataReaders,100,20,reader);
802
10eb3d17 803 item->Connect("StartRunning()",
804 "AliMUONPainterDataSourceFrame",
805 this,
b0cbe180 806 "StartRunning()");
10eb3d17 807
808 item->Connect("StopRunning()",
809 "AliMUONPainterDataSourceFrame",
810 this,
b0cbe180 811 "StopRunning()");
10eb3d17 812
0145e89a 813 fDataReaders->AddFrame(item);
814
815 fItems->Add(item);
816
817 fDataReaders->MapSubwindows();
818 fDataReaders->Resize();
819}
820
821//_____________________________________________________________________________
822void
57e2ad1a 823AliMUONPainterDataSourceFrame::DataMakerWasUnregistered(const AliMUONVTrackerDataMaker* maker)
0145e89a 824{
49419555 825 /// Update ourselves as a data reader was deleted
0145e89a 826
49419555 827 AliMUONPainterDataSourceItem* theItem(0x0);
10eb3d17 828
49419555 829 TIter next(fItems);
830 AliMUONPainterDataSourceItem* item;
831
832 while ( ( item = static_cast<AliMUONPainterDataSourceItem*>(next()) ) && !theItem )
833 {
834 if ( item->DataMaker() == maker )
835 {
836 theItem = item;
837 }
838 }
839
840 if (!theItem) return;
841
842 fDataReaders->RemoveFrame(theItem);
843 fItems->Remove(theItem);
844 theItem->DestroyWindow();
845 delete theItem;
846
847 fDataReaders->MapSubwindows();
848 fDataReaders->Resize();
849
0145e89a 850}
851
852//_____________________________________________________________________________
853void
854AliMUONPainterDataSourceFrame::OpenFileDialog()
855{
856 /// Open a file dialog to select a file to be read
857
858 TGFileInfo fileInfo;
859
10eb3d17 860 const char* fileTypes[] = {
861 "ROOT files","*.root",
862 "DATE files","*.raw",
863 "All files","*",
864 0,0 };
865
866 fileInfo.fFileTypes = fileTypes;
49419555 867 delete[] fileInfo.fIniDir;
868
869 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
870
871 fileInfo.fIniDir = StrDup(env->String("LastOpenDir","."));
10eb3d17 872
0145e89a 873 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
874 kFDOpen,&fileInfo);
875
0145e89a 876 fFilePath->SetText(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
49419555 877
878 env->Set("LastOpenDir",fileInfo.fIniDir);
879 env->Save();
0145e89a 880}
881
882
883//_____________________________________________________________________________
884void
1286237e 885AliMUONPainterDataSourceFrame::OpenFileDialogACF()
886{
887 /// Open a file dialog to select an ASCII calibration file to be read
888
889 TGFileInfo fileInfo;
890
891 const char* fileTypes[] = {
892 "All files","*",
893 0,0 };
894
895 fileInfo.fFileTypes = fileTypes;
896 delete[] fileInfo.fIniDir;
897
898 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
899
900 fileInfo.fIniDir = StrDup(env->String("LastOpenDirACF","."));
901
902 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
903 kFDOpen,&fileInfo);
904
905 fACFPath->SetText(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
906
907 env->Set("LastOpenDirACF",fileInfo.fIniDir);
908 env->Save();
909}
910
911
912//_____________________________________________________________________________
913void
0145e89a 914AliMUONPainterDataSourceFrame::OpenRecentSource()
915{
916 /// Open one source from the recently used ones
917
918 TGTextLBEntry* t = (TGTextLBEntry*)fRecentSources->GetSelectedEntry();
919
920 TString uri(t->GetText()->GetString());
921
10eb3d17 922 if ( uri.Contains(TRegexp("^RAW")) || uri.Contains(TRegexp("^HRAW")) ||
b6f591ae 923 uri.Contains(TRegexp("^CAL")) || uri.Contains(TRegexp("^HCAL")) ||
924 uri.Contains(TRegexp("^MEM")) )
0145e89a 925 {
926 CreateRawDataSource(uri);
927 }
928 else if ( uri.Contains(TRegexp("^OCDB")) )
929 {
930 CreateOCDBDataSource(uri);
931 }
1286237e 932 else if ( uri.Contains(TRegexp("^ACF")) )
933 {
934 CreateACFDataSource(uri);
935 }
0145e89a 936
937 fRecentSources->Select(-1);
938}
939
10eb3d17 940//_____________________________________________________________________________
941void
b0cbe180 942AliMUONPainterDataSourceFrame::StartRunning()
10eb3d17 943{
944 /// One data source starts running. Disable the Run button of the other ones
b0cbe180 945
946 AliMUONPainterDataSourceItem* item = reinterpret_cast<AliMUONPainterDataSourceItem*> (gTQSender);
947
948 AliInfo("");
949
10eb3d17 950 TIter next(fItems);
951 AliMUONPainterDataSourceItem* o;
952 while ( ( o = static_cast<AliMUONPainterDataSourceItem*>(next()) ) )
953 {
954 if ( o != item )
955 {
956 o->DisableRun();
957 }
958 }
959}
960
961//_____________________________________________________________________________
962void
b0cbe180 963AliMUONPainterDataSourceFrame::StopRunning()
10eb3d17 964{
965 /// One data source stops running. Enable the Run button of all items
b0cbe180 966
10eb3d17 967 TIter next(fItems);
968 AliMUONPainterDataSourceItem* o;
969 while ( ( o = static_cast<AliMUONPainterDataSourceItem*>(next()) ) )
970 {
971 o->EnableRun();
972 }
973}
974