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