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>
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(const AliMpDataStreams& dataStreams,
77 AliMq::Station12Type station,
78 AliMp::PlaneType plane)
80 fkDataStreams(dataStreams),
81 fStationType(station),
84 fMotifReader(new AliMpMotifReader(dataStreams, AliMp::kStation12, station, plane))
87 /// Standard constructor
90 //_____________________________________________________________________________
91 AliMpSectorReader::~AliMpSectorReader()
102 //_____________________________________________________________________________
103 void AliMpSectorReader::ReadSectorData(istream& in)
105 /// Read sector input data;
106 /// prepare zones and rows vectors to be filled in.
111 AliDebugStream(2) << keyword << endl;
113 if (keyword != fgkSectorKeyword) {
114 Fatal("ReadSectorData", "Wrong file format.");
118 Int_t nofZones, nofRows;
119 TString directionStr;
120 Double_t offsetX, offsetY;
127 AliMp::Direction direction;
128 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
130 AliDebugStream(2) << nofZones << " " << nofRows << endl;
132 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
138 if (nextKeyword != fgkZoneKeyword) {
139 Fatal("ReadSectorData", "Wrong file format.");
146 //_____________________________________________________________________________
147 void AliMpSectorReader::ReadZoneData(istream& in)
149 /// Read zone input data;
150 /// create zone and adds it to zones vector.
153 Double_t sizex, sizey;
158 << fgkZoneKeyword << " " << zoneID << " "
159 << sizex << " " << sizey << endl;
161 AliMpZone* zone = fSector->GetZone(zoneID);
162 zone->SetPadDimensions(sizex/2.,sizey/2.);
167 if (nextKeyword != fgkSubZoneKeyword) {
168 Fatal("ReadZoneData", "Wrong file format.");
172 ReadSubZoneData(in, zone);
175 //_____________________________________________________________________________
176 void AliMpSectorReader::ReadSubZoneData(istream& in, AliMpZone* zone)
178 /// Read subzone input data;
179 /// create subzone and its to the specified zone.
181 AliDebugStream(2) << fgkSubZoneKeyword << endl;
183 AliMpVMotif* motif = ReadMotifData(in, zone);
184 AliMpSubZone* subZone = new AliMpSubZone(motif);
185 zone->AddSubZone(subZone);
190 if (nextKeyword != fgkRowKeyword) {
191 Fatal("ReadSubZoneData", "Wrong file format.");
195 ReadRowSegmentsData(in, zone, subZone);
198 //_____________________________________________________________________________
199 AliMpVMotif* AliMpSectorReader::ReadMotifData(istream& in, AliMpZone* zone)
201 /// Read the motif input data.
208 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
210 AliMpMotifMap* motifMap = fSector->GetMotifMap();
212 AliMpMotifType* motifType = 0;
214 = motifMap->FindMotif(motifID, motifTypeID,
215 zone->GetPadDimensionX(), zone->GetPadDimensionY());
217 motifType = motifMap->FindMotifType(motifTypeID);
219 motifType = fMotifReader->BuildMotifType(motifTypeID);
220 motifMap->AddMotifType(motifType);
223 if (zone->GetPadDimensionX() != 0. && zone->GetPadDimensionY() != 0.)
224 motif = new AliMpMotif(motifID, motifType,
225 zone->GetPadDimensionX(), zone->GetPadDimensionY());
227 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
230 motifMap->AddMotif(motif);
237 //_____________________________________________________________________________
238 void AliMpSectorReader::ReadRowSegmentsData(istream& in,
239 AliMpZone* zone, AliMpSubZone* subZone)
241 /// Read row segments input data of a specified zone and subzone;
242 /// creates row segment and add it to the specified subzone
243 /// and a corresponding row in the rows vector.
248 // Read data from file
250 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
255 in >> firstMotifPositionId;
256 in >> firstMotifPositionDId;
258 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
261 << fgkRowKeyword << " "
262 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
263 << firstMotifPositionId << " " << firstMotifPositionDId
271 AliMpRow* row = fSector->GetRow(inRow);
272 AliMpVMotif* motif = subZone->GetMotif();
274 // Create row segment and add it to its zone, row
275 AliMpVRowSegment* rowSegment
276 = new AliMpRowSegment(row, motif, offX, offY, nofMotifs,
277 firstMotifPositionId, firstMotifPositionDId);
279 subZone->AddRowSegment(rowSegment);
280 row->AddRowSegment(rowSegment);
282 while (!in.eof() && (nextKeyword == fgkRowKeyword));
284 if (in.eof()) return;
286 if (nextKeyword == fgkZoneKeyword) {
289 else if (nextKeyword == fgkSubZoneKeyword) {
290 ReadSubZoneData(in, zone);
293 Fatal("ReadRowSegmentsData", "Wrong file format.");
297 //_____________________________________________________________________________
298 void AliMpSectorReader::ReadSectorSpecialData(istream& in, AliMp::XDirection direction)
300 /// Read sector input data
301 /// with a special (irregular) motifs.
306 AliDebugStream(2) << keyword << endl;
308 if (keyword != fgkSectorSpecialKeyword) {
309 Fatal("ReadSectorSpecialData", "Wrong file format.");
316 AliDebugStream(2) << keyword << endl;
318 if (nextKeyword != fgkMotifKeyword) {
319 Fatal("ReadSectorSpecialData", "Wrong file format.");
323 ReadMotifsSpecialData(in);
324 ReadRowSpecialData(in, direction);
327 //_____________________________________________________________________________
328 void AliMpSectorReader::ReadMotifsSpecialData(istream& in)
330 /// Read the special (irregular) motifs input data.
332 AliDebugStream(2) << fgkMotifKeyword << endl;
338 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
339 AliMpSubZone* subZone = new AliMpSubZone(motif);
340 fSector->GetZone(zone)->AddSubZone(subZone);
344 AliDebugStream(2) << nextKeyword << endl;
346 while (nextKeyword == fgkMotifKeyword);
348 if (nextKeyword != fgkRowSpecialKeyword) {
349 Fatal("ReadMotifSpecialData", "Wrong file format.");
354 //_____________________________________________________________________________
355 void AliMpSectorReader::ReadRowSpecialData(istream& in, AliMp::XDirection direction)
357 /// Read row input data
358 /// with a special (irregular) motifs.
363 AliDebugStream(2) << id << endl;
365 // Get the row and its border
366 AliMpRow* row = fSector->GetRow(id);
368 AliMpVRowSegmentSpecial* segment = 0;
369 if (direction == AliMp::kLeft) {
370 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
371 Double_t offsetX = firstNormalSeg->LeftBorderX();
373 // Create a special row segment
374 segment = new AliMpRowSegmentLSpecial(row, offsetX);
375 row->AddRowSegmentInFront(segment);
378 AliMpVRowSegment* precedentNormalSeg
379 = row->GetRowSegment(row->GetNofRowSegments()-1);
380 Double_t offsetX = precedentNormalSeg->RightBorderX();
382 // Create a special row segment
383 segment = new AliMpRowSegmentRSpecial(row, offsetX);
384 row->AddRowSegment(segment);
390 AliDebugStream(2) << nextKeyword << endl;
392 if (nextKeyword != fgkPadRowsKeyword) {
393 Fatal("ReadRowSpecialData", "Wrong file format.");
397 ReadRowSegmentSpecialData(in, segment, direction);
399 // Update row segment and set it to all subzones associated with
402 segment->UpdateMotifVector();
403 segment->UpdatePadsOffset();
405 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
406 AliMpSubZone* subZone = 0;
408 while (!subZone && j<fSector->GetNofZones())
409 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
411 subZone->AddRowSegment(segment);
415 //_____________________________________________________________________________
416 void AliMpSectorReader::ReadRowSegmentSpecialData(istream& in,
417 AliMpVRowSegmentSpecial* segment,
418 AliMp::XDirection direction)
420 /// Read row segment input data
421 /// with a special (irregular) motifs.
426 AliDebugStream(2) << nofPadRows << endl;
431 AliDebugStream(2) << keyword << endl;
433 if (keyword != fgkPadRowSegmentKeyword) {
434 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
442 TObjArray newPadRows;
443 for (Int_t i=0; i<nofPadRows; i++) {
446 AliMpPadRow* padRow = new AliMpPadRow(direction);
447 segment->AddPadRow(padRow);
449 // Keep the new rows in a temporary vector
450 newPadRows.Add(padRow);
456 // Read data from file
458 Int_t nofPadsInRow, motifPositionId;
459 TString motifId, motifTypeId;
462 in >> motifPositionId;
464 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
467 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
471 AliDebugStream(2) << nextKeyword << endl;
477 for (Int_t i=0; i<nofPadRows; i++) {
479 // Get pad row from the temporary vector
480 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
483 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
486 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
490 // Create pad row segment
491 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
492 motifPositionId, nofPadsInRow);
495 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
497 if (in.eof()) return;
499 if (nextKeyword == fgkPadRowsKeyword) {
500 ReadRowSegmentSpecialData(in, segment, direction);
502 else if (nextKeyword == fgkRowSpecialKeyword) {
503 ReadRowSpecialData(in, direction);
506 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
514 //_____________________________________________________________________________
515 AliMpSector* AliMpSectorReader::BuildSector()
517 /// Read the mapping data from stream and create the basic objects: \n
518 /// zones, subzones, rows, row segments, motifs.
524 CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
529 fSector->SetRowSegmentOffsets();
531 // Open input stream for special inner zone
533 // add is data function
535 TString sectorSpecialFileName
536 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
537 if ( fkDataStreams.IsDataStream(sectorSpecialFileName) ) {
540 CreateDataStream(sectorSpecialFileName);
542 ReadSectorSpecialData(in2, AliMp::kLeft);
547 // Open input file for special outer zone
548 TString sectorSpecialFileName2
549 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
550 if ( fkDataStreams.IsDataStream(sectorSpecialFileName2) ) {
553 CreateDataStream(sectorSpecialFileName2);
555 ReadSectorSpecialData(in3, AliMp::kRight);
560 fSector->Initialize();