Be explicit with the kind of manus we are counting (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEVisu.cxx
CommitLineData
215d5755 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// $MpId$
18
19#include "AliMpDEVisu.h"
e4d2775e 20
21#include "AliMpSlatMotifMap.h"
22#include "AliMpSt345Reader.h"
23#include "AliMpSectorReader.h"
24#include "AliMpSlat.h"
25#include "AliMpPCB.h"
e4d2775e 26#include "AliMpSectorReader.h"
27#include "AliMpSector.h"
28#include "AliMpRow.h"
29#include "AliMpVRowSegment.h"
e4d2775e 30#include "AliMpVPainter.h"
e4d2775e 31#include "AliMpMotifPosition.h"
32#include "AliMpMotifMap.h"
e4d2775e 33#include "AliMpDEIterator.h"
34#include "AliMpDEManager.h"
35#include "AliMpDetElement.h"
36#include "AliMpStationType.h"
37#include "AliMpSegmentation.h"
38#include "AliMpPad.h"
39#include "AliMpDDLStore.h"
215d5755 40#include "AliMpVPadIterator.h"
37ec2d4a 41#include "AliMpCDB.h"
e4d2775e 42
215d5755 43#include "AliLog.h"
44
45#include <TMath.h>
46#include <TString.h>
47#include <TVector2.h>
48#include <TCanvas.h>
49#include <TGButton.h>
50#include <TRootEmbeddedCanvas.h>
51#include <TGLabel.h>
52#include <TGComboBox.h>
53#include <TGNumberEntry.h>
54#include <TGTextView.h>
55#include <TGTextEntry.h>
e4d2775e 56
57// Category: graphics
3d1463c8 58
59//-----------------------------------------------------------------------------
e4d2775e 60// Class AliMpDEVisu
61// -----------------------
62// GUI for drawing segmentation
63// motif manu and associated channels
64// date: 2007/01/26
65// Author: Ch. Finck
3d1463c8 66//-----------------------------------------------------------------------------
e4d2775e 67
68/// \cond CLASSIMP
69ClassImp(AliMpDEVisu)
70/// \endcond
71
72//_________________________________________________________________
73AliMpDEVisu::AliMpDEVisu(UInt_t w, UInt_t h)
215d5755 74: TGFrame(gClient->GetRoot(), w, h),
75 fkMainWindow(gClient->GetRoot()),
76 fMain(new TGMainFrame(gClient->GetRoot(), w, h)),
77 fEcanvas(0x0),
78 fChamberCombo(0x0),
79 fDECombo(0x0),
80 fNumberEntry(0x0),
81 fPlaneButton(0x0),
82 fZoomButton(0x0),
d58f6c58 83 fNameDECombo(0x0),
215d5755 84 fLogMessage(0x0),
85 fLogFile(0x0),
86 fTrashList(0x0),
87 fDEComboIdx(),
d58f6c58 88 fNameDEComboIdx(),
89 fDEOccurrence(1026),
215d5755 90 fCurrentPlane(AliMp::kBendingPlane),
91 fCurrentDetElem(100),
92 fCurrentDEName(),
93 fSegmentation(),
215d5755 94 fZoomMode(false)
e4d2775e 95{
215d5755 96/// Standard constructor
e4d2775e 97
37ec2d4a 98 // Load mapping
331a617a 99 if ( ! AliMpCDB::LoadDDLStore() ) {
37ec2d4a 100 AliFatal("Could not access mapping from OCDB !");
101 }
37ec2d4a 102
103 fDDLStore = AliMpDDLStore::Instance();
104
105
215d5755 106 fTrashList.SetOwner(kFALSE);
107
108 // Create canvas widget
109
110 Int_t width = Int_t(w*0.99);
111 Int_t height = Int_t(h*0.99);
112
113 fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain, width, height);
114 fEcanvas->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
115 "AliMpDEVisu",
116 this,
117 "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
118
119 // Create a horizontal frame widget with buttons
120 TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,width,height/6);
121
122 TGTextButton *draw = new TGTextButton(hframe,"&Draw");
123 draw->Connect("Clicked()","AliMpDEVisu",this,"DrawDE()");
124 hframe->AddFrame(draw, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
125
126 TGTextButton *exit = new TGTextButton(hframe,"&Exit","gApplication->Terminate(0)");
127 hframe->AddFrame(exit, new TGLayoutHints(kLHintsLeft| kLHintsCenterY,5,5,3,4));
128
129
130 Int_t i = 0;
131 Char_t text[20];
132
133 // chamber label
134 TGLabel* chamberLabel = new TGLabel(hframe, "Chamber :");
135 hframe->AddFrame(chamberLabel, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 20, 0));
136 fChamberCombo = new TGComboBox(hframe, kChamberCombo);
137
138 fDEComboIdx.Set(26);
139 for(i = 0; i < 10; i++)
140 {
141 sprintf(text,"%d",i+1);
142 fChamberCombo->AddEntry(text,i);
143 }
144 fChamberCombo->Resize(40,20);
145 fChamberCombo->Select(0);
146 fChamberCombo->Associate(this);
147 hframe->AddFrame(fChamberCombo, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
148
149 // DE label
150 TGLabel* detElemLabel = new TGLabel(hframe, "DE :");
151 hframe->AddFrame(detElemLabel, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 20, 0));
152 fDECombo = new TGComboBox(hframe, kDECombo);
153 UpdateComboDE();
154
155 fDECombo->Resize(80,20);
156 fDECombo->Select(0);
157 fDECombo->Associate(this);
158 hframe->AddFrame(fDECombo, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
d58f6c58 159 fDEOccurrence.Reset(-1);
160
215d5755 161 TGTextButton *next = new TGTextButton(hframe,"&Next");
162 next->Connect("Clicked()","AliMpDEVisu",this,"NextDE()");
163 hframe->AddFrame(next, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,5,5,3,4));
164
165 // DE name
166 TGLabel* detElemName = new TGLabel(hframe, "Name :");
167 hframe->AddFrame(detElemName, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 20, 0));
168
169 AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
170 fCurrentDEName = detElem->GetDEName();
d58f6c58 171 fNameDECombo = new TGComboBox(hframe, kDEName);
172
09840862 173 UpdateNameView(kTRUE);
d58f6c58 174 fNameDECombo->Resize(160, 20);
175 fNameDECombo->Select(0);
176 fNameDECombo->Associate(this);
177 hframe->AddFrame(fNameDECombo, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
215d5755 178
179 // plane type
180 fPlaneButton = new TGCheckButton(hframe, "NB Plane", kPlaneType);
181 fPlaneButton->SetState(kButtonUp);
182 fPlaneButton->Associate(this);
183 hframe->AddFrame(fPlaneButton, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
184
185
186 // button motif
187 TGTextButton* drawManu = new TGTextButton(hframe,"&Search");
188 drawManu->Connect("Clicked()","AliMpDEVisu",this,"DrawManuMotif(Bool_t)");
189 drawManu->SetToolTipText("Search for a given manu number");
190 hframe->AddFrame(drawManu, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
191
192 // entry manu
193 fNumberEntry = new TGNumberEntry(hframe, 0, 4, -1,
194 TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
195 TGNumberFormat::kNELLimitMinMax, 1, 1500);
196 fNumberEntry->Resize(60,20);
197 hframe->AddFrame(fNumberEntry, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 0, 9, 0));
198
199 // reset button
200 TGTextButton *resetManu = new TGTextButton(hframe,"&Reset");
201 resetManu->Connect("Clicked()","AliMpDEVisu",this,"ResetManu()");
202 hframe->AddFrame(resetManu, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,10,5,3,4));
203
204 // delete window button
205 TGTextButton* deletePopup = new TGTextButton(hframe,"&Delete_Popup");
206 deletePopup->Connect("Clicked()","AliMpDEVisu",this,"DeletePopUp()");
207 deletePopup->SetToolTipText("Delete motif popup window");
208 hframe->AddFrame(deletePopup, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
209
210
211 // log mesg
212 TGHorizontalFrame *logFrame = new TGHorizontalFrame(fMain, width/2, height/6);
213
214 TGLabel* logName = new TGLabel(logFrame, "Log MSG:");
215 logFrame->AddFrame(logName, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 2, 0));
216
217 fLogMessage = new TGTextView(logFrame, width/2, 60);
218 fLogMessage->ShowBottom();
219
220 logFrame->AddFrame(fLogMessage, new TGLayoutHints(kLHintsLeft, 10, 0, 2, 0));
221
222 // clear log mesg
e4d2775e 223 TGTextButton* clearLog = new TGTextButton(logFrame,"&Clear");
215d5755 224 clearLog->Connect("Clicked()","AliMpDEVisu",this,"ClearLogMessage()");
225 clearLog->SetToolTipText("Clear log message");
226 logFrame->AddFrame(clearLog, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
227
228 // save log mesg
229 TGTextButton* saveLog = new TGTextButton(logFrame,"&Save");
230 saveLog->Connect("Clicked()","AliMpDEVisu",this,"SaveLogMessage()");
231 saveLog->SetToolTipText("Save log message into file");
232 logFrame->AddFrame(saveLog, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,5,5,3,4));
233
234 // log file name
235 fLogFile = new TGTextEntry(logFrame,"AliMpDEVisu.log");
236 fLogFile->SetToolTipText("Default log file name");
237 logFrame->AddFrame(fLogFile, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 0, 9, 0));
238
239 // zoom mode
240 fZoomButton = new TGCheckButton(logFrame, new TGHotString("&Zoom Mode"), kZoomMode);
241 fZoomButton->Associate(this);
242 fZoomButton->SetState(kButtonUp);
e4d2775e 243
215d5755 244 logFrame->AddFrame(fZoomButton, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 20, 0, 9, 0));
245
246 // frame
247 fMain->AddFrame(hframe, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,2,2,10,10));
248 fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsCenterX, 10,10,10,10));
249
250 fMain->AddFrame(logFrame, new TGLayoutHints(kLHintsLeft,2,2,2,10));
251
252 // Set a name to the main frame
253 fMain->SetWindowName("MUON Detection Element Visualization");
254
255 // Map all subwindows of main frame
256 fMain->MapSubwindows();
257
258 // Initialize the layout algorithm
259 fMain->Resize(fMain->GetDefaultSize());
260
261 // Map main frame
262 fMain->MapWindow();
263
264 // instance segmentation
265 fSegmentation = AliMpSegmentation::Instance()->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
266 fLogMessage->AddLine("Segmentation loaded");
267 fLogMessage->ShowBottom();
e4d2775e 268}
269
270//____________________________________________________________
271AliMpDEVisu::~AliMpDEVisu()
272{
215d5755 273 /// Clean up used widgets: frames, buttons, layouthints
274
275 fChamberCombo->Delete();
276 fDECombo->Delete();
277 fNumberEntry->Delete();
278 fPlaneButton->Delete();
d58f6c58 279 fNameDECombo->Delete();
215d5755 280 fLogMessage->Delete();
281 fLogFile->Delete();
282 fMain->Cleanup();
283 delete fMain;
e4d2775e 284}
285
286//__________________________________________________________
287void AliMpDEVisu::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject* /*select*/)
288{
215d5755 289 /// handle cursor mouvement
290
291 static Int_t eventXold, eventYold;
292 static Int_t eventX0, eventY0;
293 static Int_t linedrawn;
294
e4d2775e 295
215d5755 296 // enable again KeyAutoRepeat after HandleKey
297 if (eventType == kKeyPress) {
298 gVirtualX->SetKeyAutoRepeat(kTRUE);
299 }
e4d2775e 300
215d5755 301 fEcanvas->GetCanvas()->cd();
e4d2775e 302
215d5755 303 // zoom mode
304 if (fZoomMode) {
305
306 if (eventType == kButton1Down) {
307 gVirtualX->SetLineWidth(3);
308 eventX0 = eventX; eventY0 = eventY;
309 eventXold = eventX; eventYold = eventY;
310 linedrawn = 0;
311 }
312
313 if (eventType == kButton1Motion) {
314 if (linedrawn) gVirtualX->DrawBox(eventX0, eventY0, eventXold, eventYold, TVirtualX::kHollow);
315 eventXold = eventX;
316 eventYold = eventY;
317 linedrawn = 1;
318 gVirtualX->DrawBox(eventX0, eventY0, eventXold, eventYold, TVirtualX::kHollow);
319 }
320
321 if (eventType == kButton1Up)
322 {
323 if ( (eventX0 - eventX) && (eventY0 - eventY) )
324 {
325 PopUpZoom(eventX0,eventY0,eventX,eventY);
326 linedrawn=1;
327 }
328 }
329
330
331 } else {
332
333 // click mode
334
335 if (eventType == kButton1Down) {
336
337 // calculated in pixel
e4d2775e 338 Double_t x = 0.;
339 Double_t y = 0.;
215d5755 340
341 EventToReal(eventX,eventY,x,y);
342
343 // get manu
344 AliMpPad pad = fSegmentation->PadByPosition(TVector2(x,y), false);
345
e4d2775e 346 if (!pad.IsValid()) {
215d5755 347
348 fLogMessage->AddLine(Form("PopupManuMotif: No manu for DE: %d at position (%5.2f, %5.2f)",
349 fCurrentDetElem, x, y));
350 fLogMessage->ShowBottom();
351 return;
e4d2775e 352 }
215d5755 353
e4d2775e 354 Int_t manu = pad.GetLocation().GetFirst();
215d5755 355
e4d2775e 356 fNumberEntry->SetNumber(manu);
215d5755 357
358
359 fLogMessage->AddLine(Form("PopupManuMotif: DE: %d, manu: %d at position: %5.2f, %5.2f",
360 fCurrentDetElem, manu, x, y));
e4d2775e 361 fLogMessage->ShowBottom();
215d5755 362
e4d2775e 363 DrawManuMotif(true);
215d5755 364
e4d2775e 365 }
215d5755 366 }
e4d2775e 367}
368
369//__________________________________________________________
215d5755 370void AliMpDEVisu::DrawDE(Bool_t info)
e4d2775e 371{
215d5755 372 /// Draws function graphics in randomly choosen interval
373
374 if (info)
e4d2775e 375 InfoDE();
215d5755 376
377 fEcanvas->GetCanvas()->cd();
378 fEcanvas->GetCanvas()->SetEditable(kTRUE);
379
09840862 380 fNameDECombo->Select(fDEOccurrence[fCurrentDetElem]);
381 TGLBEntry* entry = fNameDECombo->GetSelectedEntry();
382 entry->SetBackgroundColor(0xDDDDDD);
383
215d5755 384 if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 ) {
e4d2775e 385
215d5755 386 DrawSlat("PMCI");
387
388 } else {
389
390 DrawQuadrant("RSMCI");
391
392 }
393 DeletePopUp();
394 fEcanvas->GetCanvas()->SetEditable(kFALSE);
395
e4d2775e 396}
397
398//__________________________________________________________
399void AliMpDEVisu::DrawManuMotif(Bool_t popup)
400{
71a2d3aa 401 /// Draw manu motif in yellow and popup channel motif window
e4d2775e 402
215d5755 403 fEcanvas->GetCanvas()->SetEditable(kTRUE);
404
405 if (!fNumberEntry->GetIntNumber()) return;
406
407 Char_t command[255];
408
409 if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 ) {
410
411 sprintf(command, "%s%d", "PMCI:", (Int_t)fNumberEntry->GetIntNumber());
412
413 DrawSlat(command, popup);
414
415 } else {
416
417 sprintf(command, "%s%d", "RSMCI:", (Int_t)fNumberEntry->GetIntNumber());
418
419 DrawQuadrant(command, popup);
420
421 }
422
423 fEcanvas->GetCanvas()->SetEditable(kFALSE);
e4d2775e 424}
425
426//__________________________________________________________
427void AliMpDEVisu::DrawSlat(Option_t* option, Bool_t popup)
428{
215d5755 429 /// draw slat segmentation
430
431 TCanvas *canvas = fEcanvas->GetCanvas();
432 canvas->Clear();
433
434 AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
435 TString nameType = detElem->GetSegType();
436
437 AliMpSlatMotifMap mm;
438 AliMpSt345Reader reader(mm);
439 AliMpSlat* slatCurrent = reader.ReadSlat(nameType.Data(), fCurrentPlane);
440 AliMpSlat* slatOther = reader.ReadSlat(nameType.Data(), AliMp::OtherPlaneType(fCurrentPlane));
441
442 AliMpVPainter* painter = AliMpVPainter::CreatePainter(slatCurrent);
443 painter->Draw(option);
444
445 canvas->Update();
446
447 Int_t numberOfManu =
448 slatCurrent->GetNofElectronicCards() +
449 slatOther->GetNofElectronicCards();
450
451 fLogMessage->AddLine(Form("DrawSlat: number of manus: %d", numberOfManu));
452 fLogMessage->ShowBottom();
453
454 if (popup)
455 PopUpManuMotif(slatCurrent);
e4d2775e 456
e4d2775e 457}
458
459//__________________________________________________________
215d5755 460void AliMpDEVisu::DrawQuadrant(Option_t* option, Bool_t popup)
e4d2775e 461{
215d5755 462 /// draw quadrant segmentation
463
464 TCanvas *canvas = fEcanvas->GetCanvas();
465 canvas->Clear();
466
467 AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
468 AliMp::StationType station = detElem->GetStationType();
e4d2775e 469
215d5755 470 AliMpSectorReader readerCurrent(station, fCurrentPlane);
471 AliMpSector* sectorCurrent = readerCurrent.BuildSector();
472
473 AliMpSectorReader readerOther(station, AliMp::OtherPlaneType(fCurrentPlane));
474 AliMpSector* sectorOther = readerOther.BuildSector();
475
476 AliMpVPainter *painter = AliMpVPainter::CreatePainter(sectorCurrent);
477 painter->Draw(option);
478
479 canvas->Update();
480
481 Int_t numberOfManu =
e4d2775e 482 sectorCurrent->GetMotifMap()->GetNofMotifPositions() +
483 sectorOther->GetMotifMap()->GetNofMotifPositions();
e4d2775e 484
215d5755 485 fLogMessage->AddLine(Form("DrawQuadrant: number of manus: %d", numberOfManu));
486 fLogMessage->ShowBottom();
487
488 if (popup)
489 PopUpManuMotif(sectorCurrent);
490
491}
492
493//______________________________________________________________________________
494void
495AliMpDEVisu::EventToReal(Int_t eventX, Int_t eventY, Double_t& x, Double_t& y) const
496{
497 /// estimate graphic pad sizes
e4d2775e 498
215d5755 499 static TVector2 ul(gPad->XtoPixel(0.01), gPad->YtoPixel(0.99));
500 static TVector2 br(gPad->XtoPixel(0.99), gPad->YtoPixel(0.01));
e4d2775e 501
215d5755 502 static TVector2 padDim = br - ul;
503
504 // get DE dimension (half size)
505 TVector2 deDim(fSegmentation->Dimensions()*2.0);
506
507 TVector2 padReal;
508
509 if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 )
510 {
511 // origin at center
512 x = (eventX - ul.X() - padDim.X()/2.)/(padDim.X())*deDim.X();
513 y = (br.Y() - eventY - padDim.Y()/2.)/(padDim.Y())*deDim.Y();
514
515 }
516 else
517 {
518 // origin at bottom left
519 x = (eventX - ul.X())/(padDim.X())*deDim.X();
520 y = (br.Y() - eventY)/(padDim.Y())*deDim.Y();
521 }
522
e4d2775e 523}
524
525//__________________________________________________________
526void AliMpDEVisu::ResetManu()
527{
215d5755 528 /// reset manu search entry
529 fLogMessage->AddLine("Reset Motif Search Entry:");
530 fLogMessage->ShowBottom();
531 fNumberEntry->SetNumber(0);
532
e4d2775e 533}
534
535//__________________________________________________________
536void AliMpDEVisu::DeletePopUp()
537{
538/// delete motif popup windows
215d5755 539
540 if (fTrashList.GetEntries() > 0)
541 {
542 fLogMessage->AddLine("Delete Motif PopUp Windows:");
543 fLogMessage->ShowBottom();
544
545 fTrashList.Delete();
546 }
e4d2775e 547}
548
549//__________________________________________________________
550void AliMpDEVisu::SaveLogMessage()
551{
215d5755 552 /// save log message into log file
553
554 TString logFile = fLogFile->GetDisplayText();
555 fLogMessage->GetText()->Save(logFile.Data());
e4d2775e 556
215d5755 557 fLogMessage->AddLine(Form("SaveLogMessage: saving log message into logfile: %s", logFile.Data()));
558 fLogMessage->ShowBottom();
e4d2775e 559}
560
561//__________________________________________________________
562void AliMpDEVisu::ClearLogMessage()
563{
215d5755 564 /// clear log message
565 fLogMessage->GetText()->Clear();
566 fLogMessage->AddLine("ClearLogMessage: clear log messages:");
567 fLogMessage->ShowBottom();
e4d2775e 568}
569
570//__________________________________________________________
571void AliMpDEVisu::InfoDE()
572{
215d5755 573 /// info concerning the whole DE
574
575 AliMpDetElement* detElem = fDDLStore->GetDetElement(fCurrentDetElem);
576 Int_t ddlId = detElem->GetDdlId();
577 Int_t numberOfBus = detElem->GetNofBusPatches();
578
579 Int_t vec[24];
580 for (Int_t i = 0; i < detElem->GetNofBusPatches(); ++i)
581 vec[i] = detElem->GetBusPatchId(i);
e4d2775e 582
215d5755 583 Int_t firstBus = TMath::MinElement(detElem->GetNofBusPatches(), vec);
584 Int_t lastBus = TMath::MaxElement(detElem->GetNofBusPatches(), vec);
585
586 detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
2ede3cc8 587 Int_t numberOfSerialManu = detElem->NofManusWithSerialNumber(); // number of manu with an identified serial number
215d5755 588
589 fLogMessage->AddLine(Form("DrawDE: detection element: %d, name: %s",
590 fCurrentDetElem, fCurrentDEName.Data()));
591 fLogMessage->ShowBottom();
592
593 fLogMessage->AddLine(Form("DrawDE: DDL: %d, number of buspatches %d from %d to %d",
594 ddlId, numberOfBus, firstBus, lastBus));
595 fLogMessage->ShowBottom();
596
597 if (numberOfSerialManu != 0) { // not available yet for all DE
598 fLogMessage->AddLine(Form("DrawDE: number of manus with serial number: %d", numberOfSerialManu));
e4d2775e 599 fLogMessage->ShowBottom();
215d5755 600 }
601
e4d2775e 602}
603
604//__________________________________________________________
605Bool_t AliMpDEVisu::ProcessMessage(Long_t msg, Long_t parm1, Long_t /*parm2*/)
606{
215d5755 607 /// process message from widgets actions/entries
e4d2775e 608
215d5755 609 AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
610
611 switch(GET_MSG(msg))
612 {
e4d2775e 613 case kC_COMMAND:
614 switch (GET_SUBMSG(msg))
615 {
215d5755 616 case kCM_COMBOBOX:
617
618 switch (parm1)
619 {
620 case kChamberCombo:
621 UpdateComboDE();
09840862 622 UpdateNameView(kTRUE);
215d5755 623 break;
624
625 case kDECombo:
626 UpdateNameView();
627 break;
d58f6c58 628
629 case kDEName:
630 UpdateComboCH();
631 break;
215d5755 632 }
633 break;
634
635 case kCM_CHECKBUTTON:
636 switch (parm1)
637 {
638 case kPlaneType:
639 if (fPlaneButton->GetState() == kButtonDown) {
640 fCurrentPlane = AliMp::kNonBendingPlane;
641 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() <= 1024)
642 fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() + 1024);
643 } else {
644 fCurrentPlane = AliMp::kBendingPlane;
645 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() > 1024)
646 fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() - 1024);
647 }
648 DrawDE();
649 fSegmentation = AliMpSegmentation::Instance()
650 ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
651 break;
652
653 case kZoomMode:
654 if (fZoomButton->GetState() == kButtonDown)
655 fZoomMode = true;
656 else
657 fZoomMode = false;
658 break;
659 }
660 break;
661
e4d2775e 662 }
663 break;
215d5755 664 }
665 return true;
e4d2775e 666}
667
97c15de5 668//__________________________________________________________
669void AliMpDEVisu::NextDE()
670{
215d5755 671 /// select next DE
672
673 Int_t next = fDECombo->GetSelected() + 1;
674
675 if (next < fDECombo->GetNumberOfEntries())
676 fDECombo->Select(next);
677 else
678 fDECombo->Select(0);
679
680 UpdateNameView();
681 DrawDE();
97c15de5 682}
683
d58f6c58 684//__________________________________________________________
685void AliMpDEVisu::UpdateComboCH()
686{
687 /// update Chamber/DE in respect to DE Name
688
689 fCurrentDEName = fNameDEComboIdx[fNameDECombo->GetSelected()];
690
691 AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDEName);
692
09840862 693 Int_t idx = AliMpDEManager::GetChamberId(detElem->GetId());
694 fChamberCombo->Select(idx);
d58f6c58 695
696 UpdateComboDE();
697
09840862 698 idx = detElem->GetId() % 100;
699 fDECombo->Select(idx);
d58f6c58 700
701 fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
702
703 fSegmentation = AliMpSegmentation::Instance()
704 ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
705}
706
e4d2775e 707//__________________________________________________________
708void AliMpDEVisu::UpdateComboDE()
709{
215d5755 710 /// update DE in respect to selected chamber
711
712 fDECombo->RemoveAll();
713
714 AliMpDEIterator it;
715 Int_t i = 0;
716 fDEComboIdx.Reset();
215d5755 717
718 for ( it.First(fChamberCombo->GetSelected()); ! it.IsDone(); it.Next() ) {
d58f6c58 719 fDECombo->AddEntry(Form("%d",it.CurrentDE()->GetId()), i);
215d5755 720 fDEComboIdx[i++] = it.CurrentDE()->GetId();
721 }
722 fDECombo->Select(0);
e4d2775e 723}
724
725//__________________________________________________________
09840862 726void AliMpDEVisu::UpdateNameView(Bool_t firstTime)
e4d2775e 727{
215d5755 728 /// update DE name in respect to selected DE id.
d58f6c58 729
215d5755 730 fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
d58f6c58 731
215d5755 732 AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
d58f6c58 733
215d5755 734 fCurrentDEName = detElem->GetDEName();
e4d2775e 735
09840862 736 if (firstTime) {
737 AliMpDEIterator it;
738
739 fNameDECombo->RemoveAll();
740
741 for ( it.First(fChamberCombo->GetSelected()); !it.IsDone(); it.Next() ) {
742
743 Int_t detElemId = it.CurrentDE()->GetId();
744 TString deName = it.CurrentDE()->GetDEName();
745
746 Int_t idx = fNameDECombo->GetNumberOfEntries();
747 fNameDECombo->AddEntry(deName.Data(), idx);
748 fNameDEComboIdx[idx] = deName;
749 fDEOccurrence[detElemId] = idx;
750 }
d58f6c58 751 }
752
753 fNameDECombo->Select(fDEOccurrence[fCurrentDetElem]);
215d5755 754 fSegmentation = AliMpSegmentation::Instance()
755 ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
756}
e4d2775e 757
215d5755 758//______________________________________________________________________________
759void
760AliMpDEVisu::CreatePopupWindow(Int_t w, Int_t h, const char* windowName,
761 AliMpVPainter* painter,
762 const char* option)
763{
71a2d3aa 764 /// Create transient frame
215d5755 765
766 TCanvas* c = new TCanvas(windowName,windowName,-200,100,w,h);
e4d2775e 767
215d5755 768 Int_t n = fTrashList.GetEntries();
769
770 c->Connect("Closed()","AliMpDEVisu",this,Form("ClosePopupWindow(=%d)",n));
771
772 fTrashList.AddLast(c);
773
774 c->Draw();
775
776 painter->Draw(option);
777
778 c->Update();
e4d2775e 779}
780
781//__________________________________________________________
782void AliMpDEVisu::PopUpManuMotif(AliMpSlat* slat)
783{
215d5755 784 /// pop up manu window motif painter for slat
785
786 // motif painter
787 AliMpMotifPosition* motifPosFound = 0x0;
788 AliMpMotifPosition* motifPos = 0x0;
789 Int_t manuId = 0;
e4d2775e 790
215d5755 791 for ( AliMpSlat::Size_t i = 0; i < slat->GetSize(); ++i ) {
792
e4d2775e 793 AliMpPCB* pcb = slat->GetPCB(i);
215d5755 794
e4d2775e 795 for ( AliMpPCB::Size_t j = 0; j < slat->GetPCB(i)->GetSize(); ++j ) {
796
97c15de5 797 motifPos = pcb->GetMotifPosition(j);
e4d2775e 798
215d5755 799 manuId = motifPos->GetID();
e4d2775e 800 if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
215d5755 801 motifPosFound = motifPos;
802 break;
e4d2775e 803 }
804 }
805 if (motifPosFound)
215d5755 806 break;
e4d2775e 807 }
97c15de5 808
215d5755 809 if(motifPosFound)
810 {
811 InfoManuMotif(motifPosFound);
97c15de5 812
215d5755 813 TVector2 dimension(motifPosFound->Dimensions());
97c15de5 814
215d5755 815 Int_t h = 500;
816 Int_t w = Int_t(h*dimension.X()/dimension.Y());
817 AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
818
819 CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
820 painter,"ZT");
821 }
e4d2775e 822}
215d5755 823
e4d2775e 824//__________________________________________________________
825void AliMpDEVisu::PopUpManuMotif(AliMpSector* sector)
826{
215d5755 827 /// pop up manu window motif painter for sector
828
829 // motif painter
830 AliMpMotifPosition* motifPosFound = 0x0;
831 AliMpMotifPosition* motifPos = 0x0;
832 Int_t manuId = 0;
97c15de5 833
215d5755 834 for (Int_t iRow = 0; iRow < sector->GetNofRows(); ++iRow) {
835
836 AliMpRow* row = sector->GetRow(iRow);
837
838 for (Int_t iRowSeg = 0; iRowSeg < sector->GetRow(iRow)->GetNofRowSegments(); ++iRowSeg){
839
840 for (Int_t iRowSeg = 0; iRowSeg < row->GetNofRowSegments(); ++iRowSeg) {
841 AliMpVRowSegment *rowSegment = row->GetRowSegment(iRowSeg);
842
843 for (Int_t iMotif = 0; iMotif < rowSegment->GetNofMotifs(); ++iMotif){
844
845 Int_t motifPositionId = rowSegment->GetMotifPositionId(iMotif);
846 motifPos = rowSegment->GetRow()
847 ->GetMotifMap()->FindMotifPosition(motifPositionId);
848
849 manuId = motifPos->GetID();
850 if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
851 motifPosFound = motifPos;
852 break;
853 }
854 }
855 if (motifPosFound)
856 break;
857 }
858 }
859 if (motifPosFound)
860 break;
861 }
862
863 if(motifPosFound)
864 {
e4d2775e 865
215d5755 866 InfoManuMotif(motifPosFound);
e4d2775e 867
215d5755 868 TVector2 dimension(motifPosFound->Dimensions());
e4d2775e 869
215d5755 870 // Create transient frame
871 Int_t h = 400;
872 Int_t w = Int_t(h*dimension.X()/dimension.Y());
e4d2775e 873
215d5755 874 AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
875
876 CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
877 painter,"ZT");
878
879 }
880}
e4d2775e 881
215d5755 882//__________________________________________________________
883void AliMpDEVisu::InfoManuMotif(AliMpMotifPosition* motifPos)
884{
885/// info for popup manu motif
e4d2775e 886
215d5755 887 // log message
888 Int_t manuId = fNumberEntry->GetIntNumber();
889 TVector2 dimension(motifPos->Dimensions());
890 fLogMessage->AddLine(Form("PopupManuMotif: motif dimension: %5.2f, %5.2f",
891 dimension.X()*2., dimension.Y()*2.));
892
893 fLogMessage->AddLine( Form("PopupManuMotif: pad dimension: %4.2f, %4.2f",
894 motifPos->GetMotif()->GetPadDimensions(0).X()*2.,
895 motifPos->GetMotif()->GetPadDimensions(0).Y()*2. ));
e4d2775e 896
215d5755 897 fLogMessage->AddLine( Form("PopupManuMotif: manu: %d, serial number: %d, buspatch: %d",
898 manuId,
899 fDDLStore->GetDetElement(fCurrentDetElem)->GetManuSerialFromId(manuId),
900 fDDLStore->GetBusPatchId(fCurrentDetElem, manuId)) );
97c15de5 901
215d5755 902 fLogMessage->ShowBottom();
e4d2775e 903
215d5755 904}
e4d2775e 905
215d5755 906//______________________________________________________________________________
907void AliMpDEVisu::PopUpZoom(Int_t ix0, Int_t iy0, Int_t ix1, Int_t iy1)
908{
909 /// popup zoom window
e4d2775e 910
215d5755 911 Double_t x0,y0;
912 EventToReal(ix0,iy0,x0,y0);
913 Double_t x1,y1;
914 EventToReal(ix1,iy1,x1,y1);
e4d2775e 915
215d5755 916 fLogMessage->AddLine(Form("PopUpZoom: zoom positions (x0, y0: %6.2f, %6.2f), (x1, y1: %6.2f, %6.2f)",
917 x0, y0, x1, y1));
918 fLogMessage->ShowBottom();
919
920 // Create transient frame
921 Int_t h = 500;//TMath::Abs(x1-x0);
922 Int_t w = 500;//TMath::Abs(y1-y0);
e4d2775e 923
215d5755 924 AliMpArea area(TVector2((x0+x1)/2.0,(y0+y1)/2.0),
925 TVector2(TMath::Abs(x1-x0)/2.0,TMath::Abs(y1-y0)/2.0));
926// area.Print();
927
928 if ( area.IsValid() )
929 {
930 AliMpVPadIterator* iterator = fSegmentation->CreateIterator(area);
931 if (iterator)
932 {
933 AliMpVPainter* painter = AliMpVPainter::CreatePainter(iterator);
934 CreatePopupWindow(w,h,"Zoom",painter,"");
e4d2775e 935 }
215d5755 936 else
937 {
938 AliError("could not get iterator for that area");
e4d2775e 939 }
215d5755 940
941 delete iterator;
942 }
97c15de5 943}
944
945//__________________________________________________________
215d5755 946void AliMpDEVisu::ClosePopupWindow(Int_t id)
97c15de5 947{
215d5755 948 /// close signal
949 fEcanvas->GetCanvas()->cd();
950 fTrashList.RemoveAt(id);
e4d2775e 951}