]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifReader.cxx
AliMUONDigitCalibrator
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifReader.cxx
CommitLineData
197883c2 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$
13985652 17// $MpId: AliMpMotifReader.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $
197883c2 18// Category: sector
3d1463c8 19
20//-----------------------------------------------------------------------------
197883c2 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
3d1463c8 26//-----------------------------------------------------------------------------
197883c2 27
197883c2 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"
197883c2 36
2c605e66 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
13985652 48/// \cond CLASSIMP
197883c2 49ClassImp(AliMpMotifReader)
13985652 50/// \endcond
197883c2 51
197883c2 52//_____________________________________________________________________________
cddd101e 53AliMpMotifReader::AliMpMotifReader(AliMp::StationType station,
54 AliMp::PlaneType plane)
197883c2 55 : TObject(),
56 fStationType(station),
2c605e66 57 fPlaneType(plane)
197883c2 58{
59/// Standard constructor
60}
61
62//_____________________________________________________________________________
63AliMpMotifReader::AliMpMotifReader()
64 : TObject(),
cddd101e 65 fStationType(AliMp::kStation1),
66 fPlaneType(AliMp::kBendingPlane)
197883c2 67{
68/// Default constructor
69}
70
197883c2 71//_____________________________________________________________________________
72AliMpMotifReader::~AliMpMotifReader()
73{
74/// Destructor
75}
76
197883c2 77//
78// public methods
79//
80
81//_____________________________________________________________________________
82AliMpMotifType* 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
d1c53ece 91 TString padPosFileName(AliMpFiles::PadPosFilePath(fStationType,
92 fPlaneType, motifTypeId));
197883c2 93 ifstream padPos(padPosFileName);
da3a1bb2 94 AliDebugStream(2) << "Opening file " << padPosFileName << endl;
197883c2 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
5006ec94 121 positions.Add( AliMpExMap::GetIndex(key),
122 AliMpExMap::GetIndex(AliMpIntPair(i,j)) );
197883c2 123#endif
124 } while (!padPos.eof());
125
126 padPos.close();
127
128 TString bergToGCFileName
d1c53ece 129 = AliMpFiles::BergToGCFilePath(fStationType);
da3a1bb2 130 AliDebugStream(2) << "Opening file " << bergToGCFileName << endl;
197883c2 131
132 ifstream bergToGCFile(bergToGCFileName);
f29ba3e1 133 const Int_t knbergpins =
cddd101e 134 (fStationType == AliMp::kStation1 || fStationType == AliMp::kStation2 ) ? 80 : 100;
197883c2 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;
f29ba3e1 144 if (bergNum>knbergpins) {
197883c2 145 Fatal("BuildMotifType","Berg number > 80 ...");
146 continue;
147 }
148 gassiChannel[bergNum-1]= atoi(gcStr);
149 }
150 bergToGCFile.close();
151
d1c53ece 152 TString motifTypeFileName(AliMpFiles::MotifFilePath(fStationType,
153 fPlaneType, motifTypeId));
197883c2 154 ifstream motif(motifTypeFileName);
da3a1bb2 155 AliDebugStream(2) << "Opening file " << motifTypeFileName << endl;
197883c2 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// }
f29ba3e1 204 if ( (numBerg<1) || (numBerg>knbergpins) ) {
205 AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
197883c2 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()) {
2c605e66 214 AliWarningStream()
215 << "Problem: Pad number " << padNum
216 << " found in the file " << motifTypeFileName
217 << " but not in the file " << padPosFileName << endl;
197883c2 218 continue;
219 }
220
221 ix= iter->second.first;
222 iy= iter->second.second;
223#endif
224
225#ifdef WITH_ROOT
5006ec94 226 Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
197883c2 227 if (!value) {
2c605e66 228 AliWarningStream()
229 << "Problem: Pad number " << padNum
230 << " found in the file " << motifTypeFileName
231 << " but not in the file " << padPosFileName << endl;
197883c2 232 continue;
233 }
234
5006ec94 235 ix = AliMpExMap::GetPair(value).GetFirst();
236 iy = AliMpExMap::GetPair(value).GetSecond();
630711ed 237
197883c2 238#endif
239
630711ed 240 AliMpConnection* connection
241 = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, AliMpIntPair(ix,iy));
242
243 motifType->AddConnection(AliMpIntPair(ix,iy),connection);
244
197883c2 245 if (ix>=nofPadsX) nofPadsX=ix+1;
246 if (iy>=nofPadsY) nofPadsY=iy+1;
247
248 } while (!motif.eof());
249
250
251 motifType->SetNofPads(nofPadsX, nofPadsY);
252
253 motif.close();
254
255 return motifType;
256}
257
0e8df63e 258//_____________________________________________________________________________
259TString
260AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
261{
262 /// Build the name taking into the scale, if not 1.0
263 TString id;
264
265 if ( scale != 1.0 )
266 {
267 id = Form("%s-%e",motifID.Data(),scale);
268 }
269 else
270 {
271 id = motifID;
272 }
273 return id;
274}
197883c2 275
276//_____________________________________________________________________________
277AliMpMotifSpecial*
278AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
d1c53ece 279 AliMpMotifType* motifType,
280 Double_t scale)
197883c2 281{
282/// Build a special motif by reading the file motifSpecial<motifId>.dat
283/// in the data directory
284
285 // Open the input file
d1c53ece 286 TString motifSpecialFileName(AliMpFiles::MotifSpecialFilePath(fStationType,
287 fPlaneType, motifID));
197883c2 288 ifstream in(motifSpecialFileName);
289 if (!in) {
2c605e66 290 AliErrorStream()
291 << "File " << motifSpecialFileName.Data() << " not found." << endl;
197883c2 292 return 0;
293 }
294
0e8df63e 295 TString id = MotifSpecialName(motifID,scale);
296
297 AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
197883c2 298 Int_t i,j;
299 Double_t x,y;
300 in >> i;
301 while (!in.eof()){
302 in >>j >>x >> y;
d1c53ece 303 res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x*scale/2.,y*scale/2.));
197883c2 304 in >> i;
305 }
d7885370 306 res->CalculateDimensions();
197883c2 307
308 in.close();
309 return res;
310}
311