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