Line data Source code
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 :
16 : // $Id$
17 : // $MpId: AliMpSectorReader.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
18 : // Category: sector
19 :
20 : //-----------------------------------------------------------------------------
21 : // Class AliMpSectorReader
22 : // -----------------------
23 : // Class that takes care of reading the sector data.
24 : // Included in AliRoot: 2003/05/02
25 : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 : //-----------------------------------------------------------------------------
27 :
28 : #include "AliMpSectorReader.h"
29 : #include "AliMpSector.h"
30 : #include "AliMpFiles.h"
31 : #include "AliMpDataStreams.h"
32 : #include "AliMpZone.h"
33 : #include "AliMpSubZone.h"
34 : #include "AliMpRow.h"
35 : #include "AliMpVRowSegment.h"
36 : #include "AliMpRowSegment.h"
37 : #include "AliMpRowSegmentLSpecial.h"
38 : #include "AliMpRowSegmentRSpecial.h"
39 : #include "AliMpPadRow.h"
40 : #include "AliMpMotifReader.h"
41 : #include "AliMpMotifMap.h"
42 : #include "AliMpMotif.h"
43 : #include "AliMpMotifSpecial.h"
44 : #include "AliMpMotifType.h"
45 : #include "AliMpConnection.h"
46 : #include "AliMpDirection.h"
47 : #include "AliMpConstants.h"
48 :
49 : #include "AliLog.h"
50 :
51 : #include <Riostream.h>
52 : #include <Rstrstream.h>
53 : #include <TSystem.h>
54 : #include <TMath.h>
55 :
56 : #include <limits>
57 :
58 : #if !defined(__HP_aCC) && !defined(__alpha)
59 : #include <sstream>
60 : #endif
61 :
62 : /// \cond CLASSIMP
63 18 : ClassImp(AliMpSectorReader)
64 : /// \endcond
65 :
66 : //
67 : // static private methods
68 : //
69 :
70 : //_____________________________________________________________________________
71 : const TString& AliMpSectorReader::GetSectorKeyword()
72 : {
73 : /// sector keyword
74 33 : static const TString kSectorKeyword = "SECTOR_DATA";
75 12 : return kSectorKeyword;
76 0 : }
77 :
78 : //_____________________________________________________________________________
79 : const TString& AliMpSectorReader::GetZoneKeyword()
80 : {
81 : /// zone keyword
82 531 : static const TString kZoneKeyword = "ZONE";
83 261 : return kZoneKeyword;
84 0 : }
85 :
86 : //_____________________________________________________________________________
87 : const TString& AliMpSectorReader::GetSubZoneKeyword()
88 : {
89 : /// subzone keyword
90 885 : static const TString kSubZoneKeyword = "SUBZONE";
91 438 : return kSubZoneKeyword;
92 0 : }
93 :
94 : //_____________________________________________________________________________
95 : const TString& AliMpSectorReader::GetRowKeyword()
96 : {
97 : /// row keyword
98 2523 : static const TString kRowKeyword = "ROW_SEGMENT";
99 1257 : return kRowKeyword;
100 0 : }
101 :
102 : //_____________________________________________________________________________
103 : const TString& AliMpSectorReader::GetSectorSpecialKeyword()
104 : {
105 : /// sector special keyword
106 39 : static const TString kSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
107 15 : return kSectorSpecialKeyword;
108 0 : }
109 :
110 : //_____________________________________________________________________________
111 : const TString& AliMpSectorReader::GetMotifKeyword()
112 : {
113 : /// motif keyword
114 375 : static const TString kMotifKeyword = "MOTIF";
115 183 : return kMotifKeyword;
116 0 : }
117 :
118 : //_____________________________________________________________________________
119 : const TString& AliMpSectorReader::GetRowSpecialKeyword()
120 : {
121 : /// row special keyword
122 195 : static const TString kRowSpecialKeyword = "ROW";
123 93 : return kRowSpecialKeyword;
124 0 : }
125 :
126 : //_____________________________________________________________________________
127 : const TString& AliMpSectorReader::GetPadRowsKeyword()
128 : {
129 : /// pad rows keyword
130 1161 : static const TString kPadRowsKeyword = "PAD_ROWS";
131 576 : return kPadRowsKeyword;
132 0 : }
133 :
134 : //_____________________________________________________________________________
135 : const TString& AliMpSectorReader::GetPadRowSegmentKeyword()
136 : {
137 : /// pad row segment keyword
138 2739 : static const TString kPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
139 1365 : return kPadRowSegmentKeyword;
140 0 : }
141 :
142 : //
143 : // ctors, dtor
144 : //
145 :
146 : //_____________________________________________________________________________
147 : AliMpSectorReader::AliMpSectorReader(AliMq::Station12Type station,
148 : AliMp::PlaneType plane)
149 12 : : TObject(),
150 12 : fStationType(station),
151 12 : fPlaneType(plane),
152 12 : fSector(0),
153 36 : fMotifReader(new AliMpMotifReader(AliMp::kStation12, station, plane))
154 :
155 60 : {
156 : /// Standard constructor
157 24 : }
158 :
159 : //_____________________________________________________________________________
160 : AliMpSectorReader::~AliMpSectorReader()
161 48 : {
162 : /// Destructor
163 :
164 24 : delete fMotifReader;
165 24 : }
166 :
167 : //
168 : // private methods
169 : //
170 :
171 : //_____________________________________________________________________________
172 : void AliMpSectorReader::ReadSectorData(const AliMpDataStreams& dataStreams,
173 : istream& in)
174 : {
175 : /// Read sector input data;
176 : /// prepare zones and rows vectors to be filled in.
177 :
178 24 : TString keyword;
179 12 : in >> keyword;
180 :
181 48 : AliDebugStream(2) << keyword << endl;
182 :
183 36 : if (keyword != GetSectorKeyword()) {
184 0 : AliErrorStream() << "Wrong file format." << endl;
185 0 : return;
186 : }
187 :
188 12 : Int_t nofZones, nofRows;
189 12 : TString directionStr;
190 12 : Double_t offsetX, offsetY;
191 12 : in >> nofZones;
192 12 : in >> nofRows;
193 12 : in >> directionStr;
194 12 : in >> offsetX;
195 12 : in >> offsetY;
196 :
197 : AliMp::Direction direction;
198 24 : direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
199 :
200 72 : AliDebugStream(2) << nofZones << " " << nofRows << endl;
201 :
202 48 : if ( nofZones < 0 || nofZones >= std::numeric_limits<Int_t>::max() ||
203 24 : nofRows < 0 || nofRows >= std::numeric_limits<Int_t>::max() ) {
204 0 : AliErrorStream() << "Wrong nofZones/nofRows value." << endl;
205 0 : return;
206 : }
207 :
208 60 : fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
209 12 : offsetX, offsetY);
210 :
211 12 : TString nextKeyword;
212 12 : in >> nextKeyword;
213 :
214 36 : if (nextKeyword != GetZoneKeyword()) {
215 0 : AliErrorStream() << "Wrong file format." << endl;
216 0 : return;
217 : }
218 :
219 12 : ReadZoneData(dataStreams, in);
220 48 : }
221 :
222 : //_____________________________________________________________________________
223 : void AliMpSectorReader::ReadZoneData(const AliMpDataStreams& dataStreams,
224 : istream& in)
225 : {
226 : /// Read zone input data;
227 : /// create zone and adds it to zones vector.
228 :
229 84 : Int_t zoneID;
230 42 : Double_t sizex, sizey;
231 42 : in >> zoneID;
232 42 : in >> sizex;
233 42 : in >> sizey;
234 42 : AliDebugStream(2)
235 42 : << GetZoneKeyword() << " " << zoneID << " "
236 42 : << sizex << " " << sizey << endl;
237 :
238 42 : AliMpZone* zone = fSector->GetZone(zoneID);
239 42 : zone->SetPadDimensions(sizex/2.,sizey/2.);
240 :
241 42 : TString nextKeyword;
242 42 : in >> nextKeyword;
243 :
244 126 : if (nextKeyword != GetSubZoneKeyword()) {
245 0 : AliErrorStream() << "Wrong file format." << endl;
246 0 : return;
247 : }
248 :
249 42 : ReadSubZoneData(dataStreams, in, zone);
250 84 : }
251 :
252 : //_____________________________________________________________________________
253 : void AliMpSectorReader::ReadSubZoneData(const AliMpDataStreams& dataStreams,
254 : istream& in, AliMpZone* zone)
255 : {
256 : /// Read subzone input data;
257 : /// create subzone and its to the specified zone.
258 :
259 438 : AliDebugStream(2) << GetSubZoneKeyword() << endl;
260 :
261 219 : AliMpVMotif* motif = ReadMotifData(dataStreams, in, zone);
262 219 : AliMpSubZone* subZone = new AliMpSubZone(motif);
263 219 : zone->AddSubZone(subZone);
264 :
265 219 : TString nextKeyword;
266 219 : in >> nextKeyword;
267 :
268 657 : if (nextKeyword != GetRowKeyword()) {
269 0 : AliErrorStream() << "Wrong file format." << endl;
270 0 : return;
271 : }
272 :
273 219 : ReadRowSegmentsData(dataStreams, in, zone, subZone);
274 438 : }
275 :
276 : //_____________________________________________________________________________
277 : AliMpVMotif* AliMpSectorReader::ReadMotifData(
278 : const AliMpDataStreams& dataStreams,
279 : istream& in, AliMpZone* zone)
280 : {
281 : /// Read the motif input data.
282 :
283 744 : TString motifID;
284 372 : TString motifTypeID;
285 372 : in >> motifID;
286 372 : in >> motifTypeID;
287 :
288 2232 : AliDebugStream(2) << motifID << " " << motifTypeID << endl;
289 :
290 372 : AliMpMotifMap* motifMap = fSector->GetMotifMap();
291 :
292 : AliMpMotifType* motifType = 0;
293 : AliMpVMotif* motif
294 372 : = motifMap->FindMotif(motifID, motifTypeID,
295 372 : zone->GetPadDimensionX(), zone->GetPadDimensionY());
296 372 : if (!motif) {
297 372 : motifType = motifMap->FindMotifType(motifTypeID);
298 372 : if (!motifType) {
299 318 : motifType = fMotifReader->BuildMotifType(dataStreams, motifTypeID);
300 318 : motifMap->AddMotifType(motifType);
301 : }
302 :
303 729 : if (zone->GetPadDimensionX() != 0. && zone->GetPadDimensionY() != 0.)
304 1428 : motif = new AliMpMotif(motifID, motifType,
305 357 : zone->GetPadDimensionX(), zone->GetPadDimensionY());
306 : else
307 30 : motif = fMotifReader->BuildMotifSpecial(dataStreams, motifID, motifType);
308 :
309 372 : if (motif)
310 372 : motifMap->AddMotif(motif);
311 :
312 : }
313 :
314 : return motif;
315 372 : }
316 :
317 : //_____________________________________________________________________________
318 : void AliMpSectorReader::ReadRowSegmentsData(const AliMpDataStreams& dataStreams,
319 : istream& in,
320 : AliMpZone* zone, AliMpSubZone* subZone)
321 : {
322 : /// Read row segments input data of a specified zone and subzone;
323 : /// creates row segment and add it to the specified subzone
324 : /// and a corresponding row in the rows vector.
325 :
326 438 : TString nextKeyword;
327 219 : do {
328 : //
329 : // Read data from file
330 : //
331 525 : Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
332 525 : in >> offX;
333 525 : in >> offY;
334 525 : in >> inRow;
335 525 : in >> nofMotifs;
336 525 : in >> firstMotifPositionId;
337 525 : in >> firstMotifPositionDId;
338 :
339 1050 : firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
340 :
341 1050 : AliDebugStream(2)
342 1575 : << GetRowKeyword() << " "
343 4200 : << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
344 1575 : << firstMotifPositionId << " " << firstMotifPositionDId
345 525 : << endl;
346 :
347 525 : in >> nextKeyword;
348 :
349 : //
350 : // Process data
351 : //
352 525 : AliMpRow* row = fSector->GetRow(inRow);
353 525 : AliMpVMotif* motif = subZone->GetMotif();
354 :
355 : // Create row segment and add it to its zone, row
356 : AliMpVRowSegment* rowSegment
357 2100 : = new AliMpRowSegment(row, motif, offX, offY, nofMotifs,
358 525 : firstMotifPositionId, firstMotifPositionDId);
359 :
360 525 : subZone->AddRowSegment(rowSegment);
361 525 : row->AddRowSegment(rowSegment);
362 1038 : }
363 2076 : while (!in.eof() && (nextKeyword == GetRowKeyword()));
364 :
365 450 : if (in.eof()) return;
366 :
367 621 : if (nextKeyword == GetZoneKeyword()) {
368 0 : ReadZoneData(dataStreams, in);
369 : }
370 531 : else if (nextKeyword == GetSubZoneKeyword()) {
371 0 : ReadSubZoneData(dataStreams, in, zone);
372 : }
373 : else {
374 0 : AliErrorStream() << "Wrong file format." << endl;
375 : }
376 426 : }
377 :
378 : //_____________________________________________________________________________
379 : void AliMpSectorReader::ReadSectorSpecialData(
380 : const AliMpDataStreams& dataStreams,
381 : istream& in, AliMp::XDirection direction)
382 : {
383 : /// Read sector input data
384 : /// with a special (irregular) motifs.
385 :
386 30 : TString keyword;
387 15 : in >> keyword;
388 :
389 60 : AliDebugStream(2) << keyword << endl;
390 :
391 45 : if (keyword != GetSectorSpecialKeyword()) {
392 0 : AliErrorStream() << "Wrong file format." << endl;
393 0 : return;
394 : }
395 :
396 15 : TString nextKeyword;
397 15 : in >> nextKeyword;
398 :
399 60 : AliDebugStream(2) << keyword << endl;
400 :
401 45 : if (nextKeyword != GetMotifKeyword()) {
402 0 : AliErrorStream() << "Wrong file format." << endl;
403 0 : return;
404 : }
405 :
406 15 : ReadMotifsSpecialData(dataStreams, in);
407 15 : ReadRowSpecialData(dataStreams, in, direction);
408 45 : }
409 :
410 : //_____________________________________________________________________________
411 : void AliMpSectorReader::ReadMotifsSpecialData(
412 : const AliMpDataStreams& dataStreams,
413 : istream& in)
414 : {
415 : /// Read the special (irregular) motifs input data.
416 :
417 30 : AliDebugStream(2) << GetMotifKeyword() << endl;
418 :
419 15 : TString nextKeyword;
420 15 : do {
421 153 : Int_t zone;
422 153 : in >> zone;
423 306 : AliMpVMotif* motif = ReadMotifData(dataStreams, in, fSector->GetZone(zone));
424 306 : AliMpSubZone* subZone = new AliMpSubZone(motif);
425 306 : fSector->GetZone(zone)->AddSubZone(subZone);
426 :
427 153 : in >> nextKeyword;
428 :
429 612 : AliDebugStream(2) << nextKeyword << endl;
430 306 : }
431 306 : while (nextKeyword == GetMotifKeyword());
432 :
433 45 : if (nextKeyword != GetRowSpecialKeyword()) {
434 0 : AliErrorStream() << "Wrong file format." << endl;
435 0 : return;
436 : }
437 30 : }
438 :
439 : //_____________________________________________________________________________
440 : void AliMpSectorReader::ReadRowSpecialData(
441 : const AliMpDataStreams& dataStreams,
442 : istream& in, AliMp::XDirection direction)
443 : {
444 : /// Read row input data
445 : /// with a special (irregular) motifs.
446 :
447 186 : Int_t id;
448 93 : in >> id;
449 :
450 93 : AliDebugStream(2) << id << endl;
451 :
452 : // Get the row and its border
453 93 : AliMpRow* row = fSector->GetRow(id);
454 :
455 : AliMpVRowSegmentSpecial* segment = 0;
456 93 : if (direction == AliMp::kLeft) {
457 36 : AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
458 36 : Double_t offsetX = firstNormalSeg->LeftBorderX();
459 :
460 : // Create a special row segment
461 72 : segment = new AliMpRowSegmentLSpecial(row, offsetX);
462 36 : row->AddRowSegmentInFront(segment);
463 36 : }
464 : else {
465 : AliMpVRowSegment* precedentNormalSeg
466 57 : = row->GetRowSegment(row->GetNofRowSegments()-1);
467 57 : Double_t offsetX = precedentNormalSeg->RightBorderX();
468 :
469 : // Create a special row segment
470 114 : segment = new AliMpRowSegmentRSpecial(row, offsetX);
471 57 : row->AddRowSegment(segment);
472 : }
473 :
474 93 : TString nextKeyword;
475 93 : in >> nextKeyword;
476 :
477 372 : AliDebugStream(2) << nextKeyword << endl;
478 :
479 279 : if (nextKeyword != GetPadRowsKeyword()) {
480 0 : AliErrorStream() << "Wrong file format." << endl;
481 0 : return;
482 : }
483 :
484 15 : ReadRowSegmentSpecialData(dataStreams, in, segment, direction);
485 :
486 : // Update row segment and set it to all subzones associated with
487 : // contained motifs
488 :
489 93 : segment->UpdateMotifVector();
490 93 : segment->UpdatePadsOffset();
491 :
492 828 : for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
493 : AliMpSubZone* subZone = 0;
494 : Int_t j = 0;
495 1842 : while (!subZone && j<fSector->GetNofZones())
496 1107 : subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
497 :
498 366 : if (subZone) subZone->AddRowSegment(segment);
499 : }
500 186 : }
501 :
502 : //_____________________________________________________________________________
503 : void AliMpSectorReader::ReadRowSegmentSpecialData(
504 : const AliMpDataStreams& dataStreams,
505 : istream& in,
506 : AliMpVRowSegmentSpecial* segment,
507 : AliMp::XDirection direction)
508 : {
509 : /// Read row segment input data
510 : /// with a special (irregular) motifs.
511 :
512 996 : Int_t nofPadRows;
513 498 : in >> nofPadRows;
514 :
515 498 : AliDebugStream(2) << nofPadRows << endl;
516 :
517 996 : if ( nofPadRows < 0 || nofPadRows >= std::numeric_limits<Int_t>::max()) {
518 0 : AliErrorStream() << "Wrong nofPadRows value." << endl;
519 0 : return;
520 : }
521 :
522 498 : TString keyword;
523 498 : in >> keyword;
524 :
525 1992 : AliDebugStream(2) << keyword << endl;
526 :
527 1494 : if (keyword != GetPadRowSegmentKeyword()) {
528 0 : AliErrorStream() << "Wrong file format." << endl;
529 0 : return;
530 : }
531 :
532 : //
533 : // Process data
534 : //
535 :
536 498 : TObjArray newPadRows;
537 3528 : for (Int_t i=0; i<nofPadRows; i++) {
538 :
539 : // Create pad row
540 2532 : AliMpPadRow* padRow = new AliMpPadRow(direction);
541 1266 : segment->AddPadRow(padRow);
542 :
543 : // Keep the new rows in a temporary vector
544 1266 : newPadRows.Add(padRow);
545 : }
546 :
547 498 : TString nextKeyword;
548 : do {
549 : //
550 : // Read data from file
551 : //
552 882 : Int_t nofPadsInRow, motifPositionId;
553 1764 : TString motifId, motifTypeId;
554 882 : in >> nofPadsInRow;
555 882 : in >> motifId;
556 882 : in >> motifPositionId;
557 :
558 1764 : motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
559 :
560 1764 : AliDebugStream(2)
561 5292 : << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
562 :
563 882 : in >> nextKeyword;
564 :
565 3528 : AliDebugStream(2) << nextKeyword << endl;
566 :
567 : //
568 : // Process data
569 : //
570 :
571 6984 : for (Int_t i=0; i<nofPadRows; i++) {
572 :
573 : // Get pad row from the temporary vector
574 4338 : AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
575 :
576 : // Find motif
577 2169 : AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
578 :
579 2169 : if (!motif) {
580 0 : AliErrorStream() << "Unknown motif" << endl;
581 0 : return;
582 : }
583 :
584 : // Create pad row segment
585 8676 : padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
586 2169 : motifPositionId, nofPadsInRow);
587 2169 : }
588 2631 : }
589 3498 : while (!in.eof() && (nextKeyword == GetPadRowSegmentKeyword()));
590 :
591 1011 : if (in.eof()) return;
592 :
593 1449 : if (nextKeyword == GetPadRowsKeyword()) {
594 0 : ReadRowSegmentSpecialData(dataStreams, in, segment, direction);
595 : }
596 234 : else if (nextKeyword == GetRowSpecialKeyword()) {
597 0 : ReadRowSpecialData(dataStreams, in, direction);
598 : }
599 : else {
600 0 : AliErrorStream() << "Wrong file format." << endl;
601 : }
602 1977 : }
603 :
604 : //
605 : // public methods
606 : //
607 :
608 : //_____________________________________________________________________________
609 : AliMpSector* AliMpSectorReader::BuildSector(const AliMpDataStreams& dataStreams)
610 : {
611 : /// Read the mapping data from stream and create the basic objects: \n
612 : /// zones, subzones, rows, row segments, motifs.
613 :
614 : // Open input stream
615 : //
616 : istream& in
617 24 : = dataStreams.
618 24 : CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
619 :
620 12 : ReadSectorData(dataStreams, in);
621 24 : delete ∈
622 :
623 12 : fSector->SetRowSegmentOffsets();
624 :
625 : // Open input stream for special inner zone
626 :
627 : // add is data function
628 :
629 12 : TString sectorSpecialFileName
630 12 : = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
631 24 : if ( dataStreams.IsDataStream(sectorSpecialFileName) ) {
632 : istream& in2
633 9 : = dataStreams.
634 : CreateDataStream(sectorSpecialFileName);
635 :
636 9 : ReadSectorSpecialData(dataStreams, in2, AliMp::kLeft);
637 :
638 18 : delete &in2;
639 9 : }
640 :
641 : // Open input file for special outer zone
642 12 : TString sectorSpecialFileName2
643 12 : = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
644 24 : if ( dataStreams.IsDataStream(sectorSpecialFileName2) ) {
645 : istream& in3
646 6 : = dataStreams.
647 : CreateDataStream(sectorSpecialFileName2);
648 :
649 6 : ReadSectorSpecialData(dataStreams, in3, AliMp::kRight);
650 :
651 12 : delete &in3;
652 6 : }
653 :
654 12 : fSector->Initialize();
655 :
656 12 : return fSector;
657 12 : }
658 :
|