**************************************************************************/
// $Id$
-// $MpId: AliMpSt345Reader.cxx,v 1.5 2005/09/23 12:57:32 ivana Exp $
+// $MpId: AliMpSt345Reader.cxx,v 1.11 2006/05/24 13:58:50 ivana Exp $
#include "AliMpSt345Reader.h"
#include "AliLog.h"
+#include "AliMpSlatMotifMap.h"
#include "AliMpMotifReader.h"
#include "AliMpFiles.h"
#include "AliMpMotifType.h"
#include "AliMpPCB.h"
#include "AliMpSlat.h"
-#include "AliMpMotifMap.h"
#include "AliMpMotifPosition.h"
#include "AliMpMotif.h"
#include "AliMpHelper.h"
+#include "AliMpConstants.h"
#include "Riostream.h"
-
#include "TClass.h"
#include "TObjString.h"
#include "TString.h"
#include <sstream>
-#include <assert.h>
-ClassImp(AliMpSt345Reader)
+///
+/// \class AliMpSt345Reader
+//
+/// Read slat and pcb ASCII files.
+///
+/// Basically this class provides two methods :
+/// - AliMpSlat* ReadSlat()
+/// - AliMpPCB ReadPCB()
+///
+/// \author Laurent Aphecetche
-TMap AliMpSt345Reader::fgPCBMap;
+/// \cond CLASSIMP
+ClassImp(AliMpSt345Reader)
+/// \endcond
//_____________________________________________________________________________
-AliMpSt345Reader::AliMpSt345Reader() : TObject()
+AliMpSt345Reader::AliMpSt345Reader(AliMpSlatMotifMap& motifMap)
+:
+TObject(),
+fMotifMap(motifMap)
{
- //
- // Default ctor.
- //
+ ///
+ /// Default ctor.
+ ///
}
//_____________________________________________________________________________
AliMpSt345Reader::~AliMpSt345Reader()
{
- //
- // Dtor.
- //
- fgPCBMap.Delete();
-}
-
-//_____________________________________________________________________________
-AliMpPCB*
-AliMpSt345Reader::PCB(const char* pcbType)
-{
- //
- // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...)
- //
- // Note that the returned object is either a new one (read from file) or a
- // reused one if it is already present in the internal map.
- //
-
- TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType);
- if ( pair )
- {
- AliDebugClass(1,Form("Getting pcb %s from internal map",pcbType));
- return (AliMpPCB*)pair->Value();
- }
- else
- {
- AliDebugClass(1,Form("Reading pcb %s from file",pcbType));
- return ReadPCB(pcbType);
- }
+ ///
+ /// Dtor.
+ ///
}
//_____________________________________________________________________________
AliMpPCB*
AliMpSt345Reader::ReadPCB(const char* pcbType)
{
- //
- // Create a new AliMpPCB object, by reading it from file.
- //
+ ///
+ /// Create a new AliMpPCB object, by reading it from file.
+ /// The returned object must be deleted by the client
- std::ifstream in(AliMpFiles::SlatPCBFilePath(kStation345,pcbType).Data());
+ std::ifstream in(AliMpFiles::SlatPCBFilePath(AliMp::kStation345,pcbType).Data());
if (!in.good())
{
AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
return 0;
}
- AliMpMotifReader reader(kStation345,kNonBendingPlane);
+ AliMpMotifReader reader(AliMp::kStation345,AliMp::kNonBendingPlane);
// note that the nonbending
// parameter is of no use for station345, as far as reading motif is
// concerned, as all motifs are supposed to be in the same directory
char line[80];
- const TString sizeKeyword("SIZES");
- const TString motifKeyword("MOTIF");
+ const TString kSizeKeyword("SIZES");
+ const TString kMotifKeyword("MOTIF");
AliMpPCB* pcb = 0;
TString sline(line);
- if ( sline(0,sizeKeyword.Length()) == sizeKeyword )
+ if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
{
- std::istringstream sin(sline(sizeKeyword.Length(),
- sline.Length()-sizeKeyword.Length()).Data());
- float padSizeX = 0.0;
- float padSizeY = 0.0;
- float pcbSizeX = 0.0;
- float pcbSizeY = 0.0;
+ std::istringstream sin(sline(kSizeKeyword.Length(),
+ sline.Length()-kSizeKeyword.Length()).Data());
+ double padSizeX = 0.0;
+ double padSizeY = 0.0;
+ double pcbSizeX = 0.0;
+ double pcbSizeY = 0.0;
sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
- assert(pcb==0);
- pcb = new AliMpPCB(pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
+ if (pcb)
+ {
+ AliError("pcb not null as expected");
+ }
+ pcb = new AliMpPCB(&fMotifMap,pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
}
- if ( sline(0,motifKeyword.Length()) == motifKeyword )
+ if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
{
- std::istringstream sin(sline(motifKeyword.Length(),
- sline.Length()-motifKeyword.Length()).Data());
+ std::istringstream sin(sline(kMotifKeyword.Length(),
+ sline.Length()-kMotifKeyword.Length()).Data());
TString sMotifType;
int ix;
int iy;
sin >> sMotifType >> ix >> iy;
- AliMpMotifType* motifType =
- reader.BuildMotifType(sMotifType.Data());
+ AliMpMotifType* motifType = fMotifMap.FindMotifType(sMotifType);
+ if (!motifType)
+ {
+ AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
+ motifType = reader.BuildMotifType(sMotifType.Data());
+ fMotifMap.AddMotifType(motifType);
+ }
+ else
+ {
+ AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));
+ }
- assert(pcb!=0);
pcb->Add(motifType,ix,iy);
}
}
in.close();
- fgPCBMap.Add(new TObjString(pcbType),pcb);
return pcb;
}
//_____________________________________________________________________________
AliMpSlat*
-AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
+AliMpSt345Reader::ReadSlat(const char* slatType, AliMp::PlaneType planeType)
{
- //
- // Create a new AliMpSlat object, by reading it from file.
- //
+ ///
+ /// Create a new AliMpSlat object, by reading it from file.
+ /// The returned object must be deleted by the client.
- std::ifstream in(AliMpFiles::SlatFilePath(kStation345,slatType,
+ std::ifstream in(AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,
planeType).Data());
if (!in.good())
{
AliErrorClass(Form("Cannot read slat from %s",
- AliMpFiles::SlatFilePath(kStation345,slatType,planeType).Data()));
+ AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,planeType).Data()));
return 0;
}
char line[80];
- const TString pcbKeyword("PCB");
+ const TString kpcbKeyword("PCB");
AliMpSlat* slat = new AliMpSlat(slatType, planeType);
TString sline(AliMpHelper::Normalize(line));
- if ( sline(0,pcbKeyword.Length()) == pcbKeyword )
+ if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
{
- TString tmp(sline(pcbKeyword.Length()+1,sline.Length()-pcbKeyword.Length()));
+ TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
Ssiz_t blankPos = tmp.First(' ');
if ( blankPos < 0 )
{
TString pcbName(tmp(0,blankPos));
TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
- AliMpPCB* pcbType = PCB(pcbName.Data());
+ AliMpPCB* pcbType = ReadPCB(pcbName.Data());
if (!pcbType)
{
AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
TArrayI manuList;
AliMpHelper::DecodeName(manus,';',manuList);
- if ( manuList.GetSize() != pcbType->GetSize() )
+ if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
{
AliErrorClass(Form("Wrong number of manu ids for this PCB ("
"%s) : %d out of %d",pcbName.Data(),
manuList.GetSize(),pcbType->GetSize()));
+ delete pcbType;
delete slat;
return 0;
}
- slat->Add(pcbType,manuList);
+
+ for ( Int_t i = 0; i < manuList.GetSize(); ++i )
+ {
+ manuList[i] |= AliMpConstants::ManuMask(planeType);
+ }
+ slat->Add(*pcbType,manuList);
+ delete pcbType;
}
}