]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPainterDataSourceItem.cxx
AliMUONTrackerCalibratedDataMaker
[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
20#include "AliMUONVTrackerDataMaker.h"
21#include "AliMUONVTrackerData.h"
22#include "AliLog.h"
23#include <TGLabel.h>
24#include <TGButton.h>
25#include <TThread.h>
26#include <Riostream.h>
27
28///\class AliMUONPainterDataSourceItem
29///
30/// Widget to show one data source, and allow to run/stop/rewind/remove it
31///
32/// WARNING : the thread business is not really working yet (AliRawReaders are
33/// not really thread-safe for the moment). So please use a single raw data
34/// source at a time, otherwise you'll get a crash !
35///
36///\author Laurent Aphecetche, Subatech
37
38///\cond CLASSIMP
39ClassImp(AliMUONPainterDataSourceItem)
40///\endcond
41
42namespace
43{
44 void* RunFunction(void* args)
45 {
46 Long_t* params = (Long_t*)(args);
47
48 AliMUONPainterDataSourceItem* calling = reinterpret_cast<AliMUONPainterDataSourceItem*>(params[0]);
49 AliMUONVTrackerDataMaker* reader = reinterpret_cast<AliMUONVTrackerDataMaker*> (params[1]);
50
51 Bool_t ok(kTRUE);
52
53 while ( ok )
54 {
55 ok = reader->NextEvent();
56 }
57
58 calling->Rewind();
59
60 return 0x0;
61 }
62}
63
64//_____________________________________________________________________________
65AliMUONPainterDataSourceItem::AliMUONPainterDataSourceItem(const TGWindow* p,
66 UInt_t w, UInt_t h,
67 AliMUONVTrackerDataMaker* reader)
68: TGCompositeFrame(p,w,h,kHorizontalFrame),
69 fDataReader(reader),
70 fSourceName(new TGLabel(this,reader->Data()->Name())),
71 fSource(new TGLabel(this,reader->Source().Data())),
10eb3d17 72 fNumberOfEvents(new TGLabel(this,Form("%10d",0))),
0145e89a 73 fRun(new TGTextButton(this,"Run")),
74 fStop(new TGTextButton(this,"Stop")),
75 fRewind(new TGTextButton(this,"Rewind")),
10eb3d17 76 fRemove(0x0),//new TGTextButton(this,"Remove")),
0145e89a 77 fThread(0x0),
78 fShouldReset(kFALSE)
79{
80 /// ctor
81
82 Update();
83
84 fRun->SetEnabled(reader->Data()->IsRunnable());
85 fRun->Connect("Clicked()",
86 "AliMUONPainterDataSourceItem",
87 this,
88 "Run()");
89
90 fStop->SetEnabled(kFALSE);
91 fStop->Connect("Clicked()",
92 "AliMUONPainterDataSourceItem",
93 this,
94 "Stop()");
95
96 fRewind->SetEnabled(kFALSE);
97 fRewind->Connect("Clicked()",
98 "AliMUONPainterDataSourceItem",
99 this,
100 "Rewind()");
101
10eb3d17 102// fRemove->Connect("Clicked()",
103// "AliMUONPainterDataSourceItem",
104// this,
105// "Remove()");
0145e89a 106
107 AddFrame(fSourceName, new TGLayoutHints(kLHintsNormal | kLHintsCenterY,5,5,5,5));
108 AddFrame(fSource,new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,5,5,5,5));
109 AddFrame(fNumberOfEvents,new TGLayoutHints(kLHintsNormal | kLHintsCenterY,5,5,5,5));
110 AddFrame(fRun,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
111 AddFrame(fStop,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
112 AddFrame(fRewind,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
10eb3d17 113// AddFrame(fRemove,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
0145e89a 114
115 reader->Data()->Connect("NumberOfEventsChanged()",
116 "AliMUONPainterDataSourceItem",
117 this,
118 "Update()");
119 Resize();
120}
121
122//_____________________________________________________________________________
123AliMUONPainterDataSourceItem::~AliMUONPainterDataSourceItem()
124{
125 /// dtor
126 TThread::Delete(fThread);
127 delete fThread;
128}
129
10eb3d17 130
0145e89a 131//_____________________________________________________________________________
10eb3d17 132void
133AliMUONPainterDataSourceItem::EnableRun()
134{
135 /// Enable run button
136 fRun->SetEnabled(kTRUE);
0145e89a 137}
10eb3d17 138
139//_____________________________________________________________________________
140void
141AliMUONPainterDataSourceItem::DisableRun()
142{
143 /// Disable run button
144 fRun->SetEnabled(kFALSE);
145}
146
0145e89a 147//_____________________________________________________________________________
148void
149AliMUONPainterDataSourceItem::Reset()
150{
151 /// Reset the data
152 fDataReader->Data()->Clear();
153}
154
155//_____________________________________________________________________________
156void
157AliMUONPainterDataSourceItem::Rewind()
158{
159 /// Rewind button was clicked
160
161 fRewind->SetEnabled(kTRUE);
162
163 Stop();
164
165 TThread::Delete(fThread);
166 delete fThread;
167 fThread = 0x0;
168
169 fRun->SetEnabled(kTRUE);
170 fStop->SetEnabled(kFALSE);
171 fRewind->SetEnabled(kFALSE);
172
173 fDataReader->Rewind();
174
175 fShouldReset = kTRUE;
176}
177
178//_____________________________________________________________________________
179void
180AliMUONPainterDataSourceItem::Run()
181{
182 /// Run button was clicked
183
10eb3d17 184 StartRunning();
185
0145e89a 186 if ( fShouldReset )
187 {
188 Reset();
189 fShouldReset = kFALSE;
190 }
191
10eb3d17 192// fRemove->SetEnabled(kFALSE);
0145e89a 193
194 if (!fThread)
195 {
196 fParams[0] = (Long_t)(this);
197 fParams[1] = (Long_t)(fDataReader);
198 fThread = new TThread(RunFunction,(void*)(&fParams[0]));
199 fThread->Run();
200 }
201
202 fDataReader->SetRunning(kTRUE);
203
204 fRun->SetEnabled(kFALSE);
205 fStop->SetEnabled(kTRUE);
206}
207
208//_____________________________________________________________________________
209void
210AliMUONPainterDataSourceItem::Stop()
211{
212 /// Stop button was clicked
213
10eb3d17 214 StopRunning();
215
0145e89a 216 fDataReader->SetRunning(kFALSE);
217
218 fStop->SetEnabled(kFALSE);
219 fRun->SetEnabled(kTRUE);
10eb3d17 220
221 // fRemove->SetEnabled(kTRUE);
0145e89a 222}
223
224//_____________________________________________________________________________
225void
226AliMUONPainterDataSourceItem::Update()
227{
228 /// Update ourselves
229
230 fNumberOfEvents->SetText(Form("%10d",fDataReader->Data()->NumberOfEvents()));
231}
10eb3d17 232
233//_____________________________________________________________________________
234void
235AliMUONPainterDataSourceItem::StartRunning()
236{
237 /// Signal we start to run
238 Emit("StartRunning()");
239}
240
241//_____________________________________________________________________________
242void
243AliMUONPainterDataSourceItem::StopRunning()
244{
245 /// Signal we stop to run
246 Emit("StopRunning()");
247}