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