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.5 2005/09/23 12:57:32 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"
41 ClassImp(AliMpSt345Reader)
43 TMap AliMpSt345Reader::fgPCBMap;
45 //_____________________________________________________________________________
46 AliMpSt345Reader::AliMpSt345Reader() : TObject()
53 //_____________________________________________________________________________
54 AliMpSt345Reader::~AliMpSt345Reader()
62 //_____________________________________________________________________________
64 AliMpSt345Reader::PCB(const char* pcbType)
67 // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...)
69 // Note that the returned object is either a new one (read from file) or a
70 // reused one if it is already present in the internal map.
73 TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType);
76 AliDebugClass(1,Form("Getting pcb %s from internal map",pcbType));
77 return (AliMpPCB*)pair->Value();
81 AliDebugClass(1,Form("Reading pcb %s from file",pcbType));
82 return ReadPCB(pcbType);
86 //_____________________________________________________________________________
88 AliMpSt345Reader::ReadPCB(const char* pcbType)
91 // Create a new AliMpPCB object, by reading it from file.
94 std::ifstream in(AliMpFiles::Instance()->SlatPCBFilePath(pcbType).Data());
97 AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
101 AliMpMotifReader reader(kStation345,kNonBendingPlane);
102 // note that the nonbending
103 // parameter is of no use for station345, as far as reading motif is
104 // concerned, as all motifs are supposed to be in the same directory
105 // (as they are shared by bending/non-bending planes).
109 const TString sizeKeyword("SIZES");
110 const TString motifKeyword("MOTIF");
114 while ( in.getline(line,80) )
116 if ( line[0] == '#' ) continue;
120 if ( sline(0,sizeKeyword.Length()) == sizeKeyword )
122 std::istringstream sin(sline(sizeKeyword.Length(),
123 sline.Length()-sizeKeyword.Length()).Data());
124 float padSizeX = 0.0;
125 float padSizeY = 0.0;
126 float pcbSizeX = 0.0;
127 float pcbSizeY = 0.0;
128 sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
130 pcb = new AliMpPCB(pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
133 if ( sline(0,motifKeyword.Length()) == motifKeyword )
135 std::istringstream sin(sline(motifKeyword.Length(),
136 sline.Length()-motifKeyword.Length()).Data());
140 sin >> sMotifType >> ix >> iy;
142 AliMpMotifType* motifType =
143 reader.BuildMotifType(sMotifType.Data());
146 pcb->Add(motifType,ix,iy);
152 fgPCBMap.Add(new TObjString(pcbType),pcb);
156 //_____________________________________________________________________________
158 AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
161 // Create a new AliMpSlat object, by reading it from file.
164 std::ifstream in(AliMpFiles::Instance()->SlatFilePath(slatType,
168 AliErrorClass(Form("Cannot read slat from %s",
169 AliMpFiles::Instance()->
170 SlatFilePath(slatType,planeType).Data()));
176 const TString pcbKeyword("PCB");
178 AliMpSlat* slat = new AliMpSlat(slatType);
180 while ( in.getline(line,80) )
182 if ( line[0] == '#' ) continue;
184 TString sline(AliMpHelper::Normalize(line));
186 if ( sline(0,pcbKeyword.Length()) == pcbKeyword )
188 TString tmp(sline(pcbKeyword.Length()+1,sline.Length()-pcbKeyword.Length()));
189 Ssiz_t blankPos = tmp.First(' ');
192 AliErrorClass("Syntax error in PCB file, should get a list of "
193 "manu ids after the pcbname");
198 TString pcbName(tmp(0,blankPos));
199 TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
201 AliMpPCB* pcbType = PCB(pcbName.Data());
204 AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
210 AliMpHelper::DecodeName(manus,';',manuList);
211 if ( manuList.GetSize() != pcbType->GetSize() )
213 AliErrorClass(Form("Wrong number of manu ids for this PCB ("
214 "%s) : %d out of %d",pcbName.Data(),
215 manuList.GetSize(),pcbType->GetSize()));
219 slat->Add(pcbType,manuList);