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