]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPedestalSubprocessor.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestalSubprocessor.cxx
index 056168890f5378b61f084d660aec26957cc01e60..4ac64a9d394f6d3c26a2a49f361e7de630060bd0 100644 (file)
@@ -18,6 +18,8 @@
 #include "AliMUONPedestalSubprocessor.h"
 
 #include "AliCDBMetaData.h"
+#include "AliCDBEntry.h"
+#include "AliDAQ.h"
 #include "AliLog.h"
 #include "AliMUON2DMap.h"
 #include "AliMUON2DStoreValidator.h"
@@ -57,7 +59,8 @@ AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* ma
                        "Upload MUON Tracker pedestals to OCDB"),
 fPedestals(0x0),
 fConfig(0x0),
-fConfigChanged(kFALSE)
+fConfigChanged(kFALSE),
+fTooFewEvents(kFALSE)
 {
   /// default ctor
 }
@@ -70,6 +73,51 @@ AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
   delete fConfig;
 }
 
+//_____________________________________________________________________________
+Bool_t
+AliMUONPedestalSubprocessor::HasConfigChanged(const AliMUONVStore& newConfig) const
+{
+  /// Check whether the config changed. 
+  /// Any error will return kTRUE to trig a config upload (safer way).
+  
+  AliCDBEntry* entry = Master()->GetFromOCDB("Calib","Config");
+  if (!entry)
+  {
+    AliError("Could not get MUON/Calib/Config entry for current run ! That's not OK !");
+    return kTRUE;
+  }
+  AliMUONVStore* oldConfig = dynamic_cast<AliMUONVStore*>(entry->GetObject());
+  if (!oldConfig)
+  {
+    AliError("Could not get MUON/Calib/Config object for current run (wrong type ?) ! That's not OK !");
+    return kTRUE;
+  }
+  
+  if ( oldConfig->GetSize() != newConfig.GetSize() ) 
+  {
+    return kTRUE;
+  }
+  
+  TIter next(oldConfig->CreateIterator());
+  AliMUONVCalibParam* old;
+  
+  while ( ( old = static_cast<AliMUONVCalibParam*>(next()) ) )
+  {
+    Int_t detElemId = old->ID0();
+    Int_t manuId = old->ID1();
+    
+    if ( ! newConfig.FindObject(detElemId,manuId) )
+    {
+      // not found in new. Configurations are different. Return right now.
+      return kTRUE;
+    }
+  }
+  
+  // all tests OK. Configuration has not changed.
+  return kFALSE;
+}
+
+
 //_____________________________________________________________________________
 Bool_t 
 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
@@ -85,7 +133,9 @@ AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endT
   delete fConfig;
   fConfig = new AliMUON2DMap(kTRUE);
   
-  Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
+  fTooFewEvents = kFALSE;
+  
+  Master()->Log(Form("Reading pedestal files for Run %d startTime %u endTime %u",
                      run,startTime,endTime));
   
   TList* sources = Master()->GetFileSources(kSystem,kId);
@@ -110,10 +160,25 @@ AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endT
   if (!n)
   {
     Master()->Log("Failed to read any pedestals");
+
     delete fPedestals;
     fPedestals = 0;
     delete fConfig;
     fConfig = 0;
+
+    // OK, we did not get our pedestals. Check if the ped run itself
+    // was bad, i.e. too few events
+    TString nevents(Master()->GetRunParameter("totalEvents"));
+    
+    if ( nevents.Atoi() < 50 ) 
+    {
+      Master()->Log(Form("The run had only %d events, so the failure to read pedestals is normal",nevents.Atoi()));
+      // too few events, failure is normal, returns OK.
+      fTooFewEvents = kTRUE;
+      return kTRUE;
+    }
+    
+    // no ped, but run looks clean, that's an error
     return kFALSE;
   }
   
@@ -124,8 +189,6 @@ AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endT
   Int_t nconf(0);
   Int_t nconfFiles(0);
   
-  fConfigChanged = kFALSE;
-  
   while ( ( o = static_cast<TObjString*>(nextConf()) ) )
   {
     TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName()));
@@ -149,6 +212,8 @@ AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endT
     return kFALSE;
   }
   
+  fConfigChanged = HasConfigChanged(*fConfig);
+  
   return kTRUE;
 }
 
@@ -160,9 +225,18 @@ AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
   
   if (!fPedestals || !fConfig) 
   {
-    // this is the only reason to fail for the moment : getting no pedestal or no config
-    // at all.
-    return 1;
+    if ( fTooFewEvents ) 
+    {
+      // ped run was too short, no reason to complain about that, it's "normal" 
+      // not to have pedestals in that case.
+      return 0;
+    }
+    else
+    {
+      // this is the only reason to fail for the moment : getting no pedestal or no config
+      // at all.
+      return 1;
+    }
   }
     
   AliMUON2DStoreValidator validator;
@@ -247,8 +321,6 @@ AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename)
   /// Read the configuration from an ASCII file.                              
   /// Format of that file is one line per manu :                              
   /// BUS_PATCH MANU_ADDR
-  /// And the first line contains "unchanged" if the configuration is the same
-  /// as before.
   /// Return kFALSE if reading was not successfull.                           
   ///
   
@@ -256,7 +328,7 @@ AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename)
   
   Master()->Log(Form("Reading %s",sFilename.Data()));
   
-  Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig,fConfigChanged);
+  Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig);
   
   switch (n)
   {