1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
21 /// Decodes rawdata from buffer and stores in TClonesArray.
23 /// First version implement for Tracker
25 ///////////////////////////////////////////////////////////////////////////////
27 #include "AliMUONPayloadTracker.h"
29 #include "AliRawReader.h"
30 #include "AliRawDataHeader.h"
33 #include "AliMUONDspHeader.h"
34 #include "AliMUONBlockHeader.h"
35 #include "AliMUONBusStruct.h"
36 #include "AliMUONDDLTracker.h"
38 ClassImp(AliMUONPayloadTracker)
40 AliMUONPayloadTracker::AliMUONPayloadTracker()
49 fDDLTracker(new AliMUONDDLTracker()),
50 fBusStruct(new AliMUONBusStruct()),
51 fBlockHeader(new AliMUONBlockHeader()),
52 fDspHeader(new AliMUONDspHeader())
55 // create an object to decode MUON payload
60 //___________________________________
61 AliMUONPayloadTracker::~AliMUONPayloadTracker()
72 //______________________________________________________
73 Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize)
76 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most
77 // and each of DSP has at most 5 buspatches.
78 // The different structures, Block (CRT), DSP (FRT) and Buspatch,
79 // are identified by a key word 0xFC0000FC, 0xF000000F and 0xB000000B respectively.
80 // (fBusPatchManager no more needed !)
83 //Read Header Size of DDL,Block,DSP and BusPatch
84 static Int_t kBlockHeaderSize = fBlockHeader->GetHeaderLength();
85 static Int_t kDspHeaderSize = fDspHeader->GetHeaderLength();
86 static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
91 Int_t totalBusPatchSize;
103 while (buffer[index] == fBlockHeader->GetDefaultDataKey()) {
105 if (iBlock > fMaxBlock) break;
107 // copy within padding words
108 memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4);
110 totalBlockSize = fBlockHeader->GetTotalLength();
113 index += kBlockHeaderSize;
115 // copy in TClonesArray
116 fDDLTracker->AddBlkHeader(*fBlockHeader);
120 while (buffer[index] == fDspHeader->GetDefaultDataKey()) {
122 if (iDsp > fMaxDsp) break; // if ever...
124 memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
126 totalDspSize = fDspHeader->GetTotalLength();
128 index += kDspHeaderSize;
130 // if (fDspHeader->GetPaddingWord() != fDspHeader->GetDefaultPaddingWord()) {
131 // // copy the field of Padding word into ErrorWord field
132 // fDspHeader->SetErrorWord(fDspHeader->GetPaddingWord());
136 // copy in TClonesArray
137 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
139 // buspatch structure
141 while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
143 if (iBusPatch > fMaxBus) break; // if ever
145 //copy buffer into header structure
146 memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
148 totalBusPatchSize = fBusStruct->GetTotalLength();
149 indexBusPatch = index;
151 //Check Buspatch header, not empty events
152 if(totalBusPatchSize > kBusPatchHeaderSize) {
154 index += kBusPatchHeaderSize;
155 dataSize = fBusStruct->GetLength();
156 bufSize = fBusStruct->GetBufSize();
158 if(dataSize > 0) { // check data present
159 if (dataSize > bufSize) // check buffer size
160 fBusStruct->SetAlloc(dataSize);
162 //copy buffer into data structure
163 memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
164 fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
165 fBusStruct->SetDspId(iDsp);
170 // copy in TClonesArray
171 fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
175 } // testing buspatch
177 index = indexBusPatch + totalBusPatchSize;
178 if (index >= totalDDLSize) {// check the end of DDL
179 index = totalDDLSize - 1; // point to the last element of buffer
185 // skipping additionnal word if padding
186 if (fDspHeader->GetPaddingWord() == 1) {
187 if (buffer[index++] != fDspHeader->GetDefaultPaddingWord())
188 AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n",
189 iBlock, iDsp, iBusPatch));
192 index = indexDsp + totalDspSize;
193 if (index >= totalDDLSize) {
194 index = totalDDLSize - 1;
200 index = indexBlk + totalBlockSize;
201 if (index >= totalDDLSize) {
202 index = totalDDLSize - 1;
211 //______________________________________________________
212 void AliMUONPayloadTracker::ResetDDL()
214 // reseting TClonesArray
217 fDDLTracker->GetBlkHeaderArray()->Delete();
220 //______________________________________________________
221 void AliMUONPayloadTracker::SetMaxBlock(Int_t blk)
223 // set regional card number
224 if (blk > 2) blk = 2;
228 //______________________________________________________
229 Bool_t AliMUONPayloadTracker::CheckDataParity()
232 // taken from MuTrkBusPatch.cxx (sotfware test for CROCUS)
238 Int_t dataSize = fBusStruct->GetLength();
239 for (int idata = 0; idata < dataSize; idata++) {
241 data = fBusStruct->GetData(idata);
243 // Compute the parity for each data word
245 for (Int_t i = 1; i <= 30; i++)
246 parity ^= ((data >> i) & 0x1);
249 if (parity != fBusStruct->GetParity(idata)) {
250 AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n",
251 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata)));