]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 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 purpeateose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
5006ec94 | 17 | // $MpId: AliMpSt345Reader.cxx,v 1.5 2005/09/23 12:57:32 ivana Exp $ |
dee1d5f1 | 18 | |
19 | #include "AliMpSt345Reader.h" | |
20 | ||
21 | #include "AliLog.h" | |
22 | #include "AliMpMotifReader.h" | |
23 | #include "AliMpFiles.h" | |
24 | #include "AliMpMotifType.h" | |
25 | #include "AliMpPCB.h" | |
26 | #include "AliMpSlat.h" | |
27 | #include "AliMpMotifMap.h" | |
28 | #include "AliMpMotifPosition.h" | |
29 | #include "AliMpMotif.h" | |
30 | #include "AliMpHelper.h" | |
31 | ||
32 | #include "Riostream.h" | |
33 | ||
34 | #include "TClass.h" | |
35 | #include "TObjString.h" | |
36 | #include "TString.h" | |
37 | ||
38 | #include <sstream> | |
28b486f1 | 39 | #include <assert.h> |
dee1d5f1 | 40 | |
41 | ClassImp(AliMpSt345Reader) | |
42 | ||
43 | TMap AliMpSt345Reader::fgPCBMap; | |
44 | ||
45 | //_____________________________________________________________________________ | |
46 | AliMpSt345Reader::AliMpSt345Reader() : TObject() | |
47 | { | |
48 | // | |
49 | // Default ctor. | |
50 | // | |
51 | } | |
52 | ||
53 | //_____________________________________________________________________________ | |
54 | AliMpSt345Reader::~AliMpSt345Reader() | |
55 | { | |
56 | // | |
57 | // Dtor. | |
58 | // | |
59 | fgPCBMap.Delete(); | |
60 | } | |
61 | ||
62 | //_____________________________________________________________________________ | |
63 | AliMpPCB* | |
64 | AliMpSt345Reader::PCB(const char* pcbType) | |
65 | { | |
66 | // | |
67 | // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...) | |
68 | // | |
69 | // Note that the returned object is either a new one (read from file) or a | |
70 | // reused one if it is already present in the internal map. | |
71 | // | |
72 | ||
73 | TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType); | |
74 | if ( pair ) | |
75 | { | |
76 | AliDebugClass(1,Form("Getting pcb %s from internal map",pcbType)); | |
77 | return (AliMpPCB*)pair->Value(); | |
78 | } | |
79 | else | |
80 | { | |
81 | AliDebugClass(1,Form("Reading pcb %s from file",pcbType)); | |
82 | return ReadPCB(pcbType); | |
83 | } | |
84 | } | |
85 | ||
86 | //_____________________________________________________________________________ | |
87 | AliMpPCB* | |
88 | AliMpSt345Reader::ReadPCB(const char* pcbType) | |
89 | { | |
90 | // | |
91 | // Create a new AliMpPCB object, by reading it from file. | |
92 | // | |
93 | ||
94 | std::ifstream in(AliMpFiles::Instance()->SlatPCBFilePath(pcbType).Data()); | |
95 | if (!in.good()) | |
96 | { | |
97 | AliErrorClass(Form("Cannot open file for PCB %s",pcbType)); | |
98 | return 0; | |
99 | } | |
100 | ||
101 | AliMpMotifReader reader(kStation345,kNonBendingPlane); | |
102 | // note that the nonbending | |
103 | // parameter is of no use for station345, as far as reading motif is | |
104 | // concerned, as all motifs are supposed to be in the same directory | |
105 | // (as they are shared by bending/non-bending planes). | |
106 | ||
107 | char line[80]; | |
108 | ||
109 | const TString sizeKeyword("SIZES"); | |
110 | const TString motifKeyword("MOTIF"); | |
111 | ||
112 | AliMpPCB* pcb = 0; | |
113 | ||
114 | while ( in.getline(line,80) ) | |
115 | { | |
116 | if ( line[0] == '#' ) continue; | |
117 | ||
118 | TString sline(line); | |
119 | ||
120 | if ( sline(0,sizeKeyword.Length()) == sizeKeyword ) | |
121 | { | |
122 | std::istringstream sin(sline(sizeKeyword.Length(), | |
123 | sline.Length()-sizeKeyword.Length()).Data()); | |
124 | float padSizeX = 0.0; | |
125 | float padSizeY = 0.0; | |
126 | float pcbSizeX = 0.0; | |
127 | float pcbSizeY = 0.0; | |
128 | sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY; | |
129 | assert(pcb==0); | |
130 | pcb = new AliMpPCB(pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY); | |
131 | } | |
132 | ||
133 | if ( sline(0,motifKeyword.Length()) == motifKeyword ) | |
134 | { | |
135 | std::istringstream sin(sline(motifKeyword.Length(), | |
136 | sline.Length()-motifKeyword.Length()).Data()); | |
137 | TString sMotifType; | |
138 | int ix; | |
139 | int iy; | |
140 | sin >> sMotifType >> ix >> iy; | |
141 | ||
142 | AliMpMotifType* motifType = | |
143 | reader.BuildMotifType(sMotifType.Data()); | |
144 | ||
145 | assert(pcb!=0); | |
146 | pcb->Add(motifType,ix,iy); | |
147 | } | |
148 | } | |
149 | ||
150 | in.close(); | |
151 | ||
152 | fgPCBMap.Add(new TObjString(pcbType),pcb); | |
153 | return pcb; | |
154 | } | |
155 | ||
156 | //_____________________________________________________________________________ | |
157 | AliMpSlat* | |
158 | AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType) | |
159 | { | |
160 | // | |
161 | // Create a new AliMpSlat object, by reading it from file. | |
162 | // | |
163 | ||
164 | std::ifstream in(AliMpFiles::Instance()->SlatFilePath(slatType, | |
165 | planeType).Data()); | |
166 | if (!in.good()) | |
167 | { | |
168 | AliErrorClass(Form("Cannot read slat from %s", | |
169 | AliMpFiles::Instance()-> | |
170 | SlatFilePath(slatType,planeType).Data())); | |
171 | return 0; | |
172 | } | |
173 | ||
174 | char line[80]; | |
175 | ||
176 | const TString pcbKeyword("PCB"); | |
177 | ||
178 | AliMpSlat* slat = new AliMpSlat(slatType); | |
179 | ||
180 | while ( in.getline(line,80) ) | |
181 | { | |
182 | if ( line[0] == '#' ) continue; | |
183 | ||
184 | TString sline(AliMpHelper::Normalize(line)); | |
185 | ||
186 | if ( sline(0,pcbKeyword.Length()) == pcbKeyword ) | |
187 | { | |
188 | TString tmp(sline(pcbKeyword.Length()+1,sline.Length()-pcbKeyword.Length())); | |
189 | Ssiz_t blankPos = tmp.First(' '); | |
190 | if ( blankPos < 0 ) | |
191 | { | |
192 | AliErrorClass("Syntax error in PCB file, should get a list of " | |
193 | "manu ids after the pcbname"); | |
194 | delete slat; | |
195 | return 0; | |
196 | } | |
197 | ||
198 | TString pcbName(tmp(0,blankPos)); | |
199 | TString manus(tmp(blankPos+1,tmp.Length()-blankPos)); | |
200 | ||
201 | AliMpPCB* pcbType = PCB(pcbName.Data()); | |
202 | if (!pcbType) | |
203 | { | |
204 | AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data())); | |
205 | delete slat; | |
206 | return 0; | |
207 | } | |
208 | ||
209 | TArrayI manuList; | |
210 | AliMpHelper::DecodeName(manus,';',manuList); | |
211 | if ( manuList.GetSize() != pcbType->GetSize() ) | |
212 | { | |
213 | AliErrorClass(Form("Wrong number of manu ids for this PCB (" | |
214 | "%s) : %d out of %d",pcbName.Data(), | |
215 | manuList.GetSize(),pcbType->GetSize())); | |
216 | delete slat; | |
217 | return 0; | |
218 | } | |
219 | slat->Add(pcbType,manuList); | |
220 | } | |
221 | } | |
222 | ||
223 | in.close(); | |
224 | ||
225 | return slat; | |
226 | } | |
227 |