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