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 "AliMpZone.h"
32 #include "AliMpSubZone.h"
34 #include "AliMpVRowSegment.h"
35 #include "AliMpRowSegment.h"
36 #include "AliMpRowSegmentLSpecial.h"
37 #include "AliMpRowSegmentRSpecial.h"
38 #include "AliMpPadRow.h"
39 #include "AliMpMotifReader.h"
40 #include "AliMpMotifMap.h"
41 #include "AliMpMotif.h"
42 #include "AliMpMotifSpecial.h"
43 #include "AliMpMotifType.h"
44 #include "AliMpConnection.h"
45 #include "AliMpIntPair.h"
46 #include "AliMpDirection.h"
47 #include "AliMpConstants.h"
51 #include <Riostream.h>
52 #include <Rstrstream.h>
56 #if !defined(__HP_aCC) && !defined(__alpha)
61 ClassImp(AliMpSectorReader)
64 const TString AliMpSectorReader::fgkSectorKeyword = "SECTOR_DATA";
65 const TString AliMpSectorReader::fgkZoneKeyword = "ZONE";
66 const TString AliMpSectorReader::fgkSubZoneKeyword = "SUBZONE";
67 const TString AliMpSectorReader::fgkRowKeyword = "ROW_SEGMENT";
68 const TString AliMpSectorReader::fgkEofKeyword = "EOF";
69 const TString AliMpSectorReader::fgkSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
70 const TString AliMpSectorReader::fgkMotifKeyword = "MOTIF";
71 const TString AliMpSectorReader::fgkRowSpecialKeyword = "ROW";
72 const TString AliMpSectorReader::fgkPadRowsKeyword = "PAD_ROWS";
73 const TString AliMpSectorReader::fgkPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
75 //_____________________________________________________________________________
76 AliMpSectorReader::AliMpSectorReader(AliMp::StationType station,
77 AliMp::PlaneType plane)
79 fStationType(station),
82 fMotifReader(new AliMpMotifReader(station, plane))
84 /// Standard constructor
87 //_____________________________________________________________________________
88 AliMpSectorReader::AliMpSectorReader()
90 fStationType(AliMp::kStation1),
91 fPlaneType(AliMp::kBendingPlane),
95 /// Default constructor
98 //_____________________________________________________________________________
99 AliMpSectorReader::~AliMpSectorReader()
110 //_____________________________________________________________________________
111 void AliMpSectorReader::ReadSectorData(ifstream& in)
113 /// Read sector input data;
114 /// prepare zones and rows vectors to be filled in.
119 AliDebugStream(2) << keyword << endl;
121 if (keyword != fgkSectorKeyword) {
122 Fatal("ReadSectorData", "Wrong file format.");
126 Int_t nofZones, nofRows;
127 TString directionStr;
128 Double_t offsetX, offsetY;
135 AliMp::Direction direction;
136 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
138 AliDebugStream(2) << nofZones << " " << nofRows << endl;
140 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
141 TVector2(offsetX, offsetY));
146 if (nextKeyword != fgkZoneKeyword) {
147 Fatal("ReadSectorData", "Wrong file format.");
154 //_____________________________________________________________________________
155 void AliMpSectorReader::ReadZoneData(ifstream& in)
157 /// Read zone input data;
158 /// create zone and adds it to zones vector.
161 Double_t sizex, sizey;
166 << fgkZoneKeyword << " " << zoneID << " "
167 << sizex << " " << sizey << endl;
169 AliMpZone* zone = fSector->GetZone(zoneID);
170 zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.));
175 if (nextKeyword != fgkSubZoneKeyword) {
176 Fatal("ReadZoneData", "Wrong file format.");
180 ReadSubZoneData(in, zone);
183 //_____________________________________________________________________________
184 void AliMpSectorReader::ReadSubZoneData(ifstream& in, AliMpZone* zone)
186 /// Read subzone input data;
187 /// create subzone and its to the specified zone.
189 AliDebugStream(2) << fgkSubZoneKeyword << endl;
191 AliMpVMotif* motif = ReadMotifData(in, zone);
192 AliMpSubZone* subZone = new AliMpSubZone(motif);
193 zone->AddSubZone(subZone);
198 if (nextKeyword != fgkRowKeyword) {
199 Fatal("ReadSubZoneData", "Wrong file format.");
203 ReadRowSegmentsData(in, zone, subZone);
206 //_____________________________________________________________________________
207 AliMpVMotif* AliMpSectorReader::ReadMotifData(ifstream& in, AliMpZone* zone)
209 /// Read the motif input data.
216 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
218 AliMpMotifMap* motifMap = fSector->GetMotifMap();
220 AliMpMotifType* motifType = 0;
222 = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
224 motifType = motifMap->FindMotifType(motifTypeID);
226 motifType = fMotifReader->BuildMotifType(motifTypeID);
227 motifMap->AddMotifType(motifType);
230 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
231 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
233 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
236 motifMap->AddMotif(motif);
243 //_____________________________________________________________________________
244 void AliMpSectorReader::ReadRowSegmentsData(ifstream& in,
245 AliMpZone* zone, AliMpSubZone* subZone)
247 /// Read row segments input data of a specified zone and subzone;
248 /// creates row segment and add it to the specified subzone
249 /// and a corresponding row in the rows vector.
254 // Read data from file
256 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
261 in >> firstMotifPositionId;
262 in >> firstMotifPositionDId;
264 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
267 << fgkRowKeyword << " "
268 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
269 << firstMotifPositionId << " " << firstMotifPositionDId
277 AliMpRow* row = fSector->GetRow(inRow);
278 AliMpVMotif* motif = subZone->GetMotif();
280 // Create row segment and add it to its zone, row
281 AliMpVRowSegment* rowSegment
282 = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs,
283 firstMotifPositionId, firstMotifPositionDId);
285 subZone->AddRowSegment(rowSegment);
286 row->AddRowSegment(rowSegment);
288 while (!in.eof() && (nextKeyword == fgkRowKeyword));
290 if (in.eof()) return;
292 if (nextKeyword == fgkZoneKeyword) {
295 else if (nextKeyword == fgkSubZoneKeyword) {
296 ReadSubZoneData(in, zone);
299 Fatal("ReadRowSegmentsData", "Wrong file format.");
303 //_____________________________________________________________________________
304 void AliMpSectorReader::ReadSectorSpecialData(ifstream& in, AliMp::XDirection direction)
306 /// Read sector input data
307 /// with a special (irregular) motifs.
312 AliDebugStream(2) << keyword << endl;
314 if (keyword != fgkSectorSpecialKeyword) {
315 Fatal("ReadSectorSpecialData", "Wrong file format.");
322 AliDebugStream(2) << keyword << endl;
324 if (nextKeyword != fgkMotifKeyword) {
325 Fatal("ReadSectorSpecialData", "Wrong file format.");
329 ReadMotifsSpecialData(in);
330 ReadRowSpecialData(in, direction);
333 //_____________________________________________________________________________
334 void AliMpSectorReader::ReadMotifsSpecialData(ifstream& in)
336 /// Read the special (irregular) motifs input data.
338 AliDebugStream(2) << fgkMotifKeyword << endl;
344 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
345 AliMpSubZone* subZone = new AliMpSubZone(motif);
346 fSector->GetZone(zone)->AddSubZone(subZone);
350 AliDebugStream(2) << nextKeyword << endl;
352 while (nextKeyword == fgkMotifKeyword);
354 if (nextKeyword != fgkRowSpecialKeyword) {
355 Fatal("ReadMotifSpecialData", "Wrong file format.");
360 //_____________________________________________________________________________
361 void AliMpSectorReader::ReadRowSpecialData(ifstream& in, AliMp::XDirection direction)
363 /// Read row input data
364 /// with a special (irregular) motifs.
369 AliDebugStream(2) << id << endl;
371 // Get the row and its border
372 AliMpRow* row = fSector->GetRow(id);
374 AliMpVRowSegmentSpecial* segment = 0;
375 if (direction == AliMp::kLeft) {
376 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
377 Double_t offsetX = firstNormalSeg->LeftBorderX();
379 // Create a special row segment
380 segment = new AliMpRowSegmentLSpecial(row, offsetX);
381 row->AddRowSegmentInFront(segment);
384 AliMpVRowSegment* precedentNormalSeg
385 = row->GetRowSegment(row->GetNofRowSegments()-1);
386 Double_t offsetX = precedentNormalSeg->RightBorderX();
388 // Create a special row segment
389 segment = new AliMpRowSegmentRSpecial(row, offsetX);
390 row->AddRowSegment(segment);
396 AliDebugStream(2) << nextKeyword << endl;
398 if (nextKeyword != fgkPadRowsKeyword) {
399 Fatal("ReadRowSpecialData", "Wrong file format.");
403 ReadRowSegmentSpecialData(in, segment, direction);
405 // Update row segment and set it to all subzones associated with
408 segment->UpdateMotifVector();
409 segment->UpdatePadsOffset();
411 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
412 AliMpSubZone* subZone = 0;
414 while (!subZone && j<fSector->GetNofZones())
415 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
417 subZone->AddRowSegment(segment);
421 //_____________________________________________________________________________
422 void AliMpSectorReader::ReadRowSegmentSpecialData(ifstream& in,
423 AliMpVRowSegmentSpecial* segment,
424 AliMp::XDirection direction)
426 /// Read row segment input data
427 /// with a special (irregular) motifs.
432 AliDebugStream(2) << nofPadRows << endl;
437 AliDebugStream(2) << keyword << endl;
439 if (keyword != fgkPadRowSegmentKeyword) {
440 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
448 AliMpVRowSegmentSpecial::PadRowVector newPadRows;
449 for (Int_t i=0; i<nofPadRows; i++) {
452 AliMpPadRow* padRow = new AliMpPadRow(direction);
453 segment->AddPadRow(padRow);
455 // Keep the new rows in a temporary vector
457 newPadRows.push_back(padRow);
460 newPadRows.Add(padRow);
467 // Read data from file
469 Int_t nofPadsInRow, motifPositionId;
470 TString motifId, motifTypeId;
473 in >> motifPositionId;
475 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
478 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
482 AliDebugStream(2) << nextKeyword << endl;
488 for (Int_t i=0; i<nofPadRows; i++) {
490 // Get pad row from the temporary vector
492 AliMpPadRow* padRow = newPadRows[i];
495 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
499 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
502 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
506 // Create pad row segment
507 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
508 motifPositionId, nofPadsInRow);
511 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
513 if (in.eof()) return;
515 if (nextKeyword == fgkPadRowsKeyword) {
516 ReadRowSegmentSpecialData(in, segment, direction);
518 else if (nextKeyword == fgkRowSpecialKeyword) {
519 ReadRowSpecialData(in, direction);
522 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
530 //_____________________________________________________________________________
531 AliMpSector* AliMpSectorReader::BuildSector()
533 /// Read the mapping data from ascii data file
534 /// and create the basic objects: \n
535 /// zones, subzones, rows, row segments, motifs.
538 ifstream in(AliMpFiles::SectorFilePath(fStationType, fPlaneType).Data(), ios::in);
541 << "File " << AliMpFiles::SectorFilePath(fStationType, fPlaneType)
542 << " not found." << endl;
547 fSector->SetRowSegmentOffsets();
549 // Open input file for special inner zone
550 TString sectorSpecialFileName
551 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
552 if (!gSystem->AccessPathName(sectorSpecialFileName.Data())) {
553 ifstream in2(sectorSpecialFileName.Data(), ios::in);
556 << "File " << AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType)
557 << " not found." << endl;
561 ReadSectorSpecialData(in2, AliMp::kLeft);
564 // Open input file for special outer zone
565 TString sectorSpecialFileName2
566 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
567 if (!gSystem->AccessPathName(sectorSpecialFileName2.Data())) {
568 ifstream in3(sectorSpecialFileName2.Data(), ios::in);
571 << "File " << AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType)
572 << " not found."<< endl;
576 ReadSectorSpecialData(in3, AliMp::kRight);
579 fSector->Initialize();