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