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