]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MUONTRGda.cxx
PHOS calibration macros
[u/mrichter/AliRoot.git] / MUON / MUONTRGda.cxx
index 34609493d59a972b46bf2f4ca56e128b710d3367..acafe0f2ffa5febc56d77791ecc333785cccd820 100644 (file)
@@ -3,27 +3,20 @@ MTR DA for online
 
 Contact: Franck Manso <manso@clermont.in2p3.fr>
 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
-Reference run: 61898, 63698 (dead channels), 63701 (noisy channels)
-Run Type:  PHYSICS (noisy channels), STANDALONE (dead channels)
+Reference run: 61898
+Run Type:  PHYSICS
 DA Type: MON
-Number of events needed: 1000 events for noisy and dead channels
-Input Files: Rawdata file (DATE format)
-Input Files from DB:
-MtgGlobalCrate-<version>.dat
-MtgRegionalCrate-<version>.dat
-MtgLocalMask-<version>.dat
-MtgLocalLut-<version>.dat
-MtgCurrent.dat
-
-Output Files: local dir (not persistent) 
-ExportedFiles.dat
+Number of events needed: 1000 events
+Input files: MtgGlobalCrate.dat MtgRegionalCrate.dat MtgLocalMask.dat MtgLocalLut.dat MtgCurrent.dat DAConfig.dat
+Output Files: ExportedFiles.dat MtgGlobalCrate.dat
+Trigger types used: PHYSICS_EVENT CALIBRATION_EVENT
 */
 
 //////////////////////////////////////////////////////////////////////////////
 // Detector Algorithm for the MUON trigger configuration.                   //
 //                                                                          //
 // Calculates masks for the global trigger input, by looking at dead        //
-// channels in calibration runs and at noisy channels in physics runs.      //
+// channels in calibration events and at noisy channels in physics events.  //
 // Transfers trigger configuration files to the File Exchange Server and    //
 // writes them (if modified) into the trigger configuration data base.      //
 //                                                                          //
@@ -34,6 +27,8 @@ ExportedFiles.dat
 //                                                                          //
 //////////////////////////////////////////////////////////////////////////////
 
+//#define OFFLINE
+
 extern "C" {
 #include <daqDA.h>
 }
