]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Attempt to make the HV filtering more robust
authorlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 1 Apr 2011 16:09:26 +0000 (16:09 +0000)
committerlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 1 Apr 2011 16:09:26 +0000 (16:09 +0000)
MUON/AliMUONCDB.cxx
MUON/AliMUONCDB.h
MUON/AliMUONCalibrationData.cxx
MUON/AliMUONCalibrationData.h
MUON/AliMUONPadStatusMaker.h

index 0113ab7a62c214dfeec85a6dd7002b13d16fcd45..5e9082ea9bc44f899285bba005fdb5d9404ac89b 100644 (file)
@@ -43,6 +43,7 @@
 #include "AliMUONCalibrationData.h"
 #include "AliMUONConstants.h"
 #include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONLogger.h"
 #include "AliMUONPadStatusMaker.h"
 #include "AliMUONPadStatusMapMaker.h"
 #include "AliMUONRecoParam.h"
@@ -129,6 +130,8 @@ void getBoundaries(const AliMUONVStore& store, Int_t dim,
     const AliMpVSegmentation* seg = 
       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
         
+    if (!seg) continue;
+    
     for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
     {
       AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
@@ -407,14 +410,14 @@ AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
 }
 
 //_____________________________________________________________________________
-void 
+TH1** 
 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
 {
   /// Make histograms of each dimension of the AliMUONVCalibParam
   /// contained inside store.
   /// It produces histograms named name_0, name_1, etc...
   
-  if (!AliMUONCDB::CheckMapping(kTRUE)) return;
+  if (!AliMUONCDB::CheckMapping(kTRUE)) return 0x0;
   
   TIter next(store.CreateIterator());
   AliMUONVCalibParam* param;
@@ -452,6 +455,8 @@ AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
     const AliMpVSegmentation* seg = 
       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
     
+    if (!seg) continue;
+    
     for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
     {
       AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
@@ -475,6 +480,8 @@ AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
   AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
   
   delete[] nPerStation;
+  
+  return h;
 }
 
 //_____________________________________________________________________________
@@ -1735,6 +1742,13 @@ void AliMUONCDB::ShowFaultyBusPatches(const char* runlist, double occLimit,
     
     AliCDBEntry* e = man->Get("MUON/Calib/OccupancyMap",runNumber);
     
+    if (!e)
+    {
+      AliErrorGeneral("AliMUONCDB::ShowFaultyBusPatches",
+                      Form("Could not get OccupancyMap for run %09d",runNumber));
+      continue;
+    }
+    
     AliMUONVStore* occmap = static_cast<AliMUONVStore*>(e->GetObject());
     
     AliMUONTrackerData td("occ","occ",*occmap);
@@ -1810,3 +1824,126 @@ void AliMUONCDB::ShowFaultyBusPatches(const char* runlist, double occLimit,
   
 }
 
+//______________________________________________________________________________
+void AliMUONCDB::CheckHV(Int_t runNumber, Int_t verbose)
+{
+  /// Check the HV values in OCDB for a given run
+  
+  TList messages;
+  messages.SetOwner(kTRUE);
+  
+  Bool_t patched(kTRUE);
+  
+  if (!AliCDBManager::Instance()->IsDefaultStorageSet())
+  {
+    AliCDBManager::Instance()->SetDefaultStorage("raw://");
+  }
+
+  AliCDBManager::Instance()->SetRun(runNumber);
+
+  LoadMapping();
+  
+  AliMUONCalibrationData::CreateHV(runNumber,0,patched,&messages);
+  
+  AliMUONCalibrationData cd(runNumber,true);
+  
+  AliMUONPadStatusMaker statusMaker(cd);
+  
+  AliMUONRecoParam* rp = AliMUONCDB::LoadRecoParam();
+  
+  if (!rp)
+  {
+    AliErrorGeneral("AliMUONCDB::CheckHV","Could not get RecoParam !!!");
+    return;
+  }
+  
+  statusMaker.SetLimits(*rp);
+  
+  TIter next(&messages);
+  TObjString* s;
+  AliMpDCSNamer hvNamer("TRACKER");
+  AliMUONLogger log;
+  
+  while ( ( s = static_cast<TObjString*>(next()) ) )
+  {
+    TObjArray* a = s->String().Tokenize(":");
+    
+    TString name(static_cast<TObjString*>(a->At(0))->String());
+    
+    if ( name.Contains("sw") || name.Contains("SUMMARY") ) continue;
+    
+    Int_t index = hvNamer.DCSIndexFromDCSAlias(name.Data());
+    
+    Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
+    
+    AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
+    
+    if (!de)
+    {
+      AliErrorGeneral("AliMUONCDB::CheckHV",Form("Could not get detElemId from dcsAlias %s",name.Data()));
+      continue;
+    }
+    
+    Int_t manuId;
+    
+    if ( index >= 0 )
+    {
+      const AliMpArrayI* array = de->ManusForHV(index);
+      manuId = array->GetValue(0);
+    }
+    else
+      
+    {
+      AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(de->GetBusPatchId(0));
+      
+      manuId = bp->GetManuId(0);
+    }
+    
+    Int_t status = statusMaker.HVStatus(detElemId,manuId);
+    
+    log.Log(AliMUONPadStatusMaker::AsString(status).Data());
+    
+    s->String() += Form(" (DE %4d) ",detElemId);
+    s->String() += AliMUONPadStatusMaker::AsString(status).Data();
+    
+    delete a;
+  }    
+  
+  TIter nextMessage(&messages);
+  TObjString* msg;
+  
+  while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
+  {
+    if ( verbose > 0 || msg->String().Contains("SUMMARY") )
+    {
+      AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d HVchannel %s",runNumber,msg->String().Data()));
+    }
+  }
+  
+  TString lmsg;
+  Int_t occurance;
+  TString totalLog;
+  
+  while (log.Next(lmsg,occurance))
+  {
+    totalLog += Form("%s(%d)",lmsg.Data(),occurance);
+    totalLog += " | ";
+  }
+
+  AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d %s",runNumber,totalLog.Data()));
+
+  // one last loop to get the list of problematic HV channels
+  nextMessage.Reset();
+  
+  while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
+  {
+    if ( msg->String().Contains("HV ") )
+    {
+      AliInfoGeneral("AliMUONCDB::CheckHV",Form("     Problem at %s",msg->String().Data()));      
+    }
+  }
+   
+  AliCDBManager::Instance()->ClearCache();
+}
+
+
index 73145d9bcc130bc8a6f2fece00b70e130afe766a..2e54fb758f7078c743cd595091eabdd21e7fff0d 100644 (file)
@@ -25,12 +25,15 @@ class AliMUONRegionalTriggerConfig;
 class AliMUONGlobalCrateConfig;
 class AliMUONRejectList;
 class AliMUONRecoParam;
+class TH1;
 
 namespace AliMUONCDB
 {
   Bool_t CheckOCDB(Bool_t pathOnly = kFALSE);
   Bool_t CheckMapping(Bool_t segmentationOnly = kFALSE);
   
+  void CheckHV(Int_t runNumber, Int_t verbose=0);
+
   Bool_t LoadField();
   Bool_t LoadMapping(Bool_t segmentationOnly = kFALSE);
   AliMUONRecoParam* LoadRecoParam();
@@ -56,7 +59,7 @@ namespace AliMUONCDB
 
   AliMUONVStore* Diff(AliMUONVStore& store1, AliMUONVStore& store2, const char* opt="abs");
   
-  void Plot(const AliMUONVStore& store, const char* name, Int_t nbins=512);
+  TH1** Plot(const AliMUONVStore& store, const char* name, Int_t nbins=512);
 
   void ReadIntegers(const char* filename, std::vector<int>& integers);
 
index 1ae8717b17eff06ab22443e1a46ef3e8554f02ec..3f63f3231aa130f1a8a8f99caee819c2813326ab 100644 (file)
@@ -23,6 +23,7 @@
 #include "AliDCSValue.h"
 #include "AliLog.h"
 #include "AliMpDCSNamer.h"
+#include "AliMpIntPair.h"
 #include "AliMUONConstants.h"
 #include "AliMUONGlobalCrateConfig.h"
 #include "AliMUONRegionalTriggerConfig.h"
@@ -36,6 +37,7 @@
 #include <Riostream.h>
 #include <TClass.h>
 #include <TMap.h>
+#include <TMath.h>
 
 //-----------------------------------------------------------------------------
 /// \class AliMUONCalibrationData
@@ -60,6 +62,17 @@ ClassImp(AliMUONCalibrationData)
 AliMUONVStore* AliMUONCalibrationData::fgBypassPedestals(0x0);
 AliMUONVStore* AliMUONCalibrationData::fgBypassGains(0x0);
 
+namespace  
+{
+  void MarkForDeletion(Int_t* indices, Int_t first, Int_t last)
+  {
+    for ( Int_t i = first; i <= last; ++i ) 
+    {
+      indices[i] = 1;
+    }
+  }
+}
+
 //_____________________________________________________________________________
 AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
                                                Bool_t deferredInitialization) 
@@ -157,128 +170,405 @@ 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)
+Bool_t AliMUONCalibrationData::CheckHVGroup(TObjArray& values, Int_t first, Int_t last, Double_t& value, Int_t& slope, 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); 
+  // Get the HV of the values between first and last indices
+  // return the HV slope  (in Volt per second) and a message
+  // Return kFALSE if we must discard the group
+  //
   
-  Bool_t eorProblem(kFALSE);
+  if (msg) *msg="";
   
-  UInt_t mergeDelay(300); // in seconds
+  if ( last < first ) return kFALSE;
+  if ( last - first < 2 ) return kFALSE;
   
-  // First start by removing values within the last mergeDelay seconds, keeping only
-  // the last one
+  Double_t a(0.0);
+  Double_t b(0.0);
+
+  Float_t HVSAME(1); // 1 volts
+
+  AliDCSValue* vfirst = static_cast<AliDCSValue*>(values.UncheckedAt(first));
+  AliDCSValue* vlast = static_cast<AliDCSValue*>(values.UncheckedAt(last));
+
+  Int_t deltaHV = TMath::Nint(TMath::Abs(vfirst->GetFloat()-vlast->GetFloat()));
   
-  AliDCSValue* last = static_cast<AliDCSValue*>(values.At(values.GetLast()));
+  if ( deltaHV < HVSAME ) return kFALSE;
+
+  for ( Int_t i = first; i <= last; ++i )
+  {
+    AliDCSValue* v = static_cast<AliDCSValue*>(values.UncheckedAt(i));
+
+    Double_t y = v->GetFloat() - vfirst->GetFloat();
+    Double_t x = v->GetTimeStamp() - vfirst->GetTimeStamp();
   
-  Int_t* toberemoved = new Int_t[values.GetLast()+1];
+    a += x*y;
+    b += x*x;
+  }
   
-  memset(toberemoved,0,(values.GetLast()+1)*sizeof(Int_t));
+  value = a/b;
+  slope = value > 0 ? 1 : -1;
+  value = TMath::Abs(value);
   
-  Int_t ntoberemoved(0);
+  UInt_t deltaTime = vlast->GetTimeStamp() - vfirst->GetTimeStamp();
   
-  for ( Int_t i = values.GetLast()-1; i > 0; --i ) 
+  if (msg)
   {
-    AliDCSValue* val = static_cast<AliDCSValue*>(values.At(i));
+    if (slope>0) (*msg) = Form("RU%d[%d:%d](%d)",TMath::Nint(value),first,last,deltaTime);
+    if (slope<0) (*msg) = Form("RD%d[%d:%d](%d)",TMath::Nint(value),first,last,deltaTime);
     
-    if ( last->GetTimeStamp() - val->GetTimeStamp() < mergeDelay )
+    if ( TMath::Nint(value) == 0 )
     {
-      toberemoved[i]=1;
-      ++ntoberemoved;
+      // this is to protect for the few cases 
+      // (see e.g. MchHvLvLeft/Chamber00Left/Quad2Sect0.actual.vMon in run 134497)
+      // where we can have *lots* of values (2483 in this example) but that
+      // are more or less constant...
+      //
+      // or simply to remove small ramps
+      //
+      slope = 0;
+      value = (vfirst->GetFloat()+vlast->GetFloat())/2.0;
+      *msg = Form("FLUCT%d[%d:%d]",TMath::Nint(value),first,last);
     }
   }
   
-  if (ntoberemoved)
+  return kTRUE;
+}
+
+//______________________________________________________________________________
+Bool_t AliMUONCalibrationData::PatchHVValues(TObjArray& values,
+                                             TString* msg)
+{
+  /// We do here a little bit of massaging of the HV values, if needed.
+  ///
+  /// The main point is to "gather" values that are within a given small amount
+  /// of time (typically 60 seconds) and infer a slope from those values
+  /// slope > 0 means it is a ramp-up, slope < 0 that's a ramp-down
+  ///
+  /// This is to avoid both the "ramp-down-before-end-of-run" and the
+  /// "ramp-up-after-start-of-run" syndroms...
+  ///
+  /// Return kFALSE is the kind of HV (trouble) case we have here
+  /// has not been identified...
+  ///
+  
+  UInt_t DELTATIME(60); // in seconds
+  Int_t IENDRU(60); // in seconds
+  
+  // Start by finding groups of values which are not separated (each) by more than
+  // deltaTime
+  
+  Bool_t gather(kFALSE);
+  Int_t ifirst(0);
+  Int_t ilast(0);
+  TObjArray groups;
+  groups.SetOwner(kTRUE);
+  
+  for ( Int_t i = values.GetLast(); i > 0; --i ) 
   {
-    // 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 ) 
+    AliDCSValue* vi = static_cast<AliDCSValue*>(values.UncheckedAt(i));
+    AliDCSValue* vj = static_cast<AliDCSValue*>(values.UncheckedAt(i-1));
+
+    if ( vi->GetTimeStamp() - vj->GetTimeStamp() < DELTATIME )
     {
-      eorProblem=kTRUE;
-      if (msg) *msg = "ERROR RAMP-DOWN BEFORE EOR";
-      toberemoved[values.GetLast()]=1;
+      if ( !gather ) 
+      {
+        gather = kTRUE;
+        ifirst = i;    
+      }
+      ilast=i;
     }
-    
-    for ( Int_t i = 0; i <= values.GetLast(); ++i ) 
+    else
     {
-      if ( toberemoved[i] ) values.RemoveAt(i);
+      if ( gather ) 
+      {
+        ilast=i;
+        
+        groups.Add(new AliMpIntPair(ilast,ifirst));
+      }
+      gather = kFALSE;
     }
-    
-    values.Compress();
-    
   }
   
-  delete[] toberemoved;
-  
-  if (eorProblem)
+  if (gather)
   {
-    ++neor;
-    return;
+    groups.Add(new AliMpIntPair(0,ifirst));
   }
+                 
+  TIter nextGroup(&groups,kIterBackward);
+  AliMpIntPair* p;
+  TString internalMsg;
+  Int_t ngroups(0);
+
+  Int_t nRU(0);
+  Int_t nRD(0);
+  Int_t nStartRU(0);
+  Int_t nEndAndShortRU(0);
+  Int_t nEndRD(0);
+  Int_t nTripRD(0);
+  Int_t nFluct(0);
   
-  // now for the rest of the diagnosis
-  
-  Int_t ntmpoff(0);
-  Int_t ntmpready(0);
-  
-  for ( Int_t i = 0; i <= values.GetLast(); ++i ) 
+  while ( ( p = static_cast<AliMpIntPair*>(nextGroup()) ) )
   {
-    AliDCSValue* val = static_cast<AliDCSValue*>(values.At(i));
+    Double_t value;
+    Int_t slope;
     
-    if ( val->GetFloat() < AliMpDCSNamer::TrackerHVOFF() ) 
+    TString groupMsg;
+    
+    AliDebugClass(1,Form("group %d:%d",p->GetFirst(),p->GetSecond()));
+    
+    Bool_t ok = CheckHVGroup(values,p->GetFirst(),p->GetSecond(),value,slope,&groupMsg);
+    
+    if (!ok) continue;
+    
+    ++ngroups;
+    
+    if ( slope > 0 )
+    {
+      if ( p->GetFirst() == 0 ) 
+      {
+        // start with a ramp-up
+        ++nStartRU;
+      }
+      else if ( p->GetSecond() == values.GetLast() && TMath::Nint(value) < IENDRU )
+      {
+        ++nEndAndShortRU;
+      }
+      else
+      {
+        // ramp-up in the middle of nowhere...
+        ++nRU;
+      }
+    }
+    else if ( slope < 0 )
     {
-      ++ntmpoff;
+      if ( p->GetSecond() == values.GetLast() ) 
+      {
+        // end with a ramp-down
+        ++nEndRD;
+      }
+      else
+      {
+        // ramp-down in the middle of nowhere
+        ++nRD;
+      }
+
+      AliDCSValue* d = static_cast<AliDCSValue*>(values.At(p->GetSecond()));
+      
+      if ( d->GetFloat() < AliMpDCSNamer::TrackerHVOFF() )
+      {
+        ++nTripRD;
+      }
     }
-    else if ( val->GetFloat() < HVBEAMTUNING )
+    else
     {
-      ++ntmpready;
+      ++nFluct;
     }
+    
+    internalMsg += groupMsg;
+    internalMsg += " ";    
   }
   
-  if ( ntmpoff )
+  /*
+   
+   Once we have "decoded" the groups we try to find out which of 
+   the following cases we're facing :
+  
+   case A = -------- = OK(1)
+  
+   case B = ----
+                \
+                \   = OK, once we have removed the ramp-down (2)
+  
+   case C =    ----- 
+              /
+             /       = OK, once we have removed the ramp-up (3)
+  
+   case D =    ----- 
+              /     \
+             /       \ = OK, once we have removed the ramp-down (2) and the ramp-up (3)
+  
+   case E = ----
+                \
+                 \____ = TRIP = BAD (here the ramp-down slope should be bigger than in case C)
+  
+   case F = ----         
+                \      ----- = BAD (trip + ramp-up at end of run)
+                 \____/   
+  
+   case G = fluctuations (within a range defined in CheckHVGroup...)
+   
+   case H =            
+                   /
+                  /   = ramp-up right at the end-of-run = OK (4)
+            ------
+   
+   (1) OK means the group is identified correctly, still the value can be below ready...
+   (2) ramp-down values will be removed if the ramp is indeed the last values in the serie
+       i.e. it's really an end-of-run problem (otherwise it's not case B)
+   (3) ramp-up values will be removed if the ramp is indeed the first values in the serie
+       i.e. it's really a start-of-run problem (otherwise it's not case C)
+   (4) OK if short enough...
+   
+   Any other case is unknown and we'll :
+   a) return kFALSE
+   b) assume the channel is OFF.
+  
+  
+  */
+  
+  AliDebugClass(1,Form("msg=%s ngroupds=%d",internalMsg.Data(),ngroups));
+  AliDebugClass(1,Form("nRU %d nRD %d nStartRU %d nEndRD %d nTripRD %d nFluct %d",
+                       nRU,nRD,nStartRU,nEndRD,nTripRD,nFluct));
+  
+  TString hvCase("OTHER");
+  int dummy(0),a(-1),b(-1);
+  char r[80];
+  Int_t nvalues = values.GetSize();  
+  Int_t* indices = new Int_t[nvalues];
+  memset(indices,0,nvalues*sizeof(Int_t));
+         
+  AliDCSValue* vfirst = static_cast<AliDCSValue*>(values.UncheckedAt(0));
+  AliDCSValue* vlast = static_cast<AliDCSValue*>(values.UncheckedAt(values.GetLast()));
+
+  UInt_t meanTimeStamp = ( vfirst->GetTimeStamp() + vlast->GetTimeStamp() ) / 2;
+  
+  if ( ngroups == 0 ) 
   {
-    if ( ntmpoff == values.GetLast()+1 ) 
+    hvCase = "A"; 
+  }
+  else if ( nTripRD > 0 )
+  {
+    if ( nRU > 0 && nRD > 0 )
     {
-      if (msg) *msg = "ERROR HV OFF";
-      ++noff;
+      hvCase = "F";
     }
     else
     {
-      if (msg) *msg = "ERROR TRIP";
-      ++ntrips;    
+      hvCase = "E";
     }
+    internalMsg += "TRIP ";
+    MarkForDeletion(indices,0,values.GetLast());
+    values.Add(new AliDCSValue(static_cast<Float_t>(0),meanTimeStamp));
+  }
+  else if ( nStartRU > 0 && nRU == 0 && nRD == 0 && nEndRD == 0 )
+  {
+    hvCase = "C";
+    sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
+    MarkForDeletion(indices,a,b);
+  }
+  else if ( nStartRU > 0 && nEndRD > 0 && nRD == 0 && nRU == 0 )
+  {
+    hvCase = "D";
+    sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);    
+    MarkForDeletion(indices,a,b-1);
+    Int_t i = internalMsg.Index("RD",strlen("RD"),0,TString::kExact);
+    sscanf(internalMsg(i,internalMsg.Length()-i).Data(),
+           "RD%10d[%10d:%10d]%80s",&dummy,&a,&b,r);    
+    MarkForDeletion(indices,a+1,b);
+  }
+  else if ( nEndRD > 0 && nStartRU == 0 && nRU == 0 && nRD == 0 )
+  {
+    hvCase = "B";
+    Int_t i = internalMsg.Index("RD",strlen("RD"),0,TString::kExact);
+    sscanf(internalMsg(i,internalMsg.Length()-i).Data(),
+           "RD%10d[%10d:%10d]%80s",&dummy,&a,&b,r);    
+    MarkForDeletion(indices,a,b);
+  }
+  else if ( nFluct > 0 )
+  {
+    hvCase = "G";
+    TObjArray* af = internalMsg.Tokenize(" ");
+    TIter next(af);
+    TObjString* str;
+    while ( ( str = static_cast<TObjString*>(next()) ) )
+    {
+      TString s(str->String());
+      if ( s.BeginsWith("FLUCT") )
+      {
+        sscanf(s.Data(),"FLUCT%d[%d:%d]",&dummy,&a,&b);
+        MarkForDeletion(indices,a,b);
+      }
+    }
+    delete af;
+  }
+  else if ( nEndAndShortRU > 0 && nStartRU == 0 && nRU == 0 && nRD == 0 && nEndRD == 0 )
+  {
+    hvCase = "H";
+    sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
+    MarkForDeletion(indices,a,b);
+  }
+  else
+  {
+    // last chance... 
+    // here we know it's not a trip, so let's assume everything is OK
+    // if first and last value are in the same ballpark
+
+    const Double_t HVFLUCT(20); // volts
+    
+    if ( TMath::Abs(vfirst->GetFloat() - vlast->GetFloat()) < HVFLUCT )
+    {
+      hvCase = "Z";
+    }
+    MarkForDeletion(indices,1,nvalues-1);
   }
   
-  if ( ntmpready == values.GetLast()+1 ) 
+  for ( Int_t i = 0; i < nvalues; ++i ) 
   {
-    if (msg) *msg = "ERROR BELOW READY";    
-  }      
+    if ( indices[i] )
+    {
+      values.RemoveAt(i);
+    }
+  }
   
