]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpBusPatch.cxx
Fix in AliMpSectorSegmentation::PadByPosition;
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpBusPatch.cxx
index 996f25edcd4cea4c60a93a0db1181ec4ec17c0a5..b8e603fbed9af1c05f0d61b4e637dd2198ea59d0 100644 (file)
  **************************************************************************/
 
 // $Id$
-// $MpId: AliMpBusPatch.cxx,v 1.2 2006/03/13 12:22:15 ivana Exp $
-// Category: management
+// $MpId: AliMpBusPatch.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
 
+//-----------------------------------------------------------------------------
 // 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
-//
-// Author: Ch. Finck; Subatech Nantes
+// --------------------
+// The class defines the properties of BusPatch
+// Author: Ivana Hrivnacova, IPN Orsay
+//-----------------------------------------------------------------------------
 
 #include "AliMpBusPatch.h"
-#include "AliMpFiles.h"
-#include "AliMpHelper.h"
+
+#include "AliDAQ.h"
+#include "AliMpConstants.h"
+#include "AliMpDEManager.h"
+#include "AliMpSegmentation.h"
+#include "AliMpSlat.h"
+#include "AliMpPCB.h"
+#include "AliMpMotifPosition.h"
 
 #include "AliLog.h"
 
 #include <Riostream.h>
 
+/// \cond CLASSIMP
 ClassImp(AliMpBusPatch)
+/// \endcond
 
-//////////////////////////////////////////////////////////
+const Int_t  AliMpBusPatch::fgkOffset = 100;
 //
-// This class contains the informations about buspatch vs (DE-DDL)
+// static methods
 //
-//////////////////////////////////////////////////////////
-
 
-//_____________________________________________________________________________
-AliMpBusPatch::AliMpBusPatch()
-  : TObject(),
-    fDetElemIdToBusPatch(300),
-    fBusPatchToDetElem(300),
-    fBusPatchToDDL(300)
+//____________________________________________________________________
+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
+  /// return local bus id from local bus id
+
+  return globalID - ddlID*fgkOffset;
 
- *this = rhs;
 }
 
-//_____________________________________________________________________________
-AliMpBusPatch::~AliMpBusPatch() 
+//______________________________________________________________________________
+AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
+  : TObject(),
+    fId(id),
+    fDEId(detElemId),
+    fDdlId(ddlId),
+    fManus(false),
+    fNofManusPerModule(false),
+    fCableLength(-1),
+    fCableLabel(),
+    fTranslatorLabel(),
+    fFrtId(0)
 {
-/// Destructor
-
-  fDetElemIdToBusPatch.Delete();
-  fBusPatchToDetElem.Delete();
-  fBusPatchToDDL.Delete();
+/// Standard constructor
 }
 
-//_____________________________________________________________________________
-AliMpBusPatch& AliMpBusPatch::operator = (const AliMpBusPatch& /*rhs*/) 
+//______________________________________________________________________________
+AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
+  : TObject(),
+    fId(),
+    fDEId(),
+    fDdlId(),
+    fManus(false),
+    fNofManusPerModule(false),
+    fCableLength(-1),
+    fCableLabel(),
+    fTranslatorLabel(),
+    fFrtId(0)
 {
-/// Assignment operator
-  AliFatal("= operator not implemented");
-
-  return *this;
+/// Root IO constructor
 }
 
-//____________________________________________________________________
-Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
+//______________________________________________________________________________
+AliMpBusPatch::~AliMpBusPatch()
 {
- /// getting DE id from bus patch
-  Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
-
- if ( it ) 
-   return (Int_t)it;
- else 
-   return -1;
+/// Destructor
 }
 
