]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerIO.cxx
Renamed output file to Vertex.Performance.root
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerIO.cxx
index 549b15c74b20229db982728c0486076909901516..bc6a4cf0360b8dba9e481fba15043b47b1285794 100644 (file)
@@ -28,6 +28,9 @@
 #include "AliMpDDLStore.h"
 #include "AliMpLocalBoard.h"
 #include "AliMpTriggerCrate.h"
+#include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
+#include "AliMUONTriggerCrateConfig.h"
 
 #include "AliLog.h"
 
 ClassImp(AliMUONTriggerIO)
 /// \endcond
 
+
+const UInt_t AliMUONTriggerIO::fgkLocalLutSize = 1 << 14; // 16384
+
 //_____________________________________________________________________________
 AliMUONTriggerIO::AliMUONTriggerIO() 
     : TObject(), 
-      fRegionalTrigger(),
-      fGlobalCrate()
+      fRegionalTrigger()
 {
   /// ctor
 }
@@ -58,11 +63,10 @@ AliMUONTriggerIO::AliMUONTriggerIO()
 //_____________________________________________________________________________
 AliMUONTriggerIO::AliMUONTriggerIO(const char* regionalFileToRead) 
     :TObject(), 
-     fRegionalTrigger(),
-     fGlobalCrate()
+     fRegionalTrigger()
 {
   /// ctor
-  ReadRegional(regionalFileToRead,0);
+  ReadRegionalConfig(regionalFileToRead,0);
 }
 
 //_____________________________________________________________________________
@@ -205,11 +209,11 @@ AliMUONTriggerIO::ReadLocalMasks(const char* localFile, AliMUONVStore& localMask
   
   UShort_t maskBuffer[8];
   
-  Int_t nLocalBoards(0);
-  
+  Int_t localBoardIndex(0);
+    
   while ( fread ( maskBuffer, 2, 8, fp ) )
   {
-    Int_t localBoardId = LocalBoardId(nLocalBoards);
+    Int_t localBoardId = fRegionalTrigger.LocalBoardId(localBoardIndex);
     AliDebug(1,Form("LB %03d X1 %4x X2 %4x X3 %4x X4 %4x "
                     "Y1 %4x Y2 %4x Y3 %4x Y4 %4x",
                     localBoardId,
@@ -222,28 +226,32 @@ AliMUONTriggerIO::ReadLocalMasks(const char* localFile, AliMUONVStore& localMask
                     maskBuffer[6],
                     maskBuffer[7]));
     
-    if ( localBoardId ) 
+    if ( localBoardId > 0 
     {
       AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,localBoardId,0,0);
       for ( Int_t index = 0; index < 8; ++index )
       {
-       localBoard->SetValueAsInt(index,0,maskBuffer[index]);
+        localBoard->SetValueAsInt(index,0,maskBuffer[index]);
       }
       localMasks.Add(localBoard);
     }
+    else
+    {
+      AliError(Form("Oups. Got localBoardId=%d for index=%d",localBoardId,localBoardIndex));
+    }
     
-    ++nLocalBoards;
+    ++localBoardIndex;
   }
   
-  if ( nLocalBoards != NofLocalBoards() ) 
+  if ( localBoardIndex != NofLocalBoards() ) 
   {
     AliError(Form("Read %d out of %d local boards",
-                  nLocalBoards, NofLocalBoards()));
+                  localBoardIndex, NofLocalBoards()));
   }
   
   fclose(fp);
   
-  return nLocalBoards;
+  return localBoardIndex+1;
 }
 
 //_____________________________________________________________________________
@@ -256,7 +264,7 @@ AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
 
   UShort_t address;
   
-  UChar_t buffer[16384];   // 32768 hpt/lpt addresses divided by two
+  UChar_t buffer[fgkLocalLutSize];   // 32768 hpt/lpt addresses divided by two
   UChar_t mask1 = 0xF0;
   UChar_t mask2 = 0x0F;
   UChar_t maskHpt = 0x0C;
@@ -275,10 +283,10 @@ AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
   Bool_t trigx = kFALSE;
   
   // read two lut addresses at once, 32768/2=16384 times
-  fread(buffer,16384,1,flut);
+  fread(buffer,fgkLocalLutSize,1,flut);
 
   // create the 32767 addresses for the 4-bits lpt and hpt half-bytes
