1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 /// This class provides access to MUON digits in raw data.
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.
26 /// First version implement for Tracker
28 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliMUONRawStreamTracker.h"
32 #include "AliRawReader.h"
33 #include "AliRawDataHeader.h"
36 #include "AliMUONDspHeader.h"
37 #include "AliMUONBlockHeader.h"
38 #include "AliMUONBusStruct.h"
39 #include "AliMUONDDLTracker.h"
41 ClassImp(AliMUONRawStreamTracker)
43 AliMUONRawStreamTracker::AliMUONRawStreamTracker()
57 // create an object to read MUON raw digits
58 // Default ctor for monitoring purposes
60 fBusPatchManager = new AliMpBusPatch();
61 fBusPatchManager->ReadBusPatchFile();
63 fDDLTracker = new AliMUONDDLTracker();
64 fBusStruct = new AliMUONBusStruct();
65 fBlockHeader = new AliMUONBlockHeader();
66 fDspHeader = new AliMUONDspHeader();
69 //_________________________________________________________________
70 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
83 // ctor with AliRawReader as argument
84 // for reconstruction purpose
87 fRawReader = rawReader;
89 fBusPatchManager = new AliMpBusPatch();
90 fBusPatchManager->ReadBusPatchFile();
92 fDDLTracker = new AliMUONDDLTracker();
93 fBusStruct = new AliMUONBusStruct();
94 fBlockHeader = new AliMUONBlockHeader();
95 fDspHeader = new AliMUONDspHeader();
98 //_________________________________________________________________
99 AliMUONRawStreamTracker::AliMUONRawStreamTracker(const AliMUONRawStreamTracker& stream) :
105 AliFatal("copy constructor not implemented");
108 //______________________________________________________________________
109 AliMUONRawStreamTracker& AliMUONRawStreamTracker::operator = (const AliMUONRawStreamTracker&
113 // assignment operator
115 AliFatal("assignment operator not implemented");
120 //___________________________________
121 AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
126 delete fBusPatchManager;
133 //_____________________________________________________________
134 Bool_t AliMUONRawStreamTracker::Next()
137 // read the next raw digit (buspatch structure)
138 // returns kFALSE if there is no digit left
139 // (under development)
141 AliMUONDDLTracker* ddlTracker = 0x0;
142 AliMUONBlockHeader* blkHeader = 0x0;
143 AliMUONDspHeader* dspHeader = 0x0;
150 printf("iDDL %d\n", fDDL+1);
159 ddlTracker = GetDDLTracker();
161 nBlock = ddlTracker->GetBlkHeaderEntries();
162 if (fBlkId < nBlock) {
164 blkHeader = ddlTracker->GetBlkHeaderEntry(fBlkId);
165 nDsp = blkHeader->GetDspHeaderEntries();
168 dspHeader = blkHeader->GetDspHeaderEntry(fDspId);
169 nBusPatch = dspHeader->GetBusPatchEntries();
171 if (fBusPatchId < nBusPatch) {
172 fBusStructPtr = dspHeader->GetBusPatchEntry(fBusPatchId++);
202 //______________________________________________________
203 Bool_t AliMUONRawStreamTracker::NextDDL()
205 // reading tracker DDL
206 // store buspatch info into Array
207 // store only non-empty structures (buspatch info with datalength !=0)
209 fDDLTracker->GetBlkHeaderArray()->Delete();
210 // fDDLTracker->GetBlkHeaderArray()->Clear("C");
212 //Read Header Size of DDL,Block,DSP and BusPatch
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();
219 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
222 Int_t iBusPerDSP[5]; // number of bus patches per DSP
223 Int_t iDspMax; // number max of DSP per block
225 // minimum data size (only header's)
227 Int_t blankBlockSize;
234 AliDebug(3, Form("DDL Number %d\n", fDDL ));
237 fBusPatchManager->GetDspInfo(fDDL/2, iDspMax, iBusPerDSP);
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;
246 for (Int_t i = 0; i < iDspMax; i++) {
247 blankDDLSize += 2*iBusPerDSP[i]*kBusPatchHeaderSize;
248 blankBlockSize += iBusPerDSP[i]*kBusPatchHeaderSize;
251 fRawReader->Select(0X9, fDDL, fDDL); //Select the DDL file to be read
253 fRawReader->ReadHeader();
255 // 4 is multiplied to convert 2 bytes words
256 totalDDLSize = (fRawReader->GetDataSize() + sizeof(AliRawDataHeader))/4;
258 // Compare the DDL header with an empty DDL header size to read the file
259 if(totalDDLSize > blankDDLSize) {
261 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
262 UInt_t *buffer = new UInt_t[totalDataWord/4];
264 fRawReader->ReadNext((UChar_t*)buffer, totalDataWord);
271 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
273 // copy within padding words
274 memcpy(fBlockHeader->GetHeader(),&buffer[index], (kBlockHeaderSize+1)*4);
276 totalBlockSize = fBlockHeader->GetTotalLength();
278 fDDLTracker->AddBlkHeader(*fBlockHeader);
280 if (fBlockHeader->GetPadding() == 0xDEAD) // skipping padding word
283 if(totalBlockSize > blankBlockSize) { // compare block header
284 index += kBlockHeaderSize;
286 for(Int_t iDsp = 0; iDsp < iDspMax ;iDsp++){ //DSP loop
288 if (iDsp > fMaxDsp) break;
290 memcpy(fDspHeader->GetHeader(),&buffer[index], kDspHeaderSize*4);
292 totalDspSize = fDspHeader->GetTotalLength();
295 blankDspSize = kDspHeaderSize + iBusPerDSP[iDsp]*kBusPatchHeaderSize; // no data just header
297 fDDLTracker->AddDspHeader(*fDspHeader, iBlock);
299 if(totalDspSize > blankDspSize) { // Compare DSP Header
300 index += kDspHeaderSize;
302 for(Int_t iBusPatch = 0; iBusPatch < iBusPerDSP[iDsp]; iBusPatch++) {
304 if (iBusPatch > fMaxBus) break;
306 //copy buffer into header structure
307 memcpy(fBusStruct->GetBusPatchHeader(), &buffer[index], kBusPatchHeaderSize*4);
309 totalBusPatchSize = fBusStruct->GetTotalLength();
310 indexBusPatch = index;
312 //Check Buspatch header, not empty events
313 if(totalBusPatchSize > kBusPatchHeaderSize) {
315 index += kBusPatchHeaderSize;
316 dataSize = fBusStruct->GetLength();
317 Int_t bufSize = fBusStruct->GetBufSize();
319 if(dataSize > 0) { // check data present
320 if (dataSize > bufSize) fBusStruct->SetAlloc(dataSize);
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);
330 } // testing buspatch
332 index = indexBusPatch + totalBusPatchSize;
338 index = indexDsp + totalDspSize;
344 index = totalBlockSize;
349 } //loop checking the header size of DDL
356 //______________________________________________________
357 void AliMUONRawStreamTracker::ResetDDL()
359 // reseting TClonesArray
362 fDDLTracker->GetBlkHeaderArray()->Clear("C");
365 //______________________________________________________
366 void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl)
369 if (ddl > 20) ddl = 20;
373 //______________________________________________________
374 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk)
376 // set regional card number
377 if (blk > 2) blk = 2;