]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPayloadTracker.cxx
Implemented writing and checking of parity bit in data word (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONPayloadTracker.cxx
CommitLineData
939ae4b2 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
17///////////////////////////////////////////////////////////////////////////////
18///
19/// Class Payload
20///
21/// Decodes rawdata from buffer and stores in TClonesArray.
22///
23/// First version implement for Tracker
24///
25///////////////////////////////////////////////////////////////////////////////
26
27#include "AliMUONPayloadTracker.h"
28
29#include "AliRawReader.h"
30#include "AliRawDataHeader.h"
31#include "AliLog.h"
32
33#include "AliMUONDspHeader.h"
34#include "AliMUONBlockHeader.h"
35#include "AliMUONBusStruct.h"
36#include "AliMUONDDLTracker.h"
37
38ClassImp(AliMUONPayloadTracker)
39
40AliMUONPayloadTracker::AliMUONPayloadTracker()
41 : TObject(),
42 fMaxBlock(2),
43 fMaxDsp(5),
44 fMaxBus(5)
45{
46 //
84ceeb06 47 // create an object to decode MUON payload
939ae4b2 48 //
939ae4b2 49
50 fDDLTracker = new AliMUONDDLTracker();
51 fBusStruct = new AliMUONBusStruct();
52 fBlockHeader = new AliMUONBlockHeader();
53 fDspHeader = new AliMUONDspHeader();
54}
55
56//_________________________________________________________________
57AliMUONPayloadTracker::AliMUONPayloadTracker(const AliMUONPayloadTracker& stream) :
58 TObject(stream)
59{
60 //
61 // copy ctor
62 //
63 AliFatal("copy constructor not implemented");
64}
65
66//______________________________________________________________________
67AliMUONPayloadTracker& AliMUONPayloadTracker::operator = (const AliMUONPayloadTracker&
68 /* stream */)
69{
70 //
71 // assignment operator
72 //
73 AliFatal("assignment operator not implemented");
74 return *this;
75}
76
77
78//___________________________________
79AliMUONPayloadTracker::~AliMUONPayloadTracker()
80{
81 //
82 // clean up
83 //
939ae4b2 84 delete fDDLTracker;
85 delete fBusStruct;
86 delete fBlockHeader;
87 delete fDspHeader;
88}
89
90//______________________________________________________
84ceeb06 91Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize)
939ae4b2 92{
84ceeb06 93
94 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most
95 // and each of DSP has at most 5 buspatches.
96 // The different structures, Block (CRT), DSP (FRT) and Buspatch,
97 // are identified by a key word 0xFC0000FC, 0xF000000F and 0xB000000B respectively.
98 // (fBusPatchManager no more needed !)
939ae4b2 99
100
101 //Read Header Size of DDL,Block,DSP and BusPatch
8ecc5cf0 102 static Int_t kBlockHeaderSize = fBlockHeader->GetHeaderLength();
103 static Int_t kDspHeaderSize = fDspHeader->GetHeaderLength();
104 static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
939ae4b2 105
84ceeb06 106 // size structures
939ae4b2 107 Int_t totalBlockSize;
108 Int_t totalDspSize;
109 Int_t totalBusPatchSize;
110 Int_t dataSize;
84ceeb06 111 Int_t bufSize;
939ae4b2 112
84ceeb06 113 // indexes
114 Int_t indexBlk;
115 Int_t indexDsp;
116 Int_t indexBusPatch;
117 Int_t index = 0;
118 Int_t iBlock = 0;
939ae4b2 119
84ceeb06 120 // CROCUS CRT
121 while (buffer[index] == fBlockHeader->GetDefaultDataKey()) {
939ae4b2 122
84ceeb06 123 if (iBlock > fMaxBlock) break;
124
125 // copy within padding words
126 memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4);
939ae4b2 127
84ceeb06 128 totalBlockSize = fBlockHeader->GetTotalLength();
939ae4b2 129
84ceeb06 130 indexBlk = index;
131 index += kBlockHeaderSize;
939ae4b2 132
84ceeb06 133 // copy in TClonesArray
134 fDDLTracker->AddBlkHeader(*fBlockHeader);
939ae4b2 135
84ceeb06 136 // Crocus FRT
137 Int_t iDsp = 0;
138 while (buffer[index] == fDspHeader->GetDefaultDataKey()) {
939ae4b2 139
84ceeb06 140 if (iDsp > fMaxDsp) break; // if ever...
141
142 memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
939ae4b2 143
84ceeb06 144 totalDspSize = fDspHeader->GetTotalLength();
145 indexDsp = index;
146 index += kDspHeaderSize;
939ae4b2 147
86400e61 148// if (fDspHeader->GetPaddingWord() != fDspHeader->GetDefaultPaddingWord()) {
149// // copy the field of Padding word into ErrorWord field
150// fDspHeader->SetErrorWord(fDspHeader->GetPaddingWord());
151// index--;
152// }
939ae4b2 153
84ceeb06 154 // copy in TClonesArray
155 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
939ae4b2 156
84ceeb06 157 // buspatch structure
158 Int_t iBusPatch = 0;
159 while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
939ae4b2 160
84ceeb06 161 if (iBusPatch > fMaxBus) break; // if ever
162
163 //copy buffer into header structure
164 memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
939ae4b2 165
84ceeb06 166 totalBusPatchSize = fBusStruct->GetTotalLength();
167 indexBusPatch = index;
939ae4b2 168
84ceeb06 169 //Check Buspatch header, not empty events
170 if(totalBusPatchSize > kBusPatchHeaderSize) {
171
172 index += kBusPatchHeaderSize;
173 dataSize = fBusStruct->GetLength();
174 bufSize = fBusStruct->GetBufSize();
175
176 if(dataSize > 0) { // check data present
177 if (dataSize > bufSize) // check buffer size
178 fBusStruct->SetAlloc(dataSize);
179
180 //copy buffer into data structure
181 memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
182 fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
183 fBusStruct->SetDspId(iDsp);
184
6dee95a7 185 // check parity
186 CheckDataParity();
187
84ceeb06 188 // copy in TClonesArray
189 fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
190
191 } // dataSize test
192
193 } // testing buspatch
194
195 index = indexBusPatch + totalBusPatchSize;
196 if (index >= totalDDLSize) {// check the end of DDL
197 index = totalDDLSize - 1; // point to the last element of buffer
198 break;
199 }
200 iBusPatch++;
201 } // buspatch loop
86400e61 202
203 // skipping additionnal word if padding
204 if (fDspHeader->GetPaddingWord() == 1) {
205 if (buffer[index++] != fDspHeader->GetDefaultPaddingWord())
206 AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n",
207 iBlock, iDsp, iBusPatch));
208 }
209
84ceeb06 210 index = indexDsp + totalDspSize;
211 if (index >= totalDDLSize) {
212 index = totalDDLSize - 1;
213 break;
214 }
215 iDsp++;
216 } // dsp loop
217
218 index = indexBlk + totalBlockSize;
219 if (index >= totalDDLSize) {
220 index = totalDDLSize - 1;
221 break;
222 }
223 iBlock++;
224 } // block loop
939ae4b2 225
226 return kTRUE;
227}
228
229//______________________________________________________
230void AliMUONPayloadTracker::ResetDDL()
231{
232 // reseting TClonesArray
233 // after each DDL
234 //
235 fDDLTracker->GetBlkHeaderArray()->Delete();
236}
237
238//______________________________________________________
239void AliMUONPayloadTracker::SetMaxBlock(Int_t blk)
240{
241 // set regional card number
242 if (blk > 2) blk = 2;
243 fMaxBlock = blk;
244}
607fb67b 245
6dee95a7 246//______________________________________________________
607fb67b 247Bool_t AliMUONPayloadTracker::CheckDataParity()
248{
249 // parity check
250 // taken from MuTrkBusPatch.cxx (sotfware test for CROCUS)
251 // A. Baldisseri
252
6dee95a7 253 Int_t parity;
607fb67b 254 UInt_t data;
255
256 Int_t dataSize = fBusStruct->GetLength();
257 for (int idata = 0; idata < dataSize; idata++) {
258
259 data = fBusStruct->GetData(idata);
607fb67b 260
6dee95a7 261 // Compute the parity for each data word
262 parity = data & 0x1;
263 for (Int_t i = 1; i <= 30; i++)
264 parity ^= ((data >> i) & 0x1);
607fb67b 265
266 // Check
267 if (parity != fBusStruct->GetParity(idata)) {
268 AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n",
269 idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata)));
270 return kFALSE;
271
272 }
273 }
274 return kTRUE;
275}