]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerSubprocessor.cxx
Adding more bins in QA (Alis)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerSubprocessor.cxx
index 3c9ab14abe2cc2f0d499349d670898063705cfcc..11ff1c5eee48c69c7aa36a87a794f362ae81cf3c 100644 (file)
@@ -20,6 +20,8 @@
 #include "AliCDBMetaData.h"
 #include "AliLog.h"
 #include "AliMUON1DArray.h"
+#include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
 #include "AliMUONCalibParamNI.h"
 #include "AliMUONPreprocessor.h"
 #include "AliMUONTriggerIO.h"
@@ -38,6 +40,7 @@
 ///
 /// \author L. Aphecetche
 
+using std::ifstream;
 /// \cond CLASSIMP
 ClassImp(AliMUONTriggerSubprocessor)
 /// \endcond
@@ -47,9 +50,9 @@ AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* mast
 : AliMUONVSubprocessor(master,
                        "Triggers",
                        "Upload MUON Trigger masks and LUT to OCDB"),
-fRegionalMasks(0x0),
+fRegionalConfig(0x0),
 fLocalMasks(0x0),
-fGlobalMasks(0x0),
+fGlobalConfig(0x0),
 fLUT(0x0)
 {
   /// default ctor
@@ -59,9 +62,9 @@ fLUT(0x0)
 AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
 {
   /// dtor
-  delete fRegionalMasks;
+  delete fRegionalConfig;
   delete fLocalMasks;
-  delete fGlobalMasks;
+  delete fGlobalConfig;
   delete fLUT;
 }
 
@@ -82,35 +85,117 @@ AliMUONTriggerSubprocessor::GetFileName(const char* fid) const
 }
 
 //_____________________________________________________________________________
-void 
+Bool_t 
 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
 {
   /// When starting a new run, reads in the trigger online files.
   
-  Master()->Log(Form("Reading trigger masks for Run %d startTime %ld endTime %ld",
+  // First thing to do (after cleanup, that is), is to check whether the DA
+  // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
+  // on the FXS. 
+  //
+  
+  Bool_t da(kTRUE);
+  
+  TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
+  
+  if ( exportedFiles == "" ) 
+  {
+    Master()->Log("exported files not specified !");
+    da = kFALSE;
+  }
+  
+  if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
+  {
+    Master()->Log(Form("%s is not there !",exportedFiles.Data()));
+    da = kFALSE;
+  }
+  
+  if (!da)
+  {
+    Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
+    Master()->Invalidate();
+    return kFALSE;
+  }
+  
+  // OK. We have an exportedFiles.dat file at hand.
+  // Read it to know what other files should be there.
+  
+  Bool_t regionalFile(kFALSE);
+  Bool_t globalFile(kFALSE);
+  Bool_t localFile(kFALSE);
+  Bool_t lutFile(kFALSE);
+  
+  WhichFilesToRead(GetFileName("EXPORTED").Data(),
+                   globalFile,regionalFile,localFile,lutFile);
+  
+  if ((globalFile+regionalFile+localFile+lutFile) == 0) {
+    Master()->Log("No file(s) to be processed for this run. Exiting.");
+    return kTRUE;
+  }
+  
+  delete fRegionalConfig; fRegionalConfig = 0x0;
+  delete fLocalMasks; fLocalMasks = 0x0;
+  delete fGlobalConfig; fGlobalConfig = 0x0;
+  delete fLUT; fLUT = 0x0;
+  
+  Master()->Log(Form("Reading trigger masks for Run %d startTime %u endTime %u",
                      run,startTime,endTime));
     
-  delete fRegionalMasks;
-  delete fLocalMasks;
-  delete fGlobalMasks;
+  Int_t check = 
+    TestFile("REGIONAL",regionalFile) + 
+    TestFile("LOCAL",localFile) + 
+    TestFile("GLOBAL",globalFile) +
+    TestFile("LUT",lutFile);
+
+  if ( check ) 
+  {
+    Master()->Log("Could not read some input file(s). Exiting");
+    Master()->Invalidate();
+    return kFALSE;
+  }
   
-  fRegionalMasks = new AliMUON1DArray(16);
-  fLocalMasks = new AliMUON1DArray(AliMpConstants::NofLocalBoards()+1);
-  fGlobalMasks = 0x0; // new AliMUONCalibParamNI(1,16,1,0,0);
+  if ( regionalFile ) globalFile = kTRUE;
+
+  if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
+  if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
+  if ( globalFile )   fGlobalConfig   = new AliMUONGlobalCrateConfig();
 
   AliMUONTriggerIO tio;
   
-  tio.ReadMasks(GetFileName("LOCAL").Data(),
-                GetFileName("REGIONAL").Data(),
-                GetFileName("GLOBAL").Data(),
-                fLocalMasks,fRegionalMasks,fGlobalMasks);
+  Bool_t ok = tio.ReadConfig(localFile ? GetFileName("LOCAL").Data() : "",
+                             regionalFile ? GetFileName("REGIONAL").Data() : "",
+                             globalFile ? GetFileName("GLOBAL").Data() : "",
+                             fLocalMasks,fRegionalConfig,fGlobalConfig);
+  
+  if (!ok)
+  {
+    Master()->Log("ERROR : ReadConfig failed");
+    delete fLocalMasks;
+    delete fRegionalConfig;
+    delete fGlobalConfig;
+    fLocalMasks = 0x0;
+    fRegionalConfig = 0x0;
+    fGlobalConfig = 0x0;
+  }
 
-  delete fLUT;
-  fLUT = 0x0; // new AliMUONTriggerLut;
+  if ( lutFile ) 
+  {
+    fLUT = new AliMUONTriggerLut;
     
-//  Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
-//                     run,startTime,endTime));
-//  tio.ReadLut(lutFile,fLUT);
+    Master()->Log(Form("Reading trigger LUT for Run %d startTime %u endTime %u",
+                       run,startTime,endTime));
+  
+    ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
+
+    if (!ok)
+    {
+      Master()->Log("ERROR : ReadLUT failed");
+      delete fLUT;
+      fLUT = 0x0;
+    }
+  }
+  return kTRUE;
 }
 
 //_____________________________________________________________________________
@@ -119,16 +204,17 @@ AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
 {
   /// Store the trigger masks into the CDB
   
-  if ( !fGlobalMasks && !fRegionalMasks && !fLocalMasks && !fLUT )
+  if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
   {
     // nothing to do
     return 0;
   }
   
-  Master()->Log(Form("N global = %d N regional = %d N local %d",                     
-                     (fGlobalMasks ? 1 : 0 ),
-                     (fRegionalMasks ? fRegionalMasks->GetSize() : 0 ),
-                     (fLocalMasks ? fLocalMasks->GetSize() : 0 )));
+  Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",                     
+                     (fGlobalConfig ? 1 : 0 ),
+                     (fRegionalConfig ? fRegionalConfig->GetNofTriggerCrates() : 0 ),
+                     (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
+                     (fLUT ? 1 : 0)));
   
   AliCDBMetaData metaData;
        metaData.SetBeamPeriod(0);
@@ -142,15 +228,15 @@ AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
   Bool_t result3(kTRUE);
   Bool_t result4(kTRUE);
   
-  if ( fGlobalMasks ) 
+  if ( fGlobalConfig ) 
   {
-    result1 = Master()->Store("Calib", "GlobalTriggerBoardMasks", fGlobalMasks
+    result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig
                               &metaData, 0, validToInfinity);
   }
   
-  if ( fRegionalMasks && fRegionalMasks->GetSize() > 0 )
+  if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 )
   {
-    result2 = Master()->Store("Calib", "RegionalTriggerBoardMasks", fRegionalMasks
+    result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig
                               &metaData, 0, validToInfinity);
   }
   
@@ -166,5 +252,64 @@ AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
                               &metaData, 0, validToInfinity);
   }
   
-  return ( result1 != kTRUE && result2 != kTRUE && result3 != kTRUE && result4 != kTRUE ); // return 0 if everything is ok.  
+  return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok.  
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
+{
+  /// Check if required file can be accessed 
+  if (!shouldBeThere) return 0; // all is ok
+  
+  TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
+  
+  if ( gSystem->AccessPathName(fileName.Data(),kFileExists) ) 
+  {
+    // mind the strange return value convention of that method !
+    Master()->Log(Form("File %s does not exist",fileName.Data()));    
+    return 1; // this is an error
+  }
+  return 0; // all is ok.
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
+                                             Bool_t& globalFile,
+                                             Bool_t& regionalFile,
+                                             Bool_t& localFile,
+                                             Bool_t& lutFile) const
+{
+  /// From the exportedFiles file, determine which other files will need
+  /// to be read in
+  ifstream in(gSystem->ExpandPathName(exportedFiles));
+  
+  globalFile = kFALSE;
+  regionalFile = kFALSE;
+  localFile = kFALSE;
+  lutFile = kFALSE;
+  
+  char line[1024];
+  
+  while ( in.getline(line,1024,'\n') )
+  {
+    TString sline(line);
+    sline.ToUpper();
+    
+    if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE;
+    if ( sline.Contains("LUT") ) lutFile = kTRUE;
+    if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE;
+    if ( sline.Contains("GLOBAL") ) globalFile = kTRUE;
+  }
+    
+  if ( regionalFile || localFile || globalFile || lutFile ) 
+  {
+    Master()->Log(Form("Will have to read the following file types:"));
+    if ( globalFile) Master()->Log("GLOBAL");
+    if ( regionalFile ) Master()->Log("REGIONAL");
+    if ( localFile) Master()->Log("LOCAL");
+    if ( lutFile ) Master()->Log("LUT");
+  }
 }
+