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 **************************************************************************/
18 /// \class AliMUONPayloadTracker
19 /// Decodes rawdata from buffer and stores in TClonesArray.
20 /// First version implement for Tracker
22 /// \author Christian Finck
24 #include "AliMUONPayloadTracker.h"
26 #include "AliRawReader.h"
27 #include "AliRawDataHeader.h"
33 #include "AliMUONDspHeader.h"
34 #include "AliMUONBlockHeader.h"
35 #include "AliMUONBusStruct.h"
36 #include "AliMUONDDLTracker.h"
39 ClassImp(AliMUONPayloadTracker)
42 AliMUONPayloadTracker::AliMUONPayloadTracker()
51 fDDLTracker(new AliMUONDDLTracker()),
52 fBusStruct(new AliMUONBusStruct()),
53 fBlockHeader(new AliMUONBlockHeader()),
54 fDspHeader(new AliMUONDspHeader())
57 /// create an object to decode MUON payload
62 //___________________________________
63 AliMUONPayloadTracker::~AliMUONPayloadTracker()
74 //______________________________________________________
75 Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize)
78 /// Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most
79 /// and each of DSP has at most 5 buspatches.
80 /// The different structures, Block (CRT), DSP (FRT) and Buspatch,
81 /// are identified by a key word 0xFC0000FC, 0xF000000F and 0xB000000B respectively.
82 /// (fBusPatchManager no more needed !)
85 //Read Header Size of DDL,Block,DSP and BusPatch
86 static Int_t kBlockHeaderSize = fBlockHeader->GetHeaderLength();
87 static Int_t kDspHeaderSize = fDspHeader->GetHeaderLength();
88 static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
93 Int_t totalBusPatchSize;
105 while (buffer[index] == fBlockHeader->GetDefaultDataKey()) {
107 if (iBlock > fMaxBlock) break;
109 // copy within padding words
110 memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4);
112 totalBlockSize = fBlockHeader->GetTotalLength();
115 index += kBlockHeaderSize;
117 // copy in TClonesArray
118 fDDLTracker->AddBlkHeader(*fBlockHeader);
122 while (buffer[index] == fDspHeader->GetDefaultDataKey()) {
124 if (iDsp > fMaxDsp) break; // if ever...
126 memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
128 totalDspSize = fDspHeader->GetTotalLength();
130 index += kDspHeaderSize;
132 // if (fDspHeader->GetPaddingWord() != fDspHeader->GetDefaultPaddingWord()) {
133 // // copy the field of Padding word into ErrorWord field
134 // fDspHeader->SetErrorWord(fDspHeader->GetPaddingWord());
138 // copy in TClonesArray
139 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
141 // buspatch structure
143 while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
145 if (iBusPatch > fMaxBus) break; // if ever
147 //copy buffer into header structure
148 memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
150 totalBusPatchSize = fBusStruct->GetTotalLength();
151 indexBusPatch = index;
153 //Check Buspatch header, not empty events
154 if(totalBusPatchSize > kBusPatchHeaderSize) {
156 index += kBusPatchHeaderSize;
157 dataSize = fBusStruct->GetLength();
158 bufSize = fBusStruct->GetBufSize();
160 if(dataSize > 0) { // check data present
161 if (dataSize > bufSize) // check buffer size
162 fBusStruct->SetAlloc(dataSize);
164 //copy buffer into data structure
165 memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
166 fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
167 fBusStruct->SetDspId(iDsp);
172 // copy in TClonesArray
173 fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
177 } // testing buspatch
179 index = indexBusPatch + totalBusPatchSize;
180 if (index >= totalDDLSize) {// check the end of DDL
181 index = totalDDLSize - 1; // point to the last element of buffer
187 // skipping additionnal word if padding
188 if (fDspHeader->GetPaddingWord() == 1) {
189 if (buffer[index++] != fDspHeader->GetDefaultPaddingWord())
192 AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n",
193 iBlock, iDsp, iBusPatch));
195 printf("Error in padding word for iBlock %d, iDsp %d, iBus %d\n", iBlock, iDsp, iBusPatch);
199 index = indexDsp + totalDspSize;
200 if (index >= totalDDLSize) {
201 index = totalDDLSize - 1;
207 index = indexBlk + totalBlockSize;
208 if (index >= totalDDLSize) {
209 index = totalDDLSize - 1;
218 //______________________________________________________
219 void AliMUONPayloadTracker::ResetDDL()
221 /// reseting TClonesArray
224 fDDLTracker->GetBlkHeaderArray()->Delete();
227 //______________________________________________________
228 void AliMUONPayloadTracker::SetMaxBlock(Int_t blk)
230 /// set regional card number
231 if (blk > 2) blk = 2;
235 //______________________________________________________
236 Bool_t AliMUONPayloadTracker::CheckDataParity()
239 /// taken from MuTrkBusPatch.cxx (sotfware test for CROCUS)
245 Int_t dataSize = fBusStruct->GetLength();
246 for (int idata = 0; idata < dataSize; idata++) {
248 data = fBusStruct->GetData(idata);
250 // Compute the parity for each data word
252 for (Int_t i = 1; i <= 30; i++)
253 parity ^= ((data >> i) & 0x1);
256 if (parity != fBusStruct->GetParity(idata)) {
258 AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n",
259 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata)));
261 printf("Parity error in word %d for manuId %d and channel %d\n",
262 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata));