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