]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGainSubprocessor.cxx
- Disentangle masks effect from trigger chamber efficiency estimation.
[u/mrichter/AliRoot.git] / MUON / AliMUONGainSubprocessor.cxx
index ffce58f745b134f6f0ab8b8f5d7bd2db06e3b83e..13a8bf5d758c486b81f57331797fa2e87e072662 100644 (file)
 
 // $Id$
 
+#include "AliMUONGainSubprocessor.h"
+
+#include "AliCDBMetaData.h"
+#include "AliLog.h"
 #include "AliMUON2DMap.h"
+#include "AliMUON2DStoreValidator.h"
 #include "AliMUONCalibParamNF.h"
 #include "AliMUONConstants.h"
-#include "AliMUONObjectPair.h"
-#include "AliMUONGainSubprocessor.h"
 #include "AliMUONPreprocessor.h"
-#include "AliMUONVDataIterator.h"
+#include "AliMUONTrackerIO.h"
+#include "AliMpConstants.h"
 #include "AliMpDDLStore.h"
-#include "AliMUON2DStoreValidator.h"
-
-#include "AliCDBMetaData.h"
-#include "AliLog.h"
-
-#include <TObjString.h>
 #include <Riostream.h>
 #include <TList.h>
 #include <TObjString.h>
+#include <TObjString.h>
 #include <TSystem.h>
-
 #include <sstream>
 
-///
+//-----------------------------------------------------------------------------
 /// \class AliMUONGainSubprocessor
 ///
 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK Gains.
 ///
-/// Gains are read in from an ascii file, with the format :                   \n            
-///---------------------------------------------------------------------------\n
-///BUS_PATCH   MANU   CHANNEL    Ped.     a0        a1         a2         xlim        P(chi2)    P(chi2)_2  \n 
-///---------------------------------------------------------------------------\n
+/// Gains are read in from an ascii file, with the format :                               
+///
+///---------------------------------------------------------------------------
+///
+///BUS_PATCH   MANU   CHANNEL    a0   a1   thres Qual
+///
+///---------------------------------------------------------------------------
 ///
 /// \author L. Aphecetche
 ///
+//-----------------------------------------------------------------------------
 
 /// \cond CLASSIMP
 ClassImp(AliMUONGainSubprocessor)
@@ -58,7 +60,9 @@ AliMUONGainSubprocessor::AliMUONGainSubprocessor(AliMUONPreprocessor* master)
 : AliMUONVSubprocessor(master,
                        "Gains",
                        "Upload MUON Tracker Gains to OCDB"),
-fGains(0x0)
+fGains(0x0),
+fSkip(kFALSE),
+fComment("")
 {
   /// default ctor
 }
@@ -71,7 +75,7 @@ AliMUONGainSubprocessor::~AliMUONGainSubprocessor()
 }
 
 //_____________________________________________________________________________
