Removing leftover return
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterDataSourceItem.cxx
CommitLineData
0145e89a 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 "AliMUONPainterDataSourceItem.h"
19
49419555 20#include "AliMUONPainterEnv.h"
21#include "AliMUONPainterHelper.h"
8f0acce4 22#include "AliMUONPainterDataRegistry.h"
0145e89a 23#include "AliMUONVTrackerDataMaker.h"
24#include "AliMUONVTrackerData.h"
25#include "AliLog.h"
49419555 26#include <TFile.h>
27#include <TGFileDialog.h>
0145e89a 28#include <TGLabel.h>
29#include <TGButton.h>
d59bbae8 30#include <TSystem.h>
0145e89a 31#include <TThread.h>
32#include <Riostream.h>
33
34///\class AliMUONPainterDataSourceItem
35///
36/// Widget to show one data source, and allow to run/stop/rewind/remove it
37///
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 !
41///
42///\author Laurent Aphecetche, Subatech
43
44///\cond CLASSIMP
45ClassImp(AliMUONPainterDataSourceItem)
46///\endcond
47
48namespace
49{
50 void* RunFunction(void* args)
51 {
52 Long_t* params = (Long_t*)(args);
53
54 AliMUONPainterDataSourceItem* calling = reinterpret_cast<AliMUONPainterDataSourceItem*>(params[0]);
55 AliMUONVTrackerDataMaker* reader = reinterpret_cast<AliMUONVTrackerDataMaker*> (params[1]);
56
57 Bool_t ok(kTRUE);
58
59 while ( ok )
60 {
61 ok = reader->NextEvent();
49419555 62 if ( reader->IsZombie() )
63 {
8f0acce4 64 AliMUONPainterDataRegistry::Instance()->DeleteZombies();
49419555 65 return 0x0;
66 }
d59bbae8 67 if ( !reader->IsRunning() ) gSystem->Sleep(1000);
0145e89a 68 }
69
70 calling->Rewind();
71
72 return 0x0;
73 }
74}
75
76//_____________________________________________________________________________
77AliMUONPainterDataSourceItem::AliMUONPainterDataSourceItem(const TGWindow* p,
78 UInt_t w, UInt_t h,
49419555 79 AliMUONVTrackerDataMaker* maker)
0145e89a 80: TGCompositeFrame(p,w,h,kHorizontalFrame),
49419555 81 fDataMaker(maker),
82 fSourceName(new TGLabel(this,maker->Data()->Name())),
83 fSource(new TGLabel(this,maker->Source().Data())),
10eb3d17 84 fNumberOfEvents(new TGLabel(this,Form("%10d",0))),
49419555 85 fRun(0x0),
86 fStop(0x0),
87 fRewind(0x0),
88 fRemove(new TGTextButton(this,"Remove")),
89 fSave(new TGTextButton(this,"Save")),
90 fSaveAs(new TGTextButton(this,"Save As...")),
0145e89a 91 fThread(0x0),
92 fShouldReset(kFALSE)
93{
94 /// ctor
49419555 95
96 SetCleanup(kDeepCleanup);
0145e89a 97
98 Update();
99
0145e89a 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));
49419555 103
104 if ( fDataMaker->IsRunnable() )
105 {
106 fRun = new TGTextButton(this,"Run");
107 fStop = new TGTextButton(this,"Stop");
108 fRewind = new TGTextButton(this,"Rewind");
109
110 fRun->SetEnabled(!maker->Data()->IsSingleEvent());
111 fRun->Connect("Clicked()",
112 "AliMUONPainterDataSourceItem",
113 this,
114 "Run()");
115
116 fStop->SetEnabled(kFALSE);
117 fStop->Connect("Clicked()",
118 "AliMUONPainterDataSourceItem",
119 this,
120 "Stop()");
121
122 fRewind->SetEnabled(kFALSE);
123 fRewind->Connect("Clicked()",
124 "AliMUONPainterDataSourceItem",
125 this,
126 "Rewind()");
127
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));
131 }
132
133 AddFrame(fRemove,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
134
135 AddFrame(fSave,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
136
137 AddFrame(fSaveAs,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
138
139 maker->Data()->Connect("NumberOfEventsChanged()",
0145e89a 140 "AliMUONPainterDataSourceItem",
141 this,
142 "Update()");
49419555 143
144 fRemove->Connect("Clicked()",
145 "AliMUONPainterDataSourceItem",
146 this,
147 "Remove()");
148
149 fSave->Connect("Clicked()",
150 "AliMUONPainterDataSourceItem",
151 this,
152 "Save()");
153
154 fSaveAs->Connect("Clicked()",
155 "AliMUONPainterDataSourceItem",
156 this,
157 "SaveWithDialog()");
158
0145e89a 159 Resize();
160}
161
162//_____________________________________________________________________________
163AliMUONPainterDataSourceItem::~AliMUONPainterDataSourceItem()
164{
165 /// dtor
166 TThread::Delete(fThread);
167 delete fThread;
168}
169
10eb3d17 170
0145e89a 171//_____________________________________________________________________________
10eb3d17 172void
173AliMUONPainterDataSourceItem::EnableRun()
174{
175 /// Enable run button
49419555 176 if ( fRun )
177 {
178 fRun->SetEnabled(kTRUE);
179 }
0145e89a 180}
10eb3d17 181
182//_____________________________________________________________________________
183void
184AliMUONPainterDataSourceItem::DisableRun()
185{
186 /// Disable run button
49419555 187 if ( fRun )
188 {
189 fRun->SetEnabled(kFALSE);
190 }
10eb3d17 191}
49419555 192
193//_____________________________________________________________________________
194void
195AliMUONPainterDataSourceItem::Remove()
196{
197 /// Remove
10eb3d17 198
49419555 199 MakeZombie();
8f0acce4 200 AliMUONPainterDataRegistry::Instance()->Unregister(fDataMaker);
49419555 201}
202
0145e89a 203//_____________________________________________________________________________
204void
205AliMUONPainterDataSourceItem::Reset()
206{
207 /// Reset the data
49419555 208 fDataMaker->Data()->Clear();
0145e89a 209}
210
211//_____________________________________________________________________________
212void
213AliMUONPainterDataSourceItem::Rewind()
214{
215 /// Rewind button was clicked
216
217 fRewind->SetEnabled(kTRUE);
218
219 Stop();
220
221 TThread::Delete(fThread);
222 delete fThread;
223 fThread = 0x0;
224
49419555 225 if ( fRun && fStop && fRewind )
226 {
227 fRun->SetEnabled(kTRUE);
228 fStop->SetEnabled(kFALSE);
229 fRewind->SetEnabled(kFALSE);
230 }
0145e89a 231
49419555 232 fDataMaker->Rewind();
0145e89a 233
234 fShouldReset = kTRUE;
235}
236
237//_____________________________________________________________________________
238void
239AliMUONPainterDataSourceItem::Run()
240{
241 /// Run button was clicked
242
10eb3d17 243 StartRunning();
244
0145e89a 245 if ( fShouldReset )
246 {
247 Reset();
248 fShouldReset = kFALSE;
249 }
250
49419555 251 fRemove->SetEnabled(kFALSE);
0145e89a 252
253 if (!fThread)
254 {
255 fParams[0] = (Long_t)(this);
49419555 256 fParams[1] = (Long_t)(fDataMaker);
0145e89a 257 fThread = new TThread(RunFunction,(void*)(&fParams[0]));
258 fThread->Run();
259 }
260
49419555 261 fDataMaker->SetRunning(kTRUE);
0145e89a 262
49419555 263 if ( fRun && fStop )
264 {
265 fRun->SetEnabled(kFALSE);
266 fStop->SetEnabled(kTRUE);
267 }
268}
269
270//_____________________________________________________________________________
271void
272AliMUONPainterDataSourceItem::Save(const char* filename)
273{
274 /// Save the data maker
275
276 TFile* f = TFile::Open(filename,"RECREATE");
277
278 fDataMaker->Write();
279
280 f->Write();
281 f->Close();
282
283 delete f;
284}
285
286//_____________________________________________________________________________
287void
288AliMUONPainterDataSourceItem::Save()
289{
290 /// Save the data maker (filename is fixed)
291
292 TString dname(fDataMaker->Data()->GetName());
293 dname.ToLower();
294
295 TString outputDir(AliMUONPainterHelper::Instance()->Env()->String("LastSaveDir","."));
296
297 TString filename(Form("%s/mchview.%s.root",gSystem->ExpandPathName(outputDir.Data()),dname.Data()));
298
299 Save(filename.Data());
300}
301
302//_____________________________________________________________________________
303void
304AliMUONPainterDataSourceItem::SaveWithDialog()
305{
306 /// Save the data maker (filename given by dialog)
307
308 TGFileInfo fileInfo;
309
310// fileInfo.fFileTypes = fgkFileTypes;
311
312 delete[] fileInfo.fIniDir;
313
314 AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
315
316 fileInfo.fIniDir = StrDup(env->String("LastSaveDir","."));
317
318 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
319 kFDSave,&fileInfo);
320
321 env->Set("LastSaveDir",fileInfo.fIniDir);
322 env->Save();
323
324 Save(fileInfo.fFilename);
0145e89a 325}
326
327//_____________________________________________________________________________
328void
329AliMUONPainterDataSourceItem::Stop()
330{
331 /// Stop button was clicked
332
10eb3d17 333 StopRunning();
334
49419555 335 fDataMaker->SetRunning(kFALSE);
0145e89a 336
49419555 337 if ( fStop && fRun )
338 {
339 fStop->SetEnabled(kFALSE);
340 fRun->SetEnabled(kTRUE);
341 }
342
343 fRemove->SetEnabled(kTRUE);
0145e89a 344}
345
346//_____________________________________________________________________________
347void
348AliMUONPainterDataSourceItem::Update()
349{
350 /// Update ourselves
351
e83120bd 352 fNumberOfEvents->SetText(Form("%10d",fDataMaker->Data()->NumberOfEvents(-1)));
0145e89a 353}
10eb3d17 354
355//_____________________________________________________________________________
356void
357AliMUONPainterDataSourceItem::StartRunning()
358{
359 /// Signal we start to run
360 Emit("StartRunning()");
361}
362
363//_____________________________________________________________________________
364void
365AliMUONPainterDataSourceItem::StopRunning()
366{
367 /// Signal we stop to run
368 Emit("StopRunning()");
369}