]>
Commit | Line | Data |
---|---|---|
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 | ||
3d1463c8 | 16 | // $Id$ |
17 | ||
18 | //----------------------------------------------------------------------------- | |
00e86732 | 19 | /// \class AliMUONPayloadTracker |
939ae4b2 | 20 | /// Decodes rawdata from buffer and stores in TClonesArray. |
939ae4b2 | 21 | /// First version implement for Tracker |
22 | /// | |
00e86732 | 23 | /// \author Christian Finck |
3d1463c8 | 24 | //----------------------------------------------------------------------------- |
939ae4b2 | 25 | |
26 | #include "AliMUONPayloadTracker.h" | |
27 | ||
939ae4b2 | 28 | #include "AliMUONDspHeader.h" |
29 | #include "AliMUONBlockHeader.h" | |
30 | #include "AliMUONBusStruct.h" | |
31 | #include "AliMUONDDLTracker.h" | |
32 | ||
1ed3c5c2 | 33 | #include "AliLog.h" |
34 | ||
00e86732 | 35 | /// \cond CLASSIMP |
939ae4b2 | 36 | ClassImp(AliMUONPayloadTracker) |
00e86732 | 37 | /// \endcond |
939ae4b2 | 38 | |
39 | AliMUONPayloadTracker::AliMUONPayloadTracker() | |
40 | : TObject(), | |
9f5dcca3 | 41 | fBusPatchId(0), |
42 | fDspId(0), | |
43 | fBlkId(0), | |
44 | fMaxDDL(20), | |
939ae4b2 | 45 | fMaxBlock(2), |
46 | fMaxDsp(5), | |
9f5dcca3 | 47 | fMaxBus(5), |
48 | fDDLTracker(new AliMUONDDLTracker()), | |
49 | fBusStruct(new AliMUONBusStruct()), | |
50 | fBlockHeader(new AliMUONBlockHeader()), | |
1ed3c5c2 | 51 | fDspHeader(new AliMUONDspHeader()), |
52 | fParityErrBus(), | |
b48fc831 | 53 | fGlitchErrors(0), |
54 | fPaddingErrors(0) | |
939ae4b2 | 55 | { |
71a2d3aa | 56 | /// |
57 | /// create an object to decode MUON payload | |
58 | /// | |
939ae4b2 | 59 | |
939ae4b2 | 60 | } |
61 | ||
939ae4b2 | 62 | //___________________________________ |
63 | AliMUONPayloadTracker::~AliMUONPayloadTracker() | |
64 | { | |
71a2d3aa | 65 | /// |
66 | /// clean up | |
67 | /// | |
939ae4b2 | 68 | delete fDDLTracker; |
69 | delete fBusStruct; | |
70 | delete fBlockHeader; | |
71 | delete fDspHeader; | |
72 | } | |
73 | ||
74 | //______________________________________________________ | |
84ceeb06 | 75 | Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize) |
939ae4b2 | 76 | { |
84ceeb06 | 77 | |
71a2d3aa | 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 !) | |
939ae4b2 | 83 | |
84 | ||
85 | //Read Header Size of DDL,Block,DSP and BusPatch | |
8ecc5cf0 | 86 | static Int_t kBlockHeaderSize = fBlockHeader->GetHeaderLength(); |
87 | static Int_t kDspHeaderSize = fDspHeader->GetHeaderLength(); | |
88 | static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength(); | |
939ae4b2 | 89 | |
84ceeb06 | 90 | // size structures |
939ae4b2 | 91 | Int_t totalBlockSize; |
92 | Int_t totalDspSize; | |
93 | Int_t totalBusPatchSize; | |
94 | Int_t dataSize; | |
84ceeb06 | 95 | Int_t bufSize; |
939ae4b2 | 96 | |
84ceeb06 | 97 | // indexes |
98 | Int_t indexBlk; | |
99 | Int_t indexDsp; | |
100 | Int_t indexBusPatch; | |
101 | Int_t index = 0; | |
102 | Int_t iBlock = 0; | |
939ae4b2 | 103 | |
84ceeb06 | 104 | // CROCUS CRT |
105 | while (buffer[index] == fBlockHeader->GetDefaultDataKey()) { | |
939ae4b2 | 106 | |
84ceeb06 | 107 | if (iBlock > fMaxBlock) break; |
108 | ||
109 | // copy within padding words | |
110 | memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4); | |
939ae4b2 | 111 | |
84ceeb06 | 112 | totalBlockSize = fBlockHeader->GetTotalLength(); |
939ae4b2 | 113 | |
84ceeb06 | 114 | indexBlk = index; |
115 | index += kBlockHeaderSize; | |
939ae4b2 | 116 | |
84ceeb06 | 117 | // copy in TClonesArray |
118 | fDDLTracker->AddBlkHeader(*fBlockHeader); | |
939ae4b2 | 119 | |
84ceeb06 | 120 | // Crocus FRT |
121 | Int_t iDsp = 0; | |
122 | while (buffer[index] == fDspHeader->GetDefaultDataKey()) { | |
939ae4b2 | 123 | |
84ceeb06 | 124 | if (iDsp > fMaxDsp) break; // if ever... |
125 | ||
126 | memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4); | |
939ae4b2 | 127 | |
84ceeb06 | 128 | totalDspSize = fDspHeader->GetTotalLength(); |
1ed3c5c2 | 129 | |
130 | if (fDspHeader->GetErrorWord()) { | |
131 | fDspHeader->Print(""); | |
d806c948 | 132 | if ( fDspHeader->GetErrorWord() == (0x000000B1 | fBlockHeader->GetDspId()) |
133 | || fDspHeader->GetErrorWord() == (0x00000091 | fBlockHeader->GetDspId()) ){ | |
1ed3c5c2 | 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 | |
137 | ||
138 | AliWarning(Form("Glitch in data detected, skipping event ")); | |
139 | ||
140 | fGlitchErrors++; | |
141 | return kFALSE ; | |
142 | } | |
143 | } | |
144 | ||
84ceeb06 | 145 | indexDsp = index; |
146 | index += kDspHeaderSize; | |
939ae4b2 | 147 | |
84ceeb06 | 148 | // copy in TClonesArray |
149 | fDDLTracker->AddDspHeader(*fDspHeader, iBlock); | |
939ae4b2 | 150 | |
84ceeb06 | 151 | // buspatch structure |
152 | Int_t iBusPatch = 0; | |
153 | while (buffer[index] == fBusStruct->GetDefaultDataKey()) { | |
939ae4b2 | 154 | |
84ceeb06 | 155 | if (iBusPatch > fMaxBus) break; // if ever |
156 | ||
157 | //copy buffer into header structure | |
158 | memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4); | |
939ae4b2 | 159 | |
84ceeb06 | 160 | totalBusPatchSize = fBusStruct->GetTotalLength(); |
161 | indexBusPatch = index; | |
939ae4b2 | 162 | |
84ceeb06 | 163 | //Check Buspatch header, not empty events |
164 | if(totalBusPatchSize > kBusPatchHeaderSize) { | |
165 | ||
166 | index += kBusPatchHeaderSize; | |
167 | dataSize = fBusStruct->GetLength(); | |
168 | bufSize = fBusStruct->GetBufSize(); | |
169 | ||
170 | if(dataSize > 0) { // check data present | |
171 | if (dataSize > bufSize) // check buffer size | |
172 | fBusStruct->SetAlloc(dataSize); | |
173 | ||
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); | |
178 | ||
6dee95a7 | 179 | // check parity |
1ed3c5c2 | 180 | if(!CheckDataParity()) |
181 | AddParityErrBus(fBusStruct->GetBusPatchId()); | |
6dee95a7 | 182 | |
84ceeb06 | 183 | // copy in TClonesArray |
184 | fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp); | |
185 | ||
186 | } // dataSize test | |
187 | ||
188 | } // testing buspatch | |
189 | ||
190 | index = indexBusPatch + totalBusPatchSize; | |
191 | if (index >= totalDDLSize) {// check the end of DDL | |
192 | index = totalDDLSize - 1; // point to the last element of buffer | |
193 | break; | |
194 | } | |
195 | iBusPatch++; | |
196 | } // buspatch loop | |
86400e61 | 197 | |
198 | // skipping additionnal word if padding | |
199 | if (fDspHeader->GetPaddingWord() == 1) { | |
200 | if (buffer[index++] != fDspHeader->GetDefaultPaddingWord()) | |
77a606e8 | 201 | |
ea59383d | 202 | AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n", |
86400e61 | 203 | iBlock, iDsp, iBusPatch)); |
1ed3c5c2 | 204 | |
ea59383d | 205 | fPaddingErrors++; |
86400e61 | 206 | } |
207 | ||
84ceeb06 | 208 | index = indexDsp + totalDspSize; |
209 | if (index >= totalDDLSize) { | |
210 | index = totalDDLSize - 1; | |
211 | break; | |
212 | } | |
213 | iDsp++; | |
214 | } // dsp loop | |
215 | ||
216 | index = indexBlk + totalBlockSize; | |
217 | if (index >= totalDDLSize) { | |
218 | index = totalDDLSize - 1; | |
219 | break; | |
220 | } | |
221 | iBlock++; | |
222 | } // block loop | |
939ae4b2 | 223 | |
224 | return kTRUE; | |
225 | } | |
226 | ||
227 | //______________________________________________________ | |
228 | void AliMUONPayloadTracker::ResetDDL() | |
229 | { | |
71a2d3aa | 230 | /// reseting TClonesArray |
231 | /// after each DDL | |
232 | /// | |
939ae4b2 | 233 | fDDLTracker->GetBlkHeaderArray()->Delete(); |
1ed3c5c2 | 234 | fGlitchErrors = 0; |
ea59383d | 235 | fPaddingErrors = 0; |
1ed3c5c2 | 236 | fParityErrBus.Reset(); |
237 | ||
939ae4b2 | 238 | } |
239 | ||
240 | //______________________________________________________ | |
241 | void AliMUONPayloadTracker::SetMaxBlock(Int_t blk) | |
242 | { | |
71a2d3aa | 243 | /// set regional card number |
939ae4b2 | 244 | if (blk > 2) blk = 2; |
245 | fMaxBlock = blk; | |
246 | } | |
607fb67b | 247 | |
6dee95a7 | 248 | //______________________________________________________ |
607fb67b | 249 | Bool_t AliMUONPayloadTracker::CheckDataParity() |
250 | { | |
71a2d3aa | 251 | /// parity check |
252 | /// taken from MuTrkBusPatch.cxx (sotfware test for CROCUS) | |
253 | /// A. Baldisseri | |
607fb67b | 254 | |
6dee95a7 | 255 | Int_t parity; |
607fb67b | 256 | UInt_t data; |
257 | ||
258 | Int_t dataSize = fBusStruct->GetLength(); | |
259 | for (int idata = 0; idata < dataSize; idata++) { | |
260 | ||
261 | data = fBusStruct->GetData(idata); | |
607fb67b | 262 | |
6dee95a7 | 263 | // Compute the parity for each data word |
264 | parity = data & 0x1; | |
265 | for (Int_t i = 1; i <= 30; i++) | |
266 | parity ^= ((data >> i) & 0x1); | |
607fb67b | 267 | |
268 | // Check | |
269 | if (parity != fBusStruct->GetParity(idata)) { | |
1ed3c5c2 | 270 | |
607fb67b | 271 | AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n", |
272 | idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata))); | |
77a606e8 | 273 | |
607fb67b | 274 | return kFALSE; |
275 | ||
276 | } | |
277 | } | |
278 | return kTRUE; | |
279 | } | |
1ed3c5c2 | 280 | |
281 | //______________________________________________________ | |
282 | void AliMUONPayloadTracker::AddParityErrBus(Int_t buspatch) | |
283 | { | |
b8f24738 | 284 | /// adding bus with at least on parity error |
1ed3c5c2 | 285 | fParityErrBus.Set(fParityErrBus.GetSize() + 1); |
286 | fParityErrBus.AddAt(buspatch, fParityErrBus.GetSize() - 1); | |
287 | } |