Fixing Doxygen 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
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"
228fd720 31#include "AliMpDataStreams.h"
5f91c9e8 32#include "AliMpZone.h"
33#include "AliMpSubZone.h"
34#include "AliMpRow.h"
35#include "AliMpVRowSegment.h"
36#include "AliMpRowSegment.h"
4139354b 37#include "AliMpRowSegmentLSpecial.h"
38#include "AliMpRowSegmentRSpecial.h"
5f91c9e8 39#include "AliMpPadRow.h"
197883c2 40#include "AliMpMotifReader.h"
5f91c9e8 41#include "AliMpMotifMap.h"
42#include "AliMpMotif.h"
43#include "AliMpMotifSpecial.h"
44#include "AliMpMotifType.h"
45#include "AliMpConnection.h"
5f91c9e8 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//_____________________________________________________________________________
ab167304 76AliMpSectorReader::AliMpSectorReader(const AliMpDataStreams& dataStreams,
4e51cfd2 77 AliMq::Station12Type station,
cddd101e 78 AliMp::PlaneType plane)
5f91c9e8 79 : TObject(),
7d5d0cc5 80 fkDataStreams(dataStreams),
4139354b 81 fStationType(station),
5f91c9e8 82 fPlaneType(plane),
83 fSector(0),
4e51cfd2 84 fMotifReader(new AliMpMotifReader(dataStreams, AliMp::kStation12, station, plane))
228fd720 85
5f91c9e8 86{
f5671fc3 87/// Standard constructor
5f91c9e8 88}
89
90//_____________________________________________________________________________
197883c2 91AliMpSectorReader::~AliMpSectorReader()
92{
93/// Destructor
94
95 delete fMotifReader;
5f91c9e8 96}
97
98//
99// private methods
100//
101
f79c58a5 102//_____________________________________________________________________________
228fd720 103void AliMpSectorReader::ReadSectorData(istream& in)
f79c58a5 104{
197883c2 105/// Read sector input data;
106/// prepare zones and rows vectors to be filled in.
5f91c9e8 107
108 TString keyword;
109 in >> keyword;
110
da3a1bb2 111 AliDebugStream(2) << keyword << endl;
5f91c9e8 112
113 if (keyword != fgkSectorKeyword) {
114 Fatal("ReadSectorData", "Wrong file format.");
115 return;
116 }
117
118 Int_t nofZones, nofRows;
119 TString directionStr;
14b7b896 120 Double_t offsetX, offsetY;
5f91c9e8 121 in >> nofZones;
122 in >> nofRows;
123 in >> directionStr;
14b7b896 124 in >> offsetX;
125 in >> offsetY;
5f91c9e8 126
cddd101e 127 AliMp::Direction direction;
128 direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
2c605e66 129
da3a1bb2 130 AliDebugStream(2) << nofZones << " " << nofRows << endl;
5f91c9e8 131
14b7b896 132 fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
6e97fbb8 133 offsetX, offsetY);
5f91c9e8 134
135 TString nextKeyword;
136 in >> nextKeyword;
137
138 if (nextKeyword != fgkZoneKeyword) {
139 Fatal("ReadSectorData", "Wrong file format.");
140 return;
141 }
142
143 ReadZoneData(in);
144}
145
146//_____________________________________________________________________________
228fd720 147void AliMpSectorReader::ReadZoneData(istream& in)
5f91c9e8 148{
197883c2 149/// Read zone input data;
150/// create zone and adds it to zones vector.
5f91c9e8 151
152 Int_t zoneID;
153 Double_t sizex, sizey;
154 in >> zoneID;
155 in >> sizex;
156 in >> sizey;
da3a1bb2 157 AliDebugStream(2)
2c605e66 158 << fgkZoneKeyword << " " << zoneID << " "
159 << sizex << " " << sizey << endl;
5f91c9e8 160
161 AliMpZone* zone = fSector->GetZone(zoneID);
6e97fbb8 162 zone->SetPadDimensions(sizex/2.,sizey/2.);
5f91c9e8 163
164 TString nextKeyword;
165 in >> nextKeyword;
166
167 if (nextKeyword != fgkSubZoneKeyword) {
168 Fatal("ReadZoneData", "Wrong file format.");
169 return;
170 }
171
172 ReadSubZoneData(in, zone);
173}
174
175//_____________________________________________________________________________
228fd720 176void AliMpSectorReader::ReadSubZoneData(istream& in, AliMpZone* zone)
5f91c9e8 177{
197883c2 178/// Read subzone input data;
179/// create subzone and its to the specified zone.
5f91c9e8 180
da3a1bb2 181 AliDebugStream(2) << fgkSubZoneKeyword << endl;
5f91c9e8 182
183 AliMpVMotif* motif = ReadMotifData(in, zone);
184 AliMpSubZone* subZone = new AliMpSubZone(motif);
185 zone->AddSubZone(subZone);
186
187 TString nextKeyword;
188 in >> nextKeyword;
189
190 if (nextKeyword != fgkRowKeyword) {
191 Fatal("ReadSubZoneData", "Wrong file format.");
192 return;
193 }
194
195 ReadRowSegmentsData(in, zone, subZone);
196}
197
198//_____________________________________________________________________________
228fd720 199AliMpVMotif* AliMpSectorReader::ReadMotifData(istream& in, AliMpZone* zone)
5f91c9e8 200{
197883c2 201/// Read the motif input data.
5f91c9e8 202
203 TString motifID;
204 TString motifTypeID;
205 in >> motifID;
206 in >> motifTypeID;
2c605e66 207
da3a1bb2 208 AliDebugStream(2) << motifID << " " << motifTypeID << endl;
5f91c9e8 209
210 AliMpMotifMap* motifMap = fSector->GetMotifMap();
211
212 AliMpMotifType* motifType = 0;
213 AliMpVMotif* motif
6e97fbb8 214 = motifMap->FindMotif(motifID, motifTypeID,
215 zone->GetPadDimensionX(), zone->GetPadDimensionY());
5f91c9e8 216 if (!motif) {
217 motifType = motifMap->FindMotifType(motifTypeID);
218 if (!motifType) {
197883c2 219 motifType = fMotifReader->BuildMotifType(motifTypeID);
5f91c9e8 220 motifMap->AddMotifType(motifType);
221 }
222
6e97fbb8 223 if (zone->GetPadDimensionX() != 0. && zone->GetPadDimensionY() != 0.)
224 motif = new AliMpMotif(motifID, motifType,
225 zone->GetPadDimensionX(), zone->GetPadDimensionY());
5f91c9e8 226 else
197883c2 227 motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
5f91c9e8 228
229 if (motif)
230 motifMap->AddMotif(motif);
231
232 }
233
234 return motif;
235}
236
237//_____________________________________________________________________________
228fd720 238void AliMpSectorReader::ReadRowSegmentsData(istream& in,
5f91c9e8 239 AliMpZone* zone, AliMpSubZone* subZone)
240{
197883c2 241/// Read row segments input data of a specified zone and subzone;
242/// creates row segment and add it to the specified subzone
243/// and a corresponding row in the rows vector.
5f91c9e8 244
245 TString nextKeyword;
246 do {
247 //
248 // Read data from file
249 //
250 Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
251 in >> offX;
252 in >> offY;
253 in >> inRow;
254 in >> nofMotifs;
255 in >> firstMotifPositionId;
256 in >> firstMotifPositionDId;
f0eac1a3 257
258 firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
259
da3a1bb2 260 AliDebugStream(2)
2c605e66 261 << fgkRowKeyword << " "
262 << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
263 << firstMotifPositionId << " " << firstMotifPositionDId
264 << endl;
5f91c9e8 265
266 in >> nextKeyword;
267
268 //
269 // Process data
270 //
271 AliMpRow* row = fSector->GetRow(inRow);
272 AliMpVMotif* motif = subZone->GetMotif();
273
274 // Create row segment and add it to its zone, row
275 AliMpVRowSegment* rowSegment
168e9c4d 276 = new AliMpRowSegment(row, motif, offX, offY, nofMotifs,
5f91c9e8 277 firstMotifPositionId, firstMotifPositionDId);
278
279 subZone->AddRowSegment(rowSegment);
280 row->AddRowSegment(rowSegment);
281 }
282 while (!in.eof() && (nextKeyword == fgkRowKeyword));
283
284 if (in.eof()) return;
285
286 if (nextKeyword == fgkZoneKeyword) {
287 ReadZoneData(in);
288 }
289 else if (nextKeyword == fgkSubZoneKeyword) {
290 ReadSubZoneData(in, zone);
291 }
292 else {
293 Fatal("ReadRowSegmentsData", "Wrong file format.");
294 }
295}
296
297//_____________________________________________________________________________
228fd720 298void AliMpSectorReader::ReadSectorSpecialData(istream& in, AliMp::XDirection direction)
5f91c9e8 299{
197883c2 300/// Read sector input data
301/// with a special (irregular) motifs.
5f91c9e8 302
303 TString keyword;
304 in >> keyword;
2c605e66 305
da3a1bb2 306 AliDebugStream(2) << keyword << endl;
5f91c9e8 307
308 if (keyword != fgkSectorSpecialKeyword) {
309 Fatal("ReadSectorSpecialData", "Wrong file format.");
310 return;
311 }
312
313 TString nextKeyword;
314 in >> nextKeyword;
2c605e66 315
da3a1bb2 316 AliDebugStream(2) << keyword << endl;
5f91c9e8 317
318 if (nextKeyword != fgkMotifKeyword) {
319 Fatal("ReadSectorSpecialData", "Wrong file format.");
320 return;
321 }
322
323 ReadMotifsSpecialData(in);
4139354b 324 ReadRowSpecialData(in, direction);
5f91c9e8 325}
326
327//_____________________________________________________________________________
228fd720 328void AliMpSectorReader::ReadMotifsSpecialData(istream& in)
5f91c9e8 329{
197883c2 330/// Read the special (irregular) motifs input data.
5f91c9e8 331
da3a1bb2 332 AliDebugStream(2) << fgkMotifKeyword << endl;
5f91c9e8 333
334 TString nextKeyword;
335 do {
4139354b 336 Int_t zone;
337 in >> zone;
338 AliMpVMotif* motif = ReadMotifData(in, fSector->GetZone(zone));
5f91c9e8 339 AliMpSubZone* subZone = new AliMpSubZone(motif);
4139354b 340 fSector->GetZone(zone)->AddSubZone(subZone);
5f91c9e8 341
342 in >> nextKeyword;
2c605e66 343
da3a1bb2 344 AliDebugStream(2) << nextKeyword << endl;
5f91c9e8 345 }
346 while (nextKeyword == fgkMotifKeyword);
347
348 if (nextKeyword != fgkRowSpecialKeyword) {
349 Fatal("ReadMotifSpecialData", "Wrong file format.");
350 return;
351 }
352}
353
354//_____________________________________________________________________________
228fd720 355void AliMpSectorReader::ReadRowSpecialData(istream& in, AliMp::XDirection direction)
5f91c9e8 356{
197883c2 357/// Read row input data
358/// with a special (irregular) motifs.
5f91c9e8 359
360 Int_t id;
361 in >> id;
2c605e66 362
da3a1bb2 363 AliDebugStream(2) << id << endl;
5f91c9e8 364
365 // Get the row and its border
366 AliMpRow* row = fSector->GetRow(id);
4139354b 367
368 AliMpVRowSegmentSpecial* segment = 0;
cddd101e 369 if (direction == AliMp::kLeft) {
4139354b 370 AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
371 Double_t offsetX = firstNormalSeg->LeftBorderX();
5f91c9e8 372
4139354b 373 // Create a special row segment
374 segment = new AliMpRowSegmentLSpecial(row, offsetX);
375 row->AddRowSegmentInFront(segment);
376 }
377 else {
378 AliMpVRowSegment* precedentNormalSeg
379 = row->GetRowSegment(row->GetNofRowSegments()-1);
380 Double_t offsetX = precedentNormalSeg->RightBorderX();
5f91c9e8 381
4139354b 382 // Create a special row segment
383 segment = new AliMpRowSegmentRSpecial(row, offsetX);
384 row->AddRowSegment(segment);
385 }
386
5f91c9e8 387 TString nextKeyword;
388 in >> nextKeyword;
2c605e66 389
da3a1bb2 390 AliDebugStream(2) << nextKeyword << endl;
5f91c9e8 391
392 if (nextKeyword != fgkPadRowsKeyword) {
393 Fatal("ReadRowSpecialData", "Wrong file format.");
394 return;
395 }
396
4139354b 397 ReadRowSegmentSpecialData(in, segment, direction);
5f91c9e8 398
399 // Update row segment and set it to all subzones associated with
400 // contained motifs
401
402 segment->UpdateMotifVector();
403 segment->UpdatePadsOffset();
404
4139354b 405 for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
406 AliMpSubZone* subZone = 0;
407 Int_t j = 0;
408 while (!subZone && j<fSector->GetNofZones())
409 subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
410
411 subZone->AddRowSegment(segment);
412 }
5f91c9e8 413}
414
415//_____________________________________________________________________________
228fd720 416void AliMpSectorReader::ReadRowSegmentSpecialData(istream& in,
4139354b 417 AliMpVRowSegmentSpecial* segment,
cddd101e 418 AliMp::XDirection direction)
5f91c9e8 419{
197883c2 420/// Read row segment input data
421/// with a special (irregular) motifs.
5f91c9e8 422
423 Int_t nofPadRows;
424 in >> nofPadRows;
2c605e66 425
da3a1bb2 426 AliDebugStream(2) << nofPadRows << endl;
5f91c9e8 427
428 TString keyword;
429 in >> keyword;
2c605e66 430
da3a1bb2 431 AliDebugStream(2) << keyword << endl;
5f91c9e8 432
433 if (keyword != fgkPadRowSegmentKeyword) {
434 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
435 return;
436 }
437
438 //
439 // Process data
440 //
441
2294822d 442 TObjArray newPadRows;
5f91c9e8 443 for (Int_t i=0; i<nofPadRows; i++) {
444
445 // Create pad row
4139354b 446 AliMpPadRow* padRow = new AliMpPadRow(direction);
5f91c9e8 447 segment->AddPadRow(padRow);
448
449 // Keep the new rows in a temporary vector
f79c58a5 450 newPadRows.Add(padRow);
5f91c9e8 451 }
452
453 TString nextKeyword;
454 do {
455 //
456 // Read data from file
457 //
458 Int_t nofPadsInRow, motifPositionId;
459 TString motifId, motifTypeId;
460 in >> nofPadsInRow;
461 in >> motifId;
462 in >> motifPositionId;
463
f0eac1a3 464 motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
465
da3a1bb2 466 AliDebugStream(2)
2c605e66 467 << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
5f91c9e8 468
469 in >> nextKeyword;
2c605e66 470
da3a1bb2 471 AliDebugStream(2) << nextKeyword << endl;
5f91c9e8 472
473 //
474 // Process data
475 //
476
477 for (Int_t i=0; i<nofPadRows; i++) {
478
479 // Get pad row from the temporary vector
f79c58a5 480 AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
5f91c9e8 481
482 // Find motif
483 AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
484
485 if (!motif) {
486 Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
487 return;
488 }
489
490 // Create pad row segment
4139354b 491 padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
492 motifPositionId, nofPadsInRow);
5f91c9e8 493 }
494 }
495 while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
496
497 if (in.eof()) return;
498
499 if (nextKeyword == fgkPadRowsKeyword) {
4139354b 500 ReadRowSegmentSpecialData(in, segment, direction);
5f91c9e8 501 }
502 else if (nextKeyword == fgkRowSpecialKeyword) {
4139354b 503 ReadRowSpecialData(in, direction);
5f91c9e8 504 }
505 else {
506 Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
507 }
508}
509
510//
511// public methods
512//
513
514//_____________________________________________________________________________
197883c2 515AliMpSector* AliMpSectorReader::BuildSector()
5f91c9e8 516{
228fd720 517/// Read the mapping data from stream and create the basic objects: \n
197883c2 518/// zones, subzones, rows, row segments, motifs.
5f91c9e8 519
228fd720 520 // Open input stream
521 //
522 istream& in
7d5d0cc5 523 = fkDataStreams.
ab167304 524 CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
228fd720 525
5f91c9e8 526 ReadSectorData(in);
228fd720 527 delete &in;
528
5f91c9e8 529 fSector->SetRowSegmentOffsets();
530
228fd720 531 // Open input stream for special inner zone
532
533 // add is data function
534
5f91c9e8 535 TString sectorSpecialFileName
3d16af90 536 = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
7d5d0cc5 537 if ( fkDataStreams.IsDataStream(sectorSpecialFileName) ) {
228fd720 538 istream& in2
7d5d0cc5 539 = fkDataStreams.
ab167304 540 CreateDataStream(sectorSpecialFileName);
228fd720 541
cddd101e 542 ReadSectorSpecialData(in2, AliMp::kLeft);
228fd720 543
544 delete &in2;
545 }
4139354b 546
547 // Open input file for special outer zone
548 TString sectorSpecialFileName2
3d16af90 549 = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
7d5d0cc5 550 if ( fkDataStreams.IsDataStream(sectorSpecialFileName2) ) {
228fd720 551 istream& in3
7d5d0cc5 552 = fkDataStreams.
ab167304 553 CreateDataStream(sectorSpecialFileName2);
4139354b 554
cddd101e 555 ReadSectorSpecialData(in3, AliMp::kRight);
228fd720 556
557 delete &in3;
5f91c9e8 558 }
559
560 fSector->Initialize();
561
562 return fSector;
563}
564