]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerIO.cxx
- update track cuts
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerIO.cxx
index 9d96642f426f8157ea5dc34890948e4e0da8e03c..e05b1022da503c91376c98c7d83009f33988ba3a 100644 (file)
@@ -45,6 +45,9 @@
 /// \author Laurent Aphecetche, Christian Finck Subatech
 /// \author Bogdan Vulpescu, LPC Clermont-Ferrand
 
+using std::endl;
+using std::cout;
+using std::ofstream;
 /// \cond CLASSIMP
 ClassImp(AliMUONTriggerIO)
 /// \endcond
@@ -209,11 +212,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 = fRegionalTrigger.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,
@@ -226,28 +229,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;
 }
 
 //_____________________________________________________________________________
@@ -279,7 +286,10 @@ AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
   Bool_t trigx = kFALSE;
   
   // read two lut addresses at once, 32768/2=16384 times
-  fread(buffer,fgkLocalLutSize,1,flut);
+  if (fread(buffer,fgkLocalLutSize,1,flut) == 0) {
+    AliWarning("Error reading the LUT file");
+    return;
+  }
 
   // create the 32767 addresses for the 4-bits lpt and hpt half-bytes
   for (UShort_t ilut = 0; ilut < fgkLocalLutSize*2; ilut += 2) 
@@ -371,8 +381,30 @@ AliMUONTriggerIO::ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut)
     ReadLocalLUT(lut,fRegionalTrigger.LocalBoardId(i),flut);
   }
   
+  // 
+  // 1st/2nd cut code   pt cut [GeV/c]
+  //
+  // 0                 0.5 (a.k.a. Apt)
+  // 1                 1.0 (a.k.a. Lpt)
+  // 2                 1.7 (a.k.a. Hpt)
+  // 3                 4.2 (a.k.a. infinity)
+  // 4                 free
+  // .
+  // .
+  // .
+  //15                 default (for backward compatibility)
+
+  UChar_t lutCode = 0xFF;
+
+  if (!fread(&lutCode,1,1,flut)) {
+    AliWarning("No LUT info in the file (old version)");
+  }
+  AliInfo(Form("LUT code: 0x%02x",lutCode));
+
   fclose(flut);
-  
+
+  lut.SetLutCode(lutCode);
+
   return kTRUE;
   
 }
