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