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"
36 #include "AliMUONDspHeader.h"
37 #include "AliMUONBlockHeader.h"
38 #include "AliMUONBusStruct.h"
39 #include "AliMUONDDLTracker.h"
41 ClassImp(AliMUONPayloadTracker)
43 AliMUONPayloadTracker::AliMUONPayloadTracker()
52 fDDLTracker(new AliMUONDDLTracker()),
53 fBusStruct(new AliMUONBusStruct()),
54 fBlockHeader(new AliMUONBlockHeader()),
55 fDspHeader(new AliMUONDspHeader())
58 // create an object to decode MUON payload
63 //___________________________________
64 AliMUONPayloadTracker::~AliMUONPayloadTracker()
75 //______________________________________________________
76 Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize)
79 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most
80 // and each of DSP has at most 5 buspatches.
81 // The different structures, Block (CRT), DSP (FRT) and Buspatch,
82 // are identified by a key word 0xFC0000FC, 0xF000000F and 0xB000000B respectively.
83 // (fBusPatchManager no more needed !)
86 //Read Header Size of DDL,Block,DSP and BusPatch
87 static Int_t kBlockHeaderSize = fBlockHeader->GetHeaderLength();
88 static Int_t kDspHeaderSize = fDspHeader->GetHeaderLength();
89 static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
94 Int_t totalBusPatchSize;
106 while (buffer[index] == fBlockHeader->GetDefaultDataKey()) {
108 if (iBlock > fMaxBlock) break;
110 // copy within padding words
111 memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4);
113 totalBlockSize = fBlockHeader->GetTotalLength();
116 index += kBlockHeaderSize;
118 // copy in TClonesArray
119 fDDLTracker->AddBlkHeader(*fBlockHeader);
123 while (buffer[index] == fDspHeader->GetDefaultDataKey()) {
125 if (iDsp > fMaxDsp) break; // if ever...
127 memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
129 totalDspSize = fDspHeader->GetTotalLength();
131 index += kDspHeaderSize;
133 // if (fDspHeader->GetPaddingWord() != fDspHeader->GetDefaultPaddingWord()) {
134 // // copy the field of Padding word into ErrorWord field
135 // fDspHeader->SetErrorWord(fDspHeader->GetPaddingWord());
139 // copy in TClonesArray
140 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
142 // buspatch structure
144 while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
146 if (iBusPatch > fMaxBus) break; // if ever
148 //copy buffer into header structure
149 memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
151 totalBusPatchSize = fBusStruct->GetTotalLength();
152 indexBusPatch = index;
154 //Check Buspatch header, not empty events
155 if(totalBusPatchSize > kBusPatchHeaderSize) {
157 index += kBusPatchHeaderSize;
158 dataSize = fBusStruct->GetLength();
159 bufSize = fBusStruct->GetBufSize();
161 if(dataSize > 0) { // check data present
162 if (dataSize > bufSize) // check buffer size
163 fBusStruct->SetAlloc(dataSize);
165 //copy buffer into data structure
166 memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
167 fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
168 fBusStruct->SetDspId(iDsp);
173 // copy in TClonesArray
174 fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
178 } // testing buspatch
180 index = indexBusPatch + totalBusPatchSize;
181 if (index >= totalDDLSize) {// check the end of DDL
182 index = totalDDLSize - 1; // point to the last element of buffer
188 // skipping additionnal word if padding
189 if (fDspHeader->GetPaddingWord() == 1) {
190 if (buffer[index++] != fDspHeader->GetDefaultPaddingWord())
193 AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n",
194 iBlock, iDsp, iBusPatch));
196 printf("Error in padding word for iBlock %d, iDsp %d, iBus %d\n", iBlock, iDsp, iBusPatch);
200 index = indexDsp + totalDspSize;
201 if (index >= totalDDLSize) {
202 index = totalDDLSize - 1;
208 index = indexBlk + totalBlockSize;
209 if (index >= totalDDLSize) {
210 index = totalDDLSize - 1;
219 //______________________________________________________
220 void AliMUONPayloadTracker::ResetDDL()
222 // reseting TClonesArray
225 fDDLTracker->GetBlkHeaderArray()->Delete();
228 //______________________________________________________
229 void AliMUONPayloadTracker::SetMaxBlock(Int_t blk)
231 // set regional card number
232 if (blk > 2) blk = 2;
236 //______________________________________________________
237 Bool_t AliMUONPayloadTracker::CheckDataParity()
240 // taken from MuTrkBusPatch.cxx (sotfware test for CROCUS)
246 Int_t dataSize = fBusStruct->GetLength();
247 for (int idata = 0; idata < dataSize; idata++) {
249 data = fBusStruct->GetData(idata);
251 // Compute the parity for each data word
253 for (Int_t i = 1; i <= 30; i++)
254 parity ^= ((data >> i) & 0x1);
257 if (parity != fBusStruct->GetParity(idata)) {
259 AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n",
260 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata)));
262 printf("Parity error in word %d for manuId %d and channel %d\n",
263 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata));