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.4 2005/09/02 10:01:09 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 #if !defined(__HP_aCC) && !defined(__alpha)
30 #include <Riostream.h>
31 #include <Rstrstream.h>
36 #include "AliMpSectorReader.h"
37 #include "AliMpSector.h"
38 #include "AliMpFiles.h"
39 #include "AliMpZone.h"
40 #include "AliMpSubZone.h"
42 #include "AliMpVRowSegment.h"
43 #include "AliMpRowSegment.h"
44 #include "AliMpRowSegmentLSpecial.h"
45 #include "AliMpRowSegmentRSpecial.h"
46 #include "AliMpPadRow.h"
47 #include "AliMpMotifReader.h"
48 #include "AliMpMotifMap.h"
49 #include "AliMpMotif.h"
50 #include "AliMpMotifSpecial.h"
51 #include "AliMpMotifType.h"
52 #include "AliMpConnection.h"
53 #include "AliMpIntPair.h"
54 #include "AliMpDirection.h"
56 ClassImp(AliMpSectorReader)
58 const TString AliMpSectorReader::fgkSectorKeyword = "SECTOR_DATA";
59 const TString AliMpSectorReader::fgkZoneKeyword = "ZONE";
60 const TString AliMpSectorReader::fgkSubZoneKeyword = "SUBZONE";
61 const TString AliMpSectorReader::fgkRowKeyword = "ROW_SEGMENT";
62 const TString AliMpSectorReader::fgkEofKeyword = "EOF";
63 const TString AliMpSectorReader::fgkSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
64 const TString AliMpSectorReader::fgkMotifKeyword = "MOTIF";
65 const TString AliMpSectorReader::fgkRowSpecialKeyword = "ROW";
66 const TString AliMpSectorReader::fgkPadRowsKeyword = "PAD_ROWS";
67 const TString AliMpSectorReader::fgkPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
69 //_____________________________________________________________________________
70 AliMpSectorReader::AliMpSectorReader(AliMpStationType station,
73 fStationType(station),
76 fMotifReader(new AliMpMotifReader(station, plane)),
79 // Standard constructor
82 //_____________________________________________________________________________
83 AliMpSectorReader::AliMpSectorReader()
85 fStationType(kStation1),
86 fPlaneType(kBendingPlane),
91 // Default constructor
94 //_____________________________________________________________________________
95 AliMpSectorReader::AliMpSectorReader(const AliMpSectorReader& right)
98 /// Protected copy constructor (not provided)
100 Fatal("AliMpSectorReader", "Copy constructor not provided.");
103 //_____________________________________________________________________________
104 AliMpSectorReader::~AliMpSectorReader()
115 //_____________________________________________________________________________
116 AliMpSectorReader& AliMpSectorReader::operator=(const AliMpSectorReader& right)
118 /// Protected assignment operator (not provided)
120 // check assignment to self
121 if (this == &right) return *this;
123 Fatal("operator =", "Assignment operator not provided.");
132 //_____________________________________________________________________________
133 void AliMpSectorReader::ReadSectorData(ifstream& in)
135 /// Read sector input data;
136 /// prepare zones and rows vectors to be filled in.
142 cout << keyword << endl;
144 if (keyword != fgkSectorKeyword) {
145 Fatal("ReadSectorData", "Wrong file format.");
149 Int_t nofZones, nofRows;
150 TString directionStr;
151 Double_t offsetX, offsetY;
158 AliMpDirection direction;
159 direction = (directionStr == "Y") ? kY : kX;
161 cout << nofZones << " " << nofRows << endl;
163 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
164 TVector2(offsetX, offsetY));
169 if (nextKeyword != fgkZoneKeyword) {
170 Fatal("ReadSectorData", "Wrong file format.");
177 //_____________________________________________________________________________
178 void AliMpSectorReader::ReadZoneData(ifstream& in)
180 /// Read zone input data;
181 /// create zone and adds it to zones vector.
184 Double_t sizex, sizey;
189 cout << fgkZoneKeyword << " " << zoneID << " "
190 << sizex << " " << sizey << endl;
192 AliMpZone* zone = fSector->GetZone(zoneID);
193 zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.));
198 if (nextKeyword != fgkSubZoneKeyword) {
199 Fatal("ReadZoneData", "Wrong file format.");
203 ReadSubZoneData(in, zone);
206 //_____________________________________________________________________________
207 void AliMpSectorReader::ReadSubZoneData(ifstream& in, AliMpZone* zone)
209 /// Read subzone input data;
210 /// create subzone and its to the specified zone.
213 cout << fgkSubZoneKeyword << " ";
215 AliMpVMotif* motif = ReadMotifData(in, zone);
216 AliMpSubZone* subZone = new AliMpSubZone(motif);
217 zone->AddSubZone(subZone);
222 if (nextKeyword != fgkRowKeyword) {
223 Fatal("ReadSubZoneData", "Wrong file format.");
227 ReadRowSegmentsData(in, zone, subZone);
230 //_____________________________________________________________________________
231 AliMpVMotif* AliMpSectorReader::ReadMotifData(ifstream& in, AliMpZone* zone)
233 /// Read the motif input data.
239 if (fVerboseLevel>0) {
240 cout << motifID << " "
241 << motifTypeID << endl;
244 AliMpMotifMap* motifMap = fSector->GetMotifMap();
246 AliMpMotifType* motifType = 0;
248 = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
250 motifType = motifMap->FindMotifType(motifTypeID);
252 motifType = fMotifReader->BuildMotifType(motifTypeID);
253 motifMap->AddMotifType(motifType);
256 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
257 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
259 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
262 motifMap->AddMotif(motif);
269 //_____________________________________________________________________________
270 void AliMpSectorReader::ReadRowSegmentsData(ifstream& in,
271 AliMpZone* zone, AliMpSubZone* subZone)
273 /// Read row segments input data of a specified zone and subzone;
274 /// creates row segment and add it to the specified subzone
275 /// and a corresponding row in the rows vector.
280 // Read data from file
282 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
287 in >> firstMotifPositionId;
288 in >> firstMotifPositionDId;
290 cout << fgkRowKeyword << " "
291 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
292 << firstMotifPositionId << " " << firstMotifPositionDId
300 AliMpRow* row = fSector->GetRow(inRow);
301 AliMpVMotif* motif = subZone->GetMotif();
303 // Create row segment and add it to its zone, row
304 AliMpVRowSegment* rowSegment
305 = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs,
306 firstMotifPositionId, firstMotifPositionDId);
308 subZone->AddRowSegment(rowSegment);
309 row->AddRowSegment(rowSegment);
311 while (!in.eof() && (nextKeyword == fgkRowKeyword));
313 if (in.eof()) return;
315 if (nextKeyword == fgkZoneKeyword) {
318 else if (nextKeyword == fgkSubZoneKeyword) {
319 ReadSubZoneData(in, zone);
322 Fatal("ReadRowSegmentsData", "Wrong file format.");
326 //_____________________________________________________________________________
327 void AliMpSectorReader::ReadSectorSpecialData(ifstream& in, AliMpXDirection direction)
329 /// Read sector input data
330 /// with a special (irregular) motifs.
335 cout << keyword << endl;
337 if (keyword != fgkSectorSpecialKeyword) {
338 Fatal("ReadSectorSpecialData", "Wrong file format.");
345 cout << keyword << endl;
347 if (nextKeyword != fgkMotifKeyword) {
348 Fatal("ReadSectorSpecialData", "Wrong file format.");
352 ReadMotifsSpecialData(in);
353 ReadRowSpecialData(in, direction);
356 //_____________________________________________________________________________
357 void AliMpSectorReader::ReadMotifsSpecialData(ifstream& in)
359 /// Read the special (irregular) motifs input data.
362 cout << fgkMotifKeyword << " ";
368 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
369 AliMpSubZone* subZone = new AliMpSubZone(motif);
370 fSector->GetZone(zone)->AddSubZone(subZone);
374 cout << nextKeyword << " ";
376 while (nextKeyword == fgkMotifKeyword);
378 if (nextKeyword != fgkRowSpecialKeyword) {
379 Fatal("ReadMotifSpecialData", "Wrong file format.");
384 //_____________________________________________________________________________
385 void AliMpSectorReader::ReadRowSpecialData(ifstream& in, AliMpXDirection direction)
387 /// Read row input data
388 /// with a special (irregular) motifs.
395 // Get the row and its border
396 AliMpRow* row = fSector->GetRow(id);
398 AliMpVRowSegmentSpecial* segment = 0;
399 if (direction == kLeft) {
400 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
401 Double_t offsetX = firstNormalSeg->LeftBorderX();
403 // Create a special row segment
404 segment = new AliMpRowSegmentLSpecial(row, offsetX);
405 row->AddRowSegmentInFront(segment);
408 AliMpVRowSegment* precedentNormalSeg
409 = row->GetRowSegment(row->GetNofRowSegments()-1);
410 Double_t offsetX = precedentNormalSeg->RightBorderX();
412 // Create a special row segment
413 segment = new AliMpRowSegmentRSpecial(row, offsetX);
414 row->AddRowSegment(segment);
420 cout << nextKeyword << " ";
422 if (nextKeyword != fgkPadRowsKeyword) {
423 Fatal("ReadRowSpecialData", "Wrong file format.");
427 ReadRowSegmentSpecialData(in, segment, direction);
429 // Update row segment and set it to all subzones associated with
432 segment->UpdateMotifVector();
433 segment->UpdatePadsOffset();
435 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
436 AliMpSubZone* subZone = 0;
438 while (!subZone && j<fSector->GetNofZones())
439 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
441 subZone->AddRowSegment(segment);
445 //_____________________________________________________________________________
446 void AliMpSectorReader::ReadRowSegmentSpecialData(ifstream& in,
447 AliMpVRowSegmentSpecial* segment,
448 AliMpXDirection direction)
450 /// Read row segment input data
451 /// with a special (irregular) motifs.
456 cout << nofPadRows << endl;
461 cout << keyword << " ";
463 if (keyword != fgkPadRowSegmentKeyword) {
464 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
472 PadRowVector newPadRows;
473 for (Int_t i=0; i<nofPadRows; i++) {
476 AliMpPadRow* padRow = new AliMpPadRow(direction);
477 segment->AddPadRow(padRow);
479 // Keep the new rows in a temporary vector
481 newPadRows.push_back(padRow);
484 newPadRows.Add(padRow);
491 // Read data from file
493 Int_t nofPadsInRow, motifPositionId;
494 TString motifId, motifTypeId;
497 in >> motifPositionId;
500 cout << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
504 cout << nextKeyword << " ";
510 for (Int_t i=0; i<nofPadRows; i++) {
512 // Get pad row from the temporary vector
514 AliMpPadRow* padRow = newPadRows[i];
517 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
521 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
524 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
528 // Create pad row segment
529 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
530 motifPositionId, nofPadsInRow);
533 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
535 if (in.eof()) return;
537 if (nextKeyword == fgkPadRowsKeyword) {
538 ReadRowSegmentSpecialData(in, segment, direction);
540 else if (nextKeyword == fgkRowSpecialKeyword) {
541 ReadRowSpecialData(in, direction);
544 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
552 //_____________________________________________________________________________
553 AliMpSector* AliMpSectorReader::BuildSector()
555 /// Read the mapping data from ascii data file
556 /// and create the basic objects: \n
557 /// zones, subzones, rows, row segments, motifs.
560 ifstream in(AliMpFiles::Instance()
561 ->SectorFilePath(fStationType, fPlaneType).Data(), ios::in);
563 cerr << AliMpFiles::Instance()
564 ->SectorFilePath(fStationType, fPlaneType) << endl;
565 Error("BuildSector", "File not found.");
570 fSector->SetRowSegmentOffsets();
572 // Open input file for special inner zone
573 TString sectorSpecialFileName
574 = AliMpFiles::Instance()->SectorSpecialFilePath(fStationType, fPlaneType);
575 if (!gSystem->AccessPathName(sectorSpecialFileName.Data())) {
576 ifstream in2(sectorSpecialFileName.Data(), ios::in);
578 cerr << AliMpFiles::Instance()
579 ->SectorSpecialFilePath(fStationType, fPlaneType) << endl;
580 Error("BuildSector", "File not found.");
584 ReadSectorSpecialData(in2, kLeft);
587 // Open input file for special outer zone
588 TString sectorSpecialFileName2
589 = AliMpFiles::Instance()->SectorSpecialFilePath2(fStationType, fPlaneType);
590 if (!gSystem->AccessPathName(sectorSpecialFileName2.Data())) {
591 ifstream in3(sectorSpecialFileName2.Data(), ios::in);
593 cerr << AliMpFiles::Instance()
594 ->SectorSpecialFilePath2(fStationType, fPlaneType) << endl;
595 Error("Build", "File not found.");
599 ReadSectorSpecialData(in3, kRight);
602 fSector->Initialize();
607 //_____________________________________________________________________________
608 void AliMpSectorReader::SetVerboseLevel(Int_t verboseLevel)
610 /// Set verbose level.
612 fVerboseLevel = verboseLevel;
613 if (fMotifReader) fMotifReader->SetVerboseLevel(verboseLevel);