]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifReader.cxx
Replacement of AliMpIntPair object with algoritmic
[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];
134 while(1) {
135 Int_t bergNum;
136 TString gcStr;
228fd720 137 bergToGCStream>>bergNum>>gcStr;
138 if (!bergToGCStream.good()) break;
197883c2 139 if (gcStr=="GND") continue;
f29ba3e1 140 if (bergNum>knbergpins) {
197883c2 141 Fatal("BuildMotifType","Berg number > 80 ...");
142 continue;
143 }
144 gassiChannel[bergNum-1]= atoi(gcStr);
145 }
197883c2 146
197883c2 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;
228fd720 155 lineStr.ReadLine(motifTypeStream);
156 if (!motifTypeStream.good()) break;
197883c2 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// }
f29ba3e1 194 if ( (numBerg<1) || (numBerg>knbergpins) ) {
195 AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
197883c2 196 continue;
197 }
198
199 gassiNum = gassiChannel[numBerg-1];
200
5006ec94 201 Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
197883c2 202 if (!value) {
2c605e66 203 AliWarningStream()
204 << "Problem: Pad number " << padNum
228fd720 205 << " for motif type " << motifTypeId.Data()
206 << " found in the motifType stream, but not in the padPos stream" << endl;
197883c2 207 continue;
208 }
209
630711ed 210 AliMpConnection* connection
168e9c4d 211 = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, --value);
630711ed 212
3635f34f 213 Bool_t ok = motifType->AddConnection(connection);
214
215 if (!ok)
216 {
217 AliFatal("Could not add connection");
218 }
630711ed 219
168e9c4d 220 ix = AliMp::PairFirst(value);
221 iy = AliMp::PairSecond(value);
222
197883c2 223 if (ix>=nofPadsX) nofPadsX=ix+1;
224 if (iy>=nofPadsY) nofPadsY=iy+1;
225
228fd720 226 } while (!motifTypeStream.eof());
197883c2 227
228
229 motifType->SetNofPads(nofPadsX, nofPadsY);
228fd720 230
231 delete &padPosStream;
232 delete &bergToGCStream;
233 delete &motifTypeStream;
197883c2 234
235 return motifType;
236}
237
197883c2 238//_____________________________________________________________________________
239AliMpMotifSpecial*
240AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
d1c53ece 241 AliMpMotifType* motifType,
242 Double_t scale)
197883c2 243{
244/// Build a special motif by reading the file motifSpecial<motifId>.dat
245/// in the data directory
246
228fd720 247 // Open streams
248 //
249 istream& in
7d5d0cc5 250 = fkDataStreams.
ab167304 251 CreateDataStream(AliMpFiles::MotifSpecialFilePath(
4e51cfd2 252 fStationType, fStation12Type, fPlaneType, motifID));
197883c2 253
0e8df63e 254 TString id = MotifSpecialName(motifID,scale);
255
256 AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
197883c2 257 Int_t i,j;
258 Double_t x,y;
259 in >> i;
260 while (!in.eof()){
261 in >>j >>x >> y;
168e9c4d 262 res->SetPadDimensions(i,j,TVector2(x*scale/2.,y*scale/2.));
197883c2 263 in >> i;
264 }
d7885370 265 res->CalculateDimensions();
197883c2 266
228fd720 267 delete &in;
268
197883c2 269 return res;
270}
271
228fd720 272//_____________________________________________________________________________
273TString
274AliMpMotifReader::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