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(const AliMpDataStreams& dataStreams,
148 AliMq::Station12Type station,
149 AliMp::PlaneType plane)
151 fkDataStreams(dataStreams),
152 fStationType(station),
155 fMotifReader(new AliMpMotifReader(dataStreams, AliMp::kStation12, station, plane))
158 /// Standard constructor
161 //_____________________________________________________________________________
162 AliMpSectorReader::~AliMpSectorReader()
173 //_____________________________________________________________________________
174 void AliMpSectorReader::ReadSectorData(istream& in)
176 /// Read sector input data;
177 /// prepare zones and rows vectors to be filled in.
182 AliDebugStream(2) << keyword << endl;
184 if (keyword != GetSectorKeyword()) {
185 AliErrorStream() << "Wrong file format." << endl;
189 Int_t nofZones, nofRows;
190 TString directionStr;
191 Double_t offsetX, offsetY;
198 AliMp::Direction direction;
199 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
201 AliDebugStream(2) << nofZones << " " << nofRows << endl;
203 if ( nofZones < 0 || nofZones >= std::numeric_limits<Int_t>::max() ||
204 nofRows < 0 || nofRows >= std::numeric_limits<Int_t>::max() ) {
205 AliErrorStream() << "Wrong nofZones/nofRows value." << endl;
209 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
215 if (nextKeyword != GetZoneKeyword()) {
216 AliErrorStream() << "Wrong file format." << endl;
223 //_____________________________________________________________________________
224 void AliMpSectorReader::ReadZoneData(istream& in)
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(in, zone);
252 //_____________________________________________________________________________
253 void AliMpSectorReader::ReadSubZoneData(istream& in, AliMpZone* zone)
255 /// Read subzone input data;
256 /// create subzone and its to the specified zone.
258 AliDebugStream(2) << GetSubZoneKeyword() << endl;
260 AliMpVMotif* motif = ReadMotifData(in, zone);
261 AliMpSubZone* subZone = new AliMpSubZone(motif);
262 zone->AddSubZone(subZone);
267 if (nextKeyword != GetRowKeyword()) {
268 AliErrorStream() << "Wrong file format." << endl;
272 ReadRowSegmentsData(in, zone, subZone);
275 //_____________________________________________________________________________
276 AliMpVMotif* AliMpSectorReader::ReadMotifData(istream& in, AliMpZone* zone)
278 /// Read the motif input data.
285 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
287 AliMpMotifMap* motifMap = fSector->GetMotifMap();
289 AliMpMotifType* motifType = 0;
291 = motifMap->FindMotif(motifID, motifTypeID,
292 zone->GetPadDimensionX(), zone->GetPadDimensionY());
294 motifType = motifMap->FindMotifType(motifTypeID);
296 motifType = fMotifReader->BuildMotifType(motifTypeID);
297 motifMap->AddMotifType(motifType);
300 if (zone->GetPadDimensionX() != 0. && zone->GetPadDimensionY() != 0.)
301 motif = new AliMpMotif(motifID, motifType,
302 zone->GetPadDimensionX(), zone->GetPadDimensionY());
304 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
307 motifMap->AddMotif(motif);
314 //_____________________________________________________________________________
315 void AliMpSectorReader::ReadRowSegmentsData(istream& in,
316 AliMpZone* zone, AliMpSubZone* subZone)
318 /// Read row segments input data of a specified zone and subzone;
319 /// creates row segment and add it to the specified subzone
320 /// and a corresponding row in the rows vector.
325 // Read data from file
327 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
332 in >> firstMotifPositionId;
333 in >> firstMotifPositionDId;
335 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
338 << GetRowKeyword() << " "
339 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
340 << firstMotifPositionId << " " << firstMotifPositionDId
348 AliMpRow* row = fSector->GetRow(inRow);
349 AliMpVMotif* motif = subZone->GetMotif();
351 // Create row segment and add it to its zone, row
352 AliMpVRowSegment* rowSegment
353 = new AliMpRowSegment(row, motif, offX, offY, nofMotifs,
354 firstMotifPositionId, firstMotifPositionDId);
356 subZone->AddRowSegment(rowSegment);
357 row->AddRowSegment(rowSegment);
359 while (!in.eof() && (nextKeyword == GetRowKeyword()));
361 if (in.eof()) return;
363 if (nextKeyword == GetZoneKeyword()) {
366 else if (nextKeyword == GetSubZoneKeyword()) {
367 ReadSubZoneData(in, zone);
370 AliErrorStream() << "Wrong file format." << endl;
374 //_____________________________________________________________________________
375 void AliMpSectorReader::ReadSectorSpecialData(istream& in, AliMp::XDirection direction)
377 /// Read sector input data
378 /// with a special (irregular) motifs.
383 AliDebugStream(2) << keyword << endl;
385 if (keyword != GetSectorSpecialKeyword()) {
386 AliErrorStream() << "Wrong file format." << endl;
393 AliDebugStream(2) << keyword << endl;
395 if (nextKeyword != GetMotifKeyword()) {
396 AliErrorStream() << "Wrong file format." << endl;
400 ReadMotifsSpecialData(in);
401 ReadRowSpecialData(in, direction);
404 //_____________________________________________________________________________
405 void AliMpSectorReader::ReadMotifsSpecialData(istream& in)
407 /// Read the special (irregular) motifs input data.
409 AliDebugStream(2) << GetMotifKeyword() << endl;
415 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
416 AliMpSubZone* subZone = new AliMpSubZone(motif);
417 fSector->GetZone(zone)->AddSubZone(subZone);
421 AliDebugStream(2) << nextKeyword << endl;
423 while (nextKeyword == GetMotifKeyword());
425 if (nextKeyword != GetRowSpecialKeyword()) {
426 AliErrorStream() << "Wrong file format." << endl;
431 //_____________________________________________________________________________
432 void AliMpSectorReader::ReadRowSpecialData(istream& in, AliMp::XDirection direction)
434 /// Read row input data
435 /// with a special (irregular) motifs.
440 AliDebugStream(2) << id << endl;
442 // Get the row and its border
443 AliMpRow* row = fSector->GetRow(id);
445 AliMpVRowSegmentSpecial* segment = 0;
446 if (direction == AliMp::kLeft) {
447 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
448 Double_t offsetX = firstNormalSeg->LeftBorderX();
450 // Create a special row segment
451 segment = new AliMpRowSegmentLSpecial(row, offsetX);
452 row->AddRowSegmentInFront(segment);
455 AliMpVRowSegment* precedentNormalSeg
456 = row->GetRowSegment(row->GetNofRowSegments()-1);
457 Double_t offsetX = precedentNormalSeg->RightBorderX();
459 // Create a special row segment
460 segment = new AliMpRowSegmentRSpecial(row, offsetX);
461 row->AddRowSegment(segment);
467 AliDebugStream(2) << nextKeyword << endl;
469 if (nextKeyword != GetPadRowsKeyword()) {
470 AliErrorStream() << "Wrong file format." << endl;
474 ReadRowSegmentSpecialData(in, segment, direction);
476 // Update row segment and set it to all subzones associated with
479 segment->UpdateMotifVector();
480 segment->UpdatePadsOffset();
482 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
483 AliMpSubZone* subZone = 0;
485 while (!subZone && j<fSector->GetNofZones())
486 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
488 if (subZone) subZone->AddRowSegment(segment);
492 //_____________________________________________________________________________
493 void AliMpSectorReader::ReadRowSegmentSpecialData(istream& in,
494 AliMpVRowSegmentSpecial* segment,
495 AliMp::XDirection direction)
497 /// Read row segment input data
498 /// with a special (irregular) motifs.
503 AliDebugStream(2) << nofPadRows << endl;
505 if ( nofPadRows < 0 || nofPadRows >= std::numeric_limits<Int_t>::max()) {
506 AliErrorStream() << "Wrong nofPadRows value." << endl;
513 AliDebugStream(2) << keyword << endl;
515 if (keyword != GetPadRowSegmentKeyword()) {
516 AliErrorStream() << "Wrong file format." << endl;
524 TObjArray newPadRows;
525 for (Int_t i=0; i<nofPadRows; i++) {
528 AliMpPadRow* padRow = new AliMpPadRow(direction);
529 segment->AddPadRow(padRow);
531 // Keep the new rows in a temporary vector
532 newPadRows.Add(padRow);
538 // Read data from file
540 Int_t nofPadsInRow, motifPositionId;
541 TString motifId, motifTypeId;
544 in >> motifPositionId;
546 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
549 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
553 AliDebugStream(2) << nextKeyword << endl;
559 for (Int_t i=0; i<nofPadRows; i++) {
561 // Get pad row from the temporary vector
562 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
565 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
568 AliErrorStream() << "Unknown motif" << endl;
572 // Create pad row segment
573 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
574 motifPositionId, nofPadsInRow);
577 while (!in.eof() && (nextKeyword == GetPadRowSegmentKeyword()));
579 if (in.eof()) return;
581 if (nextKeyword == GetPadRowsKeyword()) {
582 ReadRowSegmentSpecialData(in, segment, direction);
584 else if (nextKeyword == GetRowSpecialKeyword()) {
585 ReadRowSpecialData(in, direction);
588 AliErrorStream() << "Wrong file format." << endl;
596 //_____________________________________________________________________________
597 AliMpSector* AliMpSectorReader::BuildSector()
599 /// Read the mapping data from stream and create the basic objects: \n
600 /// zones, subzones, rows, row segments, motifs.
606 CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
611 fSector->SetRowSegmentOffsets();
613 // Open input stream for special inner zone
615 // add is data function
617 TString sectorSpecialFileName
618 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
619 if ( fkDataStreams.IsDataStream(sectorSpecialFileName) ) {
622 CreateDataStream(sectorSpecialFileName);
624 ReadSectorSpecialData(in2, AliMp::kLeft);
629 // Open input file for special outer zone
630 TString sectorSpecialFileName2
631 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
632 if ( fkDataStreams.IsDataStream(sectorSpecialFileName2) ) {
635 CreateDataStream(sectorSpecialFileName2);
637 ReadSectorSpecialData(in3, AliMp::kRight);
642 fSector->Initialize();