]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpDDLStore.cxx
Hopefully sorting out the local board id versus index problems once for all...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDDLStore.cxx
index 8afaeab8967bffae3a3ddead6fb69be78b13435e..6933e64e9e0a777672492b87012dd3766cfd1cbe 100644 (file)
 //          Christian Finck, SUBATECH Nantes
 //-----------------------------------------------------------------------------
 
+#include <cstdlib>
 #include "AliMpDDLStore.h"
+#include "AliMpExMapIterator.h"
 #include "AliMpConstants.h"
 #include "AliMpDEStore.h"
+#include "AliMpFrtCrocusConstants.h"
 #include "AliMpDDL.h"
 #include "AliMpFiles.h"
+#include "AliMpDataStreams.h"
 #include "AliMpHelper.h"
 #include "AliMpDEManager.h"
+#include "AliMpManuStore.h"
 #include "AliMpDetElement.h"
 #include "AliMpBusPatch.h"
 #include "AliMpTriggerCrate.h"
@@ -41,6 +46,7 @@
 #include "AliMpSegmentation.h"
 #include "AliMpVSegmentation.h"
 #include "AliMpStringObjMap.h"
+
 #include "AliLog.h"
 
 #include <Riostream.h>
@@ -57,6 +63,8 @@ ClassImp(AliMpDDLStore)
 AliMpDDLStore* AliMpDDLStore::fgInstance = 0;
 const Int_t    AliMpDDLStore::fgkNofDDLs = 20;
 const Int_t    AliMpDDLStore::fgkNofTriggerDDLs = 2;
+const TString  AliMpDDLStore::fgkRevertKeyword = "REVERT"; 
+const TString  AliMpDDLStore::fgkExplicitKeyword = "EXPLICIT";
 
 //
 // static methods
@@ -76,7 +84,8 @@ AliMpDDLStore* AliMpDDLStore::Instance(Bool_t warn)
 }
 
 //______________________________________________________________________________
-AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn) 
+AliMpDDLStore* AliMpDDLStore::ReadData(const AliMpDataStreams& dataStreams,
+                                       Bool_t warn) 
 {
     /// Load the DDL store from ASCII data files
     /// and return its instance
@@ -87,9 +96,10 @@ AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn)
         return fgInstance;
     }
 
-    AliInfoClass("Reading DDL Store from ASCII files.");
+    if ( dataStreams.GetReadFromFiles() )
+      AliInfoClass("Reading Manu Store from ASCII files.");
 
-    fgInstance = new AliMpDDLStore();
+    fgInstance = new AliMpDDLStore(dataStreams);
     return fgInstance;
 }
 
@@ -98,15 +108,14 @@ AliMpDDLStore* AliMpDDLStore::ReadData(Bool_t warn)
 //
 
 //______________________________________________________________________________
-AliMpDDLStore::AliMpDDLStore()
+AliMpDDLStore::AliMpDDLStore(const AliMpDataStreams& dataStreams)
         : TObject(),
+        fDataStreams(dataStreams),
         fDDLs(fgkNofDDLs+fgkNofTriggerDDLs), // FIXEME
-        fBusPatches(true),
-        fTriggerCrates(true),
-        fLocalBoards(true),
+        fBusPatches(),
         fManuList12(),
         fManuBridge2(),
-        fGlobalCrate(new AliMpGlobalCrate())
+        fRegionalTrigger()
 {
     /// Standard constructor
 
@@ -114,36 +123,30 @@ AliMpDDLStore::AliMpDDLStore()
     fDDLs.SetOwner(true);
     fBusPatches.SetOwner(true);
     fBusPatches.SetSize(900);
-
-    fTriggerCrates.SetOwner(true);
-    fTriggerCrates.SetSize(16);
-
-    fLocalBoards.SetOwner(true);
-    fLocalBoards.SetSize(242); // included non-identied board
-
-
+    
     // Load segmentation & DE store data
     if ( ! AliMpSegmentation::Instance(false) )
-        AliMpSegmentation::ReadData(true);
+        AliMpSegmentation::ReadData(dataStreams, true);
 
     // Create all detection elements
     ReadDDLs();
-    ReadTriggerDDLs();
+    ReadTrigger();
+    SetTriggerDDLs();
     SetManus();
+    ReadBusPatchSpecial();
     SetPatchModules();
-    SetBusPatchLength();
+    ReadBusPatchInfo();
 }
 
 //______________________________________________________________________________