@@ -45,93 +40,45 @@ extern "C" {
 #include <stdio.h>
 #include <stdlib.h>
 
-//AliRoot
 #include "AliRawReaderDate.h"
 
 #include "AliMpConstants.h"
 #include "AliMUONRawStreamTrigger.h"
+#include "AliMUONRawStreamTriggerHP.h"
 #include "AliMUONDarcHeader.h"
+#include "AliMUONRegHeader.h"
 #include "AliMUONDDLTrigger.h"
 #include "AliMUONVStore.h"
 #include "AliMUON1DArray.h"
 #include "AliMUONTriggerIO.h"
 #include "AliMUONRegionalTriggerConfig.h"
 #include "AliMUONGlobalCrateConfig.h"
-#include "AliMUONTriggerCrateConfig.h"
+#include "AliMUONVCalibParam.h"
+#include "AliMUONCalibParamND.h"
+#include "AliMUONCalibParamNI.h"
+#include "AliMUONLocalStruct.h"
 
-//ROOT
 #include "TString.h"
 #include "TSystem.h"
 #include "TStopwatch.h"
 #include "TROOT.h"
 #include "TPluginManager.h"
+#include "TArrayS.h"
 
-// structure for DA run parameters and DA working space
-struct DAConfig {
-
-  const TString fDAConfigFileName;
-  const TString fCurrentFileName;
-  const TString fLastCurrentFileName;
-
-  TString fSodName;
-  Int_t   fSodFlag;
-
-  TString fDAName;
-  Int_t   fDAFlag;
-
-  TString fGlobalFileName;
-  TString fRegionalFileName;
-  TString fLocalMaskFileName;
-  TString fLocalLutFileName;
-  TString fSignatureFileName;
-
-  Int_t   fGlobalFileVersion;
-  Int_t   fRegionalFileVersion;
-  Int_t   fLocalMaskFileVersion;
-  Int_t   fLocalLutFileVersion;
-  Int_t   fSignatureFileVersion;
-  
-  Int_t   fGlobalFileLastVersion;
-  Int_t   fRegionalFileLastVersion;
-  Int_t   fLocalMaskFileLastVersion;
-  Int_t   fLocalLutFileLastVersion;
-
-  Int_t   fNEventsN;
-  Int_t   fNEventsD;
-
-  Int_t   fPrintLevel;
-
-  AliMUONVStore*                fLocalMasks;
-  AliMUONRegionalTriggerConfig* fRegionalMasks;
-  AliMUONGlobalCrateConfig*     fGlobalMasks;    
-
-  AliMUONTriggerIO *fTriggerIO;
-
-  Bool_t fAlgoNoisyInput;
-  Bool_t fAlgoDeadInput;
+/// class for DA run parameters and DA working space
+class AliDAConfig : TObject {
 
-  Float_t fThrN;
-  Float_t fThrD;
-  Int_t   fMinEvents;
-  Int_t   fSkipEvents;
-  Int_t   fMaxEvents;
-  Bool_t  fWithWarnings;
+public:
 
-  const Int_t fNLocalBoard;
-
-  enum { kGlobalInputs = 4, kGlobalInputLength = 32 };
-
-  Int_t fAccGlobalInputN[kGlobalInputs][kGlobalInputLength];
-  Int_t fAccGlobalInputD[kGlobalInputs][kGlobalInputLength];
-
-  DAConfig() : 
-    fDAConfigFileName("DAConfig.txt"),
+  AliDAConfig() : 
+    fDAConfigFileName("DAConfig.dat"),
     fCurrentFileName("MtgCurrent.dat"), 
     fLastCurrentFileName("MtgLastCurrent.dat"), 
     fSodName(""),
     fSodFlag(0),
     fDAName(""),
     fDAFlag(0),
+    fDAMode(1),
     fGlobalFileName(""),
     fRegionalFileName(""),
     fLocalMaskFileName(""),
@@ -146,49 +93,376 @@ struct DAConfig {
     fRegionalFileLastVersion(0),
     fLocalMaskFileLastVersion(0),
     fLocalLutFileLastVersion(0),
-    fNEventsN(0),
-    fNEventsD(0),
+    fEventsN(0),
+    fEventsD(0),
     fPrintLevel(0),
     fLocalMasks(0x0),
+    fLocalMasksDA(0x0),
     fRegionalMasks(0x0),
     fGlobalMasks(0x0),
     fTriggerIO(new AliMUONTriggerIO),
-    fAlgoNoisyInput(false),
-    fAlgoDeadInput(false),
+    fAlgoNoisyInput(kFALSE),
+    fAlgoDeadcInput(kFALSE),
     fThrN(0.1),
     fThrD(0.9),
+    fThrLocN(0.1),
+    fThrLocD(0.9),
     fMinEvents(10),
     fSkipEvents(0),
     fMaxEvents(65535),
-    fWithWarnings(false),
-    fNLocalBoard(AliMpConstants::TotalNofLocalBoards()+1)
+    fWithWarnings(kFALSE),
+    fUseFastDecoder(kFALSE),
+    fNLocalBoard(AliMpConstants::TotalNofLocalBoards()+1),
+    fPatternStoreN(0x0),
+    fPatternStoreD(0x0)
   {
+    /// default constructor
     for (Int_t ii = 0; ii < kGlobalInputs; ii++) {
       for (Int_t il = 0; il < kGlobalInputLength; il++) {
        fAccGlobalInputN[ii][il] = 0;
        fAccGlobalInputD[ii][il] = 0;
       }
     }
+    fLocalMasks    = new AliMUON1DArray(fNLocalBoard);
+    fLocalMasksDA  = new AliMUON1DArray(fNLocalBoard);
+    fRegionalMasks = new AliMUONRegionalTriggerConfig();
+    fGlobalMasks   = new AliMUONGlobalCrateConfig();
+    fPatternStoreN = new AliMUON1DArray(fNLocalBoard);
+    fPatternStoreD = new AliMUON1DArray(fNLocalBoard);
+
+    // Generate local trigger masks store. All masks are set to FFFF
+    for (Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); i++) {
+      AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
+      for (Int_t x = 0; x < 2; x++) {
+       for (Int_t y = 0; y < 4; y++) {
+         Int_t index = x*4+y;
+         localBoard->SetValueAsInt(index,0,0xFFFF);
+       }
+      }
+      fLocalMasksDA->Add(localBoard);
+    }
+    
+    // Create a default pattern store
+    for (Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); i++) {
+      AliMUONVCalibParam *patN = new AliMUONCalibParamND(2, 64, i, 0, 0.);
+      AliMUONVCalibParam *patD = new AliMUONCalibParamND(2, 64, i, 0, 0.);
+      fPatternStoreN->Add(patN);       
+      fPatternStoreD->Add(patD);       
+    }
+
+  }
+
+  virtual ~AliDAConfig()
+  {
+    /// destructor
+    delete fLocalMasks;
+    delete fLocalMasksDA;
+    delete fRegionalMasks;
+    delete fGlobalMasks; 
+    delete fPatternStoreN;
+    delete fPatternStoreD;
+    delete fTriggerIO;
+  }
+  void PrintConfig()
+  {
+    /// print DA parameters
+    printf("DA config file name: %s \n",GetDAConfigFileName());
+    printf("Current file name: %s \n",GetCurrentFileName());
+    printf("Last current file name: %s \n",GetLastCurrentFileName());
+    printf("Global file name: %s (%d %d)\n",GetGlobalFileName(),GetGlobalFileVersion(),GetGlobalFileLastVersion());
+    printf("Regional file name: %s (%d %d)\n",GetRegionalFileName(),GetRegionalFileVersion(),GetRegionalFileLastVersion());
+    printf("Local mask file name: %s (%d %d)\n",GetLocalMaskFileName(),GetLocalMaskFileVersion(),GetLocalMaskFileLastVersion());
+    printf("Local LUT file name: %s (%d %d)\n",GetLocalLutFileName(),GetLocalLutFileVersion(),GetLocalLutFileLastVersion());
+    printf("Signature file name: %s (%d)\n",GetSignatureFileName(),GetSignatureFileVersion());
   }
 
-  DAConfig (const DAConfig& cfg);
-  DAConfig& operator=(const DAConfig& cfg);
+     /// name of the DA configuration file from detector DB
+  const Char_t* GetDAConfigFileName()    { return fDAConfigFileName.Data(); }
+     /// file with current versions of the configuration files, usually MtgCurrent.dat
+  const Char_t* GetCurrentFileName()     { return fCurrentFileName.Data(); }
+     /// last known versions of the configuration files, usually MtgLastCurrent.dat
+  const Char_t* GetLastCurrentFileName() { return fLastCurrentFileName.Data(); }
+
+     /// name of the Start-of-data field in MtgCurrent.dat
+  const Char_t* GetSodName() { return fSodName.Data(); }
+     /// flag value of the Start-of-data field in MtgCurrent.dat
+  Int_t GetSodFlag() const { return fSodFlag; }
+
+     /// name of the Detector Algorithm field in MtgCurrent.dat
+  const Char_t* GetDAName() { return fDAName.Data(); }
+     /// flag value of the Detector Algorithm field in MtgCurrent.dat
+  Int_t GetDAFlag() const { return fDAFlag; }
+     /// DA active mode (GLOBAL or GLOBAL+LOCAL)
+  Int_t GetDAMode() const { return fDAMode; }
+
+     /// global crate configuration file name
+  const Char_t* GetGlobalFileName()    { return fGlobalFileName.Data(); }
+     /// regional crate configuration file name
+  const Char_t* GetRegionalFileName()  { return fRegionalFileName.Data(); }
+     /// masks for the local cards, file name
+  const Char_t* GetLocalMaskFileName() { return fLocalMaskFileName.Data(); }
+     /// transverse momentum Look-Up-Table, file name
+  const Char_t* GetLocalLutFileName()  { return fLocalLutFileName.Data(); }
+     /// signature file name
+  const Char_t* GetSignatureFileName() { return fSignatureFileName.Data(); }
+
+     /// version of the global crate configuration in the detector DB
+  Int_t GetGlobalFileVersion()    const { return fGlobalFileVersion; }
+     /// version of the regional crate configuration in the detector DB
+  Int_t GetRegionalFileVersion()  const { return fRegionalFileVersion; }
+     /// version of the masks for the local cards in the detector DB
+  Int_t GetLocalMaskFileVersion() const { return fLocalMaskFileVersion; }
+     /// version of the transverse momentum Look-Up-Table in the detector DB
+  Int_t GetLocalLutFileVersion()  const { return fLocalLutFileVersion; }
+     /// version of the signature file in the detector DB
+  Int_t GetSignatureFileVersion() const { return fSignatureFileVersion; }
+
+     /// last known version of the global crate configuration
+  Int_t GetGlobalFileLastVersion()    const { return fGlobalFileLastVersion; }
+     /// last known version of the regional crate configuration
+  Int_t GetRegionalFileLastVersion()  const { return fRegionalFileLastVersion; }
+     /// last known version of the masks for the local cards
+  Int_t GetLocalMaskFileLastVersion() const { return fLocalMaskFileLastVersion; }
+     /// last known version of the transverse momentum Look-Up-Table
+  Int_t GetLocalLutFileLastVersion()  const { return fLocalLutFileLastVersion; }
+
+     /// store for the masks for the local cards (own)
+  AliMUONVStore*                GetLocalMasks()    const { return fLocalMasks; }
+     /// store for the DA-calculated masks for the local cards (own)
+  AliMUONVStore*                GetLocalMasksDA()  const { return fLocalMasksDA; }
+     /// configuration object for the regional crate (own)
+  AliMUONRegionalTriggerConfig* GetRegionalMasks() const { return fRegionalMasks; }
+     /// configuration object for the global crate (own)
+  AliMUONGlobalCrateConfig*     GetGlobalMasks()   const { return fGlobalMasks; }
+
+     /// read/write configurations, masks and LUT to/from online files (own)
+  AliMUONTriggerIO* GetTriggerIO() const { return fTriggerIO; }
+
+     /// store for local strips patterns (noisy strips)
+  AliMUONVStore* GetPatternStoreN() const { return fPatternStoreN; }
+     /// store for local strips patterns (dead strips)
+  AliMUONVStore* GetPatternStoreD() const { return fPatternStoreD; }
+
+     /// number of accumulated PHYSICS events for noisy channels analysis
+  Int_t GetEventsN() const { return fEventsN; }
+     /// number of accumulated CALIBRATION events for dead channels analysis
+  Int_t GetEventsD() const { return fEventsD; }
+
+     /// print verbosity of the DA
+  Int_t GetPrintLevel() const { return fPrintLevel; }
+
+     /// select PHYSICS events for noisy channels analysis
+  Bool_t GetAlgoNoisyInput() const { return fAlgoNoisyInput; }
+     /// select CALIBRATION events for dead channels analysis
+  Bool_t GetAlgoDeadcInput() const { return fAlgoDeadcInput; }
+
+     /// threshold for noisy global inputs (fraction of events)
+  Float_t GetThrN() const { return fThrN; }
+     /// threshold for dead global inputs (fraction of events)
+  Float_t GetThrD() const { return fThrD; }
+     /// threshold for noisy local strips (fraction of events)
+  Float_t GetThrLocN() const { return fThrLocN; }
+     /// threshold for dead local strips (fraction of events)
+  Float_t GetThrLocD() const { return fThrLocD; }
+
+     /// minumum nr of events for rate calculation
+  Int_t GetMinEvents()  const { return fMinEvents; }
+     /// maximum number of events to analyze
+  Int_t GetMaxEvents()  const { return fMaxEvents; }
+     /// number of events to skip from start
+  Int_t GetSkipEvents() const { return fSkipEvents; }
+
+     /// show warnings from the raw data decoder
+  Bool_t WithWarnings() const { return fWithWarnings; }
+     /// use the high-performance (HP) decoder
+  Bool_t UseFastDecoder() const { return fUseFastDecoder; }
+
+     /// number of global input words
+  Int_t GetGlobalInputs()      const { return kGlobalInputs; }
+    /// length in bits of a global input word
+  Int_t GetGlobalInputLength() const { return kGlobalInputLength; }
+
+     /// get accumulated values for bit "ib" from global input word "ii", PHYSICS events
+  Int_t GetAccGlobalInputN(Int_t ii, Int_t ib) const { return fAccGlobalInputN[ii][ib]; }
+     /// get accumulated values for bit "ib" from global input word "ii", CALIBRATION events
+  Int_t GetAccGlobalInputD(Int_t ii, Int_t ib) const { return fAccGlobalInputD[ii][ib]; }
+
+     /// set the name of the Start-of-data field in MtgCurrent.dat
+  void SetSodName(Char_t *name) { fSodName = TString(name); }
+     /// set the flag value of the Start-of-data field in MtgCurrent.dat
+  void SetSodFlag(Int_t flag)   { fSodFlag = flag; }
+
+     /// set the name of the Detector Algorithm field in MtgCurrent.dat
+  void SetDAName(Char_t *name) { fDAName = TString(name); }
+     /// set the flag value of the Detector Algorithm field in MtgCurrent.dat
+  void SetDAFlag(Int_t flag)   { fDAFlag = flag; }
+     /// set DA active mode, 1 = GLOBAL (default), 2 = GLOBAL and LOCAL
+  void SetDAMode(Int_t mode)   { fDAMode = mode; }
+
+     /// set the global crate configuration file name
+  void SetGlobalFileName(const Char_t *name)    { fGlobalFileName = TString(name); }
+     /// set the regional crate configuration file name
+  void SetRegionalFileName(const Char_t *name)  { fRegionalFileName = TString(name); }
+     /// set the masks for the local cards, file name
+  void SetLocalMaskFileName(const Char_t *name) { fLocalMaskFileName = TString(name); }
+     /// set the transverse momentum Look-Up-Table, file name
+  void SetLocalLutFileName(const Char_t *name)  { fLocalLutFileName = TString(name); }
+     /// set the signature file name
+  void SetSignatureFileName(const Char_t *name) { fSignatureFileName = TString(name); }
+
+     /// set the version of the global crate configuration in the detector DB
+  void SetGlobalFileVersion(Int_t ver)    { fGlobalFileVersion = ver; }
+     /// set the version of the regional crate configuration in the detector DB
+  void SetRegionalFileVersion(Int_t ver)  { fRegionalFileVersion = ver; }
+     /// set the version of the masks for the local cards in the detector DB
+  void SetLocalMaskFileVersion(Int_t ver) { fLocalMaskFileVersion = ver; }
+     /// set the version of the transverse momentum Look-Up-Table in the detector DB
+  void SetLocalLutFileVersion(Int_t ver)  { fLocalLutFileVersion = ver; }
+     /// set the version of the signature file in the detector DB
+  void SetSignatureFileVersion(Int_t ver) { fSignatureFileVersion = ver; }
+
+     /// set the last known version of the global crate configuration
+  void SetGlobalFileLastVersion(Int_t ver)    { fGlobalFileLastVersion = ver; }
+     /// set the last known version of the regional crate configuration
+  void SetRegionalFileLastVersion(Int_t ver)  { fRegionalFileLastVersion = ver; }
+     /// set the last known version of the masks for the local cards
+  void SetLocalMaskFileLastVersion(Int_t ver) { fLocalMaskFileLastVersion = ver; }
+     /// set the last known version of the transverse momentum Look-Up-Table
+  void SetLocalLutFileLastVersion(Int_t ver)  { fLocalLutFileLastVersion = ver; }
+
+     /// increment the number of selected PHYSICS events
+  void IncNoiseEvent() { fEventsN++; }
+     /// increment the number of selected CALIBRATION events
+  void IncDeadcEvent() { fEventsD++; }
+
+     /// count the value of the bit "ib" of global input word "ii" (PHYSICS events)
+  void AddAccGlobalInputN(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputN[ii][ib] += val; }
+     /// count the value of the bit "ib" of global input word "ii" (CALIBRATION events)
+  void AddAccGlobalInputD(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputD[ii][ib] += val; }
+
+     /// set the print verbosity level of the DA
+  void SetPrintLevel(Int_t level) { fPrintLevel = level; }
+
+     /// select PHYSICS events for noisy channels analysis
+  void SetAlgoNoisyInput(Bool_t val) { fAlgoNoisyInput = val; }
+     /// select CALIBRATION events for dead channels analysis
+  void SetAlgoDeadcInput(Bool_t val) { fAlgoDeadcInput = val; }
+
+     /// set the threshold for noisy global inputs (fraction of events)
+  void SetThrN(Float_t val) { fThrN = val; }
+     /// set the threshold for dead global inputs (fraction of events)
+  void SetThrD(Float_t val) { fThrD = val; }
+     /// set the threshold for noisy local strips (fraction of events)
+  void SetThrLocN(Float_t val) { fThrLocN = val; }
+     /// set the threshold for dead local strips (fraction of events)
+  void SetThrLocD(Float_t val) { fThrLocD = val; }
+
+     /// set the minumum nr of events for rate calculation
+  void SetMinEvents(Int_t val)  { fMinEvents = val; }
+     /// set the maximum number of events to analyze
+  void SetMaxEvents(Int_t val)  { fMaxEvents = val; }
+     /// set the number of events to skip from start
+  void SetSkipEvents(Int_t val) { fSkipEvents = val; }
+
+     /// set/unset to show warnings from the raw data decoder
+  void SetWithWarnings() { fWithWarnings = kTRUE; }
+     /// set/unset the use of the high-performance (HP) decoder
+  void SetUseFastDecoder() { fUseFastDecoder = kTRUE; }
+
+    /// increment version of the global crate configuration file
+  void IncGlobalFileVersion() { fGlobalFileVersion++; }
+    /// increment version of the local mask configuration file
+  void IncLocalMaskFileVersion() { fLocalMaskFileVersion++; }
+    /// count skipped events
+  void DecSkipEvents() { fSkipEvents--; }
+
+private:
+
+  /// copy constructor, not implemented
+  AliDAConfig (const AliDAConfig& cfg);
+  /// assignment operator, not implemented
+  AliDAConfig& operator=(const AliDAConfig& cfg);
+
+  const TString fDAConfigFileName;    //!< name of the DA configuration file from detector DB
+  const TString fCurrentFileName;     //!< usually MtgCurrent.dat
+  const TString fLastCurrentFileName; //!< usually MtgLastCurrent.dat
+
+  TString fSodName; //!< name of the Start-of-data field in MtgCurrent.dat
+  Int_t   fSodFlag; //!< flag value of the Start-of-data field in MtgCurrent.dat
+
+  TString fDAName;  //!< name of the Detector Algorithm field in MtgCurrent.dat 
+  Int_t   fDAFlag;  //!< flag value of the Detector Algorithm field in MtgCurrent.dat (enabled/disabled)
+  Int_t   fDAMode;  //!< DA active mode, GLOBAL or GLOBAL+LOCAL
+
+  TString fGlobalFileName;      //!< global crate configuration, file name
+  TString fRegionalFileName;    //!< regional crate configuration, file name
+  TString fLocalMaskFileName;   //!< masks for the local cards, file name
+  TString fLocalLutFileName;    //!< transverse momentum Look-Up-Table, file name
+  TString fSignatureFileName;   //!< signature file name
+
+  Int_t   fGlobalFileVersion;    //!< version of the global crate configuration in the detector DB
+  Int_t   fRegionalFileVersion;  //!< version of the regional crate configuration in the detector DB
+  Int_t   fLocalMaskFileVersion; //!< version of the masks for the local cards in the detector DB
+  Int_t   fLocalLutFileVersion;  //!< version of the transverse momentum Look-Up-Table in the detector DB
+  Int_t   fSignatureFileVersion; //!< version of the signature file in the detector DB
+  
+  Int_t   fGlobalFileLastVersion;    //!< last known version of the global crate configuration
+  Int_t   fRegionalFileLastVersion;  //!< last known version of the regional crate configuration
+  Int_t   fLocalMaskFileLastVersion; //!< last known version of the masks for the local cards
+  Int_t   fLocalLutFileLastVersion;  //!< last known version of the transverse momentum Look-Up-Table
+
+  Int_t   fEventsN; //!< number of accumulated PHYSICS events
+  Int_t   fEventsD; //!< number of accumulated CALIBRATION events
+
+  Int_t   fPrintLevel;  //!< print verbosity of the DA
+
+  AliMUONVStore*                fLocalMasks;    //!< store for the masks for the local cards
+  AliMUONVStore*                fLocalMasksDA;  //!< store for the DA-calculated masks for the local cards
+  AliMUONRegionalTriggerConfig* fRegionalMasks; //!< configuration object for the regional crate
+  AliMUONGlobalCrateConfig*     fGlobalMasks;   //!< configuration object for the global crate
+
+  AliMUONTriggerIO *fTriggerIO;  //!< read/write masks and LUT to/from online files
+
+  Bool_t fAlgoNoisyInput; //!< select PHYSICS events for noisy channels analysis
+  Bool_t fAlgoDeadcInput; //!< select CALIBRATION events for dead channels analysis
+
+  Float_t fThrN;           //!< threshold for noisy global inputs (fraction of events)
+  Float_t fThrD;           //!< threshold for dead global inputs (fraction of events)
+  Float_t fThrLocN;        //!< threshold for noisy local strips (fraction of events)
+  Float_t fThrLocD;        //!< threshold for dead local strips (fraction of events)
+  Int_t   fMinEvents;      //!< minumum nr of events for rate calculation
+  Int_t   fSkipEvents;     //!< number of events to skip from start
+  Int_t   fMaxEvents;      //!< maximum number of events to analyze
+  Bool_t  fWithWarnings;   //!< show warnings from the raw data decoder
+  Bool_t  fUseFastDecoder; //!< use the high-performance (HP) decoder
+
+  const Int_t fNLocalBoard; //!< number of local boards
+
+  enum { kGlobalInputs = 4,         //!< number of global input words
+        kGlobalInputLength = 32    //!< length in bits of a global input word
+  };
+
+  AliMUONVStore *fPatternStoreN; //! store for local strips patterns
+  AliMUONVStore *fPatternStoreD; //! store for local strips patterns
+
+  Int_t fAccGlobalInputN[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (PHYSICS events)
+  Int_t fAccGlobalInputD[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (CALIBRATION events)
 
 };
 
 //__________________________________________________________________
-Bool_t ReadDAConfig(DAConfig& cfg)
+Bool_t ReadDAConfig(AliDAConfig& cfg)
 {
-  // read run parameters for the DA
+    /// read run parameters for the DA
 
     char line[80];
 
     TString file;
-    file = cfg.fDAConfigFileName;
+    file = cfg.GetDAConfigFileName();
     std::ifstream in(gSystem->ExpandPathName(file.Data()));
     if (!in.good()) {
       printf("Cannot open DA configuration file %s ; use default values.\n",file.Data());
-      return true;
+      return kTRUE;
     }
 
     TString tmp;
@@ -198,208 +472,240 @@ Bool_t ReadDAConfig(DAConfig& cfg)
     tmp = line;
     pos = tmp.First(" ");
     tmp = tmp(0,pos);
-    cfg.fPrintLevel = tmp.Atoi();
+    cfg.SetPrintLevel(tmp.Atoi());
     
     in.getline(line,80);  
     tmp = line;
     pos = tmp.First(" ");
     tmp = tmp(0,pos);
-    cfg.fThrN = tmp.Atof();
+    cfg.SetThrN(tmp.Atof());
 
     in.getline(line,80);  
     tmp = line;
     pos = tmp.First(" ");
     tmp = tmp(0,pos);
-    cfg.fThrD = tmp.Atof();
+    cfg.SetThrD(tmp.Atof());
 
     in.getline(line,80);  
     tmp = line;
     pos = tmp.First(" ");
     tmp = tmp(0,pos);
-    cfg.fMinEvents = tmp.Atoi();
+    cfg.SetMinEvents(tmp.Atoi());
 
     in.getline(line,80);  
     tmp = line;
     pos = tmp.First(" ");
     tmp = tmp(0,pos);
-    cfg.fSkipEvents = tmp.Atoi();
+    cfg.SetSkipEvents(tmp.Atoi());
 
     in.getline(line,80);  
     tmp = line;
     pos = tmp.First(" ");
     tmp = tmp(0,pos);
-    cfg.fMaxEvents = tmp.Atoi();
+    cfg.SetMaxEvents(tmp.Atoi());
 
     in.getline(line,80);  
     tmp = line;
     pos = tmp.First(" ");
     tmp = tmp(0,pos);
-    cfg.fWithWarnings = tmp.Atoi();
+    if (tmp.Atoi() != 0) cfg.SetWithWarnings();
     
-    return true;
+    in.getline(line,80);  
+    tmp = line;
+    pos = tmp.First(" ");
+    tmp = tmp(0,pos);
+    if (tmp.Atoi() != 0) cfg.SetUseFastDecoder();
+    
+    in.getline(line,80);  
+    tmp = line;
+    pos = tmp.First(" ");
+    tmp = tmp(0,pos);
+    cfg.SetThrLocN(tmp.Atof());
+
+    in.getline(line,80);  
+    tmp = line;
+    pos = tmp.First(" ");
+    tmp = tmp(0,pos);
+    cfg.SetThrLocD(tmp.Atof());
+
+    in.getline(line,80);  
+    tmp = line;
+    pos = tmp.First(" ");
+    tmp = tmp(0,pos);
+    cfg.SetDAMode(tmp.Atoi());
+
+    return kTRUE;
 
 }
 
 //__________________________________________________________________
-void WriteLastCurrentFile(DAConfig& cfg, TString currentFile)
+void WriteLastCurrentFile(AliDAConfig& cfg, TString currentFile)
 {
+    /// write last current file
 
-    // write last current file
     ofstream out;
     TString file;
     file = currentFile;
     out.open(file.Data());
-    out << cfg.fSodName << " " << cfg.fSodFlag << endl;
-    out << cfg.fDAName  << " " << cfg.fDAFlag  << endl;
+    out << cfg.GetSodName() << " " << cfg.GetSodFlag() << endl;
+    out << cfg.GetDAName()  << " " << cfg.GetDAFlag()  << endl;
 
-    out << cfg.fGlobalFileName    << " " << cfg.fGlobalFileVersion    << endl;
-    out << cfg.fRegionalFileName  << " " << cfg.fRegionalFileVersion  << endl;
-    out << cfg.fLocalMaskFileName << " " << cfg.fLocalMaskFileVersion << endl;
-    out << cfg.fLocalLutFileName  << " " << cfg.fLocalLutFileVersion  << endl;
-    out << cfg.fSignatureFileName << " " << cfg.fSignatureFileVersion << endl;
+    out << cfg.GetGlobalFileName()    << " " << cfg.GetGlobalFileVersion()    << endl;
+    out << cfg.GetRegionalFileName()  << " " << cfg.GetRegionalFileVersion()  << endl;
+    out << cfg.GetLocalMaskFileName() << " " << cfg.GetLocalMaskFileVersion() << endl;
+    out << cfg.GetLocalLutFileName()  << " " << cfg.GetLocalLutFileVersion()  << endl;
+    out << cfg.GetSignatureFileName() << " " << cfg.GetSignatureFileVersion() << endl;
 
     out.close();
 }
 
 //___________________________________________________________________________________________
-Bool_t ReadCurrentFile(DAConfig& cfg, TString currentFile, Bool_t lastCurrentFlag = false)
+Bool_t ReadCurrentFile(AliDAConfig& cfg, TString currentFile, Bool_t lastCurrentFlag = kFALSE)
 {
+    /// read last current file name and version
 
-    // read last current file name and version
     char line[80];
     char name[80];
+    Int_t flag;
 
     TString file;
     file = currentFile;
     std::ifstream in(gSystem->ExpandPathName(file.Data()));
     if (!in.good()) {
       printf("Cannot open last current file %s\n",currentFile.Data());
-      return false;
+      return kFALSE;
     }
     
     // read SOD 
     in.getline(line,80);  
-    sscanf(line, "%s %d", name, &cfg.fSodFlag);
-    cfg.fSodName = name;
-    if (cfg.fPrintLevel) printf("Sod Flag %d\n", cfg.fSodFlag);
+    sscanf(line, "%s %d", name, &flag);
+    cfg.SetSodName(name);
+    cfg.SetSodFlag(flag);
+    if (cfg.GetPrintLevel()) printf("Sod Flag %d\n", cfg.GetSodFlag());
 
     //read DA
     in.getline(line,80);    
-    sscanf(line, "%s %d", name, &cfg.fDAFlag);
-    cfg.fDAName = name;
-    if (cfg.fPrintLevel) printf("DA Flag: %d\n", cfg.fDAFlag);
+    sscanf(line, "%s %d", name, &flag);
+    cfg.SetDAName(name);
+    cfg.SetDAFlag(flag);
+    if (cfg.GetPrintLevel()) printf("DA Flag: %d\n", cfg.GetDAFlag());
 
     // read global
     in.getline(line,80);    
     TString tmp(line);
     Int_t pos =  tmp.First(" ");
-    cfg.fGlobalFileName = tmp(0, pos);
+    TString tmp1 = tmp(0, pos);
+    cfg.SetGlobalFileName(tmp1.Data());
     
     if (!lastCurrentFlag) {
-       cfg.fGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-       if (cfg.fPrintLevel) printf("Global File Name: %s version: %d\n", 
-                           cfg.fGlobalFileName.Data(), cfg.fGlobalFileVersion);
+      cfg.SetGlobalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Global File Name: %s version: %d\n", 
+                                     cfg.GetGlobalFileName(), cfg.GetGlobalFileVersion());
     } else {
-       cfg.fGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-       if (cfg.fPrintLevel) printf("Global File Name: %s last version: %d\n", 
-                               cfg.fGlobalFileName.Data(), cfg.fGlobalFileLastVersion);
+      cfg.SetGlobalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Global File Name: %s last version: %d\n", 
+                                     cfg.GetGlobalFileName(), cfg.GetGlobalFileLastVersion());
     }
 
     // read regional
     in.getline(line,80);
     tmp = line;
     pos = tmp.First(" ");
-    cfg.fRegionalFileName = tmp(0, pos);
+    tmp1 = tmp(0, pos);
+    cfg.SetRegionalFileName(tmp1.Data());
 
     if (!lastCurrentFlag) {
-       cfg.fRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-       if (cfg.fPrintLevel) printf("Regional File Name: %s version: %d\n", 
-                               cfg.fRegionalFileName.Data(), cfg.fRegionalFileVersion);
+      cfg.SetRegionalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Regional File Name: %s version: %d\n", 
+                                     cfg.GetRegionalFileName(), cfg.GetRegionalFileVersion());
 
     } else {
-       cfg.fRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-       if (cfg.fPrintLevel) printf("Regional File Name: %s last version: %d\n", 
-                               cfg.fRegionalFileName.Data(), cfg.fRegionalFileLastVersion);
+      cfg.SetRegionalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Regional File Name: %s last version: %d\n", 
+                                     cfg.GetRegionalFileName(), cfg.GetRegionalFileLastVersion());
     }
 
     // read mask
     in.getline(line,80);    
     tmp = line;
     pos = tmp.First(" ");
