]>
Commit | Line | Data |
---|---|---|
1d9e7bed | 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: AliMpTriggerReader.cxx,v 1.4 2006/05/24 13:58:52 ivana Exp $ |
1d9e7bed | 18 | |
19 | #include "AliMpTriggerReader.h" | |
183279c1 | 20 | |
21 | #include "AliLog.h" | |
22 | #include "AliMpConstants.h" | |
228fd720 | 23 | #include "AliMpDataStreams.h" |
183279c1 | 24 | #include "AliMpFiles.h" |
25 | #include "AliMpHelper.h" | |
26 | #include "AliMpMotif.h" | |
27 | #include "AliMpMotifPosition.h" | |
28 | #include "AliMpMotifReader.h" | |
29 | #include "AliMpMotifSpecial.h" | |
1d9e7bed | 30 | #include "AliMpMotifType.h" |
31 | #include "AliMpPCB.h" | |
32 | #include "AliMpSlat.h" | |
cf25b4e1 | 33 | #include "AliMpSlatMotifMap.h" |
183279c1 | 34 | #include "AliMpSlatMotifMap.h" |
1d9e7bed | 35 | #include "AliMpSt345Reader.h" |
36 | #include "AliMpTrigger.h" | |
63ed9c6b | 37 | #include "Riostream.h" |
1d9e7bed | 38 | #include "TClass.h" |
1d9e7bed | 39 | #include "TList.h" |
183279c1 | 40 | #include "TObjString.h" |
1d9e7bed | 41 | #include "TString.h" |
17c7d4c9 | 42 | #include <TArrayI.h> |
183279c1 | 43 | #include <cstdlib> |
1d9e7bed | 44 | #include <sstream> |
1d9e7bed | 45 | |
3d1463c8 | 46 | //----------------------------------------------------------------------------- |
85fec35d | 47 | /// \class AliMpTriggerReader |
48 | /// Read trigger slat ASCII files | |
cf25b4e1 | 49 | /// Basically provides two methods: |
85fec35d | 50 | /// - AliMpTrigger* ReadSlat() |
51 | /// - AliMpPCB* ReadPCB() | |
52 | /// | |
53 | /// \author Laurent Aphecetche | |
3d1463c8 | 54 | //----------------------------------------------------------------------------- |
85fec35d | 55 | |
13985652 | 56 | /// \cond CLASSIMP |
57 | ClassImp(AliMpTriggerReader) | |
58 | /// \endcond | |
59 | ||
31edb2d7 | 60 | // |
61 | // static private methods | |
62 | // | |
63 | ||
64 | //_____________________________________________________________________________ | |
65 | const TString& AliMpTriggerReader::GetKeywordLayer() | |
66 | { | |
67 | /// Keyword: LAYER | |
68 | static const TString kKeywordLayer("LAYER"); | |
69 | return kKeywordLayer; | |
70 | } | |
71 | ||
72 | //_____________________________________________________________________________ | |
73 | const TString& AliMpTriggerReader::GetKeywordScale() | |
74 | { | |
75 | /// Keyword: SCALE | |
76 | static const TString kKeywordScale("SCALE"); | |
77 | return kKeywordScale; | |
78 | } | |
79 | ||
80 | //_____________________________________________________________________________ | |
81 | const TString& AliMpTriggerReader::GetKeywordPcb() | |
82 | { | |
83 | /// Keyword : PCB | |
84 | static const TString kKeywordPcb("PCB"); | |
85 | return kKeywordPcb; | |
86 | } | |
87 | ||
88 | //_____________________________________________________________________________ | |
89 | const TString& AliMpTriggerReader::GetKeywordFlipX() | |
90 | { | |
91 | /// Keyword : FLIPX | |
92 | static const TString kKeywordFlipX("FLIP_X"); | |
93 | return kKeywordFlipX; | |
94 | } | |
95 | ||
96 | //_____________________________________________________________________________ | |
97 | const TString& AliMpTriggerReader::GetKeywordFlipY() | |
98 | { | |
99 | /// Keyword : FLIPY | |
100 | static const TString kKeywordFlipY("FLIP_Y"); | |
101 | return kKeywordFlipY; | |
102 | } | |
103 | ||
104 | // | |
105 | // ctors, dtor | |
106 | // | |
1d9e7bed | 107 | |
108 | //_____________________________________________________________________________ | |
21027e5a | 109 | AliMpTriggerReader::AliMpTriggerReader(AliMpSlatMotifMap* motifMap) |
cf25b4e1 | 110 | : TObject(), |
183279c1 | 111 | fMotifMap(motifMap), |
cf25b4e1 | 112 | fLocalBoardMap() |
1d9e7bed | 113 | { |
71a2d3aa | 114 | /// |
115 | /// Default ctor. | |
116 | /// | |
cf25b4e1 | 117 | fLocalBoardMap.SetOwner(kTRUE); |
1d9e7bed | 118 | } |
119 | ||
120 | //_____________________________________________________________________________ | |
121 | AliMpTriggerReader::~AliMpTriggerReader() | |
122 | { | |
71a2d3aa | 123 | /// |
124 | /// Dtor. | |
125 | /// | |
cf25b4e1 | 126 | fLocalBoardMap.DeleteAll(); |
1d9e7bed | 127 | } |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | AliMpSlat* | |
21027e5a | 131 | AliMpTriggerReader::BuildSlat(const AliMpDataStreams& dataStreams, |
132 | const char* slatName, | |
cddd101e | 133 | AliMp::PlaneType planeType, |
1d9e7bed | 134 | const TList& lines, |
135 | Double_t scale) | |
136 | { | |
cf25b4e1 | 137 | /// Construct a slat from the list of lines, taking into account |
138 | /// the scale factor. The returned pointer must be deleted by the client | |
85fec35d | 139 | |
cf25b4e1 | 140 | AliDebug(1,Form("slat %s %s scale %e", |
141 | slatName,PlaneTypeName(planeType).Data(),scale)) | |
142 | ; | |
143 | ||
1d9e7bed | 144 | AliMpSlat* slat = new AliMpSlat(slatName, planeType); |
145 | ||
146 | TIter it(&lines); | |
cf25b4e1 | 147 | |
1a3b5b04 | 148 | // StdoutToAliDebug(3,lines.Print();); |
cf25b4e1 | 149 | |
1d9e7bed | 150 | TObjString* osline; |
151 | while ( ( osline = (TObjString*)it.Next() ) ) | |
152 | { | |
153 | // note that at this stage lines should not be empty. | |
154 | TString sline(osline->String()); | |
155 | ||
156 | TObjArray* tokens = sline.Tokenize(' '); | |
157 | ||
158 | TString& keyword = ((TObjString*)tokens->At(0))->String(); | |
159 | ||
31edb2d7 | 160 | if ( keyword == GetKeywordPcb() ) |
1d9e7bed | 161 | { |
162 | if ( tokens->GetEntriesFast() != 3 ) | |
163 | { | |
164 | AliErrorClass(Form("Syntax error : expecting PCB type localboard-list" | |
165 | " in following line:\n%s",sline.Data())); | |
166 | delete slat; | |
167 | delete tokens; | |
168 | return 0; | |
169 | } | |
170 | TString pcbName = ((TObjString*)tokens->At(1))->String(); | |
171 | ||
172 | TObjArray* localBoardList = ((TObjString*)tokens->At(2))->String().Tokenize(','); | |
173 | ||
174 | if ( scale != 1.0 ) | |
175 | { | |
176 | std::ostringstream s; | |
177 | s << pcbName.Data() << "x" << scale; | |
178 | pcbName = s.str().c_str(); | |
179 | } | |
180 | ||
21027e5a | 181 | AliMpPCB* pcbType = ReadPCB(dataStreams, pcbName.Data()); |
1d9e7bed | 182 | if (!pcbType) |
183 | { | |
184 | AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data())); | |
185 | delete slat; | |
09d5920f | 186 | delete tokens; |
1d9e7bed | 187 | return 0; |
188 | } | |
189 | ||
190 | TArrayI allLocalBoards; | |
191 | ||
192 | for ( Int_t ilb = 0; ilb < localBoardList->GetEntriesFast(); ++ilb) | |
193 | { | |
194 | TArrayI localBoardNumbers; | |
195 | TString& localBoards = ((TObjString*)localBoardList->At(ilb))->String(); | |
196 | Ssiz_t pos = localBoards.First('-'); | |
197 | if ( pos < 0 ) | |
198 | { | |
199 | pos = localBoards.Length(); | |
200 | } | |
201 | AliMpHelper::DecodeName(localBoards(pos-1,localBoards.Length()-pos+1).Data(), | |
202 | ';',localBoardNumbers); | |
203 | for ( int i = 0; i < localBoardNumbers.GetSize(); ++i ) | |
204 | { | |
205 | std::ostringstream name; | |
206 | name << localBoards(0,pos-1) << localBoardNumbers[i]; | |
207 | AliDebugClass(3,name.str().c_str()); | |
21027e5a | 208 | localBoardNumbers[i] = LocalBoardNumber(dataStreams,name.str().c_str()); |
1d9e7bed | 209 | AliDebugClass(3,Form("LOCALBOARDNUMBER %d\n",localBoardNumbers[i])); |
210 | allLocalBoards.Set(allLocalBoards.GetSize()+1); | |
211 | allLocalBoards[allLocalBoards.GetSize()-1] = localBoardNumbers[i]; | |
212 | if (localBoardNumbers[i] < 0 ) | |
213 | { | |
214 | AliErrorClass(Form("Got a negative local board number in %s ? Unlikely" | |
215 | " to be correct... : %s\n",slatName,name.str().c_str())); | |
216 | } | |
217 | } | |
218 | } | |
cf25b4e1 | 219 | AliDebug(3,"Deleting tokens"); |
1d9e7bed | 220 | delete tokens; |
cf25b4e1 | 221 | AliDebug(3,"Deleting localBoardList"); |
1d9e7bed | 222 | delete localBoardList; |
cf25b4e1 | 223 | AliDebug(3,"Adding pcb to slat"); |
224 | slat->Add(*pcbType,allLocalBoards); | |
225 | AliDebug(3,Form("Deleting pcbType=%p %s",pcbType,pcbName.Data())); | |
226 | delete pcbType; | |
1d9e7bed | 227 | } |
228 | } | |
229 | ||
230 | if ( slat->DX()== 0 || slat->DY() == 0 ) | |
231 | { | |
232 | AliFatalClass(Form("Slat %s has invalid null size\n",slat->GetID())); | |
233 | } | |
234 | return slat; | |
235 | } | |
236 | ||
237 | //_____________________________________________________________________________ | |
238 | TString | |
239 | AliMpTriggerReader::GetBoardNameFromPCBLine(const TString& s) | |
240 | { | |
71a2d3aa | 241 | /// Decode the string to get the board name |
1d9e7bed | 242 | TString boardName; |
243 | ||
244 | TObjArray* tokens = s.Tokenize(' '); | |
245 | ||
246 | TString& keyword = ((TObjString*)tokens->At(0))->String(); | |
247 | ||
31edb2d7 | 248 | if ( keyword == GetKeywordPcb() && |
1d9e7bed | 249 | tokens->GetEntriesFast() == 3 ) |
250 | { | |
251 | boardName = ((TObjString*)tokens->At(2))->String(); | |
252 | } | |
253 | ||
254 | delete tokens; | |
255 | ||
256 | return boardName; | |
257 | } | |
258 | ||
259 | //_____________________________________________________________________________ | |
260 | void | |
21027e5a | 261 | AliMpTriggerReader::FlipLines(const AliMpDataStreams& dataStreams, |
262 | TList& lines, Bool_t flipX, Bool_t flipY, | |
1d9e7bed | 263 | Int_t srcLine, Int_t destLine) |
264 | { | |
cf25b4e1 | 265 | /// |
266 | /// Change the local board names contained in lines, | |
267 | /// to go from right to left, and/or | |
268 | /// from top to bottom | |
269 | /// | |
1d9e7bed | 270 | |
85fec35d | 271 | |
1d9e7bed | 272 | if ( flipX ) |
273 | { | |
85fec35d | 274 | // Simply swaps R(ight) and L(eft) in the first character of |
275 | // local board names | |
1d9e7bed | 276 | |
277 | TObjString* oline; | |
278 | TIter it(&lines); | |
279 | while ( ( oline = (TObjString*)it.Next() ) ) | |
280 | { | |
281 | TString& s = oline->String(); | |
282 | if ( s.Contains("RC") ) | |
283 | { | |
284 | // Change right to left | |
285 | s.ReplaceAll("RC","LC"); | |
286 | } | |
287 | else if ( s.Contains("LC") ) | |
288 | { | |
289 | // Change left to right | |
290 | s.ReplaceAll("LC","RC"); | |
291 | } | |
292 | } | |
293 | } | |
294 | ||
1d9e7bed | 295 | if ( flipY ) |
296 | { | |
297 | // Change line number, according to parameters srcLine and destLine | |
298 | // Note that because of road opening (for planes 3 and 4 at least), | |
299 | // we loop for srcLine +-1 | |
300 | // | |
301 | for ( Int_t line = -1; line <=1; ++line ) | |
302 | { | |
303 | std::ostringstream src,dest; | |
304 | src << "L" << srcLine+line; | |
305 | dest << "L" << destLine-line; | |
306 | if ( src.str() == dest.str() ) continue; | |
307 | ||
308 | for ( Int_t i = 0; i < lines.GetSize(); ++i ) | |
309 | { | |
310 | TObjString* oline = (TObjString*)lines.At(i); | |
311 | ||
312 | TString& s = oline->String(); | |
313 | ||
31edb2d7 | 314 | if ( !s.Contains(GetKeywordPcb()) ) |
1d9e7bed | 315 | { |
316 | // Only consider PCB lines. | |
317 | continue; | |
318 | } | |
319 | ||
320 | if ( s.Contains(src.str().c_str()) ) | |
321 | { | |
322 | AliDebugClass(4,Form("Replacing %s by %s in %s\n", | |
323 | src.str().c_str(),dest.str().c_str(),s.Data())); | |
324 | ||
325 | s.ReplaceAll(src.str().c_str(),dest.str().c_str()); | |
326 | ||
327 | AliDebugClass(4,s.Data()); | |
328 | ||
329 | TString boardName(GetBoardNameFromPCBLine(s)); | |
330 | ||
331 | if ( line ) | |
332 | { | |
333 | // We must also change board numbers, with the tricky | |
334 | // thing that up and down must be swapped... | |
335 | // Up can only be 1 card so it must be B1 | |
336 | // Down must be the uppper card of the line before, so | |
337 | // the biggest possible board number for this Line,Column | |
338 | ||
339 | if (line>0) | |
340 | { | |
341 | // force to B1 | |
342 | AliDebugClass(4,Form("Forcing B1 in %s\n",s.Data())); | |
343 | s.ReplaceAll(boardName(boardName.Length()-2,2),"B1"); | |
344 | AliDebugClass(4,s.Data()); | |
345 | } | |
346 | else | |
347 | { | |
348 | // find the largest valid board number | |
349 | for ( int b = 4; b>=1; --b ) | |
350 | { | |
351 | std::ostringstream bs; | |
352 | bs << boardName(0,boardName.Length()-1) << b; | |
21027e5a | 353 | if ( LocalBoardNumber(dataStreams,bs.str().c_str()) >= 0 ) |
1d9e7bed | 354 | { |
355 | AliDebugClass(4,Form("Replacing %s by %s in %s\n", | |
356 | boardName(boardName.Length()-2,2).Data(), | |
357 | Form("B%d",b), | |
358 | s.Data())); | |
359 | s.ReplaceAll(boardName(boardName.Length()-2,2), | |
360 | Form("B%d",b)); | |
361 | AliDebugClass(4,s); | |
362 | break; | |
363 | } | |
364 | } | |
365 | } | |
366 | // Check that the replacement we did is ok. If not, | |
367 | // skip the line. | |
21027e5a | 368 | Int_t lbn = LocalBoardNumber(dataStreams,GetBoardNameFromPCBLine(s)); |
1d9e7bed | 369 | if ( lbn < 0 ) |
370 | { | |
371 | AliDebugClass(4,Form("Removing line %s\n",s.Data())); | |
372 | lines.Remove(oline); | |
373 | } | |
374 | ||
375 | } // if (line) | |
376 | } | |
377 | } | |
378 | } | |
379 | } | |
1d9e7bed | 380 | } |
381 | ||
382 | //___________________________________________________________________________ | |
383 | Int_t | |
9ee1d6ff | 384 | AliMpTriggerReader::IsLayerLine(const TString& sline) const |
1d9e7bed | 385 | { |
cf25b4e1 | 386 | /// Whether sline contains LAYER keyword |
85fec35d | 387 | |
31edb2d7 | 388 | if ( sline.BeginsWith(GetKeywordLayer()) ) |
1d9e7bed | 389 | { |
390 | return 1; | |
391 | } | |
392 | else | |
393 | { | |
394 | return 0; | |
395 | } | |
396 | } | |
397 | ||
398 | //___________________________________________________________________________ | |
399 | Int_t | |
400 | AliMpTriggerReader::DecodeFlipLine(const TString& sline, | |
401 | TString& slatType2, | |
402 | Bool_t& flipX, Bool_t& flipY) | |
403 | { | |
cf25b4e1 | 404 | /// Decode a line containing FLIP_X and/or FLIP_Y keywords |
85fec35d | 405 | |
1d9e7bed | 406 | Ssiz_t blankPos = sline.First(' '); |
407 | if ( blankPos < 0 ) return 0; | |
408 | ||
409 | TString keyword(sline(0,blankPos)); | |
410 | ||
31edb2d7 | 411 | if ( keyword == GetKeywordFlipX() ) |
1d9e7bed | 412 | { |
413 | flipX = kTRUE; | |
31edb2d7 | 414 | } else if ( keyword == GetKeywordFlipY() ) |
1d9e7bed | 415 | { |
416 | flipY = kTRUE; | |
417 | } | |
418 | else | |
419 | { | |
420 | return 0; | |
421 | } | |
422 | ||
423 | slatType2 = sline(blankPos+1,sline.Length()-blankPos-1); | |
424 | return 1; | |
425 | } | |
426 | ||
427 | //___________________________________________________________________________ | |
428 | Int_t | |
429 | AliMpTriggerReader::DecodeScaleLine(const TString& sline, | |
430 | Double_t& scale, TString& slatType) | |
431 | { | |
cf25b4e1 | 432 | /// Decode sline containing SCALE keyword |
85fec35d | 433 | |
31edb2d7 | 434 | if ( sline(0,GetKeywordScale().Length()) == GetKeywordScale() ) |
1d9e7bed | 435 | { |
31edb2d7 | 436 | TString tmp(sline(GetKeywordScale().Length()+1, |
437 | sline.Length()-GetKeywordScale().Length()-1)); | |
1d9e7bed | 438 | Ssiz_t blankPos = tmp.First(' '); |
439 | if ( blankPos < 0 ) | |
440 | { | |
441 | AliErrorClass(Form("Syntax error in slat file, should get a slatType after " | |
442 | " SCALE keyword : %s\n",tmp.Data())); | |
443 | return -1; | |
444 | } | |
445 | else | |
446 | { | |
447 | slatType = tmp(0,blankPos); | |
448 | scale = TString(tmp(blankPos+1,tmp.Length()-blankPos-1)).Atof(); | |
449 | return 1; | |
450 | } | |
451 | } | |
452 | scale = 1.0; | |
453 | return 0; | |
454 | } | |
455 | ||
456 | //_____________________________________________________________________________ | |
457 | Int_t | |
458 | AliMpTriggerReader::GetLine(const TString& slatType) | |
459 | { | |
cf25b4e1 | 460 | /// |
461 | /// Assuming slatType is a 4 character string of the form XSLN | |
462 | /// where X=1,2,3 or 4 | |
463 | /// S = R or L | |
464 | /// N is the line number | |
465 | /// returns N | |
466 | ||
1d9e7bed | 467 | if ( isdigit(slatType[0]) && |
468 | ( slatType[1] == 'R' || slatType[1] == 'L' ) && | |
469 | slatType[2] == 'L' ) | |
470 | { | |
471 | return atoi(slatType(3,1).Data()); | |
472 | } | |
473 | return -1; | |
474 | } | |
475 | ||
476 | //_____________________________________________________________________________ | |
477 | int | |
21027e5a | 478 | AliMpTriggerReader::LocalBoardNumber(const AliMpDataStreams& dataStreams, |
479 | const char* localBoardName) | |
1d9e7bed | 480 | { |
cf25b4e1 | 481 | /// From local board name to local board number |
85fec35d | 482 | |
cf25b4e1 | 483 | if ( !fLocalBoardMap.GetSize() ) |
1d9e7bed | 484 | { |
21027e5a | 485 | ReadLocalBoardMapping(dataStreams); |
1d9e7bed | 486 | } |
487 | ||
cf25b4e1 | 488 | TPair* pair = (TPair*)fLocalBoardMap.FindObject(localBoardName); |
1d9e7bed | 489 | |
490 | if (pair) | |
491 | { | |
492 | return atoi(((TObjString*)pair->Value())->String().Data()); | |
493 | } | |
494 | return -1; | |
495 | } | |
496 | ||
1d9e7bed | 497 | //_____________________________________________________________________________ |
498 | void | |
21027e5a | 499 | AliMpTriggerReader::ReadLines(const AliMpDataStreams& dataStreams, |
500 | const char* slatType, | |
cddd101e | 501 | AliMp::PlaneType planeType, |
1d9e7bed | 502 | TList& lines, |
503 | Double_t& scale, | |
504 | Bool_t& flipX, Bool_t& flipY, | |
505 | Int_t& srcLine, Int_t& destLine) | |
506 | { | |
cf25b4e1 | 507 | /// |
508 | /// Reads in lines from file for a given slat | |
509 | /// Returns the list of lines (lines), together with some global | |
510 | /// information as the scale, whether to flip the lines, etc... | |
511 | /// | |
da3a1bb2 | 512 | AliDebugClass(2,Form("SlatType %s Scale %e FlipX %d FlipY %d srcLine %d" |
1d9e7bed | 513 | " destLine %d\n",slatType,scale,flipX,flipY, |
514 | srcLine,destLine)); | |
515 | ||
228fd720 | 516 | istream& in |
21027e5a | 517 | = dataStreams. |
ab167304 | 518 | CreateDataStream(AliMpFiles::SlatFilePath( |
228fd720 | 519 | AliMp::kStationTrigger,slatType, planeType)); |
1d9e7bed | 520 | |
521 | char line[80]; | |
522 | ||
523 | while ( in.getline(line,80) ) | |
524 | { | |
525 | TString sline(AliMpHelper::Normalize(line)); | |
526 | ||
527 | if ( sline.Length() == 0 || sline[0] == '#' ) continue; | |
528 | ||
529 | Bool_t isKeywordThere = | |
31edb2d7 | 530 | sline.Contains(GetKeywordPcb()) || |
531 | sline.Contains(GetKeywordLayer()) || | |
532 | sline.Contains(GetKeywordScale()) || | |
533 | sline.Contains(GetKeywordFlipX()) || | |
534 | sline.Contains(GetKeywordFlipY()); | |
1d9e7bed | 535 | |
536 | if ( !isKeywordThere ) | |
537 | { | |
538 | AliErrorClass(Form("Got a line with no keyword : %s." | |
539 | "That's not valid\n",line)); | |
540 | continue; | |
541 | } | |
542 | ||
543 | Double_t scale2; | |
544 | TString slatType2; | |
545 | ||
546 | Int_t isScaleLine = DecodeScaleLine(sline,scale2,slatType2); | |
547 | ||
548 | scale *= scale2; | |
549 | ||
550 | if ( isScaleLine < 0 ) | |
551 | { | |
31edb2d7 | 552 | AliFatalClass(Form("Syntax error near %s keyword\n",GetKeywordScale().Data())); |
1d9e7bed | 553 | } |
554 | else if ( isScaleLine > 0 && slatType2 != slatType ) | |
555 | { | |
21027e5a | 556 | ReadLines(dataStreams, |
557 | slatType2.Data(),planeType,lines,scale,flipX,flipY,srcLine,destLine); | |
1d9e7bed | 558 | } |
559 | else | |
560 | { | |
561 | Bool_t fx(kFALSE); | |
562 | Bool_t fy(kFALSE); | |
563 | Int_t isFlipLine = DecodeFlipLine(sline,slatType2,fx,fy); | |
564 | if ( isFlipLine ) | |
565 | { | |
566 | if (fy) | |
567 | { | |
568 | srcLine = GetLine(slatType2); | |
569 | destLine = GetLine(slatType); | |
570 | } | |
571 | flipX |= fx; | |
572 | flipY |= fy; | |
21027e5a | 573 | ReadLines(dataStreams, |
574 | slatType2.Data(),planeType,lines,scale,flipX,flipY,srcLine,destLine); | |
1d9e7bed | 575 | } |
576 | else | |
577 | { | |
578 | lines.Add(new TObjString(sline.Data())); | |
579 | } | |
580 | } | |
581 | } | |
582 | ||
228fd720 | 583 | delete ∈ |
1d9e7bed | 584 | } |
585 | ||
586 | //_____________________________________________________________________________ | |
587 | void | |
21027e5a | 588 | AliMpTriggerReader::ReadLocalBoardMapping(const AliMpDataStreams& dataStreams) |
1d9e7bed | 589 | { |
cf25b4e1 | 590 | /// Reads the file that contains the mapping local board name <-> number |
85fec35d | 591 | |
cf25b4e1 | 592 | fLocalBoardMap.DeleteAll(); |
1d9e7bed | 593 | |
53b051d2 | 594 | UShort_t mask; |
595 | ||
228fd720 | 596 | istream& in |
21027e5a | 597 | = dataStreams. |
ab167304 | 598 | CreateDataStream(AliMpFiles::LocalTriggerBoardMapping()); |
228fd720 | 599 | |
600 | char line[80]; | |
601 | Char_t localBoardName[20]; | |
602 | Int_t j,localBoardId; | |
603 | UInt_t switches; | |
113ad708 | 604 | Int_t nofBoards; |
605 | ||
228fd720 | 606 | while (!in.eof()) |
1d9e7bed | 607 | { |
228fd720 | 608 | for (Int_t i = 0; i < 4; ++i) |
609 | if (!in.getline(line,80)) continue; //skip 4 first lines | |
53b051d2 | 610 | |
228fd720 | 611 | // read mask |
612 | if (!in.getline(line,80)) break; | |
613 | sscanf(line,"%hx",&mask); | |
113ad708 | 614 | |
615 | // read # boards | |
616 | if (!in.getline(line,80)) break; | |
617 | sscanf(line,"%d",&nofBoards); | |
618 | ||
619 | for ( Int_t i = 0; i < nofBoards; ++i ) | |
228fd720 | 620 | { |
113ad708 | 621 | |
622 | if (!in.getline(line,80)) break; | |
8980e5a2 | 623 | sscanf(line,"%02d %19s %03d %03x", &j, localBoardName, &localBoardId, &switches); |
113ad708 | 624 | if (localBoardId <= AliMpConstants::NofLocalBoards()) |
228fd720 | 625 | { |
113ad708 | 626 | fLocalBoardMap.Add(new TObjString(localBoardName), new TObjString(Form("%d",localBoardId))); |
627 | AliDebugClass(10,Form("Board %s has number %d\n", localBoardName, localBoardId)); | |
628 | } | |
629 | // skip 2 following lines | |
630 | if (!in.getline(line,80)) break; | |
631 | if (!in.getline(line,80)) break; | |
632 | ||
228fd720 | 633 | } |
1d9e7bed | 634 | } |
228fd720 | 635 | |
636 | delete ∈ | |
1d9e7bed | 637 | } |
638 | ||
639 | //_____________________________________________________________________________ | |
640 | AliMpPCB* | |
21027e5a | 641 | AliMpTriggerReader::ReadPCB(const AliMpDataStreams& dataStreams, |
642 | const char* pcbType) | |
1d9e7bed | 643 | { |
cf25b4e1 | 644 | /// |
645 | /// Create a new AliMpPCB object, by reading it from file. | |
646 | /// Returned pointer must be deleted by client. | |
1d9e7bed | 647 | |
da3a1bb2 | 648 | AliDebugClass(2,Form("pcbType=%s\n",pcbType)); |
1d9e7bed | 649 | |
650 | TString pcbName(pcbType); | |
651 | ||
652 | Ssiz_t pos = pcbName.First('x'); | |
653 | ||
654 | Double_t scale = 1.0; | |
655 | ||
656 | if ( pos > 0 ) | |
657 | { | |
658 | scale = TString(pcbName(pos+1,pcbName.Length()-pos-1)).Atof(); | |
659 | pcbName = pcbName(0,pos); | |
660 | } | |
661 | ||
228fd720 | 662 | istream& in |
21027e5a | 663 | = dataStreams. |
ab167304 | 664 | CreateDataStream(AliMpFiles::SlatPCBFilePath( |
228fd720 | 665 | AliMp::kStationTrigger,pcbName)); |
1d9e7bed | 666 | |
21027e5a | 667 | AliMpMotifReader reader(AliMp::kStationTrigger, AliMq::kNotSt12, AliMp::kNonBendingPlane); |
1d9e7bed | 668 | // note that the nonbending |
669 | // parameter is of no use for trigger, as far as reading motif is | |
670 | // concerned, as all motifs are supposed to be in the same directory | |
671 | // (as they are shared by bending/non-bending planes). | |
672 | ||
673 | char line[80]; | |
674 | ||
84aac932 | 675 | const TString kSizeKeyword("SIZES"); |
676 | const TString kMotifKeyword("MOTIF"); | |
677 | const TString kMotifSpecialKeyword("SPECIAL_MOTIF"); | |
1d9e7bed | 678 | |
cf25b4e1 | 679 | AliMpPCB* pcb(0x0); |
1d9e7bed | 680 | |
681 | while ( in.getline(line,80) ) | |
682 | { | |
683 | if ( line[0] == '#' ) continue; | |
684 | ||
685 | TString sline(line); | |
686 | ||
84aac932 | 687 | if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword ) |
1d9e7bed | 688 | { |
84aac932 | 689 | std::istringstream sin(sline(kSizeKeyword.Length(), |
690 | sline.Length()-kSizeKeyword.Length()-1).Data()); | |
1d9e7bed | 691 | float padSizeX = 0.0; |
692 | float padSizeY = 0.0; | |
693 | float pcbSizeX = 0.0; | |
694 | float pcbSizeY = 0.0; | |
695 | sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY; | |
c918393d | 696 | if (pcb) |
697 | { | |
698 | AliError("pcb not null as expected"); | |
699 | } | |
657b96e3 | 700 | pcb = new AliMpPCB(fMotifMap,pcbType,padSizeX*scale,padSizeY*scale, |
1d9e7bed | 701 | pcbSizeX*scale,pcbSizeY*scale); |
702 | } | |
703 | ||
84aac932 | 704 | if ( sline(0,kMotifSpecialKeyword.Length()) == kMotifSpecialKeyword ) |
1d9e7bed | 705 | { |
84aac932 | 706 | std::istringstream sin(sline(kMotifSpecialKeyword.Length(), |
707 | sline.Length()-kMotifSpecialKeyword.Length()).Data()); | |
1d9e7bed | 708 | TString sMotifSpecial; |
709 | TString sMotifType; | |
710 | sin >> sMotifSpecial >> sMotifType; | |
711 | ||
cf25b4e1 | 712 | TString id = reader.MotifSpecialName(sMotifSpecial,scale); |
713 | ||
714 | AliMpMotifSpecial* specialMotif = | |
657b96e3 | 715 | dynamic_cast<AliMpMotifSpecial*>(fMotifMap->FindMotif(id)); |
cf25b4e1 | 716 | if (!specialMotif) |
717 | { | |
718 | AliDebug(1,Form("Reading motifSpecial %s (%s) from file", | |
719 | sMotifSpecial.Data(),id.Data())); | |
657b96e3 | 720 | AliMpMotifType* motifType = fMotifMap->FindMotifType(sMotifType.Data()); |
cf25b4e1 | 721 | if ( !motifType) |
722 | { | |
723 | AliDebug(1,Form("Reading motifType %s (%s) from file", | |
724 | sMotifType.Data(),id.Data())); | |
21027e5a | 725 | motifType = reader.BuildMotifType(dataStreams,sMotifType.Data()); |
657b96e3 | 726 | fMotifMap->AddMotifType(motifType); |
cf25b4e1 | 727 | } |
728 | else | |
729 | { | |
730 | AliDebug(1,Form("Got motifType %s (%s) from motifMap", | |
731 | sMotifType.Data(),id.Data())); | |
732 | } | |
21027e5a | 733 | specialMotif = reader.BuildMotifSpecial(dataStreams,sMotifSpecial,motifType,scale); |
657b96e3 | 734 | fMotifMap->AddMotif(specialMotif); |
cf25b4e1 | 735 | } |
736 | else | |
737 | { | |
738 | AliDebug(1,Form("Got motifSpecial %s from motifMap",sMotifSpecial.Data())); | |
739 | } | |
c918393d | 740 | if (pcb) |
741 | { | |
742 | AliError("pcb not null as expected"); | |
743 | } | |
1d9e7bed | 744 | pcb = new AliMpPCB(pcbType,specialMotif); |
745 | } | |
746 | ||
84aac932 | 747 | if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword ) |
1d9e7bed | 748 | { |
84aac932 | 749 | std::istringstream sin(sline(kMotifKeyword.Length(), |
750 | sline.Length()-kMotifKeyword.Length()).Data()); | |
1d9e7bed | 751 | TString sMotifType; |
752 | int ix; | |
753 | int iy; | |
754 | sin >> sMotifType >> ix >> iy; | |
755 | ||
657b96e3 | 756 | AliMpMotifType* motifType = fMotifMap->FindMotifType(sMotifType.Data()); |
cf25b4e1 | 757 | if ( !motifType) |
758 | { | |
759 | AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data())); | |
21027e5a | 760 | motifType = reader.BuildMotifType(dataStreams,sMotifType.Data()); |
657b96e3 | 761 | fMotifMap->AddMotifType(motifType); |
cf25b4e1 | 762 | } |
763 | else | |
764 | { | |
765 | AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data())); | |
766 | } | |
1d9e7bed | 767 | |
17b4ec8d | 768 | if (! pcb) |
769 | { | |
770 | AliError("pcb null"); | |
771 | continue; | |
772 | } | |
1d9e7bed | 773 | pcb->Add(motifType,ix,iy); |
774 | } | |
775 | } | |
776 | ||
228fd720 | 777 | delete ∈ |
1d9e7bed | 778 | |
1d9e7bed | 779 | return pcb; |
780 | } | |
781 | ||
782 | //_____________________________________________________________________________ | |
783 | AliMpTrigger* | |
21027e5a | 784 | AliMpTriggerReader::ReadSlat(const AliMpDataStreams& dataStreams, |
785 | const char* slatType, AliMp::PlaneType planeType) | |
1d9e7bed | 786 | { |
cf25b4e1 | 787 | /// |
788 | /// Create a new AliMpTrigger object, by reading it from file. | |
789 | /// Returned object must be deleted by client. | |
1d9e7bed | 790 | |
791 | Double_t scale = 1.0; | |
792 | Bool_t flipX = kFALSE; | |
793 | Bool_t flipY = kFALSE; | |
794 | TList lines; | |
cf25b4e1 | 795 | lines.SetOwner(kTRUE); |
1d9e7bed | 796 | Int_t srcLine(-1); |
797 | Int_t destLine(-1); | |
798 | ||
799 | // Read the file and its include (if any) and store the result | |
800 | // in a TObjArray of TObjStrings. | |
21027e5a | 801 | ReadLines(dataStreams, |
802 | slatType,planeType,lines,scale,flipX,flipY,srcLine,destLine); | |
1d9e7bed | 803 | |
804 | // Here some more sanity checks could be done. | |
805 | // For the moment we only insure that the first line contains | |
806 | // a layer keyword. | |
807 | TString& firstLine = ((TObjString*)lines.First())->String(); | |
808 | if ( !IsLayerLine(firstLine) ) | |
809 | { | |
810 | std::ostringstream s; | |
31edb2d7 | 811 | s << GetKeywordLayer(); |
1d9e7bed | 812 | lines.AddFirst(new TObjString(s.str().c_str())); |
813 | } | |
814 | ||
815 | AliDebugClass(2,Form("Scale=%g\n",scale)); | |
816 | ||
21027e5a | 817 | FlipLines(dataStreams,lines,flipX,flipY,srcLine,destLine); |
1d9e7bed | 818 | |
819 | // Now splits the lines in packets corresponding to different layers | |
820 | // (if any), and create sub-slats. | |
821 | TObjArray layers; | |
cf25b4e1 | 822 | layers.SetOwner(kTRUE); |
1d9e7bed | 823 | Int_t ilayer(-1); |
824 | TIter it(&lines); | |
825 | TObjString* osline; | |
826 | ||
827 | while ( ( osline = (TObjString*)it.Next() ) ) | |
828 | { | |
829 | TString& s = osline->String(); | |
830 | if ( IsLayerLine(s) ) | |
831 | { | |
17c7d4c9 | 832 | TList* list = new TList; |
cf25b4e1 | 833 | list->SetOwner(kTRUE); |
834 | layers.Add(list); | |
1d9e7bed | 835 | ++ilayer; |
836 | } | |
837 | else | |
838 | { | |
839 | ((TList*)layers.At(ilayer))->Add(new TObjString(s)); | |
840 | } | |
841 | } | |
842 | ||
843 | AliDebugClass(2,Form("nlayers=%d\n",layers.GetEntriesFast())); | |
844 | ||
845 | AliMpTrigger* triggerSlat = new AliMpTrigger(slatType, planeType); | |
846 | ||
6b6c7c4f | 847 | for ( ilayer = 0; ilayer < layers.GetEntriesFast(); ++ilayer ) |
1d9e7bed | 848 | { |
6b6c7c4f | 849 | TList& lines1 = *((TList*)layers.At(ilayer)); |
1d9e7bed | 850 | std::ostringstream slatName; |
851 | slatName << slatType << "-LAYER" << ilayer; | |
21027e5a | 852 | AliMpSlat* slat = BuildSlat(dataStreams, |
853 | slatName.str().c_str(),planeType,lines1,scale); | |
1d9e7bed | 854 | if ( slat ) |
855 | { | |
cf25b4e1 | 856 | Bool_t ok = triggerSlat->AdoptLayer(slat); |
857 | if (!ok) | |
858 | { | |
859 | StdoutToAliError(cout << "could not add slat=" << endl; | |
860 | slat->Print(); | |
861 | cout << "to the triggerSlat=" << endl; | |
862 | triggerSlat->Print(); | |
863 | ); | |
864 | AliError("Slat is="); | |
865 | for ( Int_t i = 0; i < slat->GetSize(); ++i ) | |
866 | { | |
867 | AliMpPCB* pcb = slat->GetPCB(i); | |
868 | AliError(Form("ERR pcb %d size %e,%e (unscaled is %e,%e)", | |
869 | i,pcb->DX()*2,pcb->DY()*2, | |
870 | pcb->DX()*2/scale,pcb->DY()*2/scale)); | |
871 | } | |
872 | AliError("TriggerSlat is="); | |
873 | for ( Int_t j = 0; j < triggerSlat->GetSize(); ++j ) | |
874 | { | |
6b6c7c4f | 875 | AliMpSlat* slat1 = triggerSlat->GetLayer(j); |
cf25b4e1 | 876 | AliError(Form("Layer %d",j)); |
6b6c7c4f | 877 | for ( Int_t i = 0; i < slat1->GetSize(); ++i ) |
cf25b4e1 | 878 | { |
6b6c7c4f | 879 | AliMpPCB* pcb = slat1->GetPCB(i); |
cf25b4e1 | 880 | AliError(Form("ERR pcb %d size %e,%e (unscaled is %e,%e)", |
881 | i,pcb->DX()*2,pcb->DY()*2, | |
882 | pcb->DX()*2/scale,pcb->DY()*2/scale)); | |
883 | } | |
884 | } | |
657b96e3 | 885 | StdoutToAliError(fMotifMap->Print();); |
cf25b4e1 | 886 | } |
1d9e7bed | 887 | } |
888 | else | |
889 | { | |
890 | AliErrorClass(Form("Could not read %s\n",slatName.str().c_str())); | |
891 | delete triggerSlat; | |
892 | return 0; | |
893 | } | |
894 | } | |
895 | ||
1d9e7bed | 896 | return triggerSlat; |
897 | } |