-//____________________________________________________________________
-TArrayI*  AliMpBusPatch::GetBusfromDE(Int_t idDE)
-{
-/// getting bus patch from DE id 
+//
+// public methods
+//
 
-  return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
-}
-//____________________________________________________________________
-Int_t AliMpBusPatch::GetDDLfromBus(Int_t busPatchId)
+//______________________________________________________________________________
+Bool_t AliMpBusPatch::AddManu(Int_t manuId)
 {
-/// getting DE id from bus patch
-  Long_t it = fBusPatchToDDL.GetValue(busPatchId);
+/// 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(Int_t manuNumber)
+{
+/// Set the number of manus per patch module (PCB):
+/// - for stations 1 all manus are connected to one PCB,
+/// - for stations 2 there maximum two PCBs per buspatch,
+/// - for slat stations there are maximum three PCBs per buspatch
 
- if ( it ) 
-   return (Int_t)it;
- else 
-   return -1;
-}
+  if ( AliMpDEManager::GetStation12Type(fDEId) == AliMq::kStation1) {
 
-//____________________________________________________________________
-void AliMpBusPatch::GetDspInfo(Int_t iCh, Int_t& iDspMax, Int_t* iBusPerDSP)
-{
-/// calculates the number of DSP & buspatch per block
+    // simply fill the number of manus, no bridge for station 1
+       
+    fNofManusPerModule.Add(GetNofManus());
+    return true;
+  }
 
-  Int_t iBusPerBlk = fMaxBusPerCh[iCh]/4; //per half chamber; per block
+ if ( AliMpDEManager::GetStation12Type(fDEId) == AliMq::kStation2) {
 
-  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;
+    // there is max two patch modules per buspatch
+       
+    fNofManusPerModule.Add(manuNumber);
+    if (manuNumber != GetNofManus())
+       fNofManusPerModule.Add(GetNofManus() - manuNumber);
+
+    return true;
   }
+
+  if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation345 ) {
   
+    const AliMpSlat* kSlat0 
+       = AliMpSegmentation::Instance()->GetSlat(fDEId, AliMp::kCath0);
+
+    const AliMpSlat* kSlat1 
+       = AliMpSegmentation::Instance()->GetSlat(fDEId, AliMp::kCath1);
+       
+    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 = kSlat0->FindMotifPosition(manuId);
+      AliMpMotifPosition* motifPos1 = kSlat1->FindMotifPosition(manuId);         
+      
+      if ( !motifPos0 && !motifPos1 ) {
+        // should never happen
+        AliErrorStream() 
+          << "Motif position for manuId = " << manuId << "not found" << endl;
+        return false;
+      }
+
+      // find PCB id
+      if ( motifPos0 ) {
+        x = motifPos0->Position().X();
+        length = kSlat0->GetPCB(0)->DX()*2.;
+      }
+      if ( motifPos1 ) {
+        x = motifPos1->Position().X();
+        length = kSlat1->GetPCB(0)->DX()*2.;
+      }
+      
+      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;
+      }
+      iPcbPrev = iPcb;
+    }
+   
+    // store last PCB
+    //vec.Set(vec.GetSize()+1);
+    //vec[vec.GetSize()-1] = manuPerPcb+1;
+    fNofManusPerModule.Add(manuPerPcb+1);
+    return true;  
+  } 
+  
+  return false; 
+}     
+
+//______________________________________________________________________________
+void  AliMpBusPatch::RevertReadout()
+{
+/// Revert order of manus
+
+  fManus.Revert();
 }
-//____________________________________________________________________
-void AliMpBusPatch::ReadBusPatchFile()
+
+//______________________________________________________________________________
+void  AliMpBusPatch::ResetReadout()
 {
-/// idDE <> buspatch <> iDDL map's
-  
-   TString infile = AliMpFiles::BusPatchFilePath();
+/// Revert order of manus
 
-   ifstream in(infile, ios::in);
-   if (!in) AliError("DetElemIdToBusPatch.dat not found.");
-       
-   char line[80];
+  fManus.Reset();
+}
 
