]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerElectronics.cxx
Fixing FORWARD_NULL defects reported by Coverity
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerElectronics.cxx
index eff5ec424738c5a644499bd1a424bc4ac58d36ee..388c3447d900ffcd50471c297f610f3298550a9f 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "AliLoader.h"
 #include "AliLog.h"
-#include "AliMUON.h" 
 #include "AliMUONCalibrationData.h"
 #include "AliMUONVDigit.h"
 #include "AliMUONVDigitStore.h"
@@ -47,6 +46,7 @@
 #include "AliMUONVTriggerStore.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMpCathodType.h"
+#include "AliMpCDB.h"
 #include "AliMpDEManager.h"
 #include "AliMpSegmentation.h"
 #include "AliMpVSegmentation.h"
@@ -63,6 +63,8 @@
 #include <TBits.h>
 #include <TSystem.h>
 
+#include "AliCodeTimer.h"
+
 
 /// \cond CLASSIMP
 ClassImp(AliMUONTriggerElectronics)
@@ -84,6 +86,12 @@ AliMUONTriggerElectronics::AliMUONTriggerElectronics(AliMUONCalibrationData* cal
     fCopyYInput[i]->SetOwner();
   }
 
+  // force loading of mapping if not already done
+  if ( !AliMpDDLStore::Instance(kFALSE) )
+  {
+    AliMpCDB::LoadDDLStore();
+  }
+  
   SetCopyInput();
   
   Factory(calibData);
@@ -168,6 +176,8 @@ void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
 {
   /// FILL INPUTS
   ///
+
+  AliCodeTimerAuto("",0);
   
   TIter next(digitStore.CreateTriggerIterator());
   AliMUONVDigit* mdig;
@@ -195,32 +205,42 @@ void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
       
       AliDebug(3,Form("cathode %d ix %d iy %d ",cathode,ix,iy));
 
-      AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
+      AliMpPad pad = seg->PadByIndices(ix,iy,kTRUE);
       
       for (Int_t i=0; i<pad.GetNofLocations(); i++) 
       {
-        AliMpIntPair location = pad.GetLocation(i);
-        
-        Int_t nboard = location.GetFirst();
+        Int_t nboard = pad.GetLocalBoardId(i);
         
-        Int_t ibitxy = location.GetSecond();
+        Int_t ibitxy = pad.GetLocalBoardChannel(i);
         
         AliMUONLocalTriggerBoard *b = fCrates->LocalBoard(nboard);
         
         if (b) 
         {
-          if (cathode && b->GetSwitch(6)) ibitxy += 8;
+          if (cathode && b->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) ibitxy += 8;
           
           b->SetbitM(ibitxy,cathode,ichamber-10);
         }
         else
         {
-          AliError(Form("Could not get local board number %d",b->GetNumber()));
+          AliError(Form("Could not get local board number %d",nboard));
         }
       }
     }          
   }
 
+  FeedCopyNeighbours();
+}
+
+
+//___________________________________________
+void AliMUONTriggerElectronics::FeedCopyNeighbours()
+{
+  //
+  /// Feed the local copies
+  /// and complete the feed with the information of neighbours
+  //
+
   // Particular case of the columns with 22 local boards (2R(L) 3R(L))   
   // fill copy input from mapping instead of hardcoded valued (Ch.F)
   AliMUONTriggerCrate *crate = 0x0; TObjArray *bs = 0x0;
@@ -275,10 +295,9 @@ void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
   
   // FILL UP/DOWN OF CURRENT BOARD (DONE VIA J3 BUS IN REAL LIFE)
   AliMUONTriggerCrate* cr;
+  TIter next2(fCrates->CreateCrateIterator());
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next2()) ) )
   {            
     TObjArray *boards = cr->Boards();
     
@@ -318,10 +337,9 @@ void AliMUONTriggerElectronics::Feed(UShort_t pattern[2][4])
   /// FILL INPUTS
   ///
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());
    
-   fCrates->FirstCrate();
-   
-   while ( ( cr = fCrates->NextCrate() ) )
+   while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
    {                 
      TObjArray *boards = cr->Boards();
      
@@ -352,16 +370,15 @@ void AliMUONTriggerElectronics::DumpOS()
 }
 
 //___________________________________________
