]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawStreamTracker.cxx
Implemented a flag to enable/disable the error info logger
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTracker.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
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 **************************************************************************/
15
16 /* $Id $ */
17
18
19 ///////////////////////////////////////////////////////////////////////////////
20 ///
21 /// \class AliMUONRawStreamTracker
22 /// This class provides access to MUON digits in raw data.
23 ///
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
28 /// in Payload class.
29 /// 
30 /// Version implement for Tracker
31 ///
32 /// \author Christian Finck & Laurent Aphecetche
33 ///////////////////////////////////////////////////////////////////////////////
34
35 #include "AliMUONRawStreamTracker.h"
36
37 #include "AliRawReader.h"
38 #include "AliRawDataHeader.h"
39 #include "AliDAQ.h"
40 #include "AliLog.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"
47
48 /// \cond CLASSIMP
49 ClassImp(AliMUONRawStreamTracker)
50 /// \endcond
51
52 AliMUONRawStreamTracker::AliMUONRawStreamTracker()
53 : TObject(),
54   fRawReader(0x0),
55   fDDL(0),
56   fMaxDDL(20),
57   fPayload(new AliMUONPayloadTracker()),
58   fCurrentDDL(0),
59   fCurrentDDLIndex(fMaxDDL),
60   fCurrentBlockHeader(0),
61   fCurrentBlockHeaderIndex(0),
62   fCurrentDspHeader(0),
63   fCurrentDspHeaderIndex(0),
64   fCurrentBusStruct(0),
65   fCurrentBusStructIndex(0),
66   fCurrentDataIndex(0),
67   fEnableErrorLogger(kFALSE)
68 {
69   ///
70   /// create an object to read MUON raw digits
71   /// Default ctor for monitoring purposes
72   ///
73   
74   
75 }
76
77 //_________________________________________________________________
78 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
79 : TObject(),
80   fRawReader(rawReader),
81   fDDL(0),
82   fMaxDDL(20),
83   fPayload(new AliMUONPayloadTracker()),
84   fCurrentDDL(0L),
85   fCurrentDDLIndex(fMaxDDL),
86   fCurrentBlockHeader(0),
87   fCurrentBlockHeaderIndex(0),
88   fCurrentDspHeader(0),
89   fCurrentDspHeaderIndex(0),
90   fCurrentBusStruct(0),
91   fCurrentBusStructIndex(0),
92   fCurrentDataIndex(0),
93   fEnableErrorLogger(kFALSE)
94 {
95   ///
96   /// ctor with AliRawReader as argument
97   /// for reconstruction purpose
98   ///
99   
100   
101 }
102
103 //___________________________________
104 AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
105 {
106   ///
107   /// clean up
108   ///
109   delete fPayload;
110 }
111
112 //_____________________________________________________________
113 Bool_t 
114 AliMUONRawStreamTracker::Next(Int_t& busPatchId,
115                               UShort_t& manuId, UChar_t& manuChannel,
116                               UShort_t& adc)
117 {
118   ///
119   /// read the next raw digit (buspatch structure)
120   /// returns kFALSE if there is no digit left
121   ///
122   
123   if ( IsDone() ) return kFALSE;
124   
125   if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
126   {
127     Bool_t ok = GetNextBusStruct();
128     if (!ok)
129     {
130       // this is the end
131       return kFALSE;
132     } 
133   }
134
135   ++fCurrentDataIndex;
136
137   busPatchId = fCurrentBusStruct->GetBusPatchId();
138   manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
139   manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
140   adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
141
142   return kTRUE;
143 }
144
145 //______________________________________________________
146 Bool_t
147 AliMUONRawStreamTracker::IsDone() const
148 {
149   /// Whether the iteration is finished or not
150   return (fCurrentBusStruct==0);
151 }
152
153 //______________________________________________________
154 void
155 AliMUONRawStreamTracker::First()
156 {
157   /// Initialize the iteration process
158   
159   fCurrentDDLIndex = -1;
160   fCurrentDspHeaderIndex = -1;
161   fCurrentBusStructIndex = -1;
162
163   fCurrentDspHeader = 0;
164   fCurrentBusStruct = 0;
165   
166   // Find the first non-empty structure
167   GetNextDDL();
168   GetNextBlockHeader();
169   GetNextDspHeader();
170   GetNextBusStruct();
171 }
172
173 //______________________________________________________
174 Bool_t
175 AliMUONRawStreamTracker::GetNextDDL()
176 {
177   /// Returns the next DDL present
178   
179   Bool_t kFound(kFALSE);
180   
181   while ( fCurrentDDLIndex < fMaxDDL-1 && !kFound ) 
182   {
183     ++fCurrentDDLIndex;
184     fRawReader->Reset();
185     fRawReader->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
186     if ( fRawReader->ReadHeader() ) 
187     {
188       kFound = kTRUE;
189     }
190   }
191   
192   if ( !kFound ) 
193   {
194     fCurrentDDLIndex = fMaxDDL;
195     return kFALSE;
196   }
197   
198   Int_t totalDataWord  = fRawReader->GetDataSize(); // in bytes
199   
200   AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
201                    totalDataWord));
202   
203   UInt_t *buffer = new UInt_t[totalDataWord/4];
204   
205   if ( !fRawReader->ReadNext((UChar_t*)buffer, totalDataWord) )
206   {
207     fCurrentDDL = 0;
208     return kFALSE;
209   }
210   fPayload->ResetDDL();
211   
212   Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
213   
214   if (fEnableErrorLogger) AddErrorMessage();
215
216   delete[] buffer;
217   
218   fCurrentDDL = fPayload->GetDDLTracker();
219   
220   fCurrentBlockHeaderIndex = -1;
221   
222   return ok;
223 }
224
225 //______________________________________________________
226 Bool_t
227 AliMUONRawStreamTracker::GetNextBlockHeader()
228 {
229   /// Returns the next block Header present
230
231   fCurrentBlockHeader = 0;
232
233   Int_t i(fCurrentBlockHeaderIndex);
234   
235   while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 ) 
236   {
237     ++i;
238     fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
239   }
240   
241   if ( !fCurrentBlockHeader ) 
242   {
243     Bool_t ok = GetNextDDL();
244     if (!ok) 
245     {
246       return kFALSE;
247     }
248     else
249     {
250       return GetNextBlockHeader();
251     }
252   }
253   
254   fCurrentBlockHeaderIndex = i;
255   
256   fCurrentDspHeaderIndex = -1;
257   
258   return kTRUE;
259 }
260
261 //______________________________________________________
262 Bool_t
263 AliMUONRawStreamTracker::GetNextDspHeader()
264 {
265   /// Returns the next Dsp Header present
266
267   fCurrentDspHeader = 0;
268   
269   Int_t i(fCurrentDspHeaderIndex);
270   
271   while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
272   {
273     ++i;
274     fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
275   }
276   
277   if ( !fCurrentDspHeader ) 
278   {
279     Bool_t ok = GetNextBlockHeader();
280     if (!ok) 
281     {
282       return kFALSE;
283     }
284     else
285     {
286       return GetNextDspHeader();
287     }
288   }
289   
290   fCurrentDspHeaderIndex = i;
291   
292   fCurrentBusStructIndex = -1;
293   
294   return kTRUE;
295 }
296
297 //______________________________________________________
298 Bool_t
299 AliMUONRawStreamTracker::GetNextBusStruct()
300 {
301   /// Find the next non-empty busPatch structure
302   
303   fCurrentBusStruct = 0;
304
305   Int_t i(fCurrentBusStructIndex);
306   
307   while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 ) 
308   {
309     ++i;
310     fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
311   }
312     
313   if ( !fCurrentBusStruct ) 
314   {
315     Bool_t ok = GetNextDspHeader();
316     if (!ok)
317     {
318       return kFALSE;
319     }
320     else
321     {
322       return GetNextBusStruct();
323     }
324   }
325   
326   fCurrentBusStructIndex = i;
327   
328   fCurrentDataIndex = -1;
329   
330   return kTRUE;
331 }
332
333 //______________________________________________________
334 Bool_t AliMUONRawStreamTracker::NextDDL()
335 {
336   /// reading tracker DDL
337   
338   fPayload->ResetDDL();
339   
340   while ( fDDL < 20 ) 
341   {
342     fRawReader->Reset();
343     fRawReader->Select("MUONTRK", fDDL, fDDL);  //Select the DDL file to be read  
344     if (fRawReader->ReadHeader()) break;
345     AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
346     ++fDDL;
347   }
348   
349   if ( fDDL == 20 ) 
350   {
351     fDDL = 0;
352     return kFALSE;
353   }
354   
355   AliDebug(3, Form("DDL Number %d\n", fDDL ));
356   
357   Int_t totalDataWord  = fRawReader->GetDataSize(); // in bytes
358   
359   UInt_t *buffer = new UInt_t[totalDataWord/4];
360   
361   if(!fRawReader->ReadNext((UChar_t*)buffer, totalDataWord))
362   {
363     delete[] buffer;
364     return kFALSE;
365   }
366   
367   Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
368
369   if (fEnableErrorLogger) AddErrorMessage();
370
371   delete[] buffer;
372   
373   fDDL++;
374   
375   return ok;
376 }
377
378 //______________________________________________________
379 void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl) 
380 {
381   /// set DDL number
382   if (ddl > 20) ddl = 20;
383   fMaxDDL = ddl;
384 }
385
386 //______________________________________________________
387 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk) 
388 {
389   /// set regional card number
390   fPayload->SetMaxBlock(blk);
391 }
392
393 //______________________________________________________
394 void AliMUONRawStreamTracker::AddErrorMessage()
395 {
396 /// add message into logger of AliRawReader per event
397
398     for (Int_t i = 0; i < fPayload->GetParityErrors(); ++i)
399         fRawReader->AddMinorErrorLog(kParityErr, Form("Parity error for buspatch %s",  
400                                                       fPayload->GetParityErrBus()[i]));
401
402     for (Int_t i = 0; i < fPayload->GetGlitchErrors(); ++i)
403         fRawReader->AddMajorErrorLog(kGlitchErr, "Glitch error occurs skip event");
404
405     for (Int_t i = 0; i < fPayload->GetPaddingErrors(); ++i)
406         fRawReader->AddMinorErrorLog(kPaddingWordErr, "Padding word error");
407
408 }