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