]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPadStatusMaker.cxx
Changes to speed up creating of status and status map (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONPadStatusMaker.cxx
index 267738e4ec1ca97f16186e3e90ed68d783706a85..5e45d38ab429e95f290612449513d6f20755ddcc 100644 (file)
 **************************************************************************/
 
 // $Id$
 **************************************************************************/
 
 // $Id$
+
+//-----------------------------------------------------------------------------
 /// \class AliMUONPadStatusMaker
 ///
 /// Make a 2DStore of pad statuses, using different sources of information,
 /// like pedestal values, gain values, and HV values.
 ///
 /// \class AliMUONPadStatusMaker
 ///
 /// Make a 2DStore of pad statuses, using different sources of information,
 /// like pedestal values, gain values, and HV values.
 ///
-///
-// Author Laurent Aphecetche
+/// \author Laurent Aphecetche
+//-----------------------------------------------------------------------------
 
 #include "AliMUONPadStatusMaker.h"
 
 
 #include "AliMUONPadStatusMaker.h"
 
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliCodeTimer.h"
+#include "AliDCSValue.h"
+#include "AliLog.h"
 #include "AliMUON2DMap.h"
 #include "AliMUON2DMap.h"
-#include "AliMUONCalibParam1I.h"
+#include "AliMUON2DStoreValidator.h"
+#include "AliMUONCalibParamNI.h"
 #include "AliMUONCalibrationData.h"
 #include "AliMUONCalibrationData.h"
-#include "AliMUONHVNamer.h"
-#include "AliMUONObjectPair.h"
+#include "AliMUONStringIntMap.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVCalibParam.h"
-#include "AliMUONVDataIterator.h"
-
 #include "AliMpArea.h"
 #include "AliMpArea.h"
+#include "AliMpArrayI.h"
+#include "AliMpConstants.h"
+#include "AliMpDDLStore.h"
 #include "AliMpDEIterator.h"
 #include "AliMpDEManager.h"
 #include "AliMpDEIterator.h"
 #include "AliMpDEManager.h"
+#include "AliMpDetElement.h"
+#include "AliMpExMap.h"
+#include "AliMpHVNamer.h"
 #include "AliMpIntPair.h"
 #include "AliMpIntPair.h"
-#include "AliMpManuList.h"
+#include "AliMpManuUID.h"
 #include "AliMpMotifMap.h"
 #include "AliMpMotifPosition.h"
 #include "AliMpPCB.h"
 #include "AliMpPad.h"
 #include "AliMpMotifMap.h"
 #include "AliMpMotifPosition.h"
 #include "AliMpPCB.h"
 #include "AliMpPad.h"
-#include "AliMpSector.h"
-#include "AliMpSectorSegmentation.h"
 #include "AliMpSegmentation.h"
 #include "AliMpSlat.h"
 #include "AliMpSlatSegmentation.h"
 #include "AliMpStationType.h"
 #include "AliMpVPadIterator.h"
 #include "AliMpSegmentation.h"
 #include "AliMpSlat.h"
 #include "AliMpSlatSegmentation.h"
 #include "AliMpStationType.h"
 #include "AliMpVPadIterator.h"
+#include "AliMpVSegmentation.h"
+#include <Riostream.h>
+#include <TArrayI.h>
+#include <TExMap.h>
+#include <TMap.h>
+#include <TString.h>
 
 
-#include "AliCDBManager.h"
-#include "AliCDBEntry.h"
-#include "AliDCSValue.h"
-#include "AliLog.h"
-
-#include "Riostream.h"
-#include "TMap.h"
-#include "TStopwatch.h"
-#include "TString.h"
-
-#include <cassert>
-
+/// \cond CLASSIMP
 ClassImp(AliMUONPadStatusMaker)
 ClassImp(AliMUONPadStatusMaker)
+/// \endcond
 
 //_____________________________________________________________________________
 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
 : fCalibrationData(calibData),
 
 //_____________________________________________________________________________
 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
 : fCalibrationData(calibData),
+  fGainA0Limits(0,1E30),
+  fGainA1Limits(-1E-30,1E30),
+  fGainThresLimits(0,4095),
+  fHVSt12Limits(0,5000),
+  fHVSt345Limits(0,5000),
   fPedMeanLimits(0,4095),
   fPedSigmaLimits(0,4095),
   fPedMeanLimits(0,4095),
   fPedSigmaLimits(0,4095),
-  fHVSt12Limits(0,5000),
-  fHVSt345Limits(0,5000)
+  fStatus(new AliMUON2DMap(true)),
+  fHV(new TExMap),
+  fPedestals(calibData.Pedestals()),
+  fGains(calibData.Gains())
 {
 {
-    // ctor
+   /// ctor
+    AliInfo(Form("ped store %s gain store %s",
+                 fPedestals->ClassName(),
+                 fGains->ClassName()));
 }
 
 //_____________________________________________________________________________
 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
 {
 }
 
 //_____________________________________________________________________________
 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
 {
-  // dtor.
+  /// dtor.
+  delete fStatus;
+  delete fHV;
 }
 
 //_____________________________________________________________________________
 }
 
 //_____________________________________________________________________________
-AliMUONV2DStore*
-AliMUONPadStatusMaker::Combine(const AliMUONV2DStore& store1,
-                               const AliMUONV2DStore& store2,
-                               Int_t binShift) const
+TString
+AliMUONPadStatusMaker::AsString(Int_t status)
 {
 {
-  /// Combine two status containers into one, shifting store2 status bits
-  /// to the left by binShift before making an OR with store1.
-  
-  TStopwatch timer;
-  timer.Start(kTRUE);
-  
-  AliMUONV2DStore* combined = static_cast<AliMUONV2DStore*>(store1.Clone());
-  
-  AliMUONVDataIterator* it = store1.Iterator();
-  AliMUONObjectPair* pair;
-  
-  while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
-  {
-    AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
-    Int_t detElemId = ip->GetFirst();
-    Int_t manuId = ip->GetSecond();
-    AliMUONVCalibParam* param1 = static_cast<AliMUONVCalibParam*>(store1.Get(detElemId,manuId));
-    if (!param1)
-    {
-      AliError(Form("Oups. Could not get statuses for store1 for DE %d ManuId %d !!!",
-                    detElemId,manuId));
-      delete combined;
-      combined = 0x0;
-      break;
-    }
-    AliMUONVCalibParam* param2 = static_cast<AliMUONVCalibParam*>(store2.Get(detElemId,manuId));
-    if (!param2)
-    {
-      AliError(Form("Oups. Could not get statuses for store2 for DE %d ManuId %d",
-                    detElemId,manuId));
-      delete combined;
-      combined = 0x0;
-      break;
-    }
-    AliMUONVCalibParam* paramCombined = static_cast<AliMUONVCalibParam*>(combined->Get(detElemId,manuId));
-    if (!paramCombined)
-    {
-      AliError(Form("Oups. Could not get statuses for combined for DE %d ManuId %d",
-                    detElemId,manuId));
-      delete combined;
-      combined = 0x0;
-      break;
-    }
-    
-    for ( Int_t manuChannel = 0; manuChannel < param1->Size(); ++manuChannel )
-    {
-      if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
-      {
-        Int_t status1(param1->ValueAsInt(manuChannel));
-        Int_t status2(param2->ValueAsInt(manuChannel));
-        
-        Int_t status = status1 | (status2 << binShift);
-        
-        paramCombined->SetValueAsInt(manuChannel,0,status);
-      }
-    }
-  }
-  
-  delete it;
+  /// return a human readable version of the integer status
+  Int_t pedStatus;
+  Int_t gainStatus;
+  Int_t hvStatus;
+  
+  DecodeStatus(status,pedStatus,hvStatus,gainStatus);
+  
+//  /// Gain status
+//  enum EGainStatus
+//  {
+//    kGainOK = 0,
+//    kGainA0TooLow = (1<<1),
+//    kGainA0TooHigh = (1<<2),
+//    kGainA1TooLow = (1<<3),
+//    kGainA1TooHigh = (1<<4),
+//    kGainThresTooLow = (1<<5),
+//    kGainThresTooHigh = (1<<6),
+//    
+//    kGainMissing = kMissing // please always use last bit for meaning "missing"
+//  };
+//  
+//  /// Pedestal status
+//  enum EPedestalStatus
+//  {
+//    kPedOK = 0,
+//    kPedMeanZero = (1<<1),
+//    kPedMeanTooLow = (1<<2),
+//    kPedMeanTooHigh = (1<<3),
+//    kPedSigmaTooLow = (1<<4),
+//    kPedSigmaTooHigh = (1<<5),
+//    
+//    kPedMissing = kMissing // please always use last bit for meaning "missing"
+//  };
+//  
+  TString s("PED ");
+  
+  if ( pedStatus == 0 ) s+= " OK";
+  if ( pedStatus & kPedMeanZero ) s += " Mean is Zero. ";
+  if ( pedStatus & kPedMeanTooLow ) s += " Mean Too Low. ";
+  if ( pedStatus & kPedMeanTooHigh ) s += " Mean Too High. ";
+  if ( pedStatus & kPedSigmaTooLow ) s += " Sigma Too Low. ";
+  if ( pedStatus & kPedSigmaTooHigh ) s += " Sigma Too High. ";
+  if ( pedStatus & kPedMissing ) s += " is missing.";
+  
+//  /// HV Error
+//  enum EHVError 
+//  {
+//    kHVOK = 0,
+//    kHVError = (1<<0),
+//    kHVTooLow = (1<<1),
+//    kHVTooHigh = (1<<2),
+//    kHVChannelOFF = (1<<3),
+//    kHVSwitchOFF = (1<<4),
+//    
+//    kHVMissing = kMissing // please always use last bit for meaning "missing"
+//  };
+
+  return s;
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus, 
+                                   Int_t hvStatus, 
+                                   Int_t gainStatus)
+{
+  /// Build a complete status from specific parts (ped,hv,gain)
   
   
-  AliInfo("Timer:");
-  StdoutToAliInfo(timer.Print(););
+  return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) | 
+  ( ( gainStatus & 0xFF ) << 16 );
+}
+
+//_____________________________________________________________________________
+void
+AliMUONPadStatusMaker::DecodeStatus(Int_t status, 
+                                    Int_t& pedStatus, 
+                                    Int_t& hvStatus, 
+                                    Int_t& gainStatus)
+{
+  /// Decode complete status into specific parts (ped,hv,gain)
   
   
-  return combined;
+  gainStatus = ( status & 0xFF0000 ) >> 16;
+  pedStatus = ( status & 0xFF00 ) >> 8;
+  hvStatus = (status & 0xFF);
 }
 
 //_____________________________________________________________________________
 Bool_t 
 }
 
 //_____________________________________________________________________________
 Bool_t 
-AliMUONPadStatusMaker::GetSt12Status(const TMap& hvMap,
-                                     Int_t detElemId, Int_t sector,
-                                     Bool_t& hvChannelTooLow,
-                                     Bool_t& hvChannelTooHigh,
-                                     Bool_t& hvChannelON) const
+AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
+                                    Bool_t& hvChannelTooLow,
+                                    Bool_t& hvChannelTooHigh,
+                                    Bool_t& hvChannelON) const
 {
   /// Get HV status for one HV sector of St12
   
 {
   /// Get HV status for one HV sector of St12
   
@@ -166,16 +200,19 @@ AliMUONPadStatusMaker::GetSt12Status(const TMap& hvMap,
   /// and the switch).
   /// Returns false if hv switch changed during the run.
   
   /// and the switch).
   /// Returns false if hv switch changed during the run.
   
+  AliCodeTimerAuto("")
+  
   Bool_t error = kFALSE;
   hvChannelTooLow = kFALSE;
   hvChannelTooHigh = kFALSE;
   hvChannelON = kTRUE;
   Bool_t error = kFALSE;
   hvChannelTooLow = kFALSE;
   hvChannelTooHigh = kFALSE;
   hvChannelON = kTRUE;
-  
-  AliMUONHVNamer hvNamer;
+
+  AliMpHVNamer hvNamer;
   
   TString hvChannel(hvNamer.DCSHVChannelName(detElemId,sector));
   
   
   TString hvChannel(hvNamer.DCSHVChannelName(detElemId,sector));
   
-  TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
+  TMap* hvMap = fCalibrationData.HV();
+  TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
   if (!hvPair)
   {
     AliError(Form("Did not find expected alias (%s) for DE %d",
   if (!hvPair)
   {
     AliError(Form("Did not find expected alias (%s) for DE %d",
@@ -219,29 +256,32 @@ AliMUONPadStatusMaker::GetSt12Status(const TMap& hvMap,
 
 //_____________________________________________________________________________
 Bool_t 
 
 //_____________________________________________________________________________
 Bool_t 
-AliMUONPadStatusMaker::GetSt345Status(const TMap& hvMap,
-                                      Int_t detElemId, Int_t pcbIndex,
-                                      Bool_t& hvChannelTooLow,
-                                      Bool_t& hvChannelTooHigh,
-                                      Bool_t& hvChannelON,
-                                      Bool_t& hvSwitchON) const
+AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
+                                     Bool_t& hvChannelTooLow,
+                                     Bool_t& hvChannelTooHigh,
+                                     Bool_t& hvChannelON,
+                                     Bool_t& hvSwitchON) const
 {
   /// For a given PCB in a given DE, get the HV status (both the channel
   /// and the switch).
   /// Returns false if something goes wrong (in particular if 
   /// hv switch changed during the run).
   
 {
   /// For a given PCB in a given DE, get the HV status (both the channel
   /// and the switch).
   /// Returns false if something goes wrong (in particular if 
   /// hv switch changed during the run).
   
+  AliCodeTimerAuto("")
+  
   Bool_t error = kFALSE;
   hvChannelTooLow = kFALSE;
   hvChannelTooHigh = kFALSE;
   hvSwitchON = kTRUE;
   hvChannelON = kTRUE;
   
   Bool_t error = kFALSE;
   hvChannelTooLow = kFALSE;
   hvChannelTooHigh = kFALSE;
   hvSwitchON = kTRUE;
   hvChannelON = kTRUE;
   
-  AliMUONHVNamer hvNamer;
+  AliMpHVNamer hvNamer;
   
   TString hvChannel(hvNamer.DCSHVChannelName(detElemId));
   
   
   TString hvChannel(hvNamer.DCSHVChannelName(detElemId));
   
-  TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
+  TMap* hvMap = fCalibrationData.HV();
+  
+  TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
   if (!hvPair)
   {
     AliError(Form("Did not find expected alias (%s) for DE %d",
   if (!hvPair)
   {
     AliError(Form("Did not find expected alias (%s) for DE %d",
@@ -275,13 +315,13 @@ AliMUONPadStatusMaker::GetSt345Status(const TMap& hvMap,
       float highThreshold = fHVSt345Limits.Y();
 
       if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
       float highThreshold = fHVSt345Limits.Y();
 
       if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
-      if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
+      else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
       if ( hvMin < 1 ) hvChannelON = kFALSE;
     }
   }
   
   TString hvSwitch(hvNamer.DCSHVSwitchName(detElemId,pcbIndex));
       if ( hvMin < 1 ) hvChannelON = kFALSE;
     }
   }
   
   TString hvSwitch(hvNamer.DCSHVSwitchName(detElemId,pcbIndex));
-  TPair* switchPair = static_cast<TPair*>(hvMap.FindObject(hvSwitch.Data()));
+  TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
   if (!switchPair)
   {
     AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
   if (!switchPair)
   {
     AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
@@ -332,283 +372,211 @@ AliMUONPadStatusMaker::GetSt345Status(const TMap& hvMap,
 }
 
 //_____________________________________________________________________________
 }
 
 //_____________________________________________________________________________
-AliMUONV2DStore* 
-AliMUONPadStatusMaker::MakeGainStatus(const AliMUONV2DStore& /*gainValues*/) const
-{
-  /// FIXME: to be implemented
-  AliWarning("Not implemented yet");
-  return 0x0;
-}
-
-//_____________________________________________________________________________
-AliMUONV2DStore* 
-AliMUONPadStatusMaker::MakeHVStatus(const TMap& hvValues) const
+Int_t
+AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
 {
 {
-  /// Scrutinize HV values and deduce an HV status for each pad
-  
-  TStopwatch timerSt12;
-  TStopwatch timerSt345;
-  
-  timerSt12.Start(kTRUE);
-  timerSt12.Stop();
-  timerSt345.Start(kTRUE);
-  timerSt345.Stop();
+  /// Get HV status of one manu
   
   
-  AliMUONHVNamer hvNamer;
+  AliCodeTimerAuto("")
   
   
-  AliMpDEIterator deIt;
+  if ( !fCalibrationData.HV() ) return kMissing;
+
+  Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
   
   
-  deIt.First();
+  if ( lint ) 
+  {
+    return (Int_t)(lint - 1);
+  }
+
+  Int_t status(0);
   
   
-  AliMUONV2DStore* hv = new AliMUON2DMap(kTRUE);
+  AliMpHVNamer hvNamer;
   
   
-  while ( !deIt.IsDone() )
+  switch ( AliMpDEManager::GetStationType(detElemId) )
   {
   {
-    Int_t detElemId = deIt.CurrentDEId();
-    
-    switch ( AliMpDEManager::GetStationType(detElemId) )
+    case AliMp::kStation1:
+    case AliMp::kStation2:
     {
     {
-      case AliMp::kStation1:
-      case AliMp::kStation2:
-        timerSt12.Start(kFALSE);
-        for ( int sector = 0; sector < 3; ++sector)
-        {
-          AliDebug(1,Form("detElemId %5d sector %d",detElemId,sector));
-
-          Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
-          Bool_t error = GetSt12Status(hvValues,
-                                       detElemId,sector,
-                                       hvChannelTooLow,hvChannelTooHigh,
-                                       hvChannelON);
-          Int_t status = 0;
-          if ( error ) status |= kHVError;
-          if ( hvChannelTooLow ) status |= kHVTooLow;
-          if ( hvChannelTooHigh ) status |= kHVTooHigh; 
-          if ( !hvChannelON ) status |= kHVChannelOFF;
-          SetStatusSt12(*hv,detElemId,sector,status);
-          
-        }
-          timerSt12.Stop();
-        break;
-      case AliMp::kStation345:
+      int sector = hvNamer.ManuId2Sector(detElemId,manuId);
+      if ( sector >= 0 ) 
       {
       {
-        timerSt345.Start(kFALSE);
-        for ( Int_t pcbIndex = 0; pcbIndex < hvNamer.NumberOfPCBs(detElemId); ++pcbIndex)
-        {
-          AliDebug(1,Form("detElemId %5d pcbIndex %d",detElemId,pcbIndex));
-          Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
-          Bool_t error = GetSt345Status(hvValues,
-                                        detElemId,pcbIndex,
-                                        hvChannelTooLow,hvChannelTooHigh,
-                                        hvChannelON,hvSwitchON);
-          Int_t status = 0;
-          if ( error ) status |= kHVError;
-          if ( hvChannelTooLow ) status |= kHVTooLow;
-          if ( hvChannelTooHigh ) status |= kHVTooHigh; 
-          if ( !hvSwitchON ) status |= kHVSwitchOFF; 
-          if ( !hvChannelON) status |= kHVChannelOFF;
-          SetStatusSt345(*hv,detElemId,pcbIndex,status);
-        }
-        timerSt345.Stop();
+        Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
+        Bool_t error = HVSt12Status(detElemId,sector,
+                                    hvChannelTooLow,
+                                    hvChannelTooHigh,
+                                    hvChannelON);
+        if ( error ) status |= kHVError;
+        if ( hvChannelTooLow ) status |= kHVTooLow;
+        if ( hvChannelTooHigh ) status |= kHVTooHigh; 
+        if ( !hvChannelON ) status |= kHVChannelOFF;
+        // assign this status to all the other manus handled by the same HV channel
+        SetHVStatus(detElemId,sector,status);
       }
       }
-        break;
-      default:
-        break;
     }
     }
-    deIt.Next();
+      break;
+    case AliMp::kStation345:
+    {
+      int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
+      if ( pcbIndex >= 0 ) 
+      {
+        Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
+        Bool_t error = HVSt345Status(detElemId,pcbIndex,
+                                     hvChannelTooLow,hvChannelTooHigh,
+                                     hvChannelON,hvSwitchON);
+        if ( error ) status |= kHVError;
+        if ( hvChannelTooLow ) status |= kHVTooLow;
+        if ( hvChannelTooHigh ) status |= kHVTooHigh; 
+        if ( !hvSwitchON ) status |= kHVSwitchOFF; 
+        if ( !hvChannelON) status |= kHVChannelOFF;
+        // assign this status to all the other manus handled by the same HV channel
+        SetHVStatus(detElemId,pcbIndex,status);
+      }
+    }
+      break;
+    default:
+      break;
   }
   
   }
   
-  AliInfo("St12 timer:");
-  StdoutToAliInfo(timerSt12.Print(););
-  AliInfo("St345 timer:");
-  StdoutToAliInfo(timerSt345.Print(););
-  
-  return hv;
+  return status;
 }
 
 //_____________________________________________________________________________
 }
 
 //_____________________________________________________________________________
-AliMUONV2DStore
-AliMUONPadStatusMaker::MakePedestalStatus(const AliMUONV2DStore& pedValues) const
+AliMUONVCalibParam
+AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
 {
 {
-  /// Assign a pedestal status to each pad
+  /// Get the neighbours parameters for a given manu
+  AliMUONVStore* neighbourStore = fCalibrationData.Neighbours();
+  return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
+}
+
+//_____________________________________________________________________________
+AliMUONVStore* 
+AliMUONPadStatusMaker::NeighboursStore() const
+{
+  /// Return the store containing all the neighbours
+  return fCalibrationData.Neighbours();
+}
+
+//_____________________________________________________________________________
+AliMUONVCalibParam*
+AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
+{
+  /// Compute the status of a given manu, using all available information,
+  /// i.e. pedestals, gains, and HV
   
   
-  TStopwatch timer;
+//  AliCodeTimerAuto("")
   
   
-  timer.Start(kTRUE);
+//  AliCodeTimerStart("Param creation");
+  AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
+  fStatus->Add(param);
+//  AliCodeTimerStop("Param creation");
   
   
-  AliMUONV2DStore* pedStatuses = new AliMUON2DMap(kTRUE);
+//  AliCodeTimerStart("FindObject");
+  AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
+
+  AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
+//  AliCodeTimerStop("FindObject");
   
   
-  AliMUONVDataIterator* it = pedValues.Iterator();
-  AliMUONObjectPair* pair;
-  Int_t nofManus(0);
+  Int_t hvStatus = HVStatus(detElemId,manuId);
+
+//  AliCodeTimerStart("Loop");
   
   
-  while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
+  for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
   {
   {
-    AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
-    Int_t detElemId = ip->GetFirst();
-    Int_t manuId = ip->GetSecond();
-    AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(pair->Second());
-    ++nofManus;
-    for ( Int_t manuChannel = 0; manuChannel < pedestals->Size(); ++manuChannel )
+    Int_t pedStatus(0);
+    
+    if (pedestals) 
     {
     {
-      Int_t status(0);
-      if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
-      {
-        Float_t pedMean = pedestals->ValueAsFloat(manuChannel,0);
-        Float_t pedSigma = pedestals->ValueAsFloat(manuChannel,1);
-        if ( pedMean < fPedMeanLimits.X() ) status |= kPedMeanTooLow;
-        if ( pedMean > fPedMeanLimits.Y() ) status |= kPedMeanTooHigh;
-        if ( pedSigma < fPedSigmaLimits.X() ) status |= kPedSigmaTooLow;
-        if ( pedSigma > fPedSigmaLimits.Y() ) status |= kPedSigmaTooHigh;
-        if ( pedMean == 0 ) status |= kPedMeanZero;
-        
-        AliMUONVCalibParam* vStatus = 
-          static_cast<AliMUONVCalibParam*>(pedStatuses->Get(detElemId,manuId));
-        if ( !vStatus ) 
-        {
-          vStatus = new AliMUONCalibParam1I(64,0);
-          pedStatuses->Set(detElemId,manuId,vStatus,false);
-        }
-        vStatus->SetValueAsInt(manuChannel,0,status);
-      }
+      Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
+      Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
+      if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
+      else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
+      if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
+      else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
+      if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
     }
     }
+    else
+    {
+      pedStatus = kPedMissing;
+    }
+    
+    Int_t gainStatus(0);
+  
+    if ( gains ) 
+    {
+      Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
+      Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
+      Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
+  
+      if ( a0 < fGainA0Limits.X() ) gainStatus |= kGainA0TooLow;
+      else if ( a0 > fGainA0Limits.Y() ) gainStatus |= kGainA0TooHigh;
+      if ( a1 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
+      else if ( a1 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
+      if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
+      else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
+    }
+    else
+    {
+      gainStatus = kGainMissing;
+    }
+        
+    Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus);
+      
+    param->SetValueAsIntFast(manuChannel,0,status);
   }
   
   }
   
-  AliInfo(Form("%d manus checked in :",nofManus));
-  StdoutToAliInfo(timer.Print(););
-  return pedStatuses;  
+//  AliCodeTimerStop("Loop");
+  
+  return param;
 }
 
 //_____________________________________________________________________________
 }
 
 //_____________________________________________________________________________
-AliMUONV2DStore
-AliMUONPadStatusMaker::MakeStatus() const
+AliMUONVCalibParam
+AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
 {
 {
-  /// Read ped, gains and hv values from CDB, apply some Q&A and produces
-  /// a combined status for each pad.
-
-  TMap* hvValues = fCalibrationData.HV();
+  /// Get the status for a given channel
   
   
-  if (!hvValues)
+  AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
+  if (!param)
   {
   {
-    AliError("Could not get HV values from CDB");
-    return 0x0;
+    // not already there, so compute it now
+    AliCodeTimerAuto("ComputeStatus");
+    param = ComputeStatus(detElemId,manuId);
   }
   }
-  
-  AliMUONV2DStore* pedValues = fCalibrationData.Pedestals();
-
-  if (!pedValues)
-  {
-    AliError("Could not get pedestals values from CDB");
-    return 0x0;
-
-  }
-  
-//  AliMUONV2DStore* gainValues = fCalibrationData.Gains();
-    
-  AliMUONV2DStore* hvStatus = MakeHVStatus(*hvValues);
-  AliMUONV2DStore* pedStatus = MakePedestalStatus(*pedValues);
-  
-  AliMUONV2DStore* status = Combine(*hvStatus,*pedStatus,8);
-  
-  delete hvStatus;
-  delete pedStatus;
-  
-  return status;
+  return param;
 }
 
 //_____________________________________________________________________________
 }
 
 //_____________________________________________________________________________
-void
-AliMUONPadStatusMaker::SetStatusSt12(AliMUONV2DStore& hvStatus,
-                                     Int_t detElemId, 
-                                     Int_t isector,
-                                     Int_t status) const
+Int_t 
+AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
 {
 {
-  /// Flag all pads of detElemId (for St12) as bad.
-  
-  // FIXME: need a way to iterator on pads over a given HV sector for St12... 
-  // we currently suppose that one sector is about a third of the chamber...
-  // FIXME !! This has to be checked very carefully...
+  /// Get the status for a given channel
   
   
-  const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
-  
-  for ( Int_t icathode = 0; icathode < 2; ++icathode )
+  AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
+  if (!param)
   {
   {
-    const AliMpSectorSegmentation* seg = 
-    static_cast<const AliMpSectorSegmentation*>(AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
-    const AliMpSector* sector = seg->GetSector();
-    AliMpMotifMap* mMap = sector->GetMotifMap();
-    TArrayI a;
-    
-    mMap->GetAllMotifPositionsIDs(a);
-    
-    TVector2 dim = seg->Dimensions();
-    Double_t x = dim.X()*2;
-    Double_t xmin = isector*x/3.0;
-    Double_t xmax = xmin + x/3.0;   
-    
-    for ( Int_t i = 0; i < a.GetSize(); ++i ) 
-    {
-      AliMpMotifPosition* pos = mMap->FindMotifPosition(a[i]);
-      Int_t manuId = pos->GetID();
-      TVector2 position = pos->Position();
-      if ( position.X() >= xmin && position.X() <= xmax) 
-      {
-        AliMUONVCalibParam* dead =
-        static_cast<AliMUONVCalibParam*>(hvStatus.Get(detElemId,manuId));
-        if (!dead)
-        {
-          dead = new AliMUONCalibParam1I(64,status);
-          hvStatus.Set(detElemId,manuId,dead,false);
-        }        
-        else
-        {
-          // FIXME: this should really not happen, if we'd know really the
-          // relationship between manuId and HV sector...
-          // For the time being, let's leave it like that, for testing
-          // purposes only. For production, this will have to be fixed.
-          AliWarning("Please fixme.");
-        }
-      }
-    }
-  }  
+    // not already there, so compute it now
+    param = ComputeStatus(detElemId,manuId);
+  }
+  return param->ValueAsInt(manuChannel,0);
 }
 
 //_____________________________________________________________________________
 void
 }
 
 //_____________________________________________________________________________
 void
-AliMUONPadStatusMaker::SetStatusSt345(AliMUONV2DStore& hvStatus,
-                                      Int_t detElemId, Int_t pcbIndex,
-                                      Int_t status) const
+AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
 {
 {
-  /// Flag all pads of pcbIndex-th PCB of detElemId (for St345) as bad.
+  /// Assign status to all manus in a given HV "zone" (defined by index, meaning
+  /// is different thing from St12 and St345)
+  
+  AliCodeTimerAuto("")
+  
+  AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
   
   
-  const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
+  const AliMpArrayI* manus = de->ManusForHV(index);
   
   
-  for ( Int_t icathode = 0; icathode < 2; ++icathode )
+  for ( Int_t i = 0; i < manus->GetSize(); ++ i ) 
   {
   {
-    const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
-    (AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
-    const AliMpSlat* slat = seg->Slat();
-    const AliMpPCB* pcb = slat->GetPCB(pcbIndex);
-
-    for ( Int_t i = 0; i < pcb->GetSize(); ++i ) 
-    {
-      AliMpMotifPosition* pos = pcb->GetMotifPosition(i);
-      Int_t manuId = pos->GetID();
-      AliMUONVCalibParam* dead = 
-        static_cast<AliMUONVCalibParam*>(hvStatus.Get(detElemId,manuId));
-      if (dead)
-      {
-        AliError(Form("dead is not null as expected from DE %d manuId %d",
-                      detElemId,manuId));
-      }
-      if (!dead)
-      {
-        dead = new AliMUONCalibParam1I(64,status);
-        hvStatus.Set(detElemId,manuId,dead,false);
-      }
-    }    
+    Int_t manuId = manus->GetValue(i);
+    fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);
   }
 }
   }
 }
-
-
-