-    cfg.fLocalMaskFileName = tmp(0, pos);
+    tmp1 = tmp(0, pos);
+    cfg.SetLocalMaskFileName(tmp1.Data());
 
     if (!lastCurrentFlag) {
-      cfg.fLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-      if (cfg.fPrintLevel) printf("Mask File Name: %s version: %d\n", 
-                           cfg.fLocalMaskFileName.Data(), cfg.fLocalMaskFileVersion);
+      cfg.SetLocalMaskFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Mask File Name: %s version: %d\n", 
+                                     cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileVersion());
     } else {
-      cfg.fLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-      if (cfg.fPrintLevel) printf("Mask File Name: %s last version: %d\n", 
-                           cfg.fLocalMaskFileName.Data(), cfg.fLocalMaskFileLastVersion);
+      cfg.SetLocalMaskFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Mask File Name: %s last version: %d\n", 
+                                     cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileLastVersion());
     }
     // read Lut
     in.getline(line,80);    
     tmp = line;
     pos = tmp.First(" ");
-    cfg.fLocalLutFileName = tmp(0, pos);
+    tmp1 = tmp(0, pos);
+    cfg.SetLocalLutFileName(tmp1.Data());
 
     if (!lastCurrentFlag) {
-       cfg.fLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-       if (cfg.fPrintLevel) printf("Lut File Name: %s version: %d\n", 
-                               cfg.fLocalLutFileName.Data(), cfg.fLocalLutFileVersion);
+      cfg.SetLocalLutFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n", 
+                                     cfg.GetLocalLutFileName(), cfg.GetLocalLutFileVersion());
     } else {
-       cfg.fLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-       if (cfg.fPrintLevel) printf("Lut File Name: %s last version: %d\n", 
-                               cfg.fLocalLutFileName.Data(), cfg.fLocalLutFileLastVersion);
+      cfg.SetLocalLutFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+      if (cfg.GetPrintLevel()) printf("Lut File Name: %s last version: %d\n", 
+                                     cfg.GetLocalLutFileName(), cfg.GetLocalLutFileLastVersion());
     }
 
     in.getline(line,80);    
     tmp = line;
     pos = tmp.First(" ");
