]> 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 11cb22a597dc6057dc0ff60f6b3bf8ea47b100c0..b8e603fbed9af1c05f0d61b4e637dd2198ea59d0 100644 (file)
  **************************************************************************/
 
 // $Id$
-// $MpId: AliMpBusPatch.cxx,v 1.5 2006/05/24 13:58:34 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 DDL
-// Create a bus Iterator for DDL, needed especially for station 3
-// Implementing a Sort method for Iterator, not really needed for the moment
-//
-// 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 "TArrayI.h"
-#include "Riostream.h"
+#include <Riostream.h>
 
 /// \cond CLASSIMP
 ClassImp(AliMpBusPatch)
 /// \endcond
 
-//_____________________________________________________________________________
-AliMpBusPatch::AliMpBusPatch()
-  : TObject(),
-    fDetElemIdToBusPatch(300),
-    fBusPatchToDetElem(300),
-    fBusPatchToDDL(300)
-{
-/// Default constructor
-}
+const Int_t  AliMpBusPatch::fgkOffset = 100;
+//
+// static methods
+//
 
-//_____________________________________________________________________________
-AliMpBusPatch::~AliMpBusPatch() 
+//____________________________________________________________________
+Int_t AliMpBusPatch::GetGlobalBusID(Int_t localID, Int_t ddlID)
 {
-/// Destructor
+  /// return global bus id from local bus and ddl id
 
-  fDetElemIdToBusPatch.Delete();
-  fBusPatchToDetElem.Delete();
-  fBusPatchToDDL.Delete();
+  return ddlID*fgkOffset + localID;
 
 }
-
 //____________________________________________________________________
-Int_t AliMpBusPatch::GetDEfromBus(Int_t busPatchId)
+Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
 {
- /// getting DE id from bus patch
-  Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
+  /// return local bus id from local bus id
+
+  return globalID - ddlID*fgkOffset;
 
- if ( it ) 
-   return (Int_t)it;
- else 
-   return -1;
 }
 
-//____________________________________________________________________
-TArrayI*  AliMpBusPatch::GetBusfromDE(Int_t idDE)
+//______________________________________________________________________________
+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)
 {
-/// getting bus patch from DE id 
-
-  return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
+/// Standard constructor
 }
-//____________________________________________________________________
-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;
+//______________________________________________________________________________
+AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
+  : TObject(),
+    fId(),
+    fDEId(),
+    fDdlId(),
+    fManus(false),
+    fNofManusPerModule(false),
+    fCableLength(-1),
+    fCableLabel(),
+    fTranslatorLabel(),
+    fFrtId(0)
+{
+/// Root IO constructor
 }
 
-//____________________________________________________________________
-void AliMpBusPatch::GetDspInfo(Int_t iDDL, Int_t& iDspMax, Int_t* iBusPerDSP) 
-const
+//______________________________________________________________________________
+AliMpBusPatch::~AliMpBusPatch()
 {
-/// calculates the number of DSP & buspatch per block
-
-  Int_t iBusPerBlk = fBusInDDL[iDDL].GetSize()/2; //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;
-  }
-  
+/// Destructor
 }
-//____________________________________________________________________
-void AliMpBusPatch::ReadBusPatchFile()
-{
-/// idDE <> buspatch <> iDDL map's
-  
-   TString infile = AliMpFiles::BusPatchFilePath();
-
-   ifstream in(infile, ios::in);
-   if (!in) AliError("DetElemIdToBusPatch.dat not found.");
-       
-   char line[80];
-
-   while ( in.getline(line,80) ) {
-
-      if ( line[0] == '#' ) continue;
 
-      TString tmp(AliMpHelper::Normalize(line));
+//
+// public methods
+//
 
-      Int_t blankPos  = tmp.First(' ');
-      Int_t blankPos1 = tmp.Last(' ');
+//______________________________________________________________________________
+Bool_t AliMpBusPatch::AddManu(Int_t manuId)
+{
+/// 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
 
-      TString sDE(tmp(0, blankPos));
+  if ( AliMpDEManager::GetStation12Type(fDEId) == AliMq::kStation1) {
 
-      Int_t idDE = atoi(sDE.Data());
+    // simply fill the number of manus, no bridge for station 1
+       
+    fNofManusPerModule.Add(GetNofManus());
+    return true;
+  }
 
-      TString sDDL(tmp(blankPos1 + 1, tmp.Length()-blankPos1));
+ if ( AliMpDEManager::GetStation12Type(fDEId) == AliMq::kStation2) {
 
-      Int_t iDDL = atoi(sDDL.Data());
+    // there is max two patch modules per buspatch
+       
+    fNofManusPerModule.Add(manuNumber);
+    if (manuNumber != GetNofManus())
+       fNofManusPerModule.Add(GetNofManus() - manuNumber);
 
-      // always working local DDL number... for the moment.
-      if (iDDL >= AliDAQ::DdlIDOffset("MUONTRK"))
-       iDDL -= AliDAQ::DdlIDOffset("MUONTRK");
+    return true;
+  }
 
-      TString busPatch(tmp(blankPos + 1,blankPos1-blankPos-1));
-      AliDebug(3,Form("idDE %d buspatch %s iDDL %d\n", idDE, busPatch.Data(), iDDL));
+  if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation345 ) {
+  
+    const AliMpSlat* kSlat0 
+       = AliMpSegmentation::Instance()->GetSlat(fDEId, AliMp::kCath0);
 
-      TArrayI busPatchList;
-      // decoding range of buspatch
-      AliMpHelper::DecodeName(busPatch,';',busPatchList);
+    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);         
       
-      // 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);
-       AddBus(iDDL, busPatchList[i]);
+      if ( !motifPos0 && !motifPos1 ) {
+        // should never happen
+        AliErrorStream() 
+          << "Motif position for manuId = " << manuId << "not found" << endl;
+        return false;
       }
-   
-      // filling idDE -> buspatch list (vector)
-      fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList))); 
 
