// $Id$
// $MpId: AliMpTriggerReader.cxx,v 1.4 2006/05/24 13:58:52 ivana Exp $
-#include <cstdlib>
#include "AliMpTriggerReader.h"
-#include "AliMpMotifReader.h"
+
+#include "AliLog.h"
+#include "AliMpConstants.h"
+#include "AliMpDataStreams.h"
#include "AliMpFiles.h"
+#include "AliMpHelper.h"
+#include "AliMpMotif.h"
+#include "AliMpMotifPosition.h"
+#include "AliMpMotifReader.h"
+#include "AliMpMotifSpecial.h"
#include "AliMpMotifType.h"
#include "AliMpPCB.h"
#include "AliMpSlat.h"
#include "AliMpSlatMotifMap.h"
-#include "AliMpMotifSpecial.h"
-#include "AliMpMotifPosition.h"
-#include "AliMpMotif.h"
-#include "AliMpHelper.h"
+#include "AliMpSlatMotifMap.h"
#include "AliMpSt345Reader.h"
#include "AliMpTrigger.h"
-#include "AliMpConstants.h"
-
-#include "AliLog.h"
-
#include "Riostream.h"
#include "TClass.h"
-#include "TObjString.h"
#include "TList.h"
+#include "TObjString.h"
#include "TString.h"
#include <TArrayI.h>
+#include <cstdlib>
#include <sstream>
//-----------------------------------------------------------------------------
ClassImp(AliMpTriggerReader)
/// \endcond
-const TString AliMpTriggerReader::fgkKeywordLayer("LAYER");
-const TString AliMpTriggerReader::fgkKeywordScale("SCALE");
-const TString AliMpTriggerReader::fgkKeywordPcb("PCB");
-const TString AliMpTriggerReader::fgkKeywordFlipX("FLIP_X");
-const TString AliMpTriggerReader::fgkKeywordFlipY("FLIP_Y");
+//
+// static private methods
+//
+
+//_____________________________________________________________________________
+const TString& AliMpTriggerReader::GetKeywordLayer()
+{
+ /// Keyword: LAYER
+ static const TString kKeywordLayer("LAYER");
+ return kKeywordLayer;
+}
+
+//_____________________________________________________________________________
+const TString& AliMpTriggerReader::GetKeywordScale()
+{
+ /// Keyword: SCALE
+ static const TString kKeywordScale("SCALE");
+ return kKeywordScale;
+}
//_____________________________________________________________________________
-AliMpTriggerReader::AliMpTriggerReader()
+const TString& AliMpTriggerReader::GetKeywordPcb()
+{
+ /// Keyword : PCB
+ static const TString kKeywordPcb("PCB");
+ return kKeywordPcb;
+}
+
+//_____________________________________________________________________________
+const TString& AliMpTriggerReader::GetKeywordFlipX()
+{
+ /// Keyword : FLIPX
+ static const TString kKeywordFlipX("FLIP_X");
+ return kKeywordFlipX;
+}
+
+//_____________________________________________________________________________
+const TString& AliMpTriggerReader::GetKeywordFlipY()
+{
+ /// Keyword : FLIPY
+ static const TString kKeywordFlipY("FLIP_Y");
+ return kKeywordFlipY;
+}
+
+//
+// ctors, dtor
+//
+
+//_____________________________________________________________________________
+AliMpTriggerReader::AliMpTriggerReader(AliMpSlatMotifMap* motifMap)
: TObject(),
- fMotifMap(AliMpSlatMotifMap::Instance()),
+ fMotifMap(motifMap),
fLocalBoardMap()
{
///
//_____________________________________________________________________________
AliMpSlat*
-AliMpTriggerReader::BuildSlat(const char* slatName,
+AliMpTriggerReader::BuildSlat(const AliMpDataStreams& dataStreams,
+ const char* slatName,
AliMp::PlaneType planeType,
const TList& lines,
Double_t scale)
TString& keyword = ((TObjString*)tokens->At(0))->String();
- if ( keyword == fgkKeywordPcb )
+ if ( keyword == GetKeywordPcb() )
{
if ( tokens->GetEntriesFast() != 3 )
{
pcbName = s.str().c_str();
}
- AliMpPCB* pcbType = ReadPCB(pcbName.Data());
+ AliMpPCB* pcbType = ReadPCB(dataStreams, pcbName.Data());
if (!pcbType)
{
AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
delete slat;
+ delete tokens;
return 0;
}
std::ostringstream name;
name << localBoards(0,pos-1) << localBoardNumbers[i];
AliDebugClass(3,name.str().c_str());
- localBoardNumbers[i] = LocalBoardNumber(name.str().c_str());
+ localBoardNumbers[i] = LocalBoardNumber(dataStreams,name.str().c_str());
AliDebugClass(3,Form("LOCALBOARDNUMBER %d\n",localBoardNumbers[i]));
allLocalBoards.Set(allLocalBoards.GetSize()+1);
allLocalBoards[allLocalBoards.GetSize()-1] = localBoardNumbers[i];
TString& keyword = ((TObjString*)tokens->At(0))->String();
- if ( keyword == fgkKeywordPcb &&
+ if ( keyword == GetKeywordPcb() &&
tokens->GetEntriesFast() == 3 )
{
boardName = ((TObjString*)tokens->At(2))->String();
//_____________________________________________________________________________
void
-AliMpTriggerReader::FlipLines(TList& lines, Bool_t flipX, Bool_t flipY,
+AliMpTriggerReader::FlipLines(const AliMpDataStreams& dataStreams,
+ TList& lines, Bool_t flipX, Bool_t flipY,
Int_t srcLine, Int_t destLine)
{
///
TString& s = oline->String();
- if ( !s.Contains(fgkKeywordPcb) )
+ if ( !s.Contains(GetKeywordPcb()) )
{
// Only consider PCB lines.
continue;
{
std::ostringstream bs;
bs << boardName(0,boardName.Length()-1) << b;
- if ( LocalBoardNumber(bs.str().c_str()) >= 0 )
+ if ( LocalBoardNumber(dataStreams,bs.str().c_str()) >= 0 )
{
AliDebugClass(4,Form("Replacing %s by %s in %s\n",
boardName(boardName.Length()-2,2).Data(),
}
// Check that the replacement we did is ok. If not,
// skip the line.
- Int_t lbn = LocalBoardNumber(GetBoardNameFromPCBLine(s));
+ Int_t lbn = LocalBoardNumber(dataStreams,GetBoardNameFromPCBLine(s));
if ( lbn < 0 )
{
AliDebugClass(4,Form("Removing line %s\n",s.Data()));
//___________________________________________________________________________
Int_t
-AliMpTriggerReader::IsLayerLine(const TString& sline)
+AliMpTriggerReader::IsLayerLine(const TString& sline) const
{
/// Whether sline contains LAYER keyword
- if ( sline.BeginsWith(fgkKeywordLayer) )
+ if ( sline.BeginsWith(GetKeywordLayer()) )
{
return 1;
}
TString keyword(sline(0,blankPos));
- if ( keyword == fgkKeywordFlipX )
+ if ( keyword == GetKeywordFlipX() )
{
flipX = kTRUE;
- } else if ( keyword == fgkKeywordFlipY )
+ } else if ( keyword == GetKeywordFlipY() )
{
flipY = kTRUE;
}
{
/// Decode sline containing SCALE keyword
- if ( sline(0,fgkKeywordScale.Length()) == fgkKeywordScale )
+ if ( sline(0,GetKeywordScale().Length()) == GetKeywordScale() )
{
- TString tmp(sline(fgkKeywordScale.Length()+1,
- sline.Length()-fgkKeywordScale.Length()-1));
+ TString tmp(sline(GetKeywordScale().Length()+1,
+ sline.Length()-GetKeywordScale().Length()-1));
Ssiz_t blankPos = tmp.First(' ');
if ( blankPos < 0 )
{
//_____________________________________________________________________________
int
-AliMpTriggerReader::LocalBoardNumber(const char* localBoardName)
+AliMpTriggerReader::LocalBoardNumber(const AliMpDataStreams& dataStreams,
+ const char* localBoardName)
{
/// From local board name to local board number
if ( !fLocalBoardMap.GetSize() )
{
- ReadLocalBoardMapping();
+ ReadLocalBoardMapping(dataStreams);
}
TPair* pair = (TPair*)fLocalBoardMap.FindObject(localBoardName);
//_____________________________________________________________________________
void
-AliMpTriggerReader::ReadLines(const char* slatType,
+AliMpTriggerReader::ReadLines(const AliMpDataStreams& dataStreams,
+ const char* slatType,
AliMp::PlaneType planeType,
TList& lines,
Double_t& scale,
" destLine %d\n",slatType,scale,flipX,flipY,
srcLine,destLine));
- TString filename(AliMpFiles::SlatFilePath(AliMp::kStationTrigger,slatType,
- planeType).Data());
- std::ifstream in(filename.Data());
- if (!in.good())
- {
- AliErrorClass(Form("Cannot read slat from %s",filename.Data()));
- }
+ istream& in
+ = dataStreams.
+ CreateDataStream(AliMpFiles::SlatFilePath(
+ AliMp::kStationTrigger,slatType, planeType));
char line[80];
if ( sline.Length() == 0 || sline[0] == '#' ) continue;
Bool_t isKeywordThere =
- sline.Contains(fgkKeywordPcb) ||
- sline.Contains(fgkKeywordLayer) ||
- sline.Contains(fgkKeywordScale) ||
- sline.Contains(fgkKeywordFlipX) ||
- sline.Contains(fgkKeywordFlipY);
+ sline.Contains(GetKeywordPcb()) ||
+ sline.Contains(GetKeywordLayer()) ||
+ sline.Contains(GetKeywordScale()) ||
+ sline.Contains(GetKeywordFlipX()) ||
+ sline.Contains(GetKeywordFlipY());
if ( !isKeywordThere )
{
if ( isScaleLine < 0 )
{
- AliFatalClass(Form("Syntax error near %s keyword\n",fgkKeywordScale.Data()));
+ AliFatalClass(Form("Syntax error near %s keyword\n",GetKeywordScale().Data()));
}
else if ( isScaleLine > 0 && slatType2 != slatType )
{
- ReadLines(slatType2.Data(),planeType,lines,scale,flipX,flipY,srcLine,destLine);
+ ReadLines(dataStreams,
+ slatType2.Data(),planeType,lines,scale,flipX,flipY,srcLine,destLine);
}
else
{
}
flipX |= fx;
flipY |= fy;
- ReadLines(slatType2.Data(),planeType,lines,scale,flipX,flipY,srcLine,destLine);
+ ReadLines(dataStreams,
+ slatType2.Data(),planeType,lines,scale,flipX,flipY,srcLine,destLine);
}
else
{
}
}
- in.close();
+ delete ∈
}
//_____________________________________________________________________________
void
-AliMpTriggerReader::ReadLocalBoardMapping()
+AliMpTriggerReader::ReadLocalBoardMapping(const AliMpDataStreams& dataStreams)
{
/// Reads the file that contains the mapping local board name <-> number
- TString filename(AliMpFiles::LocalTriggerBoardMapping());
-
- AliDebugClass(2,Form("Reading from %s\n",filename.Data()));
-
fLocalBoardMap.DeleteAll();
UShort_t mask;
- ifstream in(filename.Data());
- if (!in.good())
- {
- AliErrorClass(Form("Cannot read file %s\n",filename.Data()));
- }
- else
+ istream& in
+ = dataStreams.
+ CreateDataStream(AliMpFiles::LocalTriggerBoardMapping());
+
+ char line[80];
+ Char_t localBoardName[20];
+ Int_t j,localBoardId;
+ UInt_t switches;
+ Int_t nofBoards;
+
+ while (!in.eof())
{
- char line[80];
- Char_t localBoardName[20];
- Int_t j,localBoardId;
- UInt_t switches;
-
- while (!in.eof())
- {
- for (Int_t i = 0; i < 4; ++i)
- if (!in.getline(line,80)) continue; //skip 4 first lines
+ for (Int_t i = 0; i < 4; ++i)
+ if (!in.getline(line,80)) continue; //skip 4 first lines
- // read mask
- if (!in.getline(line,80)) break;
- sscanf(line,"%hx",&mask);
-
- for ( Int_t i = 0; i < 16; ++i )
- {
- if ( (mask >> i ) & 0x1 )
- {
- if (!in.getline(line,80)) break;
- sscanf(line,"%02d %s %03d %03x", &j, localBoardName, &localBoardId, &switches);
- if (localBoardId <= AliMpConstants::NofLocalBoards())
- {
- fLocalBoardMap.Add(new TObjString(localBoardName), new TObjString(Form("%d",localBoardId)));
- AliDebugClass(10,Form("Board %s has number %d\n", localBoardName, localBoardId));
- }
- // skip 2 following lines
- if (!in.getline(line,80)) break;
- if (!in.getline(line,80)) break;
- }
+ // read mask
+ if (!in.getline(line,80)) break;
+ sscanf(line,"%hx",&mask);
+
+ // read # boards
+ if (!in.getline(line,80)) break;
+ sscanf(line,"%d",&nofBoards);
+
+ for ( Int_t i = 0; i < nofBoards; ++i )
+ {
+
+ if (!in.getline(line,80)) break;
+ sscanf(line,"%02d %19s %03d %03x", &j, localBoardName, &localBoardId, &switches);
+ if (localBoardId <= AliMpConstants::NofLocalBoards())
+ {
+ fLocalBoardMap.Add(new TObjString(localBoardName), new TObjString(Form("%d",localBoardId)));
+ AliDebugClass(10,Form("Board %s has number %d\n", localBoardName, localBoardId));
}
- }
+ // skip 2 following lines
+ if (!in.getline(line,80)) break;
+ if (!in.getline(line,80)) break;
+
+ }
}
-
- in.close();
+
+ delete ∈
}
//_____________________________________________________________________________
AliMpPCB*
-AliMpTriggerReader::ReadPCB(const char* pcbType)
+AliMpTriggerReader::ReadPCB(const AliMpDataStreams& dataStreams,
+ const char* pcbType)
{
///
/// Create a new AliMpPCB object, by reading it from file.
pcbName = pcbName(0,pos);
}
- std::ifstream in(AliMpFiles::SlatPCBFilePath(AliMp::kStationTrigger,pcbName).Data());
- if (!in.good())
- {
- AliErrorClass(Form("Cannot open file for PCB %s",pcbName.Data()));
- return 0;
- }
+ istream& in
+ = dataStreams.
+ CreateDataStream(AliMpFiles::SlatPCBFilePath(
+ AliMp::kStationTrigger,pcbName));
- AliMpMotifReader reader(AliMp::kStationTrigger,AliMp::kNonBendingPlane);
+ AliMpMotifReader reader(AliMp::kStationTrigger, AliMq::kNotSt12, AliMp::kNonBendingPlane);
// note that the nonbending
// parameter is of no use for trigger, as far as reading motif is
// concerned, as all motifs are supposed to be in the same directory
{
AliDebug(1,Form("Reading motifType %s (%s) from file",
sMotifType.Data(),id.Data()));
- motifType = reader.BuildMotifType(sMotifType.Data());
+ motifType = reader.BuildMotifType(dataStreams,sMotifType.Data());
fMotifMap->AddMotifType(motifType);
}
else
AliDebug(1,Form("Got motifType %s (%s) from motifMap",
sMotifType.Data(),id.Data()));
}
- specialMotif = reader.BuildMotifSpecial(sMotifSpecial,motifType,scale);
+ specialMotif = reader.BuildMotifSpecial(dataStreams,sMotifSpecial,motifType,scale);
fMotifMap->AddMotif(specialMotif);
}
else
if ( !motifType)
{
AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
- motifType = reader.BuildMotifType(sMotifType.Data());
+ motifType = reader.BuildMotifType(dataStreams,sMotifType.Data());
fMotifMap->AddMotifType(motifType);
}
else
AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));
}
+ if (! pcb)
+ {
+ AliError("pcb null");
+ continue;
+ }
pcb->Add(motifType,ix,iy);
}
}
- in.close();
+ delete ∈
return pcb;
}
//_____________________________________________________________________________
AliMpTrigger*
-AliMpTriggerReader::ReadSlat(const char* slatType, AliMp::PlaneType planeType)
+AliMpTriggerReader::ReadSlat(const AliMpDataStreams& dataStreams,
+ const char* slatType, AliMp::PlaneType planeType)
{
///
/// Create a new AliMpTrigger object, by reading it from file.
// Read the file and its include (if any) and store the result
// in a TObjArray of TObjStrings.
- ReadLines(slatType,planeType,lines,scale,flipX,flipY,srcLine,destLine);
+ ReadLines(dataStreams,
+ slatType,planeType,lines,scale,flipX,flipY,srcLine,destLine);
// Here some more sanity checks could be done.
// For the moment we only insure that the first line contains
if ( !IsLayerLine(firstLine) )
{
std::ostringstream s;
- s << fgkKeywordLayer;
+ s << GetKeywordLayer();
lines.AddFirst(new TObjString(s.str().c_str()));
}
AliDebugClass(2,Form("Scale=%g\n",scale));
- FlipLines(lines,flipX,flipY,srcLine,destLine);
+ FlipLines(dataStreams,lines,flipX,flipY,srcLine,destLine);
// Now splits the lines in packets corresponding to different layers
// (if any), and create sub-slats.
AliMpTrigger* triggerSlat = new AliMpTrigger(slatType, planeType);
- for ( Int_t ilayer = 0; ilayer < layers.GetEntriesFast(); ++ilayer )
+ for ( ilayer = 0; ilayer < layers.GetEntriesFast(); ++ilayer )
{
- TList& lines = *((TList*)layers.At(ilayer));
+ TList& lines1 = *((TList*)layers.At(ilayer));
std::ostringstream slatName;
slatName << slatType << "-LAYER" << ilayer;
- AliMpSlat* slat = BuildSlat(slatName.str().c_str(),planeType,lines,scale);
+ AliMpSlat* slat = BuildSlat(dataStreams,
+ slatName.str().c_str(),planeType,lines1,scale);
if ( slat )
{
Bool_t ok = triggerSlat->AdoptLayer(slat);
AliError("TriggerSlat is=");
for ( Int_t j = 0; j < triggerSlat->GetSize(); ++j )
{
- AliMpSlat* slat = triggerSlat->GetLayer(j);
+ AliMpSlat* slat1 = triggerSlat->GetLayer(j);
AliError(Form("Layer %d",j));
- for ( Int_t i = 0; i < slat->GetSize(); ++i )
+ for ( Int_t i = 0; i < slat1->GetSize(); ++i )
{
- AliMpPCB* pcb = slat->GetPCB(i);
+ AliMpPCB* pcb = slat1->GetPCB(i);
AliError(Form("ERR pcb %d size %e,%e (unscaled is %e,%e)",
i,pcb->DX()*2,pcb->DY()*2,
pcb->DX()*2/scale,pcb->DY()*2/scale));