#include "AliMpDetElement.h"
#include "AliMpArrayI.h"
#include "AliMpConstants.h"
#include "AliMpDEManager.h"
#include "AliMpDCSNamer.h"
#include "AliMpHVUID.h"
#include "AliMpManuUID.h"
#include "AliMpPadUID.h"
#include "AliMpSegmentation.h"
#include "AliMpVSegmentation.h"
#include "AliCodeTimer.h"
#include "AliLog.h"
#include <Riostream.h>
using std::endl;
ClassImp(AliMpDetElement)
const char AliMpDetElement::fgkNameSeparator = '_';
AliMpDetElement::AliMpDetElement(Int_t id, const TString& name,
const TString& segType, AliMp::PlaneType planeType)
: TObject(),
fId(id),
fDdlId(-1),
fName(name),
fSegType(segType),
fPlaneType(planeType),
fBusPatchIds(false),
fManuList(),
fTrackerChannels(),
fHVmanus(),
fNofChannels(0)
{
}
AliMpDetElement::AliMpDetElement(TRootIOCtor* ioCtor)
: TObject(),
fId(0),
fDdlId(-1),
fName(),
fSegType(),
fPlaneType(),
fBusPatchIds(),
fManuList(),
fTrackerChannels(),
fHVmanus(ioCtor),
fNofChannels()
{
}
AliMpDetElement::~AliMpDetElement()
{
}
Bool_t AliMpDetElement::AddBusPatch(Int_t busPatchId)
{
if ( HasBusPatchId(busPatchId) ) {
AliWarningStream()
<< "Bus patch Id = " << busPatchId << " already present."
<< endl;
return false;
}
fBusPatchIds.Add(busPatchId);
return true;
}
TString AliMpDetElement::GetSegName(AliMp::CathodType cathType) const
{
return fSegType + fgkNameSeparator + PlaneTypeName(GetPlaneType(cathType));
}
AliMp::PlaneType AliMpDetElement::GetPlaneType(AliMp::CathodType cath) const
{
if ( cath == AliMp::kCath0 ) return fPlaneType;
else return AliMp::OtherPlaneType(fPlaneType);
}
AliMp::CathodType AliMpDetElement::GetCathodType(AliMp::PlaneType planeType) const
{
if ( fPlaneType == planeType ) return AliMp::kCath0;
else return AliMp::kCath1;
}
AliMp::CathodType AliMpDetElement::GetCathodTypeFromManuId(Int_t manuId) const
{
AliMp::PlaneType planeType = AliMp::kBendingPlane;
if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
{
planeType = AliMp::kNonBendingPlane;
}
return GetCathodType(planeType);
}
AliMp::StationType AliMpDetElement::GetStationType() const
{
Int_t chamberId = AliMpDEManager::GetChamberId(fId, false);
if ( ! AliMpDEManager::IsValidChamberId(chamberId, true) ) {
AliFatal("Cannot return AliMp::StationType value.");
return AliMp::kStation12;
}
if ( chamberId >= 0 && chamberId <= 3 ) return AliMp::kStation12;
if ( chamberId >= 4 && chamberId <= 9 ) return AliMp::kStation345;
if ( chamberId >= 10 && chamberId <= 13 ) return AliMp::kStationTrigger;
AliFatal("Cannot return AliMp::StationType value.");
return AliMp::kStation12;
}
AliMq::Station12Type AliMpDetElement::GetStation12Type() const
{
Int_t chamberId = AliMpDEManager::GetChamberId(fId, false);
if ( ! AliMpDEManager::IsValidChamberId(chamberId, true) ) {
AliFatal("Cannot return AliMp::StationType value.");
return AliMq::kNotSt12;
}
if ( chamberId == 0 || chamberId == 1 ) return AliMq::kStation1;
if ( chamberId == 2 || chamberId == 3 ) return AliMq::kStation2;
if ( chamberId >= 4 || chamberId <= 13 ) return AliMq::kNotSt12;
AliFatal("Cannot return AliMp::StationType value.");
return AliMq::kNotSt12;
}
Int_t AliMpDetElement::GetNofBusPatches() const
{
return fBusPatchIds.GetSize();
}
Int_t AliMpDetElement::GetBusPatchId(Int_t index) const
{
if ( index < 0 || index >= GetNofBusPatches() ) {
AliErrorStream()
<< "In DE = " << fId << ": Index " << index << " outside limits." << endl;
return 0;
}
return fBusPatchIds.GetValue(index);
}
Bool_t AliMpDetElement::HasBusPatchId(Int_t busPatchId) const
{
return fBusPatchIds.HasValue(busPatchId);;
}
Int_t
AliMpDetElement::NofChannelsInManu(Int_t manuId) const
{
Long_t uid = AliMpManuUID::BuildUniqueID(fId,manuId);
return (Int_t)(fManuList.GetValue(uid));
}
Bool_t
AliMpDetElement::IsExistingChannel(Int_t manuId, Int_t manuChannel) const
{
if ( NofChannelsInManu(manuId) > 0 &&
manuChannel >= 0 &&
manuChannel < AliMpConstants::ManuNofChannels() )
{
return kTRUE;
}
else
{
return kFALSE;
}
}
Bool_t
AliMpDetElement::IsConnectedChannel(Int_t manuId, Int_t manuChannel) const
{
return ( fTrackerChannels.GetValue(AliMpPadUID::BuildUniqueID(fId,manuId,manuChannel)) > 0 );
}
void
AliMpDetElement::AddManu(Int_t manuId)
{
AliMp::StationType stationType = AliMpDEManager::GetStationType(fId);
if ( stationType == AliMp::kStationTrigger ) return;
AliCodeTimerAuto("",0)
AliDebug(1,Form("DE %4d Manu %4d",fId,manuId));
AliCodeTimerStart(Form("%s",AliMp::StationTypeName(stationType).Data()));
if ( fHVmanus.GetSize() == 0 )
{
fHVmanus.SetOwner(kTRUE);
Int_t nmanus(0);
AliMp::CathodType cathodes[] = { AliMp::kCath0, AliMp::kCath1 };
for ( Int_t i = 0; i < 2; ++i )
{
const AliMpVSegmentation* seg =
AliMpSegmentation::Instance()->GetMpSegmentation(fId,cathodes[i]);
TArrayI manus;
seg->GetAllElectronicCardIDs(manus);
nmanus += manus.GetSize();
}
fHVmanus.SetSize(nmanus);
}
const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(fId,manuId);
Int_t n(0);
for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
{
if ( seg->PadByLocation(manuId,i,kFALSE).IsValid() )
{
++n;
fTrackerChannels.Add((Long_t)AliMpPadUID::BuildUniqueID(fId,manuId,i),
(Long_t)1);
}
}
fManuList.Add(AliMpManuUID::BuildUniqueID(fId,manuId),(Long_t)n);
fNofChannels += n;
AliMpDCSNamer hvNamer("TRACKER");
Int_t index = hvNamer.ManuId2Index(fId,manuId);
UInt_t hvuid = AliMpHVUID::BuildUniqueID(fId,index);
AliMpArrayI* hv = static_cast<AliMpArrayI*>(fHVmanus.GetValue(hvuid));
if (!hv)
{
Bool_t sort(kFALSE);
hv = new AliMpArrayI(sort);
fHVmanus.Add(hvuid,hv);
}
hv->Add(manuId,kFALSE);
AliCodeTimerStop(Form("%s",AliMp::StationTypeName(stationType).Data()));
}
const AliMpArrayI*
AliMpDetElement::ManusForHV(Int_t hvIndex) const
{
return static_cast<AliMpArrayI*>(fHVmanus.GetValue(AliMpHVUID::BuildUniqueID(fId,hvIndex)));
}
Int_t
AliMpDetElement::NofManus() const
{
return fManuList.GetSize();
}