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