]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPainterMasterFrame.cxx
fix finding of pad neighbours; remove methods to write them in OCDB
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterMasterFrame.cxx
index 63fdb74d952c23309782e3eedbc518f46410eb3f..9c62950f3be8f96b5b446fdf140bd21196c2927c 100644 (file)
 #include <TCanvas.h>
 #include <TEnv.h>
 #include <TGComboBox.h>
+#include <TGFileDialog.h>
 #include <TGLabel.h>
 #include <TObjArray.h>
 #include <TObjString.h>
 #include <TGButtonGroup.h>
 #include <TGMsgBox.h>
+#include <TSystem.h>
 
 /// \class AliMUONPainterMasterFrame
 ///
 ClassImp(AliMUONPainterMasterFrame)
 ///\endcond
 
-namespace
-{
-  UInt_t UniqueID(Int_t nx, Int_t ny)
-  {
-    return ny | (nx << 8);
-  }
-  
-  Int_t Nx(UInt_t uniqueID)
-  {
-    return ( uniqueID & 0xFF00 ) >> 8;
-  }
-
-  Int_t Ny(UInt_t uniqueID)
-  {
-    return uniqueID & 0xFF;
-  }
-
-}
-
 const Int_t AliMUONPainterMasterFrame::fgkBorderSize = 10;
 
 //_____________________________________________________________________________
 AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p, 
-                                                     UInt_t w, UInt_t h)
+                                                     UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
 : TGCompositeFrame(p,w,h,kVerticalFrame),
-  fNavigationFrame(0x0),
-  fPainterMatrixFrame(0x0),
-  fBackButton(0x0),
-  fForwardButton(0x0),
-  fGroupTitle(0x0),
-  fNavigation(),
-  fCurrentNavigationPosition(-1),
-  fAttPainterSelectorFrame(0x0)
+fNavigationFrame(0x0),
+fPainterMatrixFrame(0x0),
+fBackButton(0x0),
+fForwardButton(0x0),
+fGroupTitle(0x0),
+fPrintMeButton(0x0),
+fPrintAsButton(0x0),
+fNavigation(),
+fCurrentNavigationPosition(-1),
+fAttPainterSelectorFrame(0x0)
 {  
   /// ctor
     
@@ -92,12 +77,15 @@ AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p,
   AddFrame(fNavigationFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
                                               fgkBorderSize,fgkBorderSize,
                                               fgkBorderSize,fgkBorderSize));
-    
+  
   fBackButton = new TGPictureButton(fNavigationFrame,
-                                       gClient->GetPicture("tb_back.xpm"));
+                                    gClient->GetPicture("tb_back.xpm"));
   
   fForwardButton = new TGPictureButton(fNavigationFrame,
-                                       gClient->GetPicture("tb_forw.xpm"));
+                                       gClient->GetPicture("tb_forw.xpm"));    
+
+  fPrintMeButton = new TGTextButton(fNavigationFrame,"Print");
+  fPrintAsButton = new TGTextButton(fNavigationFrame,"Print As...");
 
   fAttPainterSelectorFrame = new AliMUONAttPainterSelectorFrame(fNavigationFrame,w/2,20);
   
@@ -107,7 +95,10 @@ AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p,
   fNavigationFrame->AddFrame(fForwardButton,new TGLayoutHints(kLHintsCenterY));
   
   fNavigationFrame->AddFrame(fAttPainterSelectorFrame,new TGLayoutHints(kLHintsCenterY,10));
-  
+
+  fNavigationFrame->AddFrame(fPrintMeButton,new TGLayoutHints(kLHintsCenterY,10));
+  fNavigationFrame->AddFrame(fPrintAsButton,new TGLayoutHints(kLHintsCenterY,10));
+
   fAttPainterSelectorFrame->Connect("Clicked(AliMUONAttPainter*)",
                                     "AliMUONPainterMasterFrame",
                                     this,
@@ -123,12 +114,19 @@ AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p,
                           this,
                           "Backward()");
     
+  fPrintMeButton->Connect("Clicked()","AliMUONPainterMasterFrame",
+                        this,
+                        "PrintMe()");
+
+  fPrintAsButton->Connect("Clicked()","AliMUONPainterMasterFrame",
+                        this,
+                        "PrintAs()");
   
-                                                                   
   UInt_t w1 = wi;
-  UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize;
+  //  UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize;
+  UInt_t h1 = hi - 7*12;
   