-    cfg.fSignatureFileName = tmp(0, pos);
-    cfg.fSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
-    if (cfg.fPrintLevel) printf("Lut File Name: %s version: %d\n", 
-                           cfg.fSignatureFileName.Data(), cfg.fSignatureFileVersion);
+    tmp1 = tmp(0, pos);
+    cfg.SetSignatureFileName(tmp1.Data());
+    cfg.SetSignatureFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
+    if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n", 
+                                   cfg.GetSignatureFileName(), cfg.GetSignatureFileVersion());
 
-    return true;
+    return kTRUE;
 }
 
 //_____________
-void ReadFileNames(DAConfig& cfg)
+void ReadFileNames(AliDAConfig& cfg)
 {
+  /// if last current file does not exist than read current file
 
-    // if last current file does not exist than read current file
-    if (!ReadCurrentFile(cfg,cfg.fLastCurrentFileName, true)) 
+  if (!ReadCurrentFile(cfg,cfg.GetLastCurrentFileName(), kTRUE)) 
     {
-      ReadCurrentFile(cfg,cfg.fCurrentFileName, true);
+      ReadCurrentFile(cfg,cfg.GetCurrentFileName(), kTRUE);
     } 
-
-    // any case read current file
-    ReadCurrentFile(cfg,cfg.fCurrentFileName);
-
+  
+  // any case read current file
+  ReadCurrentFile(cfg,cfg.GetCurrentFileName());
+  
 }
 
 //__________________
