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