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 /// \class AliMUONPayloadTracker
18 /// Decodes rawdata from buffer and stores in TClonesArray.
19 /// First version implement for Tracker
21 /// \author Christian Finck
23 #include "AliMUONPayloadTracker.h"
25 #include "AliMUONDspHeader.h"
26 #include "AliMUONBlockHeader.h"
27 #include "AliMUONBusStruct.h"
28 #include "AliMUONDDLTracker.h"
33 ClassImp(AliMUONPayloadTracker)
36 AliMUONPayloadTracker::AliMUONPayloadTracker()
45 fDDLTracker(new AliMUONDDLTracker()),
46 fBusStruct(new AliMUONBusStruct()),
47 fBlockHeader(new AliMUONBlockHeader()),
48 fDspHeader(new AliMUONDspHeader()),
53 /// create an object to decode MUON payload
58 //___________________________________
59 AliMUONPayloadTracker::~AliMUONPayloadTracker()
70 //______________________________________________________
71 Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize)
74 /// Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most
75 /// and each of DSP has at most 5 buspatches.
76 /// The different structures, Block (CRT), DSP (FRT) and Buspatch,
77 /// are identified by a key word 0xFC0000FC, 0xF000000F and 0xB000000B respectively.
78 /// (fBusPatchManager no more needed !)
81 //Read Header Size of DDL,Block,DSP and BusPatch
82 static Int_t kBlockHeaderSize = fBlockHeader->GetHeaderLength();
83 static Int_t kDspHeaderSize = fDspHeader->GetHeaderLength();
84 static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
89 Int_t totalBusPatchSize;
101 while (buffer[index] == fBlockHeader->GetDefaultDataKey()) {
103 if (iBlock > fMaxBlock) break;
105 // copy within padding words
106 memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4);
108 totalBlockSize = fBlockHeader->GetTotalLength();
111 index += kBlockHeaderSize;
113 // copy in TClonesArray
114 fDDLTracker->AddBlkHeader(*fBlockHeader);
118 while (buffer[index] == fDspHeader->GetDefaultDataKey()) {
120 if (iDsp > fMaxDsp) break; // if ever...
122 memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
124 totalDspSize = fDspHeader->GetTotalLength();
126 if (fDspHeader->GetErrorWord()) {
127 fDspHeader->Print("");
128 if (fDspHeader->GetErrorWord() == (0x000000B1 | fBlockHeader->GetDspId())){
129 // an event with a glitch in the readout has been detected
130 // it means that somewhere a 1 byte word has been randomly inserted
131 // all the readout sequence is shifted untill the next event
133 AliWarning(Form("Glitch in data detected, skipping event "));
141 index += kDspHeaderSize;
143 // copy in TClonesArray
144 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
146 // buspatch structure
148 while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
150 if (iBusPatch > fMaxBus) break; // if ever
152 //copy buffer into header structure
153 memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
155 totalBusPatchSize = fBusStruct->GetTotalLength();
156 indexBusPatch = index;
158 //Check Buspatch header, not empty events
159 if(totalBusPatchSize > kBusPatchHeaderSize) {
161 index += kBusPatchHeaderSize;
162 dataSize = fBusStruct->GetLength();
163 bufSize = fBusStruct->GetBufSize();
165 if(dataSize > 0) { // check data present
166 if (dataSize > bufSize) // check buffer size
167 fBusStruct->SetAlloc(dataSize);
169 //copy buffer into data structure
170 memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
171 fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
172 fBusStruct->SetDspId(iDsp);
175 if(!CheckDataParity())
176 AddParityErrBus(fBusStruct->GetBusPatchId());
178 // copy in TClonesArray
179 fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
183 } // testing buspatch
185 index = indexBusPatch + totalBusPatchSize;
186 if (index >= totalDDLSize) {// check the end of DDL
187 index = totalDDLSize - 1; // point to the last element of buffer
193 // skipping additionnal word if padding
194 if (fDspHeader->GetPaddingWord() == 1) {
195 if (buffer[index++] != fDspHeader->GetDefaultPaddingWord())
197 AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n",
198 iBlock, iDsp, iBusPatch));
203 index = indexDsp + totalDspSize;
204 if (index >= totalDDLSize) {
205 index = totalDDLSize - 1;
211 index = indexBlk + totalBlockSize;
212 if (index >= totalDDLSize) {
213 index = totalDDLSize - 1;
222 //______________________________________________________
223 void AliMUONPayloadTracker::ResetDDL()
225 /// reseting TClonesArray
228 fDDLTracker->GetBlkHeaderArray()->Delete();
231 fParityErrBus.Reset();
235 //______________________________________________________
236 void AliMUONPayloadTracker::SetMaxBlock(Int_t blk)
238 /// set regional card number
239 if (blk > 2) blk = 2;
243 //______________________________________________________
244 Bool_t AliMUONPayloadTracker::CheckDataParity()
247 /// taken from MuTrkBusPatch.cxx (sotfware test for CROCUS)
253 Int_t dataSize = fBusStruct->GetLength();
254 for (int idata = 0; idata < dataSize; idata++) {
256 data = fBusStruct->GetData(idata);
258 // Compute the parity for each data word
260 for (Int_t i = 1; i <= 30; i++)
261 parity ^= ((data >> i) & 0x1);
264 if (parity != fBusStruct->GetParity(idata)) {
266 AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n",
267 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata)));
276 //______________________________________________________
277 void AliMUONPayloadTracker::AddParityErrBus(Int_t buspatch)
279 /// adding bus with at least on parity error
280 fParityErrBus.Set(fParityErrBus.GetSize() + 1);
281 fParityErrBus.AddAt(buspatch, fParityErrBus.GetSize() - 1);