]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpDetElement.cxx
Replacement of AliMpIntPair object with algoritmic
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDetElement.cxx
index 634bb2d91c114848f61e02392f5917ef62c711f8..7eae3c32eaa83b29afe5c73c3836c99d13f45a8e 100644 (file)
 // $Id$
 // $MpId: AliMpDetElement.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
 // Category: management
-//
+
+//-----------------------------------------------------------------------------
 // Class AliMpDetElement
 // --------------------
 // The class defines the electronics properties of detection element
 // Authors: Ivana Hrivnacova, IPN Orsay
 //          Laurent Aphecetche, Christian Finck, SUBATECH Nantes
+//-----------------------------------------------------------------------------
 
 #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>
 
 /// \cond CLASSIMP
@@ -46,15 +58,16 @@ AliMpDetElement::AliMpDetElement(Int_t id, const TString& name,
     fSegType(segType),
     fPlaneType(planeType),
     fBusPatchIds(false),
-    fManuToSerialNbs(1700),
-    fSerialNbToManus(1700)
+    fManuList(),
+    fTrackerChannels(),
+    fHVmanus(),
+    fNofChannels(0)
 {
 /// Standard constructor
-
 }
 
 //______________________________________________________________________________
-AliMpDetElement::AliMpDetElement(TRootIOCtor* /*ioCtor*/)
+AliMpDetElement::AliMpDetElement(TRootIOCtor* ioCtor)
   : TObject(),
     fId(0),
     fDdlId(-1),
@@ -62,8 +75,10 @@ AliMpDetElement::AliMpDetElement(TRootIOCtor* /*ioCtor*/)
     fSegType(),
     fPlaneType(),
     fBusPatchIds(),
-    fManuToSerialNbs(),
-    fSerialNbToManus()
+    fManuList(),
+    fTrackerChannels(),
+    fHVmanus(ioCtor),
+    fNofChannels()
 {
 /// Root IO constructor
 }
@@ -96,16 +111,6 @@ Bool_t AliMpDetElement::AddBusPatch(Int_t busPatchId)
   return true;
 }  
  
-//______________________________________________________________________________
-void AliMpDetElement::AddManuSerial(Int_t manuId, Int_t serialNb)
-{
-/// Map the serial manu number 
-/// (Eventually add check if the given pair already present)
-
-  fManuToSerialNbs.Add(Long_t(manuId), Long_t(serialNb)); 
-  fSerialNbToManus.Add(Long_t(serialNb), Long_t(manuId));
-}      
-
 //______________________________________________________________________________
 TString AliMpDetElement::GetSegName(AliMp::CathodType cathType) const
 {
@@ -155,17 +160,38 @@ 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::kStation1;
+    return AliMp::kStation12;
   }  
   
-  if ( chamberId ==  0 || chamberId ==  1 )  return AliMp::kStation1;
-  if ( chamberId ==  2 || chamberId ==  3 )  return AliMp::kStation2;
+  if ( chamberId >=  0 && chamberId <=  3 )  return AliMp::kStation12;
   if ( chamberId >=  4 && chamberId <=  9 )  return AliMp::kStation345;
   if ( chamberId >= 10 && chamberId <= 13 )  return AliMp::kStationTrigger;
 
   // Should never get to this line
   AliFatal("Cannot return AliMp::StationType value.");
-  return AliMp::kStation1;
+  return AliMp::kStation12;
+}
+
+//______________________________________________________________________________
+AliMq::Station12Type AliMpDetElement::GetStation12Type() const
+{
+/// Return station12 type                                                      \n
+/// Failure causes Fatal error - as AliMp::Station12Type has no possibility
+/// to return undefined value
+
+  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;
+
+  // Should never get to this line
+  AliFatal("Cannot return AliMp::StationType value.");
+  return AliMq::kNotSt12;
 }
 
 //______________________________________________________________________________
@@ -200,26 +226,135 @@ Bool_t  AliMpDetElement::HasBusPatchId(Int_t busPatchId) const
 }
 
 //______________________________________________________________________________
-Int_t  AliMpDetElement::GetNofManus() const
+Int_t 
+AliMpDetElement::NofChannelsInManu(Int_t manuId) const
 {
-/// Return the number of manus in this detection element  
-
-  return fManuToSerialNbs.GetSize();
-}   
+  /// Return the number of channels in a given manu
+  
+  Long_t uid = AliMpManuUID::BuildUniqueID(fId,manuId);
+  
+  return (Int_t)(fManuList.GetValue(uid));
+}
 
 //______________________________________________________________________________
-Int_t  AliMpDetElement::GetManuSerialFromId(Int_t manuId) const
+Bool_t 
+AliMpDetElement::IsExistingChannel(Int_t manuId, Int_t manuChannel) const
 {
-/// Return manu serial number from manuId
+  /// Whether or not the channel is a valid one (does not tell if it is
+  /// connected or not
+  
+  if ( NofChannelsInManu(manuId) > 0 && 
+       manuChannel >= 0 && 
+       manuChannel < AliMpConstants::ManuNofChannels() ) 
+  {
+    return kTRUE;
+  }
+  else
+  {
+    return kFALSE;
+  }
+}
 
-  return (Int_t)fManuToSerialNbs.GetValue(Long_t(manuId));
+//______________________________________________________________________________
+Bool_t 
+AliMpDetElement::IsConnectedChannel(Int_t manuId, Int_t manuChannel) const
+{
+  /// Whether or not the channel is a *connected* one (i.e. it is valid plus
+  /// it corresponds to a real pad)
+  
+  return ( fTrackerChannels.GetValue(AliMpPadUID::BuildUniqueID(fId,manuId,manuChannel)) > 0 );
 }
 
 //______________________________________________________________________________
-Int_t  AliMpDetElement::GetManuIdFromSerial(Int_t serialNb) const
+void
+AliMpDetElement::AddManu(Int_t manuId)
 {
-/// Return manuId from manu serial number
+  /// Fills the fManuList and fTrackerChannels
+  AliMp::StationType stationType = AliMpDEManager::GetStationType(fId);
+  
+  if ( stationType == AliMp::kStationTrigger ) return;
+    
+  AliCodeTimerAuto("")
+  
+  AliDebug(1,Form("DE %4d Manu %4d",fId,manuId));
+
+  AliCodeTimerStart(Form("%s",AliMp::StationTypeName(stationType).Data()));
+  
+  if ( fHVmanus.GetSize() == 0 ) 
+  {
+    fHVmanus.SetOwner(kTRUE); // to be 100% explicit
+    
+    // get the size, to avoid resizing when adding later on
+    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);        
   
-  return (Int_t)fSerialNbToManus.GetValue(Long_t(serialNb));
+  AliCodeTimerStop(Form("%s",AliMp::StationTypeName(stationType).Data()));
+}
+  
+//______________________________________________________________________________
+const AliMpArrayI* 
+AliMpDetElement::ManusForHV(Int_t hvIndex) const
+{
+  /// Return the list of manus sharing a hv channel
+  return static_cast<AliMpArrayI*>(fHVmanus.GetValue(AliMpHVUID::BuildUniqueID(fId,hvIndex)));
+}
+
+//______________________________________________________________________________
+Int_t 
+AliMpDetElement::NofManus() const
+{
+  /// Return the number of manus in this detection element
+  return fManuList.GetSize();
 }