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