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