-AliMpDDLStore::AliMpDDLStore(TRootIOCtor* /*ioCtor*/)
+AliMpDDLStore::AliMpDDLStore(TRootIOCtor* ioCtor)
         : TObject(),
+        fDataStreams(ioCtor),
         fDDLs(),
-        fBusPatches(),
-        fTriggerCrates(true),
-        fLocalBoards(true),
-        fGlobalCrate()
+        fBusPatches(ioCtor),
+        fRegionalTrigger(ioCtor)
 {
-    /// Constructor for IO
+    /// Constructor for I0
 
     AliDebug(1,"");
 
@@ -162,7 +165,6 @@ AliMpDDLStore::~AliMpDDLStore()
     // Bus patches objects are deleted with fBusPatches
 
     fgInstance = 0;
-    delete fGlobalCrate;
 }
 
 //
@@ -201,212 +203,14 @@ Int_t AliMpDDLStore::GetBusPatchIndex(Int_t detElemId, Int_t manuId) const
     return pos;
 }
 
-//______________________________________________________________________________
-Bool_t  AliMpDDLStore::ReadGlobalTrigger(AliMpGlobalCrate& crate, const Char_t* globalName) 
-{
-    /// Fill trigger global crate object from ascii file
-    /// put the method static to be used by other class w/o initializing object
-  
-    TString infile;
-        
-    if (globalName == 0)
-      infile = AliMpFiles::GlobalTriggerBoardMapping();
-    else
-      infile = globalName;
-    
-    ifstream in(infile, ios::in);
-
-    if (!in) {
-        printf("Local Trigger Board Mapping File %s not found", infile.Data());
-        return kFALSE;
-    }
-
-    TArrayI list;
-
-    char line[255];
-    in.getline(line, 255);
-    TString tmp(AliMpHelper::Normalize(line));
-
-    if (!tmp.Contains(crate.GetName()))
-        printf("Wrong Global Crate File");
-
-    in.getline(line, 255);
-    tmp = AliMpHelper::Normalize(line);
-
-    if (tmp.Contains(crate.GetJtagName())) {
-        // vme addr
-        in.getline(line, 255);
-        TString tmp(AliMpHelper::Normalize(line));
-        ULong_t addr;
-        sscanf(tmp.Data(), "%lx", &addr);
-        crate.SetJtagVmeAddr(addr);
-        //AliDebug(1, Form("Jtag Vme Address: 0x%x", addr));
-
-        // clk div, rx phase, read delay
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        TArrayI list;
-        AliMpHelper::DecodeName(line, ' ', list);
-        crate.SetJtagClockDiv(list[0]);
-        crate.SetJtagRxPhase(list[1]);
-        crate.SetJtagRdDelay(list[2]);
-        //AliDebug(1, Form("Jtag Clock Div: %d, Rx Phase: %d, Read Delay %d", list[0], list[1], list[2]));
-
-        // enable
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        AliMpHelper::DecodeName(line, ' ', list);
-        UChar_t enable = 0;
-        for (Int_t i = 0; i < crate.GetJtagNofLines(); ++i)
-            enable |= (list[i] << i);
-        crate.SetEnableJtag(enable);
-        //AliDebug(1, Form("Jtag Enable: 0x%x", enable));
-
-        for (Int_t i = 0; i < crate.GetJtagNofLines(); ++i) {
-            in.getline(line, 255);
-            for (Int_t j = 0; j < crate.GetJtagNofLines(); ++j) {
-                in.getline(line, 255);
-                tmp = AliMpHelper::Normalize(line);
-                crate.SetJtagCrateName(i*crate.GetJtagNofLines() + j, tmp);
-                //AliDebug(1, Form("Jtag Crate Name: %s", tmp.Data()));
-            }
-        }
-    }
-
-    in.getline(line, 255);
-    tmp = AliMpHelper::Normalize(line);
-    if (tmp.Contains(crate.GetFirstDarcName())) {
-        // vme addr
-        in.getline(line, 255);
-        TString tmp(AliMpHelper::Normalize(line));
-        ULong_t addr;
-        sscanf(tmp.Data(), "%lx", &addr);
-        crate.SetFirstDarcVmeAddr(addr);
-        //AliDebug(1, Form("First Darc Vme Address: 0x%x", addr));
-
-        // type
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        crate.SetFirstDarcType(tmp.Atoi());
-        //AliDebug(1, Form("First Darc Type: %d", tmp.Atoi()));
-
-        // enable
-        in.getline(line, 255);
-        UInt_t item;
-        tmp = AliMpHelper::Normalize(line);
-        sscanf(tmp.Data(), "%x", &item);
-        crate.SetFirstDarcDisable(item);
-        //AliDebug(1, Form("First Darc Enable: 0x%x", item));
-
-        // L0
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        sscanf(tmp.Data(), "%x", &item);
-        crate.SetFirstDarcL0Delay(item);
-        //AliDebug(1, Form("First Darc L0 Delay: 0x%x", item));
-
-        // L1
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        sscanf(tmp.Data(), "%x", &item);
-        crate.SetFirstDarcL1TimeOut(item);
-        //AliDebug(1, Form("First Darc L1 Time Out: 0x%x", item));
-    }
-
-    in.getline(line, 255);
-    tmp = AliMpHelper::Normalize(line);
-    if (tmp.Contains(crate.GetSecondDarcName())) {
-        // vme addr
-        in.getline(line, 255);
-        TString tmp(AliMpHelper::Normalize(line));
-        ULong_t addr;
-        sscanf(tmp.Data(), "%lx", &addr);
-        crate.SetSecondDarcVmeAddr(addr);
-        //AliDebug(1, Form("Second Darc Vme Address: 0x%x", addr));
-        
-        // type
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        crate.SetSecondDarcType(tmp.Atoi());
-        //AliDebug(1, Form("Second Darc Type: %d", tmp.Atoi()));
-        
-        // enable
-        in.getline(line, 255);
-        UInt_t item;
-        tmp = AliMpHelper::Normalize(line);
-        sscanf(tmp.Data(), "%x", &item);
-        crate.SetSecondDarcDisable(item);
-        //AliDebug(1, Form("Second Darc Enable: 0x%x", item));
-        
-        // L0
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        sscanf(tmp.Data(), "%x", &item);
-        crate.SetSecondDarcL0Delay(item);
-        //AliDebug(1, Form("Second Darc L0 Delay: 0x%x", item));
-        
-        // L1
-        in.getline(line, 255);
-        tmp = AliMpHelper::Normalize(line);
-        sscanf(tmp.Data(), "%x", &item);
-        crate.SetSecondDarcL1TimeOut(item);
-        //AliDebug(1, Form("Second Darc L1 Time Out: 0x%x", item));
-    }
-
-    in.getline(line, 255);
-    tmp = AliMpHelper::Normalize(line);
-    if (tmp.Contains(crate.GetGlobalName())) {
-        in.getline(line, 255);
-        TString tmp(AliMpHelper::Normalize(line));
-        ULong_t addr;
-        sscanf(tmp.Data(), "%lx", &addr);
-        crate.SetGlobalVmeAddr(addr);
-        //AliDebug(1, Form("Global Vme Address: 0x%x", addr));
-
-        for (Int_t i = 0; i < crate.GetGlobalNofRegisters(); ++i) {
-            in.getline(line, 255);
-            TString tmp(AliMpHelper::Normalize(line));
-            UInt_t reg;
-            sscanf(tmp.Data(), "%x", &reg);
-            crate.SetGlobalRegister(i, reg);
-            //AliDebug(1, Form("Global Register %d: 0x%x", i, reg));
-        }
-    }
-
-    in.getline(line, 255);
-    tmp = AliMpHelper::Normalize(line);
-    if (tmp.Contains(crate.GetFetName())) {
-        in.getline(line, 255);
-        TString tmp(AliMpHelper::Normalize(line));
-        ULong_t addr;
-        sscanf(tmp.Data(), "%lx", &addr);
-        crate.SetFetVmeAddr(addr);
-        //AliDebug(1, Form("Fet Vme Address: 0x%x", addr));
-
-        for (Int_t i = 0; i < crate.GetFetNofRegisters(); ++i) {
-            in.getline(line, 255);
-            TString tmp(AliMpHelper::Normalize(line));
-            UInt_t reg;
-            sscanf(tmp.Data(), "%x", &reg);
-            crate.SetFetRegister(i, reg);
-            //AliDebug(1, Form("Fet Register %d: 0x%x", i, reg));
-        }
-    }
-
-    return kTRUE;
-}
 //______________________________________________________________________________
 Bool_t AliMpDDLStore::ReadDDLs() 
 {
     /// Read ddl <-> bus patch file
 
-    TString infile = AliMpFiles::BusPatchFilePath();
-
-    ifstream in(infile, ios::in);
-    if (!in) {
-        AliErrorStream() << "Data file " << infile << " not found.";
-        return false;
-    }
+    istream& in 
+      = fDataStreams.
+          CreateDataStream(AliMpFiles::BusPatchFilePath());
 
     char line[255];
 
@@ -485,152 +289,86 @@ Bool_t AliMpDDLStore::ReadDDLs()
         ddl->FillBusPatchIds();
     }
 
