]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifReader.cxx
From Cvetan: new macro to load ITS clusters.
[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
19//
20// Class AliMpMotifReader
21// -------------------
22// Class that takes care of reading the sector data.
23// Included in AliRoot: 2003/05/02
24// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
197883c2 26#include "AliMpFiles.h"
27#include "AliMpMotifReader.h"
28#include "AliMpMotifMap.h"
29#include "AliMpMotif.h"
30#include "AliMpMotifSpecial.h"
31#include "AliMpMotifType.h"
32#include "AliMpConnection.h"
33#include "AliMpIntPair.h"
197883c2 34
2c605e66 35#include "AliLog.h"
36
37#include <TSystem.h>
38#include <TMath.h>
39#include <Riostream.h>
40#include <Rstrstream.h>
41
42#if !defined(__HP_aCC) && !defined(__alpha)
43 #include <sstream>
44#endif
45
13985652 46/// \cond CLASSIMP
197883c2 47ClassImp(AliMpMotifReader)
13985652 48/// \endcond
197883c2 49
197883c2 50//_____________________________________________________________________________
cddd101e 51AliMpMotifReader::AliMpMotifReader(AliMp::StationType station,
52 AliMp::PlaneType plane)
197883c2 53 : TObject(),
54 fStationType(station),
2c605e66 55 fPlaneType(plane)
197883c2 56{
57/// Standard constructor
58}
59
60//_____________________________________________________________________________
61AliMpMotifReader::AliMpMotifReader()
62 : TObject(),
cddd101e 63 fStationType(AliMp::kStation1),
64 fPlaneType(AliMp::kBendingPlane)
197883c2 65{
66/// Default constructor
67}
68
197883c2 69//_____________________________________________________________________________
70AliMpMotifReader::~AliMpMotifReader()
71{
72/// Destructor
73}
74
197883c2 75//
76// public methods
77//
78
79//_____________________________________________________________________________
80AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
81{
82/// Read the files describing a motif in the "$MINSTALL/data" directory
83/// and fill the AliMpMotifType structure with.
84/// The files mentioned are are named padPos<maskName>.dat
85/// and connect<maskName>.dat
86
87 AliMpMotifType* motifType = new AliMpMotifType(motifTypeId);
88
d1c53ece 89 TString padPosFileName(AliMpFiles::PadPosFilePath(fStationType,
90 fPlaneType, motifTypeId));
197883c2 91 ifstream padPos(padPosFileName);
da3a1bb2 92 AliDebugStream(2) << "Opening file " << padPosFileName << endl;
197883c2 93
94 PadMapType positions;
95
96 char line[256];
97 do {
98 padPos.getline(line,255);
99 if (!padPos) break;
100
101#if defined (__HP_aCC) || (__alpha)
102 strstream strline;
103 strline << line;
104#else
105 istringstream strline(line);
106#endif
107 string key;
108
109 strline>>key;
110 if ((key=="#") || (key=="") ) continue;
111
112 int i,j;
113 strline>>i>>j;
114#ifdef WITH_STL
115 positions[key].first=i;
116 positions[key].second=j;
117#endif
118#ifdef WITH_ROOT
5006ec94 119 positions.Add( AliMpExMap::GetIndex(key),
120 AliMpExMap::GetIndex(AliMpIntPair(i,j)) );
197883c2 121#endif
122 } while (!padPos.eof());
123
124 padPos.close();
125
126 TString bergToGCFileName
d1c53ece 127 = AliMpFiles::BergToGCFilePath(fStationType);
da3a1bb2 128 AliDebugStream(2) << "Opening file " << bergToGCFileName << endl;
197883c2 129
130 ifstream bergToGCFile(bergToGCFileName);
f29ba3e1 131 const Int_t knbergpins =
cddd101e 132 (fStationType == AliMp::kStation1 || fStationType == AliMp::kStation2 ) ? 80 : 100;
197883c2 133 // Station1 & 2 Bergstak connectors have 80 pins, while for stations
134 // 3, 4 and 5 they have 100 pins.
135 Int_t gassiChannel[100];
136 while(1) {
137 Int_t bergNum;
138 TString gcStr;
139 bergToGCFile>>bergNum>>gcStr;
140 if (!bergToGCFile.good()) break;
141 if (gcStr=="GND") continue;
f29ba3e1 142 if (bergNum>knbergpins) {
197883c2 143 Fatal("BuildMotifType","Berg number > 80 ...");
144 continue;
145 }
146 gassiChannel[bergNum-1]= atoi(gcStr);
147 }
148 bergToGCFile.close();
149
d1c53ece 150 TString motifTypeFileName(AliMpFiles::MotifFilePath(fStationType,
151 fPlaneType, motifTypeId));
197883c2 152 ifstream motif(motifTypeFileName);
da3a1bb2 153 AliDebugStream(2) << "Opening file " << motifTypeFileName << endl;
197883c2 154
155 Int_t nofPadsX=0;
156 Int_t nofPadsY=0;
157
158 do {
159
160 Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
161
162 TString lineStr,token;
163 lineStr.ReadLine(motif);
164 if (!motif.good()) break;
165#if defined (__HP_aCC) || (__alpha)
166 strstream tokenList;
167 tokenList << lineStr.Data();
168#else
169 istringstream tokenList(lineStr.Data());
170#endif
171
172 token.ReadToken(tokenList);
173 if (!tokenList.good()) continue; // column is missing...
174 if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
175
176 numBerg = atoi(token.Data());
177 if (numBerg==0) {
178 AliWarning(Form("Berg number %s invalid",token.Data()));
179 continue;
180 }
181
182 token.ReadToken(tokenList);
183 if (!tokenList.good()) continue; // column is missing...
184 numKapton = atoi(token.Data());
185 if (numKapton==0) continue;
186
187
188 token.ReadToken(tokenList);
189 if (!tokenList.good()) continue; // column is missing...
190 if (token=="GND") continue;
191 string padName = token.Data();
192 padNum = motifType->PadNum(token);
193
194 token.ReadToken(tokenList);
195 if (token.IsNull() ) continue; // column is missing...
196// if (token[0]!='E') {
197// cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
198// continue;
199// } else {
200// gassiNum = atoi(token.Data() +1 )-1;
201// }
f29ba3e1 202 if ( (numBerg<1) || (numBerg>knbergpins) ) {
203 AliWarning(Form("Berg number %d outside range (1..%d)",numBerg,knbergpins));
197883c2 204 continue;
205 }
206
207 gassiNum = gassiChannel[numBerg-1];
208
209#ifdef WITH_STL
210 PadMapTypeIterator iter = positions.find(padName);
211 if (iter==positions.end()) {
2c605e66 212 AliWarningStream()
213 << "Problem: Pad number " << padNum
214 << " found in the file " << motifTypeFileName
215 << " but not in the file " << padPosFileName << endl;
197883c2 216 continue;
217 }
218
219 ix= iter->second.first;
220 iy= iter->second.second;
221#endif
222
223#ifdef WITH_ROOT
5006ec94 224 Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName));
197883c2 225 if (!value) {
2c605e66 226 AliWarningStream()
227 << "Problem: Pad number " << padNum
228 << " found in the file " << motifTypeFileName
229 << " but not in the file " << padPosFileName << endl;
197883c2 230 continue;
231 }
232
5006ec94 233 ix = AliMpExMap::GetPair(value).GetFirst();
234 iy = AliMpExMap::GetPair(value).GetSecond();
197883c2 235#endif
236
237 motifType->AddConnection(AliMpIntPair(ix,iy),
238 new AliMpConnection(padNum,numBerg,numKapton,gassiNum));
239
240 if (ix>=nofPadsX) nofPadsX=ix+1;
241 if (iy>=nofPadsY) nofPadsY=iy+1;
242
243 } while (!motif.eof());
244
245
246 motifType->SetNofPads(nofPadsX, nofPadsY);
247
248 motif.close();
249
250 return motifType;
251}
252
0e8df63e 253//_____________________________________________________________________________
254TString
255AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale)
256{
257 /// Build the name taking into the scale, if not 1.0
258 TString id;
259
260 if ( scale != 1.0 )
261 {
262 id = Form("%s-%e",motifID.Data(),scale);
263 }
264 else
265 {
266 id = motifID;
267 }
268 return id;
269}
197883c2 270
271//_____________________________________________________________________________
272AliMpMotifSpecial*
273AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
d1c53ece 274 AliMpMotifType* motifType,
275 Double_t scale)
197883c2 276{
277/// Build a special motif by reading the file motifSpecial<motifId>.dat
278/// in the data directory
279
280 // Open the input file
d1c53ece 281 TString motifSpecialFileName(AliMpFiles::MotifSpecialFilePath(fStationType,
282 fPlaneType, motifID));
197883c2 283 ifstream in(motifSpecialFileName);
284 if (!in) {
2c605e66 285 AliErrorStream()
286 << "File " << motifSpecialFileName.Data() << " not found." << endl;
197883c2 287 return 0;
288 }
289
0e8df63e 290 TString id = MotifSpecialName(motifID,scale);
291
292 AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType);
197883c2 293 Int_t i,j;
294 Double_t x,y;
295 in >> i;
296 while (!in.eof()){
297 in >>j >>x >> y;
d1c53ece 298 res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x*scale/2.,y*scale/2.));
197883c2 299 in >> i;
300 }
d7885370 301 res->CalculateDimensions();
197883c2 302
303 in.close();
304 return res;
305}
306