-Bool_t ExportFiles(DAConfig& cfg)
+Bool_t ExportFiles(AliDAConfig& cfg)
 {
+    /// Export files to FES
 
-    // Export files to FES
     // env variables have to be set (suppose by ECS ?)
     // setenv DATE_FES_PATH
     // setenv DATE_RUN_NUMBER
     // setenv DATE_ROLE_NAME
     // setenv DATE_DETECTOR_CODE
 
-    // offline:
-    //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
-
-    // offline: use a dummy FES (local directory)
-    //gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/FES");
+#ifdef OFFLINE
+    gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
+    gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/FES");
+#endif
 
     // update files
     Int_t status = 0;
 
-    Bool_t modified = false;
+    Bool_t modified = kFALSE;
+    Bool_t globalExported = kFALSE;
 
     ofstream out;
     TString fileExp("ExportedFiles.dat");
@@ -408,217 +714,230 @@ Bool_t ExportFiles(DAConfig& cfg)
     out.open(fileExp.Data());
     if (!out.good()) {
        printf("Failed to create file: %s\n",file.Data());
-       return false;
+       return kFALSE;
     }      
 
     // check if MtgLastCurrent.dat exists
     // if not, do initial export of all files
-    Bool_t initFES = false;
+    Bool_t initFES = kFALSE;
     if (gSystem->AccessPathName("MtgLastCurrent.dat"))
-      initFES = true;
+      initFES = kTRUE;
     if (initFES) printf("Copy all configuration files to the FES.\n");
 
-    file = cfg.fGlobalFileName;
-    if ((cfg.fGlobalFileLastVersion != cfg.fGlobalFileVersion) || initFES) {
-      status = daqDA_FES_storeFile(file.Data(), file.Data());
+    file = cfg.GetLocalMaskFileName();  
+    if ((cfg.GetLocalMaskFileLastVersion() != cfg.GetLocalMaskFileVersion()) || initFES) {
+      modified = kTRUE;
+      status = daqDA_FES_storeFile(file.Data(), "LOCAL");
       if (status) {
-       printf("Failed to export file: %s\n",cfg.fGlobalFileName.Data());
-       return false;
+       printf("Failed to export file: %s\n",cfg.GetLocalMaskFileName());
+       return kFALSE;
       }
-      if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fGlobalFileName.Data());
-      out << cfg.fGlobalFileName.Data() << endl;
+      if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalMaskFileName());
+      out << cfg.GetLocalMaskFileName() << endl;
     }
 
-    file = cfg.fLocalMaskFileName;  
-    if ((cfg.fLocalMaskFileLastVersion != cfg.fLocalMaskFileVersion) || initFES) {
-      modified = true;
-      status = daqDA_FES_storeFile(file.Data(), file.Data());
+    file = cfg.GetLocalLutFileName();
+    if ((cfg.GetLocalLutFileLastVersion() != cfg.GetLocalLutFileVersion()) || initFES) {
+      modified = kTRUE;
+      status = daqDA_FES_storeFile(file.Data(), "LUT");
       if (status) {
-       printf("Failed to export file: %s\n",cfg.fLocalMaskFileName.Data());
-       return false;
+       printf("Failed to export file: %s\n",cfg.GetLocalLutFileName());
+       return kFALSE;
       }
-      if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fLocalMaskFileName.Data());
-      out << cfg.fLocalMaskFileName.Data() << endl;
+      if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalLutFileName());
+      out << cfg.GetLocalLutFileName() << endl;
+
     }
 
-    file = cfg.fLocalLutFileName;
-    if ((cfg.fLocalLutFileLastVersion != cfg.fLocalLutFileVersion) || initFES) {
-      modified = true;
-      status = daqDA_FES_storeFile(file.Data(), file.Data());
+    file = cfg.GetGlobalFileName();
+    if ((cfg.GetGlobalFileLastVersion() != cfg.GetGlobalFileVersion()) || modified || initFES) {
+      modified = kTRUE;
+      globalExported = kTRUE;
+      status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
       if (status) {
-       printf("Failed to export file: %s\n",cfg.fLocalLutFileName.Data());
-       return false;
+       printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
+       return kFALSE;
       }
-      if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fLocalLutFileName.Data());
-      out << cfg.fLocalLutFileName.Data() << endl;
-
+      if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
+      out << cfg.GetGlobalFileName() << endl;
     }
 
-    // exported regional file whenever mask or/and Lut are modified
-    file = cfg.fRegionalFileName;
-    if ( (cfg.fRegionalFileLastVersion != cfg.fRegionalFileVersion) || modified || initFES) {
-      status = daqDA_FES_storeFile(file.Data(), file.Data());
+    file = cfg.GetRegionalFileName();
+    if ( (cfg.GetRegionalFileLastVersion() != cfg.GetRegionalFileVersion()) || modified || initFES) {
+      status = daqDA_FES_storeFile(file.Data(), "REGIONAL");
       if (status) {
-       printf("Failed to export file: %s\n",cfg.fRegionalFileName.Data());
-       return false;
+       printf("Failed to export file: %s\n",cfg.GetRegionalFileName());
+       return kFALSE;
+      }
+      if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetRegionalFileName());
+      out << cfg.GetRegionalFileName() << endl;
+
+      // needed for the initialisation of the mapping
+      if (!globalExported) {
+       file = cfg.GetGlobalFileName();
+       status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
+       if (status) {
+         printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
+         return kFALSE;
+       }
+       if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
+       out << cfg.GetGlobalFileName() << endl;
       }
-      if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fRegionalFileName.Data());
-      out << cfg.fRegionalFileName.Data() << endl;
+
     }
 
     out.close();
 
     // export Exported file to FES anyway
-    status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
+    status = daqDA_FES_storeFile(fileExp.Data(), "EXPORTED");
     if (status) {
       printf("Failed to export file: %s\n", fileExp.Data());
-      return false;
+      return kFALSE;
     }
-    if(cfg.fPrintLevel) printf("Export file: %s\n",fileExp.Data());
+    if(cfg.GetPrintLevel()) printf("Export file: %s\n",fileExp.Data());
 
     // write last current file
-    WriteLastCurrentFile(cfg,cfg.fLastCurrentFileName);
+    WriteLastCurrentFile(cfg,cfg.GetLastCurrentFileName());
 
-    return true;
+    return kTRUE;
 }
 
 //__________________
-Bool_t ImportFiles(DAConfig& cfg)
+Bool_t ImportFiles(AliDAConfig& cfg)
 {
-    // copy locally a file from daq detector config db 
-    // The current detector is identified by detector code in variable
-    // DATE_DETECTOR_CODE. It must be defined.
-    // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
-    // instead of the database. The usual environment variables are not needed.
+    /// copy locally a file from daq detector config db 
+    /// The current detector is identified by detector code in variable
+    /// DATE_DETECTOR_CODE. It must be defined.
+    /// If environment variable DAQDA_TEST_DIR is defined, files are copied from 
+    /// DAQDA_TEST_DIR instead of the database. 
+    /// The usual environment variables are not needed.
 
     Int_t status = 0;
 
-    // offline:
-    //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
+#ifdef OFFLINE
+    gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
+#endif
 
-    status = daqDA_DB_getFile(cfg.fDAConfigFileName.Data(), cfg.fDAConfigFileName.Data());
+    status = daqDA_DB_getFile(cfg.GetDAConfigFileName(), cfg.GetDAConfigFileName());
     if (status) {
-      printf("Failed to get DA config file from DB: %s\n",cfg.fDAConfigFileName.Data());
-      return false;
+      printf("Failed to get DA config file from DB: %s\n",cfg.GetDAConfigFileName());
+      return kFALSE;
     }
  
     ReadDAConfig(cfg);
-
-    status = daqDA_DB_getFile(cfg.fCurrentFileName.Data(), cfg.fCurrentFileName.Data());
+    
+    status = daqDA_DB_getFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
     if (status) {
-      printf("Failed to get current config file from DB: %s\n",cfg.fCurrentFileName.Data());
-      return false;
+      printf("Failed to get current config file from DB: %s\n",cfg.GetCurrentFileName());
+      return kFALSE;
     }
+    
     ReadFileNames(cfg);
 
-    status = daqDA_DB_getFile(cfg.fGlobalFileName.Data(), cfg.fGlobalFileName.Data());
+    status = daqDA_DB_getFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
     if (status) {
-      printf("Failed to get current config file from DB: %s\n", cfg.fGlobalFileName.Data());
-      return false;
+      printf("Failed to get current config file from DB: %s\n", cfg.GetGlobalFileName());
+      return kFALSE;
     }
 
-    status = daqDA_DB_getFile(cfg.fRegionalFileName.Data(), cfg.fRegionalFileName.Data());
+    status = daqDA_DB_getFile(cfg.GetRegionalFileName(), cfg.GetRegionalFileName());
     if (status) {
-      printf("Failed to get current config file from DB: %s\n",cfg.fRegionalFileName.Data());
-      return false;
+      printf("Failed to get current config file from DB: %s\n",cfg.GetRegionalFileName());
+      return kFALSE;
     }
 
-    status = daqDA_DB_getFile(cfg.fLocalMaskFileName.Data(), cfg.fLocalMaskFileName.Data());
+    status = daqDA_DB_getFile(cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileName());
     if (status) {
-      printf("Failed to get current config file from DB: %s\n",cfg.fLocalMaskFileName.Data());
-      return false;
+      printf("Failed to get current config file from DB: %s\n",cfg.GetLocalMaskFileName());
+      return kFALSE;
     }
 
-    status = daqDA_DB_getFile(cfg.fLocalLutFileName.Data(), cfg.fLocalLutFileName.Data());
+    status = daqDA_DB_getFile(cfg.GetLocalLutFileName(), cfg.GetLocalLutFileName());
     if (status) {
-      printf("Failed to get current config file from DB: %s\n",cfg.fLocalLutFileName.Data());
-      return false;
+      printf("Failed to get current config file from DB: %s\n",cfg.GetLocalLutFileName());
+      return kFALSE;
     }
  
-    return true;
+    return kTRUE;
 }
 
 //_____________
-void ReadMaskFiles(DAConfig& cfg)
+void ReadMaskFiles(AliDAConfig& cfg)
 {
+    /// read mask files
 
-    // read mask files
-    cfg.fLocalMasks    = new AliMUON1DArray(cfg.fNLocalBoard);
-    cfg.fRegionalMasks = new AliMUONRegionalTriggerConfig();
-    cfg.fGlobalMasks   = new AliMUONGlobalCrateConfig();
+    const Char_t* localFile    = cfg.GetLocalMaskFileName();
+    const Char_t* regionalFile = cfg.GetRegionalFileName();
+    const Char_t* globalFile   = cfg.GetGlobalFileName();
 
-    TString localFile    = cfg.fLocalMaskFileName;
-    TString regionalFile = cfg.fRegionalFileName;
-    TString globalFile   = cfg.fGlobalFileName;
-
-    cfg.fTriggerIO->ReadConfig(localFile.Data(), regionalFile.Data(), globalFile.Data(),
-                        cfg.fLocalMasks, cfg.fRegionalMasks, cfg.fGlobalMasks);                        
+    cfg.GetTriggerIO()->ReadConfig(localFile, regionalFile, globalFile, cfg.GetLocalMasks(), cfg.GetRegionalMasks(), cfg.GetGlobalMasks());                    
 }
 
 //______________________________________________________________
