Coding conventions
[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"
36#include "AliMpIntPair.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
67//_____________________________________________________________________________
197883c2 68AliMpMotifReader::~AliMpMotifReader()
69{
70/// Destructor
71}
72
73//
197883c2 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
102 PadMapType positions;
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;
122#ifdef WITH_STL
123 positions[key].first=i;
124 positions[key].second=j;
125#endif
126#ifdef WITH_ROOT
5006ec94 127 positions.Add( AliMpExMap::GetIndex(key),
128 AliMpExMap::GetIndex(AliMpIntPair(i,j)) );
197883c2 129#endif
228fd720 130 } while (!padPosStream.eof());
197883c2 131
f29ba3e1 132 const Int_t knbergpins =
4e51cfd2 133 (fStationType == AliMp::kStation12 ) ? 80 : 100;
197883c2 134 // Station1 & 2 Bergstak connectors have 80 pins, while for stations
135 // 3, 4 and 5 they have 100 pins.
136 Int_t gassiChannel[100];
137 while(1) {
138 Int_t bergNum;
139 TString gcStr;
228fd720 140 bergToGCStream>>bergNum>>gcStr;
141 if (!bergToGCStream.good()) break;
197883c2 142 if (gcStr=="GND") continue;
f29ba3e1 143 if (bergNum>knbergpins) {
197883c2 144 Fatal("BuildMotifType","Berg number > 80 ...");
145 continue;
146 }
147 gassiChannel[bergNum-1]= atoi(gcStr);
148 }
197883c2 149
197883c2 150 Int_t nofPadsX=0;
151 Int_t nofPadsY=0;
152
153 do {
154
155 Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
156
157 TString lineStr,token;
228fd720 158 lineStr.ReadLine(motifTypeStream);
159 if (!motifTypeStream.good()) break;
197883c2 160#if defined (__HP_aCC) || (__alpha)
161 strstream tokenList;
162 tokenList << lineStr.Data();
163#else
164 istringstream tokenList(lineStr.Data());
165#endif
166
167 token.ReadToken(tokenList);
168 if (!tokenList.good()) continue; // column is missing...
169 if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
170
171 numBerg = atoi(token.Data());
172 if (numBerg==0) {
173 AliWarning(Form("Berg number %s invalid",token.Data()));
174 continue;
175 }
176
177 token.ReadToken(tokenList);
178 if (!tokenList.good()) continue; // column is missing...
179 numKapton = atoi(token.Data());
180 if (numKapton==0) continue;
181
182
183 token.ReadToken(tokenList);
184 if (!tokenList.good()) continue; // column is missing...
185 if (token=="GND") continue;
186 string padName = token.Data();
187 padNum = motifType->PadNum(token);
188
189 token.ReadToken(tokenList);
190 if (token.IsNull() ) continue; // column is missing...
191// if (token[0]!='E') {
192// cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
193// continue;
194// } else {
195// gassiNum = atoi(token.Data() +1 )-1;
196// }
f29ba3e1 197 if ( (numBerg<1) || (numBerg>knbergpins) ) {
198 AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
197883c2 199 continue;
200 }
201
202 gassiNum = gassiChannel[numBerg-1];
203
204#ifdef WITH_STL
205 PadMapTypeIterator iter = positions.find(padName);
206 if (iter==positions.end()) {
2c605e66 207 AliWarningStream()
208 << "Problem: Pad number " << padNum
228fd720 209 << " for motif type " << motifTypeId.Data()
210 << " found in the motifType stream, but not in the padPos stream" << endl;
197883c2 211 continue;
212 }
213
214 ix= iter->second.first;
215 iy= iter->second.second;
216#endif
217
218#ifdef WITH_ROOT
5006ec94 219 Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
197883c2 220 if (!value) {
2c605e66 221 AliWarningStream()
222 << "Problem: Pad number " << padNum
228fd720 223 << " for motif type " << motifTypeId.Data()
224 << " found in the motifType stream, but not in the padPos stream" << endl;
197883c2 225 continue;
226 }
227
5006ec94 228 ix = AliMpExMap::GetPair(value).GetFirst();
229 iy = AliMpExMap::GetPair(value).GetSecond();
630711ed 230
197883c2 231#endif
232
630711ed 233 AliMpConnection* connection
234 = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, AliMpIntPair(ix,iy));
235
236 motifType->AddConnection(AliMpIntPair(ix,iy),connection);
237
197883c2 238 if (ix>=nofPadsX) nofPadsX=ix+1;
239 if (iy>=nofPadsY) nofPadsY=iy+1;
240
228fd720 241 } while (!motifTypeStream.eof());
197883c2 242
243
244 motifType->SetNofPads(nofPadsX, nofPadsY);
228fd720 245
246 delete &padPosStream;
247 delete &bergToGCStream;
248 delete &motifTypeStream;
197883c2 249
250 return motifType;
251}
252
0e8df63e 253//_____________________________________________________________________________
197883c2 254AliMpMotifSpecial*
255AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
d1c53ece 256 AliMpMotifType* motifType,
257 Double_t scale)
197883c2 258{
259/// Build a special motif by reading the file motifSpecial<motifId>.dat
260/// in the data directory
261
228fd720 262 // Open streams
263 //
264 istream& in
7d5d0cc5 265 = fkDataStreams.
ab167304 266 CreateDataStream(AliMpFiles::MotifSpecialFilePath(
4e51cfd2 267 fStationType, fStation12Type, fPlaneType, motifID));
197883c2 268
0e8df63e 269 TString id = MotifSpecialName(motifID,scale);
270
271 AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
197883c2 272 Int_t i,j;
273 Double_t x,y;
274 in >> i;
275 while (!in.eof()){
276 in >>j >>x >> y;
d1c53ece 277 res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x*scale/2.,y*scale/2.));
197883c2 278 in >> i;
279 }
d7885370 280 res->CalculateDimensions();
197883c2 281
228fd720 282 delete &in;
283
197883c2 284 return res;
285}
286
228fd720 287//_____________________________________________________________________________
288TString
289AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
290{
291 /// Build the name taking into the scale, if not 1.0
292 TString id;
293
294 if ( scale != 1.0 )
295 {
296 id = Form("%s-%e",motifID.Data(),scale);
297 }
298 else
299 {
300 id = motifID;
301 }
302 return id;
303}
304