]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPedestalSubprocessor.cxx
Adding calibration library and updating the loadlib*.C macros (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestalSubprocessor.cxx
index ac2440b23148a947b7280d6894da8c5827826347..13749bb206bb43fe5fb39d94f528713c348a4012 100644 (file)
 
 // $Id$
 
-#include "AliMUONPedestalSubprocessor.h"
+#include <sstream>
+
+#include <Riostream.h>
+#include <TList.h>
+#include <TObjString.h>
+#include <TSystem.h>
 
 #include "AliCDBMetaData.h"
 #include "AliLog.h"
 #include "AliMUON2DMap.h"
-#include "AliMUON2DStoreValidator.h"
-#include "AliMUONCalibParam2F.h"
-#include "Riostream.h"
-#include "TObjString.h"
-#include "TSystem.h"
-#include <sstream>
-#include "AliMUONVDataIterator.h"
+#include "AliMUONCalibParamNF.h"
 #include "AliMUONConstants.h"
 #include "AliMUONObjectPair.h"
-#include "AliMpDDLStore.h"
+#include "AliMUONPedestalSubprocessor.h"
 #include "AliMUONPreprocessor.h"
+#include "AliMUONVDataIterator.h"
+#include "AliMpDDLStore.h"
+#include "AliMUON2DStoreValidator.h"
+#include "TObjString.h"
 
 ///
 /// \class AliMUONPedestalSubprocessor
@@ -56,13 +59,13 @@ AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* ma
                        "Upload MUON Tracker pedestals to OCDB"),
 fPedestals(0x0)
 {
-  // default ctor
+  /// default ctor
 }
 
 //_____________________________________________________________________________
 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
 {
-  // dtor
+  /// dtor
   delete fPedestals;
 }
 
@@ -78,21 +81,34 @@ AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endT
   delete fPedestals;
   fPedestals = new AliMUON2DMap(kTRUE);
   
-  AliInfo(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
-               run,startTime,endTime));
+  Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
+                     run,startTime,endTime));
   
   TList* sources = Master()->GetFileSources(kSystem,kId);
   TIter next(sources);
   TObjString* o(0x0);
+  Int_t n(0);
+  
   while ( ( o = static_cast<TObjString*>(next()) ) )
   {
     TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
-    Bool_t ok = ReadFile(fileName.Data());
+    Int_t ok = ReadFile(fileName.Data());
     if (!ok)
     {
-      AliError(Form("Could not read file %s",fileName.Data()));
+      Master()->Log(Form("Could not read file %s",fileName.Data()));
+    }
+    else
+    {
+      n += ok;
     }
   }
+  
+  if (!n)
+  {
+    Master()->Log("Failed to read any pedestals");
+    delete fPedestals;
+    fPedestals = 0;
+  }
   delete sources;
 }
 
@@ -100,57 +116,80 @@ AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endT
 UInt_t 
 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
 {
-  // Store the pedestals into the CDB
-  
-  if (!fPedestals) return 0;
+  /// Store the pedestals into the CDB
   
-  AliInfo("Validating pedestals");
+  if (!fPedestals) 
+  {
+    // this is the only reason to fail for the moment : getting no pedestal
+    // at all.
+    return 0;
+  }
+    
   AliMUON2DStoreValidator validator;
-  TObjArray* missing =
-    validator.Validate(*fPedestals,AliMUONCalibParam2F::InvalidFloatValue());  
+
+  Master()->Log("Validating");
+
+  TObjArray* chambers = validator.Validate(*fPedestals);
   
-  if (missing)  
+  if (chambers)
   {
-    validator.Report(*missing);
-//    AliError("Will not write into CDB as some pieces are missing...");
-//    return 0;
+    // we hereby report what's missing, but this is not a reason to fail ;-)
+    // the only reason to fail would be if we got no pedestal at all
+    TList lines;
+    lines.SetOwner(kTRUE);
+  
+    validator.Report(lines,*chambers);
+  
+    TIter next(&lines);
+    TObjString* line;
+  
+    while ( ( line = static_cast<TObjString*>(next()) ) )
+    {
+      Master()->Log(line->String().Data());
+    }
   }
   
-  AliInfo("Storing pedestals");
+  Master()->Log("Storing pedestals");
   
   AliCDBMetaData metaData;
        metaData.SetBeamPeriod(0);
        metaData.SetResponsible("MUON TRK");
        metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
   
-       UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, 0);
+  Bool_t validToInfinity = kTRUE;
+       UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
   
   return result;  
 }
 
 //_____________________________________________________________________________
-Bool_t
+Int_t
 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
 {
-  // Read the pedestals from an ASCII file.
-  // Format of that file is one line per channel :
-  //---------------------------------------------------------------------------
-  // BUS_PATCH MANU_ADDR CHANNEL      MEAN       SIGMA
-  //---------------------------------------------------------------------------
-  //
-  // Return kFALSE if reading was not successfull.
-  //
+  /// Read the pedestals from an ASCII file.                                  \n
+  /// Format of that file is one line per channel :                           \n
+  ///-------------------------------------------------------------------------\n
+  /// BUS_PATCH MANU_ADDR CHANNEL      MEAN       SIGMA                       \n
+  ///-------------------------------------------------------------------------\n
+  ///                                                                         \n
+  /// Return kFALSE if reading was not successfull.                           \n
+  ///
   
-  AliInfo(Form("Reading %s",filename));
+  TString sFilename(gSystem->ExpandPathName(filename));
   
-  std::ifstream in(gSystem->ExpandPathName(filename));
-  if (!in.good()) return kFALSE;
+  Master()->Log(Form("Reading %s",sFilename.Data()));
   
+  std::ifstream in(sFilename.Data());
+  if (!in.good()) 
+  {
+    return 0;
+  }
   char line[80];
   Int_t busPatchID, manuID, manuChannel;
   Float_t pedMean, pedSigma;
   static const Int_t kNchannels(64);
   static Bool_t replace(kFALSE);
+  Int_t n(0);
   
   while ( in.getline(line,80) )
   {
@@ -166,14 +205,15 @@ AliMUONPedestalSubprocessor::ReadFile(const char* filename)
     
     if (!ped) 
     {
-      ped = new AliMUONCalibParam2F(kNchannels,AliMUONCalibParam2F::InvalidFloatValue());  
+      ped = new AliMUONCalibParamNF(2,kNchannels,AliMUONVCalibParam::InvalidFloatValue());  
       fPedestals->Set(detElemID,manuID,ped,replace);
     }
     ped->SetValueAsFloat(manuChannel,0,pedMean);
     ped->SetValueAsFloat(manuChannel,1,pedSigma);
+    ++n;
   }
   in.close();
-  return kTRUE;
+  return n;
 }