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