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