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 // Class AliMpSectorReader
21 // -----------------------
22 // Class that takes care of reading the sector data.
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 #include "AliMpSectorReader.h"
27 #include "AliMpSector.h"
28 #include "AliMpFiles.h"
29 #include "AliMpZone.h"
30 #include "AliMpSubZone.h"
32 #include "AliMpVRowSegment.h"
33 #include "AliMpRowSegment.h"
34 #include "AliMpRowSegmentLSpecial.h"
35 #include "AliMpRowSegmentRSpecial.h"
36 #include "AliMpPadRow.h"
37 #include "AliMpMotifReader.h"
38 #include "AliMpMotifMap.h"
39 #include "AliMpMotif.h"
40 #include "AliMpMotifSpecial.h"
41 #include "AliMpMotifType.h"
42 #include "AliMpConnection.h"
43 #include "AliMpIntPair.h"
44 #include "AliMpDirection.h"
45 #include "AliMpConstants.h"
49 #include <Riostream.h>
50 #include <Rstrstream.h>
54 #if !defined(__HP_aCC) && !defined(__alpha)
59 ClassImp(AliMpSectorReader)
62 const TString AliMpSectorReader::fgkSectorKeyword = "SECTOR_DATA";
63 const TString AliMpSectorReader::fgkZoneKeyword = "ZONE";
64 const TString AliMpSectorReader::fgkSubZoneKeyword = "SUBZONE";
65 const TString AliMpSectorReader::fgkRowKeyword = "ROW_SEGMENT";
66 const TString AliMpSectorReader::fgkEofKeyword = "EOF";
67 const TString AliMpSectorReader::fgkSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
68 const TString AliMpSectorReader::fgkMotifKeyword = "MOTIF";
69 const TString AliMpSectorReader::fgkRowSpecialKeyword = "ROW";
70 const TString AliMpSectorReader::fgkPadRowsKeyword = "PAD_ROWS";
71 const TString AliMpSectorReader::fgkPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
73 //_____________________________________________________________________________
74 AliMpSectorReader::AliMpSectorReader(AliMpStationType station,
77 fStationType(station),
80 fMotifReader(new AliMpMotifReader(station, plane))
82 // Standard constructor
85 //_____________________________________________________________________________
86 AliMpSectorReader::AliMpSectorReader()
88 fStationType(kStation1),
89 fPlaneType(kBendingPlane),
93 // Default constructor
96 //_____________________________________________________________________________
97 AliMpSectorReader::~AliMpSectorReader()
108 //_____________________________________________________________________________
109 void AliMpSectorReader::ReadSectorData(ifstream& in)
111 /// Read sector input data;
112 /// prepare zones and rows vectors to be filled in.
117 AliDebugStream(2) << keyword << endl;
119 if (keyword != fgkSectorKeyword) {
120 Fatal("ReadSectorData", "Wrong file format.");
124 Int_t nofZones, nofRows;
125 TString directionStr;
126 Double_t offsetX, offsetY;
133 AliMpDirection direction;
134 direction = (directionStr == "Y") ? kY : kX;
136 AliDebugStream(2) << nofZones << " " << nofRows << endl;
138 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
139 TVector2(offsetX, offsetY));
144 if (nextKeyword != fgkZoneKeyword) {
145 Fatal("ReadSectorData", "Wrong file format.");
152 //_____________________________________________________________________________
153 void AliMpSectorReader::ReadZoneData(ifstream& in)
155 /// Read zone input data;
156 /// create zone and adds it to zones vector.
159 Double_t sizex, sizey;
164 << fgkZoneKeyword << " " << zoneID << " "
165 << sizex << " " << sizey << endl;
167 AliMpZone* zone = fSector->GetZone(zoneID);
168 zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.));
173 if (nextKeyword != fgkSubZoneKeyword) {
174 Fatal("ReadZoneData", "Wrong file format.");
178 ReadSubZoneData(in, zone);
181 //_____________________________________________________________________________
182 void AliMpSectorReader::ReadSubZoneData(ifstream& in, AliMpZone* zone)
184 /// Read subzone input data;
185 /// create subzone and its to the specified zone.
187 AliDebugStream(2) << fgkSubZoneKeyword << endl;
189 AliMpVMotif* motif = ReadMotifData(in, zone);
190 AliMpSubZone* subZone = new AliMpSubZone(motif);
191 zone->AddSubZone(subZone);
196 if (nextKeyword != fgkRowKeyword) {
197 Fatal("ReadSubZoneData", "Wrong file format.");
201 ReadRowSegmentsData(in, zone, subZone);
204 //_____________________________________________________________________________
205 AliMpVMotif* AliMpSectorReader::ReadMotifData(ifstream& in, AliMpZone* zone)
207 /// Read the motif input data.
214 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
216 AliMpMotifMap* motifMap = fSector->GetMotifMap();
218 AliMpMotifType* motifType = 0;
220 = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
222 motifType = motifMap->FindMotifType(motifTypeID);
224 motifType = fMotifReader->BuildMotifType(motifTypeID);
225 motifMap->AddMotifType(motifType);
228 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
229 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
231 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
234 motifMap->AddMotif(motif);
241 //_____________________________________________________________________________
242 void AliMpSectorReader::ReadRowSegmentsData(ifstream& in,
243 AliMpZone* zone, AliMpSubZone* subZone)
245 /// Read row segments input data of a specified zone and subzone;
246 /// creates row segment and add it to the specified subzone
247 /// and a corresponding row in the rows vector.
252 // Read data from file
254 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
259 in >> firstMotifPositionId;
260 in >> firstMotifPositionDId;
262 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
265 << fgkRowKeyword << " "
266 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
267 << firstMotifPositionId << " " << firstMotifPositionDId
275 AliMpRow* row = fSector->GetRow(inRow);
276 AliMpVMotif* motif = subZone->GetMotif();
278 // Create row segment and add it to its zone, row
279 AliMpVRowSegment* rowSegment
280 = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs,
281 firstMotifPositionId, firstMotifPositionDId);
283 subZone->AddRowSegment(rowSegment);
284 row->AddRowSegment(rowSegment);
286 while (!in.eof() && (nextKeyword == fgkRowKeyword));
288 if (in.eof()) return;
290 if (nextKeyword == fgkZoneKeyword) {
293 else if (nextKeyword == fgkSubZoneKeyword) {
294 ReadSubZoneData(in, zone);
297 Fatal("ReadRowSegmentsData", "Wrong file format.");
301 //_____________________________________________________________________________
302 void AliMpSectorReader::ReadSectorSpecialData(ifstream& in, AliMpXDirection direction)
304 /// Read sector input data
305 /// with a special (irregular) motifs.
310 AliDebugStream(2) << keyword << endl;
312 if (keyword != fgkSectorSpecialKeyword) {
313 Fatal("ReadSectorSpecialData", "Wrong file format.");
320 AliDebugStream(2) << keyword << endl;
322 if (nextKeyword != fgkMotifKeyword) {
323 Fatal("ReadSectorSpecialData", "Wrong file format.");
327 ReadMotifsSpecialData(in);
328 ReadRowSpecialData(in, direction);
331 //_____________________________________________________________________________
332 void AliMpSectorReader::ReadMotifsSpecialData(ifstream& in)
334 /// Read the special (irregular) motifs input data.
336 AliDebugStream(2) << fgkMotifKeyword << endl;
342 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
343 AliMpSubZone* subZone = new AliMpSubZone(motif);
344 fSector->GetZone(zone)->AddSubZone(subZone);
348 AliDebugStream(2) << nextKeyword << endl;
350 while (nextKeyword == fgkMotifKeyword);
352 if (nextKeyword != fgkRowSpecialKeyword) {
353 Fatal("ReadMotifSpecialData", "Wrong file format.");
358 //_____________________________________________________________________________
359 void AliMpSectorReader::ReadRowSpecialData(ifstream& in, AliMpXDirection direction)
361 /// Read row input data
362 /// with a special (irregular) motifs.
367 AliDebugStream(2) << id << endl;
369 // Get the row and its border
370 AliMpRow* row = fSector->GetRow(id);
372 AliMpVRowSegmentSpecial* segment = 0;
373 if (direction == kLeft) {
374 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
375 Double_t offsetX = firstNormalSeg->LeftBorderX();
377 // Create a special row segment
378 segment = new AliMpRowSegmentLSpecial(row, offsetX);
379 row->AddRowSegmentInFront(segment);
382 AliMpVRowSegment* precedentNormalSeg
383 = row->GetRowSegment(row->GetNofRowSegments()-1);
384 Double_t offsetX = precedentNormalSeg->RightBorderX();
386 // Create a special row segment
387 segment = new AliMpRowSegmentRSpecial(row, offsetX);
388 row->AddRowSegment(segment);
394 AliDebugStream(2) << nextKeyword << endl;
396 if (nextKeyword != fgkPadRowsKeyword) {
397 Fatal("ReadRowSpecialData", "Wrong file format.");
401 ReadRowSegmentSpecialData(in, segment, direction);
403 // Update row segment and set it to all subzones associated with
406 segment->UpdateMotifVector();
407 segment->UpdatePadsOffset();
409 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
410 AliMpSubZone* subZone = 0;
412 while (!subZone && j<fSector->GetNofZones())
413 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
415 subZone->AddRowSegment(segment);
419 //_____________________________________________________________________________
420 void AliMpSectorReader::ReadRowSegmentSpecialData(ifstream& in,
421 AliMpVRowSegmentSpecial* segment,
422 AliMpXDirection direction)
424 /// Read row segment input data
425 /// with a special (irregular) motifs.
430 AliDebugStream(2) << nofPadRows << endl;
435 AliDebugStream(2) << keyword << endl;
437 if (keyword != fgkPadRowSegmentKeyword) {
438 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
446 AliMpVRowSegmentSpecial::PadRowVector newPadRows;
447 for (Int_t i=0; i<nofPadRows; i++) {
450 AliMpPadRow* padRow = new AliMpPadRow(direction);
451 segment->AddPadRow(padRow);
453 // Keep the new rows in a temporary vector
455 newPadRows.push_back(padRow);
458 newPadRows.Add(padRow);
465 // Read data from file
467 Int_t nofPadsInRow, motifPositionId;
468 TString motifId, motifTypeId;
471 in >> motifPositionId;
473 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
476 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
480 AliDebugStream(2) << nextKeyword << endl;
486 for (Int_t i=0; i<nofPadRows; i++) {
488 // Get pad row from the temporary vector
490 AliMpPadRow* padRow = newPadRows[i];
493 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
497 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
500 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
504 // Create pad row segment
505 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
506 motifPositionId, nofPadsInRow);
509 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
511 if (in.eof()) return;
513 if (nextKeyword == fgkPadRowsKeyword) {
514 ReadRowSegmentSpecialData(in, segment, direction);
516 else if (nextKeyword == fgkRowSpecialKeyword) {
517 ReadRowSpecialData(in, direction);
520 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
528 //_____________________________________________________________________________
529 AliMpSector* AliMpSectorReader::BuildSector()
531 /// Read the mapping data from ascii data file
532 /// and create the basic objects: \n
533 /// zones, subzones, rows, row segments, motifs.
536 ifstream in(AliMpFiles::SectorFilePath(fStationType, fPlaneType).Data(), ios::in);
539 << "File " << AliMpFiles::SectorFilePath(fStationType, fPlaneType)
540 << " not found." << endl;
545 fSector->SetRowSegmentOffsets();
547 // Open input file for special inner zone
548 TString sectorSpecialFileName
549 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
550 if (!gSystem->AccessPathName(sectorSpecialFileName.Data())) {
551 ifstream in2(sectorSpecialFileName.Data(), ios::in);
554 << "File " << AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType)
555 << " not found." << endl;
559 ReadSectorSpecialData(in2, kLeft);
562 // Open input file for special outer zone
563 TString sectorSpecialFileName2
564 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
565 if (!gSystem->AccessPathName(sectorSpecialFileName2.Data())) {
566 ifstream in3(sectorSpecialFileName2.Data(), ios::in);
569 << "File " << AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType)
570 << " not found."<< endl;
574 ReadSectorSpecialData(in3, kRight);
577 fSector->Initialize();