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