-  for (UShort_t ilut = 0; ilut < 32768; ilut += 2) 
+  for (UShort_t ilut = 0; ilut < fgkLocalLutSize*2; ilut += 2) 
   {
     
     // 1st 4-bits half-byte
@@ -364,7 +372,7 @@ AliMUONTriggerIO::ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut)
   
   for ( Int_t i = 0; i < NofLocalBoards(); ++i ) 
   {
-    ReadLocalLUT(lut,LocalBoardId(i),flut);
+    ReadLocalLUT(lut,fRegionalTrigger.LocalBoardId(i),flut);
   }
   
   fclose(flut);
@@ -375,107 +383,79 @@ AliMUONTriggerIO::ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut)
 
 //_____________________________________________________________________________
 Bool_t 
-AliMUONTriggerIO::ReadMasks(const char* localFile,
-                            const char* regionalFile,
-                            const char* globalFile,
-                            AliMUONVStore* localMasks,
-                            AliMUONVStore* regionalMasks,
-                            AliMUONVCalibParam* globalMasks,
-                            Bool_t warn)
+AliMUONTriggerIO::ReadConfig(const char* localFile,
+                             const char* regionalFile,
+                             const char* globalFile,
+                             AliMUONVStore* localMasks,
+                             AliMUONRegionalTriggerConfig* regionalConfig,
+                             AliMUONGlobalCrateConfig* globalConfig)
 {
   /// Fill the various masks store from files
   
-  if ( !regionalFile ) 
+  if ( !regionalFile || strlen(regionalFile)==0 
   {
     AliError("Must have a regional file name to proceeed");
     return kFALSE;
   }
   
-  Int_t nCrates = ReadRegional(regionalFile,regionalMasks, warn);
+  AliDebug(1,Form("regionalConfig=%p",regionalConfig));
   
-  if (!nCrates) return kFALSE;
+  Int_t nCrates = ReadRegionalConfig(regionalFile, regionalConfig);
+
+  if (!nCrates) 
+  {
+    AliError("nCrates=0 !");
+    return kFALSE;
+  }
   
-  if (localMasks && localFile)
+  if (localMasks && localFile && strlen(localFile) > 0 )
   {
     Int_t nLocal = ReadLocalMasks(localFile,*localMasks);
     AliDebug(1,Form("Read masks for %d local boards",nLocal));
   }
   
-  Int_t nDarc = ReadGlobal(globalFile, globalMasks);
-  AliDebug(1,Form("Read disable for %d DARC boards",nDarc));
+  Int_t nDarc = ReadGlobalConfig(globalFile, globalConfig);
+  AliDebug(1,Form("Read config for %d DARC boards",nDarc));
   
   if (!nDarc) return kFALSE;
   
   return kTRUE;
 }
 
+
+
 //_____________________________________________________________________________
  Int_t 
- AliMUONTriggerIO::ReadGlobal(const char* globalFile, AliMUONVCalibParam* globalMasks)
+ AliMUONTriggerIO::ReadGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig) const
 {
-  /// read the global crate file and file corresponding mask
+  /// read the global crate file
   /// the masks are disable bit for each crate, 8 per darc board
   /// bit value 0 means enable, 1 means disable                                                 * 
   
   Int_t nDarc = 0;
-  if ( ! fGlobalCrate.ReadData(globalFile) ) return 0;
-  
-  UChar_t mask    = fGlobalCrate.GetFirstDarcDisable();
-  ULong_t vmeAddr = fGlobalCrate.GetFirstDarcVmeAddr();   
-  if (vmeAddr) nDarc++;
-  globalMasks->SetValueAsInt(0,0,mask);
-  
-  mask    = fGlobalCrate.GetSecondDarcDisable();
-  vmeAddr = fGlobalCrate.GetSecondDarcVmeAddr();    
-  if (vmeAddr) nDarc++;
-  globalMasks->SetValueAsInt(1,0,mask);
+  if ( !(nDarc = globalConfig->ReadData(globalFile)) ) return 0;
   
   return nDarc;
 }
  
 //_____________________________________________________________________________
 Int_t
