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"
20 #include "AliMUONPainterDataSourceItem.h"
21 #include "AliMUONPainterEnv.h"
22 #include "AliMUONPainterHelper.h"
23 #include "AliMUONPainterRegistry.h"
24 #include "AliMUONTrackerOCDBDataMaker.h"
25 #include "AliMUONTrackerRawDataMaker.h"
26 #include "AliMUONVTrackerDataMaker.h"
28 #include "AliRawReaderDate.h"
29 #include "AliRawReaderRoot.h"
31 #include <TGComboBox.h>
32 #include <TGFileDialog.h>
33 #include <TGNumberEntry.h>
34 #include <TGTextEntry.h>
36 #include <TObjArray.h>
37 #include <TObjString.h>
42 ///\class AliMUONPainterDataSourceFrame
44 /// A complete frame to select and display various data sources to
45 /// be displayed : either raw data or OCDB data.
46 /// Later on we might add digits and clusters for instance.
48 ///\author Laurent Aphecetche, Subatech
50 const char* AliMUONPainterDataSourceFrame::fgkNumberOfDataSourcesKey = "NumberOfDataSources";
51 const char* AliMUONPainterDataSourceFrame::fgkDataSourceURIKey = "DataSourceURI.%d";
54 ClassImp(AliMUONPainterDataSourceFrame)
57 //_____________________________________________________________________________
58 AliMUONPainterDataSourceFrame::AliMUONPainterDataSourceFrame(const TGWindow* p, UInt_t w, UInt_t h)
59 : TGCompositeFrame(p,w,h,kVerticalFrame),
60 fRecentSourceSelector(new TGGroupFrame(p,"Recent sources",kHorizontalFrame)),
61 fRawSelector(new TGGroupFrame(p,"Raw file URI",kHorizontalFrame)),
62 fOCDBSelector(new TGGroupFrame(p,"OCDB Path",kHorizontalFrame)),
63 fDataReaders(new TGGroupFrame(p,"Data sources")),
64 fFilePath(new TGTextEntry(fRawSelector,"")),
65 fRawOCDBPath(new TGTextEntry(fRawSelector,"")),
66 fOCDBPath(new TGTextEntry(fOCDBSelector,"")),
67 fRunSelector(new TGNumberEntry(fOCDBSelector,0)),
68 fOCDBTypes(new TGComboBox(fOCDBSelector)),
69 fRecentSources(new TGComboBox(fRecentSourceSelector)),
74 AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
76 reg->Connect("DataReaderWasRegistered(AliMUONVTrackerDataMaker*)",
77 "AliMUONPainterDataSourceFrame",
79 "DataReaderWasRegistered(AliMUONVTrackerDataMaker*)");
81 reg->Connect("DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)",
82 "AliMUONPainterDataSourceFrame",
84 "DataReaderWasUnregistered(AliMUONVTrackerDataMaker*)");
86 fItems->SetOwner(kFALSE);
88 /// Recent source selection
90 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
92 Int_t nsources = env->Integer(fgkNumberOfDataSourcesKey);
94 for ( Int_t i = 0; i < nsources; ++i )
96 AddRecentSource(env->String(Form(fgkDataSourceURIKey,i)));
99 fRecentSources->Resize(100,20);
101 TGButton* createRecentButton = new TGTextButton(fRecentSourceSelector,"Create data source");
102 createRecentButton->Connect("Clicked()",
103 "AliMUONPainterDataSourceFrame",
105 "OpenRecentSource()");
107 fRecentSourceSelector->AddFrame(fRecentSources,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
108 fRecentSourceSelector->AddFrame(createRecentButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
110 /// Raw file selection
112 TGButton* openButton = new TGPictureButton(fRawSelector,
113 gClient->GetPicture("fileopen.xpm"));
114 openButton->SetToolTipText("Click to open file dialog");
116 TGButton* createRawButton = new TGTextButton(fRawSelector,"Create data source");
118 fRawSelector->AddFrame(fFilePath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
119 fRawSelector->AddFrame(fRawOCDBPath, new TGLayoutHints(kLHintsTop,5,5,5,5));
120 fRawSelector->AddFrame(openButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
121 fRawSelector->AddFrame(createRawButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
123 openButton->Connect("Clicked()",
124 "AliMUONPainterDataSourceFrame",
128 createRawButton->Connect("Clicked()",
129 "AliMUONPainterDataSourceFrame",
131 "CreateRawDataSource()");
135 fOCDBTypes->AddEntry("Pedestals",0);
136 fOCDBTypes->AddEntry("Gains",1);
137 fOCDBTypes->AddEntry("Capacitances",2);
138 fOCDBTypes->Select(0);
139 fOCDBTypes->Resize(100,20);
141 TGButton* createOCDBButton = new TGTextButton(fOCDBSelector,"Create data source");
142 createOCDBButton->Connect("Clicked()",
143 "AliMUONPainterDataSourceFrame",
145 "CreateOCDBDataSource()");
148 fOCDBSelector->AddFrame(fOCDBPath,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
149 fOCDBSelector->AddFrame(fRunSelector,new TGLayoutHints(kLHintsTop,5,5,5,5));
150 fOCDBSelector->AddFrame(fOCDBTypes,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
151 fOCDBSelector->AddFrame(createOCDBButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
153 AddFrame(fRecentSourceSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
155 AddFrame(fRawSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
157 AddFrame(fOCDBSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
159 AddFrame(fDataReaders, new TGLayoutHints(kLHintsExpandX,10,10,10,10));
163 //_____________________________________________________________________________
164 AliMUONPainterDataSourceFrame::~AliMUONPainterDataSourceFrame()
171 //_____________________________________________________________________________
173 AliMUONPainterDataSourceFrame::AddRecentSource(const char* name)
175 /// Add a source to the list of recently used sources
177 TGListBox* lb = fRecentSources->GetListBox();
179 for ( Int_t i = 0; i < lb->GetNumberOfEntries(); ++i )
181 TGTextLBEntry* t = (TGTextLBEntry*)lb->GetEntry(i);
182 TString s(t->GetText()->GetString());
189 fRecentSources->AddEntry(name,lb->GetNumberOfEntries());
190 fRecentSources->MapSubwindows();
191 fRecentSources->Layout();
194 //_____________________________________________________________________________
196 AliMUONPainterDataSourceFrame::CreateOCDBDataSource()
198 /// Create an OCDB data source (using information from the widgets)
200 TString cdbPath = fOCDBPath->GetText();
201 Int_t runNumber = fRunSelector->GetIntNumber();
202 TGTextLBEntry* t = static_cast<TGTextLBEntry*>(fOCDBTypes->GetSelectedEntry());
203 TString type = t->GetText()->GetString();
205 CreateOCDBDataSource(cdbPath,runNumber,type);
207 fOCDBPath->SetText("");
208 fRunSelector->SetNumber(0);
211 //_____________________________________________________________________________
213 AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& uri)
215 /// Create an OCDB data source, given it's URI
217 TObjArray* a = uri.Tokenize(";");
218 TString cdbPath = static_cast<TObjString*>(a->At(1))->String();
219 TString srun = static_cast<TObjString*>(a->At(2))->String();
220 TString type = static_cast<TObjString*>(a->At(3))->String();
222 CreateOCDBDataSource(cdbPath,atoi(srun.Data()),type);
227 //_____________________________________________________________________________
229 AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& cdbPath,
233 /// Create an OCDB data source for a given (path,runnumber,type) triplet
235 AliMUONVTrackerDataMaker* reader = new AliMUONTrackerOCDBDataMaker(cdbPath.Data(),
239 if ( reader->IsValid() )
241 AliMUONPainterRegistry::Instance()->Register(reader);
243 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
245 Int_t n = env->Integer(fgkNumberOfDataSourcesKey);
247 env->Set(fgkNumberOfDataSourcesKey,n+1);
249 TString ds(Form("OCDB;%s;%d;%s",cdbPath.Data(),runNumber,type.Data()));
251 env->Set(Form(fgkDataSourceURIKey,n),ds.Data());
255 AddRecentSource(ds.Data());
259 //_____________________________________________________________________________
261 AliMUONPainterDataSourceFrame::CreateRawDataSource()
263 /// Create a new raw data source (using info from the widgets)
265 TString uri(gSystem->ExpandPathName(fFilePath->GetText()));
267 if ( gSystem->AccessPathName(uri.Data()) )
269 AliError(Form("File %s does not exist",uri.Data()));
270 fFilePath->SetText("");
274 uri = Form("RAW;%s;%s",uri.Data(),fRawOCDBPath->GetText());
276 if ( CreateRawDataSource(uri) )
278 fFilePath->SetText("");
279 fRawOCDBPath->SetText("");
283 //_____________________________________________________________________________
285 AliMUONPainterDataSourceFrame::CreateRawDataSource(const TString& uri)
287 /// Create a new raw data source, given its URI
292 TObjArray* a = uri.Tokenize(";");
294 filename = static_cast<TObjString*>(a->At(1))->String();
296 if ( a->GetLast() > 1 )
298 ocdbPath = static_cast<TObjString*>(a->At(2))->String();
301 AliRawReader* rawReader = 0x0;
303 if ( filename.Contains(TRegexp(".root$")) )
305 AliDebug(1,"Using RawReaderRoot");
306 if ( filename.Contains(TRegexp("^alien")) )
308 // insure we've initialized the grid...
311 TGrid::Connect("alien://");
315 rawReader = new AliRawReaderRoot(filename.Data());
317 else if ( uri.Contains(TRegexp(".raw")) )
319 AliDebug(1,"Using RawReaderDate");
320 rawReader = new AliRawReaderDate(filename.Data());
324 AliError(Form("Don't know how to open that file : %s\nURI=%s",filename.Data(),uri.Data()));
328 AliMUONTrackerRawDataMaker* reader = new AliMUONTrackerRawDataMaker(rawReader,ocdbPath.Data());
330 reader->SetSource(filename.Data());
332 AliMUONPainterRegistry::Instance()->Register(reader);
334 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
336 Int_t n = env->Integer(fgkNumberOfDataSourcesKey);
338 env->Set(fgkNumberOfDataSourcesKey,n+1);
340 TString ds(Form("RAW;%s;%s",filename.Data(),ocdbPath.Data()));
342 env->Set(Form(fgkDataSourceURIKey,n),ds.Data());
344 AddRecentSource(ds.Data());
351 //_____________________________________________________________________________
353 AliMUONPainterDataSourceFrame::DataReaderWasRegistered(AliMUONVTrackerDataMaker* reader)
355 /// Update ourselves as a new data reader was created
357 AliInfo(Form("%s",reader->GetName()));
359 AliMUONPainterDataSourceItem* item = new AliMUONPainterDataSourceItem(fDataReaders,100,20,reader);
361 fDataReaders->AddFrame(item);
365 fDataReaders->MapSubwindows();
366 fDataReaders->Resize();
369 //_____________________________________________________________________________
371 AliMUONPainterDataSourceFrame::DataReaderWasUnregistered(AliMUONVTrackerDataMaker* reader)
373 /// Update ourselves as a new data reader was deleted
375 AliInfo(Form("%s",reader->GetName()));
379 //_____________________________________________________________________________
381 AliMUONPainterDataSourceFrame::OpenFileDialog()
383 /// Open a file dialog to select a file to be read
387 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
391 fFilePath->SetText(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
395 //_____________________________________________________________________________
397 AliMUONPainterDataSourceFrame::OpenRecentSource()
399 /// Open one source from the recently used ones
401 TGTextLBEntry* t = (TGTextLBEntry*)fRecentSources->GetSelectedEntry();
403 TString uri(t->GetText()->GetString());
405 if ( uri.Contains(TRegexp("^RAW")) )
407 CreateRawDataSource(uri);
409 else if ( uri.Contains(TRegexp("^OCDB")) )
411 CreateOCDBDataSource(uri);
414 fRecentSources->Select(-1);