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