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