-AliMUONTriggerIO::ReadRegional(const char* regionalFile, AliMUONVStore* regionalMasks, Bool_t warn)
+AliMUONTriggerIO::ReadRegionalConfig(const char* regionalFile, AliMUONRegionalTriggerConfig* regionalConfig)
 {
-  /// Read regional file to fill the regional mask store *AND* 
-  /// determine the order in which local boards will appear in local 
-  /// and lut files.
+  /// Read regional file to fill  
   
-  if ( ! fRegionalTrigger.ReadData(regionalFile) ) return 0;
-
-  Int_t nCrates(0);
+  AliDebug(1,Form("regionalConfig=%p",regionalConfig));
   
-  for (Int_t iCrate = 0; iCrate < fRegionalTrigger.GetNofTriggerCrates(); ++iCrate) 
-  {
+  Int_t nCrates = 0;
+  if ( !(nCrates = regionalConfig->ReadData(regionalFile)) ) return 0;
+
+  // read the mapping file also
+  if ( ! fRegionalTrigger.ReadData(regionalFile) ) return 0;
 
-    AliMpTriggerCrate* crate = fRegionalTrigger.GetTriggerCrateFast(iCrate);
-    
-    if (warn)
-    {
-      AliMpTriggerCrate* triggerCrate = AliMpDDLStore::Instance()->GetTriggerCrate(crate->GetName());
-          
-      if (!triggerCrate)
-      {
-        AliError(Form("Mapping error : could not get crate %s", crate->GetName()));
-       return 0;
-      }
-    }
-    nCrates++;
-    
-    UShort_t masks = 0;
-    if (regionalMasks != 0x0) 
-    {
-      masks = crate->GetMask();
-      
-      AliMUONVCalibParam* regionalBoard = new AliMUONCalibParamNI(1, 1, crate->GetId(), 0, 0);
-      regionalBoard->SetValueAsInt(0, 0, masks);
-      regionalMasks->Add(regionalBoard);
-    } 
-  }
-   
   return nCrates;  
 }
 
