#include "AliMpSt345Reader.h"
#include "AliLog.h"
#include "AliMpSlatMotifMap.h"
#include "AliMpMotifReader.h"
#include "AliMpFiles.h"
#include "AliMpDataStreams.h"
#include "AliMpMotifType.h"
#include "AliMpPCB.h"
#include "AliMpSlat.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>
ClassImp(AliMpSt345Reader)
AliMpSt345Reader::AliMpSt345Reader(AliMpSlatMotifMap* motifMap)
:
TObject(),
fMotifMap(motifMap)
{
}
AliMpSt345Reader::~AliMpSt345Reader()
{
}
AliMpPCB*
AliMpSt345Reader::ReadPCB(const AliMpDataStreams& dataStreams,
const char* pcbType)
{
istream& in
= dataStreams.
CreateDataStream(AliMpFiles::SlatPCBFilePath(
AliMp::kStation345, pcbType));
AliMpMotifReader reader(AliMp::kStation345, AliMq::kNotSt12, AliMp::kNonBendingPlane);
char line[80];
const TString kSizeKeyword("SIZES");
const TString kMotifKeyword("MOTIF");
AliMpPCB* pcb = 0;
while ( in.getline(line,80) )
{
if ( line[0] == '#' ) continue;
TString sline(line);
if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
{
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;
if (pcb)
{
AliError("pcb not null as expected");
}
pcb = new AliMpPCB(fMotifMap,pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
}
if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
{
std::istringstream sin(sline(kMotifKeyword.Length(),
sline.Length()-kMotifKeyword.Length()).Data());
TString sMotifType;
int ix;
int iy;
sin >> sMotifType >> ix >> iy;
AliMpMotifType* motifType = fMotifMap->FindMotifType(sMotifType);
if (!motifType)
{
AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
motifType = reader.BuildMotifType(dataStreams, sMotifType.Data());
fMotifMap->AddMotifType(motifType);
}
else
{
AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));
}
if (pcb) pcb->Add(motifType,ix,iy);
}
}
delete ∈
return pcb;
}
AliMpSlat*
AliMpSt345Reader::ReadSlat(const AliMpDataStreams& dataStreams,
const char* slatType, AliMp::PlaneType planeType)
{
istream& in
= dataStreams.
CreateDataStream(AliMpFiles::SlatFilePath(
AliMp::kStation345, slatType, planeType));
char line[80];
const TString kpcbKeyword("PCB");
AliMpSlat* slat = new AliMpSlat(slatType, planeType);
while ( in.getline(line,80) )
{
if ( line[0] == '#' ) continue;
TString sline(AliMpHelper::Normalize(line));
if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
{
TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
Ssiz_t blankPos = tmp.First(' ');
if ( blankPos < 0 )
{
AliErrorClass("Syntax error in PCB file, should get a list of "
"manu ids after the pcbname");
delete slat;
return 0;
}
TString pcbName(tmp(0,blankPos));
TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
AliMpPCB* pcbType = ReadPCB(dataStreams,pcbName.Data());
if (!pcbType)
{
AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
delete slat;
return 0;
}
TArrayI manuList;
AliMpHelper::DecodeName(manus,';',manuList);
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;
}
for ( Int_t i = 0; i < manuList.GetSize(); ++i )
{
manuList[i] |= AliMpConstants::ManuMask(planeType);
}
slat->Add(*pcbType,manuList);
delete pcbType;
}
}
delete ∈
return slat;
}