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