#include "AliMpUID.h"
#include "AliLog.h"
#include "Riostream.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TSystem.h"
using std::cout;
using std::endl;
ClassImp(AliMpUID)
namespace
{
const char* nameTemplateMANU = "MANU %d";
const char* nameTemplateDE = "DE %d";
const char* nameTemplateBP = "BusPatch %d";
const char* nameTemplateCHAMBER = "Chamber %d";
const char* nameTemplateSTATION = "Station %d";
const char* nameTemplatePCB = "PCB %d";
const char* pathTemplateMANU = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d/MANU%04d";
const char* pathTemplateBP = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d";
const char* pathTemplateDE = "Cathode%d/Station%d/Chamber%d/DE%04d";
const char* pathTemplateCHAMBER = "Cathode%d/Station%d/Chamber%d";
const char* pathTemplateSTATION = "Cathode%d/Station%d";
const char* pathTemplateMANUPCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d/MANU%04d";
const char* pathTemplatePCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d";
}
AliMpUID::AliMpUID()
:
fCathodeId(-1),
fStationId(-1),
fChamberId(-1),
fDetElemId(-1),
fBusPatchId(-1),
fManuId(-1),
fPCBId(-1)
{
}
AliMpUID::AliMpUID(AliMp::CathodType cathodeType, Int_t station, Int_t chamber, Int_t de, Int_t bp, Int_t manu, Int_t pcb)
:
fCathodeId(cathodeType),
fStationId(station),
fChamberId(chamber),
fDetElemId(de),
fBusPatchId(bp),
fManuId(manu),
fPCBId(pcb)
{
}
AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const AliMpUID& b)
:
fCathodeId(cathodeType),
fStationId(b.StationId()),
fChamberId(b.ChamberId()),
fDetElemId(b.DetElemId()),
fBusPatchId(b.BusPatchId()),
fManuId(b.ManuId()),
fPCBId(b.PCBId())
{
}
AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const char* pathname)
:
fCathodeId(cathodeType),
fStationId(-1),
fChamberId(-1),
fDetElemId(-1),
fBusPatchId(-1),
fManuId(-1),
fPCBId(-1)
{
if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
}
AliMpUID::AliMpUID(const char* pathname)
:
fCathodeId(2),
fStationId(-1),
fChamberId(-1),
fDetElemId(-1),
fBusPatchId(-1),
fManuId(-1),
fPCBId(-1)
{
if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
}
TString
AliMpUID::BaseName() const
{
return gSystem->BaseName(PathName().Data());
}
AliMp::CathodType
AliMpUID::CathodeId() const
{
return AliMp::GetCathodType(fCathodeId);
}
Bool_t
AliMpUID::CheckTemplate(const char* name, const char* pathTemplateName, Int_t& value)
{
if ( TString(name).Contains("Cathode") )
{
sscanf(name,pathTemplateName,&fCathodeId,&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
}
else
{
TString templ(pathTemplateName);
Int_t i = templ.Index("/");
templ = templ(i+1,templ.Length()-i-1);
sscanf(name,templ.Data(),&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
}
return IsValid();
}
TString
AliMpUID::DirName() const
{
return gSystem->DirName(PathName().Data());
}
Bool_t
AliMpUID::IsStation() const
{
return fCathodeId >= 0 && fStationId >= 0 && fChamberId == -1 ;
}
Bool_t
AliMpUID::IsChamber() const
{
return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId == -1;
}
Bool_t
AliMpUID::IsDetectionElement() const
{
return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId==-1 && fPCBId == -1;
}
Bool_t
AliMpUID::IsBusPatch() const
{
return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId>=0 && fManuId ==-1;
}
Bool_t AliMpUID::IsManu() const
{
return
fCathodeId >= 0 &&
fStationId >= 0 &&
fChamberId >= 0 &&
fDetElemId >= 0 &&
( fBusPatchId>=0 || fPCBId >=0 ) &&
fManuId >=0;
}
Bool_t AliMpUID::IsPCB() const
{
return fCathodeId >= 0 && fPCBId >= 0 && fManuId == -1;
}
Bool_t AliMpUID::IsValid() const
{
return IsStation() || IsChamber() || IsDetectionElement() || IsBusPatch() || IsManu() || IsPCB();
}
TString
AliMpUID::Name() const
{
if ( IsManu() )
{
return Form(nameTemplateMANU,ManuId());
}
if ( IsPCB() )
{
return Form(nameTemplatePCB,PCBId());
}
if ( IsBusPatch() )
{
return Form(nameTemplateBP,BusPatchId());
}
if ( IsDetectionElement() )
{
return Form(nameTemplateDE,DetElemId());
}
if ( IsChamber() )
{
return Form(nameTemplateCHAMBER,ChamberId());
}
if ( IsStation() )
{
return Form(nameTemplateSTATION,StationId());
}
return "INVALID NAME";
}
TString
AliMpUID::PathName() const
{
if ( IsManu() )
{
if ( fPCBId >= 0 )
{
return StripCathode(Form(pathTemplateMANUPCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId(),ManuId()));
}
else
{
return StripCathode(Form(pathTemplateMANU,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId(),ManuId()));
}
}
if ( IsPCB() )
{
return StripCathode(Form(pathTemplatePCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId()));
}
if ( IsBusPatch() )
{
return StripCathode(Form(pathTemplateBP,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId()));
}
if ( IsDetectionElement() )
{
return StripCathode(Form(pathTemplateDE,CathodeId(),StationId(),ChamberId(),DetElemId()));
}
if ( IsChamber() )
{
return StripCathode(Form(pathTemplateCHAMBER,CathodeId(),StationId(),ChamberId()));
}
if ( IsStation() )
{
return StripCathode(Form(pathTemplateSTATION,CathodeId(),StationId()));
}
return "INVALID PATHNAME";
}
void
AliMpUID::Print(Option_t*) const
{
cout << Name().Data() << " (" << PathName().Data() << ")" << endl;
}
TString
AliMpUID::StripCathode(const char* name) const
{
TString rv(name);
if ( fCathodeId == 2 )
{
rv.ReplaceAll("Cathode2/","");
}
return rv;
}
TString
AliMpUID::Type() const
{
TString n(Name());
TObjArray* s = n.Tokenize(" ");
TString rv(static_cast<TObjString*>(s->At(0))->String());
delete s;
return rv;
}