]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorReader.cxx
Removing a comma that gcc 3.4 does not like ;-)
[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                             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(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, 
215                           zone->GetPadDimensionX(), zone->GetPadDimensionY());
216   if (!motif) {    
217     motifType = motifMap->FindMotifType(motifTypeID);
218     if (!motifType) {
219       motifType = fMotifReader->BuildMotifType(motifTypeID);     
220       motifMap->AddMotifType(motifType);
221     }
222     
223     if (zone->GetPadDimensionX() != 0. && zone->GetPadDimensionY() != 0.) 
224       motif = new AliMpMotif(motifID, motifType, 
225                      zone->GetPadDimensionX(), zone->GetPadDimensionY());
226     else 
227       motif = fMotifReader->BuildMotifSpecial(motifID, motifType);
228       
229     if (motif) 
230       motifMap->AddMotif(motif);
231
232   }  
233
234   return motif;   
235 }  
236
237 //_____________________________________________________________________________
238 void AliMpSectorReader::ReadRowSegmentsData(istream& in, 
239                                       AliMpZone* zone, AliMpSubZone* subZone)
240 {
241 /// Read row segments input data of a specified zone and subzone;
242 /// creates row segment and add it to the specified subzone
243 /// and a corresponding row in the rows vector.
244
245   TString nextKeyword;
246   do {
247     // 
248     // Read data from file
249     //
250     Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
251     in >> offX;
252     in >> offY;
253     in >> inRow;
254     in >> nofMotifs;
255     in >> firstMotifPositionId;
256     in >> firstMotifPositionDId;
257     
258     firstMotifPositionId |= AliMpConstants::ManuMask(fPlaneType);
259     
260     AliDebugStream(2)
261       << fgkRowKeyword << " " 
262       << offX << " " << offY << " " << inRow << " " << nofMotifs << " " 
263       << firstMotifPositionId << " " << firstMotifPositionDId
264       << endl;
265
266     in >> nextKeyword;
267
268     //
269     // Process data
270     //
271     AliMpRow* row = fSector->GetRow(inRow);
272     AliMpVMotif* motif = subZone->GetMotif();
273     
274     // Create row segment and add it to its zone, row   
275     AliMpVRowSegment* rowSegment
276       = new AliMpRowSegment(row, motif, offX, offY, nofMotifs, 
277                         firstMotifPositionId, firstMotifPositionDId);
278                         
279     subZone->AddRowSegment(rowSegment);
280     row->AddRowSegment(rowSegment);
281   }
282   while (!in.eof() && (nextKeyword == fgkRowKeyword));
283
284   if (in.eof()) return;
285
286   if (nextKeyword == fgkZoneKeyword) {
287     ReadZoneData(in);
288   }
289   else if (nextKeyword == fgkSubZoneKeyword) {
290     ReadSubZoneData(in, zone);
291   }   
292   else {
293     Fatal("ReadRowSegmentsData", "Wrong file format.");
294   } 
295 }   
296
297 //_____________________________________________________________________________
298 void AliMpSectorReader::ReadSectorSpecialData(istream& in, AliMp::XDirection direction)
299 {
300 /// Read sector input data
301 /// with a special (irregular) motifs.
302
303   TString keyword;
304   in >> keyword;
305
306   AliDebugStream(2) << keyword << endl;
307
308   if (keyword != fgkSectorSpecialKeyword) {
309      Fatal("ReadSectorSpecialData", "Wrong file format.");
310      return;
311   }   
312
313   TString nextKeyword;
314   in >> nextKeyword;
315
316   AliDebugStream(2) << keyword << endl;
317     
318   if (nextKeyword != fgkMotifKeyword) {
319     Fatal("ReadSectorSpecialData", "Wrong file format.");
320     return;
321   }  
322
323   ReadMotifsSpecialData(in);     
324   ReadRowSpecialData(in, direction); 
325 }  
326
327 //_____________________________________________________________________________
328 void AliMpSectorReader::ReadMotifsSpecialData(istream& in)
329 {
330 /// Read the special (irregular) motifs input data.
331
332   AliDebugStream(2) << fgkMotifKeyword << endl;
333
334   TString nextKeyword;
335   do {
336     Int_t zone;
337     in >> zone;
338     AliMpVMotif* motif =  ReadMotifData(in, fSector->GetZone(zone));
339     AliMpSubZone* subZone = new AliMpSubZone(motif); 
340     fSector->GetZone(zone)->AddSubZone(subZone); 
341   
342     in >> nextKeyword;
343
344     AliDebugStream(2) << nextKeyword << endl;      
345   }
346   while (nextKeyword == fgkMotifKeyword);
347     
348   if (nextKeyword != fgkRowSpecialKeyword) {
349      Fatal("ReadMotifSpecialData", "Wrong file format.");
350      return;
351   }      
352 }  
353
354 //_____________________________________________________________________________
355 void AliMpSectorReader::ReadRowSpecialData(istream& in, AliMp::XDirection direction)
356 {
357 /// Read row input data
358 /// with a special (irregular) motifs.
359
360   Int_t id;
361   in >> id;
362
363   AliDebugStream(2) << id << endl;      
364   
365   // Get the row and its border
366   AliMpRow* row = fSector->GetRow(id);
367
368   AliMpVRowSegmentSpecial* segment = 0;
369   if (direction == AliMp::kLeft) {
370     AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
371     Double_t offsetX = firstNormalSeg->LeftBorderX();
372   
373     // Create a special row segment
374     segment = new AliMpRowSegmentLSpecial(row, offsetX);
375     row->AddRowSegmentInFront(segment);
376   }
377   else { 
378     AliMpVRowSegment* precedentNormalSeg 
379       = row->GetRowSegment(row->GetNofRowSegments()-1);
380     Double_t offsetX = precedentNormalSeg->RightBorderX();
381   
382     // Create a special row segment
383     segment = new AliMpRowSegmentRSpecial(row, offsetX);
384     row->AddRowSegment(segment);
385   }  
386       
387   TString nextKeyword;
388   in >> nextKeyword;
389   
390   AliDebugStream(2) << nextKeyword << endl;
391     
392   if (nextKeyword != fgkPadRowsKeyword) {
393      Fatal("ReadRowSpecialData", "Wrong file format.");
394      return;
395   }  
396     
397   ReadRowSegmentSpecialData(in, segment, direction); 
398   
399   // Update row segment and set it to all subzones associated with
400   // contained motifs
401   
402   segment->UpdateMotifVector();
403   segment->UpdatePadsOffset();
404   
405   for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
406     AliMpSubZone* subZone = 0;
407     Int_t j = 0;
408     while (!subZone && j<fSector->GetNofZones())
409       subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
410     
411     subZone->AddRowSegment(segment);
412   }  
413 }  
414
415 //_____________________________________________________________________________
416 void AliMpSectorReader::ReadRowSegmentSpecialData(istream& in, 
417                                             AliMpVRowSegmentSpecial* segment,
418                                             AliMp::XDirection direction)
419 {
420 /// Read row segment input data
421 /// with a special (irregular) motifs.
422
423   Int_t nofPadRows;
424   in >> nofPadRows;
425   
426   AliDebugStream(2) << nofPadRows << endl;
427   
428   TString keyword;
429   in >> keyword;
430
431   AliDebugStream(2) << keyword << endl;
432     
433   if (keyword != fgkPadRowSegmentKeyword) {
434      Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
435      return;
436   }  
437   
438   //
439   // Process data
440   //
441     
442   TObjArray newPadRows;
443   for (Int_t i=0; i<nofPadRows; i++) {
444     
445      // Create pad row
446      AliMpPadRow* padRow = new AliMpPadRow(direction);
447      segment->AddPadRow(padRow);
448      
449      // Keep the new rows in a temporary vector
450      newPadRows.Add(padRow);
451   }   
452       
453   TString nextKeyword;
454   do {
455     // 
456     // Read data from file
457     //
458     Int_t    nofPadsInRow, motifPositionId;
459     TString   motifId, motifTypeId;
460     in >> nofPadsInRow;
461     in >> motifId;
462     in >> motifPositionId; 
463   
464     motifPositionId |= AliMpConstants::ManuMask(fPlaneType);
465
466     AliDebugStream(2)
467       << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
468
469     in >> nextKeyword;
470
471     AliDebugStream(2) << nextKeyword << endl;
472
473     //
474     // Process data
475     //
476     
477     for (Int_t i=0; i<nofPadRows; i++) {
478     
479       // Get pad row from the temporary vector
480       AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
481       
482       // Find motif
483       AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
484       
485       if (!motif) {
486         Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
487         return;
488       }
489
490       // Create pad row segment
491       padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif), 
492                                motifPositionId, nofPadsInRow);
493     }  
494   }
495   while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
496   
497   if (in.eof()) return;
498
499   if (nextKeyword == fgkPadRowsKeyword) {
500     ReadRowSegmentSpecialData(in, segment, direction);
501   }
502   else if (nextKeyword == fgkRowSpecialKeyword) {
503     ReadRowSpecialData(in, direction);
504   }   
505   else {
506     Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
507   } 
508 }  
509
510 //
511 // public methods
512 //
513
514 //_____________________________________________________________________________
515 AliMpSector* AliMpSectorReader::BuildSector()
516 {
517 /// Read the mapping data from stream and create the basic objects:         \n
518 /// zones, subzones, rows, row segments, motifs.
519
520   // Open input stream
521   //
522   istream& in 
523     = fkDataStreams.
524         CreateDataStream(AliMpFiles::SectorFilePath(fStationType,fPlaneType));
525
526   ReadSectorData(in);
527   delete &in;
528   
529   fSector->SetRowSegmentOffsets();
530
531   // Open input stream for special inner zone
532   
533   // add is data function
534   
535   TString sectorSpecialFileName 
536     = AliMpFiles::SectorSpecialFilePath(fStationType, fPlaneType);
537   if ( fkDataStreams.IsDataStream(sectorSpecialFileName) ) {
538     istream& in2 
539       = fkDataStreams.
540           CreateDataStream(sectorSpecialFileName);
541   
542     ReadSectorSpecialData(in2, AliMp::kLeft);
543     
544     delete &in2;
545   }  
546
547   // Open input file for special outer zone
548   TString sectorSpecialFileName2 
549     = AliMpFiles::SectorSpecialFilePath2(fStationType, fPlaneType);
550   if ( fkDataStreams.IsDataStream(sectorSpecialFileName2) ) {
551     istream& in3
552       = fkDataStreams.
553           CreateDataStream(sectorSpecialFileName2);
554     
555     ReadSectorSpecialData(in3, AliMp::kRight);
556     
557     delete &in3;
558   }   
559
560   fSector->Initialize();
561   
562   return fSector;
563 }  
564