]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifReader.cxx
Adding new libraries
[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 // Class AliMpMotifReader
21 // -------------------
22 // Class that takes care of reading the sector data.
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
26 #include "AliMpFiles.h"
27 #include "AliMpMotifReader.h"
28 #include "AliMpMotifMap.h"
29 #include "AliMpMotif.h"
30 #include "AliMpMotifSpecial.h"
31 #include "AliMpMotifType.h"
32 #include "AliMpConnection.h"
33 #include "AliMpIntPair.h"
34
35 #include "AliLog.h"
36
37 #include <TSystem.h>
38 #include <TMath.h>
39 #include <Riostream.h>
40 #include <Rstrstream.h>
41
42 #if !defined(__HP_aCC) && !defined(__alpha)
43   #include <sstream>
44 #endif
45
46 /// \cond CLASSIMP
47 ClassImp(AliMpMotifReader)
48 /// \endcond
49
50 //_____________________________________________________________________________
51 AliMpMotifReader::AliMpMotifReader(AliMp::StationType station, 
52                                    AliMp::PlaneType plane) 
53   : TObject(),
54     fStationType(station),
55     fPlaneType(plane)
56 {
57 /// Standard constructor
58 }
59
60 //_____________________________________________________________________________
61 AliMpMotifReader::AliMpMotifReader() 
62   : TObject(),
63     fStationType(AliMp::kStation1),
64     fPlaneType(AliMp::kBendingPlane)
65 {
66 /// Default constructor
67 }
68
69 //_____________________________________________________________________________
70 AliMpMotifReader::~AliMpMotifReader() 
71 {
72 /// Destructor  
73 }
74
75 //
76 // public methods
77 //
78
79 //_____________________________________________________________________________
80 AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
81 {
82 /// Read the files describing a motif in the "$MINSTALL/data" directory
83 /// and fill the AliMpMotifType structure with.
84 /// The files mentioned are are named padPos<maskName>.dat
85 /// and connect<maskName>.dat
86
87   AliMpMotifType*  motifType = new AliMpMotifType(motifTypeId); 
88
89   TString padPosFileName(AliMpFiles::PadPosFilePath(fStationType, 
90                                                     fPlaneType, motifTypeId));
91   ifstream padPos(padPosFileName);
92   AliDebugStream(2) << "Opening file " << padPosFileName << endl;
93
94   PadMapType positions;
95
96   char line[256];
97   do {
98     padPos.getline(line,255);
99     if (!padPos) break;
100
101 #if defined (__HP_aCC) || (__alpha)
102     strstream strline;
103     strline << line;
104 #else
105     istringstream strline(line);
106 #endif    
107     string key;
108
109     strline>>key;
110     if ((key=="#") || (key=="") ) continue;
111
112     int i,j;
113     strline>>i>>j;
114 #ifdef WITH_STL
115     positions[key].first=i;
116     positions[key].second=j;
117 #endif
118 #ifdef WITH_ROOT
119     positions.Add( AliMpExMap::GetIndex(key), 
120                    AliMpExMap::GetIndex(AliMpIntPair(i,j)) ); 
121 #endif
122   } while (!padPos.eof());
123
124   padPos.close();
125
126   TString bergToGCFileName
127     = AliMpFiles::BergToGCFilePath(fStationType);
128   AliDebugStream(2) << "Opening file " << bergToGCFileName << endl;
129
130   ifstream bergToGCFile(bergToGCFileName);
131   const Int_t knbergpins = 
132     (fStationType == AliMp::kStation1 || fStationType == AliMp::kStation2 ) ? 80 : 100;
133   // Station1 & 2 Bergstak connectors have 80 pins, while for stations
134   // 3, 4 and 5 they have 100 pins.
135   Int_t gassiChannel[100];
136   while(1) {
137     Int_t bergNum;
138     TString gcStr;
139     bergToGCFile>>bergNum>>gcStr;
140     if (!bergToGCFile.good()) break;
141     if (gcStr=="GND") continue;
142     if (bergNum>knbergpins) {
143         Fatal("BuildMotifType","Berg number > 80 ...");
144         continue;
145     }
146     gassiChannel[bergNum-1]= atoi(gcStr);
147   }
148   bergToGCFile.close();
149   
150   TString motifTypeFileName(AliMpFiles::MotifFilePath(fStationType, 
151                                                       fPlaneType, motifTypeId));
152   ifstream motif(motifTypeFileName);
153   AliDebugStream(2) << "Opening file " << motifTypeFileName << endl;
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(motif);
164     if (!motif.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         << " found in the file " << motifTypeFileName
215         << " but not in the file " << padPosFileName << 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         << " found in the file " << motifTypeFileName
229         << " but not in the file " << padPosFileName << endl;
230       continue;
231     }
232
233     ix = AliMpExMap::GetPair(value).GetFirst();
234     iy = AliMpExMap::GetPair(value).GetSecond();
235 #endif
236
237     motifType->AddConnection(AliMpIntPair(ix,iy),
238                   new AliMpConnection(padNum,numBerg,numKapton,gassiNum));
239
240     if (ix>=nofPadsX) nofPadsX=ix+1;
241     if (iy>=nofPadsY) nofPadsY=iy+1;
242
243   } while (!motif.eof());    
244
245
246   motifType->SetNofPads(nofPadsX, nofPadsY);
247
248   motif.close();
249
250   return motifType;
251 }
252
253 //_____________________________________________________________________________
254 TString 
255 AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
256 {
257   /// Build the name taking into the scale, if not 1.0
258   TString id;
259   
260   if ( scale != 1.0 )
261   {
262     id = Form("%s-%e",motifID.Data(),scale);
263   }
264   else
265   {
266     id = motifID;
267   }
268   return id;
269 }
270
271 //_____________________________________________________________________________
272 AliMpMotifSpecial*  
273 AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
274                                     AliMpMotifType* motifType,
275                                     Double_t scale)
276 {
277 /// Build a special motif by reading the file motifSpecial<motifId>.dat
278 /// in the data directory
279
280   // Open the input file
281   TString motifSpecialFileName(AliMpFiles::MotifSpecialFilePath(fStationType, 
282                                                                 fPlaneType, motifID));
283   ifstream in(motifSpecialFileName);
284   if (!in) {    
285      AliErrorStream() 
286        << "File " << motifSpecialFileName.Data() << " not found." << endl;
287      return 0;
288   }
289
290   TString id = MotifSpecialName(motifID,scale);
291   
292   AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
293   Int_t i,j;
294   Double_t x,y;
295   in >> i;
296   while (!in.eof()){
297     in >>j >>x >> y;
298     res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x*scale/2.,y*scale/2.));
299     in >> i;
300   }
301   res->CalculateDimensions();
302   
303   in.close();
304   return res;
305 }
306