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 "AliMUONPainterDataSourceItem.h"
20 #include "AliMUONPainterEnv.h"
21 #include "AliMUONPainterHelper.h"
22 #include "AliMUONPainterDataRegistry.h"
23 #include "AliMUONVTrackerDataMaker.h"
24 #include "AliMUONVTrackerData.h"
27 #include <TGFileDialog.h>
32 #include <Riostream.h>
34 ///\class AliMUONPainterDataSourceItem
36 /// Widget to show one data source, and allow to run/stop/rewind/remove it
38 /// WARNING : the thread business is not really working yet (AliRawReaders are
39 /// not really thread-safe for the moment). So please use a single raw data
40 /// source at a time, otherwise you'll get a crash !
42 ///\author Laurent Aphecetche, Subatech
45 ClassImp(AliMUONPainterDataSourceItem)
50 void* RunFunction(void* args)
52 Long_t* params = (Long_t*)(args);
54 AliMUONPainterDataSourceItem* calling = reinterpret_cast<AliMUONPainterDataSourceItem*>(params[0]);
55 AliMUONVTrackerDataMaker* reader = reinterpret_cast<AliMUONVTrackerDataMaker*> (params[1]);
61 ok = reader->NextEvent();
62 if ( reader->IsZombie() )
64 AliMUONPainterDataRegistry::Instance()->DeleteZombies();
67 if ( !reader->IsRunning() ) gSystem->Sleep(1000);
76 //_____________________________________________________________________________
77 AliMUONPainterDataSourceItem::AliMUONPainterDataSourceItem(const TGWindow* p,
79 AliMUONVTrackerDataMaker* maker)
80 : TGCompositeFrame(p,w,h,kHorizontalFrame),
82 fSourceName(new TGLabel(this,maker->Data()->Name())),
83 fSource(new TGLabel(this,maker->Source().Data())),
84 fNumberOfEvents(new TGLabel(this,Form("%10d",0))),
88 fRemove(new TGTextButton(this,"Remove")),
89 fSave(new TGTextButton(this,"Save")),
90 fSaveAs(new TGTextButton(this,"Save As...")),
96 SetCleanup(kDeepCleanup);
100 AddFrame(fSourceName, new TGLayoutHints(kLHintsNormal | kLHintsCenterY,5,5,5,5));
101 AddFrame(fSource,new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,5,5,5,5));
102 AddFrame(fNumberOfEvents,new TGLayoutHints(kLHintsNormal | kLHintsCenterY,5,5,5,5));
104 if ( fDataMaker->IsRunnable() )
106 fRun = new TGTextButton(this,"Run");
107 fStop = new TGTextButton(this,"Stop");
108 fRewind = new TGTextButton(this,"Rewind");
110 fRun->SetEnabled(!maker->Data()->IsSingleEvent());
111 fRun->Connect("Clicked()",
112 "AliMUONPainterDataSourceItem",
116 fStop->SetEnabled(kFALSE);
117 fStop->Connect("Clicked()",
118 "AliMUONPainterDataSourceItem",
122 fRewind->SetEnabled(kFALSE);
123 fRewind->Connect("Clicked()",
124 "AliMUONPainterDataSourceItem",
128 AddFrame(fRun,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
129 AddFrame(fStop,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
130 AddFrame(fRewind,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
133 AddFrame(fRemove,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
135 AddFrame(fSave,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
137 AddFrame(fSaveAs,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
139 maker->Data()->Connect("NumberOfEventsChanged()",
140 "AliMUONPainterDataSourceItem",
144 fRemove->Connect("Clicked()",
145 "AliMUONPainterDataSourceItem",
149 fSave->Connect("Clicked()",
150 "AliMUONPainterDataSourceItem",
154 fSaveAs->Connect("Clicked()",
155 "AliMUONPainterDataSourceItem",
162 //_____________________________________________________________________________
163 AliMUONPainterDataSourceItem::~AliMUONPainterDataSourceItem()
166 TThread::Delete(fThread);
171 //_____________________________________________________________________________
173 AliMUONPainterDataSourceItem::EnableRun()
175 /// Enable run button
178 fRun->SetEnabled(kTRUE);
182 //_____________________________________________________________________________
184 AliMUONPainterDataSourceItem::DisableRun()
186 /// Disable run button
189 fRun->SetEnabled(kFALSE);
193 //_____________________________________________________________________________
195 AliMUONPainterDataSourceItem::Remove()
200 AliMUONPainterDataRegistry::Instance()->Unregister(fDataMaker);
203 //_____________________________________________________________________________
205 AliMUONPainterDataSourceItem::Reset()
208 fDataMaker->Data()->Clear();
211 //_____________________________________________________________________________
213 AliMUONPainterDataSourceItem::Rewind()
215 /// Rewind button was clicked
217 fRewind->SetEnabled(kTRUE);
221 TThread::Delete(fThread);
225 if ( fRun && fStop && fRewind )
227 fRun->SetEnabled(kTRUE);
228 fStop->SetEnabled(kFALSE);
229 fRewind->SetEnabled(kFALSE);
232 fDataMaker->Rewind();
234 fShouldReset = kTRUE;
237 //_____________________________________________________________________________
239 AliMUONPainterDataSourceItem::Run()
241 /// Run button was clicked
248 fShouldReset = kFALSE;
251 fRemove->SetEnabled(kFALSE);
255 fParams[0] = (Long_t)(this);
256 fParams[1] = (Long_t)(fDataMaker);
257 fThread = new TThread(RunFunction,(void*)(&fParams[0]));
261 fDataMaker->SetRunning(kTRUE);
265 fRun->SetEnabled(kFALSE);
266 fStop->SetEnabled(kTRUE);
270 //_____________________________________________________________________________
272 AliMUONPainterDataSourceItem::Save(const char* filename)
274 /// Save the data maker
276 TFile* f = TFile::Open(filename,"RECREATE");
286 //_____________________________________________________________________________
288 AliMUONPainterDataSourceItem::Save()
290 /// Save the data maker (filename is fixed)
292 TString dname(fDataMaker->Data()->GetName());
295 TString outputDir(AliMUONPainterHelper::Instance()->Env()->String("LastSaveDir","."));
297 TString filename(Form("%s/mchview.%s.root",gSystem->ExpandPathName(outputDir.Data()),dname.Data()));
299 Save(filename.Data());
302 //_____________________________________________________________________________
304 AliMUONPainterDataSourceItem::SaveWithDialog()
306 /// Save the data maker (filename given by dialog)
310 // fileInfo.fFileTypes = fgkFileTypes;
312 delete[] fileInfo.fIniDir;
314 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
316 fileInfo.fIniDir = StrDup(env->String("LastSaveDir","."));
318 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
321 env->Set("LastSaveDir",fileInfo.fIniDir);
324 Save(fileInfo.fFilename);
327 //_____________________________________________________________________________
329 AliMUONPainterDataSourceItem::Stop()
331 /// Stop button was clicked
335 fDataMaker->SetRunning(kFALSE);
339 fStop->SetEnabled(kFALSE);
340 fRun->SetEnabled(kTRUE);
343 fRemove->SetEnabled(kTRUE);
346 //_____________________________________________________________________________
348 AliMUONPainterDataSourceItem::Update()
352 fNumberOfEvents->SetText(Form("%10d",fDataMaker->Data()->NumberOfEvents(-1)));
355 //_____________________________________________________________________________
357 AliMUONPainterDataSourceItem::StartRunning()
359 /// Signal we start to run
360 Emit("StartRunning()");
363 //_____________________________________________________________________________
365 AliMUONPainterDataSourceItem::StopRunning()
367 /// Signal we stop to run
368 Emit("StopRunning()");