1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // $MpId: AliMpSectorReader.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpSectorReader
22 // -----------------------
23 // Class that takes care of reading the sector data.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpSectorReader.h"
29 #include "AliMpSector.h"
30 #include "AliMpFiles.h"
31 #include "AliMpDataStreams.h"
32 #include "AliMpZone.h"
33 #include "AliMpSubZone.h"
35 #include "AliMpVRowSegment.h"
36 #include "AliMpRowSegment.h"
37 #include "AliMpRowSegmentLSpecial.h"
38 #include "AliMpRowSegmentRSpecial.h"
39 #include "AliMpPadRow.h"
40 #include "AliMpMotifReader.h"
41 #include "AliMpMotifMap.h"
42 #include "AliMpMotif.h"
43 #include "AliMpMotifSpecial.h"
44 #include "AliMpMotifType.h"
45 #include "AliMpConnection.h"
46 #include "AliMpDirection.h"
47 #include "AliMpConstants.h"
51 #include <Riostream.h>
52 #include <Rstrstream.h>
58 #if !defined(__HP_aCC) && !defined(__alpha)
63 ClassImp(AliMpSectorReader)
67 // static private methods
70 //_____________________________________________________________________________
71 const TString& AliMpSectorReader::GetSectorKeyword()
74 static const TString kSectorKeyword = "SECTOR_DATA";
75 return kSectorKeyword;
78 //_____________________________________________________________________________
79 const TString& AliMpSectorReader::GetZoneKeyword()
82 static const TString kZoneKeyword = "ZONE";
86 //_____________________________________________________________________________
87 const TString& AliMpSectorReader::GetSubZoneKeyword()
90 static const TString kSubZoneKeyword = "SUBZONE";
91 return kSubZoneKeyword;
94 //_____________________________________________________________________________
95 const TString& AliMpSectorReader::GetRowKeyword()
98 static const TString kRowKeyword = "ROW_SEGMENT";
102 //_____________________________________________________________________________
103 const TString& AliMpSectorReader::GetSectorSpecialKeyword()
105 /// sector special keyword
106 static const TString kSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
107 return kSectorSpecialKeyword;
110 //_____________________________________________________________________________
111 const TString& AliMpSectorReader::GetMotifKeyword()
114 static const TString kMotifKeyword = "MOTIF";
115 return kMotifKeyword;
118 //_____________________________________________________________________________
119 const TString& AliMpSectorReader::GetRowSpecialKeyword()
121 /// row special keyword
122 static const TString kRowSpecialKeyword = "ROW";
123 return kRowSpecialKeyword;
126 //_____________________________________________________________________________
127 const TString& AliMpSectorReader::GetPadRowsKeyword()
130 static const TString kPadRowsKeyword = "PAD_ROWS";
131 return kPadRowsKeyword;
134 //_____________________________________________________________________________
135 const TString& AliMpSectorReader::GetPadRowSegmentKeyword()
137 /// pad row segment keyword
138 static const TString kPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
139 return kPadRowSegmentKeyword;
146 //_____________________________________________________________________________
147 AliMpSectorReader::AliMpSectorReader(AliMq::Station12Type station,
148 AliMp::PlaneType plane)
150 fStationType(station),
153 fMotifReader(new AliMpMotifReader(AliMp::kStation12, station, plane))
156 /// Standard constructor
159 //_____________________________________________________________________________
160 AliMpSectorReader::~AliMpSectorReader()
171 //_____________________________________________________________________________
172 void AliMpSectorReader::ReadSectorData(const AliMpDataStreams& dataStreams,
175 /// Read sector input data;
176 /// prepare zones and rows vectors to be filled in.
181 AliDebugStream(2) << keyword << endl;
183 if (keyword != GetSectorKeyword()) {
184 AliErrorStream() << "Wrong file format." << endl;
188 Int_t nofZones, nofRows;
189 TString directionStr;
190 Double_t offsetX, offsetY;
197 AliMp::Direction direction;
198 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
200 AliDebugStream(2) << nofZones << " " << nofRows << endl;
202 if ( nofZones < 0 || nofZones >= std::numeric_limits<Int_t>::max() ||
203 nofRows < 0 || nofRows >= std::numeric_limits<Int_t>::max() ) {
204 AliErrorStream() << "Wrong nofZones/nofRows value." << endl;
208 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
214 if (nextKeyword != GetZoneKeyword()) {
215 AliErrorStream() << "Wrong file format." << endl;
219 ReadZoneData(dataStreams, in);
222 //_____________________________________________________________________________
223 void AliMpSectorReader::ReadZoneData(const AliMpDataStreams& dataStreams,
226 /// Read zone input data;
227 /// create zone and adds it to zones vector.
230 Double_t sizex, sizey;
235 << GetZoneKeyword() << " " << zoneID << " "
236 << sizex << " " << sizey << endl;
238 AliMpZone* zone = fSector->GetZone(zoneID);
239 zone->SetPadDimensions(sizex/2.,sizey/2.);
244 if (nextKeyword != GetSubZoneKeyword()) {
245 AliErrorStream() << "Wrong file format." << endl;
249 ReadSubZoneData(dataStreams, in, zone);
252 //_____________________________________________________________________________
253 void AliMpSectorReader::ReadSubZoneData(const AliMpDataStreams& dataStreams,
254 istream& in, AliMpZone* zone)
256 /// Read subzone input data;
257 /// create subzone and its to the specified zone.
259 AliDebugStream(2) << GetSubZoneKeyword() << endl;
261 AliMpVMotif* motif = ReadMotifData(dataStreams, in, zone);
262 AliMpSubZone* subZone = new AliMpSubZone(motif);
263 zone->AddSubZone(subZone);
268 if (nextKeyword != GetRowKeyword()) {
269 AliErrorStream() << "Wrong file format." << endl;
273 ReadRowSegmentsData(dataStreams, in, zone, subZone);
276 //_____________________________________________________________________________
277 AliMpVMotif* AliMpSectorReader::ReadMotifData(
278 const AliMpDataStreams& dataStreams,
279 istream& in, AliMpZone* zone)
281 /// Read the motif input data.
288 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
290 AliMpMotifMap* motifMap = fSector->GetMotifMap();
292 AliMpMotifType* motifType = 0;
294 = motifMap->FindMotif(motifID, motifTypeID,
295 zone->GetPadDimensionX(), zone->GetPadDimensionY());
297 motifType = motifMap->FindMotifType(motifTypeID);
299 motifType = fMotifReader->BuildMotifType(dataStreams, motifTypeID);
300 motifMap->AddMotifType(motifType);
303 if (zone->GetPadDimensionX() != 0. && zone->GetPadDimensionY() != 0.)
304 motif = new AliMpMotif(motifID, motifType,
305 zone->GetPadDimensionX(), zone->GetPadDimensionY());
307 motif = fMotifReader->BuildMotifSpecial(dataStreams, motifID, motifType);
310 motifMap->AddMotif(motif);
317 //_____________________________________________________________________________
318 void AliMpSectorReader::ReadRowSegmentsData(const AliMpDataStreams& dataStreams,
320 AliMpZone* zone, AliMpSubZone* subZone)
322 /// Read row segments input data of a specified zone and subzone;
323 /// creates row segment and add it to the specified subzone
324 /// and a corresponding row in the rows vector.
329 // Read data from file
331 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
336 in >> firstMotifPositionId;
337 in >> firstMotifPositionDId;
339 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
342 << GetRowKeyword() << " "
343 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
344 << firstMotifPositionId << " " << firstMotifPositionDId
352 AliMpRow* row = fSector->GetRow(inRow);
353 AliMpVMotif* motif = subZone->GetMotif();
355 // Create row segment and add it to its zone, row
356 AliMpVRowSegment* rowSegment
357 = new AliMpRowSegment(row, motif, offX, offY, nofMotifs,
358 firstMotifPositionId, firstMotifPositionDId);
360 subZone->AddRowSegment(rowSegment);
361 row->AddRowSegment(rowSegment);
363 while (!in.eof() && (nextKeyword == GetRowKeyword()));
365 if (in.eof()) return;
367 if (nextKeyword == GetZoneKeyword()) {
368 ReadZoneData(dataStreams, in);
370 else if (nextKeyword == GetSubZoneKeyword()) {
371 ReadSubZoneData(dataStreams, in, zone);
374 AliErrorStream() << "Wrong file format." << endl;
378 //_____________________________________________________________________________
379 void AliMpSectorReader::ReadSectorSpecialData(
380 const AliMpDataStreams& dataStreams,
381 istream& in, AliMp::XDirection direction)
383 /// Read sector input data
384 /// with a special (irregular) motifs.
389 AliDebugStream(2) << keyword << endl;
391 if (keyword != GetSectorSpecialKeyword()) {
392 AliErrorStream() << "Wrong file format." << endl;
399 AliDebugStream(2) << keyword << endl;
401 if (nextKeyword != GetMotifKeyword()) {
402 AliErrorStream() << "Wrong file format." << endl;
406 ReadMotifsSpecialData(dataStreams, in);
407 ReadRowSpecialData(dataStreams, in, direction);
410 //_____________________________________________________________________________
411 void AliMpSectorReader::ReadMotifsSpecialData(
412 const AliMpDataStreams& dataStreams,
415 /// Read the special (irregular) motifs input data.
417 AliDebugStream(2) << GetMotifKeyword() << endl;
423 AliMpVMotif* motif = ReadMotifData(dataStreams, in, fSector->GetZone(zone));
424 AliMpSubZone* subZone = new AliMpSubZone(motif);
425 fSector->GetZone(zone)->AddSubZone(subZone);
429 AliDebugStream(2) << nextKeyword << endl;
431 while (nextKeyword == GetMotifKeyword());
433 if (nextKeyword != GetRowSpecialKeyword()) {
434 AliErrorStream() << "Wrong file format." << endl;
439 //_____________________________________________________________________________
440 void AliMpSectorReader::ReadRowSpecialData(
441 const AliMpDataStreams& dataStreams,
442 istream& in, AliMp::XDirection direction)
444 /// Read row input data
445 /// with a special (irregular) motifs.
450 AliDebugStream(2) << id << endl;
452 // Get the row and its border
453 AliMpRow* row = fSector->GetRow(id);
455 AliMpVRowSegmentSpecial* segment = 0;
456 if (direction == AliMp::kLeft) {
457 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
458 Double_t offsetX = firstNormalSeg->LeftBorderX();
460 // Create a special row segment
461 segment = new AliMpRowSegmentLSpecial(row, offsetX);
462 row->AddRowSegmentInFront(segment);
465 AliMpVRowSegment* precedentNormalSeg
466 = row->GetRowSegment(row->GetNofRowSegments()-1);
467 Double_t offsetX = precedentNormalSeg->RightBorderX();
469 // Create a special row segment
470 segment = new AliMpRowSegmentRSpecial(row, offsetX);
471 row->AddRowSegment(segment);
477 AliDebugStream(2) << nextKeyword << endl;
479 if (nextKeyword != GetPadRowsKeyword()) {
480 AliErrorStream() << "Wrong file format." << endl;
484 ReadRowSegmentSpecialData(dataStreams, in, segment, direction);
486 // Update row segment and set it to all subzones associated with
489 segment->UpdateMotifVector();
490 segment->UpdatePadsOffset();
492 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
493 AliMpSubZone* subZone = 0;
495 while (!subZone && j<fSector->GetNofZones())
496 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
498 if (subZone) subZone->AddRowSegment(segment);
502 //_____________________________________________________________________________
503 void AliMpSectorReader::ReadRowSegmentSpecialData(
504 const AliMpDataStreams& dataStreams,
506 AliMpVRowSegmentSpecial* segment,
507 AliMp::XDirection direction)
509 /// Read row segment input data
510 /// with a special (irregular) motifs.
515 AliDebugStream(2) << nofPadRows << endl;
517 if ( nofPadRows < 0 || nofPadRows >= std::numeric_limits<Int_t>::max()) {
518 AliErrorStream() << "Wrong nofPadRows value." << endl;
525 AliDebugStream(2) << keyword << endl;
527 if (keyword != GetPadRowSegmentKeyword()) {
528 AliErrorStream() << "Wrong file format." << endl;
536 TObjArray newPadRows;
537 for (Int_t i=0; i<nofPadRows; i++) {
540 AliMpPadRow* padRow = new AliMpPadRow(direction);
541 segment->AddPadRow(padRow);
543 // Keep the new rows in a temporary vector
544 newPadRows.Add(padRow);
550 // Read data from file
552 Int_t nofPadsInRow, motifPositionId;
553 TString motifId, motifTypeId;
556 in >> motifPositionId;
558 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
561 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
565 AliDebugStream(2) << nextKeyword << endl;
571 for (Int_t i=0; i<nofPadRows; i++) {
573 // Get pad row from the temporary vector
574 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
577 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
580 AliErrorStream() << "Unknown motif" << endl;
584 // Create pad row segment
585 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
586 motifPositionId, nofPadsInRow);
589 while (!in.eof() && (nextKeyword == GetPadRowSegmentKeyword()));
591 if (in.eof()) return;
593 if (nextKeyword == GetPadRowsKeyword()) {
594 ReadRowSegmentSpecialData(dataStreams, in, segment, direction);
596 else if (nextKeyword == GetRowSpecialKeyword()) {
597 ReadRowSpecialData(dataStreams, in, direction);
600 AliErrorStream() << "Wrong file format." << endl;
608 //_____________________________________________________________________________
609 AliMpSector* AliMpSectorReader::BuildSector(const AliMpDataStreams& dataStreams)
611 /// Read the mapping data from stream and create the basic objects: \n
612 /// zones, subzones, rows, row segments, motifs.
618 CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
620 ReadSectorData(dataStreams, in);
623 fSector->SetRowSegmentOffsets();
625 // Open input stream for special inner zone
627 // add is data function
629 TString sectorSpecialFileName
630 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
631 if ( dataStreams.IsDataStream(sectorSpecialFileName) ) {
634 CreateDataStream(sectorSpecialFileName);
636 ReadSectorSpecialData(dataStreams, in2, AliMp::kLeft);
641 // Open input file for special outer zone
642 TString sectorSpecialFileName2
643 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
644 if ( dataStreams.IsDataStream(sectorSpecialFileName2) ) {
647 CreateDataStream(sectorSpecialFileName2);
649 ReadSectorSpecialData(dataStreams, in3, AliMp::kRight);
654 fSector->Initialize();