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 //-----------------------------------------------------------------------------
19 /// \class AliMUONPayloadTracker
20 /// Decodes rawdata from buffer and stores in TClonesArray.
21 /// First version implement for Tracker
23 /// \author Christian Finck
24 //-----------------------------------------------------------------------------
26 #include "AliMUONPayloadTracker.h"
28 #include "AliMUONDspHeader.h"
29 #include "AliMUONBlockHeader.h"
30 #include "AliMUONBusStruct.h"
31 #include "AliMUONDDLTracker.h"
36 ClassImp(AliMUONPayloadTracker)
39 AliMUONPayloadTracker::AliMUONPayloadTracker()
48 fDDLTracker(new AliMUONDDLTracker()),
49 fBusStruct(new AliMUONBusStruct()),
50 fBlockHeader(new AliMUONBlockHeader()),
51 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 if (fDspHeader->GetErrorWord()) {
131 fDspHeader->Print("");
132 if ( fDspHeader->GetErrorWord() == (0x000000B1 | fBlockHeader->GetDspId())
133 || fDspHeader->GetErrorWord() == (0x00000091 | fBlockHeader->GetDspId()) ){
134 // an event with a glitch in the readout has been detected
135 // it means that somewhere a 1 byte word has been randomly inserted
136 // all the readout sequence is shifted untill the next event
138 AliWarning(Form("Glitch in data detected, skipping event "));
146 index += kDspHeaderSize;
148 // copy in TClonesArray
149 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
151 // buspatch structure
153 while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
155 if (iBusPatch > fMaxBus) break; // if ever
157 //copy buffer into header structure
158 memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
160 totalBusPatchSize = fBusStruct->GetTotalLength();
161 indexBusPatch = index;
163 //Check Buspatch header, not empty events
164 if(totalBusPatchSize > kBusPatchHeaderSize) {
166 index += kBusPatchHeaderSize;
167 dataSize = fBusStruct->GetLength();
168 bufSize = fBusStruct->GetBufSize();
170 if(dataSize > 0) { // check data present
171 if (dataSize > bufSize) // check buffer size
172 fBusStruct->SetAlloc(dataSize);
174 //copy buffer into data structure
175 memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
176 fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
177 fBusStruct->SetDspId(iDsp);
180 if(!CheckDataParity())
181 AddParityErrBus(fBusStruct->GetBusPatchId());
183 // copy in TClonesArray
184 fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
188 } // testing buspatch
190 index = indexBusPatch + totalBusPatchSize;
191 if (index >= totalDDLSize) {// check the end of DDL
192 index = totalDDLSize - 1; // point to the last element of buffer
198 // skipping additionnal word if padding
199 if (fDspHeader->GetPaddingWord() == 1) {
200 if (buffer[index++] != fDspHeader->GetDefaultPaddingWord())
202 AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n",
203 iBlock, iDsp, iBusPatch));
208 index = indexDsp + totalDspSize;
209 if (index >= totalDDLSize) {
210 index = totalDDLSize - 1;
216 index = indexBlk + totalBlockSize;
217 if (index >= totalDDLSize) {
218 index = totalDDLSize - 1;
227 //______________________________________________________
228 void AliMUONPayloadTracker::ResetDDL()
230 /// reseting TClonesArray
233 fDDLTracker->GetBlkHeaderArray()->Delete();
236 fParityErrBus.Reset();
240 //______________________________________________________
241 void AliMUONPayloadTracker::SetMaxBlock(Int_t blk)
243 /// set regional card number
244 if (blk > 2) blk = 2;
248 //______________________________________________________
249 Bool_t AliMUONPayloadTracker::CheckDataParity()
252 /// taken from MuTrkBusPatch.cxx (sotfware test for CROCUS)
258 Int_t dataSize = fBusStruct->GetLength();
259 for (int idata = 0; idata < dataSize; idata++) {
261 data = fBusStruct->GetData(idata);
263 // Compute the parity for each data word
265 for (Int_t i = 1; i <= 30; i++)
266 parity ^= ((data >> i) & 0x1);
269 if (parity != fBusStruct->GetParity(idata)) {
271 AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n",
272 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata)));
281 //______________________________________________________
282 void AliMUONPayloadTracker::AddParityErrBus(Int_t buspatch)
284 /// adding bus with at least on parity error
285 fParityErrBus.Set(fParityErrBus.GetSize() + 1);
286 fParityErrBus.AddAt(buspatch, fParityErrBus.GetSize() - 1);