1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONPainterDataSourceFrame.h"
22 #include "AliMUONPainterDataSourceItem.h"
23 #include "AliMUONPainterEnv.h"
24 #include "AliMUONPainterHelper.h"
25 #include "AliMUONPainterRegistry.h"
26 #include "AliMUONTrackerCalibratedDataMaker.h"
27 #include "AliMUONTrackerOCDBDataMaker.h"
28 #include "AliMUONTrackerRawDataMaker.h"
29 #include "AliRawReaderDate.h"
30 #include "AliRawReaderRoot.h"
32 #include <TGComboBox.h>
33 #include <TGFileDialog.h>
34 #include <TGNumberEntry.h>
35 #include <TGTextEntry.h>
37 #include <TObjArray.h>
38 #include <TObjString.h>
43 ///\class AliMUONPainterDataSourceFrame
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.
49 ///\author Laurent Aphecetche, Subatech
51 const char* AliMUONPainterDataSourceFrame::fgkNumberOfDataSourcesKey = "NumberOfDataSources";
52 const char* AliMUONPainterDataSourceFrame::fgkDataSourceURIKey = "DataSourceURI.%d";
55 ClassImp(AliMUONPainterDataSourceFrame)
58 //_____________________________________________________________________________
59 AliMUONPainterDataSourceFrame::AliMUONPainterDataSourceFrame(const TGWindow* p, UInt_t w, UInt_t h)
60 : TGCompositeFrame(p,w,h,kVerticalFrame),
61 fRecentSourceSelector(new TGGroupFrame(p,"Recent sources",kHorizontalFrame)),
62 fRawSelector(new TGGroupFrame(p,"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 fCalibrateButton(new TGCheckButton(fRawSelector22,"Calibrate")),
68 fHistogramButton(new TGCheckButton(fRawSelector23,"Histogram")),
69 fRawOCDBPath(new TGTextEntry(fRawSelector22,"")),
70 fOCDBSelector(new TGGroupFrame(p,"OCDB Path",kHorizontalFrame)),
71 fDataReaders(new TGGroupFrame(p,"Data sources")),
72 fFilePath(new TGTextEntry(fRawSelector21,"")),
73 fOCDBPath(new TGTextEntry(fOCDBSelector,"")),
74 fRunSelector(new TGNumberEntry(fOCDBSelector,0)),
75 fOCDBTypes(new TGComboBox(fOCDBSelector)),
76 fRecentSources(new TGComboBox(fRecentSourceSelector)),
81 AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
83 reg->Connect("DataReaderWasRegistered(AliMUONVTrackerDataMaker*)",
84 "AliMUONPainterDataSourceFrame",
86 "DataReaderWasRegistered(AliMUONVTrackerDataMaker*)");
88 reg->Connect("DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)",
89 "AliMUONPainterDataSourceFrame",
91 "DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)");
93 fItems->SetOwner(kFALSE);
95 /// Recent source selection
97 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
99 Int_t nsources = env->Integer(fgkNumberOfDataSourcesKey);
101 for ( Int_t i = 0; i < nsources; ++i )
103 AddRecentSource(env->String(Form(fgkDataSourceURIKey,i)));
106 fRecentSources->Resize(100,20);
108 TGButton* createRecentButton = new TGTextButton(fRecentSourceSelector,"Create data source");
109 createRecentButton->Connect("Clicked()",
110 "AliMUONPainterDataSourceFrame",
112 "OpenRecentSource()");
114 fRecentSourceSelector->AddFrame(fRecentSources,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
115 fRecentSourceSelector->AddFrame(createRecentButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
117 /// Raw file selection
119 TGButton* openButton = new TGPictureButton(fRawSelector21,
120 gClient->GetPicture("fileopen.xpm"));
121 openButton->SetToolTipText("Click to open file dialog");
123 fRawSelector2->AddFrame(fRawSelector21, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
124 fRawSelector2->AddFrame(fRawSelector22, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
125 fRawSelector2->AddFrame(fRawSelector23, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
127 fRawSelector21->AddFrame(openButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
128 fRawSelector21->AddFrame(fFilePath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
130 fRawSelector22->AddFrame(fCalibrateButton, new TGLayoutHints(kLHintsTop,5,5,5,5));
131 fRawSelector22->AddFrame(fRawOCDBPath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
132 fRawOCDBPath->SetEnabled(kFALSE);
134 fRawSelector23->AddFrame(fHistogramButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
136 TGButton* createRawButton = new TGTextButton(fRawSelector,"Create data source");
138 fRawSelector->AddFrame(fRawSelector2, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
139 fRawSelector->AddFrame(createRawButton, new TGLayoutHints(kLHintsCenterY,5,5,5,5));
141 fCalibrateButton->Connect("Clicked()",
142 "AliMUONPainterDataSourceFrame",
144 "CalibrateButtonClicked()");
146 openButton->Connect("Clicked()",
147 "AliMUONPainterDataSourceFrame",
151 createRawButton->Connect("Clicked()",
152 "AliMUONPainterDataSourceFrame",
154 "CreateRawDataSource()");
158 fOCDBTypes->AddEntry("Pedestals",0);
159 fOCDBTypes->AddEntry("Gains",1);
160 fOCDBTypes->AddEntry("Capacitances",2);
161 fOCDBTypes->Select(0);
162 fOCDBTypes->Resize(100,20);
164 TGButton* createOCDBButton = new TGTextButton(fOCDBSelector,"Create data source");
165 createOCDBButton->Connect("Clicked()",
166 "AliMUONPainterDataSourceFrame",
168 "CreateOCDBDataSource()");
171 fOCDBSelector->AddFrame(fOCDBPath,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
172 fOCDBSelector->AddFrame(fRunSelector,new TGLayoutHints(kLHintsTop,5,5,5,5));
173 fOCDBSelector->AddFrame(fOCDBTypes,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
174 fOCDBSelector->AddFrame(createOCDBButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
176 AddFrame(fRecentSourceSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
178 AddFrame(fRawSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
180 AddFrame(fOCDBSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
182 AddFrame(fDataReaders, new TGLayoutHints(kLHintsExpandX,10,10,10,10));
186 //_____________________________________________________________________________
187 AliMUONPainterDataSourceFrame::~AliMUONPainterDataSourceFrame()
194 //_____________________________________________________________________________
196 AliMUONPainterDataSourceFrame::AddRecentSource(const char* name)
198 /// Add a source to the list of recently used sources
200 TGListBox* lb = fRecentSources->GetListBox();
202 for ( Int_t i = 0; i < lb->GetNumberOfEntries(); ++i )
204 TGTextLBEntry* t = (TGTextLBEntry*)lb->GetEntry(i);
205 TString s(t->GetText()->GetString());
212 fRecentSources->AddEntry(name,lb->GetNumberOfEntries());
213 fRecentSources->MapSubwindows();
214 fRecentSources->Layout();
217 //_____________________________________________________________________________
219 AliMUONPainterDataSourceFrame::CalibrateButtonClicked()
221 /// Calibrate button was clicked.
223 if ( fCalibrateButton->IsOn() )
225 fRawOCDBPath->SetEnabled(kTRUE);
226 fRawOCDBPath->SetFocus();
227 fHistogramButton->SetEnabled(kFALSE);
231 fRawOCDBPath->SetEnabled(kFALSE);
232 fHistogramButton->SetEnabled(kTRUE);
236 //_____________________________________________________________________________
238 AliMUONPainterDataSourceFrame::CreateOCDBDataSource()
240 /// Create an OCDB data source (using information from the widgets)
242 TString cdbPath = fOCDBPath->GetText();
243 Int_t runNumber = fRunSelector->GetIntNumber();
244 TGTextLBEntry* t = static_cast<TGTextLBEntry*>(fOCDBTypes->GetSelectedEntry());
245 TString type = t->GetText()->GetString();
247 CreateOCDBDataSource(cdbPath,runNumber,type);
249 fOCDBPath->SetText("");
250 fRunSelector->SetNumber(0);
253 //_____________________________________________________________________________
255 AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& uri)
257 /// Create an OCDB data source, given it's URI
259 TObjArray* a = uri.Tokenize(";");
260 TString cdbPath = static_cast<TObjString*>(a->At(1))->String();
261 TString srun = static_cast<TObjString*>(a->At(2))->String();
262 TString type = static_cast<TObjString*>(a->At(3))->String();
264 CreateOCDBDataSource(cdbPath,atoi(srun.Data()),type);
269 //_____________________________________________________________________________
271 AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& cdbPath,
275 /// Create an OCDB data source for a given (path,runnumber,type) triplet
277 AliMUONVTrackerDataMaker* reader = new AliMUONTrackerOCDBDataMaker(cdbPath.Data(),
281 if ( reader->IsValid() )
283 AliMUONPainterRegistry::Instance()->Register(reader);
285 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
287 Int_t n = env->Integer(fgkNumberOfDataSourcesKey);
289 env->Set(fgkNumberOfDataSourcesKey,n+1);
291 TString ds(Form("OCDB;%s;%d;%s",cdbPath.Data(),runNumber,type.Data()));
293 env->Set(Form(fgkDataSourceURIKey,n),ds.Data());
297 AddRecentSource(ds.Data());
301 //_____________________________________________________________________________
303 AliMUONPainterDataSourceFrame::CreateRawDataSource()
305 /// Create a new raw data source (using info from the widgets)
307 TString uri(gSystem->ExpandPathName(fFilePath->GetText()));
309 if ( gSystem->AccessPathName(uri.Data()) )
311 AliError(Form("File %s does not exist",uri.Data()));
312 fFilePath->SetText("");
316 uri = Form("%sRAW;%s;%s",( fHistogramButton->IsOn() ? "H":""),uri.Data(),fRawOCDBPath->GetText());
318 if ( CreateRawDataSource(uri) )
320 fFilePath->SetText("");
321 fRawOCDBPath->SetText("");
325 //_____________________________________________________________________________
327 AliMUONPainterDataSourceFrame::CreateRawDataSource(const TString& uri)
329 /// Create a new raw data source, given its URI
334 TObjArray* a = uri.Tokenize(";");
336 filename = static_cast<TObjString*>(a->At(1))->String();
338 if ( a->GetLast() > 1 )
340 ocdbPath = static_cast<TObjString*>(a->At(2))->String();
343 AliRawReader* rawReader = 0x0;
345 if ( filename.Contains(TRegexp(".root$")) )
347 AliDebug(1,"Using RawReaderRoot");
348 if ( filename.Contains(TRegexp("^alien")) )
350 // insure we've initialized the grid...
353 TGrid::Connect("alien://");
357 rawReader = new AliRawReaderRoot(filename.Data());
359 else if ( uri.Contains(TRegexp(".raw")) )
361 AliDebug(1,"Using RawReaderDate");
362 rawReader = new AliRawReaderDate(filename.Data());
366 AliError(Form("Don't know how to open that file : %s\nURI=%s",filename.Data(),uri.Data()));
370 AliMUONVTrackerDataMaker* reader(0x0);
371 Bool_t histogram(kFALSE);
373 if ( ocdbPath.Length() > 0 )
375 reader = new AliMUONTrackerCalibratedDataMaker(rawReader,ocdbPath.Data());
379 if ( uri.Contains(TRegexp("^H")) ) histogram = kTRUE;
380 reader = new AliMUONTrackerRawDataMaker(rawReader,histogram);
383 reader->SetSource(filename.Data());
385 AliMUONPainterRegistry::Instance()->Register(reader);
387 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
389 Int_t n = env->Integer(fgkNumberOfDataSourcesKey);
391 env->Set(fgkNumberOfDataSourcesKey,n+1);
393 TString ds(Form("%sRAW;%s;%s",(histogram ? "H":""),filename.Data(),ocdbPath.Data()));
395 env->Set(Form(fgkDataSourceURIKey,n),ds.Data());
397 AddRecentSource(ds.Data());
404 //_____________________________________________________________________________
406 AliMUONPainterDataSourceFrame::DataReaderWasRegistered(AliMUONVTrackerDataMaker* reader)
408 /// Update ourselves as a new data reader was created
410 AliMUONPainterDataSourceItem* item = new AliMUONPainterDataSourceItem(fDataReaders,100,20,reader);
412 fDataReaders->AddFrame(item);
416 fDataReaders->MapSubwindows();
417 fDataReaders->Resize();
420 //_____________________________________________________________________________
422 AliMUONPainterDataSourceFrame::DataReaderWasUnregistered(AliMUONVTrackerDataMaker* reader)
424 /// Update ourselves as a new data reader was deleted
426 // AliInfo(Form("%s",reader->GetName()));
430 //_____________________________________________________________________________
432 AliMUONPainterDataSourceFrame::OpenFileDialog()
434 /// Open a file dialog to select a file to be read
438 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
442 fFilePath->SetText(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
446 //_____________________________________________________________________________
448 AliMUONPainterDataSourceFrame::OpenRecentSource()
450 /// Open one source from the recently used ones
452 TGTextLBEntry* t = (TGTextLBEntry*)fRecentSources->GetSelectedEntry();
454 TString uri(t->GetText()->GetString());
456 if ( uri.Contains(TRegexp("^RAW")) || uri.Contains(TRegexp("^HRAW")) )
458 CreateRawDataSource(uri);
460 else if ( uri.Contains(TRegexp("^OCDB")) )
462 CreateOCDBDataSource(uri);
465 fRecentSources->Select(-1);