@@ -380,32 +412,38 @@ AliMUONTriggerIO::ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut)
 //_____________________________________________________________________________
 Bool_t 
 AliMUONTriggerIO::ReadConfig(const char* localFile,
-                            const char* regionalFile,
-                            const char* globalFile,
-                            AliMUONVStore* localMasks,
-                            AliMUONRegionalTriggerConfig* regionalConfig,
-                            AliMUONGlobalCrateConfig* globalConfig)
+                             const char* regionalFile,
+                             const char* globalFile,
+                             AliMUONVStore* localMasks,
+                             AliMUONRegionalTriggerConfig* regionalConfig,
+                             AliMUONGlobalCrateConfig* globalConfig)
 {
   /// Fill the various masks store from files
   
-  if ( !regionalFile ) 
+  if ( !regionalConfig || !regionalFile || strlen(regionalFile)==0 ) 
   {
     AliError("Must have a regional file name to proceeed");
     return kFALSE;
   }
   
-  Int_t nCrates = ReadRegionalConfig(regionalFile, regionalConfig);
+  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 = ReadGlobalConfig(globalFile, globalConfig);
-  AliDebug(1,Form("Read disable for %d DARC boards",nDarc));
+  AliDebug(1,Form("Read config for %d DARC boards",nDarc));
   
   if (!nDarc) return kFALSE;
   
@@ -416,7 +454,7 @@ AliMUONTriggerIO::ReadConfig(const char* localFile,
 
 //_____________________________________________________________________________
  Int_t 
- AliMUONTriggerIO::ReadGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig)
+ AliMUONTriggerIO::ReadGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig) const
 {
   /// read the global crate file
   /// the masks are disable bit for each crate, 8 per darc board
@@ -433,6 +471,9 @@ Int_t
 AliMUONTriggerIO::ReadRegionalConfig(const char* regionalFile, AliMUONRegionalTriggerConfig* regionalConfig)
 {
   /// Read regional file to fill  
+  
+  AliDebug(1,Form("regionalConfig=%p",regionalConfig));
+  
   Int_t nCrates = 0;
   if ( !(nCrates = regionalConfig->ReadData(regionalFile)) ) return 0;
 
@@ -479,14 +520,14 @@ Bool_t
 AliMUONTriggerIO::WriteConfig(const char* localFile,
                             const char* regionalFile,
                             const char* globalFile,
-                            AliMUONVStore* localMasks,
+                            const AliMUONVStore* localMasks,
                     AliMUONRegionalTriggerConfig* regionalConfig,
                     AliMUONGlobalCrateConfig* globalConfig) const
 {
 /// write config files
 
     Bool_t ok;
-    ok  = WriteLocalMasks(localFile, *localMasks, regionalConfig);
+    ok  = WriteLocalMasks(localFile, *localMasks);
     ok &= WriteRegionalConfig(regionalFile, regionalConfig);
     ok &= WriteGlobalConfig(globalFile, globalConfig);
     
@@ -513,11 +554,11 @@ AliMUONTriggerIO::WriteGlobalConfig(const char* globalFile, AliMUONGlobalCrateCo
   }
    
   out << globalConfig->GetName() << endl;
-  out << globalConfig->GetGlobalCrateEnable() << endl;
+  out << Form("0x%x",globalConfig->GetGlobalCrateEnable()) << endl;
   
   // Jtag
   out << globalConfig->GetJtagName() << endl;
-  out << Form("0x%08x", globalConfig->GetJtagVmeAddr()) << endl;
+  out << Form("0x%08lx", globalConfig->GetJtagVmeAddr()) << endl;
   out << Form("%d %d %d", globalConfig->GetJtagClockDiv(), 
               globalConfig->GetJtagRxPhase(), globalConfig->GetJtagRdDelay()) << endl;
  
@@ -535,7 +576,7 @@ AliMUONTriggerIO::WriteGlobalConfig(const char* globalFile, AliMUONGlobalCrateCo
   
   // first darc board
   out << globalConfig->GetFirstDarcName() << endl;
-  out << Form("0x%08x", globalConfig->GetFirstDarcVmeAddr()) << endl;
+  out << Form("0x%08lx", globalConfig->GetFirstDarcVmeAddr()) << endl;
   out << globalConfig->GetFirstDarcType() << endl;
   disable = globalConfig->GetFirstDarcDisable();
   out << Form("0x%02x", disable) << endl;
@@ -546,7 +587,7 @@ AliMUONTriggerIO::WriteGlobalConfig(const char* globalFile, AliMUONGlobalCrateCo
   
   // second darc board
   out << globalConfig->GetSecondDarcName() << endl;
-  out << Form("0x%08x", globalConfig->GetSecondDarcVmeAddr()) << endl;
+  out << Form("0x%08lx", globalConfig->GetSecondDarcVmeAddr()) << endl;
   out << globalConfig->GetSecondDarcType() << endl;
   disable = globalConfig->GetSecondDarcDisable();
   out << Form("0x%02x", disable) << endl;
@@ -557,13 +598,13 @@ AliMUONTriggerIO::WriteGlobalConfig(const char* globalFile, AliMUONGlobalCrateCo
   
   // global board
   out << globalConfig->GetGlobalName() << endl;
-  out << Form("0x%08x", globalConfig->GetGlobalVmeAddr()) << endl;
+  out << Form("0x%08lx", globalConfig->GetGlobalVmeAddr()) << endl;
   for (Int_t i = 0; i < globalConfig->GetGlobalNofRegisters(); ++i)
     out << Form("0x%x", globalConfig->GetGlobalRegister(i)) << endl;
   
   // Fet board
   out << globalConfig->GetFetName() << endl;
-  out << Form("0x%08x", globalConfig->GetFetVmeAddr()) << endl;
+  out << Form("0x%08lx", globalConfig->GetFetVmeAddr()) << endl;
   for (Int_t i = 0; i < globalConfig->GetFetNofRegisters(); ++i)
     out << Form("0x%x", globalConfig->GetFetRegister(i)) << endl;
   
@@ -593,47 +634,63 @@ AliMUONTriggerIO::WriteRegionalConfig(const char* regionalFile, AliMUONRegionalT
       AliError("Could not write regional no configuration in memory");
       return kFALSE;
     }
-    
-    TIter next(fRegionalTrigger.CreateCrateIterator());
+
+    Int_t nofDDLs = 0;
+    TString name;
     AliMpTriggerCrate* crate;
-    while ( ( crate = static_cast<AliMpTriggerCrate*>(next()) ) )
-    {
-      AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(crate->GetName());
-      if (!crateConfig) 
+    for (Int_t ddlId = 0; ddlId < 2; ddlId++) // right & left side            
       {
-        AliError(Form("Cannot find crate %s in CDB", crate->GetName()));
-        return kFALSE;
+       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 << crate->GetName()  << endl;
-      out << Form("%02x", crate->GetId())   << endl;
-      out << crateConfig->GetMode()  << endl;
-      out << crateConfig->GetCoinc() << endl;
-      out << Form("%04x", crateConfig->GetMask()) << 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 << " ";
-        for (Int_t i = 0; i < board->GetNofDEs(); ++i)
-          out << Form("%4d ", board->GetDEId(i));
-        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;
@@ -642,7 +699,7 @@ AliMUONTriggerIO::WriteRegionalConfig(const char* regionalFile, AliMUONRegionalT
 
 //_____________________________________________________________________________
 Bool_t 
-AliMUONTriggerIO::WriteLocalMasks(const char* localFile, AliMUONVStore& localMasks, AliMUONRegionalTriggerConfig* regionalConfig) const
+AliMUONTriggerIO::WriteLocalMasks(const char* localFile, const AliMUONVStore& localMasks) const
 {
     /// write local mask
     /// removing/adding enable for a local board need a update of the configuration 
@@ -657,32 +714,23 @@ AliMUONTriggerIO::WriteLocalMasks(const char* localFile, AliMUONVStore& localMas
     }   
 
     UShort_t maskBuffer[8];
+    Int_t localBoardIndex(0);
+    while (localBoardIndex < NofLocalBoards()) {
 
-    TIter next(regionalConfig->CreateCrateIterator());
-    AliMUONTriggerCrateConfig* crate;
-    
-    while ( ( crate = static_cast<AliMUONTriggerCrateConfig*>(next()) ) )
-    {      
-      UShort_t mask = crate->GetMask(); // getting mask from current config
+      Int_t localBoardId = fRegionalTrigger.LocalBoardId(localBoardIndex);
 
-      for (Int_t iLocal = 0; iLocal < crate->GetNofLocalBoards(); ++iLocal) 
-      {
-       Int_t localBoardId = crate->GetLocalBoardId(iLocal);
+      AliMUONVCalibParam* localMask = 
+       static_cast<AliMUONVCalibParam*>(localMasks.FindObject(localBoardId));
 
-       if ( (mask >> iLocal ) & 0x1 
+      for (Int_t index = 0; index < 8; ++index
        {
-         AliMUONVCalibParam* localMask = 
-             static_cast<AliMUONVCalibParam*>(localMasks.FindObject(localBoardId));
-
-         for (Int_t index = 0; index < 8; ++index) 
-         {
-           maskBuffer[index] = localMask->ValueAsInt(index,0); 
-         }
-
-         fwrite ( maskBuffer, 2, 8, fp); 
+         maskBuffer[index] = localMask->ValueAsInt(index,0); 
        }
+      
+      fwrite ( maskBuffer, 2, 8, fp); 
+
+      ++localBoardIndex;
 
-      }
     }
 
     fclose(fp);
@@ -789,3 +837,17 @@ AliMUONTriggerIO::LocalBoardId(Int_t index) const
 
   return fRegionalTrigger.LocalBoardId(index);
 }
+
+
+//______________________________________________________________________________
+
+Int_t AliMUONTriggerIO::LocalBoardId(Int_t ddlId, Int_t crateId, Int_t localId) const
+{
+    /// Return local board id from crate and local indexes.
+    
+    Int_t nofDDLs = 0;
+    TString name = AliMpTriggerCrate::GenerateName(crateId, ddlId, nofDDLs);
+
+    AliMpTriggerCrate* crate = fRegionalTrigger.FindTriggerCrate(name, false);
+    return crate->GetLocalBoardId(localId);
+}