]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifReader.cxx
Correction for cluster error (Ruben)
[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"
228fd720 29#include "AliMpDataStreams.h"
197883c2 30#include "AliMpMotifReader.h"
31#include "AliMpMotifMap.h"
32#include "AliMpMotif.h"
33#include "AliMpMotifSpecial.h"
34#include "AliMpMotifType.h"
35#include "AliMpConnection.h"
168e9c4d 36#include "AliMpEncodePair.h"
197883c2 37
2c605e66 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
13985652 49/// \cond CLASSIMP
197883c2 50ClassImp(AliMpMotifReader)
13985652 51/// \endcond
197883c2 52
197883c2 53//_____________________________________________________________________________
ab167304 54AliMpMotifReader::AliMpMotifReader(const AliMpDataStreams& dataStreams,
55 AliMp::StationType station,
4e51cfd2 56 AliMq::Station12Type station12,
cddd101e 57 AliMp::PlaneType plane)
197883c2 58 : TObject(),
7d5d0cc5 59 fkDataStreams(dataStreams),
197883c2 60 fStationType(station),
4e51cfd2 61 fStation12Type(station12),
2c605e66 62 fPlaneType(plane)
197883c2 63{
64/// Standard constructor
65}
66
197883c2 67//_____________________________________________________________________________
68AliMpMotifReader::~AliMpMotifReader()
69{
70/// Destructor
71}
72
197883c2 73//
74// public methods
75//
76
77//_____________________________________________________________________________
78AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
79{
228fd720 80/// Read the streams describing a motif in the "$MINSTALL/data" directory
197883c2 81/// and fill the AliMpMotifType structure with.
228fd720 82/// The streams mentioned are named padPos<maskName>.dat
197883c2 83/// and connect<maskName>.dat
84
228fd720 85 // Open streams
86 //
87 istream& padPosStream
7d5d0cc5 88 = fkDataStreams.
ab167304 89 CreateDataStream(AliMpFiles::PadPosFilePath(
4e51cfd2 90 fStationType, fStation12Type, fPlaneType, motifTypeId));
228fd720 91 istream& bergToGCStream
7d5d0cc5 92 = fkDataStreams.
4e51cfd2 93 CreateDataStream(AliMpFiles::BergToGCFilePath(fStationType, fStation12Type));
228fd720 94
95 istream& motifTypeStream
7d5d0cc5 96 = fkDataStreams.
ab167304 97 CreateDataStream(AliMpFiles::MotifFilePath(
4e51cfd2 98 fStationType, fStation12Type, fPlaneType, motifTypeId));
197883c2 99
228fd720 100 AliMpMotifType* motifType = new AliMpMotifType(motifTypeId);
197883c2 101
2294822d 102 TExMap positions;
197883c2 103
104 char line[256];
105 do {
228fd720 106 padPosStream.getline(line,255);
107 if (!padPosStream) break;
197883c2 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;
5006ec94 122 positions.Add( AliMpExMap::GetIndex(key),
168e9c4d 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
228fd720 127 } while (!padPosStream.eof());
197883c2 128
f29ba3e1 129 const Int_t knbergpins =
4e51cfd2 130 (fStationType == AliMp::kStation12 ) ? 80 : 100;
197883c2 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];
76e1274b 134 for (Int_t i=0; i<100; ++i) gassiChannel[i] = 0;
197883c2 135 while(1) {
136 Int_t bergNum;
137 TString gcStr;
228fd720 138 bergToGCStream>>bergNum>>gcStr;
139 if (!bergToGCStream.good()) break;
197883c2 140 if (gcStr=="GND") continue;
f29ba3e1 141 if (bergNum>knbergpins) {
197883c2 142 Fatal("BuildMotifType","Berg number > 80 ...");
143 continue;
144 }
145 gassiChannel[bergNum-1]= atoi(gcStr);
146 }
197883c2 147
197883c2 148 Int_t nofPadsX=0;
149 Int_t nofPadsY=0;
150
151 do {
152
153 Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
154
155 TString lineStr,token;
228fd720 156 lineStr.ReadLine(motifTypeStream);
157 if (!motifTypeStream.good()) break;
197883c2 158#if defined (__HP_aCC) || (__alpha)
159 strstream tokenList;
160 tokenList << lineStr.Data();
161#else
162 istringstream tokenList(lineStr.Data());
163#endif
164
165 token.ReadToken(tokenList);
166 if (!tokenList.good()) continue; // column is missing...
167 if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
168
169 numBerg = atoi(token.Data());
170 if (numBerg==0) {
171 AliWarning(Form("Berg number %s invalid",token.Data()));
172 continue;
173 }
174
175 token.ReadToken(tokenList);
176 if (!tokenList.good()) continue; // column is missing...
177 numKapton = atoi(token.Data());
178 if (numKapton==0) continue;
179
180
181 token.ReadToken(tokenList);
182 if (!tokenList.good()) continue; // column is missing...
183 if (token=="GND") continue;
184 string padName = token.Data();
185 padNum = motifType->PadNum(token);
186
187 token.ReadToken(tokenList);
188 if (token.IsNull() ) continue; // column is missing...
189// if (token[0]!='E') {
190// cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
191// continue;
192// } else {
193// gassiNum = atoi(token.Data() +1 )-1;
194// }
f29ba3e1 195 if ( (numBerg<1) || (numBerg>knbergpins) ) {
196 AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
197883c2 197 continue;
198 }
199
200 gassiNum = gassiChannel[numBerg-1];
201
5006ec94 202 Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
197883c2 203 if (!value) {
2c605e66 204 AliWarningStream()
205 << "Problem: Pad number " << padNum
228fd720 206 << " for motif type " << motifTypeId.Data()
207 << " found in the motifType stream, but not in the padPos stream" << endl;
197883c2 208 continue;
209 }
210
630711ed 211 AliMpConnection* connection
168e9c4d 212 = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, --value);
630711ed 213
3635f34f 214 Bool_t ok = motifType->AddConnection(connection);
215
216 if (!ok)
217 {
218 AliFatal("Could not add connection");
219 }
630711ed 220
168e9c4d 221 ix = AliMp::PairFirst(value);
222 iy = AliMp::PairSecond(value);
223
197883c2 224 if (ix>=nofPadsX) nofPadsX=ix+1;
225 if (iy>=nofPadsY) nofPadsY=iy+1;
226
228fd720 227 } while (!motifTypeStream.eof());
197883c2 228
229
230 motifType->SetNofPads(nofPadsX, nofPadsY);
228fd720 231
232 delete &padPosStream;
233 delete &bergToGCStream;
234 delete &motifTypeStream;
197883c2 235
236 return motifType;
237}
238
197883c2 239//_____________________________________________________________________________
240AliMpMotifSpecial*
241AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
d1c53ece 242 AliMpMotifType* motifType,
243 Double_t scale)
197883c2 244{
245/// Build a special motif by reading the file motifSpecial<motifId>.dat
246/// in the data directory
247
228fd720 248 // Open streams
249 //
250 istream& in
7d5d0cc5 251 = fkDataStreams.
ab167304 252 CreateDataStream(AliMpFiles::MotifSpecialFilePath(
4e51cfd2 253 fStationType, fStation12Type, fPlaneType, motifID));
197883c2 254
0e8df63e 255 TString id = MotifSpecialName(motifID,scale);
256
257 AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
197883c2 258 Int_t i,j;
259 Double_t x,y;
260 in >> i;
261 while (!in.eof()){
262 in >>j >>x >> y;
6e97fbb8 263 res->SetPadDimensions(i,j,x*scale/2.,y*scale/2.);
197883c2 264 in >> i;
265 }
d7885370 266 res->CalculateDimensions();
197883c2 267
228fd720 268 delete &in;
269
197883c2 270 return res;
271}
272
228fd720 273//_____________________________________________________________________________
274TString
275AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
276{
277 /// Build the name taking into the scale, if not 1.0
278 TString id;
279
280 if ( scale != 1.0 )
281 {
282 id = Form("%s-%e",motifID.Data(),scale);
283 }
284 else
285 {
286 id = motifID;
287 }
288 return id;
289}
290