-  if (ntmpready) ++nbelowready;
+  values.Compress();
+
+  delete[] indices;
+  
+  if ( !values.GetEntries() )
+  {
+    AliErrorClass(Form("No value left after patch... Check that !!! initial # of values=%d msg=%s",
+                       nvalues,internalMsg.Data()));
+    hvCase = "OTHER";
+  }
+
+  // take the max of the remaining values
+  TIter nextA(&values);
+  AliDCSValue* val;
+  Float_t maxval(-9999);
+  
+  while ( ( val = static_cast<AliDCSValue*>(nextA()) ) )
+  {
+    if ( val->GetFloat() > maxval )
+    {
+      maxval = val->GetFloat();
+    }
+  }
+  
+  values.Clear();
+  
+  values.Add(new AliDCSValue(maxval,meanTimeStamp));
+  
+  // once the case is inferred, add a "CASE:%10d",hvCase.Data()
+  // to the msg
+  // so we can them sum up for all channels and get a summary per run...
+  
+  internalMsg += Form("CASE:%s",hvCase.Data());
+  if (msg) *msg = internalMsg.Data();
+  
+  return hvCase=="OTHER" ? kFALSE : kTRUE;
 }
 
 //_____________________________________________________________________________
 TMap*
-AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity, Bool_t patched)
+AliMUONCalibrationData::CreateHV(Int_t runNumber, 
+                                 Int_t* startOfValidity, 
+                                 Bool_t patched,
+                                 TList* messages)
 {
   /// Create a new HV map from the OCDB for a given run
   TMap* hvMap = dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
+
   if (patched)
   {
     TIter next(hvMap);
@@ -298,25 +588,62 @@ AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity, Bool_t
       }
       else
       {
-        int nbelowready(0);
-        int noff(0);
-        int ntrips(0);
-        int neor(0);
+        TString msg;
+        
+        AliDebugClass(1,Form("channel %s",name.Data()));
+        Bool_t ok = PatchHVValues(*values,&msg);
+        
+        if ( messages ) 
+        {
+          messages->Add(new TObjString(Form("%s:%s",hvChannelName->String().Data(),msg.Data())));
+        }
         
-        PatchHVValues(*values,nbelowready,noff,ntrips,neor,0x0);
-        if (neor)
+        if (!ok)
         {
-          nbelowready=noff=ntrips=neor=0;
-          PatchHVValues(*values,nbelowready,noff,ntrips,neor,0x0);
-          if (neor)
-          {
-            AliErrorClass("neor is not null after PatchHVValue ! This is serious !");
-          }
+          AliErrorClass(Form("PatchHVValue was not successfull ! This is serious ! "
+                             "You'll have to check the logic for channel %s in run %09d",
+                             name.Data(),runNumber));
         }
       }
     }
     
   }