-UInt_t GetFetMode(DAConfig& cfg)
+UInt_t GetFetMode(const AliDAConfig & cfg)
 {
-  // FET mode = 3 to run algorithm for dead global inputs
-  // 0x3 prepulse
-  // 0x0 internal
+  /// FET mode = 3 to run algorithm for dead global inputs
+  /// 0x3 prepulse
+  /// 0x0 internal
 
-  return cfg.fGlobalMasks->GetFetRegister(3);
+  return cfg.GetGlobalMasks()->GetFetRegister(3);
 
 }
 
 //______________________________________________________________
-void StoreGlobalInput(DAConfig& cfg, const UInt_t * const globalInput) 
+void StoreGlobalInput(AliDAConfig& cfg, const UInt_t * const globalInput) 
 {
-  // accumulate and build statistics of global input values
+  /// accumulate and build statistics of global input values
   
-  for (Int_t ii = 0; ii < cfg.kGlobalInputs; ii++) {
-    for (Int_t ib = 0; ib < cfg.kGlobalInputLength; ib++) {
+  for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
+    for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
       // lsb -> msb
-      if (cfg.fAlgoNoisyInput)
-       cfg.fAccGlobalInputN[ii][ib] += (globalInput[ii] >> ib) & 0x1;
-      if (cfg.fAlgoDeadInput)
-       cfg.fAccGlobalInputD[ii][ib] += (globalInput[ii] >> ib) & 0x1;
+      if (cfg.GetAlgoNoisyInput())
+       cfg.AddAccGlobalInputN(ii,ib,((globalInput[ii] >> ib) & 0x1));
+      if (cfg.GetAlgoDeadcInput())
+       cfg.AddAccGlobalInputD(ii,ib,((globalInput[ii] >> ib) & 0x1));
     }
   }
 
 }
 
 //______________________________________________________________
