AliRoot Core  edcc906 (edcc906)
AliMpSectorReader.cxx
Go to the documentation of this file.
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"
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 
63 ClassImp(AliMpSectorReader)
65 
66 //
67 // static private methods
68 //
69 
70 //_____________________________________________________________________________
71 const TString& AliMpSectorReader::GetSectorKeyword()
72 {
74  static const TString kSectorKeyword = "SECTOR_DATA";
75  return kSectorKeyword;
76 }
77 
78 //_____________________________________________________________________________
80 {
82  static const TString kZoneKeyword = "ZONE";
83  return kZoneKeyword;
84 }
85 
86 //_____________________________________________________________________________
88 {
90  static const TString kSubZoneKeyword = "SUBZONE";
91  return kSubZoneKeyword;
92 }
93 
94 //_____________________________________________________________________________
96 {
98  static const TString kRowKeyword = "ROW_SEGMENT";
99  return kRowKeyword;
100 }
101 
102 //_____________________________________________________________________________
104 {
106  static const TString kSectorSpecialKeyword = "SECTOR_SPECIAL_DATA";
107  return kSectorSpecialKeyword;
108 }
109 
110 //_____________________________________________________________________________
112 {
114  static const TString kMotifKeyword = "MOTIF";
115  return kMotifKeyword;
116 }
117 
118 //_____________________________________________________________________________
120 {
122  static const TString kRowSpecialKeyword = "ROW";
123  return kRowSpecialKeyword;
124 }
125 
126 //_____________________________________________________________________________
128 {
130  static const TString kPadRowsKeyword = "PAD_ROWS";
131  return kPadRowsKeyword;
132 }
133 
134 //_____________________________________________________________________________
136 {
138  static const TString kPadRowSegmentKeyword = "PAD_ROW_SEGMENT";
139  return kPadRowSegmentKeyword;
140 }
141 
142 //
143 // ctors, dtor
144 //
145 
146 //_____________________________________________________________________________
148  AliMp::PlaneType plane)
149  : TObject(),
150  fStationType(station),
151  fPlaneType(plane),
152  fSector(0),
153  fMotifReader(new AliMpMotifReader(AliMp::kStation12, station, plane))
154 
155 {
157 }
158 
159 //_____________________________________________________________________________
161 {
163 
164  delete fMotifReader;
165 }
166 
167 //
168 // private methods
169 //
170 
171 //_____________________________________________________________________________
173  istream& in)
174 {
177 
178  TString keyword;
179  in >> keyword;
180 
181  AliDebugStream(2) << keyword << endl;
182 
183  if (keyword != GetSectorKeyword()) {
184  AliErrorStream() << "Wrong file format." << endl;
185  return;
186  }
187 
188  Int_t nofZones, nofRows;
189  TString directionStr;
190  Double_t offsetX, offsetY;
191  in >> nofZones;
192  in >> nofRows;
193  in >> directionStr;
194  in >> offsetX;
195  in >> offsetY;
196 
197  AliMp::Direction direction;
198  direction = (directionStr == "Y") ? AliMp::kY : AliMp::kX;
199 
200  AliDebugStream(2) << nofZones << " " << nofRows << endl;
201 
202  if ( nofZones < 0 || nofZones >= std::numeric_limits<Int_t>::max() ||
203  nofRows < 0 || nofRows >= std::numeric_limits<Int_t>::max() ) {
204  AliErrorStream() << "Wrong nofZones/nofRows value." << endl;
205  return;
206  }
207 
208  fSector = new AliMpSector("Not defined", nofZones, nofRows,direction,
209  offsetX, offsetY);
210 
211  TString nextKeyword;
212  in >> nextKeyword;
213 
214  if (nextKeyword != GetZoneKeyword()) {
215  AliErrorStream() << "Wrong file format." << endl;
216  return;
217  }
218 
219  ReadZoneData(dataStreams, in);
220 }
221 
222 //_____________________________________________________________________________
224  istream& in)
225 {
228 
229  Int_t zoneID;
230  Double_t sizex, sizey;
231  in >> zoneID;
232  in >> sizex;
233  in >> sizey;
234  AliDebugStream(2)
235  << GetZoneKeyword() << " " << zoneID << " "
236  << sizex << " " << sizey << endl;
237 
238  AliMpZone* zone = fSector->GetZone(zoneID);
239  zone->SetPadDimensions(sizex/2.,sizey/2.);
240 
241  TString nextKeyword;
242  in >> nextKeyword;
243 
244  if (nextKeyword != GetSubZoneKeyword()) {
245  AliErrorStream() << "Wrong file format." << endl;
246  return;
247  }
248 
249  ReadSubZoneData(dataStreams, in, zone);
250 }
251 
252 //_____________________________________________________________________________
254  istream& in, AliMpZone* zone)
255 {
258 
259  AliDebugStream(2) << GetSubZoneKeyword() << endl;
260 
261  AliMpVMotif* motif = ReadMotifData(dataStreams, in, zone);
262  AliMpSubZone* subZone = new AliMpSubZone(motif);
263  zone->AddSubZone(subZone);
264 
265  TString nextKeyword;
266  in >> nextKeyword;
267 
268  if (nextKeyword != GetRowKeyword()) {
269  AliErrorStream() << "Wrong file format." << endl;
270  return;
271  }
272 
273  ReadRowSegmentsData(dataStreams, in, zone, subZone);
274 }
275 
276 //_____________________________________________________________________________
278  const AliMpDataStreams& dataStreams,
279  istream& in, AliMpZone* zone)
280 {
282 
283  TString motifID;
284  TString motifTypeID;
285  in >> motifID;
286  in >> motifTypeID;
287 
288  AliDebugStream(2) << motifID << " " << motifTypeID << endl;
289 
290  AliMpMotifMap* motifMap = fSector->GetMotifMap();
291 
292  AliMpMotifType* motifType = 0;
293  AliMpVMotif* motif
294  = motifMap->FindMotif(motifID, motifTypeID,
295  zone->GetPadDimensionX(), zone->GetPadDimensionY());
296  if (!motif) {
297  motifType = motifMap->FindMotifType(motifTypeID);
298  if (!motifType) {
299  motifType = fMotifReader->BuildMotifType(dataStreams, motifTypeID);
300  motifMap->AddMotifType(motifType);
301  }
302 
303  if (zone->GetPadDimensionX() != 0. && zone->GetPadDimensionY() != 0.)
304  motif = new AliMpMotif(motifID, motifType,
305  zone->GetPadDimensionX(), zone->GetPadDimensionY());
306  else
307  motif = fMotifReader->BuildMotifSpecial(dataStreams, motifID, motifType);
308 
309  if (motif)
310  motifMap->AddMotif(motif);
311 
312  }
313 
314  return motif;
315 }
316 
317 //_____________________________________________________________________________
319  istream& in,
320  AliMpZone* zone, AliMpSubZone* subZone)
321 {
325 
326  TString nextKeyword;
327  do {
328  //
329  // Read data from file
330  //
331  Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
332  in >> offX;
333  in >> offY;
334  in >> inRow;
335  in >> nofMotifs;
336  in >> firstMotifPositionId;
337  in >> firstMotifPositionDId;
338 
339  firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
340 
341  AliDebugStream(2)
342  << GetRowKeyword() << " "
343  << offX << " " << offY << " " << inRow << " " << nofMotifs << " "
344  << firstMotifPositionId << " " << firstMotifPositionDId
345  << endl;
346 
347  in >> nextKeyword;
348 
349  //
350  // Process data
351  //
352  AliMpRow* row = fSector->GetRow(inRow);
353  AliMpVMotif* motif = subZone->GetMotif();
354 
355  // Create row segment and add it to its zone, row
356  AliMpVRowSegment* rowSegment
357  = new AliMpRowSegment(row, motif, offX, offY, nofMotifs,
358  firstMotifPositionId, firstMotifPositionDId);
359 
360  subZone->AddRowSegment(rowSegment);
361  row->AddRowSegment(rowSegment);
362  }
363  while (!in.eof() && (nextKeyword == GetRowKeyword()));
364 
365  if (in.eof()) return;
366 
367  if (nextKeyword == GetZoneKeyword()) {
368  ReadZoneData(dataStreams, in);
369  }
370  else if (nextKeyword == GetSubZoneKeyword()) {
371  ReadSubZoneData(dataStreams, in, zone);
372  }
373  else {
374  AliErrorStream() << "Wrong file format." << endl;
375  }
376 }
377 
378 //_____________________________________________________________________________
380  const AliMpDataStreams& dataStreams,
381  istream& in, AliMp::XDirection direction)
382 {
385 
386  TString keyword;
387  in >> keyword;
388 
389  AliDebugStream(2) << keyword << endl;
390 
391  if (keyword != GetSectorSpecialKeyword()) {
392  AliErrorStream() << "Wrong file format." << endl;
393  return;
394  }
395 
396  TString nextKeyword;
397  in >> nextKeyword;
398 
399  AliDebugStream(2) << keyword << endl;
400 
401  if (nextKeyword != GetMotifKeyword()) {
402  AliErrorStream() << "Wrong file format." << endl;
403  return;
404  }
405 
406  ReadMotifsSpecialData(dataStreams, in);
407  ReadRowSpecialData(dataStreams, in, direction);
408 }
409 
410 //_____________________________________________________________________________
412  const AliMpDataStreams& dataStreams,
413  istream& in)
414 {
416 
417  AliDebugStream(2) << GetMotifKeyword() << endl;
418 
419  TString nextKeyword;
420  do {
421  Int_t zone;
422  in >> zone;
423  AliMpVMotif* motif = ReadMotifData(dataStreams, in, fSector->GetZone(zone));
424  AliMpSubZone* subZone = new AliMpSubZone(motif);
425  fSector->GetZone(zone)->AddSubZone(subZone);
426 
427  in >> nextKeyword;
428 
429  AliDebugStream(2) << nextKeyword << endl;
430  }
431  while (nextKeyword == GetMotifKeyword());
432 
433  if (nextKeyword != GetRowSpecialKeyword()) {
434  AliErrorStream() << "Wrong file format." << endl;
435  return;
436  }
437 }
438 
439 //_____________________________________________________________________________
441  const AliMpDataStreams& dataStreams,
442  istream& in, AliMp::XDirection direction)
443 {
446 
447  Int_t id;
448  in >> id;
449 
450  AliDebugStream(2) << id << endl;
451 
452  // Get the row and its border
453  AliMpRow* row = fSector->GetRow(id);
454 
455  AliMpVRowSegmentSpecial* segment = 0;
456  if (direction == AliMp::kLeft) {
457  AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
458  Double_t offsetX = firstNormalSeg->LeftBorderX();
459 
460  // Create a special row segment
461  segment = new AliMpRowSegmentLSpecial(row, offsetX);
462  row->AddRowSegmentInFront(segment);
463  }
464  else {
465  AliMpVRowSegment* precedentNormalSeg
466  = row->GetRowSegment(row->GetNofRowSegments()-1);
467  Double_t offsetX = precedentNormalSeg->RightBorderX();
468 
469  // Create a special row segment
470  segment = new AliMpRowSegmentRSpecial(row, offsetX);
471  row->AddRowSegment(segment);
472  }
473 
474  TString nextKeyword;
475  in >> nextKeyword;
476 
477  AliDebugStream(2) << nextKeyword << endl;
478 
479  if (nextKeyword != GetPadRowsKeyword()) {
480  AliErrorStream() << "Wrong file format." << endl;
481  return;
482  }
483 
484  ReadRowSegmentSpecialData(dataStreams, in, segment, direction);
485 
486  // Update row segment and set it to all subzones associated with
487  // contained motifs
488 
489  segment->UpdateMotifVector();
490  segment->UpdatePadsOffset();
491 
492  for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
493  AliMpSubZone* subZone = 0;
494  Int_t j = 0;
495  while (!subZone && j<fSector->GetNofZones())
496  subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
497 
498  if (subZone) subZone->AddRowSegment(segment);
499  }
500 }
501 
502 //_____________________________________________________________________________
504  const AliMpDataStreams& dataStreams,
505  istream& in,
506  AliMpVRowSegmentSpecial* segment,
507  AliMp::XDirection direction)
508 {
511 
512  Int_t nofPadRows;
513  in >> nofPadRows;
514 
515  AliDebugStream(2) << nofPadRows << endl;
516 
517  if ( nofPadRows < 0 || nofPadRows >= std::numeric_limits<Int_t>::max()) {
518  AliErrorStream() << "Wrong nofPadRows value." << endl;
519  return;
520  }
521 
522  TString keyword;
523  in >> keyword;
524 
525  AliDebugStream(2) << keyword << endl;
526 
527  if (keyword != GetPadRowSegmentKeyword()) {
528  AliErrorStream() << "Wrong file format." << endl;
529  return;
530  }
531 
532  //
533  // Process data
534  //
535 
536  TObjArray newPadRows;
537  for (Int_t i=0; i<nofPadRows; i++) {
538 
539  // Create pad row
540  AliMpPadRow* padRow = new AliMpPadRow(direction);
541  segment->AddPadRow(padRow);
542 
543  // Keep the new rows in a temporary vector
544  newPadRows.Add(padRow);
545  }
546 
547  TString nextKeyword;
548  do {
549  //
550  // Read data from file
551  //
552  Int_t nofPadsInRow, motifPositionId;
553  TString motifId, motifTypeId;
554  in >> nofPadsInRow;
555  in >> motifId;
556  in >> motifPositionId;
557 
558  motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
559 
560  AliDebugStream(2)
561  << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
562 
563  in >> nextKeyword;
564 
565  AliDebugStream(2) << nextKeyword << endl;
566 
567  //
568  // Process data
569  //
570 
571  for (Int_t i=0; i<nofPadRows; i++) {
572 
573  // Get pad row from the temporary vector
574  AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
575 
576  // Find motif
577  AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
578 
579  if (!motif) {
580  AliErrorStream() << "Unknown motif" << endl;
581  return;
582  }
583 
584  // Create pad row segment
585  padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif),
586  motifPositionId, nofPadsInRow);
587  }
588  }
589  while (!in.eof() && (nextKeyword == GetPadRowSegmentKeyword()));
590 
591  if (in.eof()) return;
592 
593  if (nextKeyword == GetPadRowsKeyword()) {
594  ReadRowSegmentSpecialData(dataStreams, in, segment, direction);
595  }
596  else if (nextKeyword == GetRowSpecialKeyword()) {
597  ReadRowSpecialData(dataStreams, in, direction);
598  }
599  else {
600  AliErrorStream() << "Wrong file format." << endl;
601  }
602 }
603 
604 //
605 // public methods
606 //
607 
608 //_____________________________________________________________________________
610 {
613 
614  // Open input stream
615  //
616  istream& in
617  = dataStreams.
619 
620  ReadSectorData(dataStreams, in);
621  delete &in;
622 
624 
625  // Open input stream for special inner zone
626 
627  // add is data function
628 
629  TString sectorSpecialFileName
631  if ( dataStreams.IsDataStream(sectorSpecialFileName) ) {
632  istream& in2
633  = dataStreams.
634  CreateDataStream(sectorSpecialFileName);
635 
636  ReadSectorSpecialData(dataStreams, in2, AliMp::kLeft);
637 
638  delete &in2;
639  }
640 
641  // Open input file for special outer zone
642  TString sectorSpecialFileName2
644  if ( dataStreams.IsDataStream(sectorSpecialFileName2) ) {
645  istream& in3
646  = dataStreams.
647  CreateDataStream(sectorSpecialFileName2);
648 
649  ReadSectorSpecialData(dataStreams, in3, AliMp::kRight);
650 
651  delete &in3;
652  }
653 
654  fSector->Initialize();
655 
656  return fSector;
657 }
658 
static const TString & GetSectorSpecialKeyword()
void AddSubZone(AliMpSubZone *subZone)
Definition: AliMpZone.cxx:72
AliMq::Station12Type fStationType
station type
A pad row composed of the pad row segments.
Definition: AliMpPadRow.h:25
AliMpMotifReader * fMotifReader
motif reader
direction in x
station 1,2 (quadrants)
#define AliErrorStream()
Definition: AliLog.h:630
static TString SectorSpecialFilePath2(AliMq::Station12Type station, AliMp::PlaneType plane)
Definition: AliMpFiles.cxx:401
void AddPadRow(AliMpPadRow *padRow)
void ReadRowSegmentSpecialData(const AliMpDataStreams &dataStreams, istream &in, AliMpVRowSegmentSpecial *segment, AliMp::XDirection direction)
#define TObjArray
AliMpVMotif * GetMotif() const
AliMpMotifSpecial * BuildMotifSpecial(const AliMpDataStreams &dataStreams, const TString &motifID, AliMpMotifType *motifType, Double_t scale=1.0)
static TString SectorFilePath(AliMq::Station12Type station, AliMp::PlaneType plane)
Definition: AliMpFiles.cxx:381
AliMp::PlaneType fPlaneType
plane type
static const TString & GetZoneKeyword()
static const TString & GetPadRowSegmentKeyword()
Class that takes care of reading the sector data.
void ReadMotifsSpecialData(const AliMpDataStreams &dataStreams, istream &in)
AliMpVMotif * ReadMotifData(const AliMpDataStreams &dataStreams, istream &in, AliMpZone *zone)
AliMpSector * BuildSector(const AliMpDataStreams &dataStreams)
Bool_t IsDataStream(const TString &path) const
AliMpMotifType * BuildMotifType(const AliMpDataStreams &dataStreams, const TString &motifTypeId)
void ReadSectorSpecialData(const AliMpDataStreams &dataStreams, istream &in, AliMp::XDirection direction)
virtual void UpdatePadsOffset()=0
Update pads offset.
void SetPadDimensions(Double_t dx, Double_t dy)
Definition: AliMpZone.cxx:94
void ReadRowSegmentsData(const AliMpDataStreams &dataStreams, istream &in, AliMpZone *zone, AliMpSubZone *subZone)
void ReadZoneData(const AliMpDataStreams &dataStreams, istream &in)
AliMpVMotif * FindMotif(const TString &motifID) const
AliMpSector * fSector
sector
A region of pads of the same dimensions composed of subzones.
Definition: AliMpZone.h:25
An interface for a row segment.
static const TString & GetPadRowsKeyword()
static const TString & GetSubZoneKeyword()
AliMpVRowSegment * GetRowSegment(Int_t i) const
Definition: AliMpRow.cxx:433
void Initialize()
A special inner row segment composed of the pad rows.
void ReadSubZoneData(const AliMpDataStreams &dataStreams, istream &in, AliMpZone *zone)
Motif map containers.
Definition: AliMpMotifMap.h:34
static const TString & GetSectorKeyword()
Bool_t AddMotif(AliMpVMotif *motif, Bool_t warn=true)
A row segment composed of the the identic motifs.
void SetRowSegmentOffsets()
A special outer row segment composed of the pad rows.
Double_t GetPadDimensionY() const
Return pad y dimensions.
Definition: AliMpZone.h:70
void AddRowSegment(AliMpVRowSegment *rowSegment)
Definition: AliMpRow.cxx:164
A row composed of the row segments.
Definition: AliMpRow.h:26
AliMpMotifType * FindMotifType(const TString &motifTypeID) const
A sector (quadrant) of the MUON chamber of stations 1 and 2.
Definition: AliMpSector.h:34
static TString SectorSpecialFilePath(AliMq::Station12Type station, AliMp::PlaneType plane)
Definition: AliMpFiles.cxx:391
static const TString & GetMotifKeyword()
virtual AliMpVMotif * GetMotif(Int_t i) const
Return the i-th motif of this row segment.
Abstract base class for a special row segment composed of the pad rows.
AliMpMotifMap * GetMotifMap() const
Return the motif map.
Definition: AliMpSector.h:159
AliMpSectorReader()
Not implemented.
Abstract base class for a motif with its unique ID and the motif type.
Definition: AliMpVMotif.h:24
void AddRowSegment(AliMpVRowSegment *rowSegment)
#define AliDebugStream(level)
Definition: AliLog.h:388
Bool_t AddMotifType(AliMpMotifType *motifType, Bool_t warn=true)
Class that takes care of reading the motifs data.
virtual Int_t GetNofMotifs() const
Return the number of motifs in this this row segment.
AliMpSubZone * FindSubZone(const AliMpVMotif *motif) const
Definition: AliMpZone.cxx:80
void AddRowSegmentInFront(AliMpVRowSegment *rowSegment)
Definition: AliMpRow.cxx:172
void ReadSectorData(const AliMpDataStreams &dataStreams, istream &in)
virtual Double_t LeftBorderX() const =0
Return the x coordinate of the left border in the global coordinate system.
static const TString & GetRowKeyword()
Double_t GetPadDimensionX() const
Return pad x dimensions.
Definition: AliMpZone.h:66
static const TString & GetRowSpecialKeyword()
Int_t GetNofRowSegments() const
Definition: AliMpRow.cxx:425
special row segments built from left to right
A motif with its unique ID and the motif type.
Definition: AliMpMotif.h:23
AliMpRow * GetRow(Int_t i) const
AliMpVPadRowSegment * AddPadRowSegment(AliMpMotif *motif, Int_t motifPositionId, Int_t nofPads)
Definition: AliMpPadRow.cxx:97
virtual Double_t RightBorderX() const =0
Return the x coordinate of the right border in the global coordinate system.
void ReadRowSpecialData(const AliMpDataStreams &dataStreams, istream &in, AliMp::XDirection direction)
AliMpZone * GetZone(Int_t i) const
The namespace for mapping enums and related functions.
static Int_t ManuMask(AliMp::PlaneType planeType)
Class that defines the motif properties.
Mapping data streams provider.
A region in zone composed of the row segments with the same motif type.
Definition: AliMpSubZone.h:23
direction in y
special row segments built from right to left