]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEVisu.cxx
Replacement of TVector2 object with two doubles
[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 <TCanvas.h>
50 #include <TGButton.h>
51 #include <TRootEmbeddedCanvas.h>
52 #include <TGLabel.h>
53 #include <TGComboBox.h>
54 #include <TGNumberEntry.h>
55 #include <TGTextView.h>
56 #include <TGTextEntry.h>
57
58 // Category: graphics
59
60 //-----------------------------------------------------------------------------
61 // Class AliMpDEVisu
62 // -----------------------
63 // GUI for drawing segmentation
64 // motif manu and associated channels
65 // date: 2007/01/26
66 // Author: Ch. Finck
67 //-----------------------------------------------------------------------------
68
69 /// \cond CLASSIMP
70 ClassImp(AliMpDEVisu)
71 /// \endcond
72
73 //_________________________________________________________________
74 AliMpDEVisu::AliMpDEVisu(UInt_t w, UInt_t h) 
75 : TGFrame(gClient->GetRoot(), w, h),
76   fkMainWindow(gClient->GetRoot()),
77   fMain(new TGMainFrame(gClient->GetRoot(), w, h)),
78   fEcanvas(0x0),
79   fChamberCombo(0x0),
80   fDECombo(0x0),
81   fNumberEntry(0x0),
82   fPlaneButton(0x0),
83   fZoomButton(0x0),
84   fNameDECombo(0x0),
85   fLogMessage(0x0),
86   fLogFile(0x0),
87   fTrashList(0x0),
88   fDEComboIdx(),
89   fNameDEComboIdx(),
90   fDEOccurrence(1026),
91   fCurrentPlane(AliMp::kBendingPlane),
92   fCurrentDetElem(100),
93   fCurrentDEName(),
94   fkSegmentation(),
95   fDDLStore(0x0),
96   fManuStore(0x0),
97   fZoomMode(false)
98 {
99 /// Standard constructor
100
101   // Load mapping
102   if ( ! AliMpCDB::LoadDDLStore() ) {
103     AliFatal("Could not access mapping from OCDB !");
104   }
105
106   if ( ! AliMpCDB::LoadManuStore() ) {
107     AliFatal("Could not access run-dependent mapping from OCDB !");
108   }
109
110   fDDLStore = AliMpDDLStore::Instance();
111   fManuStore = AliMpManuStore::Instance();
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   fkSegmentation = 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 = fkSegmentation->PadByPosition(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.GetManuId();
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   AliMpDataStreams dataStreams;
445
446   AliMpSlatMotifMap mm;
447   
448   AliMpSt345Reader reader(dataStreams,&mm);  
449   AliMpSlat* slatCurrent = reader.ReadSlat(nameType.Data(), fCurrentPlane);
450   AliMpSlat* slatOther   = reader.ReadSlat(nameType.Data(), AliMp::OtherPlaneType(fCurrentPlane));
451   
452   AliMpVPainter* painter = AliMpVPainter::CreatePainter(slatCurrent);
453   painter->Draw(option);
454   
455   canvas->Update();
456   
457   Int_t numberOfManu = 
458       slatCurrent->GetNofElectronicCards() + 
459       slatOther->GetNofElectronicCards();
460     
461   fLogMessage->AddLine(Form("DrawSlat: number of manus: %d", numberOfManu));
462   fLogMessage->ShowBottom();   
463   
464   if (popup)
465     PopUpManuMotif(slatCurrent);
466   
467 }
468
469 //__________________________________________________________
470 void AliMpDEVisu::DrawQuadrant(Option_t* option, Bool_t popup)
471 {
472   /// draw quadrant segmentation
473   
474   TCanvas *canvas = fEcanvas->GetCanvas();
475   canvas->Clear();
476   
477   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
478   AliMq::Station12Type  station = detElem->GetStation12Type();
479
480   AliMpDataStreams dataStreams;
481   
482   AliMpSectorReader readerCurrent(dataStreams, station, fCurrentPlane);
483   AliMpSector* sectorCurrent = readerCurrent.BuildSector();
484     
485   AliMpSectorReader readerOther(dataStreams, station, AliMp::OtherPlaneType(fCurrentPlane));
486   AliMpSector* sectorOther = readerOther.BuildSector();
487   
488   AliMpVPainter *painter = AliMpVPainter::CreatePainter(sectorCurrent);
489   painter->Draw(option);
490   
491   canvas->Update();
492   
493   Int_t numberOfManu =  
494       sectorCurrent->GetMotifMap()->GetNofMotifPositions() + 
495       sectorOther->GetMotifMap()->GetNofMotifPositions();
496   
497   fLogMessage->AddLine(Form("DrawQuadrant: number of manus: %d", numberOfManu));
498   fLogMessage->ShowBottom();   
499
500   if (popup) 
501     PopUpManuMotif(sectorCurrent);
502  
503 }
504
505 //______________________________________________________________________________
506 void 
507 AliMpDEVisu::EventToReal(Int_t eventX, Int_t eventY, 
508                          Double_t& x, Double_t& y) const
509 {
510   /// estimate graphic pad sizes
511
512   static Double_t ulx(gPad->XtoPixel(0.01)); 
513   static Double_t uly(gPad->YtoPixel(0.99));
514   static Double_t brx(gPad->XtoPixel(0.99));
515   static Double_t bry(gPad->YtoPixel(0.01));
516
517   static Double_t padDimX = brx - ulx;
518   static Double_t padDimY = bry - uly;
519   
520   // get DE dimension (half size)
521   Double_t deDimX(fkSegmentation->GetDimensionX()*2.0);
522   Double_t deDimY(fkSegmentation->GetDimensionY()*2.0);
523   
524   if ( AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 )
525   {
526     // origin at center
527     x = (eventX - ulx - padDimX/2.)/(padDimX)*deDimX; 
528     y = (bry - eventY - padDimY/2.)/(padDimY)*deDimY; 
529     
530   } 
531   else 
532   {
533     // origin at bottom left
534     x = (eventX - ulx)/(padDimX)*deDimX; 
535     y = (bry - eventY)/(padDimY)*deDimY; 
536   }
537   
538 }
539
540 //__________________________________________________________
541 void AliMpDEVisu::ResetManu() 
542 {
543   /// reset manu search entry 
544   fLogMessage->AddLine("Reset Motif Search Entry:");
545   fLogMessage->ShowBottom();
546   fNumberEntry->SetNumber(0);
547   
548 }
549
550 //__________________________________________________________
551 void AliMpDEVisu::DeletePopUp() 
552 {
553 /// delete motif popup windows 
554   
555   if (fTrashList.GetEntries() > 0) 
556   {
557     fLogMessage->AddLine("Delete Motif PopUp Windows:");
558     fLogMessage->ShowBottom();
559     
560     fTrashList.Delete();
561   } 
562 }
563
564 //__________________________________________________________
565 void AliMpDEVisu::SaveLogMessage() 
566 {
567   /// save log message into log file
568   
569   TString logFile = fLogFile->GetDisplayText();
570   fLogMessage->GetText()->Save(logFile.Data());
571
572   fLogMessage->AddLine(Form("SaveLogMessage: saving log message into logfile: %s", logFile.Data()));
573   fLogMessage->ShowBottom();  
574 }
575
576 //__________________________________________________________
577 void AliMpDEVisu::ClearLogMessage() 
578 {
579   /// clear log message 
580   fLogMessage->GetText()->Clear();
581   fLogMessage->AddLine("ClearLogMessage: clear log messages:");
582   fLogMessage->ShowBottom();  
583 }
584
585 //__________________________________________________________
586 void AliMpDEVisu::InfoDE() 
587 {
588   /// info concerning the whole DE
589   
590   AliMpDetElement* detElem = fDDLStore->GetDetElement(fCurrentDetElem);
591   Int_t ddlId        = detElem->GetDdlId();
592   Int_t numberOfBus  = detElem->GetNofBusPatches();
593   
594   Int_t vec[24];
595   for (Int_t i = 0; i <  detElem->GetNofBusPatches(); ++i)
596       vec[i] = detElem->GetBusPatchId(i);
597
598   Int_t firstBus     = TMath::MinElement(detElem->GetNofBusPatches(), vec);
599   Int_t lastBus      = TMath::MaxElement(detElem->GetNofBusPatches(), vec);
600   
601   Int_t numberOfSerialManu = fManuStore->NofManus(detElem->GetId()); // number of manu with an identified serial number
602   
603   fLogMessage->AddLine(Form("DrawDE: detection element: %d, name: %s", 
604                        fCurrentDetElem, fCurrentDEName.Data()));
605   fLogMessage->ShowBottom();   
606   
607   fLogMessage->AddLine(Form("DrawDE: DDL: %d, number of buspatches %d from %d to %d", 
608                             ddlId, numberOfBus, firstBus, lastBus));
609   fLogMessage->ShowBottom();
610   
611   if (numberOfSerialManu != 0) { // not available yet for all DE 
612     fLogMessage->AddLine(Form("DrawDE: number of manus with serial number: %d", numberOfSerialManu));
613     fLogMessage->ShowBottom();
614   }
615   
616 }
617
618 //__________________________________________________________
619 Bool_t AliMpDEVisu::ProcessMessage(Long_t msg, Long_t parm1, Long_t /*parm2*/)
620 {
621   /// process message from widgets actions/entries
622
623   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
624
625   switch(GET_MSG(msg)) 
626   {
627     case kC_COMMAND: 
628       switch (GET_SUBMSG(msg)) 
629       {
630         case kCM_COMBOBOX: 
631           
632           switch (parm1) 
633           {
634             case kChamberCombo: 
635               UpdateComboDE();
636               UpdateNameView(kTRUE);
637               break;
638               
639             case kDECombo:
640               UpdateNameView();
641               break; 
642              
643           case kDEName:
644               UpdateComboCH();
645               break;
646           }
647           break;
648           
649         case kCM_CHECKBUTTON:
650           switch (parm1) 
651           {
652             case kPlaneType:
653               if (fPlaneButton->GetState() == kButtonDown) {
654                 fCurrentPlane = AliMp::kNonBendingPlane;
655                 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() <= 1024)
656                   fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() + 1024);
657               } else {
658                 fCurrentPlane = AliMp::kBendingPlane;
659                 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() > 1024)
660                   fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() - 1024);
661               }
662               DrawDE();
663               fkSegmentation = AliMpSegmentation::Instance()
664                 ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
665               break;
666
667             case kZoomMode:
668                 if (fZoomButton->GetState() == kButtonDown)
669                     fZoomMode = true;
670                 else
671                     fZoomMode = false;
672               break;
673           }
674           break;
675           
676       }
677       break;
678   }
679   return true;
680 }
681
682 //__________________________________________________________
683 void AliMpDEVisu::NextDE()
684 {
685   /// select next DE
686   
687   Int_t next = fDECombo->GetSelected() + 1;
688   
689   if (next < fDECombo->GetNumberOfEntries())
690     fDECombo->Select(next);
691   else 
692     fDECombo->Select(0);
693   
694   UpdateNameView();
695   DrawDE();
696 }
697
698 //__________________________________________________________
699 void AliMpDEVisu::UpdateComboCH()
700 {
701   /// update Chamber/DE in respect to DE Name
702
703     fCurrentDEName = fNameDEComboIdx[fNameDECombo->GetSelected()];
704
705     AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDEName);
706
707     Int_t idx =  AliMpDEManager::GetChamberId(detElem->GetId());
708     fChamberCombo->Select(idx);
709
710     UpdateComboDE();
711
712     idx = detElem->GetId() % 100;
713     fDECombo->Select(idx);
714
715     fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
716
717     fkSegmentation = AliMpSegmentation::Instance()
718         ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
719 }
720
721 //__________________________________________________________
722 void AliMpDEVisu::UpdateComboDE()
723 {
724   /// update DE in respect to selected chamber
725   
726   fDECombo->RemoveAll();
727   
728   AliMpDEIterator it;
729   Int_t i = 0;
730   fDEComboIdx.Reset();
731   
732   for ( it.First(fChamberCombo->GetSelected()); ! it.IsDone(); it.Next() ) {
733     fDECombo->AddEntry(Form("%d",it.CurrentDE()->GetId()), i);
734     fDEComboIdx[i++] = it.CurrentDE()->GetId();
735   }
736   fDECombo->Select(0);
737 }
738
739 //__________________________________________________________
740 void AliMpDEVisu::UpdateNameView(Bool_t firstTime)
741 {
742   /// update DE name in respect to selected DE id.
743     
744   fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
745
746   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
747
748   fCurrentDEName = detElem->GetDEName();
749
750   if (firstTime) {
751     AliMpDEIterator it;
752  
753     fNameDECombo->RemoveAll();
754   
755     for ( it.First(fChamberCombo->GetSelected()); !it.IsDone(); it.Next() ) {
756
757       Int_t detElemId = it.CurrentDE()->GetId();
758       TString deName  = it.CurrentDE()->GetDEName();
759
760       Int_t idx = fNameDECombo->GetNumberOfEntries();
761       fNameDECombo->AddEntry(deName.Data(), idx);
762       fNameDEComboIdx[idx]   = deName;
763       fDEOccurrence[detElemId] = idx;
764     }
765   }
766
767   fNameDECombo->Select(fDEOccurrence[fCurrentDetElem]);
768   fkSegmentation = AliMpSegmentation::Instance()
769     ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
770 }
771
772 //______________________________________________________________________________
773 void
774 AliMpDEVisu::CreatePopupWindow(Int_t w, Int_t h, const char* windowName,
775                                AliMpVPainter* painter,
776                                const char* option)
777 {
778   /// Create transient frame
779   
780   TCanvas* c = new TCanvas(windowName,windowName,-200,100,w,h);
781
782   Int_t n = fTrashList.GetEntries();
783   
784   c->Connect("Closed()","AliMpDEVisu",this,Form("ClosePopupWindow(=%d)",n));
785              
786   fTrashList.AddLast(c);
787   
788   c->Draw();
789   
790   painter->Draw(option);
791   
792   c->Update();
793 }
794
795 //__________________________________________________________
796 void AliMpDEVisu::PopUpManuMotif(AliMpSlat* slat)
797 {
798   /// pop up manu window motif painter for slat
799   
800   // motif painter
801   AliMpMotifPosition* motifPosFound = 0x0;
802   AliMpMotifPosition* motifPos = 0x0;
803   Int_t manuId = 0;
804
805   for ( Int_t i = 0; i < slat->GetSize(); ++i ) {
806     
807     AliMpPCB* pcb = slat->GetPCB(i);
808     
809     for ( Int_t j = 0; j < slat->GetPCB(i)->GetSize(); ++j ) {
810       
811       motifPos = pcb->GetMotifPosition(j);
812       
813       manuId = motifPos->GetID();
814       if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
815         motifPosFound = motifPos;
816         break;
817       }
818     }
819     if (motifPosFound)
820       break;
821   }  
822
823   if(motifPosFound) 
824   {
825     InfoManuMotif(motifPosFound);
826
827     Double_t dimensionX(motifPosFound->GetDimensionX()); 
828     Double_t dimensionY(motifPosFound->GetDimensionY());
829
830     Int_t h = 500;
831     Int_t w = Int_t(h*dimensionX/dimensionY);
832     AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
833       
834     CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
835                       painter,"ZT");
836   }
837 }
838
839 //__________________________________________________________
840 void AliMpDEVisu::PopUpManuMotif(AliMpSector* sector)
841 {
842   /// pop up manu window motif painter for sector
843     
844   // motif painter
845   AliMpMotifPosition* motifPosFound = 0x0;
846   AliMpMotifPosition* motifPos = 0x0;
847   Int_t manuId = 0;
848
849   for (Int_t iRow = 0; iRow < sector->GetNofRows(); ++iRow) {
850     
851     AliMpRow* row = sector->GetRow(iRow);
852     
853     for (Int_t iRowSeg = 0; iRowSeg < sector->GetRow(iRow)->GetNofRowSegments(); ++iRowSeg){
854       
855       for (Int_t iRowSeg2 = 0; iRowSeg2 < row->GetNofRowSegments(); ++iRowSeg2) {
856         AliMpVRowSegment *rowSegment = row->GetRowSegment(iRowSeg2);
857         
858         for (Int_t iMotif = 0; iMotif < rowSegment->GetNofMotifs(); ++iMotif){
859           
860           Int_t motifPositionId = rowSegment->GetMotifPositionId(iMotif);
861           motifPos = rowSegment->GetRow()
862             ->GetMotifMap()->FindMotifPosition(motifPositionId);
863           
864           manuId = motifPos->GetID();
865           if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
866             motifPosFound = motifPos;
867             break;
868           }
869         }
870         if (motifPosFound)
871           break;
872       }
873     }
874     if (motifPosFound)
875       break;
876   }
877   
878   if(motifPosFound) 
879   {    
880
881     InfoManuMotif(motifPosFound);
882
883     Double_t dimensionX(motifPosFound->GetDimensionX()); 
884     Double_t dimensionY(motifPosFound->GetDimensionY());
885
886     // Create transient frame
887     Int_t h = 400;
888     Int_t w = Int_t(h*dimensionX/dimensionY);
889
890     AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
891     
892     CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
893                       painter,"ZT");
894     
895   }
896 }
897
898 //__________________________________________________________
899 void AliMpDEVisu::InfoManuMotif(AliMpMotifPosition* motifPos)
900 {
901 /// info for popup manu motif
902
903    // log message
904     Int_t manuId = fNumberEntry->GetIntNumber();
905
906     fLogMessage->AddLine(Form("PopupManuMotif: motif dimension: %5.2f, %5.2f", 
907                               motifPos->GetDimensionX()*2., 
908                               motifPos->GetDimensionY()*2.));
909       
910     fLogMessage->AddLine( Form("PopupManuMotif: pad dimension: %4.2f, %4.2f", 
911                                motifPos->GetMotif()->GetPadDimensionX(0)*2.,  
912                                motifPos->GetMotif()->GetPadDimensionY(0)*2. ));
913
914     fLogMessage->AddLine( Form("PopupManuMotif: manu: %d, serial number: %d, buspatch: %d",
915                              manuId, 
916                              fManuStore->GetManuSerial(fCurrentDetElem, manuId),
917                              fDDLStore->GetBusPatchId(fCurrentDetElem, manuId)) );
918
919     fLogMessage->ShowBottom();
920
921 }
922
923 //______________________________________________________________________________
924 void AliMpDEVisu::PopUpZoom(Int_t ix0, Int_t iy0, Int_t ix1, Int_t iy1)
925 {
926   /// popup zoom window
927
928   Double_t x0,y0;
929   EventToReal(ix0,iy0,x0,y0);
930   Double_t x1,y1;
931   EventToReal(ix1,iy1,x1,y1);
932
933   fLogMessage->AddLine(Form("PopUpZoom: zoom positions (x0, y0: %6.2f, %6.2f), (x1, y1: %6.2f, %6.2f)",
934                              x0, y0, x1, y1));
935   fLogMessage->ShowBottom();
936   
937   // Create transient frame
938   Int_t h = 500;//TMath::Abs(x1-x0);
939   Int_t w = 500;//TMath::Abs(y1-y0);
940
941   AliMpArea area((x0+x1)/2.0,(y0+y1)/2.0,
942                  TMath::Abs(x1-x0)/2.0,TMath::Abs(y1-y0)/2.0);
943 //  area.Print();
944   
945   if ( area.IsValid() )
946   {
947     AliMpVPadIterator* iterator = fkSegmentation->CreateIterator(area);
948     if (iterator)
949     {
950       AliMpVPainter* painter = AliMpVPainter::CreatePainter(iterator);
951       CreatePopupWindow(w,h,"Zoom",painter,"");
952     }
953     else
954     {
955       AliError("could not get iterator for that area");
956     }
957         
958     delete iterator;
959   }
960 }
961
962 //__________________________________________________________
963 void AliMpDEVisu::ClosePopupWindow(Int_t id)
964 {
965   /// close signal
966   fEcanvas->GetCanvas()->cd();
967   fTrashList.RemoveAt(id);
968 }