+  
+  if ( messages ) 
+  {
+    Int_t a(0),b(0),c(0),d(0),e(0),f(0),g(0),h(0),u(0),z(0);
+    TIter next(messages);
+    TObjString* msg;
+    char hvCase;
+    
+    while ( ( msg = static_cast<TObjString*>(next()) ) )
+    {
+      Int_t i = msg->String().Index("CASE",strlen("CASE"),0,TString::kExact);
+      
+      if ( i >= 0 )
+      {
+        sscanf(msg->String()(i,msg->String().Length()-i).Data(),"CASE:%c",&hvCase);
+      }
+
+      switch (hvCase)
+      {
+        case 'A': ++a; break;
+        case 'B': ++b; break;
+        case 'C': ++c; break;
+        case 'D': ++d; break;
+        case 'E': ++e; break;
+        case 'F': ++f; break;
+        case 'G': ++g; break;
+        case 'H': ++h; break;
+        case 'Z': ++z; break;
+        default: ++u; break;
+      }
+    }
+    
+    messages->Add(new TObjString(Form("SUMMARY : # of cases A(%3d) B(%3d) C(%3d) D(%3d) E(%3d) F(%3d) G(%3d) H(%3d) Z(%3d) OTHER(%3d)",
+                                      a,b,c,d,e,f,g,h,z,u)));
+  }
+  
   return hvMap;
 }
 
