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.11 2006/05/24 13:58:50 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
53 ClassImp(AliMpSt345Reader)
56 TMap AliMpSt345Reader::fgPCBMap;
58 //_____________________________________________________________________________
59 AliMpSt345Reader::AliMpSt345Reader() : TObject()
66 //_____________________________________________________________________________
67 AliMpSt345Reader::~AliMpSt345Reader()
75 //_____________________________________________________________________________
77 AliMpSt345Reader::PCB(const char* pcbType)
80 // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...)
82 // Note that the returned object is either a new one (read from file) or a
83 // reused one if it is already present in the internal map.
86 TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType);
89 AliDebugClass(2,Form("Getting pcb %s from internal map",pcbType));
90 return (AliMpPCB*)pair->Value();
94 AliDebugClass(2,Form("Reading pcb %s from file",pcbType));
95 return ReadPCB(pcbType);
99 //_____________________________________________________________________________
101 AliMpSt345Reader::ReadPCB(const char* pcbType)
104 // Create a new AliMpPCB object, by reading it from file.
107 std::ifstream in(AliMpFiles::SlatPCBFilePath(kStation345,pcbType).Data());
110 AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
114 AliMpMotifReader reader(kStation345,kNonBendingPlane);
115 // note that the nonbending
116 // parameter is of no use for station345, as far as reading motif is
117 // concerned, as all motifs are supposed to be in the same directory
118 // (as they are shared by bending/non-bending planes).
122 const TString kSizeKeyword("SIZES");
123 const TString kMotifKeyword("MOTIF");
127 while ( in.getline(line,80) )
129 if ( line[0] == '#' ) continue;
133 if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
135 std::istringstream sin(sline(kSizeKeyword.Length(),
136 sline.Length()-kSizeKeyword.Length()).Data());
137 float padSizeX = 0.0;
138 float padSizeY = 0.0;
139 float pcbSizeX = 0.0;
140 float pcbSizeY = 0.0;
141 sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
143 pcb = new AliMpPCB(pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
146 if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
148 std::istringstream sin(sline(kMotifKeyword.Length(),
149 sline.Length()-kMotifKeyword.Length()).Data());
153 sin >> sMotifType >> ix >> iy;
155 AliMpMotifType* motifType =
156 reader.BuildMotifType(sMotifType.Data());
159 pcb->Add(motifType,ix,iy);
165 fgPCBMap.Add(new TObjString(pcbType),pcb);
169 //_____________________________________________________________________________
171 AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
174 // Create a new AliMpSlat object, by reading it from file.
177 std::ifstream in(AliMpFiles::SlatFilePath(kStation345,slatType,
181 AliErrorClass(Form("Cannot read slat from %s",
182 AliMpFiles::SlatFilePath(kStation345,slatType,planeType).Data()));
188 const TString kpcbKeyword("PCB");
190 AliMpSlat* slat = new AliMpSlat(slatType, planeType);
192 while ( in.getline(line,80) )
194 if ( line[0] == '#' ) continue;
196 TString sline(AliMpHelper::Normalize(line));
198 if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
200 TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
201 Ssiz_t blankPos = tmp.First(' ');
204 AliErrorClass("Syntax error in PCB file, should get a list of "
205 "manu ids after the pcbname");
210 TString pcbName(tmp(0,blankPos));
211 TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
213 AliMpPCB* pcbType = PCB(pcbName.Data());
216 AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
222 AliMpHelper::DecodeName(manus,';',manuList);
223 if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
225 AliErrorClass(Form("Wrong number of manu ids for this PCB ("
226 "%s) : %d out of %d",pcbName.Data(),
227 manuList.GetSize(),pcbType->GetSize()));
232 for ( Int_t i = 0; i < manuList.GetSize(); ++i )
234 manuList[i] |= AliMpConstants::ManuMask(planeType);
236 slat->Add(pcbType,manuList);