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