]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterDataSourceItem.cxx
First big commit of the mchview program and its accompanying library,
[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 <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
39 ClassImp(AliMUONPainterDataSourceItem)
40 ///\endcond
41
42 namespace
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 //_____________________________________________________________________________
65 AliMUONPainterDataSourceItem::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())),
72   fNumberOfEvents(new TGLabel(this,"0")),
73   fRun(new TGTextButton(this,"Run")),
74   fStop(new TGTextButton(this,"Stop")),
75   fRewind(new TGTextButton(this,"Rewind")),
76   fRemove(new TGTextButton(this,"Remove")),
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     
102     fRemove->Connect("Clicked()",
103                      "AliMUONPainterDataSourceItem",
104                      this,
105                      "Remove()");
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));    
113     AddFrame(fRemove,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));    
114     
115     reader->Data()->Connect("NumberOfEventsChanged()",
116                             "AliMUONPainterDataSourceItem",
117                             this,
118                             "Update()");
119     Resize();
120 }
121
122 //_____________________________________________________________________________
123 AliMUONPainterDataSourceItem::~AliMUONPainterDataSourceItem()
124 {
125   /// dtor
126   TThread::Delete(fThread);
127   delete fThread;
128 }
129
130 //_____________________________________________________________________________
131 void
132 AliMUONPainterDataSourceItem::Remove()
133 {
134   /// Remove button was clicked
135 }
136
137 //_____________________________________________________________________________
138 void
139 AliMUONPainterDataSourceItem::Reset()
140 {
141   /// Reset the data
142   fDataReader->Data()->Clear();
143 }
144
145 //_____________________________________________________________________________
146 void
147 AliMUONPainterDataSourceItem::Rewind()
148 {
149   /// Rewind button was clicked
150   
151   fRewind->SetEnabled(kTRUE);
152   
153   Stop();
154   
155   TThread::Delete(fThread);
156   delete fThread;
157   fThread = 0x0;
158   
159   fRun->SetEnabled(kTRUE);
160   fStop->SetEnabled(kFALSE);
161   fRewind->SetEnabled(kFALSE);
162   
163   fDataReader->Rewind();
164   
165   fShouldReset = kTRUE;
166 }
167
168 //_____________________________________________________________________________
169 void
170 AliMUONPainterDataSourceItem::Run()
171 {
172   /// Run button was clicked
173   
174   if ( fShouldReset ) 
175   {
176     Reset();
177     fShouldReset = kFALSE;
178   }
179   
180   fRemove->SetEnabled(kFALSE);
181   
182   if (!fThread)
183   {
184     fParams[0] = (Long_t)(this);
185     fParams[1] = (Long_t)(fDataReader);
186     fThread = new TThread(RunFunction,(void*)(&fParams[0]));
187     fThread->Run();
188   }
189   
190   fDataReader->SetRunning(kTRUE);
191   
192   fRun->SetEnabled(kFALSE);
193   fStop->SetEnabled(kTRUE);
194 }
195
196 //_____________________________________________________________________________
197 void
198 AliMUONPainterDataSourceItem::Stop()
199 {
200   /// Stop button was clicked
201   
202   fDataReader->SetRunning(kFALSE);
203   
204   fStop->SetEnabled(kFALSE);
205   fRun->SetEnabled(kTRUE);
206   fRemove->SetEnabled(kTRUE);
207 }
208
209 //_____________________________________________________________________________
210 void
211 AliMUONPainterDataSourceItem::Update()
212 {
213   /// Update ourselves
214   
215   fNumberOfEvents->SetText(Form("%10d",fDataReader->Data()->NumberOfEvents()));
216 }