**************************************************************************/
// $Id$
-// $MpId: AliMpBusPatch.cxx,v 1.5 2006/05/24 13:58:34 ivana Exp $
-// Category: management
-
-// Class AliMpBusPatch
-// ---------------
-// Class that manages the maps buspatch<>DDL<>DE
-// for the mapping
-// Calculates also the maximum DSP and buspatch numbers for a given DE
+// $MpId: AliMpBusPatch.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
//
-// Author: Ch. Finck; Subatech Nantes
+// --------------------
+// Class AliMpBusPatch
+// --------------------
+// The class defines the properties of BusPatch
+// Author: Ivana Hrivnacova, IPN Orsay
#include "AliMpBusPatch.h"
-#include "AliMpFiles.h"
-#include "AliMpHelper.h"
+#include "AliMpConstants.h"
+#include "AliMpDEManager.h"
+#include "AliMpSegmentation.h"
+#include "AliMpSlatSegmentation.h"
+#include "AliMpSlat.h"
+#include "AliMpPCB.h"
+#include "AliMpMotifPosition.h"
#include "AliLog.h"
-#include "TArrayI.h"
-#include "Riostream.h"
+#include <Riostream.h>
/// \cond CLASSIMP
ClassImp(AliMpBusPatch)
/// \endcond
-//_____________________________________________________________________________
-AliMpBusPatch::AliMpBusPatch()
- : TObject(),
- fDetElemIdToBusPatch(300),
- fBusPatchToDetElem(300),
- fBusPatchToDDL(300)
+const Int_t AliMpBusPatch::fgkOffset = 100;
+//
+// static methods
+//
+
+//____________________________________________________________________
+Int_t AliMpBusPatch::GetGlobalBusID(Int_t localID, Int_t ddlID)
{
-/// Default constructor
+ /// return global bus id from local bus and ddl id
- for (Int_t i = 0; i < 10; i++)
- fMaxBusPerCh[i] = 0;
+ return ddlID*fgkOffset + localID;
}
-
-
-//_____________________________________________________________________________
-AliMpBusPatch::AliMpBusPatch(const AliMpBusPatch& rhs)
- : TObject(rhs)
+//____________________________________________________________________
+Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
{
-/// Copy constructor
-
- *this = rhs;
-}
+ /// return local bus id from local bus id
-//_____________________________________________________________________________
-AliMpBusPatch::~AliMpBusPatch()
-{
-/// Destructor
+ return globalID - ddlID*fgkOffset;
- fDetElemIdToBusPatch.Delete();
- fBusPatchToDetElem.Delete();
- fBusPatchToDDL.Delete();
}
-//_____________________________________________________________________________
-AliMpBusPatch& AliMpBusPatch::operator = (const AliMpBusPatch& /*rhs*/)
+//______________________________________________________________________________
+AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
+ : TObject(),
+ fId(id),
+ fDEId(detElemId),
+ fDdlId(ddlId),
+ fManus(false),
+ fNofManusPerModule(false)
{
-/// Assignment operator
-
- AliFatal("= operator not implemented");
-
- return *this;
+/// Standard constructor
}
-//____________________________________________________________________
-Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
+//______________________________________________________________________________
+AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
+ : TObject(),
+ fId(),
+ fDEId(),
+ fDdlId(),
+ fManus(),
+ fNofManusPerModule(false)
{
- /// getting DE id from bus patch
- Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
-
- if ( it )
- return (Int_t)it;
- else
- return -1;
+/// Root IO constructor
}
-//____________________________________________________________________
-TArrayI* AliMpBusPatch::GetBusfromDE(Int_t idDE)
+//______________________________________________________________________________
+AliMpBusPatch::~AliMpBusPatch()
{
-/// getting bus patch from DE id
-
- return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
+/// Destructor
}
-//____________________________________________________________________
-Int_t AliMpBusPatch::GetDDLfromBus(Int_t busPatchId)
-{
-/// getting DE id from bus patch
- Long_t it = fBusPatchToDDL.GetValue(busPatchId);
- if ( it )
- return (Int_t)it;
- else
- return -1;
-}
+//
+// public methods
+//
-//____________________________________________________________________
-void AliMpBusPatch::GetDspInfo(Int_t iCh, Int_t& iDspMax, Int_t* iBusPerDSP)
-const
+//______________________________________________________________________________
+Bool_t AliMpBusPatch::AddManu(Int_t manuId)
{
-/// calculates the number of DSP & buspatch per block
-
- Int_t iBusPerBlk = fMaxBusPerCh[iCh]/4; //per half chamber; per block
-
- iDspMax = iBusPerBlk/5; //number max of DSP per block
- if (iBusPerBlk % 5 != 0)
- iDspMax += 1;
-
- for (Int_t i = 0; i < iDspMax; i++) {
- if ((iBusPerBlk -= 5) > 0)
- iBusPerDSP[i] = 5;
- else
- iBusPerDSP[i] = iBusPerBlk + 5;
- }
-
-}
-//____________________________________________________________________
-void AliMpBusPatch::ReadBusPatchFile()
+/// Add detection element with given detElemId.
+/// Return true if the detection element was added
+
+ if ( HasManu(manuId) ) {
+ AliWarningStream()
+ << "Manu with manuId=" << manuId << " already present."
+ << endl;
+ return false;
+ }
+
+ fManus.Add(manuId);
+ return true;
+}
+
+//______________________________________________________________________________
+Bool_t AliMpBusPatch::SetNofManusPerModule()
{
-/// idDE <> buspatch <> iDDL map's
-
- TString infile = AliMpFiles::BusPatchFilePath();
+/// Set the number of manus per patch module (PCB):
+/// - for stations 12 all manus are connected to one PCB,
+/// - for slat stations there are maximum three PCBs per buspatch
+/// Not correct for station 2
- ifstream in(infile, ios::in);
- if (!in) AliError("DetElemIdToBusPatch.dat not found.");
-
- char line[80];
+ if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation1 ||
+ AliMpDEManager::GetStationType(fDEId) == AliMp::kStation2 ) {
- Int_t iChprev = 1;
- Int_t maxBusPatch = 0;
-
- while ( in.getline(line,80) ) {
-
- if ( line[0] == '#' ) continue;
+ // simply fill the number of manus, no bridge for station 1
+ // not the case for station 2.
+
+ fNofManusPerModule.Add(GetNofManus());
+ return true;
+ }
- TString tmp(AliMpHelper::Normalize(line));
+ if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation345 ) {
+
+ const AliMpSlatSegmentation* seg0
+ = static_cast<const AliMpSlatSegmentation*>(
+ AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath0));
- Int_t blankPos = tmp.First(' ');
- Int_t blankPos1 = tmp.Last(' ');
+ const AliMpSlatSegmentation* seg1
+ = static_cast<const AliMpSlatSegmentation*>(
+ AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath1));
- TString sDE(tmp(0, blankPos));
+ const AliMpSlat* slat0 = seg0->Slat();
+ const AliMpSlat* slat1 = seg1->Slat();
- Int_t idDE = atoi(sDE.Data());
+
+ Int_t iPcb = 0;
+ Int_t iPcbPrev = -1;
+ Int_t manuPerPcb = 0;
+
+ Double_t x = 0.;
+ Double_t length = 0.;
+
+ // Loop over manu
+ for (Int_t iManu = 0; iManu < GetNofManus(); ++iManu) {
+ Int_t manuId = GetManuId(iManu);
+ AliMpMotifPosition* motifPos0 = slat0->FindMotifPosition(manuId);
+ AliMpMotifPosition* motifPos1 = slat1->FindMotifPosition(manuId);
- if (idDE/100 != iChprev) {
- fMaxBusPerCh[iChprev-1] = maxBusPatch-iChprev*100+1;
- iChprev = idDE/100;
+ if ( !motifPos0 && !motifPos1 ) {
+ // should never happen
+ AliErrorStream()
+ << "Motif position for manuId = " << manuId << "not found" << endl;
+ return false;
}
- TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
-
- Int_t iDDL = atoi(sDDL.Data());
-
- TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
- AliDebug(3,Form("idDE %d buspatch %s iDDL %d\n", idDE, busPatch.Data(), iDDL));
-
- TArrayI busPatchList;
- // decoding range of buspatch
- AliMpHelper::DecodeName(busPatch,';',busPatchList);
+ // find PCB id
+ if ( motifPos0 ) {
+ x = motifPos0->Position().X();
+ length = slat0->GetPCB(0)->DX()*2.;
+ }
+ if ( motifPos1 ) {
+ x = motifPos1->Position().X();
+ length = slat1->GetPCB(0)->DX()*2.;
+ }
- // filling buspatch -> idDE
- for (Int_t i = 0; i < busPatchList.GetSize(); i++) {
- fBusPatchToDetElem.Add((Long_t)busPatchList[i],(Long_t)idDE);
- fBusPatchToDDL.Add((Long_t)busPatchList[i],(Long_t)iDDL);
- maxBusPatch = busPatchList[i];
+ iPcb = Int_t(x/length + AliMpConstants::LengthTolerance());
+
+ // check when going to next PCB
+ if ( iPcb == iPcbPrev )
+ manuPerPcb++;
+ else if ( iPcbPrev != -1 ) {
+ //vec.Set(vec.GetSize()+1);
+ //vec[vec.GetSize()-1] = manuPerPcb+1;
+ fNofManusPerModule.Add(manuPerPcb+1);
+ manuPerPcb = 0;
}
-
- // filling idDE -> buspatch list (vector)
- fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList)));
-
+ iPcbPrev = iPcb;
}
- fMaxBusPerCh[iChprev-1] = maxBusPatch-iChprev*100+1;
+ // store last PCB
+ //vec.Set(vec.GetSize()+1);
+ //vec[vec.GetSize()-1] = manuPerPcb+1;
+ fNofManusPerModule.Add(manuPerPcb+1);
+ return true;
+ }
+
+ return false;
+}
+
+//______________________________________________________________________________
+Int_t AliMpBusPatch::GetNofManus() const
+{
+/// Return the number of detection elements connected to this DDL
+
+ return fManus.GetSize();
+}
+
+//______________________________________________________________________________
+Int_t AliMpBusPatch::GetManuId(Int_t index) const
+{
+/// Return the detection element by index (in loop)
+
+ return fManus.GetValue(index);
+}
- in.close();
+//______________________________________________________________________________
+Bool_t AliMpBusPatch::HasManu(Int_t manuId) const
+{
+/// Return true if bus patch has manu with given manuId
+ return fManus.HasValue(manuId);
}
+
+//______________________________________________________________________________
+Int_t AliMpBusPatch::GetNofPatchModules() const
+{
+/// Return the number of patch modules (PCB) connected to this bus patch.
+
+ return fNofManusPerModule.GetSize();
+}
+
+//______________________________________________________________________________
+Int_t AliMpBusPatch::GetNofManusPerModule(Int_t patchModule) const
+{
+/// Return the number of manus per patch module (PCB)
+
+ if ( patchModule < 0 || patchModule >= GetNofPatchModules() ) {
+ AliErrorStream() << "Invalid patch module number = " << patchModule << endl;
+ return 0;
+ }
+
+ return fNofManusPerModule.GetValue(patchModule);
+}