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