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(AliMp::StationType station,
78 AliMp::PlaneType plane)
80 fStationType(station),
83 fMotifReader(new AliMpMotifReader(station, plane))
86 /// Standard constructor
89 //_____________________________________________________________________________
90 AliMpSectorReader::AliMpSectorReader()
92 fStationType(AliMp::kStation1),
93 fPlaneType(AliMp::kBendingPlane),
97 /// Default constructor
100 //_____________________________________________________________________________
101 AliMpSectorReader::~AliMpSectorReader()
112 //_____________________________________________________________________________
113 void AliMpSectorReader::ReadSectorData(istream& in)
115 /// Read sector input data;
116 /// prepare zones and rows vectors to be filled in.
121 AliDebugStream(2) << keyword << endl;
123 if (keyword != fgkSectorKeyword) {
124 Fatal("ReadSectorData", "Wrong file format.");
128 Int_t nofZones, nofRows;
129 TString directionStr;
130 Double_t offsetX, offsetY;
137 AliMp::Direction direction;
138 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
140 AliDebugStream(2) << nofZones << " " << nofRows << endl;
142 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
143 TVector2(offsetX, offsetY));
148 if (nextKeyword != fgkZoneKeyword) {
149 Fatal("ReadSectorData", "Wrong file format.");
156 //_____________________________________________________________________________
157 void AliMpSectorReader::ReadZoneData(istream& in)
159 /// Read zone input data;
160 /// create zone and adds it to zones vector.
163 Double_t sizex, sizey;
168 << fgkZoneKeyword << " " << zoneID << " "
169 << sizex << " " << sizey << endl;
171 AliMpZone* zone = fSector->GetZone(zoneID);
172 zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.));
177 if (nextKeyword != fgkSubZoneKeyword) {
178 Fatal("ReadZoneData", "Wrong file format.");
182 ReadSubZoneData(in, zone);
185 //_____________________________________________________________________________
186 void AliMpSectorReader::ReadSubZoneData(istream& in, AliMpZone* zone)
188 /// Read subzone input data;
189 /// create subzone and its to the specified zone.
191 AliDebugStream(2) << fgkSubZoneKeyword << endl;
193 AliMpVMotif* motif = ReadMotifData(in, zone);
194 AliMpSubZone* subZone = new AliMpSubZone(motif);
195 zone->AddSubZone(subZone);
200 if (nextKeyword != fgkRowKeyword) {
201 Fatal("ReadSubZoneData", "Wrong file format.");
205 ReadRowSegmentsData(in, zone, subZone);
208 //_____________________________________________________________________________
209 AliMpVMotif* AliMpSectorReader::ReadMotifData(istream& in, AliMpZone* zone)
211 /// Read the motif input data.
218 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
220 AliMpMotifMap* motifMap = fSector->GetMotifMap();
222 AliMpMotifType* motifType = 0;
224 = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
226 motifType = motifMap->FindMotifType(motifTypeID);
228 motifType = fMotifReader->BuildMotifType(motifTypeID);
229 motifMap->AddMotifType(motifType);
232 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
233 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
235 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
238 motifMap->AddMotif(motif);
245 //_____________________________________________________________________________
246 void AliMpSectorReader::ReadRowSegmentsData(istream& in,
247 AliMpZone* zone, AliMpSubZone* subZone)
249 /// Read row segments input data of a specified zone and subzone;
250 /// creates row segment and add it to the specified subzone
251 /// and a corresponding row in the rows vector.
256 // Read data from file
258 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
263 in >> firstMotifPositionId;
264 in >> firstMotifPositionDId;
266 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
269 << fgkRowKeyword << " "
270 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
271 << firstMotifPositionId << " " << firstMotifPositionDId
279 AliMpRow* row = fSector->GetRow(inRow);
280 AliMpVMotif* motif = subZone->GetMotif();
282 // Create row segment and add it to its zone, row
283 AliMpVRowSegment* rowSegment
284 = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs,
285 firstMotifPositionId, firstMotifPositionDId);
287 subZone->AddRowSegment(rowSegment);
288 row->AddRowSegment(rowSegment);
290 while (!in.eof() && (nextKeyword == fgkRowKeyword));
292 if (in.eof()) return;
294 if (nextKeyword == fgkZoneKeyword) {
297 else if (nextKeyword == fgkSubZoneKeyword) {
298 ReadSubZoneData(in, zone);
301 Fatal("ReadRowSegmentsData", "Wrong file format.");
305 //_____________________________________________________________________________
306 void AliMpSectorReader::ReadSectorSpecialData(istream& in, AliMp::XDirection direction)
308 /// Read sector input data
309 /// with a special (irregular) motifs.
314 AliDebugStream(2) << keyword << endl;
316 if (keyword != fgkSectorSpecialKeyword) {
317 Fatal("ReadSectorSpecialData", "Wrong file format.");
324 AliDebugStream(2) << keyword << endl;
326 if (nextKeyword != fgkMotifKeyword) {
327 Fatal("ReadSectorSpecialData", "Wrong file format.");
331 ReadMotifsSpecialData(in);
332 ReadRowSpecialData(in, direction);
335 //_____________________________________________________________________________
336 void AliMpSectorReader::ReadMotifsSpecialData(istream& in)
338 /// Read the special (irregular) motifs input data.
340 AliDebugStream(2) << fgkMotifKeyword << endl;
346 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
347 AliMpSubZone* subZone = new AliMpSubZone(motif);
348 fSector->GetZone(zone)->AddSubZone(subZone);
352 AliDebugStream(2) << nextKeyword << endl;
354 while (nextKeyword == fgkMotifKeyword);
356 if (nextKeyword != fgkRowSpecialKeyword) {
357 Fatal("ReadMotifSpecialData", "Wrong file format.");
362 //_____________________________________________________________________________
363 void AliMpSectorReader::ReadRowSpecialData(istream& in, AliMp::XDirection direction)
365 /// Read row input data
366 /// with a special (irregular) motifs.
371 AliDebugStream(2) << id << endl;
373 // Get the row and its border
374 AliMpRow* row = fSector->GetRow(id);
376 AliMpVRowSegmentSpecial* segment = 0;
377 if (direction == AliMp::kLeft) {
378 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
379 Double_t offsetX = firstNormalSeg->LeftBorderX();
381 // Create a special row segment
382 segment = new AliMpRowSegmentLSpecial(row, offsetX);
383 row->AddRowSegmentInFront(segment);
386 AliMpVRowSegment* precedentNormalSeg
387 = row->GetRowSegment(row->GetNofRowSegments()-1);
388 Double_t offsetX = precedentNormalSeg->RightBorderX();
390 // Create a special row segment
391 segment = new AliMpRowSegmentRSpecial(row, offsetX);
392 row->AddRowSegment(segment);
398 AliDebugStream(2) << nextKeyword << endl;
400 if (nextKeyword != fgkPadRowsKeyword) {
401 Fatal("ReadRowSpecialData", "Wrong file format.");
405 ReadRowSegmentSpecialData(in, segment, direction);
407 // Update row segment and set it to all subzones associated with
410 segment->UpdateMotifVector();
411 segment->UpdatePadsOffset();
413 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
414 AliMpSubZone* subZone = 0;
416 while (!subZone && j<fSector->GetNofZones())
417 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
419 subZone->AddRowSegment(segment);
423 //_____________________________________________________________________________
424 void AliMpSectorReader::ReadRowSegmentSpecialData(istream& in,
425 AliMpVRowSegmentSpecial* segment,
426 AliMp::XDirection direction)
428 /// Read row segment input data
429 /// with a special (irregular) motifs.
434 AliDebugStream(2) << nofPadRows << endl;
439 AliDebugStream(2) << keyword << endl;
441 if (keyword != fgkPadRowSegmentKeyword) {
442 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
450 AliMpVRowSegmentSpecial::PadRowVector newPadRows;
451 for (Int_t i=0; i<nofPadRows; i++) {
454 AliMpPadRow* padRow = new AliMpPadRow(direction);
455 segment->AddPadRow(padRow);
457 // Keep the new rows in a temporary vector
459 newPadRows.push_back(padRow);
462 newPadRows.Add(padRow);
469 // Read data from file
471 Int_t nofPadsInRow, motifPositionId;
472 TString motifId, motifTypeId;
475 in >> motifPositionId;
477 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
480 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
484 AliDebugStream(2) << nextKeyword << endl;
490 for (Int_t i=0; i<nofPadRows; i++) {
492 // Get pad row from the temporary vector
494 AliMpPadRow* padRow = newPadRows[i];
497 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
501 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
504 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
508 // Create pad row segment
509 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
510 motifPositionId, nofPadsInRow);
513 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
515 if (in.eof()) return;
517 if (nextKeyword == fgkPadRowsKeyword) {
518 ReadRowSegmentSpecialData(in, segment, direction);
520 else if (nextKeyword == fgkRowSpecialKeyword) {
521 ReadRowSpecialData(in, direction);
524 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
532 //_____________________________________________________________________________
533 AliMpSector* AliMpSectorReader::BuildSector()
535 /// Read the mapping data from stream and create the basic objects: \n
536 /// zones, subzones, rows, row segments, motifs.
541 = AliMpDataStreams::Instance()
542 ->CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
547 fSector->SetRowSegmentOffsets();
549 // Open input stream for special inner zone
551 // add is data function
553 TString sectorSpecialFileName
554 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
555 if ( AliMpDataStreams::Instance()-> IsDataStream(sectorSpecialFileName) ) {
557 = AliMpDataStreams::Instance()
558 ->CreateDataStream(sectorSpecialFileName);
560 ReadSectorSpecialData(in2, AliMp::kLeft);
565 // Open input file for special outer zone
566 TString sectorSpecialFileName2
567 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
568 if ( AliMpDataStreams::Instance()-> IsDataStream(sectorSpecialFileName2) ) {
570 = AliMpDataStreams::Instance()
571 ->CreateDataStream(sectorSpecialFileName2);
573 ReadSectorSpecialData(in3, AliMp::kRight);
578 fSector->Initialize();