-    in.close();
+    delete &in;
     return true;
 }
+
 //______________________________________________________________________________
-Bool_t  AliMpDDLStore::ReadTriggerDDLs() 
+Bool_t  AliMpDDLStore::ReadTrigger() 
 {
     /// create trigger DDL object and Global crate object
   
-  if (!ReadGlobalTrigger(*fGlobalCrate)) return false;
-  if (!ReadLocalTrigger()) return false;
-  
+  if ( ! fRegionalTrigger.ReadData(fDataStreams) ) return false;
+
   return true;
 }
 
 //______________________________________________________________________________
-Bool_t  AliMpDDLStore::ReadLocalTrigger() 
+Bool_t  
+AliMpDDLStore::SetTriggerDDLs() 
 {
-    /// create trigger DDL object ddl<->Crate<->local board
-  
-    ReadGlobalTrigger(*fGlobalCrate);
-    
-    Int_t iDDL = -1;
-
-    TString infile = AliMpFiles::LocalTriggerBoardMapping();
-
-    ifstream in(infile, ios::in);
-
-    if (!in) {
-        AliError(Form("Local Trigger Board Mapping File %s not found", infile.Data()));
-        return kFALSE;
-    }
-
-    AliMpLocalBoard* board = 0x0;
-    AliMpTriggerCrate* crate = 0x0;
-
+  /// Create trigger DDLs and set DDL Ids in the regional trigger
 
-    Int_t localBoardId = 0;
-    TArrayI list;
-    UShort_t crateId, mask;
-    Int_t mode, coincidence;
-    
-    char line[80];
-   
-    while (!in.eof())
-    {
-    in.getline(line,80);
-    if (!strlen(line)) break;
-    TString crateName(AliMpHelper::Normalize(line));
-      
-    in.getline(line,80);    
-    sscanf(line,"%hx",&crateId);
+  Int_t iDDL = -1;
+  TIter next(fRegionalTrigger.CreateCrateIterator());
+  AliMpTriggerCrate* crate;
+  
+  while ( ( crate = static_cast<AliMpTriggerCrate*>(next()) ) )
+  {
+    TString crateName = crate->GetName();
 
-    in.getline(line,80);
-    sscanf(line,"%d",&mode);
-    
-    in.getline(line,80);
-    sscanf(line,"%d",&coincidence);
-    
-    in.getline(line,80);
-    sscanf(line,"%hx",&mask);
-    
     // determine ddl number vs crate side
     if (crateName.Contains("R"))
       iDDL = fgkNofDDLs; // starts where tracker ends
     else
       iDDL = fgkNofDDLs + 1;
 
-    AliMpDDL* ddl = GetDDL(iDDL, false);
+    // Create DDL if it does not yet exist and set it to the crate
+    AliMpDDL* ddl = (AliMpDDL*)fDDLs.At(iDDL);
     if ( !ddl) {
       ddl = new AliMpDDL(iDDL);
       fDDLs.AddAt(ddl, iDDL);
     }
-    if (!GetTriggerCrate(crateName.Data(), false)) {
-      crate = new AliMpTriggerCrate(crateName.Data(), crateId, mask, mode, coincidence);
-      crate->SetDdlId(iDDL);
-      fTriggerCrates.Add(crateName.Data(), crate);
-    }
+    crate->SetDdlId(iDDL);
     
-    // add trigger crate number for given ddl if not present
-    if ( !ddl->HasTriggerCrateId(crateId) )
-      ddl->AddTriggerCrate(crateId);
     
+    // Add trigger crate number for given ddl if not present
+    if ( !ddl->HasTriggerCrateId(crate->GetId()) )
+      ddl->AddTriggerCrate(crate->GetId());
     
-    Char_t localBoardName[20];
-    Int_t slot;
-    UInt_t switches;
     
-    for ( Int_t i = 0; i < AliMpConstants::LocalBoardNofChannels(); ++i ) 
+    // Loop over local boards in this crate
+
+    for ( Int_t j=0; j<crate->GetNofLocalBoards(); ++j ) 
     {
-      if ( (mask >> i ) & 0x1 )
-      {
-        in.getline(line,80);
-        sscanf(line,"%02d %s %03d %03x",&slot,localBoardName,&localBoardId,&switches);
-        board = new AliMpLocalBoard(localBoardId, localBoardName, slot); 
-        board->SetSwitch(switches);
-        board->SetCrate(crateName);
-        
-        if (localBoardId > AliMpConstants::NofLocalBoards())
-          board->SetNotified(false); // copy cards
-        
-        crate->AddLocalBoard(localBoardId);
-        
-        list.Reset();
-        AliMpDDL* ddl = GetDDL(iDDL, true);
-  
-        // add  DE for local board and DDL
-        in.getline(line,80);
-        TString tmp(AliMpHelper::Normalize(line));
-        AliMpHelper::DecodeName(tmp,' ',list);
-  
-        for (Int_t i = 0; i < list.GetSize(); ++i) {
-  
-          if (list[i]) { // skip copy card
-            AliMpDetElement* de = AliMpDEManager::GetDetElement(list[i]);
-            if (de->GetDdlId() == -1)
-              de->SetDdlId(iDDL);
-          }
-          board->AddDE(list[i]);
-          if(!ddl->HasDEId(list[i]))
-            ddl->AddDE(list[i]);
-        }
-        
-        // set copy number and transverse connector
-        in.getline(line,80);
-        tmp = AliMpHelper::Normalize(line);
-        AliMpHelper::DecodeName(tmp,' ',list);
-  
-        board->SetInputXfrom(list[0]);
-        board->SetInputXto(list[1]);
-        
-        board->SetInputYfrom(list[2]);
-        board->SetInputYto(list[3]);
-        
-        board->SetTC(list[4]);
+      Int_t localBoardId = crate->GetLocalBoardId(j);
+      AliMpLocalBoard* localBoard 
+        = fRegionalTrigger.FindLocalBoard(localBoardId);
+      if (!localBoard ) {
+        AliFatalClass("Cannot find local board.");
+        return kFALSE;
+      }   
+      
+      // Loop over DEs in this localBoard 
         
-        // add local board into map
-        fLocalBoards.Add(board->GetId(), board);
-      }
+      for ( Int_t k=0; k<localBoard->GetNofDEs(); ++k ) 
+      {
+    
+        Int_t deId = localBoard->GetDEId(k);
+        AliMpDetElement* de = AliMpDEManager::GetDetElement(deId);
+
+        if ( de->GetDdlId() == -1 ) de->SetDdlId(iDDL);
+
+        if ( ! ddl->HasDEId(deId) ) ddl->AddDE(deId);
+      }   
     }
-  
   }
-    return kTRUE;
+  return kTRUE;
 }
 
 //______________________________________________________________________________
-Bool_t AliMpDDLStore::SetManus() {
+Bool_t AliMpDDLStore::SetManus() 
+{
     /// Set manus for each bus patch
 
     Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane) - 1;
@@ -733,7 +471,89 @@ Bool_t AliMpDDLStore::SetManus() {
 }
 
 //______________________________________________________________________________
-Bool_t AliMpDDLStore::SetPatchModules() {
+Bool_t AliMpDDLStore::ReadBusPatchSpecial()
+{
+/// Read file with bus patches with a special order of manus
+/// and reset the manus arrays filled via SetManu function
+
+  istream& in 
+    = fDataStreams.
+        CreateDataStream(AliMpFiles::BusPatchSpecialFilePath());
+
+  char line[255];
+
+  while ( in.getline(line,255) ) {
+
+    if ( line[0] == '#' ) continue;
+
+    TString tmp(AliMpHelper::Normalize(line));
+    TObjArray* stringList = tmp.Tokenize(TString(" "));
+
+    TString sKey = ((TObjString*)stringList->At(0))->GetString();
+    
+    TString sDDL = ((TObjString*)stringList->At(1))->GetString();
+    TArrayI ddlList;
+    AliMpHelper::DecodeName(sDDL,';',ddlList);
+
+    TString sBusPatch = ((TObjString*)stringList->At(2))->GetString();
+    TArrayI busPatchList;
+    AliMpHelper::DecodeName(sBusPatch,',',busPatchList);
+    
+    // Loop over DDL and Bus Patch
+    for (Int_t iDDL = 0; iDDL < ddlList.GetSize(); ++iDDL ) {
+      for (Int_t iBusPatch = 0; iBusPatch < busPatchList.GetSize(); ++iBusPatch) {
+        // Global bus patch ID
+        Int_t busPatchID 
+          = AliMpBusPatch::GetGlobalBusID(
+              busPatchList.At(iBusPatch), ddlList.At(iDDL));
+        
+        // Get this bus patch
+        AliMpBusPatch* busPatch = GetBusPatch(busPatchID);
+        if ( ! busPatch ) {
+          AliErrorStream() << "Bus patch " << busPatchID << " does not exist." << endl;
+          return kFALSE;
+        }
+     
+        if ( sKey == fgkRevertKeyword ) {
+          AliDebugStream(3)
+            << "Reverting readout of bus patch " << busPatchID  << endl;
+        
+          // Now revert the manus in this bus patch
+          busPatch->RevertReadout();     
+        }
+        else if ( sKey == fgkExplicitKeyword ) {
+        
+          busPatch->ResetReadout();
+
+          TString sManus = ((TObjString*)stringList->At(3))->GetString();
+          TArrayI manuList;
+          AliMpHelper::DecodeName(sManus,',',manuList);
+
+          AliDebugStream(3)
+            << "Reseting readout of bus patch " << busPatchID  
+            << "  manus: " << sManus.Data() << endl;
+
+          for (Int_t i = 0; i < manuList.GetSize(); i++) {
+            busPatch->AddManu(manuList.At(i));
+          }
+        }
+        else {             
+          AliErrorStream() << "Unrecognized key." << endl;
+          return kFALSE;
+        }
+      }
+    }
+  }
+  
+  delete &in;
+  
+  return kTRUE;
+}    
+
+//______________________________________________________________________________
+Bool_t AliMpDDLStore::SetPatchModules() 
+{
     /// Compute the number of manu per PCB for each buspatch
 
     AliMpDEIterator it;
@@ -759,15 +579,14 @@ Bool_t AliMpDDLStore::SetPatchModules() {
 }
 
 //______________________________________________________________________________
-Bool_t AliMpDDLStore::SetBusPatchLength() {
-    /// read the buspatch length file and set buspatch length
-
-    TString infile = AliMpFiles::BusPatchLengthFilePath();
-    ifstream in(infile, ios::in);
-    if (!in) {
-        AliErrorStream() << "Data file " << infile << " not found.";
-        return false;
-    }
+Bool_t AliMpDDLStore::ReadBusPatchInfo() 
+{
+    /// read the buspatch info file and set buspatch info
+
+    istream& in 
+      = fDataStreams.
+          CreateDataStream(AliMpFiles::BusPatchInfoFilePath());
+
     char line[255];
 
     for (Int_t iDDL = 0; iDDL < fgkNofDDLs; ++iDDL ) {
@@ -787,22 +606,48 @@ Bool_t AliMpDDLStore::SetBusPatchLength() {
 
             TObjArray* stringList = tmp.Tokenize(TString(" "));
 
-            TString sLocalBusId = ((TObjString*)stringList->At(0))->GetString();
-            Int_t   localBusId  = sLocalBusId.Atoi();
-
-            TString sLength = ((TObjString*)stringList->At(1))->GetString();
-            Float_t length  = sLength.Atof();
+            // Crocus label
+            TString crLabel    = ((TObjString*)stringList->At(0))->GetString();
+            Int_t pos          = crLabel.First('-');
+            tmp                = crLabel(pos-2, crLabel.Length()-pos+2);
+            TArrayI list;
+            AliMpHelper::DecodeName(tmp.Data(), '-', list);
+            
+            Int_t localDDLId  = list[0];
+            Int_t frtId       = list[1] - 1; // begin at zero ! 
+            Int_t localBusId  = list[2];
+
+            // Add FRT number for given ddl if not present
+            if ( !ddl->HasFrtId(frtId) )
+              ddl->AddFrt(frtId);
+
+            // BP & translator label
+            TString label      = ((TObjString*)stringList->At(1))->GetString();
+            TString transLabel = ((TObjString*)stringList->At(2))->GetString();
+
+            // BP length
+            TString sLength    = ((TObjString*)stringList->At(3))->GetString();
+            Float_t length     = sLength.Atof();
 
             delete stringList;
-
+                       
             if (localBusId != iBusPatch + 1)
-                AliWarning(Form("Wrong local buspatch id %d instead of %d", iBusPatch+1, localBusId));
+               AliWarning(Form("Wrong local buspatch id %d instead of %d", iBusPatch+1, localBusId));
+               
+            if(localDDLId != ddl->GetId()+1)
+                AliWarning(Form("Wrong local DDL id %d instead of %d", ddl->GetId()+1, localDDLId));
 
             Int_t busPatchId = ddl->GetBusPatchId(iBusPatch);
             AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
             busPatch->SetCableLength(length);
+            busPatch->SetCableLabel(label);
+            busPatch->SetTranslatorLabel(transLabel);
+            busPatch->SetFrtId(frtId);
+
         }
     }
+    
+    delete &in;
 
     return true;
 }
@@ -812,11 +657,11 @@ Bool_t AliMpDDLStore::SetBusPatchLength() {
 Int_t AliMpDDLStore::GetLocalBoardId(TString name) const {
     /// return the first board with a given side and line
 
-    TExMapIter i = fLocalBoards.GetIterator();
-    Long_t key, value;
-    while ( i.Next(key, value) ) {
-        AliMpLocalBoard* local = (AliMpLocalBoard*)value;
-
+  TIter next(fRegionalTrigger.CreateLocalBoardIterator());
+  AliMpLocalBoard* local;
+  
+  while ( ( local = static_cast<AliMpLocalBoard*>(next()) ) )
+  {
         TString tmp(&local->GetName()[4], 2);
         if (name.Contains(tmp))
             if (name[0] == local->GetName()[0])
@@ -824,7 +669,6 @@ Int_t AliMpDDLStore::GetLocalBoardId(TString name) const {
     }
 
     return 0;
-
 }
 
 //
@@ -874,38 +718,23 @@ AliMpBusPatch* AliMpDDLStore::GetBusPatch(Int_t busPatchId, Bool_t warn) const {
     return busPatch;
 }
 
+
 //______________________________________________________________________________
 AliMpLocalBoard* AliMpDDLStore::GetLocalBoard(Int_t localBoardId, Bool_t warn) const {
     /// Return bus patch with given Id
 
-    AliMpLocalBoard* localBoard
-    = (AliMpLocalBoard*) fLocalBoards.GetValue(localBoardId);
-
-    if ( ! localBoard && warn ) {
-        AliErrorStream()
-        << "Local board with Id = " << localBoardId << " not defined." << endl;
-    }
-
-    return localBoard;
+    return fRegionalTrigger.FindLocalBoard(localBoardId, warn);
 }
 
 //______________________________________________________________________________
-AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const {
+AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(TString name, Bool_t warn) const  {
     /// Return trigger crate with given name
 
-    AliMpTriggerCrate* crate
-    = (AliMpTriggerCrate*) fTriggerCrates.GetValue(name.Data());
-
-    if ( ! crate && warn ) {
-        AliErrorStream()
-        << "Trigger crate with name = " << name.Data() << " not defined." << endl;
-    }
-
-    return crate;
+    return fRegionalTrigger.FindTriggerCrate(name, warn);
 }
 
 //______________________________________________________________________________
-AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const {
+AliMpTriggerCrate* AliMpDDLStore::GetTriggerCrate(Int_t ddlId, Int_t index, Bool_t warn) const  {
     /// Return trigger crate with given ddl and index crate
 
     if (ddlId == 0 || ddlId == 1)
@@ -989,16 +818,21 @@ Int_t AliMpDDLStore::GetBusPatchId(Int_t detElemId, Int_t manuId) const {
     return detElement->GetBusPatchId(pos);
 }
 
+
 //______________________________________________________________________________
-AliMpIntPair  AliMpDDLStore::GetDetElemIdManu(Int_t manuSerial) const {
-    /// Return the detElemId and manuId for given serial manu number
+AliMpIntPair  AliMpDDLStore::GetLinkPortId(Int_t busPatchId) const {
 
-    if ( ! AliMpDEStore::Instance() ) {
-        AliFatal("DE Store has not been loaded.");
-        return AliMpIntPair::Invalid();
-    }
+  /// Return link port for a given frtId and global busPatchId
+
+    AliMpBusPatch* busPatch = GetBusPatch(busPatchId);
+    Int_t ddlId = busPatch->GetDdlId();
+        
+    Int_t localBusPatchId = AliMpBusPatch::GetLocalBusID(busPatchId, ddlId) - 1; // begin at zero
+
+    Int_t pos = (localBusPatchId % AliMpFrtCrocusConstants::GetNofBusPatches()); 
+    
+    return AliMpFrtCrocusConstants::GetLinkPortId(pos);
 
-    return AliMpDEStore::Instance()->GetDetElemIdManu(manuSerial);
 }
 
 //______________________________________________________________________________
@@ -1026,16 +860,20 @@ void AliMpDDLStore::PrintAllManu() const {
             }
             cout << endl;
 
-            cout << "    Manu serial: ";
-            for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) {
-                cout << std::setw(6) << de->GetManuSerialFromId(busPatch->GetManuId(k)) << " ";
-            }
-            cout << endl;
+            if ( AliMpManuStore::Instance(kFALSE) ) {
+              cout << "    Manu serial: ";
+              for ( Int_t k=0; k<busPatch->GetNofManus(); ++k ) {
+                cout << std::setw(6) 
+                     << AliMpManuStore::Instance()
+                        ->GetManuSerial(de->GetId(), busPatch->GetManuId(k)) << " ";
+              }
+              cout << endl;
+            }  
         }
     }
 }
 
-//________________________________________________________________
+//______________________________________________________________________________
 Int_t  AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberId ) const {
     /// return the next detection element in line
 
@@ -1057,7 +895,7 @@ Int_t  AliMpDDLStore::GetNextDEfromLocalBoard(Int_t localBoardId, Int_t chamberI
     return 0;
 }
 
-//________________________________________________________________
+//______________________________________________________________________________
 Int_t  AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t chamberId) const {
     /// return the previous detection element in line
 
@@ -1078,3 +916,27 @@ Int_t  AliMpDDLStore::GetPreviousDEfromLocalBoard(Int_t localBoardId, Int_t cham
 
 }
 
+//______________________________________________________________________________
+void AliMpDDLStore::SetRegionalTrigger(const AliMpRegionalTrigger& regionalTrigger)
+{
+/// Replace the existing regional trigger with the given one
+
+  fRegionalTrigger = regionalTrigger;
+  
+  // Remove the existing trigger DDLsf
+  fDDLs.RemoveAt(fgkNofDDLs+1);
+  fDDLs.RemoveAt(fgkNofDDLs);
+  
+  // Set new trigger DDLs from new regional trigger
+  SetTriggerDDLs();
+}  
+
+
+//______________________________________________________________________________
+TIterator* 
+AliMpDDLStore::CreateBusPatchIterator() const
+{
+/// Create the iterator over bus patches
+
+  return fBusPatches.CreateIterator();
+}