]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawStreamTracker.cxx
Adding definition of Dmax in constants and semantic modifications for the generation...
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTracker.cxx
CommitLineData
c0751163 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/// This class provides access to MUON digits in raw data.
20///
21/// It loops over all MUON digits in the raw data given by the AliRawReader.
22/// The Next method goes to the next digit. If there are no digits left
23/// it returns kFALSE (under develpment)
24/// It can loop also over DDL and store the decoded rawdata in TClonesArray.
25///
26/// First version implement for Tracker
27///
28///////////////////////////////////////////////////////////////////////////////
29
30#include "AliMUONRawStreamTracker.h"
31
32#include "AliRawReader.h"
33#include "AliRawDataHeader.h"
34#include "AliLog.h"
35
36#include "AliMUONDspHeader.h"
37#include "AliMUONBlockHeader.h"
38#include "AliMUONBusStruct.h"
39#include "AliMUONDDLTracker.h"
40
41ClassImp(AliMUONRawStreamTracker)
42
43AliMUONRawStreamTracker::AliMUONRawStreamTracker()
44 : TObject(),
45 fRawReader(0x0),
46 fDDL(0),
47 fBusPatchId(0),
48 fDspId(0),
49 fBlkId(0),
50 fNextDDL(kTRUE),
51 fMaxDDL(20),
52 fMaxBlock(2),
53 fMaxDsp(5),
54 fMaxBus(5)
55{
56 //
57 // create an object to read MUON raw digits
58 // Default ctor for monitoring purposes
59 //
60 fBusPatchManager = new AliMpBusPatch();
61 fBusPatchManager->ReadBusPatchFile();
62
63 fDDLTracker = new AliMUONDDLTracker();
64 fBusStruct = new AliMUONBusStruct();
65 fBlockHeader = new AliMUONBlockHeader();
66 fDspHeader = new AliMUONDspHeader();
67}
68
69//_________________________________________________________________
70AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
71 : TObject(),
72 fDDL(0),
73 fBusPatchId(0),
74 fDspId(0),
75 fBlkId(0),
76 fNextDDL(kTRUE),
77 fMaxDDL(20),
78 fMaxBlock(2),
79 fMaxDsp(5),
80 fMaxBus(5)
81{
82 //
83 // ctor with AliRawReader as argument
84 // for reconstruction purpose
85 //
86
87 fRawReader = rawReader;
88
89 fBusPatchManager = new AliMpBusPatch();
90 fBusPatchManager->ReadBusPatchFile();
91
92 fDDLTracker = new AliMUONDDLTracker();
93 fBusStruct = new AliMUONBusStruct();
94 fBlockHeader = new AliMUONBlockHeader();
95 fDspHeader = new AliMUONDspHeader();
96}
97
98//_________________________________________________________________
99AliMUONRawStreamTracker::AliMUONRawStreamTracker(const AliMUONRawStreamTracker& stream) :
100 TObject(stream)
101{
102 //
103 // copy ctor
104 //
105 AliFatal("copy constructor not implemented");
106}
107
108//______________________________________________________________________
109AliMUONRawStreamTracker& AliMUONRawStreamTracker::operator = (const AliMUONRawStreamTracker&
110 /* stream */)
111{
112 //
113 // assignment operator
114 //
115 AliFatal("assignment operator not implemented");
116 return *this;
117}
118
119
120//___________________________________
121AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
122{
123 //
124 // clean up
125 //
126 delete fBusPatchManager;
127 delete fDDLTracker;
128 delete fBusStruct;
129 delete fBlockHeader;
130 delete fDspHeader;
131}
132
133//_____________________________________________________________
134Bool_t AliMUONRawStreamTracker::Next()
135{
136 //
137 // read the next raw digit (buspatch structure)
138 // returns kFALSE if there is no digit left
139 // (under development)
140
141 AliMUONDDLTracker* ddlTracker = 0x0;
142 AliMUONBlockHeader* blkHeader = 0x0;
143 AliMUONDspHeader* dspHeader = 0x0;
144 Int_t nBusPatch;
145 Int_t nDsp;
146 Int_t nBlock;
147
148 next:
149 if (fNextDDL){
150 printf("iDDL %d\n", fDDL+1);
151 fBlkId = 0;
152 fDspId = 0;
153 fBusPatchId = 0;
154 if(!NextDDL())
155 return kFALSE;
156 }
157 fNextDDL = kFALSE;
158
159 ddlTracker = GetDDLTracker();
160
161 nBlock = ddlTracker->GetBlkHeaderEntries();
162 if (fBlkId < nBlock) {
163
164 blkHeader = ddlTracker->GetBlkHeaderEntry(fBlkId);
165 nDsp = blkHeader->GetDspHeaderEntries();
166
167 if( fDspId < nDsp) {
168 dspHeader = blkHeader->GetDspHeaderEntry(fDspId);
169 nBusPatch = dspHeader->GetBusPatchEntries();
170
171 if (fBusPatchId < nBusPatch) {
172 fBusStructPtr = dspHeader->GetBusPatchEntry(fBusPatchId++);
173 return kTRUE;
174
175 } else {// iBusPatch
176 fDspId++;
177 fBusPatchId = 0;
178 goto next;
179 // Next();
180 }
181
182 } else {// iDsp
183 fBlkId++;
184 fDspId = 0;
185 fBusPatchId = 0;
186 goto next;
187 // Next();
188 }
189
190 } else {// iBlock
191 fBlkId = 0;
192 fDspId = 0;
193 fBusPatchId = 0;
194 fNextDDL = kTRUE;
195 //return kTRUE;
196 goto next;
197 }
198
199 return kFALSE;
200}
201
202//______________________________________________________
203Bool_t AliMUONRawStreamTracker::NextDDL()
204{
205 // reading tracker DDL
206 // store buspatch info into Array
207 // store only non-empty structures (buspatch info with datalength !=0)
208
209 fDDLTracker->GetBlkHeaderArray()->Delete();
210 // fDDLTracker->GetBlkHeaderArray()->Clear("C");
211
212 //Read Header Size of DDL,Block,DSP and BusPatch
213
214 Int_t kDDLHeaderSize = sizeof(AliRawDataHeader)/4;;
215 Int_t kBlockHeaderSize = fBlockHeader->GetHeaderLength();
216 Int_t kDspHeaderSize = fDspHeader->GetHeaderLength();
217 Int_t kBusPatchHeaderSize = fBusStruct->GetHeaderLength();
218
219 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
220
221
222 Int_t iBusPerDSP[5]; // number of bus patches per DSP
223 Int_t iDspMax; // number max of DSP per block
224
225 // minimum data size (only header's)
226 Int_t blankDDLSize;
227 Int_t blankBlockSize;
228 Int_t blankDspSize;
229
230 if (fDDL >= 20) {
231 fDDL = 0;
232 return kFALSE;
233 }
234 AliDebug(3, Form("DDL Number %d\n", fDDL ));
235
236 // getting DSP info
237 fBusPatchManager->GetDspInfo(fDDL/2, iDspMax, iBusPerDSP);
238
239 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most
240 // and each of DSP has at most 5 buspatches.
241 // This information is used to calculate the size of headers (DDL,Block and DSP)
242 // which has no interesting data.
243 blankDDLSize = kDDLHeaderSize + 2*kBlockHeaderSize + 2*iDspMax*kDspHeaderSize;
244 blankBlockSize = kBlockHeaderSize + iDspMax*kDspHeaderSize;
245
246 for (Int_t i = 0; i < iDspMax; i++) {
247 blankDDLSize += 2*iBusPerDSP[i]*kBusPatchHeaderSize;
248 blankBlockSize += iBusPerDSP[i]*kBusPatchHeaderSize;
249 }
250 fRawReader->Reset();
251 fRawReader->Select(0X9, fDDL, fDDL); //Select the DDL file to be read
252
253 fRawReader->ReadHeader();
254
255 // 4 is multiplied to convert 2 bytes words
256 totalDDLSize = (fRawReader->GetDataSize() + sizeof(AliRawDataHeader))/4;
257
258 // Compare the DDL header with an empty DDL header size to read the file
259 if(totalDDLSize > blankDDLSize) {
260
261 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
262 UInt_t *buffer = new UInt_t[totalDataWord/4];
263
264 fRawReader->ReadNext((UChar_t*)buffer, totalDataWord);
265
266 // indexes
267 Int_t indexDsp;
268 Int_t indexBusPatch;
269 Int_t index = 0;
270
271 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
272
273 // copy within padding words
274 memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize+1)*4);
275
276 totalBlockSize = fBlockHeader->GetTotalLength();
277
278 fDDLTracker->AddBlkHeader(*fBlockHeader);
279
280 if (fBlockHeader->GetPadding() == 0xDEAD) // skipping padding word
281 index++;
282
283 if(totalBlockSize > blankBlockSize) { // compare block header
284 index += kBlockHeaderSize;
285
286 for(Int_t iDsp = 0; iDsp < iDspMax ;iDsp++){ //DSP loop
287
288 if (iDsp > fMaxDsp) break;
289
290 memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
291
292 totalDspSize = fDspHeader->GetTotalLength();
293 indexDsp = index;
294
295 blankDspSize = kDspHeaderSize + iBusPerDSP[iDsp]*kBusPatchHeaderSize; // no data just header
296
297 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
298
299 if(totalDspSize > blankDspSize) { // Compare DSP Header
300 index += kDspHeaderSize;
301
302 for(Int_t iBusPatch = 0; iBusPatch < iBusPerDSP[iDsp]; iBusPatch++) {
303
304 if (iBusPatch > fMaxBus) break;
305
306 //copy buffer into header structure
307 memcpy(fBusStruct->GetBusPatchHeader(), &buffer[index], kBusPatchHeaderSize*4);
308
309 totalBusPatchSize = fBusStruct->GetTotalLength();
310 indexBusPatch = index;
311
312 //Check Buspatch header, not empty events
313 if(totalBusPatchSize > kBusPatchHeaderSize) {
314
315 index += kBusPatchHeaderSize;
316 dataSize = fBusStruct->GetLength();
317 Int_t bufSize = fBusStruct->GetBufSize();
318
319 if(dataSize > 0) { // check data present
320 if (dataSize > bufSize) fBusStruct->SetAlloc(dataSize);
321
322 //copy buffer into data structure
323 memcpy(fBusStruct->GetData(), &buffer[index], dataSize*4);
324 fBusStruct->SetBlockId(iBlock); // could be usefull in future applications ?
325 fBusStruct->SetDspId(iDsp);
326 fDDLTracker->AddBusPatch(*fBusStruct, iBlock, iDsp);
327
328 } // dataSize test
329
330 } // testing buspatch
331
332 index = indexBusPatch + totalBusPatchSize;
333
334 } //buspatch loop
335
336 } // dsp test
337
338 index = indexDsp + totalDspSize;
339
340 } // dsp loop
341
342 } //block test
343
344 index = totalBlockSize;
345
346 } //block loop
347
348 delete[] buffer;
349 } //loop checking the header size of DDL
350
351
352 fDDL++;
353
354 return kTRUE;
355}
356//______________________________________________________
357void AliMUONRawStreamTracker::ResetDDL()
358{
359 // reseting TClonesArray
360 // after each DDL
361 //
362 fDDLTracker->GetBlkHeaderArray()->Clear("C");
363}
364
365//______________________________________________________
366void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl)
367{
368 // set DDL number
369 if (ddl > 20) ddl = 20;
370 fMaxDDL = ddl;
371}
372
373//______________________________________________________
374void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk)
375{
376 // set regional card number
377 if (blk > 2) blk = 2;
378 fMaxBlock = blk;
379}