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