]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEVisu.cxx
Coding conventions
[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 "AliMpManuStore.h"
41 #include "AliMpVPadIterator.h"
42 #include "AliMpCDB.h"
43 #include "AliMpDataStreams.h"
44
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>
58
59 // Category: graphics
60
61 //-----------------------------------------------------------------------------
62 // Class AliMpDEVisu
63 // -----------------------
64 // GUI for drawing segmentation
65 // motif manu and associated channels
66 // date: 2007/01/26
67 // Author: Ch. Finck
68 //-----------------------------------------------------------------------------
69
70 /// \cond CLASSIMP
71 ClassImp(AliMpDEVisu)
72 /// \endcond
73
74 //_________________________________________________________________
75 AliMpDEVisu::AliMpDEVisu(UInt_t w, UInt_t h) 
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),
85   fNameDECombo(0x0),
86   fLogMessage(0x0),
87   fLogFile(0x0),
88   fTrashList(0x0),
89   fDEComboIdx(),
90   fNameDEComboIdx(),
91   fDEOccurrence(1026),
92   fCurrentPlane(AliMp::kBendingPlane),
93   fCurrentDetElem(100),
94   fCurrentDEName(),
95   fkSegmentation(),
96   fDDLStore(0x0),
97   fManuStore(0x0),
98   fZoomMode(false)
99 {
100 /// Standard constructor
101
102   // Load mapping
103   if ( ! AliMpCDB::LoadDDLStore() ) {
104     AliFatal("Could not access mapping from OCDB !");
105   }
106
107   if ( ! AliMpCDB::LoadManuStore() ) {
108     AliFatal("Could not access run-dependent mapping from OCDB !");
109   }
110
111   fDDLStore = AliMpDDLStore::Instance();
112   fManuStore = AliMpManuStore::Instance();
113
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));
167   fDEOccurrence.Reset(-1);
168
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();
179   fNameDECombo = new  TGComboBox(hframe, kDEName);
180
181   UpdateNameView(kTRUE);
182   fNameDECombo->Resize(160, 20);
183   fNameDECombo->Select(0);
184   fNameDECombo->Associate(this);
185   hframe->AddFrame(fNameDECombo, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
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
231   TGTextButton* clearLog = new TGTextButton(logFrame,"&Clear");
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);
251
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
273   fkSegmentation = AliMpSegmentation::Instance()->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
274   fLogMessage->AddLine("Segmentation loaded");
275   fLogMessage->ShowBottom();
276 }
277
278 //____________________________________________________________
279 AliMpDEVisu::~AliMpDEVisu() 
280 {
281   /// Clean up used widgets: frames, buttons, layouthints
282   
283   fChamberCombo->Delete();
284   fDECombo->Delete();
285   fNumberEntry->Delete();
286   fPlaneButton->Delete();
287   fNameDECombo->Delete();
288   fLogMessage->Delete();
289   fLogFile->Delete();
290   fMain->Cleanup();
291   delete fMain;
292 }
293
294 //__________________________________________________________
295 void AliMpDEVisu::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject* /*select*/)
296 {
297   /// handle cursor mouvement
298   
299   static Int_t eventXold, eventYold;
300   static Int_t eventX0, eventY0;
301   static Int_t linedrawn;
302   
303
304   // enable again  KeyAutoRepeat after HandleKey
305   if (eventType == kKeyPress) {
306     gVirtualX->SetKeyAutoRepeat(kTRUE);
307   }
308
309   fEcanvas->GetCanvas()->cd();
310
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 
346       Double_t x = 0.;
347       Double_t y = 0.;
348       
349       EventToReal(eventX,eventY,x,y);
350       
351       // get manu
352       AliMpPad pad = fkSegmentation->PadByPosition(TVector2(x,y), false);
353       
354       if (!pad.IsValid()) {
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;
360       }
361       
362       Int_t manu = pad.GetLocation().GetFirst();
363       
364       fNumberEntry->SetNumber(manu);
365       
366      
367       fLogMessage->AddLine(Form("PopupManuMotif: DE: %d, manu: %d at position: %5.2f, %5.2f", 
368                                 fCurrentDetElem, manu, x, y));
369       fLogMessage->ShowBottom();
370       
371       DrawManuMotif(true);
372       
373     }
374   }
375 }
376
377 //__________________________________________________________
378 void AliMpDEVisu::DrawDE(Bool_t info) 
379 {
380   /// Draws function graphics in randomly choosen interval
381   
382   if (info)
383     InfoDE();
384   
385   fEcanvas->GetCanvas()->cd();
386   fEcanvas->GetCanvas()->SetEditable(kTRUE);
387   
388   fNameDECombo->Select(fDEOccurrence[fCurrentDetElem]);
389   TGLBEntry* entry = fNameDECombo->GetSelectedEntry();
390   entry->SetBackgroundColor(0xDDDDDD);
391
392   if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 ) {
393     
394     DrawSlat("PMCI");
395     
396   } else {
397     
398     DrawQuadrant("RSMCI");
399     
400   }
401   DeletePopUp();
402   fEcanvas->GetCanvas()->SetEditable(kFALSE);
403   
404 }
405
406 //__________________________________________________________
407 void AliMpDEVisu::DrawManuMotif(Bool_t popup) 
408 {
409   ///  Draw manu motif in yellow and popup channel motif window
410   
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);
432 }
433
434 //__________________________________________________________
435 void AliMpDEVisu::DrawSlat(Option_t* option, Bool_t popup) 
436 {
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();
444
445   AliMpDataStreams dataStreams;
446
447   AliMpSlatMotifMap mm;
448   
449   AliMpSt345Reader reader(dataStreams,&mm);  
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);
467   
468 }
469
470 //__________________________________________________________
471 void AliMpDEVisu::DrawQuadrant(Option_t* option, Bool_t popup)
472 {
473   /// draw quadrant segmentation
474   
475   TCanvas *canvas = fEcanvas->GetCanvas();
476   canvas->Clear();
477   
478   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
479   AliMq::Station12Type  station = detElem->GetStation12Type();
480
481   AliMpDataStreams dataStreams;
482   
483   AliMpSectorReader readerCurrent(dataStreams, station, fCurrentPlane);
484   AliMpSector* sectorCurrent = readerCurrent.BuildSector();
485     
486   AliMpSectorReader readerOther(dataStreams, station, AliMp::OtherPlaneType(fCurrentPlane));
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 =  
495       sectorCurrent->GetMotifMap()->GetNofMotifPositions() + 
496       sectorOther->GetMotifMap()->GetNofMotifPositions();
497   
498   fLogMessage->AddLine(Form("DrawQuadrant: number of manus: %d", numberOfManu));
499   fLogMessage->ShowBottom();   
500
501   if (popup) 
502     PopUpManuMotif(sectorCurrent);
503  
504 }
505
506 //______________________________________________________________________________
507 void 
508 AliMpDEVisu::EventToReal(Int_t eventX, Int_t eventY, Double_t& x, Double_t& y) const
509 {
510   /// estimate graphic pad sizes
511
512   static TVector2 ul(gPad->XtoPixel(0.01), gPad->YtoPixel(0.99));
513   static TVector2 br(gPad->XtoPixel(0.99), gPad->YtoPixel(0.01));
514
515   static TVector2 padDim = br - ul;
516   
517   // get DE dimension (half size)
518   TVector2 deDim(fkSegmentation->Dimensions()*2.0);
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   
536 }
537
538 //__________________________________________________________
539 void AliMpDEVisu::ResetManu() 
540 {
541   /// reset manu search entry 
542   fLogMessage->AddLine("Reset Motif Search Entry:");
543   fLogMessage->ShowBottom();
544   fNumberEntry->SetNumber(0);
545   
546 }
547
548 //__________________________________________________________
549 void AliMpDEVisu::DeletePopUp() 
550 {
551 /// delete motif popup windows 
552   
553   if (fTrashList.GetEntries() > 0) 
554   {
555     fLogMessage->AddLine("Delete Motif PopUp Windows:");
556     fLogMessage->ShowBottom();
557     
558     fTrashList.Delete();
559   } 
560 }
561
562 //__________________________________________________________
563 void AliMpDEVisu::SaveLogMessage() 
564 {
565   /// save log message into log file
566   
567   TString logFile = fLogFile->GetDisplayText();
568   fLogMessage->GetText()->Save(logFile.Data());
569
570   fLogMessage->AddLine(Form("SaveLogMessage: saving log message into logfile: %s", logFile.Data()));
571   fLogMessage->ShowBottom();  
572 }
573
574 //__________________________________________________________
575 void AliMpDEVisu::ClearLogMessage() 
576 {
577   /// clear log message 
578   fLogMessage->GetText()->Clear();
579   fLogMessage->AddLine("ClearLogMessage: clear log messages:");
580   fLogMessage->ShowBottom();  
581 }
582
583 //__________________________________________________________
584 void AliMpDEVisu::InfoDE() 
585 {
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);
595
596   Int_t firstBus     = TMath::MinElement(detElem->GetNofBusPatches(), vec);
597   Int_t lastBus      = TMath::MaxElement(detElem->GetNofBusPatches(), vec);
598   
599   Int_t numberOfSerialManu = fManuStore->NofManus(detElem->GetId()); // number of manu with an identified serial number
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));
611     fLogMessage->ShowBottom();
612   }
613   
614 }
615
616 //__________________________________________________________
617 Bool_t AliMpDEVisu::ProcessMessage(Long_t msg, Long_t parm1, Long_t /*parm2*/)
618 {
619   /// process message from widgets actions/entries
620
621   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
622
623   switch(GET_MSG(msg)) 
624   {
625     case kC_COMMAND: 
626       switch (GET_SUBMSG(msg)) 
627       {
628         case kCM_COMBOBOX: 
629           
630           switch (parm1) 
631           {
632             case kChamberCombo: 
633               UpdateComboDE();
634               UpdateNameView(kTRUE);
635               break;
636               
637             case kDECombo:
638               UpdateNameView();
639               break; 
640              
641           case kDEName:
642               UpdateComboCH();
643               break;
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();
661               fkSegmentation = AliMpSegmentation::Instance()
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           
674       }
675       break;
676   }
677   return true;
678 }
679
680 //__________________________________________________________
681 void AliMpDEVisu::NextDE()
682 {
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();
694 }
695
696 //__________________________________________________________
697 void 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
705     Int_t idx =  AliMpDEManager::GetChamberId(detElem->GetId());
706     fChamberCombo->Select(idx);
707
708     UpdateComboDE();
709
710     idx = detElem->GetId() % 100;
711     fDECombo->Select(idx);
712
713     fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
714
715     fkSegmentation = AliMpSegmentation::Instance()
716         ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
717 }
718
719 //__________________________________________________________
720 void AliMpDEVisu::UpdateComboDE()
721 {
722   /// update DE in respect to selected chamber
723   
724   fDECombo->RemoveAll();
725   
726   AliMpDEIterator it;
727   Int_t i = 0;
728   fDEComboIdx.Reset();
729   
730   for ( it.First(fChamberCombo->GetSelected()); ! it.IsDone(); it.Next() ) {
731     fDECombo->AddEntry(Form("%d",it.CurrentDE()->GetId()), i);
732     fDEComboIdx[i++] = it.CurrentDE()->GetId();
733   }
734   fDECombo->Select(0);
735 }
736
737 //__________________________________________________________
738 void AliMpDEVisu::UpdateNameView(Bool_t firstTime)
739 {
740   /// update DE name in respect to selected DE id.
741     
742   fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
743
744   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
745
746   fCurrentDEName = detElem->GetDEName();
747
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     }
763   }
764
765   fNameDECombo->Select(fDEOccurrence[fCurrentDetElem]);
766   fkSegmentation = AliMpSegmentation::Instance()
767     ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
768 }
769
770 //______________________________________________________________________________
771 void
772 AliMpDEVisu::CreatePopupWindow(Int_t w, Int_t h, const char* windowName,
773                                AliMpVPainter* painter,
774                                const char* option)
775 {
776   /// Create transient frame
777   
778   TCanvas* c = new TCanvas(windowName,windowName,-200,100,w,h);
779
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();
791 }
792
793 //__________________________________________________________
794 void AliMpDEVisu::PopUpManuMotif(AliMpSlat* slat)
795 {
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;
802
803   for ( Int_t i = 0; i < slat->GetSize(); ++i ) {
804     
805     AliMpPCB* pcb = slat->GetPCB(i);
806     
807     for ( Int_t j = 0; j < slat->GetPCB(i)->GetSize(); ++j ) {
808       
809       motifPos = pcb->GetMotifPosition(j);
810       
811       manuId = motifPos->GetID();
812       if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
813         motifPosFound = motifPos;
814         break;
815       }
816     }
817     if (motifPosFound)
818       break;
819   }  
820
821   if(motifPosFound) 
822   {
823     InfoManuMotif(motifPosFound);
824
825     TVector2 dimension(motifPosFound->Dimensions());
826
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   }
834 }
835
836 //__________________________________________________________
837 void AliMpDEVisu::PopUpManuMotif(AliMpSector* sector)
838 {
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;
845
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       
852       for (Int_t iRowSeg2 = 0; iRowSeg2 < row->GetNofRowSegments(); ++iRowSeg2) {
853         AliMpVRowSegment *rowSegment = row->GetRowSegment(iRowSeg2);
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   {    
877
878     InfoManuMotif(motifPosFound);
879
880     TVector2 dimension(motifPosFound->Dimensions());
881
882     // Create transient frame
883     Int_t h = 400;
884     Int_t w = Int_t(h*dimension.X()/dimension.Y());
885
886     AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
887     
888     CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
889                       painter,"ZT");
890     
891   }
892 }
893
894 //__________________________________________________________
895 void AliMpDEVisu::InfoManuMotif(AliMpMotifPosition* motifPos)
896 {
897 /// info for popup manu motif
898
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. ));
908
909     fLogMessage->AddLine( Form("PopupManuMotif: manu: %d, serial number: %d, buspatch: %d",
910                              manuId, 
911                              fManuStore->GetManuSerial(fCurrentDetElem, manuId),
912                              fDDLStore->GetBusPatchId(fCurrentDetElem, manuId)) );
913
914     fLogMessage->ShowBottom();
915
916 }
917
918 //______________________________________________________________________________
919 void AliMpDEVisu::PopUpZoom(Int_t ix0, Int_t iy0, Int_t ix1, Int_t iy1)
920 {
921   /// popup zoom window
922
923   Double_t x0,y0;
924   EventToReal(ix0,iy0,x0,y0);
925   Double_t x1,y1;
926   EventToReal(ix1,iy1,x1,y1);
927
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);
935
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   {
942     AliMpVPadIterator* iterator = fkSegmentation->CreateIterator(area);
943     if (iterator)
944     {
945       AliMpVPainter* painter = AliMpVPainter::CreatePainter(iterator);
946       CreatePopupWindow(w,h,"Zoom",painter,"");
947     }
948     else
949     {
950       AliError("could not get iterator for that area");
951     }
952         
953     delete iterator;
954   }
955 }
956
957 //__________________________________________________________
958 void AliMpDEVisu::ClosePopupWindow(Int_t id)
959 {
960   /// close signal
961   fEcanvas->GetCanvas()->cd();
962   fTrashList.RemoveAt(id);
963 }