fix coverity
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDModule.cxx
1 // $Id$
2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4 /**************************************************************************
5  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliEveTRDModule.h"
11 #include "AliEveTRDModuleImp.h"
12
13 #include "TGButton.h"
14 #include "TGColorSelect.h"
15 #include "TGNumberEntry.h"
16 #include "TG3DLine.h"
17
18 #include "TEveManager.h"
19
20 ClassImp(AliEveTRDModule)
21 ClassImp(AliEveTRDModuleEditor)
22
23 //______________________________________________________________________________
24 AliEveTRDModule::AliEveTRDModule(const char *typ, Int_t det) :
25   TNamed(Form("%s%03d", typ, det), ""),
26   fLoadHits (kFALSE),
27   fRnrHits  (kTRUE),
28
29   fLoadDigits (kFALSE),
30   fRnrDigits  (kTRUE),
31   fDigitsLog  (kFALSE),
32   fDigitsBox  (kFALSE),
33   fDigitsNeedRecompute (kTRUE),
34
35   fLoadRecPoints (kFALSE),
36   fRnrRecPoints  (kTRUE),
37
38   fLoadTracklets (kFALSE),
39   fRnrTracklets  (kTRUE),
40
41   fDet             (det),
42   fDigitsThreshold (15)
43 {
44   // Constructor.
45 }
46
47 ///////////////////////////////////////////////////////////
48 //////////   AliEveTRDModuleEditor       //////////////////
49 ///////////////////////////////////////////////////////////
50
51 //______________________________________________________________________________
52 AliEveTRDModuleEditor::AliEveTRDModuleEditor(const TGWindow* p, Int_t width, Int_t height,
53                                              UInt_t options, Pixel_t back) :
54   TGedFrame(p, width, height, options | kVerticalFrame, back),
55   fM (0),
56   fDisplayHits(0),
57   fHitsColor(0),
58   fDisplayDigits(0), fToggleLog(0), fToggleBox(0), fThreshold(0),
59   fThresValue(0),
60   fDisplayClusters(0),
61   fClustersColor(0),
62   fDisplayTracks(0)
63 {
64   // Constructor.
65
66   MakeTitle("TRD Detector");
67
68   // "Hits" group frame
69   TGGroupFrame *fGroupFrame615 = new TGGroupFrame(this,"Hits");
70   fDisplayHits = new TGCheckButton(fGroupFrame615,"Display");
71   fDisplayHits->SetToolTipText("Display hits attached to chamber");
72   fDisplayHits->SetState(kButtonDown);
73   fGroupFrame615->AddFrame(fDisplayHits, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
74   fDisplayHits->Connect("Clicked()",
75                         "AliEveTRDModuleEditor", this, "UpdateChamber()");
76
77   // color select widget
78   ULong_t lColPar1;
79   gClient->GetColorByName("#ff00ff", lColPar1);
80   fHitsColor = new TGColorSelect(fGroupFrame615, lColPar1, -1);
81
82   fGroupFrame615->AddFrame(fHitsColor, new TGLayoutHints(kLHintsLeft | kLHintsCenterX | kLHintsTop | kLHintsCenterY,2,2,2,2));
83   fHitsColor->Connect("ColorSelected(Pixel_t)",
84                       "AliEveTRDModuleEditor", this, "UpdateHits(Pixel_t)");
85
86   fGroupFrame615->SetLayoutManager(new TGVerticalLayout(fGroupFrame615));
87   AddFrame(fGroupFrame615, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
88
89   // "Digits" group frame
90   TGGroupFrame *fGroupFrame636 = new TGGroupFrame(this,"Digits");
91   TGVerticalFrame *fVerticalFrame538 = new TGVerticalFrame(fGroupFrame636,68,63,kVerticalFrame);
92   fDisplayDigits = new TGCheckButton(fVerticalFrame538,"Display");
93   fDisplayDigits->SetState(kButtonDown);
94   fDisplayDigits->SetToolTipText("Toggle display digits attached to chamber");
95   fVerticalFrame538->AddFrame(fDisplayDigits, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
96   fDisplayDigits->Connect("Clicked()",
97                           "AliEveTRDModuleEditor", this, "UpdateChamber()");
98   fToggleLog = new TGCheckButton(fVerticalFrame538,"Log");
99   fToggleLog->SetState(kButtonUp);
100   fToggleLog->SetToolTipText("Toggle logarithmic representation of digits");
101   fVerticalFrame538->AddFrame(fToggleLog, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
102   fToggleLog->Connect("Clicked()",
103                       "AliEveTRDModuleEditor", this, "ModifyDigitsView()");
104
105   fToggleBox = new TGCheckButton(fVerticalFrame538,"Box");
106   fToggleBox->SetState(kButtonUp);
107   fToggleBox->SetToolTipText("Toggle display digits as boxes");
108   fVerticalFrame538->AddFrame(fToggleBox, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
109   fToggleBox->Connect("Clicked()",
110                       "AliEveTRDModuleEditor", this, "ModifyDigitsView()");
111   fGroupFrame636->AddFrame(fVerticalFrame538, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
112
113   TGVertical3DLine *fVertical3DLine773 = new TGVertical3DLine(fGroupFrame636,8,63);
114   fGroupFrame636->AddFrame(fVertical3DLine773, new TGLayoutHints(kLHintsLeft | kLHintsCenterX | kLHintsTop | kLHintsExpandY,2,2,2,2));
115
116   // vertical frame
117   TGVerticalFrame *fVerticalFrame543 = new TGVerticalFrame(fGroupFrame636,81,47,kVerticalFrame);
118   fThreshold = new TGCheckButton(fVerticalFrame543, "Threshold");
119   fThreshold->SetToolTipText("Toggle threshold updating display");
120   fVerticalFrame543->AddFrame(fThreshold, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
121   fThresValue = new TGNumberEntry(fVerticalFrame543, (Int_t)10, 5, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAPositive, TGNumberFormat::kNELLimitMinMax, 0, 1024);
122   fThresValue->Connect("ValueSet(Long_t)",
123                        "AliEveTRDModuleEditor", this, "SetThreshold(Long_t)");
124   fVerticalFrame543->AddFrame(fThresValue, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
125
126   fGroupFrame636->AddFrame(fVerticalFrame543, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
127
128   fGroupFrame636->SetLayoutManager(new TGHorizontalLayout(fGroupFrame636));
129   AddFrame(fGroupFrame636, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
130
131   // "Clusters" group frame
132   TGGroupFrame *fGroupFrame649 = new TGGroupFrame(this,"Clusters");
133   fDisplayClusters = new TGCheckButton(fGroupFrame649,"Display");
134   fDisplayClusters->SetToolTipText("Display clusters attached to chamber");
135   fGroupFrame649->AddFrame(fDisplayClusters, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
136   fDisplayClusters->SetState(kButtonDown);
137   fDisplayClusters->Connect("Clicked()",
138                             "AliEveTRDModuleEditor", this, "UpdateChamber()");
139
140   // color select widget
141   ULong_t lColPar2;
142   gClient->GetColorByName("#ff00ff", lColPar2);
143   fClustersColor = new TGColorSelect(fGroupFrame649, lColPar2, -1);
144
145   fGroupFrame649->AddFrame(fClustersColor, new TGLayoutHints(kLHintsLeft | kLHintsCenterX | kLHintsTop | kLHintsCenterY,2,2,2,2));
146   fClustersColor->Connect("ColorSelected(Pixel_t)",
147                           "AliEveTRDModuleEditor", this, "UpdateClusters(Pixel_t)");
148
149   fGroupFrame649->SetLayoutManager(new TGVerticalLayout(fGroupFrame649));
150   AddFrame(fGroupFrame649, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
151
152   // "Tracks" group frame
153   TGGroupFrame *fGroupFrame676 = new TGGroupFrame(this,"Tracklets");
154   fDisplayTracks = new TGCheckButton(fGroupFrame676,"Display");
155   fDisplayTracks->SetToolTipText("Display MCM tracklets attached to chamber");
156   fGroupFrame676->AddFrame(fDisplayTracks, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
157   fDisplayTracks->SetState(kButtonDown);
158   fDisplayTracks->Connect("Clicked()",
159                           "AliEveTRDModuleEditor", this, "UpdateChamber()");
160
161   fGroupFrame676->SetLayoutManager(new TGVerticalLayout(fGroupFrame676));
162   AddFrame(fGroupFrame676, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY | kLHintsExpandX,2,2,2,2));
163 }
164
165 //______________________________________________________________________________
166 void AliEveTRDModuleEditor::SetModel(TObject* obj)
167 {
168   // Set model object.
169
170   if(!(fM = dynamic_cast<AliEveTRDModule*>(obj))) return;
171
172   if(AliEveTRDNode *node = dynamic_cast<AliEveTRDNode*>(fM)) node->UpdateNode();
173
174   fDisplayHits->SetEnabled(fM->fLoadHits);
175   if(fM->fLoadHits) fDisplayHits->SetState( fM->fRnrHits ? kButtonDown : kButtonUp);
176
177   fDisplayDigits->SetEnabled(fM->fLoadDigits);
178   fToggleLog->SetEnabled(fM->fLoadDigits);
179   fToggleBox->SetEnabled(fM->fLoadDigits);
180   fThreshold->SetEnabled(fM->fLoadDigits);
181   fThresValue->GetNumberEntry()->SetEnabled(fM->fLoadDigits);
182   fThresValue->GetButtonDown()->SetEnabled(fM->fLoadDigits);
183   fThresValue->GetButtonUp()->SetEnabled(fM->fLoadDigits);
184   fThresValue->SetIntNumber(fM->fDigitsThreshold);
185   if(fM->fLoadDigits){
186     fDisplayDigits->SetState(fM->fRnrDigits ? kButtonDown : kButtonUp);
187     fToggleLog->SetState(fM->fDigitsLog ? kButtonDown : kButtonUp);
188     fToggleBox->SetState(fM->fDigitsBox ? kButtonDown : kButtonUp);
189     fThreshold->SetState(fM->fDigitsNeedRecompute ? kButtonDown : kButtonUp);
190   }
191
192   if(fM->fLoadRecPoints) fDisplayClusters->SetState(fM->fRnrRecPoints ? kButtonDown : kButtonUp);
193   else fDisplayClusters->SetEnabled(kFALSE);
194
195   if(fM->fLoadTracklets) fDisplayTracks->SetState(fM->fRnrTracklets ? kButtonDown : kButtonUp);
196   else fDisplayTracks->SetEnabled(kFALSE);
197 }
198
199 //______________________________________________________________________________
200 void AliEveTRDModuleEditor::ModifyDigitsView()
201 {
202   // Slor to modify digit view.
203
204   fM->fDigitsNeedRecompute = kTRUE;
205   UpdateChamber();
206 }
207
208 //______________________________________________________________________________
209 void AliEveTRDModuleEditor::SetThreshold(Long_t tres)
210 {
211   // Slot for SetThreshold.
212
213   if(!fM->fLoadDigits) return;
214
215   fM->fDigitsThreshold = (tres == 0) ? (int)fThresValue->GetNumber():tres;
216   fM->fDigitsNeedRecompute = fThreshold->IsDown();
217   UpdateChamber();
218 }
219
220
221 //______________________________________________________________________________
222 void AliEveTRDModuleEditor::UpdateChamber()
223 {
224   //    Info("UpdateChamber()", "");
225
226   fM->fRnrHits = kFALSE;
227   if(fDisplayHits->IsDown()) fM->fRnrHits = kTRUE;
228
229   fM->fRnrDigits = kFALSE;
230   if(fDisplayDigits->IsDown()){
231     fM->fRnrDigits = kTRUE;
232     if(fToggleLog->IsDown()) fM->fDigitsLog = kTRUE;
233     else  fM->fDigitsLog = kFALSE;
234     if(fToggleBox->IsDown()) fM->fDigitsBox = kTRUE;
235     else  fM->fDigitsBox = kFALSE;
236   }
237
238   fM->fRnrRecPoints = kFALSE;
239   if(fDisplayClusters->IsDown()) fM->fRnrRecPoints = kTRUE;
240
241   fM->fRnrTracklets = kFALSE;
242   if(fDisplayTracks->IsDown()) fM->fRnrTracklets = kTRUE;
243
244   AliEveTRDNode *node(NULL);
245   if((node = dynamic_cast<AliEveTRDNode*>(fM))) node->UpdateLeaves();
246
247   gEve->Redraw3D();
248 }
249
250 //______________________________________________________________________________
251 void AliEveTRDModuleEditor::UpdateClusters(Pixel_t /*col*/)
252 {
253   //    Info("UpdateClusters()","");
254   /*
255     if(fM->fRecPoints){
256     fM->fRecPoints->SetMarkerColor(col ? fHitsColor->GetColor() : col);
257     gEve->Redraw3D();
258     }
259   */
260 }
261
262 //______________________________________________________________________________
263 void AliEveTRDModuleEditor::UpdateHits(Pixel_t /*col*/)
264 {
265   //    Info("UpdateHits()","");
266   /*
267     if(fM->fHits){
268     fM->fHits->SetMarkerColor(col ? fClustersColor->GetColor() : col);
269     gEve->Redraw3D();
270     }
271   */
272 }