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