]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorReader.cxx
In Print(): added an option to print area borders
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorReader.cxx
CommitLineData
197883c2 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpSectorReader.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
5f91c9e8 18// Category: sector
3d1463c8 19
20//-----------------------------------------------------------------------------
197883c2 21// Class AliMpSectorReader
22// -----------------------
5f91c9e8 23// Class that takes care of reading the sector data.
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
3d1463c8 26//-----------------------------------------------------------------------------
5f91c9e8 27
197883c2 28#include "AliMpSectorReader.h"
5f91c9e8 29#include "AliMpSector.h"
30#include "AliMpFiles.h"
31#include "AliMpZone.h"
32#include "AliMpSubZone.h"
33#include "AliMpRow.h"
34#include "AliMpVRowSegment.h"
35#include "AliMpRowSegment.h"
4139354b 36#include "AliMpRowSegmentLSpecial.h"
37#include "AliMpRowSegmentRSpecial.h"
5f91c9e8 38#include "AliMpPadRow.h"
197883c2 39#include "AliMpMotifReader.h"
5f91c9e8 40#include "AliMpMotifMap.h"
41#include "AliMpMotif.h"
42#include "AliMpMotifSpecial.h"
43#include "AliMpMotifType.h"
44#include "AliMpConnection.h"
45#include "AliMpIntPair.h"
46#include "AliMpDirection.h"
f0eac1a3 47#include "AliMpConstants.h"
5f91c9e8 48
2c605e66 49#include "AliLog.h"
50
f0eac1a3 51#include <Riostream.h>
52#include <Rstrstream.h>
53#include <TSystem.h>
f0eac1a3 54#include <TMath.h>
55
56#if !defined(__HP_aCC) && !defined(__alpha)
57 #include <sstream>
58#endif
f79c58a5 59
13985652 60/// \cond CLASSIMP
61ClassImp(AliMpSectorReader)
62/// \endcond
63
197883c2 64const TString AliMpSectorReader::fgkSectorKeyword = "SECTOR_DATA";
65const TString AliMpSectorReader::fgkZoneKeyword = "ZONE";
66const TString AliMpSectorReader::fgkSubZoneKeyword = "SUBZONE";
67const TString AliMpSectorReader::fgkRowKeyword = "ROW_SEGMENT";
68const TString AliMpSectorReader::fgkEofKeyword = "EOF";
69const TString AliMpSectorReader::fgkSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
70const TString AliMpSectorReader::fgkMotifKeyword = "MOTIF";
71const TString AliMpSectorReader::fgkRowSpecialKeyword = "ROW";
72const TString AliMpSectorReader::fgkPadRowsKeyword = "PAD_ROWS";
73const TString AliMpSectorReader::fgkPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
5f91c9e8 74
75//_____________________________________________________________________________
cddd101e 76AliMpSectorReader::AliMpSectorReader(AliMp::StationType station,
77 AliMp::PlaneType plane)
5f91c9e8 78 : TObject(),
4139354b 79 fStationType(station),
5f91c9e8 80 fPlaneType(plane),
81 fSector(0),
2c605e66 82 fMotifReader(new AliMpMotifReader(station, plane))
5f91c9e8 83{
f5671fc3 84/// Standard constructor
5f91c9e8 85}
86
87//_____________________________________________________________________________
197883c2 88AliMpSectorReader::AliMpSectorReader()
5f91c9e8 89 : TObject(),
cddd101e 90 fStationType(AliMp::kStation1),
91 fPlaneType(AliMp::kBendingPlane),
5f91c9e8 92 fSector(0),
2c605e66 93 fMotifReader(0)
5f91c9e8 94{
f5671fc3 95/// Default constructor
5f91c9e8 96}
97
98//_____________________________________________________________________________
197883c2 99AliMpSectorReader::~AliMpSectorReader()
100{
101/// Destructor
102
103 delete fMotifReader;
5f91c9e8 104}
105
106//
107// private methods
108//
109
f79c58a5 110//_____________________________________________________________________________
197883c2 111void AliMpSectorReader::ReadSectorData(ifstream& in)
f79c58a5 112{
197883c2 113/// Read sector input data;
114/// prepare zones and rows vectors to be filled in.
5f91c9e8 115
116 TString keyword;
117 in >> keyword;
118
da3a1bb2 119 AliDebugStream(2) << keyword << endl;
5f91c9e8 120
121 if (keyword != fgkSectorKeyword) {
122 Fatal("ReadSectorData", "Wrong file format.");
123 return;
124 }
125
126 Int_t nofZones, nofRows;
127 TString directionStr;
14b7b896 128 Double_t offsetX, offsetY;
5f91c9e8 129 in >> nofZones;
130 in >> nofRows;
131 in >> directionStr;
14b7b896 132 in >> offsetX;
133 in >> offsetY;
5f91c9e8 134
cddd101e 135 AliMp::Direction direction;
136 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
2c605e66 137
da3a1bb2 138 AliDebugStream(2) << nofZones << " " << nofRows << endl;
5f91c9e8 139
14b7b896 140 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
141 TVector2(offsetX, offsetY));
5f91c9e8 142
143 TString nextKeyword;
144 in >> nextKeyword;
145
146 if (nextKeyword != fgkZoneKeyword) {
147 Fatal("ReadSectorData", "Wrong file format.");
148 return;
149 }
150
151 ReadZoneData(in);
152}
153
154//_____________________________________________________________________________
197883c2 155void AliMpSectorReader::ReadZoneData(ifstream& in)
5f91c9e8 156{
197883c2 157/// Read zone input data;
158/// create zone and adds it to zones vector.
5f91c9e8 159
160 Int_t zoneID;
161 Double_t sizex, sizey;
162 in >> zoneID;
163 in >> sizex;
164 in >> sizey;
da3a1bb2 165 AliDebugStream(2)
2c605e66 166 << fgkZoneKeyword << " " << zoneID << " "
167 << sizex << " " << sizey << endl;
5f91c9e8 168
169 AliMpZone* zone = fSector->GetZone(zoneID);
170 zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.));
171
172 TString nextKeyword;
173 in >> nextKeyword;
174
175 if (nextKeyword != fgkSubZoneKeyword) {
176 Fatal("ReadZoneData", "Wrong file format.");
177 return;
178 }
179
180 ReadSubZoneData(in, zone);
181}
182
183//_____________________________________________________________________________
197883c2 184void AliMpSectorReader::ReadSubZoneData(ifstream& in, AliMpZone* zone)
5f91c9e8 185{
197883c2 186/// Read subzone input data;
187/// create subzone and its to the specified zone.
5f91c9e8 188
da3a1bb2 189 AliDebugStream(2) << fgkSubZoneKeyword << endl;
5f91c9e8 190
191 AliMpVMotif* motif = ReadMotifData(in, zone);
192 AliMpSubZone* subZone = new AliMpSubZone(motif);
193 zone->AddSubZone(subZone);
194
195 TString nextKeyword;
196 in >> nextKeyword;
197
198 if (nextKeyword != fgkRowKeyword) {
199 Fatal("ReadSubZoneData", "Wrong file format.");
200 return;
201 }
202
203 ReadRowSegmentsData(in, zone, subZone);
204}
205
206//_____________________________________________________________________________
197883c2 207AliMpVMotif* AliMpSectorReader::ReadMotifData(ifstream& in, AliMpZone* zone)
5f91c9e8 208{
197883c2 209/// Read the motif input data.
5f91c9e8 210
211 TString motifID;
212 TString motifTypeID;
213 in >> motifID;
214 in >> motifTypeID;
2c605e66 215
da3a1bb2 216 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
5f91c9e8 217
218 AliMpMotifMap* motifMap = fSector->GetMotifMap();
219
220 AliMpMotifType* motifType = 0;
221 AliMpVMotif* motif
222 = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
223 if (!motif) {
224 motifType = motifMap->FindMotifType(motifTypeID);
225 if (!motifType) {
197883c2 226 motifType = fMotifReader->BuildMotifType(motifTypeID);
5f91c9e8 227 motifMap->AddMotifType(motifType);
228 }
229
230 if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.)
231 motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
232 else
197883c2 233 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
5f91c9e8 234
235 if (motif)
236 motifMap->AddMotif(motif);
237
238 }
239
240 return motif;
241}
242
243//_____________________________________________________________________________
197883c2 244void AliMpSectorReader::ReadRowSegmentsData(ifstream& in,
5f91c9e8 245 AliMpZone* zone, AliMpSubZone* subZone)
246{
197883c2 247/// Read row segments input data of a specified zone and subzone;
248/// creates row segment and add it to the specified subzone
249/// and a corresponding row in the rows vector.
5f91c9e8 250
251 TString nextKeyword;
252 do {
253 //
254 // Read data from file
255 //
256 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
257 in >> offX;
258 in >> offY;
259 in >> inRow;
260 in >> nofMotifs;
261 in >> firstMotifPositionId;
262 in >> firstMotifPositionDId;
f0eac1a3 263
264 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
265
da3a1bb2 266 AliDebugStream(2)
2c605e66 267 << fgkRowKeyword << " "
268 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
269 << firstMotifPositionId << " " << firstMotifPositionDId
270 << endl;
5f91c9e8 271
272 in >> nextKeyword;
273
274 //
275 // Process data
276 //
277 AliMpRow* row = fSector->GetRow(inRow);
278 AliMpVMotif* motif = subZone->GetMotif();
279
280 // Create row segment and add it to its zone, row
281 AliMpVRowSegment* rowSegment
282 = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs,
283 firstMotifPositionId, firstMotifPositionDId);
284
285 subZone->AddRowSegment(rowSegment);
286 row->AddRowSegment(rowSegment);
287 }
288 while (!in.eof() && (nextKeyword == fgkRowKeyword));
289
290 if (in.eof()) return;
291
292 if (nextKeyword == fgkZoneKeyword) {
293 ReadZoneData(in);
294 }
295 else if (nextKeyword == fgkSubZoneKeyword) {
296 ReadSubZoneData(in, zone);
297 }
298 else {
299 Fatal("ReadRowSegmentsData", "Wrong file format.");
300 }
301}
302
303//_____________________________________________________________________________
cddd101e 304void AliMpSectorReader::ReadSectorSpecialData(ifstream& in, AliMp::XDirection direction)
5f91c9e8 305{
197883c2 306/// Read sector input data
307/// with a special (irregular) motifs.
5f91c9e8 308
309 TString keyword;
310 in >> keyword;
2c605e66 311
da3a1bb2 312 AliDebugStream(2) << keyword << endl;
5f91c9e8 313
314 if (keyword != fgkSectorSpecialKeyword) {
315 Fatal("ReadSectorSpecialData", "Wrong file format.");
316 return;
317 }
318
319 TString nextKeyword;
320 in >> nextKeyword;
2c605e66 321
da3a1bb2 322 AliDebugStream(2) << keyword << endl;
5f91c9e8 323
324 if (nextKeyword != fgkMotifKeyword) {
325 Fatal("ReadSectorSpecialData", "Wrong file format.");
326 return;
327 }
328
329 ReadMotifsSpecialData(in);
4139354b 330 ReadRowSpecialData(in, direction);
5f91c9e8 331}
332
333//_____________________________________________________________________________
197883c2 334void AliMpSectorReader::ReadMotifsSpecialData(ifstream& in)
5f91c9e8 335{
197883c2 336/// Read the special (irregular) motifs input data.
5f91c9e8 337
da3a1bb2 338 AliDebugStream(2) << fgkMotifKeyword << endl;
5f91c9e8 339
340 TString nextKeyword;
341 do {
4139354b 342 Int_t zone;
343 in >> zone;
344 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
5f91c9e8 345 AliMpSubZone* subZone = new AliMpSubZone(motif);
4139354b 346 fSector->GetZone(zone)->AddSubZone(subZone);
5f91c9e8 347
348 in >> nextKeyword;
2c605e66 349
da3a1bb2 350 AliDebugStream(2) << nextKeyword << endl;
5f91c9e8 351 }
352 while (nextKeyword == fgkMotifKeyword);
353
354 if (nextKeyword != fgkRowSpecialKeyword) {
355 Fatal("ReadMotifSpecialData", "Wrong file format.");
356 return;
357 }
358}
359
360//_____________________________________________________________________________
cddd101e 361void AliMpSectorReader::ReadRowSpecialData(ifstream& in, AliMp::XDirection direction)
5f91c9e8 362{
197883c2 363/// Read row input data
364/// with a special (irregular) motifs.
5f91c9e8 365
366 Int_t id;
367 in >> id;
2c605e66 368
da3a1bb2 369 AliDebugStream(2) << id << endl;
5f91c9e8 370
371 // Get the row and its border
372 AliMpRow* row = fSector->GetRow(id);
4139354b 373
374 AliMpVRowSegmentSpecial* segment = 0;
cddd101e 375 if (direction == AliMp::kLeft) {
4139354b 376 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
377 Double_t offsetX = firstNormalSeg->LeftBorderX();
5f91c9e8 378
4139354b 379 // Create a special row segment
380 segment = new AliMpRowSegmentLSpecial(row, offsetX);
381 row->AddRowSegmentInFront(segment);
382 }
383 else {
384 AliMpVRowSegment* precedentNormalSeg
385 = row->GetRowSegment(row->GetNofRowSegments()-1);
386 Double_t offsetX = precedentNormalSeg->RightBorderX();
5f91c9e8 387
4139354b 388 // Create a special row segment
389 segment = new AliMpRowSegmentRSpecial(row, offsetX);
390 row->AddRowSegment(segment);
391 }
392
5f91c9e8 393 TString nextKeyword;
394 in >> nextKeyword;
2c605e66 395
da3a1bb2 396 AliDebugStream(2) << nextKeyword << endl;
5f91c9e8 397
398 if (nextKeyword != fgkPadRowsKeyword) {
399 Fatal("ReadRowSpecialData", "Wrong file format.");
400 return;
401 }
402
4139354b 403 ReadRowSegmentSpecialData(in, segment, direction);
5f91c9e8 404
405 // Update row segment and set it to all subzones associated with
406 // contained motifs
407
408 segment->UpdateMotifVector();
409 segment->UpdatePadsOffset();
410
4139354b 411 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
412 AliMpSubZone* subZone = 0;
413 Int_t j = 0;
414 while (!subZone && j<fSector->GetNofZones())
415 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
416
417 subZone->AddRowSegment(segment);
418 }
5f91c9e8 419}
420
421//_____________________________________________________________________________
197883c2 422void AliMpSectorReader::ReadRowSegmentSpecialData(ifstream& in,
4139354b 423 AliMpVRowSegmentSpecial* segment,
cddd101e 424 AliMp::XDirection direction)
5f91c9e8 425{
197883c2 426/// Read row segment input data
427/// with a special (irregular) motifs.
5f91c9e8 428
429 Int_t nofPadRows;
430 in >> nofPadRows;
2c605e66 431
da3a1bb2 432 AliDebugStream(2) << nofPadRows << endl;
5f91c9e8 433
434 TString keyword;
435 in >> keyword;
2c605e66 436
da3a1bb2 437 AliDebugStream(2) << keyword << endl;
5f91c9e8 438
439 if (keyword != fgkPadRowSegmentKeyword) {
440 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
441 return;
442 }
443
444 //
445 // Process data
446 //
447
5006ec94 448 AliMpVRowSegmentSpecial::PadRowVector newPadRows;
5f91c9e8 449 for (Int_t i=0; i<nofPadRows; i++) {
450
451 // Create pad row
4139354b 452 AliMpPadRow* padRow = new AliMpPadRow(direction);
5f91c9e8 453 segment->AddPadRow(padRow);
454
455 // Keep the new rows in a temporary vector
f79c58a5 456#ifdef WITH_STL
5f91c9e8 457 newPadRows.push_back(padRow);
f79c58a5 458#endif
459#ifdef WITH_ROOT
460 newPadRows.Add(padRow);
461#endif
5f91c9e8 462 }
463
464 TString nextKeyword;
465 do {
466 //
467 // Read data from file
468 //
469 Int_t nofPadsInRow, motifPositionId;
470 TString motifId, motifTypeId;
471 in >> nofPadsInRow;
472 in >> motifId;
473 in >> motifPositionId;
474
f0eac1a3 475 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
476
da3a1bb2 477 AliDebugStream(2)
2c605e66 478 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
5f91c9e8 479
480 in >> nextKeyword;
2c605e66 481
da3a1bb2 482 AliDebugStream(2) << nextKeyword << endl;
5f91c9e8 483
484 //
485 // Process data
486 //
487
488 for (Int_t i=0; i<nofPadRows; i++) {
489
490 // Get pad row from the temporary vector
f79c58a5 491#ifdef WITH_STL
5f91c9e8 492 AliMpPadRow* padRow = newPadRows[i];
f79c58a5 493#endif
494#ifdef WITH_ROOT
495 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
496#endif
5f91c9e8 497
498 // Find motif
499 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
500
501 if (!motif) {
502 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
503 return;
504 }
505
506 // Create pad row segment
4139354b 507 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
508 motifPositionId, nofPadsInRow);
5f91c9e8 509 }
510 }
511 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
512
513 if (in.eof()) return;
514
515 if (nextKeyword == fgkPadRowsKeyword) {
4139354b 516 ReadRowSegmentSpecialData(in, segment, direction);
5f91c9e8 517 }
518 else if (nextKeyword == fgkRowSpecialKeyword) {
4139354b 519 ReadRowSpecialData(in, direction);
5f91c9e8 520 }
521 else {
522 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
523 }
524}
525
526//
527// public methods
528//
529
530//_____________________________________________________________________________
197883c2 531AliMpSector* AliMpSectorReader::BuildSector()
5f91c9e8 532{
197883c2 533/// Read the mapping data from ascii data file
534/// and create the basic objects: \n
535/// zones, subzones, rows, row segments, motifs.
5f91c9e8 536
537 // Open input file
3d16af90 538 ifstream in(AliMpFiles::SectorFilePath(fStationType, fPlaneType).Data(), ios::in);
4139354b 539 if (!in) {
2c605e66 540 AliErrorStream()
541 << "File " << AliMpFiles::SectorFilePath(fStationType, fPlaneType)
542 << " not found." << endl;
5f91c9e8 543 return 0;
544 }
545
546 ReadSectorData(in);
547 fSector->SetRowSegmentOffsets();
548
4139354b 549 // Open input file for special inner zone
5f91c9e8 550 TString sectorSpecialFileName
3d16af90 551 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
5f91c9e8 552 if (!gSystem->AccessPathName(sectorSpecialFileName.Data())) {
553 ifstream in2(sectorSpecialFileName.Data(), ios::in);
554 if (!in2) {
2c605e66 555 AliErrorStream()
556 << "File " << AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType)
557 << " not found." << endl;
5f91c9e8 558 return 0;
559 }
560
cddd101e 561 ReadSectorSpecialData(in2, AliMp::kLeft);
4139354b 562 }
563
564 // Open input file for special outer zone
565 TString sectorSpecialFileName2
3d16af90 566 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
4139354b 567 if (!gSystem->AccessPathName(sectorSpecialFileName2.Data())) {
568 ifstream in3(sectorSpecialFileName2.Data(), ios::in);
569 if (!in3) {
2c605e66 570 AliErrorStream()
571 << "File " << AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType)
572 << " not found."<< endl;
4139354b 573 return 0;
574 }
575
cddd101e 576 ReadSectorSpecialData(in3, AliMp::kRight);
5f91c9e8 577 }
578
579 fSector->Initialize();
580
581 return fSector;
582}
583