]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONRawWriter.cxx
- Adding check and flagging for HG present
[u/mrichter/AliRoot.git] / MUON / AliMUONRawWriter.cxx
index 532b63b0b8cf0cae6b0f9d8d79968f88758d6b4c..f4359bb7d57efbc56a0b6ee8ab104ec53f49acdb 100644 (file)
@@ -63,6 +63,7 @@
 #include "AliMUONVTriggerStore.h"
 #include "AliCodeTimer.h"
 
+#include "AliMpCDB.h"
 #include "AliMpDDLStore.h"
 #include "AliMpDDL.h"
 #include "AliMpRegionalTrigger.h"
@@ -113,6 +114,13 @@ AliMUONRawWriter::AliMUONRawWriter()
   fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
   fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
 
+  // Load mapping
+  if ( ! fDDLStore ) {
+    if ( ! AliMpCDB::LoadDDLStore() ) {
+      AliFatal("Could not access mapping from OCDB !");
+    }
+    fDDLStore = AliMpDDLStore::Instance();
+  }  
 }
 
 //__________________________________________________________________________
@@ -148,12 +156,12 @@ void  AliMUONRawWriter::LocalWordPacking(UInt_t& word, UInt_t locId, UInt_t locD
 }
 
 //____________________________________________________________________
-Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
-                                   AliMUONVTriggerStore* triggerStore)
+Int_t AliMUONRawWriter::Digits2Raw(const AliMUONVDigitStore* digitStore,
+                                   const AliMUONVTriggerStore* triggerStore)
 {
   /// convert digits of the current event to raw data
 
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
   
   Int_t idDDL;
   Char_t name[255];
@@ -162,9 +170,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");
     
@@ -189,7 +197,7 @@ Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
  
   if ( triggerStore )
   {
-    AliCodeTimerAuto("for Trigger")
+    AliCodeTimerAuto("for Trigger",1)
 
     // trigger chambers
     
@@ -223,7 +231,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.
     
@@ -235,8 +243,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;
   
@@ -281,9 +292,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)
     {
@@ -309,7 +324,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");
@@ -443,7 +458,7 @@ Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore
 {
   /// Write trigger DDL
   
-  AliCodeTimerAuto("")
+  AliCodeTimerAuto("",0)
 
   if (fHeader == 0x0) {
     AliError("Raw data header must be set");
@@ -463,6 +478,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;
@@ -532,10 +548,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
@@ -551,7 +571,7 @@ 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;
     }
 
@@ -581,15 +601,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);
 
@@ -682,7 +702,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);