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