]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Macro to flip an existing PCB (Laurent)
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 12 Jan 2007 11:32:38 +0000 (11:32 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 12 Jan 2007 11:32:38 +0000 (11:32 +0000)
MUON/mapping/data/station345/flipPCB.C [new file with mode: 0644]
MUON/mapping/data/station345/flipPCB.h [new file with mode: 0644]

diff --git a/MUON/mapping/data/station345/flipPCB.C b/MUON/mapping/data/station345/flipPCB.C
new file mode 100644 (file)
index 0000000..17faed8
--- /dev/null
@@ -0,0 +1,130 @@
+
+#include "flipPCB.h"
+
+#include "AliMpMotif.h"
+#include "AliMpMotifType.h"
+#include "AliMpMotifPosition.h"
+#include "AliMpExMap.h"
+#include "AliMpPCB.h"
+#include "AliMpConnection.h"
+#include "AliMpSt345Reader.h"
+#include "Riostream.h"
+#include "TCanvas.h"
+#include "AliMpVPainter.h"
+#include "AliMpConnection.h"
+#include "AliMpSlatMotifMap.h"
+
+const char* NameIt(const TString& baseName)
+{
+  return Form("%sR",baseName.Data());
+}
+
+//______________________________________________________________________________
+AliMpPCB* Duplicate(const AliMpPCB& src, AliMpSlatMotifMap& motifMap)
+{
+  AliMpPCB* dest = new AliMpPCB(&motifMap,NameIt(src.GetID()),
+                                src.PadSizeX(),src.PadSizeY(),
+                                src.DX()*2,src.DY()*2);
+  
+  for ( Int_t i = 0; i < src.GetSize(); ++i )
+  {
+    AliMpMotifPosition* srcMotifPosition = src.GetMotifPosition(i);
+    AliMpMotifType* motifType = srcMotifPosition->GetMotif()->GetMotifType();
+    AliMpMotifType* mt = motifMap.FindMotifType(motifType->GetID());
+    if (!mt)
+    {
+      mt = static_cast<AliMpMotifType*>(motifType->Clone());
+      motifMap.AddMotifType(mt);
+    }
+    dest->Add(mt,
+              srcMotifPosition->GetLowIndicesLimit().GetFirst(),
+              srcMotifPosition->GetLowIndicesLimit().GetSecond());
+  }
+  return dest;
+}
+
+//______________________________________________________________________________
+AliMpConnection* getConnection(const AliMpPCB& pcb, Int_t ix, Int_t iy)
+{
+  AliMpMotifPosition* pos = pcb.FindMotifPosition(ix,iy);
+  if (pos)
+  {
+    AliMpMotifType* type = pos->GetMotif()->GetMotifType();
+    return type->FindConnectionByLocalIndices(AliMpIntPair(ix,iy)-pos->GetLowIndicesLimit());
+  }
+  return 0x0;
+}
+                                                      
+//______________________________________________________________________________
+AliMpPCB* flipX(const AliMpPCB& src,
+                AliMpSlatMotifMap& destMotifs)
+{
+  AliMpPCB* dest = Duplicate(src,destMotifs);
+
+  for ( Int_t iy = dest->Iymin(); iy <= dest->Iymax(); ++iy )
+  {
+    for ( Int_t ix = dest->Ixmin(); ix <= dest->Ixmax(); ++ix )
+    {
+      AliMpConnection* srcConnection = getConnection(src,ix,iy);
+      Int_t dix = dest->Ixmax() - ix;
+      AliMpConnection* destConnection = getConnection(*dest,dix,iy);
+      if ( srcConnection && destConnection )
+      {
+        destConnection->SetGassiNum(srcConnection->GetGassiNum());
+      }
+      else
+      {
+        if ( srcConnection && !destConnection )
+        {
+          cout << Form("Got no connection in dest for ix,iy=%d,%d src "
+                       "ix,iy=%d,%d in PCB %s",
+                       dix,iy,ix,iy,dest->GetID()) << endl;
+          dest->Print("M");
+          cout << "---------- src=" << endl;
+          src.Print("M");
+          delete dest;
+          return 0x0;
+        }
+      }
+    }
+  }
+  return dest;
+}
+
+//______________________________________________________________________________
+void flipPCB(const char* srcName)
+{
+  // flip PCB in X-direction
+
+  AliMpSlatMotifMap* srcMotifs = new AliMpSlatMotifMap;
+  AliMpSlatMotifMap* destMotifs = new AliMpSlatMotifMap;
+  
+  AliMpSt345Reader reader(*srcMotifs);
+
+  AliMpPCB* src = reader.ReadPCB(srcName);
+  
+  if (!src) return;
+
+  AliMpPCB* dest = flipX(*src,*destMotifs);
+    
+  if (!dest)
+  {
+    cout << "Flipping failed" << endl;
+  }
+  
+  TCanvas* csrc = new TCanvas("src","src");
+  csrc->Draw();
+  AliMpVPainter* psrc = AliMpVPainter::CreatePainter(src);
+  psrc->Draw("MZT");
+
+  if ( dest ) 
+  {
+    TCanvas* cdest = new TCanvas("dest","dest");
+    cdest->Draw();
+    AliMpVPainter* pdest = AliMpVPainter::CreatePainter(dest);
+    pdest->Draw("MZT");
+    dest->Save();
+
+  }
+  
+}
\ No newline at end of file
diff --git a/MUON/mapping/data/station345/flipPCB.h b/MUON/mapping/data/station345/flipPCB.h
new file mode 100644 (file)
index 0000000..849853a
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef FLIPPCB_H
+#define FLIPPCB_H
+
+class TString;
+class AliMpPCB;
+class AliMpMotifPosition;
+class AliMpMotifType;
+class AliMpSlatMotifMap;
+
+const char* NameIt(const TString& baseName);
+
+AliMpPCB* Duplicate(const AliMpPCB& src, AliMpSlatMotifMap& motifMap);
+
+void flipPCB(const char* srcName);
+
+#endif
\ No newline at end of file