@@ -352,7 +679,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),0);
+  AliCodeTimerAutoClass(Form("%09d : %s",runNumber,path),0);
   
   AliCDBManager* man = AliCDBManager::Instance();
   
@@ -377,7 +704,7 @@ AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* s
        
   {
     
-    AliCodeTimerAutoClass(Form("Failed to get %s for run %d",path,runNumber),1);
+    AliCodeTimerAutoClass(Form("Failed to get %s for run %09d",path,runNumber),1);
 
   }
   
@@ -457,7 +784,7 @@ AliMUONCalibrationData::Gains() const
   }
   return fGains;
 }
-
 //_____________________________________________________________________________
 AliMUONVCalibParam*
 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
@@ -841,5 +1168,3 @@ AliMUONCalibrationData::Check(Int_t runNumber)
     AliInfoClass("TriggerEfficiency read OK");
   }
 }
-
-
index fa3e2931437d86bb7cc478316826f9c216e61ccc..b73e3cbff87d05d61cd77c14d8ee02ed453fdb34 100644 (file)
@@ -50,7 +50,7 @@ public:
   static AliMUONGlobalCrateConfig* CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity=0);
   
   /// Create a hv map (which must be deleted) from OCDB for the given run
-  static TMap* CreateHV(Int_t runNumber, Int_t* startOfValidity=0, Bool_t patched=kTRUE);
+  static TMap* CreateHV(Int_t runNumber, Int_t* startOfValidity=0, Bool_t patched=kTRUE, TList* messages=0x0);
 
   /// Create a Trigger HV and current  map (which must be deleted) from OCDB for the given run
   static TMap* CreateTriggerDCS(Int_t runNumber, Int_t* startOfValidity=0);
