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