6 // Class that takes care of reading the sector data.
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
11 #if !defined(__HP_aCC) && !defined(__alpha)
15 #include <Riostream.h>
16 #include <Rstrstream.h>
21 #include "AliMpReader.h"
22 #include "AliMpSector.h"
23 #include "AliMpFiles.h"
24 #include "AliMpZone.h"
25 #include "AliMpSubZone.h"
27 #include "AliMpVRowSegment.h"
28 #include "AliMpRowSegment.h"
29 #include "AliMpRowSegmentSpecial.h"
30 #include "AliMpPadRow.h"
31 #include "AliMpPadRowSegment.h"
32 #include "AliMpMotifMap.h"
33 #include "AliMpMotif.h"
34 #include "AliMpMotifSpecial.h"
35 #include "AliMpMotifType.h"
36 #include "AliMpConnection.h"
37 #include "AliMpIntPair.h"
38 #include "AliMpDirection.h"
42 const TString AliMpReader::fgkSectorKeyword = "SECTOR_DATA";
43 const TString AliMpReader::fgkZoneKeyword = "ZONE";
44 const TString AliMpReader::fgkSubZoneKeyword = "SUBZONE";
45 const TString AliMpReader::fgkRowKeyword = "ROW_SEGMENT";
46 const TString AliMpReader::fgkEofKeyword = "EOF";
47 const TString AliMpReader::fgkSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
48 const TString AliMpReader::fgkMotifKeyword = "MOTIF";
49 const TString AliMpReader::fgkRowSpecialKeyword = "ROW";
50 const TString AliMpReader::fgkPadRowsKeyword = "PAD_ROWS";
51 const TString AliMpReader::fgkPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
53 //_____________________________________________________________________________
54 AliMpReader::AliMpReader(AliMpPlaneType plane)
63 //_____________________________________________________________________________
64 AliMpReader::AliMpReader()
66 fPlaneType(kBendingPlane),
73 //_____________________________________________________________________________
74 AliMpReader::~AliMpReader() {
82 //_____________________________________________________________________________
83 void AliMpReader::ReadSectorData(ifstream& in)
85 // Reads sector input data;
86 // prepares zones and rows vectors to be filled in.
93 cout << keyword << endl;
95 if (keyword != fgkSectorKeyword) {
96 Fatal("ReadSectorData", "Wrong file format.");
100 Int_t nofZones, nofRows;
101 TString directionStr;
106 AliMpDirection direction;
107 direction = (directionStr == "Y") ? kY : kX;
109 cout << nofZones << " " << nofRows << endl;
111 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction);
116 if (nextKeyword != fgkZoneKeyword) {
117 Fatal("ReadSectorData", "Wrong file format.");
124 //_____________________________________________________________________________
125 void AliMpReader::ReadZoneData(ifstream& in)
127 // Reads zone input data;
128 // creates zone and adds it to zones vector.
132 Double_t sizex, sizey;
137 cout << fgkZoneKeyword << " " << zoneID << " "
138 << sizex << " " << sizey << endl;
140 AliMpZone* zone = fSector->GetZone(zoneID);
141 zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.));
146 if (nextKeyword != fgkSubZoneKeyword) {
147 Fatal("ReadZoneData", "Wrong file format.");
151 ReadSubZoneData(in, zone);
154 //_____________________________________________________________________________
155 void AliMpReader::ReadSubZoneData(ifstream& in, AliMpZone* zone)
157 // Reads subzone input data;
158 // creates subzone and its to the specified zone.
162 cout << fgkSubZoneKeyword << " ";
164 AliMpVMotif* motif = ReadMotifData(in, zone);
165 AliMpSubZone* subZone = new AliMpSubZone(motif);
166 zone->AddSubZone(subZone);
171 if (nextKeyword != fgkRowKeyword) {
172 Fatal("ReadSubZoneData", "Wrong file format.");
176 ReadRowSegmentsData(in, zone, subZone);
179 //_____________________________________________________________________________
180 AliMpVMotif* AliMpReader::ReadMotifData(ifstream& in, AliMpZone* zone)
182 // Reads the motif input data.
189 if (fVerboseLevel>0) {
190 cout << motifID << " "
191 << motifTypeID << endl;
194 AliMpMotifMap* motifMap = fSector->GetMotifMap();
196 AliMpMotifType* motifType = 0;
198 = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
200 motifType = motifMap->FindMotifType(motifTypeID);
202 motifType = BuildMotifType(motifTypeID);
203 motifMap->AddMotifType(motifType);
206 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
207 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
209 motif = BuildMotifSpecial(motifID, motifType);
212 motifMap->AddMotif(motif);
219 //_____________________________________________________________________________
220 void AliMpReader::ReadRowSegmentsData(ifstream& in,
221 AliMpZone* zone, AliMpSubZone* subZone)
223 // Reads row segments input data of a specified zone and subzone;
224 // creates row segment and adds it to the specified subzone
225 // and a corresponding row in the rows vector.
231 // Read data from file
233 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
238 in >> firstMotifPositionId;
239 in >> firstMotifPositionDId;
241 cout << fgkRowKeyword << " "
242 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
243 << firstMotifPositionId << " " << firstMotifPositionDId
251 AliMpRow* row = fSector->GetRow(inRow);
252 AliMpVMotif* motif = subZone->GetMotif();
254 // Create row segment and add it to its zone, row
255 AliMpVRowSegment* rowSegment
256 = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs,
257 firstMotifPositionId, firstMotifPositionDId);
259 subZone->AddRowSegment(rowSegment);
260 row->AddRowSegment(rowSegment);
262 while (!in.eof() && (nextKeyword == fgkRowKeyword));
264 if (in.eof()) return;
266 if (nextKeyword == fgkZoneKeyword) {
269 else if (nextKeyword == fgkSubZoneKeyword) {
270 ReadSubZoneData(in, zone);
273 Fatal("ReadRowSegmentsData", "Wrong file format.");
277 //_____________________________________________________________________________
278 void AliMpReader::ReadSectorSpecialData(ifstream& in)
280 // Reads sector input data
281 // with a special (irregular) motifs.
287 cout << keyword << endl;
289 if (keyword != fgkSectorSpecialKeyword) {
290 Fatal("ReadSectorSpecialData", "Wrong file format.");
297 cout << keyword << endl;
299 if (nextKeyword != fgkMotifKeyword) {
300 Fatal("ReadSectorSpecialData", "Wrong file format.");
304 ReadMotifsSpecialData(in);
305 ReadRowSpecialData(in);
308 //_____________________________________________________________________________
309 void AliMpReader::ReadMotifsSpecialData(ifstream& in)
311 // Reads the special (irregular) motifs input data.
315 cout << fgkMotifKeyword << " ";
320 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(1));
321 AliMpSubZone* subZone = new AliMpSubZone(motif);
322 fSector->GetZone(1)->AddSubZone(subZone);
323 // special row segments are always in zone 1
327 cout << nextKeyword << " ";
329 while (nextKeyword == fgkMotifKeyword);
331 if (nextKeyword != fgkRowSpecialKeyword) {
332 Fatal("ReadMotifSpecialData", "Wrong file format.");
337 //_____________________________________________________________________________
338 void AliMpReader::ReadRowSpecialData(ifstream& in)
340 // Reads row input data
341 // with a special (irregular) motifs.
349 // Get the row and its border
350 AliMpRow* row = fSector->GetRow(id);
351 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
352 Double_t offsetX = firstNormalSeg->LeftBorderX();
354 // Create a special row segment
355 AliMpRowSegmentSpecial* segment = new AliMpRowSegmentSpecial(row, offsetX);
356 row->AddRowSegmentInFront(segment);
361 cout << nextKeyword << " ";
363 if (nextKeyword != fgkPadRowsKeyword) {
364 Fatal("ReadRowSpecialData", "Wrong file format.");
368 ReadRowSegmentSpecialData(in, segment);
370 // Update row segment and set it to all subzones associated with
373 segment->UpdateMotifVector();
374 segment->UpdatePadsOffset();
376 for (Int_t i=0; i<segment->GetNofMotifs(); i++)
377 fSector->GetZone(1)->FindSubZone(segment->GetMotif(i))->AddRowSegment(segment);
380 //_____________________________________________________________________________
381 void AliMpReader::ReadRowSegmentSpecialData(ifstream& in,
382 AliMpRowSegmentSpecial* segment)
384 // Reads row segment input data
385 // with a special (irregular) motifs.
391 cout << nofPadRows << endl;
396 cout << keyword << " ";
398 if (keyword != fgkPadRowSegmentKeyword) {
399 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
407 PadRowVector newPadRows;
408 for (Int_t i=0; i<nofPadRows; i++) {
411 AliMpPadRow* padRow = new AliMpPadRow();
412 segment->AddPadRow(padRow);
414 // Keep the new rows in a temporary vector
415 newPadRows.push_back(padRow);
421 // Read data from file
423 Int_t nofPadsInRow, motifPositionId;
424 TString motifId, motifTypeId;
427 in >> motifPositionId;
430 cout << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
434 cout << nextKeyword << " ";
440 for (Int_t i=0; i<nofPadRows; i++) {
442 // Get pad row from the temporary vector
443 AliMpPadRow* padRow = newPadRows[i];
446 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
449 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
453 // Create pad row segment
454 AliMpPadRowSegment* padRowSegment
455 = new AliMpPadRowSegment(padRow, dynamic_cast<AliMpMotif *>(motif),
456 motifPositionId, nofPadsInRow);
457 padRow->AddPadRowSegment(padRowSegment);
460 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
462 if (in.eof()) return;
464 if (nextKeyword == fgkPadRowsKeyword) {
465 ReadRowSegmentSpecialData(in, segment);
467 else if (nextKeyword == fgkRowSpecialKeyword) {
468 ReadRowSpecialData(in);
471 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
479 //_____________________________________________________________________________
480 AliMpSector* AliMpReader::BuildSector()
482 // Reads the mapping data from ascii file
483 // $MINSTALL/data/fileName and creates the basic objects:
484 // zones, subzones, rows, row segments, motifs.
488 ifstream in(AliMpFiles::Instance()->SectorFilePath(fPlaneType).Data(), ios::in);
490 Error("Read", "File not found.");
495 fSector->SetRowSegmentOffsets();
497 // Open second input file
498 TString sectorSpecialFileName
499 = AliMpFiles::Instance()->SectorSpecialFilePath(fPlaneType);
500 if (!gSystem->AccessPathName(sectorSpecialFileName.Data())) {
501 ifstream in2(sectorSpecialFileName.Data(), ios::in);
503 Error("Read", "File not found.");
507 ReadSectorSpecialData(in2);
510 fSector->Initialize();
515 //_____________________________________________________________________________
516 AliMpMotifType* AliMpReader::BuildMotifType(TString motifTypeId)
519 // Read the files describing a motif in the "$MINSTALL/data" directory
520 // and fill the AliMpMotifType structure with.
521 // The files mentioned are are named padPos<maskName>.dat
522 // and connect<maskName>.dat
524 AliMpMotifType* motifType = new AliMpMotifType(motifTypeId);
527 = AliMpFiles::Instance()->PadPosFilePath(fPlaneType,motifTypeId);
528 ifstream padPos(strPadPos.Data());
529 if (fVerboseLevel>0) cout<<"Opening file "<<strPadPos<<endl;
531 PadMapType positions;
535 padPos.getline(line,255);
538 #if defined (__HP_aCC) || (__alpha)
542 istringstream strline(line);
547 if ((key=="#") || (key=="") ) continue;
551 positions[key].first=i;
552 positions[key].second=j;
553 } while (!padPos.eof());
557 if (fVerboseLevel>0) cout <<"Opening file "
558 <<AliMpFiles::Instance()->BergToGCFilePath()
561 ifstream bergToGCFile(AliMpFiles::Instance()->BergToGCFilePath());
562 Int_t GassiChannel[80];
566 bergToGCFile>>bergNum>>GCStr;
567 if (!bergToGCFile.good()) break;
568 if (GCStr=="GND") continue;
570 Fatal("BuildMotifType","Berg number > 80 ...");
573 GassiChannel[bergNum-1]= atoi(GCStr);
575 bergToGCFile.close();
578 = AliMpFiles::Instance()->MotifFilePath(fPlaneType,motifTypeId);
579 ifstream motif(strMotif);
580 if (fVerboseLevel>0) cout<<"Opening file "<<strMotif<<endl;
588 Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
590 TString lineStr,token;
591 lineStr.ReadLine(motif);
592 if (!motif.good()) break;
593 #if defined (__HP_aCC) || (__alpha)
595 tokenList << lineStr.Data();
597 istringstream tokenList(lineStr.Data());
600 token.ReadToken(tokenList);
601 if (!tokenList.good()) continue; // column is missing...
602 if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
604 numBerg = atoi(token.Data());
606 Warning("BuildMotifType","Berg number invalid");
610 token.ReadToken(tokenList);
611 if (!tokenList.good()) continue; // column is missing...
612 numKapton = atoi(token.Data());
613 if (numKapton==0) continue;
616 token.ReadToken(tokenList);
617 if (!tokenList.good()) continue; // column is missing...
618 if (token=="GND") continue;
619 string padName = token.Data();
620 padNum = motifType->PadNum(token);
622 token.ReadToken(tokenList);
623 if (token.IsNull() ) continue; // column is missing...
624 // if (token[0]!='E') {
625 // cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
628 // gassiNum = atoi(token.Data() +1 )-1;
630 if ( (numBerg<1) || (numBerg>80) ) {
631 Warning("BuildMotifType","Berg number outside range");
635 gassiNum = GassiChannel[numBerg-1];
637 PadMapTypeIterator iter = positions.find(padName);
638 if (iter==positions.end()) {
639 cerr<<"Problem: Pad number "<<padNum<<" found in the file "<<strMotif
640 <<" but not in the file"<<strPadPos<<endl;
644 ix= iter->second.first;
645 iy= iter->second.second;
647 motifType->AddConnection(AliMpIntPair(ix,iy),
648 new AliMpConnection(padNum,numBerg,numKapton,gassiNum));
650 if (ix>=nofPadsX) nofPadsX=ix+1;
651 if (iy>=nofPadsY) nofPadsY=iy+1;
653 } while (!motif.eof());
656 motifType->SetNofPads(nofPadsX, nofPadsY);
664 //_____________________________________________________________________________
666 AliMpReader::BuildMotifSpecial(TString motifID,AliMpMotifType* motifType)
668 // Build a special motif by reading the file motifSpecial<motifId>.dat
669 // in the data directory
672 // Open the input file
673 ifstream in(AliMpFiles::Instance()
674 ->MotifSpecialFilePath(fPlaneType, motifID).Data(), ios::in);
676 Error("BuildMotifSpecial", "File not found.");
680 AliMpMotifSpecial* res = new AliMpMotifSpecial(motifID,motifType);
686 res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x/2.,y/2.));
695 //_____________________________________________________________________________
696 void AliMpReader::SetVerboseLevel(Int_t verboseLevel)
698 // Sets verbose level.
701 fVerboseLevel = verboseLevel;