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 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 /// \class AliMUONRawStreamTracker
22 /// This class provides access to MUON digits in raw data.
24 /// It loops over all MUON digits in the raw data given by the AliRawReader.
25 /// The Next method goes to the next digit. If there are no digits left
26 /// it returns kFALSE (under develpment)
27 /// It can loop also over DDL and store the decoded rawdata in TClonesArray
30 /// First version implement for Tracker
32 /// \author Christian Finck
33 ///////////////////////////////////////////////////////////////////////////////
35 #include "AliMUONRawStreamTracker.h"
37 #include "AliRawReader.h"
38 #include "AliRawDataHeader.h"
41 #include "AliMUONPayloadTracker.h"
42 #include "AliMUONBlockHeader.h"
43 #include "AliMUONDspHeader.h"
44 #include "AliMUONBusStruct.h"
45 #include "AliMUONDDLTracker.h"
46 #include "Riostream.h"
49 ClassImp(AliMUONRawStreamTracker)
52 AliMUONRawStreamTracker::AliMUONRawStreamTracker()
57 fPayload(new AliMUONPayloadTracker()),
59 fCurrentDDLIndex(fMaxDDL),
60 fCurrentBlockHeader(0),
61 fCurrentBlockHeaderIndex(0),
63 fCurrentDspHeaderIndex(0),
65 fCurrentBusStructIndex(0),
69 /// create an object to read MUON raw digits
70 /// Default ctor for monitoring purposes
76 //_________________________________________________________________
77 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
79 fRawReader(rawReader),
82 fPayload(new AliMUONPayloadTracker()),
84 fCurrentDDLIndex(fMaxDDL),
85 fCurrentBlockHeader(0),
86 fCurrentBlockHeaderIndex(0),
88 fCurrentDspHeaderIndex(0),
90 fCurrentBusStructIndex(0),
94 /// ctor with AliRawReader as argument
95 /// for reconstruction purpose
101 //___________________________________
102 AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
110 //_____________________________________________________________
112 AliMUONRawStreamTracker::Next(Int_t& busPatchId,
113 UShort_t& manuId, UChar_t& manuChannel,
117 /// read the next raw digit (buspatch structure)
118 /// returns kFALSE if there is no digit left
121 if ( IsDone() ) return kFALSE;
123 if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
125 Bool_t ok = GetNextBusStruct();
135 busPatchId = fCurrentBusStruct->GetBusPatchId();
136 manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
137 manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
138 adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
143 //______________________________________________________
145 AliMUONRawStreamTracker::IsDone() const
147 /// Whether the iteration is finished or not
148 return (fCurrentBusStruct==0);
151 //______________________________________________________
153 AliMUONRawStreamTracker::First()
155 /// Initialize the iteration process
157 fCurrentDDLIndex = -1;
158 fCurrentDspHeaderIndex = -1;
159 fCurrentBusStructIndex = -1;
161 fCurrentDspHeader = 0;
162 fCurrentBusStruct = 0;
164 // Find the first non-empty structure
166 GetNextBlockHeader();
171 //______________________________________________________
173 AliMUONRawStreamTracker::GetNextDDL()
175 /// Returns the next DDL present
177 Bool_t kFound(kFALSE);
179 while ( fCurrentDDLIndex < fMaxDDL-1 && !kFound )
183 fRawReader->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
184 if ( fRawReader->ReadHeader() )
192 fCurrentDDLIndex = fMaxDDL;
196 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
198 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
201 UInt_t *buffer = new UInt_t[totalDataWord/4];
203 if ( !fRawReader->ReadNext((UChar_t*)buffer, totalDataWord) )
208 fPayload->ResetDDL();
210 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
214 fCurrentDDL = fPayload->GetDDLTracker();
216 fCurrentBlockHeaderIndex = -1;
221 //______________________________________________________
223 AliMUONRawStreamTracker::GetNextBlockHeader()
225 /// Returns the next block Header present
227 fCurrentBlockHeader = 0;
229 Int_t i(fCurrentBlockHeaderIndex);
231 while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 )
234 fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
237 if ( !fCurrentBlockHeader )
239 Bool_t ok = GetNextDDL();
246 return GetNextBlockHeader();
250 fCurrentBlockHeaderIndex = i;
252 fCurrentDspHeaderIndex = -1;
257 //______________________________________________________
259 AliMUONRawStreamTracker::GetNextDspHeader()
261 /// Returns the next Dsp Header present
263 fCurrentDspHeader = 0;
265 Int_t i(fCurrentDspHeaderIndex);
267 while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
270 fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
273 if ( !fCurrentDspHeader )
275 Bool_t ok = GetNextBlockHeader();
282 return GetNextDspHeader();
286 fCurrentDspHeaderIndex = i;
288 fCurrentBusStructIndex = -1;
293 //______________________________________________________
295 AliMUONRawStreamTracker::GetNextBusStruct()
297 /// Find the next non-empty busPatch structure
299 fCurrentBusStruct = 0;
301 Int_t i(fCurrentBusStructIndex);
303 while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 )
306 fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
309 if ( !fCurrentBusStruct )
311 Bool_t ok = GetNextDspHeader();
318 return GetNextBusStruct();
322 fCurrentBusStructIndex = i;
324 fCurrentDataIndex = -1;
329 //______________________________________________________
330 Bool_t AliMUONRawStreamTracker::NextDDL()
332 /// reading tracker DDL
334 fPayload->ResetDDL();
339 fRawReader->Select("MUONTRK", fDDL, fDDL); //Select the DDL file to be read
340 if (fRawReader->ReadHeader()) break;
341 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
351 AliDebug(3, Form("DDL Number %d\n", fDDL ));
353 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
355 UInt_t *buffer = new UInt_t[totalDataWord/4];
357 if(!fRawReader->ReadNext((UChar_t*)buffer, totalDataWord))
359 AliError("a memory leak is here");
363 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
372 //______________________________________________________
373 void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl)
376 if (ddl > 20) ddl = 20;
380 //______________________________________________________
381 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk)
383 /// set regional card number
384 fPayload->SetMaxBlock(blk);