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 "AliMpIntPair.h"
47 #include "AliMpDirection.h"
48 #include "AliMpConstants.h"
52 #include <Riostream.h>
53 #include <Rstrstream.h>
57 #if !defined(__HP_aCC) && !defined(__alpha)
62 ClassImp(AliMpSectorReader)
65 const TString AliMpSectorReader::fgkSectorKeyword = "SECTOR_DATA";
66 const TString AliMpSectorReader::fgkZoneKeyword = "ZONE";
67 const TString AliMpSectorReader::fgkSubZoneKeyword = "SUBZONE";
68 const TString AliMpSectorReader::fgkRowKeyword = "ROW_SEGMENT";
69 const TString AliMpSectorReader::fgkEofKeyword = "EOF";
70 const TString AliMpSectorReader::fgkSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
71 const TString AliMpSectorReader::fgkMotifKeyword = "MOTIF";
72 const TString AliMpSectorReader::fgkRowSpecialKeyword = "ROW";
73 const TString AliMpSectorReader::fgkPadRowsKeyword = "PAD_ROWS";
74 const TString AliMpSectorReader::fgkPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
76 //_____________________________________________________________________________
77 AliMpSectorReader::AliMpSectorReader(const AliMpDataStreams& dataStreams,
78 AliMp::StationType station,
79 AliMp::PlaneType plane)
81 fDataStreams(dataStreams),
82 fStationType(station),
85 fMotifReader(new AliMpMotifReader(dataStreams, station, plane))
88 /// Standard constructor
91 //_____________________________________________________________________________
92 AliMpSectorReader::~AliMpSectorReader()
103 //_____________________________________________________________________________
104 void AliMpSectorReader::ReadSectorData(istream& in)
106 /// Read sector input data;
107 /// prepare zones and rows vectors to be filled in.
112 AliDebugStream(2) << keyword << endl;
114 if (keyword != fgkSectorKeyword) {
115 Fatal("ReadSectorData", "Wrong file format.");
119 Int_t nofZones, nofRows;
120 TString directionStr;
121 Double_t offsetX, offsetY;
128 AliMp::Direction direction;
129 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
131 AliDebugStream(2) << nofZones << " " << nofRows << endl;
133 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
134 TVector2(offsetX, offsetY));
139 if (nextKeyword != fgkZoneKeyword) {
140 Fatal("ReadSectorData", "Wrong file format.");
147 //_____________________________________________________________________________
148 void AliMpSectorReader::ReadZoneData(istream& in)
150 /// Read zone input data;
151 /// create zone and adds it to zones vector.
154 Double_t sizex, sizey;
159 << fgkZoneKeyword << " " << zoneID << " "
160 << sizex << " " << sizey << endl;
162 AliMpZone* zone = fSector->GetZone(zoneID);
163 zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.));
168 if (nextKeyword != fgkSubZoneKeyword) {
169 Fatal("ReadZoneData", "Wrong file format.");
173 ReadSubZoneData(in, zone);
176 //_____________________________________________________________________________
177 void AliMpSectorReader::ReadSubZoneData(istream& in, AliMpZone* zone)
179 /// Read subzone input data;
180 /// create subzone and its to the specified zone.
182 AliDebugStream(2) << fgkSubZoneKeyword << endl;
184 AliMpVMotif* motif = ReadMotifData(in, zone);
185 AliMpSubZone* subZone = new AliMpSubZone(motif);
186 zone->AddSubZone(subZone);
191 if (nextKeyword != fgkRowKeyword) {
192 Fatal("ReadSubZoneData", "Wrong file format.");
196 ReadRowSegmentsData(in, zone, subZone);
199 //_____________________________________________________________________________
200 AliMpVMotif* AliMpSectorReader::ReadMotifData(istream& in, AliMpZone* zone)
202 /// Read the motif input data.
209 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
211 AliMpMotifMap* motifMap = fSector->GetMotifMap();
213 AliMpMotifType* motifType = 0;
215 = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
217 motifType = motifMap->FindMotifType(motifTypeID);
219 motifType = fMotifReader->BuildMotifType(motifTypeID);
220 motifMap->AddMotifType(motifType);
223 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
224 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
226 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
229 motifMap->AddMotif(motif);
236 //_____________________________________________________________________________
237 void AliMpSectorReader::ReadRowSegmentsData(istream& in,
238 AliMpZone* zone, AliMpSubZone* subZone)
240 /// Read row segments input data of a specified zone and subzone;
241 /// creates row segment and add it to the specified subzone
242 /// and a corresponding row in the rows vector.
247 // Read data from file
249 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
254 in >> firstMotifPositionId;
255 in >> firstMotifPositionDId;
257 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
260 << fgkRowKeyword << " "
261 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
262 << firstMotifPositionId << " " << firstMotifPositionDId
270 AliMpRow* row = fSector->GetRow(inRow);
271 AliMpVMotif* motif = subZone->GetMotif();
273 // Create row segment and add it to its zone, row
274 AliMpVRowSegment* rowSegment
275 = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs,
276 firstMotifPositionId, firstMotifPositionDId);
278 subZone->AddRowSegment(rowSegment);
279 row->AddRowSegment(rowSegment);
281 while (!in.eof() && (nextKeyword == fgkRowKeyword));
283 if (in.eof()) return;
285 if (nextKeyword == fgkZoneKeyword) {
288 else if (nextKeyword == fgkSubZoneKeyword) {
289 ReadSubZoneData(in, zone);
292 Fatal("ReadRowSegmentsData", "Wrong file format.");
296 //_____________________________________________________________________________
297 void AliMpSectorReader::ReadSectorSpecialData(istream& in, AliMp::XDirection direction)
299 /// Read sector input data
300 /// with a special (irregular) motifs.
305 AliDebugStream(2) << keyword << endl;
307 if (keyword != fgkSectorSpecialKeyword) {
308 Fatal("ReadSectorSpecialData", "Wrong file format.");
315 AliDebugStream(2) << keyword << endl;
317 if (nextKeyword != fgkMotifKeyword) {
318 Fatal("ReadSectorSpecialData", "Wrong file format.");
322 ReadMotifsSpecialData(in);
323 ReadRowSpecialData(in, direction);
326 //_____________________________________________________________________________
327 void AliMpSectorReader::ReadMotifsSpecialData(istream& in)
329 /// Read the special (irregular) motifs input data.
331 AliDebugStream(2) << fgkMotifKeyword << endl;
337 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
338 AliMpSubZone* subZone = new AliMpSubZone(motif);
339 fSector->GetZone(zone)->AddSubZone(subZone);
343 AliDebugStream(2) << nextKeyword << endl;
345 while (nextKeyword == fgkMotifKeyword);
347 if (nextKeyword != fgkRowSpecialKeyword) {
348 Fatal("ReadMotifSpecialData", "Wrong file format.");
353 //_____________________________________________________________________________
354 void AliMpSectorReader::ReadRowSpecialData(istream& in, AliMp::XDirection direction)
356 /// Read row input data
357 /// with a special (irregular) motifs.
362 AliDebugStream(2) << id << endl;
364 // Get the row and its border
365 AliMpRow* row = fSector->GetRow(id);
367 AliMpVRowSegmentSpecial* segment = 0;
368 if (direction == AliMp::kLeft) {
369 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
370 Double_t offsetX = firstNormalSeg->LeftBorderX();
372 // Create a special row segment
373 segment = new AliMpRowSegmentLSpecial(row, offsetX);
374 row->AddRowSegmentInFront(segment);
377 AliMpVRowSegment* precedentNormalSeg
378 = row->GetRowSegment(row->GetNofRowSegments()-1);
379 Double_t offsetX = precedentNormalSeg->RightBorderX();
381 // Create a special row segment
382 segment = new AliMpRowSegmentRSpecial(row, offsetX);
383 row->AddRowSegment(segment);
389 AliDebugStream(2) << nextKeyword << endl;
391 if (nextKeyword != fgkPadRowsKeyword) {
392 Fatal("ReadRowSpecialData", "Wrong file format.");
396 ReadRowSegmentSpecialData(in, segment, direction);
398 // Update row segment and set it to all subzones associated with
401 segment->UpdateMotifVector();
402 segment->UpdatePadsOffset();
404 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
405 AliMpSubZone* subZone = 0;
407 while (!subZone && j<fSector->GetNofZones())
408 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
410 subZone->AddRowSegment(segment);
414 //_____________________________________________________________________________
415 void AliMpSectorReader::ReadRowSegmentSpecialData(istream& in,
416 AliMpVRowSegmentSpecial* segment,
417 AliMp::XDirection direction)
419 /// Read row segment input data
420 /// with a special (irregular) motifs.
425 AliDebugStream(2) << nofPadRows << endl;
430 AliDebugStream(2) << keyword << endl;
432 if (keyword != fgkPadRowSegmentKeyword) {
433 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
441 AliMpVRowSegmentSpecial::PadRowVector newPadRows;
442 for (Int_t i=0; i<nofPadRows; i++) {
445 AliMpPadRow* padRow = new AliMpPadRow(direction);
446 segment->AddPadRow(padRow);
448 // Keep the new rows in a temporary vector
450 newPadRows.push_back(padRow);
453 newPadRows.Add(padRow);
460 // Read data from file
462 Int_t nofPadsInRow, motifPositionId;
463 TString motifId, motifTypeId;
466 in >> motifPositionId;
468 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
471 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
475 AliDebugStream(2) << nextKeyword << endl;
481 for (Int_t i=0; i<nofPadRows; i++) {
483 // Get pad row from the temporary vector
485 AliMpPadRow* padRow = newPadRows[i];
488 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
492 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
495 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
499 // Create pad row segment
500 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
501 motifPositionId, nofPadsInRow);
504 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
506 if (in.eof()) return;
508 if (nextKeyword == fgkPadRowsKeyword) {
509 ReadRowSegmentSpecialData(in, segment, direction);
511 else if (nextKeyword == fgkRowSpecialKeyword) {
512 ReadRowSpecialData(in, direction);
515 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
523 //_____________________________________________________________________________
524 AliMpSector* AliMpSectorReader::BuildSector()
526 /// Read the mapping data from stream and create the basic objects: \n
527 /// zones, subzones, rows, row segments, motifs.
533 CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
538 fSector->SetRowSegmentOffsets();
540 // Open input stream for special inner zone
542 // add is data function
544 TString sectorSpecialFileName
545 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
546 if ( fDataStreams.IsDataStream(sectorSpecialFileName) ) {
549 CreateDataStream(sectorSpecialFileName);
551 ReadSectorSpecialData(in2, AliMp::kLeft);
556 // Open input file for special outer zone
557 TString sectorSpecialFileName2
558 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
559 if ( fDataStreams.IsDataStream(sectorSpecialFileName2) ) {
562 CreateDataStream(sectorSpecialFileName2);
564 ReadSectorSpecialData(in3, AliMp::kRight);
569 fSector->Initialize();