]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGainSubprocessor.cxx
o add Reset function to CalPad and CalROC o Add functionality to AliTPCdataQA - Reset...
[u/mrichter/AliRoot.git] / MUON / AliMUONGainSubprocessor.cxx
index a490f7fd6b373cbad829563dd033a8e573a930fe..13a8bf5d758c486b81f57331797fa2e87e072662 100644 (file)
@@ -24,6 +24,7 @@
 #include "AliMUONCalibParamNF.h"
 #include "AliMUONConstants.h"
 #include "AliMUONPreprocessor.h"
+#include "AliMUONTrackerIO.h"
 #include "AliMpConstants.h"
 #include "AliMpDDLStore.h"
 #include <Riostream.h>
@@ -59,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
 }
@@ -72,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.
@@ -80,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);
@@ -95,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;
 }
 
 //_____________________________________________________________________________
@@ -123,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 1;
+    // at all, except if the input file was a dummy one
+    if ( fSkip ) 
+    {
+      return 0;
+    }
+    else
+    {
+      return 1;
+    }
   }
     
   AliMUON2DStoreValidator validator;
@@ -156,7 +181,8 @@ 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;
        Bool_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
@@ -176,55 +202,27 @@ AliMUONGainSubprocessor::ReadFile(const char* filename)
   ///                                                                         
   /// 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()) 
+    
+  Int_t n = AliMUONTrackerIO::ReadGains(sFilename.Data(),*fGains,fComment);
+
+  switch (n)
   {
-    return 0;
+    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;
   }
-  char line[1024];
-  Int_t busPatchID, manuID, manuChannel;
-  Float_t a0, a1;
-  Int_t thres;
-  UInt_t qual;
-  const Int_t kSaturation(3000); // FIXME: how to get this number ?
-  
-  static const Int_t kNchannels(AliMpConstants::ManuNofChannels());
-  Int_t n(0);
   
-  while ( in.getline(line,1024) )
-  {
-    if ( strlen(line) < 10 ) continue;
-    if ( line[0] == '/' && line[1] == '/' ) continue;
-
-    sscanf(line,"%d %d %d %f %f %d %x",&busPatchID,&manuID,&manuChannel,
-           &a0,&a1,&thres,&qual); 
-    AliDebug(3,Form("line=%s",line));
-    Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
-    AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d A0 %7.2f "
-                    "A1 %e THRES %5d QUAL %x",
-                    busPatchID,detElemID,manuID,manuChannel,a0,a1,thres,qual));
-    if ( qual == 0 ) continue;
-    
-    AliMUONVCalibParam* gain = 
-      static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemID,manuID));
-    
-    if (!gain) 
-    {
-      gain = new AliMUONCalibParamNF(5,kNchannels,detElemID,manuID,0);
-      fGains->Add(gain);
-    }
-    gain->SetValueAsFloat(manuChannel,0,a0);
-    gain->SetValueAsFloat(manuChannel,1,a1);
-    gain->SetValueAsInt(manuChannel,2,thres);
-    gain->SetValueAsInt(manuChannel,3,qual);
-    gain->SetValueAsInt(manuChannel,4,kSaturation);
-    ++n;
-  }
-  in.close();
   return n;
 }