]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSt345Reader.cxx
New definition and implementation of bus patch class,
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSt345Reader.cxx
CommitLineData
dee1d5f1 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 purpeateose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// $Id$
13985652 17// $MpId: AliMpSt345Reader.cxx,v 1.11 2006/05/24 13:58:50 ivana Exp $
dee1d5f1 18
19#include "AliMpSt345Reader.h"
20
21#include "AliLog.h"
d5c9a22c 22#include "AliMpSlatMotifMap.h"
dee1d5f1 23#include "AliMpMotifReader.h"
24#include "AliMpFiles.h"
25#include "AliMpMotifType.h"
26#include "AliMpPCB.h"
27#include "AliMpSlat.h"
dee1d5f1 28#include "AliMpMotifPosition.h"
29#include "AliMpMotif.h"
30#include "AliMpHelper.h"
f0eac1a3 31#include "AliMpConstants.h"
dee1d5f1 32
33#include "Riostream.h"
dee1d5f1 34#include "TClass.h"
35#include "TObjString.h"
36#include "TString.h"
37
38#include <sstream>
28b486f1 39#include <assert.h>
dee1d5f1 40
85fec35d 41///
42/// \class AliMpSt345Reader
43//
44/// Read slat and pcb ASCII files.
45///
d5c9a22c 46/// Basically this class provides two methods :
85fec35d 47/// - AliMpSlat* ReadSlat()
48/// - AliMpPCB ReadPCB()
49///
50/// \author Laurent Aphecetche
dee1d5f1 51
13985652 52/// \cond CLASSIMP
f0eac1a3 53ClassImp(AliMpSt345Reader)
13985652 54/// \endcond
f0eac1a3 55
dee1d5f1 56//_____________________________________________________________________________
d5c9a22c 57AliMpSt345Reader::AliMpSt345Reader(AliMpSlatMotifMap& motifMap)
58:
59TObject(),
60fMotifMap(motifMap)
dee1d5f1 61{
62 //
63 // Default ctor.
64 //
65}
66
67//_____________________________________________________________________________
68AliMpSt345Reader::~AliMpSt345Reader()
69{
70 //
71 // Dtor.
72 //
dee1d5f1 73}
74
75//_____________________________________________________________________________
76AliMpPCB*
77AliMpSt345Reader::ReadPCB(const char* pcbType)
78{
d5c9a22c 79 ///
80 /// Create a new AliMpPCB object, by reading it from file.
81 /// The returned object must be deleted by the client
dee1d5f1 82
aad465b5 83 std::ifstream in(AliMpFiles::SlatPCBFilePath(kStation345,pcbType).Data());
dee1d5f1 84 if (!in.good())
85 {
86 AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
87 return 0;
88 }
89
90 AliMpMotifReader reader(kStation345,kNonBendingPlane);
91 // note that the nonbending
92 // parameter is of no use for station345, as far as reading motif is
93 // concerned, as all motifs are supposed to be in the same directory
94 // (as they are shared by bending/non-bending planes).
95
96 char line[80];
97
84aac932 98 const TString kSizeKeyword("SIZES");
99 const TString kMotifKeyword("MOTIF");
dee1d5f1 100
101 AliMpPCB* pcb = 0;
102
103 while ( in.getline(line,80) )
104 {
105 if ( line[0] == '#' ) continue;
106
107 TString sline(line);
108
84aac932 109 if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
dee1d5f1 110 {
84aac932 111 std::istringstream sin(sline(kSizeKeyword.Length(),
112 sline.Length()-kSizeKeyword.Length()).Data());
d5c9a22c 113 double padSizeX = 0.0;
114 double padSizeY = 0.0;
115 double pcbSizeX = 0.0;
116 double pcbSizeY = 0.0;
dee1d5f1 117 sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
118 assert(pcb==0);
d5c9a22c 119 pcb = new AliMpPCB(&fMotifMap,pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
dee1d5f1 120 }
121
84aac932 122 if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
dee1d5f1 123 {
84aac932 124 std::istringstream sin(sline(kMotifKeyword.Length(),
125 sline.Length()-kMotifKeyword.Length()).Data());
dee1d5f1 126 TString sMotifType;
127 int ix;
128 int iy;
129 sin >> sMotifType >> ix >> iy;
130
d5c9a22c 131 AliMpMotifType* motifType = fMotifMap.FindMotifType(sMotifType);
132 if (!motifType)
133 {
134 AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
135 motifType = reader.BuildMotifType(sMotifType.Data());
136 fMotifMap.AddMotifType(motifType);
137 }
138 else
139 {
140 AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));
141 }
dee1d5f1 142
143 assert(pcb!=0);
144 pcb->Add(motifType,ix,iy);
145 }
146 }
147
148 in.close();
149
dee1d5f1 150 return pcb;
151}
152
153//_____________________________________________________________________________
154AliMpSlat*
155AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
156{
d5c9a22c 157 ///
158 /// Create a new AliMpSlat object, by reading it from file.
159 /// The returned object must be deleted by the client.
dee1d5f1 160
aad465b5 161 std::ifstream in(AliMpFiles::SlatFilePath(kStation345,slatType,
162 planeType).Data());
dee1d5f1 163 if (!in.good())
164 {
165 AliErrorClass(Form("Cannot read slat from %s",
aad465b5 166 AliMpFiles::SlatFilePath(kStation345,slatType,planeType).Data()));
dee1d5f1 167 return 0;
168 }
169
170 char line[80];
171
84aac932 172 const TString kpcbKeyword("PCB");
dee1d5f1 173
aad465b5 174 AliMpSlat* slat = new AliMpSlat(slatType, planeType);
dee1d5f1 175
176 while ( in.getline(line,80) )
177 {
178 if ( line[0] == '#' ) continue;
179
180 TString sline(AliMpHelper::Normalize(line));
181
84aac932 182 if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
dee1d5f1 183 {
84aac932 184 TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
dee1d5f1 185 Ssiz_t blankPos = tmp.First(' ');
186 if ( blankPos < 0 )
187 {
188 AliErrorClass("Syntax error in PCB file, should get a list of "
189 "manu ids after the pcbname");
190 delete slat;
191 return 0;
192 }
193
194 TString pcbName(tmp(0,blankPos));
195 TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
196
d5c9a22c 197 AliMpPCB* pcbType = ReadPCB(pcbName.Data());
dee1d5f1 198 if (!pcbType)
199 {
200 AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
201 delete slat;
202 return 0;
203 }
204
205 TArrayI manuList;
206 AliMpHelper::DecodeName(manus,';',manuList);
c6e05ab2 207 if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
dee1d5f1 208 {
209 AliErrorClass(Form("Wrong number of manu ids for this PCB ("
210 "%s) : %d out of %d",pcbName.Data(),
211 manuList.GetSize(),pcbType->GetSize()));
d5c9a22c 212 delete pcbType;
dee1d5f1 213 delete slat;
214 return 0;
215 }
f0eac1a3 216
217 for ( Int_t i = 0; i < manuList.GetSize(); ++i )
218 {
219 manuList[i] |= AliMpConstants::ManuMask(planeType);
220 }
d5c9a22c 221 slat->Add(*pcbType,manuList);
222 delete pcbType;
dee1d5f1 223 }
224 }
225
226 in.close();
227
228 return slat;
229}
230