-void AliMUONTriggerElectronics::Scan(Option_t *option)
+void AliMUONTriggerElectronics::Scan(const Option_t *option)
 {
   /// SCAN
   ///
 
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());  
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {                
     TObjArray *boards = cr->Boards();
     
@@ -393,10 +410,8 @@ void AliMUONTriggerElectronics::Reset()
   ///
   
    AliMUONTriggerCrate* cr;
-   
-   fCrates->FirstCrate();
-   
-   while ( ( cr = fCrates->NextCrate() ) )
+  TIter next(fCrates->CreateCrateIterator());
+   while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
    {            
       TObjArray *boards = cr->Boards();
             
@@ -418,17 +433,17 @@ void AliMUONTriggerElectronics::LoadMasks(AliMUONCalibrationData* calibData)
   // Set mask
   
   AliMUONRegionalTriggerConfig* regionalConfig = calibData->RegionalTriggerConfig();
-  if (!regionalConfig)
-     AliWarning("No valid regional trigger configuration in CDB");
-
+  if (!regionalConfig) {
+     AliError("No valid regional trigger configuration in CDB");
+     return;
+  }   
   
   AliMUONTriggerCrate* cr;
-  
-  fCrates->FirstCrate();
+  TIter next(fCrates->CreateCrateIterator());
   
   Int_t irb(0);
   
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {            
     TObjArray *boards = cr->Boards();
     
@@ -466,34 +481,38 @@ void AliMUONTriggerElectronics::LoadMasks(AliMUONCalibrationData* calibData)
   }
   
    AliMUONGlobalCrateConfig * globalConfig = calibData->GlobalTriggerCrateConfig();
-  if (!globalConfig)
-     AliWarning("No valid trigger crate configuration in CDB");
-
-    UShort_t gmask = 0;
-    gmask = globalConfig->GetFirstDarcDisable();
-    fGlobalTriggerBoard->Mask(0,gmask);
-
-    gmask = globalConfig->GetSecondDarcDisable();
-    fGlobalTriggerBoard->Mask(1,gmask);
+   if (!globalConfig) {
+     AliError("No valid trigger crate configuration in CDB");
+     return;
+   }   
+
+    UInt_t gmask = 0;
+    for (Int_t i = 0; i < 4; i++) {
+      gmask = globalConfig->GetGlobalMask(i);
+      fGlobalTriggerBoard->Mask(i,gmask);
+    }
 }
 
 //___________________________________________
 void AliMUONTriggerElectronics::LocalResponse()
 {
 /// Compute the response for local cards
+
+  AliCodeTimerAuto("",0);
        
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());
+
+  UShort_t thisl[16];
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {            
     
     TObjArray *boards = cr->Boards();
     
     AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
     
-    UShort_t thisl[16]; for (Int_t j=0; j<16; j++) thisl[j] = 0;
+    for (Int_t j=0; j<16; ++j) thisl[j] = 0;
   
     for (Int_t j = 1; j < boards->GetEntries(); j++)
     {     
@@ -502,26 +521,23 @@ void AliMUONTriggerElectronics::LocalResponse()
        if (!o) break;
       
        AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
-      
-       if (board) // check if empty slot
-       {
-         board->Response();
-                               
-         UShort_t response = board->GetResponse();            
-        
-         // CRATE CONTAINING INTERFACE BOARD
-         if (board->GetNumber() == 0) // copy boards
-         {
-           if ( response != 0 ) 
-             AliWarning(Form("Interface board %s in slot %d of crate %s has a non zero response",
-                                         board->GetName(),j,cr->GetName()));
-           AliDebug(1, Form("local slot %d, number %d in crate %s\n", j, board->GetNumber(), cr->GetName()));
 
-         }
+       board->Response();
+                               
+       UShort_t response = board->GetResponse();            
         
-         thisl[j-1] = response;
+       // CRATE CONTAINING INTERFACE BOARD
+       if (board->GetNumber() == 0) // copy boards
+       {
+         if ( response != 0 ) 
+           AliWarning(Form("Interface board %s in slot %d of crate %s has a non zero response",
+                           board->GetName(),j,cr->GetName()));
+         AliDebug(1, Form("local slot %d, number %d in crate %s\n", j, board->GetNumber(), cr->GetName()));
+         
        }
-      }
+        
+       thisl[j-1] = response;
+    }
     
     regb->SetLocalResponse(thisl);
   }
@@ -531,20 +547,20 @@ void AliMUONTriggerElectronics::LocalResponse()
 void AliMUONTriggerElectronics::RegionalResponse()
 {
   /// Compute the response for all regional cards.
+
+  AliCodeTimerAuto("",0);
+
   AliMUONTriggerCrate* cr;
+  TIter next(fCrates->CreateCrateIterator());
   
-  fCrates->FirstCrate();
-  
-  while ( ( cr = fCrates->NextCrate() ) )
+  while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
   {            
       TObjArray *boards = cr->Boards();
 
       AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
-      
-      if (regb) 
-      {
-         regb->Response();
-      }  
+
+      regb->Response();
+
    }
 }
 
@@ -553,11 +569,11 @@ void AliMUONTriggerElectronics::GlobalResponse()
 {
   /// Compute the global response
 
+  AliCodeTimerAuto("",0);
+
   UShort_t regional[16];
   
   AliMUONTriggerCrate* cr;
-  
-  fCrates->FirstCrate();
   Int_t irb(0);
   
   if ( !fCrates->NumberOfCrates() >= 16 ) 
@@ -565,15 +581,23 @@ void AliMUONTriggerElectronics::GlobalResponse()
     AliFatal(Form("Something is wrong : too many crates %d",
                   fCrates->NumberOfCrates()));
   }
+
+  // send regional responses to the global trigger in right order
+  // do not used iterator order
   
-  while ( ( cr = fCrates->NextCrate() ) )
+  for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
   {            
-    AliMUONTriggerBoard* rb = 
-      static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
-    regional[irb] = rb->GetResponse();
-    ++irb;
+    for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
+    {
+      cr = fCrates->Crate(iSide, iReg);     
+
+      AliMUONTriggerBoard* rb = 
+       static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
+      regional[irb] = rb->GetResponse();
+      ++irb;
+    }
   }
-  
+
   fGlobalTriggerBoard->SetRegionalResponse(regional);
   fGlobalTriggerBoard->Response();
 }