-void UpdateGlobalMasks(DAConfig& cfg) 
+void UpdateGlobalMasks(AliDAConfig& cfg) 
 {
-  // update the global masks
+  /// update the global masks
   
-  // offline:
-  //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
+#ifdef OFFLINE
+  gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
+#endif
 
   Float_t rateN = 0.0, rateD = 0.0;
   UInt_t gmask[4], omask;
-  Bool_t noise, deadc, withEvN, withEvD, updated = false;
+  Bool_t noise, deadc, withEvN, withEvD, updated = kFALSE;
 
-  for (Int_t ii = 0; ii < cfg.kGlobalInputs; ii++) {
+  for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
     gmask[ii] = 0;
 
-    for (Int_t ib = 0; ib < cfg.kGlobalInputLength; ib++) {
+    for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
       // lsb -> msb
-      noise = false;
-      deadc = false;
-      withEvN = false;
-      withEvD = false;
-      if (cfg.fNEventsN > cfg.fMinEvents) {
-       rateN = (Float_t)cfg.fAccGlobalInputN[ii][ib]/(Float_t)cfg.fNEventsN;
-       noise = (rateN > cfg.fThrN);    
-       withEvN = true;
+      noise = kFALSE;
+      deadc = kFALSE;
+      withEvN = kFALSE;
+      withEvD = kFALSE;
+      if (cfg.GetEventsN() > cfg.GetMinEvents()) {
+       rateN = (Float_t)cfg.GetAccGlobalInputN(ii,ib)/(Float_t)cfg.GetEventsN();
+       noise = (rateN > cfg.GetThrN());        
+       withEvN = kTRUE;
       }
-      if (cfg.fNEventsD > cfg.fMinEvents) {
-       rateD = (Float_t)cfg.fAccGlobalInputD[ii][ib]/(Float_t)cfg.fNEventsD;
-       deadc = (rateD < cfg.fThrD);
-       withEvD = true;
+      if (cfg.GetEventsD() > cfg.GetMinEvents()) {
+       rateD = (Float_t)cfg.GetAccGlobalInputD(ii,ib)/(Float_t)cfg.GetEventsD();
+       deadc = (rateD < cfg.GetThrD());
+       withEvD = kTRUE;
       }
       if (!withEvN && !withEvD) {
        // - copy the bit from the old mask
-       gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib;
-       printf("Mask not changed (just copy the old values)\n");
+       gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
+       if (cfg.GetPrintLevel()) 
+         printf("Mask not changed (just copy the old values)\n");
       }
       if (!withEvN && withEvD) {
        if (!deadc) {
@@ -626,11 +945,12 @@ void UpdateGlobalMasks(DAConfig& cfg)
          //   not allowed!
          //gmask[ii] |= 0x1 << ib;
          // - copy the bit from the old mask
-         gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib;
+         gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
        } else {
          // - create a new mask, set the bit to 0
          gmask[ii] |= 0x0 << ib;
-         printf("Found dead  channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
+         if (cfg.GetPrintLevel()) 
+           printf("Found dead  channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
        }
       }
       if (withEvN && !withEvD) {
@@ -639,11 +959,12 @@ void UpdateGlobalMasks(DAConfig& cfg)
          //   not allowed!
          //gmask[ii] |= 0x1 << ib;
          // - copy the bit from the old mask
-         gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib;
+         gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
        } else {
          // - create a new mask, set the bit to 0
          gmask[ii] |= 0x0 << ib;
-         printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
+         if (cfg.GetPrintLevel()) 
+           printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
        }
       }
       if (withEvN && withEvD) {
@@ -652,26 +973,28 @@ void UpdateGlobalMasks(DAConfig& cfg)
          //   not allowed!
          //gmask[ii] |= 0x1 << ib;
          // - copy the bit from the old mask
-         gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib;
+         gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
        } else {
          // - create a new mask, set the bit to 0
          gmask[ii] |= 0x0 << ib;
-         if (noise)
-           printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
-         if (deadc)
-           printf("Found dead  channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
+         if (cfg.GetPrintLevel()) {
+           if (noise)
+             printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
+           if (deadc)
+             printf("Found dead  channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
+         }
        }
       }
     }
   }
 
   // check if at least one mask value has been changed from previous version
-  for (Int_t ii = 0; ii < cfg.kGlobalInputs; ii++) {
+  for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
     printf("Global mask [%1d] %08x \n",ii,gmask[ii]);
-    omask = cfg.fGlobalMasks->GetGlobalMask(ii);
+    omask = cfg.GetGlobalMasks()->GetGlobalMask(ii);
     if (gmask[ii] != omask) {
-      updated = true;
-      cfg.fGlobalMasks->SetGlobalMask(ii,gmask[ii]);
+      updated = kTRUE;
+      cfg.GetGlobalMasks()->SetGlobalMask(ii,gmask[ii]);
     }
   }
 
@@ -679,24 +1002,24 @@ void UpdateGlobalMasks(DAConfig& cfg)
   if (updated) {
     
     // update version
-    cfg.fGlobalFileVersion++;
+    cfg.IncGlobalFileVersion();
     
     // don't change the file version ("-x.dat")
     
-    cfg.fTriggerIO->WriteGlobalConfig(cfg.fGlobalFileName,cfg.fGlobalMasks);
+    cfg.GetTriggerIO()->WriteGlobalConfig(cfg.GetGlobalFileName(),cfg.GetGlobalMasks());
     
     // write last current file
-    WriteLastCurrentFile(cfg,cfg.fCurrentFileName);
+    WriteLastCurrentFile(cfg,cfg.GetCurrentFileName());
 
-    status = daqDA_DB_storeFile(cfg.fGlobalFileName.Data(), cfg.fGlobalFileName.Data());
+    status = daqDA_DB_storeFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
     if (status) {
-      printf("Failed to export file to DB: %s\n",cfg.fGlobalFileName.Data());
+      printf("Failed to export file to DB: %s\n",cfg.GetGlobalFileName());
       return;
     }
     
-    status = daqDA_DB_storeFile(cfg.fCurrentFileName.Data(), cfg.fCurrentFileName.Data());
+    status = daqDA_DB_storeFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
     if (status) {
-      printf("Failed to export file to DB: %s\n",cfg.fCurrentFileName.Data());
+      printf("Failed to export file to DB: %s\n",cfg.GetCurrentFileName());
       return;
     }
 
@@ -704,11 +1027,218 @@ void UpdateGlobalMasks(DAConfig& cfg)
   
 }
 
-//*************************************************************//
+//______________________________________________________________
+void UpdateLocalMask(AliDAConfig& cfg, Int_t localBoardId, Int_t connector, Int_t strip) 
+{
+
+  /// update local strip mask
+
+  AliMUONVCalibParam* localMask = 
+    static_cast<AliMUONVCalibParam*>(cfg.GetLocalMasksDA()->FindObject(localBoardId));
+  
+  UShort_t mask = static_cast<UShort_t>(localMask->ValueAsInt(connector,0)); 
+  
+  mask &= ~(0x1 << strip); // set strip mask to zero
+  
+  localMask->SetValueAsInt(connector, 0, mask);  
+
+}
+
+//______________________________________________________________
+void MakePattern(AliDAConfig& cfg, Int_t localBoardId, const TArrayS& xPattern, const TArrayS& yPattern) 
+{
+  /// calculate the hit map for each strip in x and y direction
+  
+  AliMUONVCalibParam* pat = 0x0;
+
+  if (cfg.GetAlgoNoisyInput())
+    pat = static_cast<AliMUONVCalibParam*>(cfg.GetPatternStoreN()->FindObject(localBoardId));
+  if (cfg.GetAlgoDeadcInput())
+    pat = static_cast<AliMUONVCalibParam*>(cfg.GetPatternStoreD()->FindObject(localBoardId));
+
+  if (!pat) {
+    pat = new AliMUONCalibParamND(2, 64, localBoardId, 0, 0.);
+    if (cfg.GetAlgoNoisyInput())
+      cfg.GetPatternStoreN()->Add(pat);        
+    if (cfg.GetAlgoDeadcInput())
+      cfg.GetPatternStoreD()->Add(pat);        
+  }
 
-// main routine
+  for (Int_t i = 0; i < 4; ++i) {
+    for (Int_t j = 0; j < 16; ++j) {
+       
+      Int_t xMask = xPattern[i];
+      Int_t yMask = yPattern[i];
+      
+      Int_t index = 16*i + j;
+      Double_t patOcc = 0.;
+      
+      if ( (xMask >> j ) & 0x1 ) {
+       patOcc  = pat->ValueAsDouble(index, 0) + 1.;
+       pat->SetValueAsDouble(index, 0, patOcc);
+      }
+      if ( (yMask >> j ) & 0x1 ) {
+       patOcc  = pat->ValueAsDouble(index, 1) + 1.;
+       pat->SetValueAsDouble(index, 1, patOcc);
+      }
+    }
+  }
+
+}
+
+//______________________________________________________________
+void MakePatternStore(AliDAConfig& cfg) 
+{
+  /// analyse patterns for local strips (calculate occupancy)
+  
+#ifdef OFFLINE
+  gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
+#endif
+
+  AliMUONVCalibParam* pat;
+  Int_t localBoardId = 0;
+  Int_t nEventsN = 0, nEventsD = 0;  
+  UShort_t strip = 0;
+  Int_t connector = 0;
+  Bool_t updated = kFALSE;
+  
+  if (cfg.GetEventsN() > cfg.GetMinEvents()) {
+    nEventsN = cfg.GetEventsN();
+  }
+  if (cfg.GetEventsD() > cfg.GetMinEvents()) {
+    nEventsD = cfg.GetEventsD();
+  }
+
+  // noisy strips
+  if (nEventsN > 0) {
+
+    TIter next(cfg.GetPatternStoreN()->CreateIterator());
+
+    while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) ) {
+      
+      localBoardId  = pat->ID0();
+      
+      for (Int_t index = 0; index < pat->Size(); index++) {
+       
+       Double_t patXOcc  = pat->ValueAsDouble(index, 0)/(Double_t)nEventsN;
+       Double_t patYOcc  = pat->ValueAsDouble(index, 1)/(Double_t)nEventsN;
+       
+       pat->SetValueAsDouble(index, 0, patXOcc);
+       pat->SetValueAsDouble(index, 1, patYOcc);
+       
+       // check for x strip
+       if (patXOcc > cfg.GetThrLocN()) {
+         strip  = index % 16;
+         connector = index/16;
+         UpdateLocalMask(cfg, localBoardId, connector, strip);
+       }
+       // check for y strip
+       if (patYOcc > cfg.GetThrLocN()) {
+         strip  = index % 16;
+         connector = index/16 + 4;
+         UpdateLocalMask(cfg, localBoardId, connector, strip);
+       }
+       
+      }
+    }
+    
+  }
+  
+  // dead strips
+  if (nEventsD > 0) {
+
+    TIter next(cfg.GetPatternStoreD()->CreateIterator());
+
+    while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) ) {
+      
+      localBoardId  = pat->ID0();
+      
+      for (Int_t index = 0; index < pat->Size(); index++) {
+       
+       Double_t patXOcc  = pat->ValueAsDouble(index, 0)/(Double_t)nEventsD;
+       Double_t patYOcc  = pat->ValueAsDouble(index, 1)/(Double_t)nEventsD;
+       
+       pat->SetValueAsDouble(index, 0, patXOcc);
+       pat->SetValueAsDouble(index, 1, patYOcc);
+       
+       // check for x strip
+       if (patXOcc < cfg.GetThrLocD()) {
+         strip  = index % 16;
+         connector = index/16;
+         UpdateLocalMask(cfg, localBoardId, connector, strip);
+       }
+       // check for y strip
+       if (patYOcc < cfg.GetThrLocD()) {
+         strip  = index % 16;
+         connector = index/16 + 4;
+         UpdateLocalMask(cfg, localBoardId, connector, strip);
+       }
+       
+      }
+    }
+    
+  }
+  
+  // make and AND with the previous version of the mask and
+  // check if the mask has changed
+  UShort_t maskDA, mask;
+  Int_t nMaskBits = AliMpConstants::TotalNofLocalBoards()*8*16;
+  Int_t nMaskBitsChanged = 0;
+  for (localBoardId = 1; localBoardId <= AliMpConstants::TotalNofLocalBoards(); localBoardId++) {
+    AliMUONVCalibParam* localMaskDA = static_cast<AliMUONVCalibParam*>(cfg.GetLocalMasksDA()->FindObject(localBoardId));
+    AliMUONVCalibParam* localMask = static_cast<AliMUONVCalibParam*>(cfg.GetLocalMasks()->FindObject(localBoardId));
+    for (connector = 0; connector < 8; connector++) {
+      maskDA = static_cast<UShort_t>(localMaskDA->ValueAsInt(connector,0)); 
+      mask = static_cast<UShort_t>(localMask->ValueAsInt(connector,0));
+      maskDA &= mask; 
+      localMaskDA->SetValueAsInt(connector, 0, maskDA);  
+      if (maskDA != mask) {
+       updated = kTRUE;
+       // calculated percentage of mask bits changed
+       for (Int_t iBit = 0; iBit < 16; iBit++) {
+         if (((maskDA >> iBit) & 0x1) != ((mask >> iBit) &0x1)) {
+           nMaskBitsChanged++;
+         }
+       }
+      }
+    }
+  }
+
+  printf("LOCAL mask bits changed = %5d (%7.3f %%) \n",nMaskBitsChanged,100*(Float_t)nMaskBitsChanged/(Float_t)nMaskBits);
+
+  Int_t status = 0;
+  if (updated) {
+
+    // update version
+    cfg.IncLocalMaskFileVersion();
+    
+    // don't change the file version ("-x.dat")
+    
+    cfg.GetTriggerIO()->WriteLocalMasks(cfg.GetLocalMaskFileName(),*cfg.GetLocalMasksDA());
+
+    // write last current file
+    WriteLastCurrentFile(cfg,cfg.GetCurrentFileName());
+
+    status = daqDA_DB_storeFile(cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileName());
+    if (status) {
+      printf("Failed to export file to DB: %s\n",cfg.GetLocalMaskFileName());
+      return;
+    }
+    
+    status = daqDA_DB_storeFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
+    if (status) {
+      printf("Failed to export file to DB: %s\n",cfg.GetCurrentFileName());
+      return;
+    }
+
+  }
+
+}
+
+//*************************************************************//
 int main(Int_t argc, Char_t **argv) 
 {
+    /// main routine
   
     // needed for streamer application
     gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()"); 
@@ -719,7 +1249,7 @@ int main(Int_t argc, Char_t **argv)
       return -1;
     }
 
-    DAConfig cfg;
+    AliDAConfig cfg;
 
     Char_t inputFile[256] = "";
     inputFile[0] = 0;
@@ -733,14 +1263,24 @@ int main(Int_t argc, Char_t **argv)
 
     // decoding the events
   
-    Int_t status;
+    Int_t status = 0;
     Int_t nDateEvents = 0;
 
     void* event;
 
     // containers
-    AliMUONDDLTrigger*       ddlTrigger  = 0x0;
-    AliMUONDarcHeader*       darcHeader  = 0x0;
+    // old decoder
+    AliMUONDDLTrigger*       ddlTrigger     = 0x0;
+    AliMUONDarcHeader*       darcHeader     = 0x0;
+    AliMUONRegHeader*        regHeader   = 0x0;
+    AliMUONLocalStruct*      localStruct = 0x0;
+    // new (fast) decoder
+    const AliMUONRawStreamTriggerHP::AliHeader*      darcHeaderHP  = 0x0;
+    const AliMUONRawStreamTriggerHP::AliLocalStruct* localStructHP = 0x0;
+
+    TArrayS xPattern(4);
+    TArrayS yPattern(4);
+    Int_t localBoardId = 0;
 
     TStopwatch timers;
 
@@ -755,32 +1295,48 @@ int main(Int_t argc, Char_t **argv)
     
     ReadMaskFiles(cfg);
 
-    // offline: the run number extracted from the file name
-    //TString tmp(inputFile);
-    //Int_t pos = tmp.First("daq");
-    //tmp = tmp(pos+3,5);
-    //gSystem->Setenv("DATE_RUN_NUMBER",tmp.Data());
-    //gSystem->Exec("echo \"DATE_RUN_NUMBER = \" $DATE_RUN_NUMBER");
-    
+#ifdef OFFLINE
+    // the run number extracted from the file name
+    TString tmp(inputFile);
+    Int_t pos1 = tmp.First('d');
+    Int_t pos2 = tmp.Last('.');
+    Int_t len  = pos2 - (pos1+3);
+    tmp = tmp(pos1+3,len);
+    gSystem->Setenv("DATE_RUN_NUMBER",tmp.Data());
+    gSystem->Exec("echo \"DATE_RUN_NUMBER = \" $DATE_RUN_NUMBER");
+#endif
+
     if(!ExportFiles(cfg)) {
       printf("ExportFiles failed\n");
       return -1;
     }
 
+    if (!cfg.GetDAFlag()) {
+
+      cout << "MUONTRGda: DA enable: " << cfg.GetDAFlag() << endl;
+      cout << "MUONTRGda: Print level: " << cfg.GetPrintLevel() << endl;
+      
+      printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
+
+      return status;
+
+    }
+
     // FET is triggered by CTP
+    Bool_t modeFET3 = kTRUE;
     if (GetFetMode(cfg) != 3) {
-      printf("FET is not in mode 3\n");
-      return -1;
+      printf("FET is not in mode 3. Only PHYSICS events will be analysed (noisy channels)\n");
+      modeFET3 = kFALSE;
     }
 
     // All 5 global cards are controlled by the Mts proxy
-    if (cfg.fGlobalMasks->GetGlobalCrateEnable() != 0x1F) {
+    if (cfg.GetGlobalMasks()->GetGlobalCrateEnable() != 0x1F) {
       printf("The MTS proxy does not control all global cards\n");
       return -1;
     }
 
     // The global cards are ON (active on the global inputs)
-    if (!cfg.fGlobalMasks->GetMasksOn()) {
+    if (!cfg.GetGlobalMasks()->GetMasksOn()) {
       printf("Global masks are not ON\n");
       return -1;
     }
@@ -808,25 +1364,26 @@ int main(Int_t argc, Char_t **argv)
 
     cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
 
-    UInt_t *globalInput;
-    Bool_t doUpdate = false;
+    UInt_t *globalInput = new UInt_t[4];
+    Bool_t doUpdate = kFALSE;
     Int_t runNumber = 0;
     Int_t nEvents = 0;
 
     while(1) 
     {
-      if (nEvents >= cfg.fMaxEvents) break;
-      if (nEvents && nEvents % 100 == 0)       
+      if (nEvents >= cfg.GetMaxEvents()) break;
+      if (cfg.GetPrintLevel()) {
+       if (nEvents && nEvents % 1000 == 0)     
          cout<<"Cumulated events " << nEvents << endl;
-
+      }
       // check shutdown condition 
       if (daqDA_checkShutdown()) 
          break;
 
       // Skip Events if needed
-      while (cfg.fSkipEvents) {
+      while (cfg.GetSkipEvents()) {
        status = monitorGetEventDynamic(&event);
-       cfg.fSkipEvents--;
+       cfg.DecSkipEvents();
       }
 
       // starts reading
@@ -848,43 +1405,87 @@ int main(Int_t argc, Char_t **argv)
       // CALIBRATION_EVENT 
       // SYSTEM_SOFTWARE_TRIGGER_EVENT
       // DETECTOR_SOFTWARE_TRIGGER_EVENT
-      cfg.fAlgoNoisyInput = false;
-      cfg.fAlgoDeadInput  = false;
+      cfg.SetAlgoNoisyInput(kFALSE);
+      cfg.SetAlgoDeadcInput(kFALSE);
       if (eventType == PHYSICS_EVENT) {
-       cfg.fAlgoNoisyInput = true;
-       doUpdate = true;
-       cfg.fNEventsN++;
-      } else if (eventType == CALIBRATION_EVENT) {
-       cfg.fAlgoDeadInput  = true;
-       doUpdate = true;
-       cfg.fNEventsD++;
+       cfg.SetAlgoNoisyInput(kTRUE);
+       doUpdate = kTRUE;
+       cfg.IncNoiseEvent();
+      } else if (modeFET3 && eventType == CALIBRATION_EVENT) {
+       cfg.SetAlgoDeadcInput(kTRUE);
+       doUpdate = kTRUE;
+       cfg.IncDeadcEvent();
       } else {
        continue;
       }
       
       nEvents++;
-      if (cfg.fPrintLevel) printf("\nEvent # %d\n",nEvents);
+      if (cfg.GetPrintLevel() == 2) printf("\nEvent # %d\n",nEvents);
 
       // decoding MUON payload
-      AliMUONRawStreamTrigger* rawStream  = new AliMUONRawStreamTrigger(rawReader);
+      AliMUONVRawStreamTrigger   *rawStream   = 0x0;
+      if (cfg.UseFastDecoder()) {
+       rawStream = new AliMUONRawStreamTriggerHP(rawReader);
+      } else {
+       rawStream = new AliMUONRawStreamTrigger(rawReader);
+      }
+
       // ... without warnings from the decoder !!!
-      if (!cfg.fWithWarnings)
+      if (!cfg.WithWarnings())
        rawStream->DisableWarnings();
 
       // loops over DDL 
       while((status = rawStream->NextDDL())) {
 
-       if (cfg.fPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
-
-       ddlTrigger = rawStream->GetDDLTrigger();
-       darcHeader = ddlTrigger->GetDarcHeader();
-
-       if (rawStream->GetDDL() == 0) {
-         if (cfg.fPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
+       if (cfg.GetPrintLevel() == 2) printf("iDDL %d\n", rawStream->GetDDL());
+
+       if (cfg.UseFastDecoder()) {
+         darcHeaderHP = static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetHeaders();
+         if (cfg.GetPrintLevel() == 2) printf("Global output (fast decoder) %x\n", (Int_t)darcHeaderHP->GetGlobalOutput());
+         for (Int_t ig = 0; ig < cfg.GetGlobalInputs(); ig++) {
+           globalInput[ig] = darcHeaderHP->GetGlobalInput(ig);
+         }
+         // loop over regional structure
+         Int_t nReg = (Int_t)static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetRegionalHeaderCount();
+         for(Int_t iReg = 0; iReg < nReg; iReg++) {
+           // loop over local structures
+           Int_t nLoc = (Int_t)static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetLocalStructCount(iReg);
+           for(Int_t iLoc = 0; iLoc < nLoc; iLoc++) {
+             localStructHP = static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetLocalStruct(iReg, iLoc);
+             localBoardId = cfg.GetTriggerIO()->LocalBoardId(rawStream->GetDDL(),iReg,localStructHP->GetId());
+             if (localBoardId > 0) {
+               localStructHP->GetXPattern(xPattern);
+               localStructHP->GetYPattern(yPattern);
+               MakePattern(cfg,localBoardId,xPattern,yPattern);
+             }
+           }
+         }
+       } else {
+         ddlTrigger = rawStream->GetDDLTrigger();
+         darcHeader = ddlTrigger->GetDarcHeader();
+         if (cfg.GetPrintLevel() == 2) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
          globalInput = darcHeader->GetGlobalInput();
+         // loop over regional structure
+         Int_t nReg = darcHeader->GetRegHeaderEntries();
+         for(Int_t iReg = 0; iReg < nReg; iReg++) {
+           regHeader = darcHeader->GetRegHeaderEntry(iReg);
+           // loop over local structures
+           Int_t nLoc = regHeader->GetLocalEntries();
+           for(Int_t iLoc = 0; iLoc < nLoc; iLoc++) {  
+             localStruct = regHeader->GetLocalEntry(iLoc);
+             localBoardId = cfg.GetTriggerIO()->LocalBoardId(rawStream->GetDDL(),iReg,localStruct->GetId());
+             if (localBoardId > 0) {
+               localStruct->GetXPattern(xPattern);
+               localStruct->GetYPattern(yPattern);
+               MakePattern(cfg,localBoardId,xPattern,yPattern);
+             }
+           }
+         }
+       }
+       if (rawStream->GetDDL() == 0) {
          StoreGlobalInput(cfg,globalInput);
        }
-
+       
       } // NextDDL
 
       delete rawReader;
@@ -893,32 +1494,33 @@ int main(Int_t argc, Char_t **argv)
     } // while (1)
 
     // update configuration files ifrequested event types were found
-    if (doUpdate && cfg.fDAFlag) 
-      UpdateGlobalMasks(cfg);
+    if (doUpdate) {
+      if (cfg.GetDAMode() > 0) UpdateGlobalMasks(cfg);
+      if (cfg.GetDAMode() > 1) MakePatternStore(cfg);
+    }
 
     timers.Stop();
 
-    cout << "MUONTRGda: DA enable: \t" << cfg.fDAFlag << endl;
-    cout << "MUONTRGda: Run number: \t" << runNumber << endl;
-    cout << "MUONTRGda: Nb of DATE events: \t" << nDateEvents << endl;
-    cout << "MUONTRGda: Nb of events used: \t" << nEvents << endl;
-    cout << "MUONTRGda: Nb of events used (noise): \t" << cfg.fNEventsN << endl;
-    cout << "MUONTRGda: Nb of events used (deadc): \t" << cfg.fNEventsD << endl;
-    cout << "MUONTRGda: Minumum nr of events for rate calculation: \t" << cfg.fMinEvents << endl;
-    cout << "MUONTRGda: Maximum nr of analyzed events: \t" << cfg.fMaxEvents << endl;
-    cout << "MUONTRGda: Skip events from start: \t" << cfg.fSkipEvents << endl;
-    cout << "MUONTRGda: Threshold for noisy inputs: \t" << 100*cfg.fThrN << "%" << endl;
-    cout << "MUONTRGda: Threshold for dead inputs: \t" << 100*cfg.fThrD << "%" << endl;
-    cout << "MUONTRGda: Print level: \t" << cfg.fPrintLevel << endl;
-    cout << "MUONTRGda: Show decoder warnings: \t" << cfg.fWithWarnings << endl;
+    cout << "MUONTRGda: DA enable: " << cfg.GetDAFlag() << endl;
+    cout << "MUONTRGda: Run number: " << runNumber << endl;
+    cout << "MUONTRGda: Nb of DATE events: " << nDateEvents << endl;
+    cout << "MUONTRGda: Nb of events used: " << nEvents << endl;
+    cout << "MUONTRGda: Nb of events used (noise): " << cfg.GetEventsN() << endl;
+    cout << "MUONTRGda: Nb of events used (deadc): " << cfg.GetEventsD() << endl;
+    cout << "MUONTRGda: Minumum nr of events for rate calculation: " << cfg.GetMinEvents() << endl;
+    cout << "MUONTRGda: Maximum nr of analyzed events: " << cfg.GetMaxEvents() << endl;
+    cout << "MUONTRGda: Skip events from start: " << cfg.GetSkipEvents() << endl;
+    cout << "MUONTRGda: Threshold for global noisy inputs: " << 100*cfg.GetThrN() << "%" << endl;
+    cout << "MUONTRGda: Threshold for global dead inputs: " << 100*cfg.GetThrD() << "%" << endl;
+    cout << "MUONTRGda: Threshold for local noisy inputs: " << 100*cfg.GetThrLocN() << "%" << endl;
+    cout << "MUONTRGda: Threshold for local dead inputs: " << 100*cfg.GetThrLocD() << "%" << endl;
+    cout << "MUONTRGda: Print level: " << cfg.GetPrintLevel() << endl;
+    cout << "MUONTRGda: Show decoder warnings: " << cfg.WithWarnings() << endl;
+    cout << "MUONTRGda: Use the fast decoder: " << cfg.UseFastDecoder() << endl;
+    cout << "MUONTRGda: DA mode (1=GLOBAL, 2=GLOBAL+LOCAL): " << cfg.GetDAMode() << endl;
 
     printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
 
-    delete cfg.fLocalMasks;
-    delete cfg.fRegionalMasks;
-    delete cfg.fGlobalMasks; 
-    delete cfg.fTriggerIO;
-
     return status;
 
 }