]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPayloadTracker.cxx
- Adding the array of slat segmentation and GetLayerSegmentation(..) method
[u/mrichter/AliRoot.git] / MUON / AliMUONPayloadTracker.cxx
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
32 #ifndef DATE_SYS
33 #include "AliLog.h"
34 #endif
35
36 #include "AliMUONDspHeader.h"
37 #include "AliMUONBlockHeader.h"
38 #include "AliMUONBusStruct.h"
39 #include "AliMUONDDLTracker.h"
40
41 ClassImp(AliMUONPayloadTracker)
42
43 AliMUONPayloadTracker::AliMUONPayloadTracker()
44   : TObject(),
45     fBusPatchId(0),
46     fDspId(0),
47     fBlkId(0),
48     fMaxDDL(20),
49     fMaxBlock(2),
50     fMaxDsp(5),
51     fMaxBus(5),
52     fDDLTracker(new AliMUONDDLTracker()),
53     fBusStruct(new AliMUONBusStruct()),
54     fBlockHeader(new AliMUONBlockHeader()),
55     fDspHeader(new AliMUONDspHeader())
56 {
57   //
58   // create an object to decode MUON payload
59   //
60
61 }
62
63 //___________________________________
64 AliMUONPayloadTracker::~AliMUONPayloadTracker()
65 {
66   //
67   // clean up
68   //
69   delete fDDLTracker;
70   delete fBusStruct;
71   delete fBlockHeader;
72   delete fDspHeader;
73 }
74
75 //______________________________________________________
76 Bool_t AliMUONPayloadTracker::Decode(UInt_t* buffer, Int_t totalDDLSize)
77 {
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 !)
84
85
86   //Read Header Size of DDL,Block,DSP and BusPatch
87   static Int_t kBlockHeaderSize    = fBlockHeader->GetHeaderLength();
88   static Int_t kDspHeaderSize      = fDspHeader->GetHeaderLength();
89   static Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
90
91   // size structures
92   Int_t totalBlockSize;
93   Int_t totalDspSize;
94   Int_t totalBusPatchSize;
95   Int_t dataSize; 
96   Int_t bufSize;
97
98   // indexes
99   Int_t indexBlk;
100   Int_t indexDsp;
101   Int_t indexBusPatch;
102   Int_t index = 0;
103   Int_t iBlock = 0;
104
105   // CROCUS CRT
106   while (buffer[index] == fBlockHeader->GetDefaultDataKey()) {
107
108     if (iBlock > fMaxBlock) break;
109      
110     // copy within padding words
111     memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize)*4);
112
113     totalBlockSize = fBlockHeader->GetTotalLength();
114
115     indexBlk = index;
116     index += kBlockHeaderSize;
117
118     // copy in TClonesArray
119     fDDLTracker->AddBlkHeader(*fBlockHeader);
120
121     // Crocus FRT
122     Int_t iDsp = 0;
123     while (buffer[index] == fDspHeader->GetDefaultDataKey()) {
124
125       if (iDsp > fMaxDsp) break; // if ever...
126                 
127       memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
128
129       totalDspSize = fDspHeader->GetTotalLength();
130       indexDsp = index;
131       index += kDspHeaderSize;
132
133 //       if (fDspHeader->GetPaddingWord() != fDspHeader->GetDefaultPaddingWord()) {
134 //      // copy the field of Padding word into ErrorWord field
135 //      fDspHeader->SetErrorWord(fDspHeader->GetPaddingWord());
136 //      index--;
137 //       }
138
139       // copy in TClonesArray
140       fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
141
142       // buspatch structure
143       Int_t iBusPatch = 0;
144       while (buffer[index] == fBusStruct->GetDefaultDataKey()) {
145
146         if (iBusPatch > fMaxBus) break; // if ever
147         
148         //copy buffer into header structure
149         memcpy(fBusStruct->GetHeader(), &buffer[index], kBusPatchHeaderSize*4);
150
151         totalBusPatchSize = fBusStruct->GetTotalLength();
152         indexBusPatch     = index;
153                 
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
170             // check parity
171             CheckDataParity();
172
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
187
188       // skipping additionnal word if padding
189       if (fDspHeader->GetPaddingWord() == 1) {
190         if (buffer[index++] != fDspHeader->GetDefaultPaddingWord())
191
192 #ifndef DATE_SYS
193           AliWarning(Form("Error in padding word for iBlock %d, iDsp %d, iBus %d\n", 
194                           iBlock, iDsp, iBusPatch));
195 #else
196         printf("Error in padding word for iBlock %d, iDsp %d, iBus %d\n", iBlock, iDsp, iBusPatch);
197 #endif
198       }
199
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
215
216   return kTRUE;
217 }
218
219 //______________________________________________________
220 void AliMUONPayloadTracker::ResetDDL()
221 {
222   // reseting TClonesArray
223   // after each DDL
224   //
225   fDDLTracker->GetBlkHeaderArray()->Delete();
226 }
227
228 //______________________________________________________
229 void AliMUONPayloadTracker::SetMaxBlock(Int_t blk) 
230 {
231   // set regional card number
232   if (blk > 2) blk = 2;
233   fMaxBlock = blk;
234 }
235
236 //______________________________________________________
237 Bool_t AliMUONPayloadTracker::CheckDataParity()
238 {
239   // parity check
240   // taken from MuTrkBusPatch.cxx (sotfware test for CROCUS)
241   // A. Baldisseri
242
243   Int_t  parity;
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);
250
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);
255
256     // Check
257     if (parity != fBusStruct->GetParity(idata)) {
258 #ifndef DATE_SYS
259       AliWarning(Form("Parity error in word %d for manuId %d and channel %d\n", 
260                       idata, fBusStruct->GetManuId(idata), fBusStruct->GetChannelId(idata)));
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
266       return kFALSE;
267                      
268     }
269   }
270   return kTRUE;
271 }