]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONRawWriter.cxx
Fix small printout bug; fix OFFLINE mode run number
[u/mrichter/AliRoot.git] / MUON / AliMUONRawWriter.cxx
index c922b033ebfd21c78367ca8445ffd32c1bd8fba9..bd06a746a189da86e8054e1622e432cc9214d5f1 100644 (file)
@@ -65,6 +65,7 @@
 
 #include "AliMpDDLStore.h"
 #include "AliMpDDL.h"
+#include "AliMpRegionalTrigger.h"
 #include "AliMpTriggerCrate.h"
 #include "AliMpLocalBoard.h"
 #include "AliMpDetElement.h"
@@ -152,7 +153,7 @@ Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
 {
   /// convert digits of the current event to raw data
 
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
   
   Int_t idDDL;
   Char_t name[255];
@@ -161,9 +162,9 @@ Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
   
   if ( digitStore ) 
   {
-    AliCodeTimerAuto("for Tracker")
+    AliCodeTimerAuto("for Tracker",1)
 
-    AliMpExMap busPatchMap(true);
+    AliMpExMap busPatchMap;
 
     Int_t nDDLs = AliDAQ::NumberOfDdls("MUONTRK");
     
@@ -188,7 +189,7 @@ Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
  
   if ( triggerStore )
   {
-    AliCodeTimerAuto("for Trigger")
+    AliCodeTimerAuto("for Trigger",1)
 
     // trigger chambers
     
@@ -222,7 +223,7 @@ AliMUONRawWriter::Digits2BusPatchMap(const AliMUONVDigitStore& digitStore,
 {
   /// Create bus patch structures corresponding to digits in the store
   
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
   
   static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
     
@@ -234,8 +235,11 @@ AliMUONRawWriter::Digits2BusPatchMap(const AliMUONVDigitStore& digitStore,
   UChar_t channelId = 0;
   UShort_t charge = 0;
   Int_t busPatchId = 0;
+  Int_t currentBusPatchId = -1;
   UInt_t word;
   
+  AliMUONBusStruct* busStruct(0x0);
+  
   TIter next(digitStore.CreateTrackerIterator());
   AliMUONVDigit* digit;
   
@@ -280,9 +284,13 @@ AliMUONRawWriter::Digits2BusPatchMap(const AliMUONVDigitStore& digitStore,
       parity ^=  ((word >> i) & 0x1);
     }
     AliBitPacking::PackWord((UInt_t)parity,word,31,31);
-    
-    AliMUONBusStruct* busStruct = 
-      static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
+
+    if ( currentBusPatchId != busPatchId ) 
+    {
+      busStruct = 
+        static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
+      currentBusPatchId = busPatchId;
+    }
     
     if (!busStruct)
     {
@@ -308,7 +316,7 @@ AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
   // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch 
   //   + 10 dsp words)*5 dsps + 8 block words)*2 blocks 
  
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
 
   if (fHeader == 0x0) {
     AliError("Raw data header must be set");
@@ -339,10 +347,10 @@ AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
     for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) 
     {
       // DSP header
-      Int_t length = fDspHeader->GetHeaderLength();
-      memcpy(&fBuffer[index],fDspHeader->GetHeader(),length*4);
+      Int_t dspHeaderLength = fDspHeader->GetHeaderLength();
+      memcpy(&fBuffer[index],fDspHeader->GetHeader(),dspHeaderLength*4);
       Int_t indexDsp = index;
-      index += length; 
+      index += dspHeaderLength; 
       
       // 5 buspatches max per DSP
       for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i) 
@@ -362,14 +370,14 @@ AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
         if (busStructPtr) 
         {
           // add bus patch structure header
-          Int_t length = busStructPtr->GetHeaderLength();
-          memcpy(&fBuffer[index],busStructPtr->GetHeader(),length*4);
-          index += length;
+          Int_t busHeaderLength = busStructPtr->GetHeaderLength();
+          memcpy(&fBuffer[index],busStructPtr->GetHeader(),busHeaderLength*4);
+          index += busHeaderLength;
           
           // add bus patch data
-          length = busStructPtr->GetLength();
-          memcpy(&fBuffer[index],busStructPtr->GetData(),length*4);
-          index += length;
+          Int_t busLength = busStructPtr->GetLength();
+          memcpy(&fBuffer[index],busStructPtr->GetData(),busLength*4);
+          index += busLength;
         } 
         else 
         {
@@ -442,7 +450,7 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
 {
   /// Write trigger DDL
   
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
 
   if (fHeader == 0x0) {
     AliError("Raw data header must be set");
@@ -462,6 +470,7 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
   }
   
   Int_t gloTrigResp = gloTrg->GetGlobalResponse();
+  UInt_t *gloTrigInput = gloTrg->GetGlobalInput();
 
   UInt_t word;
   Int_t* buffer = 0;
@@ -499,7 +508,7 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
                                          kGlobalHeaderLength + kGlobalScalerLength + 2);
   if(fScalerEvent) {
     eventPhys = 0; //set to generate scaler events
-    fHeader->fWord2 |= 0x1; // set L1SwC bit on
+    fHeader->fWord2 |= (0x1 << 14); // set L1SwC bit on
   }
   if(fScalerEvent)
     buffer = new Int_t [kScalerBufferSize];
@@ -531,10 +540,14 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
     index += kDarcHeaderLength;
 
     // no global input for the moment....
-    if (iDDL == 0)
-     fDarcHeader->SetGlobalOutput(gloTrigResp);
-    else 
-     fDarcHeader->SetGlobalOutput(0);
+    if (iDDL == 0) {
+      fDarcHeader->SetGlobalOutput(gloTrigResp);
+      for (Int_t ii = 0; ii < 4; ii++) {
+       fDarcHeader->SetGlobalInput(gloTrigInput[ii],ii);
+      }
+    } else {
+      fDarcHeader->SetGlobalOutput(0);
+    }
 
     if (fScalerEvent) {
       // 6 DARC scaler words
@@ -550,15 +563,17 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
 
     if (fScalerEvent) {
       // 10 Global scaler words
-      memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
+      memcpy(&buffer[index], fDarcHeader->GetGlobalScalers(), kGlobalScalerLength*4);
       index += kGlobalScalerLength;
     }
 
     // end of global word
     buffer[index++] = fDarcHeader->GetEndOfGlobal();
+    const AliMpRegionalTrigger* reg = AliMpDDLStore::Instance()->GetRegionalTrigger(); 
 
+    Int_t nCrate = reg->GetNofTriggerCrates()/2;
     // 8 regional cards per DDL
-    for (Int_t iReg = 0; iReg < 8; ++iReg) {
+    for (Int_t iReg = 0; iReg < nCrate; ++iReg) {
 
         // crate info
       AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
@@ -567,8 +582,10 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
        AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
 
       // regional info tree, make sure that no reg card missing
-      AliMUONRegionalTrigger* regTrg  = triggerStore.FindRegional(iReg+iDDL*8);
-
+      AliMUONRegionalTrigger* regTrg  = triggerStore.FindRegional(crate->GetId());
+      if (!regTrg) 
+        AliError(Form("Missing regional board %d in trigger Store\n", crate->GetId()));
+    
       // Regional card header
       word = 0;
 
@@ -576,15 +593,15 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
       fRegHeader->SetDarcWord(word);
 
       regOut    = regTrg->GetOutput();
-      regInpHpt = regTrg->GetLocalOutput(0);
-      regInpLpt = regTrg->GetLocalOutput(1);
+      regInpLpt = regTrg->GetLocalOutput(0);
+      regInpHpt = regTrg->GetLocalOutput(1);
 
       // fill darc word, not darc status for the moment (empty)
       //see  AliMUONRegHeader.h for details
       AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31); 
-      AliBitPacking::PackWord((UInt_t)serialNb,word,19,24); 
-      AliBitPacking::PackWord((UInt_t)version,word,7,14);
-      AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
+      AliBitPacking::PackWord((UInt_t)serialNb,word,20,25); 
+      AliBitPacking::PackWord((UInt_t)version,word,8,15);
+      AliBitPacking::PackWord((UInt_t)crate->GetId(),word,16,19);
       AliBitPacking::PackWord((UInt_t)regOut,word,0,7); 
       fRegHeader->SetWord(word);
 
@@ -605,7 +622,9 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
       // 16 local card per regional board
       //      UShort_t localMask = 0x0;
       
-      for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
+      Int_t nLocalBoard = AliMpConstants::LocalBoardNofChannels();
+
+      for (Int_t iLoc = 0; iLoc < nLocalBoard; iLoc++) {
          
        // slot zero for Regional card
        Int_t localBoardId = crate->GetLocalBoardId(iLoc);
@@ -675,7 +694,7 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
          
       } // local card 
       // fill regional header with local output
-      fRegHeader->SetInput(regInpHpt, 0);
+      fRegHeader->SetInput(regInpLpt, 0);
       fRegHeader->SetInput(regInpHpt, 1);
       memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);