-   Int_t iChprev = 1;
-   Int_t maxBusPatch = 0;
+//______________________________________________________________________________
+Int_t AliMpBusPatch::GetNofManus() const
+{  
+/// Return the number of detection elements connected to this DDL
 
-   while ( in.getline(line,80) ) {
+  return fManus.GetSize(); 
+}
 
-      if ( line[0] == '#' ) continue;
+//______________________________________________________________________________
+Int_t  AliMpBusPatch::GetManuId(Int_t index) const
+{  
+/// Return the detection element by index (in loop)
 
-      TString tmp(AliMpHelper::Normalize(line));
+  return fManus.GetValue(index); 
+}
 
-      Int_t blankPos  = tmp.First(' ');
-      Int_t blankPos1 = tmp.Last(' ');
+//______________________________________________________________________________
+Bool_t  AliMpBusPatch::HasManu(Int_t manuId) const
+{  
+/// Return true if bus patch has manu with given manuId
 
-      TString sDE(tmp(0, blankPos));
+  return fManus.HasValue(manuId); 
+}
 
-      Int_t idDE = atoi(sDE.Data());
-      
-      if (idDE/100 != iChprev) {
-       fMaxBusPerCh[iChprev-1] = maxBusPatch-iChprev*100+1;
-       iChprev = idDE/100;
-      }
+//______________________________________________________________________________
+Int_t  AliMpBusPatch::GetNofPatchModules() const
+{
+/// Return the number of patch modules (PCB) connected to this bus patch.
 
-      TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
+  return fNofManusPerModule.GetSize();
+}  
+  
+//______________________________________________________________________________
+TString
+AliMpBusPatch::GetFRTPosition() const
+{
+  /// Return CRXX-Y-Z where XX is the Crocus number, Y the FRT number
+  /// and Z the local bus patch number.
+  return Form("CR%2d-%d-%d",fDdlId,fFrtId+1,GetLocalBusID(fId,fDdlId));
+}
 
-      Int_t iDDL = atoi(sDDL.Data());
+//______________________________________________________________________________
+Int_t  AliMpBusPatch::GetNofManusPerModule(Int_t patchModule) const
+{
+/// Return the number of manus per patch module (PCB)
 
-      TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
-      AliDebug(3,Form("idDE %d buspatch %s iDDL %d\n", idDE, busPatch.Data(), iDDL));
+  if ( patchModule < 0 || patchModule >= GetNofPatchModules() ) {
+    AliErrorStream() << "Invalid patch module number = " << patchModule << endl;
+    return 0;
+  }
+  
+  return fNofManusPerModule.GetValue(patchModule);
+}     
 
-      TArrayI busPatchList;
-      // decoding range of buspatch
-      AliMpHelper::DecodeName(busPatch,';',busPatchList);
+//______________________________________________________________________________
+void 
+AliMpBusPatch::Print(Option_t* opt) const
+{
+  /// Printout
+  
+  cout << Form("BusPatch %04d DDL %d : %s <> %s / %s",
+               fId,
+               AliDAQ::DdlID("MUONTRK",fDdlId),
+               GetFRTPosition().Data(),
+               fCableLabel.Data(),
+               fTranslatorLabel.Data()) << endl;
+
+  TString sopt(opt);
+  sopt.ToUpper();
+  
+  if ( sopt.Contains("FULL") ) 
+  {
+    cout << Form("Nof of PCBs (i.e. patch modules) = %d",fNofManusPerModule.GetSize()) << endl;
+    
+    for ( Int_t i = 0; i < fNofManusPerModule.GetSize(); ++i ) 
+    {
+      cout << Form("\t\t %d manus in patch module %d",fNofManusPerModule.GetValue(i),i) << endl;
+    }
+    
+    if ( sopt.Contains("MANU") )
+    {
+      cout << "Manus of that buspatch=" << endl;
       
-      // 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];
+      for ( Int_t i = 0; i < fManus.GetSize(); ++i ) 
+      {
+        cout << Form("%4d,",fManus.GetValue(i));
       }
-   
-      // filling idDE -> buspatch list (vector)
-      fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList))); 
-
+      cout << endl;
     }
-   
-   fMaxBusPerCh[iChprev-1] = maxBusPatch-iChprev*100+1;
-
-  in.close();
-
+  }
+  
+//  Int_t        fId;     ///< Identifier (unique)
+//  Int_t        fDEId;   ///< Detection element to which this bus patch is connected
+//  Int_t        fDdlId;  ///< DDL to which this bus patch is connected
+//  AliMpArrayI  fManus;  ///< Manu Ids connected to this bus patch
+//  AliMpArrayI  fNofManusPerModule; ///< Nof Manus per patch modules (PCBs)
+//  Float_t      fCableLength;       ///< length of the buspatch cable
+//  TString      fCableLabel;        ///< label of the buspatch cable
+//  TString      fTranslatorLabel;   ///< label of the translator board
+//  Int_t        fFrtId;               ///< FRT Ids connected to this bus patch
+  
 }