-void 
+Bool_t 
 AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
 {
   /// When starting a new run, reads in the Gains ASCII files.
@@ -79,10 +83,13 @@ AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
   const Int_t kSystem = AliMUONPreprocessor::kDAQ;
   const char* kId = "GAINS";
   
+  fComment = "";
+  fSkip = kFALSE;
+  
   delete fGains;
   fGains = new AliMUON2DMap(kTRUE);
   
-  Master()->Log(Form("Reading Gain files for Run %d startTime %ld endTime %ld",
+  Master()->Log(Form("Reading Gain files for Run %d startTime %u endTime %u",
                      run,startTime,endTime));
   
   TList* sources = Master()->GetFileSources(kSystem,kId);
@@ -94,23 +101,35 @@ AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
   {
     TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
     Int_t ok = ReadFile(fileName.Data());
-    if (!ok)
+    if (ok>0)
     {
-      Master()->Log(Form("Could not read file %s",fileName.Data()));
+      n += ok;
     }
-    else
+    else if ( ok == AliMUONTrackerIO::kDummyFile )
     {
-      n += ok;
+      // not an interesting file.
+      fSkip = kTRUE;
+      break;
     }
   }
   
-  if (!n)
+  delete sources;
+
+  if ( fSkip ) 
+  {
+    delete fGains;
+    fGains = 0x0;
+  }
+  
+  if (!n && !fSkip)
   {
     Master()->Log("Failed to read any Gains");
     delete fGains;
-    fGains = 0;
+    fGains = 0x0;
+    return kFALSE;
   }
-  delete sources;
+  
+  return kTRUE;
 }
 
 //_____________________________________________________________________________
@@ -122,8 +141,15 @@ AliMUONGainSubprocessor::Process(TMap* /*dcsAliasMap*/)
   if (!fGains) 
   {
     // this is the only reason to fail for the moment : getting no Gain
-    // at all.
-    return 0;
+    // at all, except if the input file was a dummy one
+    if ( fSkip ) 
+    {
+      return 0;
+    }
+    else
+    {
+      return 1;
+    }
   }
     
   AliMUON2DStoreValidator validator;
@@ -155,92 +181,48 @@ AliMUONGainSubprocessor::Process(TMap* /*dcsAliasMap*/)
   AliCDBMetaData metaData;
        metaData.SetBeamPeriod(0);
        metaData.SetResponsible("MUON TRK");
-       metaData.SetComment("Computed by AliMUONGainSubprocessor $Id$");
+       metaData.SetComment(Form("Computed by AliMUONGainSubprocessor "
+                           "$Id$ ; %s",fComment.Data()));
   
   Bool_t validToInfinity = kTRUE;
-       UInt_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
+       Bool_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
   
-  return result;  
+  return ( result != kTRUE ); // return 0 if everything is ok  
 }
 
 //_____________________________________________________________________________
 Int_t
 AliMUONGainSubprocessor::ReadFile(const char* filename)
 {
-  /// Read the Gains from an ASCII file.                                  \n
-  /// Format of that file is one line per channel :                           \n
-  ///-------------------------------------------------------------------------\n
-  ///BUS_PATCH   MANU   CHANNEL    Ped.     a0        a1         a2         xlim        P(chi2)    P(chi2)_2  \n 
-  ///-------------------------------------------------------------------------\n
-  ///                                                                         \n
-  /// Return kFALSE if reading was not successfull.                           \n
+  /// Read the Gains from an ASCII file.                                  
+  /// Format of that file is one line per channel :                       
+  ///-------------------------------------------------------------------------
+  ///BUS_PATCH   MANU   CHANNEL  a0  a1 thres Qual
+  ///-------------------------------------------------------------------------
+  ///                                                                         
+  /// Return kFALSE if reading was not successfull.                           
   ///
-  
+
   TString sFilename(gSystem->ExpandPathName(filename));
   
   Master()->Log(Form("Reading %s",sFilename.Data()));
-  
-  std::ifstream in(sFilename.Data());
-  if (!in.good()) 
-  {
-    return 0;
-  }
-  char line[256];
-  Int_t busPatchID, manuID, manuChannel;
-  Float_t ped;
-  Float_t a0, a1, a2;
-  Float_t xlim;
-  Float_t chi2, chi22;
-  
-  static const Int_t kNchannels(64);
-  static Bool_t replace(kFALSE);
-  Int_t n(0);
-  
-  while ( in.getline(line,256) )
-  {
-    if ( strlen(line) < 10 ) continue;
-    if ( line[0] == '/' && line[1] == '/' ) continue;
-    std::istringstream sin(line);
-    AliDebug(3,Form("line=%s",line));
-    sin >> busPatchID >> manuID >> manuChannel >> ped >> a0 >> a1 >> a2 >> xlim >> chi2 >> chi22;
-    Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
-    AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d PED %7.2f A0 %7.2f A1 %7.2f A2 %7.2f"
-                    " XLIM %7.2f CHI2 %7.2f CHI22 %7.2f",
-                    busPatchID,detElemID,manuID,manuChannel,ped,a0,a1,a2,xlim,chi2,chi22));
-    if ( a0==a1 && a1==a2 && a0==-2) continue;
-    
-    AliMUONVCalibParam* gain = 
-      static_cast<AliMUONVCalibParam*>(fGains->Get(detElemID,manuID));
     
-    if (!gain) 
-    {
-      gain = new AliMUONCalibParamNF(6,kNchannels,0);//AliMUONVCalibParam::InvalidFloatValue());  
-      fGains->Set(detElemID,manuID,gain,replace);
-    }
-    gain->SetValueAsFloat(manuChannel,0,a0);
-    gain->SetValueAsFloat(manuChannel,1,a1);
-    gain->SetValueAsFloat(manuChannel,2,a2);
-    gain->SetValueAsFloat(manuChannel,3,xlim);
-    gain->SetValueAsFloat(manuChannel,4,chi2);
-    gain->SetValueAsFloat(manuChannel,5,chi22);
-    ++n;
-  }
-  in.close();
-  return n;
-}
+  Int_t n = AliMUONTrackerIO::ReadGains(sFilename.Data(),*fGains,fComment);
 
-
-//_____________________________________________________________________________
-void
-AliMUONGainSubprocessor::Print(Option_t* opt) const
-{
-  /// ouput to screen
-  AliMUONVDataIterator* it = fGains->Iterator();
-  AliMUONObjectPair* p;
-
-  while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
+  switch (n)
   {
-    AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());
-    value->Print(opt);
+    case AliMUONTrackerIO::kCannotOpenFile:
+      Master()->Log(Form("Could not open %s",sFilename.Data()));
+      break;
+    case AliMUONTrackerIO::kFormatError:
+      Master()->Log(Form("File %s is not of the expected format",sFilename.Data()));
+      break;
+    case AliMUONTrackerIO::kDummyFile:
+      Master()->Log(Form("File %s is a dummy one. That's fine. I won't do anything then ;-)",sFilename.Data()));
+      break;
+    default:
+      break;
   }
+  
+  return n;
 }