+      // 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;
     }
    
-  in.close();
+    // store last PCB
+    //vec.Set(vec.GetSize()+1);
+    //vec[vec.GetSize()-1] = manuPerPcb+1;
+    fNofManusPerModule.Add(manuPerPcb+1);
+    return true;  
+  } 
+  
+  return false; 
+}     
 
-}
-//____________________________________________________________________
-void AliMpBusPatch::AddBus(Int_t iDDL, Int_t busPatch)
+//______________________________________________________________________________
+void  AliMpBusPatch::RevertReadout()
 {
-/// add bus patch number per DDL
-
-  fBusInDDL[iDDL].Set(fBusInDDL[iDDL].GetSize() + 1);
-  fBusInDDL[iDDL].AddAt(busPatch, fBusInDDL[iDDL].GetSize() - 1);
+/// Revert order of manus
 
+  fManus.Revert();
 }
 
-
-//____________________________________________________________________
-Int_t AliMpBusPatch::NextBusInDDL(Int_t iDDL)
+//______________________________________________________________________________
+void  AliMpBusPatch::ResetReadout()
 {
-/// Next bus patch number in DDL
-
-  if (fBusItr[iDDL] >= fBusInDDL[iDDL].GetSize())
-    return -1;
-
-  return fBusInDDL[iDDL].At(fBusItr[iDDL]++);
+/// Revert order of manus
 
+  fManus.Reset();
 }
 
-//____________________________________________________________________
-void AliMpBusPatch::ResetBusItr(Int_t iDDL)
-{
-/// reset bus iterator for the given DDL
+//______________________________________________________________________________
+Int_t AliMpBusPatch::GetNofManus() const
+{  
+/// Return the number of detection elements connected to this DDL
 
-  fBusItr[iDDL] = 0;
+  return fManus.GetSize(); 
 }
 
-//____________________________________________________________________
-void AliMpBusPatch::Sort()
-{
-/// sort bus patch number for all DDL
+//______________________________________________________________________________
+Int_t  AliMpBusPatch::GetManuId(Int_t index) const
+{  
+/// Return the detection element by index (in loop)
 
-  for (Int_t j = 0; j < AliDAQ:: NumberOfDdls("MUONTRK"); j++) {
-    Sort(fBusInDDL[j], 0, fBusInDDL[j].GetSize() - 1);
+  return fManus.GetValue(index); 
+}
 
-    if (AliLog::GetGlobalDebugLevel() == 1) {
-      printf("DDL %d\n",j);
-      for (Int_t i = 0; i <  fBusInDDL[j].GetSize(); i++)
-       printf("buspatch %d index %d\n",fBusInDDL[j].At(i), i);
-    }
-  } 
+//______________________________________________________________________________
+Bool_t  AliMpBusPatch::HasManu(Int_t manuId) const
+{  
+/// Return true if bus patch has manu with given manuId
 
+  return fManus.HasValue(manuId); 
 }
 
-//____________________________________________________________________
-void AliMpBusPatch::Sort(TArrayI& arr, Int_t start, Int_t end)
+//______________________________________________________________________________
+Int_t  AliMpBusPatch::GetNofPatchModules() const
 {
-/// sort bus patch number per DDL
-/// not really needed, but for future developments ?
-/// quicksort method, not in Root ?
-
-  Int_t pivot;
-  Int_t starth;
-  Int_t endh; // store pivot # keep start & end in memory for split
+/// Return the number of patch modules (PCB) connected to this bus patch.
 
-  starth = start;
-  endh = end;
-  pivot = arr[start];
+  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));
+}
 
-  while(start < end) {
-      while((arr[end] >= pivot) && (start < end))
-       end--;
+//______________________________________________________________________________
+Int_t  AliMpBusPatch::GetNofManusPerModule(Int_t patchModule) const
+{
+/// Return the number of manus per patch module (PCB)
 
-      if (start != end) {
-         arr[start] = arr[end];
-         start++;
-      }
-      while ((arr[start] <= pivot) && (start < end))
-       start++;
+  if ( patchModule < 0 || patchModule >= GetNofPatchModules() ) {
+    AliErrorStream() << "Invalid patch module number = " << patchModule << endl;
+    return 0;
+  }
+  
+  return fNofManusPerModule.GetValue(patchModule);
+}     
 
-      if (start != end) {
-         arr[end] = arr[start];
-         end--;
+//______________________________________________________________________________
+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;
+      
+      for ( Int_t i = 0; i < fManus.GetSize(); ++i ) 
+      {
+        cout << Form("%4d,",fManus.GetValue(i));
       }
+      cout << endl;
+    }
   }
-
-  arr[start] = pivot;
-  pivot = start;
-  start = starth;
-  end   = endh;
-
-  if(start < pivot)
-    Sort(arr, start, pivot-1);
-
-  if(end > pivot)
-    Sort(arr, pivot+1, end);
-
+  
+//  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
+  
 }