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 //-----------------------------------------------------------------------------
20 /// \class AliMUONRawStreamTracker
21 /// This class provides access to MUON digits in raw data.
23 /// It loops over all MUON digits in the raw data given by the AliRawReader.
24 /// The Next method goes to the next digit. If there are no digits left
25 /// it returns kFALSE (under develpment)
26 /// It can loop also over DDL and store the decoded rawdata in TClonesArray
29 /// Version implement for Tracker
31 /// \author Christian Finck & Laurent Aphecetche
32 //-----------------------------------------------------------------------------
34 #include "AliMUONRawStreamTracker.h"
36 #include "AliRawReader.h"
37 #include "AliRawDataHeader.h"
40 #include "AliMUONPayloadTracker.h"
41 #include "AliMUONBlockHeader.h"
42 #include "AliMUONDspHeader.h"
43 #include "AliMUONBusStruct.h"
44 #include "AliMUONDDLTracker.h"
45 #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),
67 fEnableErrorLogger(kFALSE)
70 /// create an object to read MUON raw digits
71 /// Default ctor for monitoring purposes
77 //_________________________________________________________________
78 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
80 fRawReader(rawReader),
83 fPayload(new AliMUONPayloadTracker()),
85 fCurrentDDLIndex(fMaxDDL),
86 fCurrentBlockHeader(0),
87 fCurrentBlockHeaderIndex(0),
89 fCurrentDspHeaderIndex(0),
91 fCurrentBusStructIndex(0),
93 fEnableErrorLogger(kFALSE)
96 /// ctor with AliRawReader as argument
97 /// for reconstruction purpose
103 //___________________________________
104 AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
112 //_____________________________________________________________
114 AliMUONRawStreamTracker::Next(Int_t& busPatchId,
115 UShort_t& manuId, UChar_t& manuChannel,
119 /// read the next raw digit (buspatch structure)
120 /// returns kFALSE if there is no digit left
121 /// Should call First() before this method to start the iteration.
124 if ( IsDone() ) return kFALSE;
126 if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
128 Bool_t ok = GetNextBusStruct();
138 busPatchId = fCurrentBusStruct->GetBusPatchId();
139 manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
140 manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
141 adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
146 //______________________________________________________
148 AliMUONRawStreamTracker::IsDone() const
150 /// Whether the iteration is finished or not
151 return (fCurrentBusStruct==0);
154 //______________________________________________________
156 AliMUONRawStreamTracker::First()
158 /// Initialize the iteration process.
160 fCurrentDDLIndex = -1;
161 // fCurrentDspHeaderIndex = -1; // Not necessary since this gets reset in the GetNextXXX methods.
162 // fCurrentBusStructIndex = -1;
164 // Must reset all the pointers because if we return before calling
165 // GetNextBusStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
166 // CurrentDspHeader() or CurrentBusStruct() which should return reasonable
167 // results in that case.
169 fCurrentBlockHeader = 0;
170 fCurrentDspHeader = 0;
171 fCurrentBusStruct = 0;
173 // Find the first non-empty structure
174 if (not GetNextDDL()) return;
175 if (not GetNextBlockHeader()) return;
176 if (not GetNextDspHeader()) return;
180 //______________________________________________________
182 AliMUONRawStreamTracker::GetNextDDL()
184 /// Returns the next DDL present
186 assert( fRawReader != 0 );
188 Bool_t kFound(kFALSE);
190 while ( fCurrentDDLIndex < fMaxDDL-1 && !kFound )
194 fRawReader->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
195 if ( fRawReader->ReadHeader() )
203 // fCurrentDDLIndex is set to fMaxDDL so that we exit the above loop immediately
204 // for a subsequent call to this method, unless NextEvent is called in between.
205 fCurrentDDLIndex = fMaxDDL;
206 // We have not actually been able to complete the loading of the new DDL so
207 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
212 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
214 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
217 UInt_t *buffer = new UInt_t[totalDataWord/4];
219 if ( !fRawReader->ReadNext((UChar_t*)buffer, totalDataWord) )
221 // We have not actually been able to complete the loading of the new DDL so
222 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
227 fPayload->ResetDDL();
229 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
231 if (fEnableErrorLogger) AddErrorMessage();
235 fCurrentDDL = fPayload->GetDDLTracker();
237 fCurrentBlockHeaderIndex = -1;
242 //______________________________________________________
244 AliMUONRawStreamTracker::GetNextBlockHeader()
246 /// Returns the next block Header present
248 assert( fCurrentDDL != 0 );
250 fCurrentBlockHeader = 0;
252 Int_t i(fCurrentBlockHeaderIndex);
254 while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 )
257 fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
260 if ( !fCurrentBlockHeader )
262 Bool_t ok = GetNextDDL();
269 return GetNextBlockHeader();
273 fCurrentBlockHeaderIndex = i;
275 fCurrentDspHeaderIndex = -1;
280 //______________________________________________________
282 AliMUONRawStreamTracker::GetNextDspHeader()
284 /// Returns the next Dsp Header present
286 assert( fCurrentBlockHeader != 0 );
288 fCurrentDspHeader = 0;
290 Int_t i(fCurrentDspHeaderIndex);
292 while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
295 fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
298 if ( !fCurrentDspHeader )
300 Bool_t ok = GetNextBlockHeader();
307 return GetNextDspHeader();
311 fCurrentDspHeaderIndex = i;
313 fCurrentBusStructIndex = -1;
318 //______________________________________________________
320 AliMUONRawStreamTracker::GetNextBusStruct()
322 /// Find the next non-empty busPatch structure
324 assert( fCurrentDspHeader != 0 );
326 fCurrentBusStruct = 0;
328 Int_t i(fCurrentBusStructIndex);
330 while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 )
333 fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
336 if ( !fCurrentBusStruct )
338 Bool_t ok = GetNextDspHeader();
345 return GetNextBusStruct();
349 fCurrentBusStructIndex = i;
351 fCurrentDataIndex = -1;
356 //______________________________________________________
357 Bool_t AliMUONRawStreamTracker::NextDDL()
359 /// reading tracker DDL
361 assert( fRawReader != 0 );
363 fPayload->ResetDDL();
368 fRawReader->Select("MUONTRK", fDDL, fDDL); //Select the DDL file to be read
369 if (fRawReader->ReadHeader()) break;
370 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
380 AliDebug(3, Form("DDL Number %d\n", fDDL ));
382 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
384 UInt_t *buffer = new UInt_t[totalDataWord/4];
386 if(!fRawReader->ReadNext((UChar_t*)buffer, totalDataWord))
392 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
394 if (fEnableErrorLogger) AddErrorMessage();
403 //______________________________________________________
404 void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl)
407 if (ddl > 20) ddl = 20;
411 //______________________________________________________
412 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk)
414 /// set regional card number
415 fPayload->SetMaxBlock(blk);
418 //______________________________________________________
419 void AliMUONRawStreamTracker::AddErrorMessage()
421 /// add message into logger of AliRawReader per event
423 assert( fRawReader != 0 );
425 for (Int_t i = 0; i < fPayload->GetParityErrors(); ++i)
426 fRawReader->AddMinorErrorLog(kParityErr, Form("Parity error for buspatch %s",
427 fPayload->GetParityErrBus()[i]));
429 for (Int_t i = 0; i < fPayload->GetGlitchErrors(); ++i)
430 fRawReader->AddMajorErrorLog(kGlitchErr, "Glitch error occurs skip event");
432 for (Int_t i = 0; i < fPayload->GetPaddingErrors(); ++i)
433 fRawReader->AddMinorErrorLog(kPaddingWordErr, "Padding word error");