-  MakeTopPainterMatrix(w1,h1);
+  MakeTopPainterMatrix(w1,h1,matrix);
 
   AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX,
                                                 fgkBorderSize,fgkBorderSize,
@@ -144,7 +142,7 @@ AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p,
                                               this,
                                               "PainterMatrixWantToShow(AliMUONPainterMatrix*)");
   
-  fPainterMatrixFrame->DataSourceWasChanged("*",0x0,-1);
+  fPainterMatrixFrame->DataSourceWasChanged(matrix->DataPattern().Data(),matrix->Data(),matrix->DataIndex());
 }
 
 //_____________________________________________________________________________
@@ -160,7 +158,7 @@ AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix)
 {
   /// array is adopted (by the registry)
 
-  AliDebug(1,Form("matrix=%x %s",painterMatrix,painterMatrix->GetName()));
+  AliDebug(1,Form("matrix=%p %s",painterMatrix,painterMatrix->GetName()));
   
   Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix);
 
@@ -171,10 +169,10 @@ AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix)
 void
 AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
 {
-  // FIXME: should check whether we are the active window before
-  // responding to this message
+  /// FIXME: should check whether we are the active window before
+  /// responding to this message ?
 
-  AliDebug(1,Form("group=%x %s",group,group->GetName()));
+  AliDebug(1,Form("group=%p %s",group,group->GetName()));
   
   Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group);
 
@@ -196,7 +194,33 @@ AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
   
   ShowPainterMatrix(group);  
 }
-                                                
+     
+//_____________________________________________________________________________
+void
+AliMUONPainterMasterFrame::PrintAs() const
+{
+  /// Handle the PrintAs button
+  
+  TGFileInfo fileInfo;
+  
+  new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
+                   kFDSave,&fileInfo);
+  
+  if ( fileInfo.fFilename ) 
+  {
+    SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)),"RECREATE");
+  }
+}
+
+//_____________________________________________________________________________
+void
+AliMUONPainterMasterFrame::PrintMe() const
+{
+  /// Handle the PrintMe button
+  
+  SaveAs(gSystem->ExpandPathName(Form("%s.png",fPainterMatrixFrame->Matrix()->GetName())),"RECREATE");
+}
+
 //_____________________________________________________________________________
 void
 AliMUONPainterMasterFrame::SetNavigation(Int_t i)
@@ -283,23 +307,26 @@ void
 AliMUONPainterMasterFrame::Clicked(AliMUONVPainter* painter, Double_t* values)
 {
   /// A given painter was (singly) clicked
-  
-  AliDebug(1,Form("%s x %7.3f y %7.3f",painter->GetName(),values[0],values[1]));
 
-  AliCodeTimerAuto("")
-  
-  fPainterMatrixFrame->MouseLeave(painter);
+  if ( painter->CanBeDetached() )
+  {
+    fPainterMatrixFrame->MouseLeave(painter);
   
-  AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
+    AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
 
-  AliMUONVPainter* p = painter->Detach();
+    AliMUONVPainter* p = painter->Detach();
 
-  p->SetResponder(1);
+    p->SetResponder(1);
 
-  matrix->Adopt(p);
+    matrix->Adopt(p);
   
-  AddPainterMatrix(matrix);
-  ShowPainterMatrix(matrix);
+    AddPainterMatrix(matrix);
+    ShowPainterMatrix(matrix);
+  }
+  else
+  {
+    painter->DrawHistogram(values);
+  }
 }
 
 //_____________________________________________________________________________
@@ -308,16 +335,17 @@ AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
 {
   /// A given painter was shift-clicked
   
+  if ( !painter->CanBeDetached() ) return;
+  
   AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
   
   AliMUONAttPainter a = painter->Attributes();
   
   TString basename(Form("%s-DUAL",painter->GetName()));
   
-  TString newName = AliMUONPainterMatrix::NameIt(basename.Data(),a);
+  TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),basename.Data(),a);
   
-  AliMUONPainterMatrix* matrix = 
-    AliMUONPainterRegistry::Instance()->FindPainterMatrix(newName.Data());
+  AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
   
   if (!matrix)
   {
@@ -328,29 +356,21 @@ AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
     // create "opposite" attributes
     AliMUONAttPainter a1(a);
     AliMUONAttPainter a2(a);
-    
-    if ( a.IsCathodeDefined() ) 
-    {
-      a2.SetCathode(!a.IsCathode0(),!a.IsCathode1());
-    }
-    
-    if ( a.IsPlaneDefined() ) 
-    {
-      a2.SetPlane(!a.IsBendingPlane(),!a.IsNonBendingPlane());
-    }
+  
+    a2.Invert();
     
     a1.SetCathodeAndPlaneDisabled(kTRUE);
     a2.SetCathodeAndPlaneDisabled(kTRUE);
-
+    
     AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(),
                                                          a1,
                                                          painter->ID0(),
                                                          painter->ID1());
     
     AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(),
