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