]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifReader.cxx
Replacement of TVector2 object with two doubles
[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 "AliMpEncodePair.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                    AliMp::Pair(i,j) + 1 );
124               // we have to add 1 to the AliMp::Pair in order to 
125               // its value always != 0, as the TExMap returns 0 value
126               // if given key does not exists      
127   } while (!padPosStream.eof());
128
129   const Int_t knbergpins = 
130     (fStationType == AliMp::kStation12 ) ? 80 : 100;
131   // Station1 & 2 Bergstak connectors have 80 pins, while for stations
132   // 3, 4 and 5 they have 100 pins.
133   Int_t gassiChannel[100];
134   while(1) {
135     Int_t bergNum;
136     TString gcStr;
137     bergToGCStream>>bergNum>>gcStr;
138     if (!bergToGCStream.good()) break;
139     if (gcStr=="GND") continue;
140     if (bergNum>knbergpins) {
141         Fatal("BuildMotifType","Berg number > 80 ...");
142         continue;
143     }
144     gassiChannel[bergNum-1]= atoi(gcStr);
145   }
146   
147   Int_t nofPadsX=0;
148   Int_t nofPadsY=0;
149
150   do {
151   
152     Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
153
154     TString lineStr,token;
155     lineStr.ReadLine(motifTypeStream);
156     if (!motifTypeStream.good()) break;
157 #if defined (__HP_aCC) || (__alpha)
158     strstream tokenList;
159     tokenList << lineStr.Data();
160 #else
161     istringstream tokenList(lineStr.Data());
162 #endif    
163     
164     token.ReadToken(tokenList);
165     if (!tokenList.good()) continue; // column is missing...
166     if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
167     
168     numBerg = atoi(token.Data());
169     if (numBerg==0) {
170       AliWarning(Form("Berg number %s invalid",token.Data()));
171       continue;
172     }
173     
174     token.ReadToken(tokenList);
175     if (!tokenList.good()) continue; // column is missing...
176     numKapton = atoi(token.Data());
177     if (numKapton==0) continue;
178
179     
180     token.ReadToken(tokenList);
181     if (!tokenList.good()) continue; // column is missing...
182     if (token=="GND") continue;
183     string padName = token.Data();
184     padNum = motifType->PadNum(token);
185     
186      token.ReadToken(tokenList);
187      if (token.IsNull() ) continue; // column is missing...
188 //     if (token[0]!='E') {
189 //       cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
190 //       continue;
191 //     }  else {
192 //        gassiNum = atoi(token.Data() +1 )-1;
193 //     }
194     if ( (numBerg<1) || (numBerg>knbergpins) ) {
195       AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
196       continue;
197     }
198     
199     gassiNum  = gassiChannel[numBerg-1];
200
201     Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
202     if (!value) {
203       AliWarningStream()
204         << "Problem: Pad number " << padNum
205         << " for motif type " << motifTypeId.Data() 
206         << " found in the motifType stream, but not in the padPos stream" << endl;
207       continue;
208     }
209
210     AliMpConnection* connection 
211       = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, --value);
212     
213     Bool_t ok = motifType->AddConnection(connection);
214     
215     if (!ok)
216     {
217       AliFatal("Could not add connection");
218     }
219                   
220     ix = AliMp::PairFirst(value);
221     iy = AliMp::PairSecond(value);
222     
223     if (ix>=nofPadsX) nofPadsX=ix+1;
224     if (iy>=nofPadsY) nofPadsY=iy+1;
225
226   } while (!motifTypeStream.eof());    
227
228
229   motifType->SetNofPads(nofPadsX, nofPadsY);
230   
231   delete &padPosStream;
232   delete &bergToGCStream;
233   delete &motifTypeStream;
234
235   return motifType;
236 }
237
238 //_____________________________________________________________________________
239 AliMpMotifSpecial*  
240 AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
241                                     AliMpMotifType* motifType,
242                                     Double_t scale)
243 {
244 /// Build a special motif by reading the file motifSpecial<motifId>.dat
245 /// in the data directory
246
247   // Open streams
248   //
249   istream& in 
250     = fkDataStreams.
251         CreateDataStream(AliMpFiles::MotifSpecialFilePath(
252                              fStationType, fStation12Type, fPlaneType, motifID));
253
254   TString id = MotifSpecialName(motifID,scale);
255   
256   AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
257   Int_t i,j;
258   Double_t x,y;
259   in >> i;
260   while (!in.eof()){
261     in >>j >>x >> y;
262     res->SetPadDimensions(i,j,x*scale/2.,y*scale/2.);
263     in >> i;
264   }
265   res->CalculateDimensions();
266   
267   delete &in;
268   
269   return res;
270 }
271
272 //_____________________________________________________________________________
273 TString 
274 AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
275 {
276   /// Build the name taking into the scale, if not 1.0
277   TString id;
278   
279   if ( scale != 1.0 )
280   {
281     id = Form("%s-%e",motifID.Data(),scale);
282   }
283   else
284   {
285     id = motifID;
286   }
287   return id;
288 }
289