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.4 2005/09/19 19:01:31 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"
32 #include "Riostream.h"
35 #include "TObjString.h"
40 ClassImp(AliMpSt345Reader)
42 TMap AliMpSt345Reader::fgPCBMap;
44 //_____________________________________________________________________________
45 AliMpSt345Reader::AliMpSt345Reader() : TObject()
52 //_____________________________________________________________________________
53 AliMpSt345Reader::~AliMpSt345Reader()
61 //_____________________________________________________________________________
63 AliMpSt345Reader::PCB(const char* pcbType)
66 // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...)
68 // Note that the returned object is either a new one (read from file) or a
69 // reused one if it is already present in the internal map.
72 TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType);
75 AliDebugClass(1,Form("Getting pcb %s from internal map",pcbType));
76 return (AliMpPCB*)pair->Value();
80 AliDebugClass(1,Form("Reading pcb %s from file",pcbType));
81 return ReadPCB(pcbType);
85 //_____________________________________________________________________________
87 AliMpSt345Reader::ReadPCB(const char* pcbType)
90 // Create a new AliMpPCB object, by reading it from file.
93 std::ifstream in(AliMpFiles::Instance()->SlatPCBFilePath(pcbType).Data());
96 AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
100 AliMpMotifReader reader(kStation345,kNonBendingPlane);
101 // note that the nonbending
102 // parameter is of no use for station345, as far as reading motif is
103 // concerned, as all motifs are supposed to be in the same directory
104 // (as they are shared by bending/non-bending planes).
108 const TString sizeKeyword("SIZES");
109 const TString motifKeyword("MOTIF");
113 while ( in.getline(line,80) )
115 if ( line[0] == '#' ) continue;
119 if ( sline(0,sizeKeyword.Length()) == sizeKeyword )
121 std::istringstream sin(sline(sizeKeyword.Length(),
122 sline.Length()-sizeKeyword.Length()).Data());
123 float padSizeX = 0.0;
124 float padSizeY = 0.0;
125 float pcbSizeX = 0.0;
126 float pcbSizeY = 0.0;
127 sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
129 pcb = new AliMpPCB(pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
132 if ( sline(0,motifKeyword.Length()) == motifKeyword )
134 std::istringstream sin(sline(motifKeyword.Length(),
135 sline.Length()-motifKeyword.Length()).Data());
139 sin >> sMotifType >> ix >> iy;
141 AliMpMotifType* motifType =
142 reader.BuildMotifType(sMotifType.Data());
145 pcb->Add(motifType,ix,iy);
151 fgPCBMap.Add(new TObjString(pcbType),pcb);
155 //_____________________________________________________________________________
157 AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
160 // Create a new AliMpSlat object, by reading it from file.
163 std::ifstream in(AliMpFiles::Instance()->SlatFilePath(slatType,
167 AliErrorClass(Form("Cannot read slat from %s",
168 AliMpFiles::Instance()->
169 SlatFilePath(slatType,planeType).Data()));
175 const TString pcbKeyword("PCB");
177 AliMpSlat* slat = new AliMpSlat(slatType);
179 while ( in.getline(line,80) )
181 if ( line[0] == '#' ) continue;
183 TString sline(AliMpHelper::Normalize(line));
185 if ( sline(0,pcbKeyword.Length()) == pcbKeyword )
187 TString tmp(sline(pcbKeyword.Length()+1,sline.Length()-pcbKeyword.Length()));
188 Ssiz_t blankPos = tmp.First(' ');
191 AliErrorClass("Syntax error in PCB file, should get a list of "
192 "manu ids after the pcbname");
197 TString pcbName(tmp(0,blankPos));
198 TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
200 AliMpPCB* pcbType = PCB(pcbName.Data());
203 AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
209 AliMpHelper::DecodeName(manus,';',manuList);
210 if ( manuList.GetSize() != pcbType->GetSize() )
212 AliErrorClass(Form("Wrong number of manu ids for this PCB ("
213 "%s) : %d out of %d",pcbName.Data(),
214 manuList.GetSize(),pcbType->GetSize()));
218 slat->Add(pcbType,manuList);