]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpBusPatch.cxx
updates in Kaon Train
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpBusPatch.cxx
index 7405b356fcf47e3956b4337d7cc023c047106ad2..88941a2351f5a90aab7045ed95a69a096fd3c8be 100644 (file)
 
 // $Id$
 // $MpId: AliMpBusPatch.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
-//
-// --------------------
+
+//-----------------------------------------------------------------------------
 // Class AliMpBusPatch
 // --------------------
 // The class defines the properties of BusPatch
 // Author: Ivana Hrivnacova, IPN Orsay
+//-----------------------------------------------------------------------------
 
 #include "AliMpBusPatch.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>
 
+using std::cout;
+using std::endl;
 /// \cond CLASSIMP
 ClassImp(AliMpBusPatch)
 /// \endcond
@@ -60,7 +71,12 @@ AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
     fId(id),
     fDEId(detElemId),
     fDdlId(ddlId),
-    fManus()
+    fManus(false),
+    fNofManusPerModule(false),
+    fCableLength(-1),
+    fCableLabel(),
+    fTranslatorLabel(),
+    fFrtId(0)
 {
 /// Standard constructor
 }
@@ -71,7 +87,12 @@ AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
     fId(),
     fDEId(),
     fDdlId(),
-    fManus()
+    fManus(false),
+    fNofManusPerModule(false),
+    fCableLength(-1),
+    fCableLabel(),
+    fTranslatorLabel(),
+    fFrtId(0)
 {
 /// Root IO constructor
 }
@@ -103,6 +124,111 @@ Bool_t AliMpBusPatch::AddManu(Int_t 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 ( AliMpDEManager::GetStation12Type(fDEId) == AliMq::kStation1) {
+
+    // simply fill the number of manus, no bridge for station 1
+       
+    fNofManusPerModule.Add(GetNofManus());
+    return true;
+  }
+
+ if ( AliMpDEManager::GetStation12Type(fDEId) == AliMq::kStation2) {
+
+    // 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->GetPositionX();
+        length = kSlat0->GetPCB(0)->DX()*2.;
+      }
+      if ( motifPos1 ) {
+        x = motifPos1->GetPositionX();
+        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::ResetReadout()
+{
+/// Revert order of manus
+
+  fManus.Reset();
+}
+
 //______________________________________________________________________________
 Int_t AliMpBusPatch::GetNofManus() const
 {  
@@ -127,4 +253,81 @@ Bool_t  AliMpBusPatch::HasManu(Int_t manuId) const
   return fManus.HasValue(manuId); 
 }
 
+//______________________________________________________________________________
+Int_t  AliMpBusPatch::GetNofPatchModules() const
+{
+/// Return the number of patch modules (PCB) connected to this bus patch.
 
+  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  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);
+}     
+
+//______________________________________________________________________________
+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;
+    }
+  }
+  
+//  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
+  
+}