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
26 /// It can loop also over DDL and store the decoded rawdata in TClonesArray
29 /// Implement for Tracker
31 /// \author Christian Finck & Laurent Aphecetche
32 //-----------------------------------------------------------------------------
34 #include "AliMUONRawStreamTracker.h"
36 #include "AliMUONLogger.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 const Int_t AliMUONRawStreamTracker::fgkMaxDDL = 20;
56 //___________________________________________
57 AliMUONRawStreamTracker::AliMUONRawStreamTracker()
58 : AliMUONVRawStreamTracker(),
59 fPayload(new AliMUONPayloadTracker()),
61 fCurrentDDLIndex(fgkMaxDDL),
62 fCurrentBlockHeader(0),
63 fCurrentBlockHeaderIndex(0),
65 fCurrentDspHeaderIndex(0),
67 fCurrentBusStructIndex(0),
72 /// create an object to read MUON raw digits
73 /// Default ctor for monitoring purposes
79 //_________________________________________________________________
80 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
81 : AliMUONVRawStreamTracker(rawReader),
82 fPayload(new AliMUONPayloadTracker()),
84 fCurrentDDLIndex(fgkMaxDDL),
85 fCurrentBlockHeader(0),
86 fCurrentBlockHeaderIndex(0),
88 fCurrentDspHeaderIndex(0),
90 fCurrentBusStructIndex(0),
95 /// ctor with AliRawReader as argument
96 /// for reconstruction purpose
102 //___________________________________
103 AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
111 //_____________________________________________________________
113 AliMUONRawStreamTracker::Next(Int_t& busPatchId,
114 UShort_t& manuId, UChar_t& manuChannel,
118 /// read the next raw digit (buspatch structure)
119 /// returns kFALSE if there is no digit left
120 /// Should call First() before this method to start the iteration.
123 if ( IsDone() ) return kFALSE;
125 if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
127 Bool_t ok = GetNextBusStruct();
137 busPatchId = fCurrentBusStruct->GetBusPatchId();
138 manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
139 manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
140 adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
145 //______________________________________________________
147 AliMUONRawStreamTracker::IsDone() const
149 /// Whether the iteration is finished or not
150 return (fCurrentBusStruct==0);
153 //______________________________________________________
155 AliMUONRawStreamTracker::First()
157 /// Initialize the iteration process.
159 fCurrentDDLIndex = -1;
160 // fCurrentDspHeaderIndex = -1; // Not necessary since this gets reset in the GetNextXXX methods.
161 // fCurrentBusStructIndex = -1;
163 // Must reset all the pointers because if we return before calling
164 // GetNextBusStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
165 // CurrentDspHeader() or CurrentBusStruct() which should return reasonable
166 // results in that case.
168 fCurrentBlockHeader = 0;
169 fCurrentDspHeader = 0;
170 fCurrentBusStruct = 0;
172 // Find the first non-empty structure
173 if (not GetNextDDL()) return;
174 if (not GetNextBlockHeader()) return;
175 if (not GetNextDspHeader()) return;
179 //______________________________________________________
181 AliMUONRawStreamTracker::GetNextDDL()
183 /// Returns the next DDL present
185 assert( GetReader() != 0 );
187 Bool_t kFound(kFALSE);
189 while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound )
192 GetReader()->Reset();
193 GetReader()->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
194 if ( GetReader()->ReadHeader() )
202 // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
203 // for a subsequent call to this method, unless NextEvent is called in between.
204 fCurrentDDLIndex = fgkMaxDDL;
205 // We have not actually been able to complete the loading of the new DDL so
206 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
208 if (IsErrorLogger()) AddErrorMessage();
212 Int_t totalDataWord = GetReader()->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 ( !GetReader()->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();
230 swap(buffer, totalDataWord); // swap needed for mac power pc
233 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
237 fCurrentDDL = fPayload->GetDDLTracker();
239 fCurrentBlockHeaderIndex = -1;
244 //______________________________________________________
246 AliMUONRawStreamTracker::GetNextBlockHeader()
248 /// Returns the next block Header present
250 assert( fCurrentDDL != 0 );
252 fCurrentBlockHeader = 0;
254 Int_t i(fCurrentBlockHeaderIndex);
256 while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 )
259 fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
262 if ( !fCurrentBlockHeader )
264 Bool_t ok = GetNextDDL();
271 return GetNextBlockHeader();
275 fCurrentBlockHeaderIndex = i;
277 fCurrentDspHeaderIndex = -1;
282 //______________________________________________________
284 AliMUONRawStreamTracker::GetNextDspHeader()
286 /// Returns the next Dsp Header present
288 assert( fCurrentBlockHeader != 0 );
290 fCurrentDspHeader = 0;
292 Int_t i(fCurrentDspHeaderIndex);
294 while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
297 fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
300 if ( !fCurrentDspHeader )
302 Bool_t ok = GetNextBlockHeader();
309 return GetNextDspHeader();
313 fCurrentDspHeaderIndex = i;
315 fCurrentBusStructIndex = -1;
320 //______________________________________________________
322 AliMUONRawStreamTracker::GetNextBusStruct()
324 /// Find the next non-empty busPatch structure
326 assert( fCurrentDspHeader != 0 );
328 fCurrentBusStruct = 0;
330 Int_t i(fCurrentBusStructIndex);
332 while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 )
335 fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
338 if ( !fCurrentBusStruct )
340 Bool_t ok = GetNextDspHeader();
347 return GetNextBusStruct();
351 fCurrentBusStructIndex = i;
353 fCurrentDataIndex = -1;
358 //______________________________________________________
359 Bool_t AliMUONRawStreamTracker::NextDDL()
361 /// reading tracker DDL
363 assert( GetReader() != 0 );
365 fPayload->ResetDDL();
367 while ( fDDL < fgkMaxDDL )
369 GetReader()->Reset();
370 GetReader()->Select("MUONTRK", fDDL, fDDL); //Select the DDL file to be read
371 if (GetReader()->ReadHeader()) break;
372 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
376 if ( fDDL == fgkMaxDDL )
379 if ( IsErrorLogger()) AddErrorMessage();
383 AliDebug(3, Form("DDL Number %d\n", fDDL ));
385 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
387 UInt_t *buffer = new UInt_t[totalDataWord/4];
389 if(!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord))
396 swap(buffer, totalDataWord); // swap needed for mac power pc
399 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
408 //______________________________________________________
409 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk)
411 /// set regional card number
412 fPayload->SetMaxBlock(blk);
415 //______________________________________________________
416 void AliMUONRawStreamTracker::AddErrorMessage()
418 /// add message into logger of AliRawReader per event
420 assert( GetReader() != 0 );
423 AliMUONLogger* log = fPayload->GetErrorLogger();
426 while(log->Next(msg, occurance))
428 if (msg.Contains("Parity"))
429 GetReader()->AddMinorErrorLog(kParityErr, msg.Data());
431 if (msg.Contains("Glitch"))
432 GetReader()->AddMajorErrorLog(kGlitchErr, msg.Data());
434 if (msg.Contains("Padding"))
435 GetReader()->AddMinorErrorLog(kPaddingWordErr, msg.Data());
438 log->Clear(); // clear logger after each event
441 //______________________________________________________
442 Bool_t AliMUONRawStreamTracker::IsErrorMessage() const
444 /// true if there is any error/warning
445 if (GetPayLoad()->GetParityErrors() ||
446 GetPayLoad()->GetGlitchErrors() ||
447 GetPayLoad()->GetPaddingErrors())