+
 //_____________________________________________________________________________
 Bool_t 
 AliMUONTriggerIO::WriteLUT(const AliMUONTriggerLut& lut,
@@ -498,7 +478,7 @@ AliMUONTriggerIO::WriteLUT(const AliMUONTriggerLut& lut,
   
   for ( Int_t i = 0; i < NofLocalBoards(); ++i ) 
   {
-    WriteLocalLUT(lut,LocalBoardId(i),flut);
+    WriteLocalLUT(lut,fRegionalTrigger.LocalBoardId(i),flut);
   }
   
   fclose(flut);
@@ -506,30 +486,34 @@ AliMUONTriggerIO::WriteLUT(const AliMUONTriggerLut& lut,
   return kTRUE;
 }
 
+
 //_____________________________________________________________________________
-Bool_t
-AliMUONTriggerIO::WriteMasks(const char* localFile,
+Bool_t 
+AliMUONTriggerIO::WriteConfig(const char* localFile,
                             const char* regionalFile,
                             const char* globalFile,
                             AliMUONVStore* localMasks,
-                            AliMUONVStore* regionalMasks,
-                            AliMUONVCalibParam* globalMasks) const
+                    AliMUONRegionalTriggerConfig* regionalConfig,
+                    AliMUONGlobalCrateConfig* globalConfig) const
 {
-    /// write mask files
+/// write config files
+
     Bool_t ok;
-    ok  = WriteLocalMasks(localFile, *localMasks);
-    ok &= WriteRegional(regionalFile, regionalMasks);
-    ok &= WriteGlobal(globalFile, globalMasks);
+    ok  = WriteLocalMasks(localFile, *localMasks, regionalConfig);
+    ok &= WriteRegionalConfig(regionalFile, regionalConfig);
+    ok &= WriteGlobalConfig(globalFile, globalConfig);
     
     return ok;
+
+
 }
 
  //_____________________________________________________________________________
 Bool_t 
-AliMUONTriggerIO::WriteGlobal(const char* globalFile, AliMUONVCalibParam* globalMasks) const
+AliMUONTriggerIO::WriteGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig) const
 {
-    /// write global file
-    /// if no global masks defined take the one of configuration
+    /// write global config
 
   ofstream out;
   Int_t disable = 0;
@@ -537,73 +521,71 @@ AliMUONTriggerIO::WriteGlobal(const char* globalFile, AliMUONVCalibParam* global
   out.open(globalFile);
   if (!out.good())
   {
-    AliError(Form("Could not create output regional file %s", globalFile));
+    AliError(Form("Could not create output global file %s", globalFile));
     return kFALSE;
   }
    
-  out << fGlobalCrate.GetName() << endl;
-
+  out << globalConfig->GetName() << endl;
+  out << Form("0x%x",globalConfig->GetGlobalCrateEnable()) << endl;
+  
   // Jtag
-  out << fGlobalCrate.GetJtagName() << endl;
-  out << Form("0x%08x", fGlobalCrate.GetJtagVmeAddr()) << endl;
-  out << Form("%d %d %d", fGlobalCrate.GetJtagClockDiv(), 
-              fGlobalCrate.GetJtagRxPhase(), fGlobalCrate.GetJtagRdDelay()) << endl;
+  out << globalConfig->GetJtagName() << endl;
+  out << Form("0x%08x", globalConfig->GetJtagVmeAddr()) << endl;
+  out << Form("%d %d %d", globalConfig->GetJtagClockDiv(), 
+              globalConfig->GetJtagRxPhase(), globalConfig->GetJtagRdDelay()) << endl;
  
-  for (Int_t i = 0; i < fGlobalCrate.GetJtagNofLines(); ++i)
-    out << Form("%d ", fGlobalCrate.GetEnableJtag(i));
+  for (Int_t i = 0; i < globalConfig->GetJtagNofLines(); ++i)
+    out << Form("%d ", globalConfig->GetEnableJtag(i));
   out << endl;
 
   
-  for (Int_t i = 0; i < fGlobalCrate.GetJtagNofLines(); ++i)
+  for (Int_t i = 0; i < globalConfig->GetJtagNofLines(); ++i)
   {
     out << i << endl;
-    for (Int_t j = 0; j < fGlobalCrate.GetJtagNofLines(); ++j)
-      out << Form(" %s", fGlobalCrate.GetJtagCrateName(i,j).Data()) << endl;
+    for (Int_t j = 0; j < globalConfig->GetJtagNofLines(); ++j)
+      out << Form(" %s", globalConfig->GetJtagCrateName(i,j).Data()) << endl;
   }
   
   // first darc board
-  out << fGlobalCrate.GetFirstDarcName() << endl;
-  out << Form("0x%08x", fGlobalCrate.GetFirstDarcVmeAddr()) << endl;
-  out << fGlobalCrate.GetFirstDarcType() << endl;
-  if (globalMasks != 0x0)
-    disable = globalMasks->ValueAsInt(0);
-  else
-    disable = fGlobalCrate.GetFirstDarcDisable();
+  out << globalConfig->GetFirstDarcName() << endl;
+  out << Form("0x%08x", globalConfig->GetFirstDarcVmeAddr()) << endl;
+  out << globalConfig->GetFirstDarcType() << endl;
+  disable = globalConfig->GetFirstDarcDisable();
   out << Form("0x%02x", disable) << endl;
-  out << Form("0x%x", fGlobalCrate.GetFirstDarcL0Delay()) << endl;
-  out << Form("0x%x", fGlobalCrate.GetFirstDarcL1TimeOut()) << endl;
+  out << Form("0x%x", globalConfig->GetFirstDarcL0Delay()) << endl;
+  out << Form("0x%x", globalConfig->GetFirstDarcL1TimeOut()) << endl;
+  out << Form("0x%x", globalConfig->GetFirstDarcGlobalL0()) << endl;
+  out << Form("0x%x", globalConfig->GetFirstDarcConfig()) << endl;
   
   // second darc board
-  out << fGlobalCrate.GetSecondDarcName() << endl;
-  out << Form("0x%08x", fGlobalCrate.GetSecondDarcVmeAddr()) << endl;
-  out << fGlobalCrate.GetSecondDarcType() << endl;
-  if (globalMasks != 0x0)
-    disable = globalMasks->ValueAsInt(1);
-  else
-    disable = fGlobalCrate.GetSecondDarcDisable();
+  out << globalConfig->GetSecondDarcName() << endl;
+  out << Form("0x%08x", globalConfig->GetSecondDarcVmeAddr()) << endl;
+  out << globalConfig->GetSecondDarcType() << endl;
+  disable = globalConfig->GetSecondDarcDisable();
   out << Form("0x%02x", disable) << endl;
-  out << Form("0x%x", fGlobalCrate.GetSecondDarcL0Delay()) << endl;
-  out << Form("0x%x", fGlobalCrate.GetSecondDarcL1TimeOut()) << endl; 
+  out << Form("0x%x", globalConfig->GetSecondDarcL0Delay()) << endl;
+  out << Form("0x%x", globalConfig->GetSecondDarcL1TimeOut()) << endl; 
+  out << Form("0x%x", globalConfig->GetSecondDarcGlobalL0()) << endl; 
+  out << Form("0x%x", globalConfig->GetSecondDarcConfig()) << endl; 
   
   // global board
-  out << fGlobalCrate.GetGlobalName() << endl;
-  out << Form("0x%08x", fGlobalCrate.GetGlobalVmeAddr()) << endl;
-  for (Int_t i = 0; i < fGlobalCrate.GetGlobalNofRegisters(); ++i)
-    out << Form("0x%x", fGlobalCrate.GetGlobalRegister(i)) << endl;
+  out << globalConfig->GetGlobalName() << endl;
+  out << Form("0x%08x", globalConfig->GetGlobalVmeAddr()) << endl;
+  for (Int_t i = 0; i < globalConfig->GetGlobalNofRegisters(); ++i)
+    out << Form("0x%x", globalConfig->GetGlobalRegister(i)) << endl;
   
   // Fet board
-  out << fGlobalCrate.GetFetName() << endl;
-  out << Form("0x%08x", fGlobalCrate.GetFetVmeAddr()) << endl;
-  for (Int_t i = 0; i < fGlobalCrate.GetFetNofRegisters(); ++i)
-    out << Form("0x%x", fGlobalCrate.GetFetRegister(i)) << endl;
+  out << globalConfig->GetFetName() << endl;
+  out << Form("0x%08x", globalConfig->GetFetVmeAddr()) << endl;
+  for (Int_t i = 0; i < globalConfig->GetFetNofRegisters(); ++i)
+    out << Form("0x%x", globalConfig->GetFetRegister(i)) << endl;
   
   return kTRUE;
 }
  
-
 //_____________________________________________________________________________
 Bool_t
-AliMUONTriggerIO::WriteRegional(const char* regionalFile, AliMUONVStore* regionalMasks) const
+AliMUONTriggerIO::WriteRegionalConfig(const char* regionalFile, AliMUONRegionalTriggerConfig* regionalConfig) const
 {
 
     /// write regional mask with the current configuration
@@ -618,60 +600,78 @@ AliMUONTriggerIO::WriteRegional(const char* regionalFile, AliMUONVStore* regiona
       return kFALSE;
     }
 
-    for (Int_t iCrate = 0; iCrate < fRegionalTrigger.GetNofTriggerCrates(); ++iCrate) 
+    Int_t nCrate = fRegionalTrigger.GetNofTriggerCrates();
+    if (!nCrate)
     {
-      AliMpTriggerCrate* crate = fRegionalTrigger.GetTriggerCrateFast(iCrate);
-
-      out << crate->GetName()  << endl;
-      out << Form("%02x", crate->GetId())   << endl;
-      out << crate->GetMode()  << endl;
-      out << crate->GetCoinc() << endl;
-      
-      UShort_t masks = 0;
-      if (regionalMasks != 0x0) 
-      {
-        AliMUONVCalibParam* maskParam = 
-            static_cast<AliMUONVCalibParam*>(regionalMasks->FindObject(crate->GetId()));
-        masks = maskParam->ValueAsInt(0,0);
-      } 
-      else
-      {
-        masks = crate->GetMask();
-      } 
-      
-      out << Form("%04x", masks) << endl;
-      
-      for (Int_t iLocal = 0; iLocal < crate->GetNofLocalBoards(); ++iLocal) 
-      {
-       Int_t localBoardId = crate->GetLocalBoardId(iLocal);
-
-       AliMpLocalBoard* board = fRegionalTrigger.FindLocalBoard(localBoardId);
+      AliError("Could not write regional no configuration in memory");
+      return kFALSE;
+    }
 
-       out << Form("%02d ", board->GetSlot())  
-           << board->GetName() 
-           << Form(" %03d ", localBoardId) 
-           << Form("%03x", board->GetSwitch()) 
-           << endl;
-        out << " ";
-        for (Int_t i = 0; i < board->GetNofDEs(); ++i)
-          out << Form("%4d ", board->GetDEId(i));
-        out << endl;
-          
-          // print copy card numbers
-        out << Form(" %4d %4d", board->GetInputXfrom(), board->GetInputXto());
-        out << Form(" %4d %4d", board->GetInputYfrom(), board->GetInputYto());
-        out << Form(" %4d",     board->GetTC()) << endl;
+    Int_t nofDDLs = 0;
+    TString name;
+    AliMpTriggerCrate* crate;
+    for (Int_t ddlId = 0; ddlId < 2; ddlId++) // right & left side            
+      {
+       for (Int_t crateId = 0; crateId < 8; crateId++) // 8 crates/regional boards for each side.
+         {
+           
+           name = AliMpTriggerCrate::GenerateName(crateId, ddlId, nofDDLs);
+           
+           crate = fRegionalTrigger.FindTriggerCrate(name, false);
+           
+           AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(crate->GetName());
+           if (!crateConfig) 
+             {
+               AliError(Form("Cannot find crate %s in CDB", crate->GetName()));
+               return kFALSE;
+             }
+           
+           out << crate->GetName()  << endl;
+           out << Form("%02x", crate->GetId())   << endl;
+           out << crateConfig->GetMode()  << endl;
+           out << crateConfig->GetCoinc() << endl;
+           out << Form("%04x", crateConfig->GetMask()) << endl;
+           out << Form("%02d",crate->GetNofLocalBoards()) << endl;
+           
+           for (Int_t iLocal = 0; iLocal < crate->GetNofLocalBoards(); ++iLocal) 
+             {
+               Int_t localBoardId = crate->GetLocalBoardId(iLocal);
+               
+               AliMpLocalBoard* board = fRegionalTrigger.FindLocalBoard(localBoardId);
+               
+               out << Form("%02d ", board->GetSlot())  
+                   << board->GetName() 
+                   << Form(" %03d ", localBoardId) 
+                   << Form("%03x", board->GetSwitch()) 
+                   << endl;
+               
+               out << " ";
+               
+               if (board->IsNotified()) {
+                 for (Int_t i = 0; i < board->GetNofDEs(); ++i)
+                   out << Form("%4d ", board->GetDEId(i));
+               } else {
+                 out << Form("%4d ", 0);
+               }
+               out << endl;
+               
+               // print copy card numbers & TC
+               out << Form(" %4d %4d", board->GetInputXfrom(), board->GetInputXto());
+               out << Form(" %4d %4d", board->GetInputYfrom(), board->GetInputYto());
+               out << Form(" %4d",     board->GetTC()) << endl;
+             }
+         }
       }
-    }
+
     out.close();
     
     return kTRUE;
 }
 
+
 //_____________________________________________________________________________
 Bool_t 
-AliMUONTriggerIO::WriteLocalMasks(const char* localFile, AliMUONVStore& localMasks) const
+AliMUONTriggerIO::WriteLocalMasks(const char* localFile, AliMUONVStore& localMasks, AliMUONRegionalTriggerConfig* regionalConfig) const
 {
     /// write local mask
     /// removing/adding enable for a local board need a update of the configuration 
@@ -687,10 +687,11 @@ AliMUONTriggerIO::WriteLocalMasks(const char* localFile, AliMUONVStore& localMas
 
     UShort_t maskBuffer[8];
 
-    for (Int_t iCrate = 0; iCrate < fRegionalTrigger.GetNofTriggerCrates(); ++iCrate) 
-    {
-      AliMpTriggerCrate* crate = fRegionalTrigger.GetTriggerCrateFast(iCrate);
-      
+    TIter next(regionalConfig->CreateCrateIterator());
+    AliMUONTriggerCrateConfig* crate;
+    
+    while ( ( crate = static_cast<AliMUONTriggerCrateConfig*>(next()) ) )
+    {      
       UShort_t mask = crate->GetMask(); // getting mask from current config
 
       for (Int_t iLocal = 0; iLocal < crate->GetNofLocalBoards(); ++iLocal) 
@@ -732,10 +733,10 @@ AliMUONTriggerIO::WriteLocalLUT(const AliMUONTriggerLut& lut,
   const Int_t kMaskXdev = 0x1F;
   const Int_t kMaskXpos = 0x1F;
 
-  UChar_t buffer[16384];  // 32768 hpt/lpt addresses divided by two
+  UChar_t buffer[fgkLocalLutSize];  // 32768 hpt/lpt addresses divided by two
   Int_t bc = 0;
   
-  for (Int_t i = 0; i < 32768; ++i) 
+  for (UInt_t i = 0; i < fgkLocalLutSize*2; ++i) 
   {
     Int_t lutLpt[2] = { 0 };
     Int_t lutHpt[2] = { 0 };
@@ -815,80 +816,19 @@ AliMUONTriggerIO::LocalBoardId(Int_t index) const
 {  
   /// Return the i-th localBoardId, or -1 if index is out of bounds
 
-  AliMpLocalBoard* board = fRegionalTrigger.GetLocalBoard(index);
-  if ( ! board ) return -1;
-  
-  return board->GetId(); 
+  return fRegionalTrigger.LocalBoardId(index);
 }
 
-//_____________________________________________________________________________
-void 
-AliMUONTriggerIO::UpdateMapping(Bool_t writeFile) const
-{
-/// check if mapping in database different from current Mtg configuration
-/// Update mapping in databse and read regional crate file in repository (ext .out
-/// to avoid overwriting). This case has a low probability to happen.
-
-    // Assuming that crates do not change
 
-    if (!AliMpDDLStore::Instance(kFALSE))
-    {
-      AliMpCDB::LoadDDLStore();
-    }
-
-    Bool_t modified = false;
-
-    TExMapIter itr = AliMpDDLStore::Instance()->GetLocalBoardItr();
-
-    Long_t key, value;
-
-    while(itr.Next(key, value))
-    {
-      AliMpLocalBoard* boardMapping =  reinterpret_cast<AliMpLocalBoard*>(value);
-
-      Int_t localBoardId = boardMapping->GetId();
-      AliMpLocalBoard* board = fRegionalTrigger.FindLocalBoard(localBoardId);
-      if ( ! board ) {
-        AliFatal("Board found in mapping but not in regional trigger");
-        return;
-      }  
-
-      if ( board->GetCrate().CompareTo(boardMapping->GetCrate()) != 0 ) 
-      {
-       AliWarning(Form("Crate Name different for board %d (%s %s)", localBoardId, boardMapping->GetCrate().Data(), 
-                       board->GetCrate().Data()));
-       boardMapping->SetCrate( board->GetCrate() );
-       modified = true;
-      }
+//______________________________________________________________________________
 
-      if ((board->GetSlot()) != boardMapping->GetSlot()) 
-      {
-       AliWarning(Form("Slot different for board %d (%d %d)", localBoardId, boardMapping->GetSlot(), board->GetSlot()+1));
-       boardMapping->SetSlot(board->GetSlot());
-       modified = true;
-      }
-         
-      if (boardMapping->GetSwitch() != board->GetSwitch()) {
-       AliWarning(Form("Switch different for board %d (0x%x 0x%x)", localBoardId, 
-                       boardMapping->GetSwitch(), board->GetSwitch()));
-       boardMapping->SetSwitch(board->GetSwitch());
-       modified = true;
-      }
-    }
+Int_t AliMUONTriggerIO::LocalBoardId(Int_t ddlId, Int_t crateId, Int_t localId) const
+{
+    /// Return local board id from crate and local indexes.
     
-    if (modified) 
-    {
-      AliMpDDLStore::Instance()->SetRegionalTrigger(fRegionalTrigger);
-      AliMpCDB::WriteDDLStore(false);
-      AliWarning("Wrote new version of mapping in databse");
-      if (writeFile) 
-      {
-          TString file = AliMpFiles::LocalTriggerBoardMapping();
-          file += ".out";
-          WriteRegional(file.Data(), 0x0);
-          AliWarning(Form("Wrote regional file %s", file.Data()));
-
-      }
-    }
+    Int_t nofDDLs = 0;
+    TString name = AliMpTriggerCrate::GenerateName(crateId, ddlId, nofDDLs);
 
+    AliMpTriggerCrate* crate = fRegionalTrigger.FindTriggerCrate(name, false);
+    return crate->GetLocalBoardId(localId);
 }