@@ -582,10 +606,15 @@ void AliMUONTriggerElectronics::GlobalResponse()
 void AliMUONTriggerElectronics::Digits2Trigger(const AliMUONVDigitStore& digitStore,
                                                AliMUONVTriggerStore& triggerStore)
 {
+  AliCodeTimerAuto("",0);
+
   /// Main method to go from digits to trigger decision
   AliMUONRegionalTrigger pRegTrig;
   
   triggerStore.Clear();
+
+  // NOW RESET ELECTRONICS
+  Reset();
   
   // RUN THE FULL BEE CHAIN
   Feed(digitStore);
@@ -680,13 +709,132 @@ void AliMUONTriggerElectronics::Digits2Trigger(const AliMUONVDigitStore& digitSt
   
   // GLOBAL TRIGGER INFORMATION
   UShort_t global = fGlobalTriggerBoard->GetResponse();
-  
+  UInt_t *globalInput = fGlobalTriggerBoard->GetGlobalInput();  
+
   AliMUONGlobalTrigger globalTrigger;
   
   globalTrigger.SetFromGlobalResponse(global);
+  globalTrigger.SetFromGlobalInput(globalInput);
   // ADD A LOCAL TRIGGER IN THE LIST 
   triggerStore.SetGlobal(globalTrigger);
-  
-  // NOW RESET ELECTRONICS
+
+}
+
+//___________________________________________
+void AliMUONTriggerElectronics::Feed(const AliMUONVTriggerStore& triggerStore)
+{
+  //
+  /// Fill inputs from reconstructed local trigger store
+  //
+  AliMUONLocalTrigger* locTrg;
+  TIter next(triggerStore.CreateLocalIterator());
+  TArrayS xyPattern[2];
+  UShort_t xy[2][4];
+  Int_t loCircuit;
+  while ( ( locTrg = static_cast<AliMUONLocalTrigger*>( next() )) != NULL ){
+    locTrg->GetXPattern(xyPattern[0]);
+    locTrg->GetYPattern(xyPattern[1]);
+    loCircuit = locTrg->LoCircuit();
+    AliMUONLocalTriggerBoard* localBoard = fCrates->LocalBoard(loCircuit);
+    for (Int_t icath = 0; icath<2; ++icath){
+      for (Int_t ich = 0; ich < 4; ++ich){
+       xy[icath][ich] = xyPattern[icath][ich];
+      }
+    }
+    localBoard->SetXY(xy);
+  }
+
+  FeedCopyNeighbours();
+}
+
+//_______________________________________________________________________
+Bool_t AliMUONTriggerElectronics::ModifiedLocalResponse(Int_t loCircuit,
+                                                       Bool_t& bendingPlaneResp,
+                                                       Bool_t& nonBendingPlaneResp,
+                                                       Bool_t isCoinc44,
+                                                       Int_t removeChamber)
+{
+  //
+  /// Re-compute the local trigger response
+  /// with some modifications (i.e. setting coinc44 or after removing one chamber)
+  //
+
+  bendingPlaneResp = kFALSE;
+  nonBendingPlaneResp = kFALSE;
+
+  Bool_t isTriggered = kFALSE;
+
+  AliMUONLocalTriggerBoard* currBoard = fCrates->LocalBoard(loCircuit);
+
+  if ( ! currBoard ) return isTriggered;
+
+  AliMUONLocalTriggerBoard localBoard (*currBoard);
+
+  if (removeChamber>=0 && removeChamber<=3){
+
+    // Set the bit pattern of selected chamber to 0
+    UShort_t xy[2][4];
+    UShort_t xyu[2][4];
+    UShort_t xyd[2][4];
+
+    localBoard.GetXY(xy);
+    localBoard.GetXYU(xyu);
+    localBoard.GetXYD(xyd);
+
+    for(Int_t icath=0; icath<2; icath++){
+      xy[icath][removeChamber] = 0;
+      xyu[icath][removeChamber] = 0;
+      xyd[icath][removeChamber] = 0;
+    }
+
+    localBoard.SetXY(xy);
+    localBoard.SetXYU(xyu);
+    localBoard.SetXYD(xyd);
+  }
+
+  localBoard.ResetResponse();
+
+  localBoard.SetCoinc44((Int_t)isCoinc44);
+  localBoard.Response();
+
+  bendingPlaneResp = localBoard.IsTrigX();
+  nonBendingPlaneResp = localBoard.IsTrigY();
+  isTriggered = localBoard.Triggered();
+
+  return isTriggered;
+}
+
+
+//_______________________________________________________________________
+void AliMUONTriggerElectronics::ResponseRemovingChambers(AliMUONVTriggerStore& triggerStore)
+{
+  /// Update local board information with the trigger response after removing each chamber
+
+  AliCodeTimerAuto("", 0);
+
   Reset();
+  Feed(triggerStore);
+
+  AliMUONLocalTrigger* locTrg;
+  TIter next(triggerStore.CreateLocalIterator());
+  Int_t loCircuit;
+  Bool_t planeResp[2], isTrig44;
+  Bool_t bendPlaneRespNoCh, nonBendPlaneRespNoCh, isTrigWithoutCh;
+  while ( ( locTrg = static_cast<AliMUONLocalTrigger*>( next() )) != NULL ){
+    if ( ! ( locTrg->IsTrigX() && locTrg->IsTrigY() ) ) continue;
+    loCircuit = locTrg->LoCircuit();
+    isTrig44 = ModifiedLocalResponse(loCircuit, planeResp[0], planeResp[1], kTRUE);
+    for (Int_t ich=0; ich<4; ++ich){
+      if ( ! isTrig44 ){
+       isTrigWithoutCh = ModifiedLocalResponse(loCircuit, bendPlaneRespNoCh, nonBendPlaneRespNoCh, kFALSE, ich);
+       if ( ! isTrigWithoutCh ) continue;
+       for (Int_t icath=0; icath<2; icath++){
+         if ( ! planeResp[icath] )
+           locTrg->SetNoHitInPlane(icath, ich);
+       } // loop on cathodes
+      }
+      locTrg->SetTriggerWithoutChamber(ich);
+    } // loop on chambers
+    AliDebug(1, Form("Is44 %i  triggers %i  pattern %i", isTrig44, locTrg->GetTriggerWithoutChamber(), locTrg->GetHitPatternFromResponse()));
+  }
 }