]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/data/station345/flipPCB.C
Add more ALiFatal
[u/mrichter/AliRoot.git] / MUON / mapping / data / station345 / flipPCB.C
CommitLineData
cc7f2176 1
2#include "flipPCB.h"
3
4#include "AliMpMotif.h"
5#include "AliMpMotifType.h"
6#include "AliMpMotifPosition.h"
7#include "AliMpExMap.h"
8#include "AliMpPCB.h"
9#include "AliMpConnection.h"
10#include "AliMpSt345Reader.h"
11#include "Riostream.h"
12#include "TCanvas.h"
13#include "AliMpVPainter.h"
14#include "AliMpConnection.h"
15#include "AliMpSlatMotifMap.h"
16
17const char* NameIt(const TString& baseName)
18{
19 return Form("%sR",baseName.Data());
20}
21
22//______________________________________________________________________________
23AliMpPCB* Duplicate(const AliMpPCB& src, AliMpSlatMotifMap& motifMap)
24{
25 AliMpPCB* dest = new AliMpPCB(&motifMap,NameIt(src.GetID()),
26 src.PadSizeX(),src.PadSizeY(),
27 src.DX()*2,src.DY()*2);
28
29 for ( Int_t i = 0; i < src.GetSize(); ++i )
30 {
31 AliMpMotifPosition* srcMotifPosition = src.GetMotifPosition(i);
32 AliMpMotifType* motifType = srcMotifPosition->GetMotif()->GetMotifType();
33 AliMpMotifType* mt = motifMap.FindMotifType(motifType->GetID());
34 if (!mt)
35 {
36 mt = static_cast<AliMpMotifType*>(motifType->Clone());
37 motifMap.AddMotifType(mt);
38 }
39 dest->Add(mt,
40 srcMotifPosition->GetLowIndicesLimit().GetFirst(),
41 srcMotifPosition->GetLowIndicesLimit().GetSecond());
42 }
43 return dest;
44}
45
46//______________________________________________________________________________
47AliMpConnection* getConnection(const AliMpPCB& pcb, Int_t ix, Int_t iy)
48{
49 AliMpMotifPosition* pos = pcb.FindMotifPosition(ix,iy);
50 if (pos)
51 {
52 AliMpMotifType* type = pos->GetMotif()->GetMotifType();
53 return type->FindConnectionByLocalIndices(AliMpIntPair(ix,iy)-pos->GetLowIndicesLimit());
54 }
55 return 0x0;
56}
57
58//______________________________________________________________________________
59AliMpPCB* flipX(const AliMpPCB& src,
60 AliMpSlatMotifMap& destMotifs)
61{
62 AliMpPCB* dest = Duplicate(src,destMotifs);
63
64 for ( Int_t iy = dest->Iymin(); iy <= dest->Iymax(); ++iy )
65 {
66 for ( Int_t ix = dest->Ixmin(); ix <= dest->Ixmax(); ++ix )
67 {
68 AliMpConnection* srcConnection = getConnection(src,ix,iy);
69 Int_t dix = dest->Ixmax() - ix;
70 AliMpConnection* destConnection = getConnection(*dest,dix,iy);
71 if ( srcConnection && destConnection )
72 {
73 destConnection->SetGassiNum(srcConnection->GetGassiNum());
74 }
75 else
76 {
77 if ( srcConnection && !destConnection )
78 {
79 cout << Form("Got no connection in dest for ix,iy=%d,%d src "
80 "ix,iy=%d,%d in PCB %s",
81 dix,iy,ix,iy,dest->GetID()) << endl;
82 dest->Print("M");
83 cout << "---------- src=" << endl;
84 src.Print("M");
85 delete dest;
86 return 0x0;
87 }
88 }
89 }
90 }
91 return dest;
92}
93
94//______________________________________________________________________________
95void flipPCB(const char* srcName)
96{
97 // flip PCB in X-direction
98
99 AliMpSlatMotifMap* srcMotifs = new AliMpSlatMotifMap;
100 AliMpSlatMotifMap* destMotifs = new AliMpSlatMotifMap;
101
102 AliMpSt345Reader reader(*srcMotifs);
103
104 AliMpPCB* src = reader.ReadPCB(srcName);
105
106 if (!src) return;
107
108 AliMpPCB* dest = flipX(*src,*destMotifs);
109
110 if (!dest)
111 {
112 cout << "Flipping failed" << endl;
113 }
114
115 TCanvas* csrc = new TCanvas("src","src");
116 csrc->Draw();
117 AliMpVPainter* psrc = AliMpVPainter::CreatePainter(src);
118 psrc->Draw("MZT");
119
120 if ( dest )
121 {
122 TCanvas* cdest = new TCanvas("dest","dest");
123 cdest->Draw();
124 AliMpVPainter* pdest = AliMpVPainter::CreatePainter(dest);
125 pdest->Draw("MZT");
126 dest->Save();
127
128 }
129
130}