]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifReader.cxx
Fix in AliMpSectorSegmentation::PadByPosition;
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifReader.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: AliMpMotifReader.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $
18 // Category: sector
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifReader
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 "AliMpFiles.h"
29 #include "AliMpDataStreams.h"
30 #include "AliMpMotifReader.h"
31 #include "AliMpMotifMap.h"
32 #include "AliMpMotif.h"
33 #include "AliMpMotifSpecial.h"
34 #include "AliMpMotifType.h"
35 #include "AliMpConnection.h"
36 #include "AliMpIntPair.h"
37
38 #include "AliLog.h"
39
40 #include <TSystem.h>
41 #include <TMath.h>
42 #include <Riostream.h>
43 #include <Rstrstream.h>
44
45 #if !defined(__HP_aCC) && !defined(__alpha)
46   #include <sstream>
47 #endif
48
49 /// \cond CLASSIMP
50 ClassImp(AliMpMotifReader)
51 /// \endcond
52
53 //_____________________________________________________________________________
54 AliMpMotifReader::AliMpMotifReader(const AliMpDataStreams& dataStreams,
55                                    AliMp::StationType station, 
56                                    AliMq::Station12Type station12,
57                                    AliMp::PlaneType plane) 
58   : TObject(),
59     fkDataStreams(dataStreams),
60     fStationType(station),
61     fStation12Type(station12),
62     fPlaneType(plane)
63 {
64 /// Standard constructor
65 }
66
67 //_____________________________________________________________________________
68 AliMpMotifReader::~AliMpMotifReader() 
69 {
70 /// Destructor  
71 }
72
73 //
74 // public methods
75 //
76
77 //_____________________________________________________________________________
78 AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
79 {
80 /// Read the streams describing a motif in the "$MINSTALL/data" directory
81 /// and fill the AliMpMotifType structure with.
82 /// The streams mentioned are named padPos<maskName>.dat
83 /// and connect<maskName>.dat
84
85   // Open streams
86   //
87   istream& padPosStream 
88     = fkDataStreams.
89         CreateDataStream(AliMpFiles::PadPosFilePath(
90                             fStationType, fStation12Type, fPlaneType, motifTypeId));
91   istream& bergToGCStream 
92     = fkDataStreams.
93         CreateDataStream(AliMpFiles::BergToGCFilePath(fStationType, fStation12Type));
94       
95   istream& motifTypeStream 
96     = fkDataStreams.
97         CreateDataStream(AliMpFiles::MotifFilePath(
98                             fStationType, fStation12Type, fPlaneType, motifTypeId));
99
100   AliMpMotifType*  motifType = new AliMpMotifType(motifTypeId); 
101
102   TExMap positions;
103
104   char line[256];
105   do {
106     padPosStream.getline(line,255);
107     if (!padPosStream) break;
108
109 #if defined (__HP_aCC) || (__alpha)
110     strstream strline;
111     strline << line;
112 #else
113     istringstream strline(line);
114 #endif    
115     string key;
116
117     strline>>key;
118     if ((key=="#") || (key=="") ) continue;
119
120     int i,j;
121     strline>>i>>j;
122     positions.Add( AliMpExMap::GetIndex(key), 
123                    AliMpExMap::GetIndex(AliMpIntPair(i,j)) ); 
124   } while (!padPosStream.eof());
125
126   const Int_t knbergpins = 
127     (fStationType == AliMp::kStation12 ) ? 80 : 100;
128   // Station1 & 2 Bergstak connectors have 80 pins, while for stations
129   // 3, 4 and 5 they have 100 pins.
130   Int_t gassiChannel[100];
131   while(1) {
132     Int_t bergNum;
133     TString gcStr;
134     bergToGCStream>>bergNum>>gcStr;
135     if (!bergToGCStream.good()) break;
136     if (gcStr=="GND") continue;
137     if (bergNum>knbergpins) {
138         Fatal("BuildMotifType","Berg number > 80 ...");
139         continue;
140     }
141     gassiChannel[bergNum-1]= atoi(gcStr);
142   }
143   
144   Int_t nofPadsX=0;
145   Int_t nofPadsY=0;
146
147   do {
148   
149     Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
150
151     TString lineStr,token;
152     lineStr.ReadLine(motifTypeStream);
153     if (!motifTypeStream.good()) break;
154 #if defined (__HP_aCC) || (__alpha)
155     strstream tokenList;
156     tokenList << lineStr.Data();
157 #else
158     istringstream tokenList(lineStr.Data());
159 #endif    
160     
161     token.ReadToken(tokenList);
162     if (!tokenList.good()) continue; // column is missing...
163     if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
164     
165     numBerg = atoi(token.Data());
166     if (numBerg==0) {
167       AliWarning(Form("Berg number %s invalid",token.Data()));
168       continue;
169     }
170     
171     token.ReadToken(tokenList);
172     if (!tokenList.good()) continue; // column is missing...
173     numKapton = atoi(token.Data());
174     if (numKapton==0) continue;
175
176     
177     token.ReadToken(tokenList);
178     if (!tokenList.good()) continue; // column is missing...
179     if (token=="GND") continue;
180     string padName = token.Data();
181     padNum = motifType->PadNum(token);
182     
183      token.ReadToken(tokenList);
184      if (token.IsNull() ) continue; // column is missing...
185 //     if (token[0]!='E') {
186 //       cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
187 //       continue;
188 //     }  else {
189 //        gassiNum = atoi(token.Data() +1 )-1;
190 //     }
191     if ( (numBerg<1) || (numBerg>knbergpins) ) {
192       AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
193       continue;
194     }
195     
196     gassiNum  = gassiChannel[numBerg-1];
197
198     Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
199     if (!value) {
200       AliWarningStream()
201         << "Problem: Pad number " << padNum
202         << " for motif type " << motifTypeId.Data() 
203         << " found in the motifType stream, but not in the padPos stream" << endl;
204       continue;
205     }
206
207     ix = AliMpExMap::GetPair(value).GetFirst();
208     iy = AliMpExMap::GetPair(value).GetSecond();
209
210     AliMpConnection* connection 
211       = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, AliMpIntPair(ix,iy));
212     
213     Bool_t ok = motifType->AddConnection(connection);
214     
215     if (!ok)
216     {
217       AliFatal("Could not add connection");
218     }
219                   
220     if (ix>=nofPadsX) nofPadsX=ix+1;
221     if (iy>=nofPadsY) nofPadsY=iy+1;
222
223   } while (!motifTypeStream.eof());    
224
225
226   motifType->SetNofPads(nofPadsX, nofPadsY);
227   
228   delete &padPosStream;
229   delete &bergToGCStream;
230   delete &motifTypeStream;
231
232   return motifType;
233 }
234
235 //_____________________________________________________________________________
236 AliMpMotifSpecial*  
237 AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
238                                     AliMpMotifType* motifType,
239                                     Double_t scale)
240 {
241 /// Build a special motif by reading the file motifSpecial<motifId>.dat
242 /// in the data directory
243
244   // Open streams
245   //
246   istream& in 
247     = fkDataStreams.
248         CreateDataStream(AliMpFiles::MotifSpecialFilePath(
249                              fStationType, fStation12Type, fPlaneType, motifID));
250
251   TString id = MotifSpecialName(motifID,scale);
252   
253   AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
254   Int_t i,j;
255   Double_t x,y;
256   in >> i;
257   while (!in.eof()){
258     in >>j >>x >> y;
259     res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x*scale/2.,y*scale/2.));
260     in >> i;
261   }
262   res->CalculateDimensions();
263   
264   delete &in;
265   
266   return res;
267 }
268
269 //_____________________________________________________________________________
270 TString 
271 AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
272 {
273   /// Build the name taking into the scale, if not 1.0
274   TString id;
275   
276   if ( scale != 1.0 )
277   {
278     id = Form("%s-%e",motifID.Data(),scale);
279   }
280   else
281   {
282     id = motifID;
283   }
284   return id;
285 }
286