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