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