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,
133 TVector2(offsetX, offsetY));
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(TVector2(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, zone->GetPadDimensions());
216 motifType = motifMap->FindMotifType(motifTypeID);
218 motifType = fMotifReader->BuildMotifType(motifTypeID);
219 motifMap->AddMotifType(motifType);
222 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
223 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
225 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
228 motifMap->AddMotif(motif);
235 //_____________________________________________________________________________
236 void AliMpSectorReader::ReadRowSegmentsData(istream& in,
237 AliMpZone* zone, AliMpSubZone* subZone)
239 /// Read row segments input data of a specified zone and subzone;
240 /// creates row segment and add it to the specified subzone
241 /// and a corresponding row in the rows vector.
246 // Read data from file
248 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
253 in >> firstMotifPositionId;
254 in >> firstMotifPositionDId;
256 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
259 << fgkRowKeyword << " "
260 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
261 << firstMotifPositionId << " " << firstMotifPositionDId
269 AliMpRow* row = fSector->GetRow(inRow);
270 AliMpVMotif* motif = subZone->GetMotif();
272 // Create row segment and add it to its zone, row
273 AliMpVRowSegment* rowSegment
274 = new AliMpRowSegment(row, motif, offX, offY, nofMotifs,
275 firstMotifPositionId, firstMotifPositionDId);
277 subZone->AddRowSegment(rowSegment);
278 row->AddRowSegment(rowSegment);
280 while (!in.eof() && (nextKeyword == fgkRowKeyword));
282 if (in.eof()) return;
284 if (nextKeyword == fgkZoneKeyword) {
287 else if (nextKeyword == fgkSubZoneKeyword) {
288 ReadSubZoneData(in, zone);
291 Fatal("ReadRowSegmentsData", "Wrong file format.");
295 //_____________________________________________________________________________
296 void AliMpSectorReader::ReadSectorSpecialData(istream& in, AliMp::XDirection direction)
298 /// Read sector input data
299 /// with a special (irregular) motifs.
304 AliDebugStream(2) << keyword << endl;
306 if (keyword != fgkSectorSpecialKeyword) {
307 Fatal("ReadSectorSpecialData", "Wrong file format.");
314 AliDebugStream(2) << keyword << endl;
316 if (nextKeyword != fgkMotifKeyword) {
317 Fatal("ReadSectorSpecialData", "Wrong file format.");
321 ReadMotifsSpecialData(in);
322 ReadRowSpecialData(in, direction);
325 //_____________________________________________________________________________
326 void AliMpSectorReader::ReadMotifsSpecialData(istream& in)
328 /// Read the special (irregular) motifs input data.
330 AliDebugStream(2) << fgkMotifKeyword << endl;
336 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
337 AliMpSubZone* subZone = new AliMpSubZone(motif);
338 fSector->GetZone(zone)->AddSubZone(subZone);
342 AliDebugStream(2) << nextKeyword << endl;
344 while (nextKeyword == fgkMotifKeyword);
346 if (nextKeyword != fgkRowSpecialKeyword) {
347 Fatal("ReadMotifSpecialData", "Wrong file format.");
352 //_____________________________________________________________________________
353 void AliMpSectorReader::ReadRowSpecialData(istream& in, AliMp::XDirection direction)
355 /// Read row input data
356 /// with a special (irregular) motifs.
361 AliDebugStream(2) << id << endl;
363 // Get the row and its border
364 AliMpRow* row = fSector->GetRow(id);
366 AliMpVRowSegmentSpecial* segment = 0;
367 if (direction == AliMp::kLeft) {
368 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
369 Double_t offsetX = firstNormalSeg->LeftBorderX();
371 // Create a special row segment
372 segment = new AliMpRowSegmentLSpecial(row, offsetX);
373 row->AddRowSegmentInFront(segment);
376 AliMpVRowSegment* precedentNormalSeg
377 = row->GetRowSegment(row->GetNofRowSegments()-1);
378 Double_t offsetX = precedentNormalSeg->RightBorderX();
380 // Create a special row segment
381 segment = new AliMpRowSegmentRSpecial(row, offsetX);
382 row->AddRowSegment(segment);
388 AliDebugStream(2) << nextKeyword << endl;
390 if (nextKeyword != fgkPadRowsKeyword) {
391 Fatal("ReadRowSpecialData", "Wrong file format.");
395 ReadRowSegmentSpecialData(in, segment, direction);
397 // Update row segment and set it to all subzones associated with
400 segment->UpdateMotifVector();
401 segment->UpdatePadsOffset();
403 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
404 AliMpSubZone* subZone = 0;
406 while (!subZone && j<fSector->GetNofZones())
407 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
409 subZone->AddRowSegment(segment);
413 //_____________________________________________________________________________
414 void AliMpSectorReader::ReadRowSegmentSpecialData(istream& in,
415 AliMpVRowSegmentSpecial* segment,
416 AliMp::XDirection direction)
418 /// Read row segment input data
419 /// with a special (irregular) motifs.
424 AliDebugStream(2) << nofPadRows << endl;
429 AliDebugStream(2) << keyword << endl;
431 if (keyword != fgkPadRowSegmentKeyword) {
432 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
440 TObjArray newPadRows;
441 for (Int_t i=0; i<nofPadRows; i++) {
444 AliMpPadRow* padRow = new AliMpPadRow(direction);
445 segment->AddPadRow(padRow);
447 // Keep the new rows in a temporary vector
448 newPadRows.Add(padRow);
454 // Read data from file
456 Int_t nofPadsInRow, motifPositionId;
457 TString motifId, motifTypeId;
460 in >> motifPositionId;
462 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
465 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
469 AliDebugStream(2) << nextKeyword << endl;
475 for (Int_t i=0; i<nofPadRows; i++) {
477 // Get pad row from the temporary vector
478 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
481 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
484 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
488 // Create pad row segment
489 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
490 motifPositionId, nofPadsInRow);
493 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
495 if (in.eof()) return;
497 if (nextKeyword == fgkPadRowsKeyword) {
498 ReadRowSegmentSpecialData(in, segment, direction);
500 else if (nextKeyword == fgkRowSpecialKeyword) {
501 ReadRowSpecialData(in, direction);
504 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
512 //_____________________________________________________________________________
513 AliMpSector* AliMpSectorReader::BuildSector()
515 /// Read the mapping data from stream and create the basic objects: \n
516 /// zones, subzones, rows, row segments, motifs.
522 CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
527 fSector->SetRowSegmentOffsets();
529 // Open input stream for special inner zone
531 // add is data function
533 TString sectorSpecialFileName
534 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
535 if ( fkDataStreams.IsDataStream(sectorSpecialFileName) ) {
538 CreateDataStream(sectorSpecialFileName);
540 ReadSectorSpecialData(in2, AliMp::kLeft);
545 // Open input file for special outer zone
546 TString sectorSpecialFileName2
547 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
548 if ( fkDataStreams.IsDataStream(sectorSpecialFileName2) ) {
551 CreateDataStream(sectorSpecialFileName2);
553 ReadSectorSpecialData(in3, AliMp::kRight);
558 fSector->Initialize();