]>
Commit | Line | Data |
---|---|---|
197883c2 | 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: AliMpMotifReader.cxx,v 1.4 2005/08/26 15:43:36 ivana Exp $ | |
18 | // Category: sector | |
19 | // | |
20 | // Class AliMpMotifReader | |
21 | // ------------------- | |
22 | // Class that takes care of reading the sector data. | |
23 | // Included in AliRoot: 2003/05/02 | |
24 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay | |
25 | ||
26 | #if !defined(__HP_aCC) && !defined(__alpha) | |
27 | #include <sstream> | |
28 | #endif | |
29 | ||
30 | #include <Riostream.h> | |
31 | #include <Rstrstream.h> | |
32 | #include <TSystem.h> | |
33 | #include <TError.h> | |
34 | #include <TMath.h> | |
35 | ||
36 | #include "AliLog.h" | |
37 | #include "AliMpFiles.h" | |
38 | #include "AliMpMotifReader.h" | |
39 | #include "AliMpMotifMap.h" | |
40 | #include "AliMpMotif.h" | |
41 | #include "AliMpMotifSpecial.h" | |
42 | #include "AliMpMotifType.h" | |
43 | #include "AliMpConnection.h" | |
44 | #include "AliMpIntPair.h" | |
45 | #include "AliMpDirection.h" | |
46 | ||
47 | ClassImp(AliMpMotifReader) | |
48 | ||
49 | #ifdef WITH_ROOT | |
50 | const Int_t AliMpMotifReader::fgkSeparator = 100; | |
51 | #endif | |
52 | ||
53 | //_____________________________________________________________________________ | |
54 | AliMpMotifReader::AliMpMotifReader(AliMpStationType station, | |
55 | AliMpPlaneType plane) | |
56 | : TObject(), | |
57 | fStationType(station), | |
58 | fPlaneType(plane), | |
59 | fVerboseLevel(0) | |
60 | { | |
61 | /// Standard constructor | |
62 | } | |
63 | ||
64 | //_____________________________________________________________________________ | |
65 | AliMpMotifReader::AliMpMotifReader() | |
66 | : TObject(), | |
67 | fStationType(kStation1), | |
68 | fPlaneType(kBendingPlane), | |
69 | fVerboseLevel(0) | |
70 | { | |
71 | /// Default constructor | |
72 | } | |
73 | ||
74 | //_____________________________________________________________________________ | |
75 | AliMpMotifReader::AliMpMotifReader(const AliMpMotifReader& right) | |
76 | : TObject(right) | |
77 | { | |
78 | /// Protected copy constructor (not provided) | |
79 | ||
80 | Fatal("AliMpMotifReader", "Copy constructor not provided."); | |
81 | } | |
82 | ||
83 | //_____________________________________________________________________________ | |
84 | AliMpMotifReader::~AliMpMotifReader() | |
85 | { | |
86 | /// Destructor | |
87 | } | |
88 | ||
89 | // | |
90 | // operators | |
91 | // | |
92 | ||
93 | //_____________________________________________________________________________ | |
94 | AliMpMotifReader& AliMpMotifReader::operator=(const AliMpMotifReader& right) | |
95 | { | |
96 | /// Protected assignment operator (not provided) | |
97 | ||
98 | // check assignment to self | |
99 | if (this == &right) return *this; | |
100 | ||
101 | Fatal("operator =", "Assignment operator not provided."); | |
102 | ||
103 | return *this; | |
104 | } | |
105 | ||
106 | // | |
107 | // private methods | |
108 | // | |
109 | ||
110 | #ifdef WITH_ROOT | |
111 | //_____________________________________________________________________________ | |
112 | Int_t AliMpMotifReader::GetIndex(const string& s) const | |
113 | { | |
114 | /// Converts the TString to integer. | |
115 | ||
116 | if (s.length() > 5) { | |
117 | Fatal("GetIndex", "String too long."); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | Int_t index = 0; | |
122 | for (Int_t i=s.length(); i>=0; --i) index = index*100 + int(s[i]); | |
123 | ||
124 | return index; | |
125 | } | |
126 | ||
127 | //______________________________________________________________________________ | |
128 | Int_t AliMpMotifReader::GetIndex(const AliMpIntPair& pair) const | |
129 | { | |
130 | /// Convert the pair of integers to integer. | |
131 | ||
132 | if (pair.GetFirst() >= fgkSeparator || pair.GetSecond() >= fgkSeparator) | |
133 | Fatal("GetIndex", "Index out of limit."); | |
134 | ||
135 | return pair.GetFirst()*fgkSeparator + pair.GetSecond() + 1; | |
136 | } | |
137 | ||
138 | //_____________________________________________________________________________ | |
139 | string AliMpMotifReader::GetString(Int_t index) const | |
140 | { | |
141 | /// Convert the integer index to the string. | |
142 | ||
143 | string s; | |
144 | while (index >0) { | |
145 | Char_t c = index%100; | |
146 | s += c; | |
147 | index = index/100; | |
148 | } | |
149 | ||
150 | return s; | |
151 | ||
152 | } | |
153 | ||
154 | //______________________________________________________________________________ | |
155 | AliMpIntPair AliMpMotifReader::GetPair(Int_t index) const | |
156 | { | |
157 | /// Convert the integer index to the pair of integers. | |
158 | ||
159 | return AliMpIntPair((index-1)/fgkSeparator, (index-1)%fgkSeparator); | |
160 | } | |
161 | #endif | |
162 | ||
163 | // | |
164 | // public methods | |
165 | // | |
166 | ||
167 | //_____________________________________________________________________________ | |
168 | AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId) | |
169 | { | |
170 | /// Read the files describing a motif in the "$MINSTALL/data" directory | |
171 | /// and fill the AliMpMotifType structure with. | |
172 | /// The files mentioned are are named padPos<maskName>.dat | |
173 | /// and connect<maskName>.dat | |
174 | ||
175 | AliMpMotifType* motifType = new AliMpMotifType(motifTypeId); | |
176 | ||
177 | TString padPosFileName | |
178 | = AliMpFiles::Instance() | |
179 | ->PadPosFilePath(fStationType, fPlaneType, motifTypeId); | |
180 | ifstream padPos(padPosFileName); | |
181 | if (fVerboseLevel>0) cout<<"Opening file "<<padPosFileName<<endl; | |
182 | ||
183 | PadMapType positions; | |
184 | ||
185 | char line[256]; | |
186 | do { | |
187 | padPos.getline(line,255); | |
188 | if (!padPos) break; | |
189 | ||
190 | #if defined (__HP_aCC) || (__alpha) | |
191 | strstream strline; | |
192 | strline << line; | |
193 | #else | |
194 | istringstream strline(line); | |
195 | #endif | |
196 | string key; | |
197 | ||
198 | strline>>key; | |
199 | if ((key=="#") || (key=="") ) continue; | |
200 | ||
201 | int i,j; | |
202 | strline>>i>>j; | |
203 | #ifdef WITH_STL | |
204 | positions[key].first=i; | |
205 | positions[key].second=j; | |
206 | #endif | |
207 | #ifdef WITH_ROOT | |
208 | positions.Add(GetIndex(key), GetIndex(AliMpIntPair(i,j))); | |
209 | #endif | |
210 | } while (!padPos.eof()); | |
211 | ||
212 | padPos.close(); | |
213 | ||
214 | TString bergToGCFileName | |
215 | = AliMpFiles::Instance()->BergToGCFilePath(fStationType); | |
216 | if (fVerboseLevel>0) | |
217 | cout << "Opening file " << bergToGCFileName << endl; | |
218 | ||
219 | ifstream bergToGCFile(bergToGCFileName); | |
f29ba3e1 | 220 | const Int_t knbergpins = |
197883c2 | 221 | (fStationType == kStation1 || fStationType == kStation2 ) ? 80 : 100; |
222 | // Station1 & 2 Bergstak connectors have 80 pins, while for stations | |
223 | // 3, 4 and 5 they have 100 pins. | |
224 | Int_t gassiChannel[100]; | |
225 | while(1) { | |
226 | Int_t bergNum; | |
227 | TString gcStr; | |
228 | bergToGCFile>>bergNum>>gcStr; | |
229 | if (!bergToGCFile.good()) break; | |
230 | if (gcStr=="GND") continue; | |
f29ba3e1 | 231 | if (bergNum>knbergpins) { |
197883c2 | 232 | Fatal("BuildMotifType","Berg number > 80 ..."); |
233 | continue; | |
234 | } | |
235 | gassiChannel[bergNum-1]= atoi(gcStr); | |
236 | } | |
237 | bergToGCFile.close(); | |
238 | ||
239 | TString motifTypeFileName | |
240 | = AliMpFiles::Instance() | |
241 | ->MotifFilePath(fStationType, fPlaneType, motifTypeId); | |
242 | ifstream motif(motifTypeFileName); | |
243 | if (fVerboseLevel>0) cout<<"Opening file "<<motifTypeFileName<<endl; | |
244 | ||
245 | Int_t nofPadsX=0; | |
246 | Int_t nofPadsY=0; | |
247 | ||
248 | do { | |
249 | ||
250 | Int_t ix,iy,numBerg,numKapton,padNum,gassiNum; | |
251 | ||
252 | TString lineStr,token; | |
253 | lineStr.ReadLine(motif); | |
254 | if (!motif.good()) break; | |
255 | #if defined (__HP_aCC) || (__alpha) | |
256 | strstream tokenList; | |
257 | tokenList << lineStr.Data(); | |
258 | #else | |
259 | istringstream tokenList(lineStr.Data()); | |
260 | #endif | |
261 | ||
262 | token.ReadToken(tokenList); | |
263 | if (!tokenList.good()) continue; // column is missing... | |
264 | if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line | |
265 | ||
266 | numBerg = atoi(token.Data()); | |
267 | if (numBerg==0) { | |
268 | AliWarning(Form("Berg number %s invalid",token.Data())); | |
269 | continue; | |
270 | } | |
271 | ||
272 | token.ReadToken(tokenList); | |
273 | if (!tokenList.good()) continue; // column is missing... | |
274 | numKapton = atoi(token.Data()); | |
275 | if (numKapton==0) continue; | |
276 | ||
277 | ||
278 | token.ReadToken(tokenList); | |
279 | if (!tokenList.good()) continue; // column is missing... | |
280 | if (token=="GND") continue; | |
281 | string padName = token.Data(); | |
282 | padNum = motifType->PadNum(token); | |
283 | ||
284 | token.ReadToken(tokenList); | |
285 | if (token.IsNull() ) continue; // column is missing... | |
286 | // if (token[0]!='E') { | |
287 | // cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl; | |
288 | // continue; | |
289 | // } else { | |
290 | // gassiNum = atoi(token.Data() +1 )-1; | |
291 | // } | |
f29ba3e1 | 292 | if ( (numBerg<1) || (numBerg>knbergpins) ) { |
293 | AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins)); | |
197883c2 | 294 | continue; |
295 | } | |
296 | ||
297 | gassiNum = gassiChannel[numBerg-1]; | |
298 | ||
299 | #ifdef WITH_STL | |
300 | PadMapTypeIterator iter = positions.find(padName); | |
301 | if (iter==positions.end()) { | |
302 | cerr<<"Problem: Pad number "<<padNum<<" found in the file "<<motifTypeFileName | |
303 | <<" but not in the file"<<padPosFileName<<endl; | |
304 | continue; | |
305 | } | |
306 | ||
307 | ix= iter->second.first; | |
308 | iy= iter->second.second; | |
309 | #endif | |
310 | ||
311 | #ifdef WITH_ROOT | |
312 | Long_t value = positions.GetValue(GetIndex(padName)); | |
313 | if (!value) { | |
314 | cerr<<"Problem: Pad number "<<padNum<<" found in the file "<<motifTypeFileName | |
315 | <<" but not in the file"<<padPosFileName<<endl; | |
316 | continue; | |
317 | } | |
318 | ||
319 | ix = GetPair(value).GetFirst(); | |
320 | iy = GetPair(value).GetSecond(); | |
321 | #endif | |
322 | ||
323 | motifType->AddConnection(AliMpIntPair(ix,iy), | |
324 | new AliMpConnection(padNum,numBerg,numKapton,gassiNum)); | |
325 | ||
326 | if (ix>=nofPadsX) nofPadsX=ix+1; | |
327 | if (iy>=nofPadsY) nofPadsY=iy+1; | |
328 | ||
329 | } while (!motif.eof()); | |
330 | ||
331 | ||
332 | motifType->SetNofPads(nofPadsX, nofPadsY); | |
333 | ||
334 | motif.close(); | |
335 | ||
336 | return motifType; | |
337 | } | |
338 | ||
339 | ||
340 | //_____________________________________________________________________________ | |
341 | AliMpMotifSpecial* | |
342 | AliMpMotifReader::BuildMotifSpecial(const TString& motifID, | |
343 | AliMpMotifType* motifType) | |
344 | { | |
345 | /// Build a special motif by reading the file motifSpecial<motifId>.dat | |
346 | /// in the data directory | |
347 | ||
348 | // Open the input file | |
349 | TString motifSpecialFileName | |
350 | = AliMpFiles::Instance() | |
351 | ->MotifSpecialFilePath(fStationType, fPlaneType, motifID); | |
352 | ifstream in(motifSpecialFileName); | |
353 | if (!in) { | |
354 | Error("BuildMotifSpecial", "File not found."); | |
355 | return 0; | |
356 | } | |
357 | ||
358 | AliMpMotifSpecial* res = new AliMpMotifSpecial(motifID,motifType); | |
359 | Int_t i,j; | |
360 | Double_t x,y; | |
361 | in >> i; | |
362 | while (!in.eof()){ | |
363 | in >>j >>x >> y; | |
364 | res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x/2.,y/2.)); | |
365 | in >> i; | |
366 | } | |
367 | ||
368 | in.close(); | |
369 | return res; | |
370 | } | |
371 | ||
372 | ||
373 | //_____________________________________________________________________________ | |
374 | void AliMpMotifReader::SetVerboseLevel(Int_t verboseLevel) | |
375 | { | |
376 | // Sets verbose level. | |
377 | // --- | |
378 | ||
379 | fVerboseLevel = verboseLevel; | |
380 | } | |
381 |