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 /// Version implement for Tracker
32 /// \author Christian Finck & Laurent Aphecetche
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"
50 ClassImp(AliMUONRawStreamTracker)
53 AliMUONRawStreamTracker::AliMUONRawStreamTracker()
58 fPayload(new AliMUONPayloadTracker()),
60 fCurrentDDLIndex(fMaxDDL),
61 fCurrentBlockHeader(0),
62 fCurrentBlockHeaderIndex(0),
64 fCurrentDspHeaderIndex(0),
66 fCurrentBusStructIndex(0),
68 fEnableErrorLogger(kFALSE)
71 /// create an object to read MUON raw digits
72 /// Default ctor for monitoring purposes
78 //_________________________________________________________________
79 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
81 fRawReader(rawReader),
84 fPayload(new AliMUONPayloadTracker()),
86 fCurrentDDLIndex(fMaxDDL),
87 fCurrentBlockHeader(0),
88 fCurrentBlockHeaderIndex(0),
90 fCurrentDspHeaderIndex(0),
92 fCurrentBusStructIndex(0),
94 fEnableErrorLogger(kFALSE)
97 /// ctor with AliRawReader as argument
98 /// for reconstruction purpose
104 //___________________________________
105 AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
113 //_____________________________________________________________
115 AliMUONRawStreamTracker::Next(Int_t& busPatchId,
116 UShort_t& manuId, UChar_t& manuChannel,
120 /// read the next raw digit (buspatch structure)
121 /// returns kFALSE if there is no digit left
122 /// Should call First() before this method to start the iteration.
125 if ( IsDone() ) return kFALSE;
127 if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
129 Bool_t ok = GetNextBusStruct();
139 busPatchId = fCurrentBusStruct->GetBusPatchId();
140 manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
141 manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
142 adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
147 //______________________________________________________
149 AliMUONRawStreamTracker::IsDone() const
151 /// Whether the iteration is finished or not
152 return (fCurrentBusStruct==0);
155 //______________________________________________________
157 AliMUONRawStreamTracker::First()
159 /// Initialize the iteration process.
161 fCurrentDDLIndex = -1;
162 // fCurrentDspHeaderIndex = -1; // Not necessary since this gets reset in the GetNextXXX methods.
163 // fCurrentBusStructIndex = -1;
165 // Must reset all the pointers because if we return before calling
166 // GetNextBusStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
167 // CurrentDspHeader() or CurrentBusStruct() which should return reasonable
168 // results in that case.
170 fCurrentBlockHeader = 0;
171 fCurrentDspHeader = 0;
172 fCurrentBusStruct = 0;
174 // Find the first non-empty structure
175 if (not GetNextDDL()) return;
176 if (not GetNextBlockHeader()) return;
177 if (not GetNextDspHeader()) return;
181 //______________________________________________________
183 AliMUONRawStreamTracker::GetNextDDL()
185 /// Returns the next DDL present
187 assert( fRawReader != 0 );
189 Bool_t kFound(kFALSE);
191 while ( fCurrentDDLIndex < fMaxDDL-1 && !kFound )
195 fRawReader->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
196 if ( fRawReader->ReadHeader() )
204 // fCurrentDDLIndex is set to fMaxDDL so that we exit the above loop immediately
205 // for a subsequent call to this method, unless NextEvent is called in between.
206 fCurrentDDLIndex = fMaxDDL;
207 // We have not actually been able to complete the loading of the new DDL so
208 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
213 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
215 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
218 UInt_t *buffer = new UInt_t[totalDataWord/4];
220 if ( !fRawReader->ReadNext((UChar_t*)buffer, totalDataWord) )
222 // We have not actually been able to complete the loading of the new DDL so
223 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
228 fPayload->ResetDDL();
230 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
232 if (fEnableErrorLogger) AddErrorMessage();
236 fCurrentDDL = fPayload->GetDDLTracker();
238 fCurrentBlockHeaderIndex = -1;
243 //______________________________________________________
245 AliMUONRawStreamTracker::GetNextBlockHeader()
247 /// Returns the next block Header present
249 assert( fCurrentDDL != 0 );
251 fCurrentBlockHeader = 0;
253 Int_t i(fCurrentBlockHeaderIndex);
255 while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 )
258 fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
261 if ( !fCurrentBlockHeader )
263 Bool_t ok = GetNextDDL();
270 return GetNextBlockHeader();
274 fCurrentBlockHeaderIndex = i;
276 fCurrentDspHeaderIndex = -1;
281 //______________________________________________________
283 AliMUONRawStreamTracker::GetNextDspHeader()
285 /// Returns the next Dsp Header present
287 assert( fCurrentBlockHeader != 0 );
289 fCurrentDspHeader = 0;
291 Int_t i(fCurrentDspHeaderIndex);
293 while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
296 fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
299 if ( !fCurrentDspHeader )
301 Bool_t ok = GetNextBlockHeader();
308 return GetNextDspHeader();
312 fCurrentDspHeaderIndex = i;
314 fCurrentBusStructIndex = -1;
319 //______________________________________________________
321 AliMUONRawStreamTracker::GetNextBusStruct()
323 /// Find the next non-empty busPatch structure
325 assert( fCurrentDspHeader != 0 );
327 fCurrentBusStruct = 0;
329 Int_t i(fCurrentBusStructIndex);
331 while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 )
334 fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
337 if ( !fCurrentBusStruct )
339 Bool_t ok = GetNextDspHeader();
346 return GetNextBusStruct();
350 fCurrentBusStructIndex = i;
352 fCurrentDataIndex = -1;
357 //______________________________________________________
358 Bool_t AliMUONRawStreamTracker::NextDDL()
360 /// reading tracker DDL
362 assert( fRawReader != 0 );
364 fPayload->ResetDDL();
369 fRawReader->Select("MUONTRK", fDDL, fDDL); //Select the DDL file to be read
370 if (fRawReader->ReadHeader()) break;
371 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
381 AliDebug(3, Form("DDL Number %d\n", fDDL ));
383 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
385 UInt_t *buffer = new UInt_t[totalDataWord/4];
387 if(!fRawReader->ReadNext((UChar_t*)buffer, totalDataWord))
393 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
395 if (fEnableErrorLogger) AddErrorMessage();
404 //______________________________________________________
405 void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl)
408 if (ddl > 20) ddl = 20;
412 //______________________________________________________
413 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk)
415 /// set regional card number
416 fPayload->SetMaxBlock(blk);
419 //______________________________________________________
420 void AliMUONRawStreamTracker::AddErrorMessage()
422 /// add message into logger of AliRawReader per event
424 assert( fRawReader != 0 );
426 for (Int_t i = 0; i < fPayload->GetParityErrors(); ++i)
427 fRawReader->AddMinorErrorLog(kParityErr, Form("Parity error for buspatch %s",
428 fPayload->GetParityErrBus()[i]));
430 for (Int_t i = 0; i < fPayload->GetGlitchErrors(); ++i)
431 fRawReader->AddMajorErrorLog(kGlitchErr, "Glitch error occurs skip event");
433 for (Int_t i = 0; i < fPayload->GetPaddingErrors(); ++i)
434 fRawReader->AddMinorErrorLog(kPaddingWordErr, "Padding word error");