-                                                        a2,
-                                                        painter->ID0(),
-                                                        painter->ID1());
+                                                         a2,
+                                                         painter->ID0(),
+                                                         painter->ID1());
     
     if (!p1 || !p2)
     {
@@ -364,11 +384,6 @@ AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
       return;
     }
     
-    AliInfo(Form("Starting from %s will generate %s and %s",
-                 a.GetName(),
-                 a1.GetName(),
-                 a2.GetName()));
-    
     p1->UpdateGroupsFrom(*(painter->Master()));
     p2->UpdateGroupsFrom(*(painter->Master()));
     
@@ -379,8 +394,8 @@ AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
     Int_t ny(1);
     
     AliMpArea area(painter->Area());
-
-    if ( area.Dimensions().X() > 1.2*area.Dimensions().Y() ) 
+    
+    if ( area.GetDimensionX() > 1.2*area.GetDimensionY() ) 
     {
       nx = 1;
       ny = 2;
@@ -403,6 +418,14 @@ AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
   PainterMatrixWantToShow(matrix);
 }
 
+//_____________________________________________________________________________
+void 
+AliMUONPainterMasterFrame::SaveAs(const char* filename, Option_t* option) const
+{
+  /// Save painter matrix (in the sense of "print") in filename
+  fPainterMatrixFrame->SaveAs(filename,option);
+}
+
 //_____________________________________________________________________________
 void
 AliMUONPainterMasterFrame::Update()
@@ -410,6 +433,7 @@ AliMUONPainterMasterFrame::Update()
   /// Update ourselves
   
   fPainterMatrixFrame->Update();
+  fPainterMatrixFrame->UpdateInterface(kFALSE);
 }
 
 //_____________________________________________________________________________
@@ -423,31 +447,20 @@ AliMUONPainterMasterFrame::UpdateAttributes(const AliMUONPainterMatrix& painterM
 
 //_____________________________________________________________________________
 void
-AliMUONPainterMasterFrame::MakeTopPainterMatrix(UInt_t w, UInt_t h)
+AliMUONPainterMasterFrame::MakeTopPainterMatrix(UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
 {
   /// Create the first painter matrix that appears when we are create
   /// FIXME: how to make this more flexible ?
   
   fPainterMatrixFrame = new AliMUONPainterMatrixFrame(this,w,h);
 
-  AliMUONAttPainter att;
-  
-  att.SetCathode(kTRUE,kFALSE);
-  att.SetViewPoint(kTRUE,kFALSE);
-    
-  TString name = AliMUONPainterMatrix::NameIt("Tracker",att);
-  
-  AliMUONPainterMatrix* painterMatrix = AliMUONPainterRegistry::Instance()->FindPainterMatrix(name);
-  
-  if (!painterMatrix)
+  if (matrix)
   {
-    AliError(Form("Could not get pre-defined painter matrix %s : check that !",name.Data()));
+    PainterMatrixWantToShow(matrix);
   }
   else
   {
-    PainterMatrixWantToShow(painterMatrix);
-//    fPainterMatrixFrame->Use(painterMatrix);
-//    ShowPainterMatrix(painterMatrix);
+    AliError("Cannot work without a painterMatrix");
   }
 }
 
@@ -472,7 +485,7 @@ AliMUONPainterMasterFrame::UpdateNavigation()
 
 //_____________________________________________________________________________
 void
-AliMUONPainterMasterFrame::AttributesChanged(AliMUONAttPainter* newValues)
+AliMUONPainterMasterFrame::AttributesChanged(const AliMUONAttPainter* newValues)
 {
   /// Attributes changed (e.g. from cath0 to cath1 or bending to nonbending, etc...)
   
@@ -492,10 +505,9 @@ AliMUONPainterMasterFrame::AttributesChanged(AliMUONAttPainter* newValues)
   
   // First check if we already have this matrix available
   
-  TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Basename(),a);
+  TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),currentMatrix->Basename(),a);
   
-  AliMUONPainterMatrix* matrix = 
-    AliMUONPainterRegistry::Instance()->FindPainterMatrix(newName.Data());
+  AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
 
   if (!matrix)
   {