@@ -141,21 +141,19 @@ public:
   static TObject* CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity=0x0);
   
   static void Check(Int_t runNumber);
-  
+
   static void BypassStores(AliMUONVStore* ped, AliMUONVStore* gain);
   
-  static void PatchHVValues(TObjArray& values,
-                            Int_t& nbelowready,
-                            Int_t& noff,
-                            Int_t& ntrips,
-                            Int_t& neor,
-                            TString* msg);
-  
 protected:
   /// Not implemented
   AliMUONCalibrationData(const AliMUONCalibrationData& other);
   /// Not implemented
   AliMUONCalibrationData& operator=(const AliMUONCalibrationData& other);
+
+  static Bool_t PatchHVValues(TObjArray& values, TString* msg=0x0);
+  
+  static Bool_t CheckHVGroup(TObjArray& values, Int_t first, Int_t last, Double_t& value,
+                             Int_t& slope, TString* msg);
   
 private:
   mutable Bool_t fIsValid; ///<  Whether we were able to correctly initialize
index 6008a6a199c90340ee5cc2b46777540c0a77ca8a..9c51c7eb124f612d4c161e93ed6b3fd69d6b8cbd 100644 (file)
@@ -111,6 +111,10 @@ public:
   
   static Float_t SwitchValue(const TObjArray& dcsArray);
   
+  Int_t HVStatus(Int_t detElemId, Int_t manuId) const;
+  
+  Int_t OccupancyStatus(Int_t detElemId, Int_t manuId) const;
+  
 private:
   /// Not implemented
   AliMUONPadStatusMaker(const AliMUONPadStatusMaker&);
@@ -136,10 +140,6 @@ private:
                        Bool_t& hvChannelON,
                        Bool_t& hvSwitchON) const;
 
-  Int_t HVStatus(Int_t detElemId, Int_t manuId) const;
-
-  Int_t OccupancyStatus(Int_t detElemId, Int_t manuId) const;
-  
   void SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const;
 
 private: