]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONCalibrationData.cxx
A few fixes
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibrationData.cxx
index d3eb1ec0cb5bf7c77725e876552c89c685b35ab7..1ae8717b17eff06ab22443e1a46ef3e8554f02ec 100644 (file)
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
 #include "AliCodeTimer.h"
+#include "AliDCSValue.h"
 #include "AliLog.h"
+#include "AliMpDCSNamer.h"
+#include "AliMUONConstants.h"
+#include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
 #include "AliMUONRejectList.h"
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMUONTriggerLut.h"
+#include "AliMUONVCalibParam.h"
 #include "AliMUONVStore.h"
 #include "AliMUONVStore.h"
-#include "AliMUONVCalibParam.h"
-#include "AliMUONGlobalCrateConfig.h"
-#include "AliMUONRegionalTriggerConfig.h"
 
 #include <Riostream.h>
 #include <TClass.h>
@@ -54,8 +57,8 @@
 ClassImp(AliMUONCalibrationData)
 /// \endcond
 
-AliMUONVStore* AliMUONCalibrationData::fBypassPedestals(0x0);
-AliMUONVStore* AliMUONCalibrationData::fBypassGains(0x0);
+AliMUONVStore* AliMUONCalibrationData::fgBypassPedestals(0x0);
+AliMUONVStore* AliMUONCalibrationData::fgBypassGains(0x0);
 
 //_____________________________________________________________________________
 AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
@@ -75,7 +78,8 @@ fTriggerEfficiency(0x0),
 fCapacitances(0x0),
 fNeighbours(0x0),
 fOccupancyMap(0x0),
-fRejectList(0x0)
+fRejectList(0x0),
+fConfig(0x0)
 {
 /// Default ctor.
 
@@ -100,15 +104,16 @@ fRejectList(0x0)
     TriggerEfficiency();
     Capacitances();
     Neighbours();
+    Config();
   }
 }
 
 //_____________________________________________________________________________
 AliMUONCalibrationData::~AliMUONCalibrationData()
 {
-  /// Destructor. Note that we're the owner of our pointers.
-  //PH The owner of the objects is CDB, do not delete them!
-  //  Reset();
+  /// Destructor. Note that we're the owner of our pointers if the OCDB cache
+  /// is not set. Otherwise the cache is supposed to take care of them...
+  if (!(AliCDBManager::Instance()->GetCacheFlag())) Reset();
 }
 
 //_____________________________________________________________________________
@@ -151,13 +156,168 @@ AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* s
 }
 
 
+//______________________________________________________________________________
+void AliMUONCalibrationData::PatchHVValues(TObjArray& values,
+                                           Int_t& nbelowready,
+                                           Int_t& noff,
+                                           Int_t& ntrips,
+                                           Int_t& neor,
+                                           TString* msg)
+{
+  /// We do here a little bit of massaging of the HV values, if needed.
+  ///
+  /// The main point is to "gather" the values near the end of the run (the last XX seconds)
+  /// to avoid the ramp-down before end-of-run syndrom...
+  ///
+  /// The rest is more of a debug/expert tool to have closer look at trends
+  ///
+  
+  Double_t HVBEAMTUNING(1300); 
+  
+  Bool_t eorProblem(kFALSE);
+  
+  UInt_t mergeDelay(300); // in seconds
+  
+  // First start by removing values within the last mergeDelay seconds, keeping only
+  // the last one
+  
+  AliDCSValue* last = static_cast<AliDCSValue*>(values.At(values.GetLast()));
+  
+  Int_t* toberemoved = new Int_t[values.GetLast()+1];
+  
+  memset(toberemoved,0,(values.GetLast()+1)*sizeof(Int_t));
+  
+  Int_t ntoberemoved(0);
+  
+  for ( Int_t i = values.GetLast()-1; i > 0; --i ) 
+  {
+    AliDCSValue* val = static_cast<AliDCSValue*>(values.At(i));
+    
+    if ( last->GetTimeStamp() - val->GetTimeStamp() < mergeDelay )
+    {
+      toberemoved[i]=1;
+      ++ntoberemoved;
+    }
+  }
+  
+  if (ntoberemoved)
+  {
+    // ok, we have some values within the same mergeDelay seconds
+    // we'll "merge" them by taking the last one, except if
+    // the last one is below HVBEAMTUNING, in which case we
+    // remove that one too (meaning the ramp-down was requesting
+    // before the end-of-run)
+    
+    if ( last->GetFloat() < HVBEAMTUNING ) 
+    {
+      eorProblem=kTRUE;
+      if (msg) *msg = "ERROR RAMP-DOWN BEFORE EOR";
+      toberemoved[values.GetLast()]=1;
+    }
+    
+    for ( Int_t i = 0; i <= values.GetLast(); ++i ) 
+    {
+      if ( toberemoved[i] ) values.RemoveAt(i);
+    }
+    
+    values.Compress();
+    
+  }
+  
+  delete[] toberemoved;
+  
+  if (eorProblem)
+  {
+    ++neor;
+    return;
+  }
+  
+  // now for the rest of the diagnosis
+  
+  Int_t ntmpoff(0);
+  Int_t ntmpready(0);
+  
+  for ( Int_t i = 0; i <= values.GetLast(); ++i ) 
+  {
+    AliDCSValue* val = static_cast<AliDCSValue*>(values.At(i));
+    
+    if ( val->GetFloat() < AliMpDCSNamer::TrackerHVOFF() ) 
+    {
+      ++ntmpoff;
+    }
+    else if ( val->GetFloat() < HVBEAMTUNING )
+    {
+      ++ntmpready;
+    }
+  }
+  
+  if ( ntmpoff )
+  {
+    if ( ntmpoff == values.GetLast()+1 ) 
+    {
+      if (msg) *msg = "ERROR HV OFF";
+      ++noff;
+    }
+    else
+    {
+      if (msg) *msg = "ERROR TRIP";
+      ++ntrips;    
+    }
+  }
+  
+  if ( ntmpready == values.GetLast()+1 ) 
+  {
+    if (msg) *msg = "ERROR BELOW READY";    
+  }      
+  
+  if (ntmpready) ++nbelowready;
+}
 
 //_____________________________________________________________________________
 TMap*
-AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity)
+AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity, Bool_t patched)
 {
   /// Create a new HV map from the OCDB for a given run
-  return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
+  TMap* hvMap = dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
+  if (patched)
+  {
+    TIter next(hvMap);
+    TObjString* hvChannelName;
+    
+    while ( ( hvChannelName = static_cast<TObjString*>(next()) ) )
+    {
+      TString name(hvChannelName->String());
+      
+      if ( name.Contains("sw") ) continue; // skip switches
+      
+      TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(name.Data()));
+      TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
+      if (!values)
+      {
+        AliErrorClass(Form("Could not get values for alias %s",name.Data()));
+      }
+      else
+      {
+        int nbelowready(0);
+        int noff(0);
+        int ntrips(0);
+        int neor(0);
+        
+        PatchHVValues(*values,nbelowready,noff,ntrips,neor,0x0);
+        if (neor)
+        {
+          nbelowready=noff=ntrips=neor=0;
+          PatchHVValues(*values,nbelowready,noff,ntrips,neor,0x0);
+          if (neor)
+          {
+            AliErrorClass("neor is not null after PatchHVValue ! This is serious !");
+          }
+        }
+      }
+    }
+    
+  }
+  return hvMap;
 }
 
 //_____________________________________________________________________________
@@ -192,7 +352,7 @@ AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* s
   /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
   /// and return the corresponding TObject.
   
-  AliCodeTimerAutoClass(Form("%d : %s",runNumber,path));
+  AliCodeTimerAutoClass(Form("%d : %s",runNumber,path),0);
   
   AliCDBManager* man = AliCDBManager::Instance();
   
@@ -203,8 +363,11 @@ AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* s
                if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
                
     TObject* object = entry->GetObject();
-    entry->SetOwner(kFALSE);
-    if (!(man->GetCacheFlag())) delete entry;
+    if (!(man->GetCacheFlag()))
+    {
+      entry->SetOwner(kFALSE);
+      delete entry;      
+    }
     return object;
   }
        else
@@ -214,7 +377,7 @@ AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* s
        
   {
     
-  AliCodeTimerAutoClass(Form("Failed to get %s for run %d",path,runNumber));
+    AliCodeTimerAutoClass(Form("Failed to get %s for run %d",path,runNumber),1);
 
   }
   
@@ -245,6 +408,14 @@ AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
 }
 
+//_____________________________________________________________________________
+AliMUONVStore*
+AliMUONCalibrationData::CreateConfig(Int_t runNumber, Int_t* startOfValidity)
+{
+  /// Create a new config store from the OCDB for a given run
+  return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Config",startOfValidity));
+}
+
 
 //_____________________________________________________________________________
 AliMUONRegionalTriggerConfig*
@@ -278,7 +449,7 @@ AliMUONVStore*
 AliMUONCalibrationData::Gains() const
 {
   /// Create (if needed) and return the internal store for gains.
-  if (fBypassGains) return fBypassGains;
+  if (fgBypassGains) return fgBypassGains;
   
   if (!fGains)
   {
@@ -320,13 +491,13 @@ AliMUONCalibrationData::GlobalTriggerCrateConfig() const
 
 //_____________________________________________________________________________
 TMap*
-AliMUONCalibrationData::HV() const
+AliMUONCalibrationData::HV(Bool_t patched) const
 {
   /// Return the calibration for a given (detElemId, manuId) pair
   
   if (!fHV)
   {
-    fHV = CreateHV(fRunNumber);
+    fHV = CreateHV(fRunNumber,0,patched);
   }
   return fHV;
 }
@@ -409,8 +580,8 @@ void
 AliMUONCalibrationData::BypassStores(AliMUONVStore* ped, AliMUONVStore* gain)
 {
   /// Force the use of those pedestals and gains
-  fBypassPedestals = ped;
-  fBypassGains = gain;
+  fgBypassPedestals = ped;
+  fgBypassGains = gain;
   
 }
 
@@ -420,7 +591,7 @@ AliMUONCalibrationData::Pedestals() const
 {
   /// Return pedestals
   
-  if (fBypassPedestals) return fBypassPedestals;
+  if (fgBypassPedestals) return fgBypassPedestals;
   
   if (!fPedestals)
   {
@@ -429,6 +600,19 @@ AliMUONCalibrationData::Pedestals() const
   return fPedestals;
 }
 
+//_____________________________________________________________________________
+AliMUONVStore*
+AliMUONCalibrationData::Config() const
+{
+  /// Return config
+  
+  if (!fConfig)
+  {
+    fConfig = CreateConfig(fRunNumber);
+  }
+  return fConfig;
+}
+
 //_____________________________________________________________________________
 AliMUONVCalibParam*
 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
@@ -455,6 +639,7 @@ AliMUONCalibrationData::Print(Option_t*) const
   cout << "RunNumber " << RunNumber()
   << " fGains=" << fGains
   << " fPedestals=" << fPedestals
+  << " fConfig=" << fConfig
   << " fHV=" << fHV
   << " fTriggerDCS=" << fTriggerDCS
   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
@@ -512,6 +697,10 @@ AliMUONCalibrationData::Reset()
 {
 /// Reset all data
 
+  AliCodeTimerAuto("",0);
+  
+  delete fConfig;
+  fConfig = 0x0;
   delete fPedestals;
   fPedestals = 0x0;
   delete fGains;
@@ -615,6 +804,15 @@ AliMUONCalibrationData::Check(Int_t runNumber)
   {
     AliInfoClass("Pedestals read OK");
   }
+
+  if ( ! CreateConfig(runNumber) )
+  {
+    AliErrorClass("Could not read config");
+  }
+  else
+  {
+    AliInfoClass("Config read OK");
+  }
   
   if ( ! CreateRegionalTriggerConfig(runNumber) )
   {