1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpSt345Reader.cxx,v 1.9 2006/03/02 16:36:23 ivana Exp $
19 #include "AliMpSt345Reader.h"
22 #include "AliMpMotifReader.h"
23 #include "AliMpFiles.h"
24 #include "AliMpMotifType.h"
26 #include "AliMpSlat.h"
27 #include "AliMpMotifMap.h"
28 #include "AliMpMotifPosition.h"
29 #include "AliMpMotif.h"
30 #include "AliMpHelper.h"
31 #include "AliMpConstants.h"
33 #include "Riostream.h"
35 #include "TObjString.h"
42 /// \class AliMpSt345Reader
44 /// Read slat and pcb ASCII files.
46 /// Basically this class provides 2 static methods :
47 /// - AliMpSlat* ReadSlat()
48 /// - AliMpPCB ReadPCB()
50 /// \author Laurent Aphecetche
52 ClassImp(AliMpSt345Reader)
54 TMap AliMpSt345Reader::fgPCBMap;
56 //_____________________________________________________________________________
57 AliMpSt345Reader::AliMpSt345Reader() : TObject()
64 //_____________________________________________________________________________
65 AliMpSt345Reader::~AliMpSt345Reader()
73 //_____________________________________________________________________________
75 AliMpSt345Reader::PCB(const char* pcbType)
78 // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...)
80 // Note that the returned object is either a new one (read from file) or a
81 // reused one if it is already present in the internal map.
84 TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType);
87 AliDebugClass(1,Form("Getting pcb %s from internal map",pcbType));
88 return (AliMpPCB*)pair->Value();
92 AliDebugClass(1,Form("Reading pcb %s from file",pcbType));
93 return ReadPCB(pcbType);
97 //_____________________________________________________________________________
99 AliMpSt345Reader::ReadPCB(const char* pcbType)
102 // Create a new AliMpPCB object, by reading it from file.
105 std::ifstream in(AliMpFiles::SlatPCBFilePath(kStation345,pcbType).Data());
108 AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
112 AliMpMotifReader reader(kStation345,kNonBendingPlane);
113 // note that the nonbending
114 // parameter is of no use for station345, as far as reading motif is
115 // concerned, as all motifs are supposed to be in the same directory
116 // (as they are shared by bending/non-bending planes).
120 const TString kSizeKeyword("SIZES");
121 const TString kMotifKeyword("MOTIF");
125 while ( in.getline(line,80) )
127 if ( line[0] == '#' ) continue;
131 if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
133 std::istringstream sin(sline(kSizeKeyword.Length(),
134 sline.Length()-kSizeKeyword.Length()).Data());
135 float padSizeX = 0.0;
136 float padSizeY = 0.0;
137 float pcbSizeX = 0.0;
138 float pcbSizeY = 0.0;
139 sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
141 pcb = new AliMpPCB(pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
144 if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
146 std::istringstream sin(sline(kMotifKeyword.Length(),
147 sline.Length()-kMotifKeyword.Length()).Data());
151 sin >> sMotifType >> ix >> iy;
153 AliMpMotifType* motifType =
154 reader.BuildMotifType(sMotifType.Data());
157 pcb->Add(motifType,ix,iy);
163 fgPCBMap.Add(new TObjString(pcbType),pcb);
167 //_____________________________________________________________________________
169 AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
172 // Create a new AliMpSlat object, by reading it from file.
175 std::ifstream in(AliMpFiles::SlatFilePath(kStation345,slatType,
179 AliErrorClass(Form("Cannot read slat from %s",
180 AliMpFiles::SlatFilePath(kStation345,slatType,planeType).Data()));
186 const TString kpcbKeyword("PCB");
188 AliMpSlat* slat = new AliMpSlat(slatType, planeType);
190 while ( in.getline(line,80) )
192 if ( line[0] == '#' ) continue;
194 TString sline(AliMpHelper::Normalize(line));
196 if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
198 TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
199 Ssiz_t blankPos = tmp.First(' ');
202 AliErrorClass("Syntax error in PCB file, should get a list of "
203 "manu ids after the pcbname");
208 TString pcbName(tmp(0,blankPos));
209 TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
211 AliMpPCB* pcbType = PCB(pcbName.Data());
214 AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
220 AliMpHelper::DecodeName(manus,';',manuList);
221 if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
223 AliErrorClass(Form("Wrong number of manu ids for this PCB ("
224 "%s) : %d out of %d",pcbName.Data(),
225 manuList.GetSize(),pcbType->GetSize()));
230 for ( Int_t i = 0; i < manuList.GetSize(); ++i )
232 manuList[i] |= AliMpConstants::ManuMask(planeType);
234 slat->Add(pcbType,manuList);