]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawStreamTracker.cxx
Changes to speed up creating of status and status map (Laurent)
[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 /// \class AliMUONRawStreamTracker
21 /// This class provides access to MUON digits in raw data.
22 ///
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
27 /// in Payload class.
28 /// 
29 /// Version implement for Tracker
30 ///
31 /// \author Christian Finck & Laurent Aphecetche
32 //-----------------------------------------------------------------------------
33
34 #include "AliMUONRawStreamTracker.h"
35
36 #include "AliRawReader.h"
37 #include "AliRawDataHeader.h"
38 #include "AliDAQ.h"
39 #include "AliLog.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"
46 #include <cassert>
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   /// Should call First() before this method to start the iteration.
122   ///
123   
124   if ( IsDone() ) return kFALSE;
125   
126   if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
127   {
128     Bool_t ok = GetNextBusStruct();
129     if (!ok)
130     {
131       // this is the end
132       return kFALSE;
133     } 
134   }
135
136   ++fCurrentDataIndex;
137
138   busPatchId = fCurrentBusStruct->GetBusPatchId();
139   manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
140   manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
141   adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
142
143   return kTRUE;
144 }
145
146 //______________________________________________________
147 Bool_t
148 AliMUONRawStreamTracker::IsDone() const
149 {
150   /// Whether the iteration is finished or not
151   return (fCurrentBusStruct==0);
152 }
153
154 //______________________________________________________
155 void
156 AliMUONRawStreamTracker::First()
157 {
158   /// Initialize the iteration process.
159   
160   fCurrentDDLIndex = -1;
161 //  fCurrentDspHeaderIndex = -1; // Not necessary since this gets reset in the GetNextXXX methods.
162 //  fCurrentBusStructIndex = -1;
163
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.
168   fCurrentDDL = 0;
169   fCurrentBlockHeader = 0;
170   fCurrentDspHeader = 0;
171   fCurrentBusStruct = 0;
172   
173   // Find the first non-empty structure
174   if (not GetNextDDL()) return;
175   if (not GetNextBlockHeader()) return;
176   if (not GetNextDspHeader()) return;
177   GetNextBusStruct();
178 }
179
180 //______________________________________________________
181 Bool_t
182 AliMUONRawStreamTracker::GetNextDDL()
183 {
184   /// Returns the next DDL present
185   
186   assert( fRawReader != 0 );
187   
188   Bool_t kFound(kFALSE);
189   
190   while ( fCurrentDDLIndex < fMaxDDL-1 && !kFound ) 
191   {
192     ++fCurrentDDLIndex;
193     fRawReader->Reset();
194     fRawReader->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
195     if ( fRawReader->ReadHeader() ) 
196     {
197       kFound = kTRUE;
198     }
199   }
200   
201   if ( !kFound ) 
202   {
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.
208     //fCurrentDDL = 0;
209     return kFALSE;
210   }
211   
212   Int_t totalDataWord  = fRawReader->GetDataSize(); // in bytes
213   
214   AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
215                    totalDataWord));
216   
217   UInt_t *buffer = new UInt_t[totalDataWord/4];
218   
219   if ( !fRawReader->ReadNext((UChar_t*)buffer, totalDataWord) )
220   {
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.
223     //fCurrentDDL = 0;
224     delete [] buffer;
225     return kFALSE;
226   }
227   fPayload->ResetDDL();
228   
229   Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
230   
231   if (fEnableErrorLogger) AddErrorMessage();
232
233   delete[] buffer;
234   
235   fCurrentDDL = fPayload->GetDDLTracker();
236   
237   fCurrentBlockHeaderIndex = -1;
238   
239   return ok;
240 }
241
242 //______________________________________________________
243 Bool_t
244 AliMUONRawStreamTracker::GetNextBlockHeader()
245 {
246   /// Returns the next block Header present
247   
248   assert( fCurrentDDL != 0 );
249
250   fCurrentBlockHeader = 0;
251
252   Int_t i(fCurrentBlockHeaderIndex);
253   
254   while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 ) 
255   {
256     ++i;
257     fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
258   }
259   
260   if ( !fCurrentBlockHeader ) 
261   {
262     Bool_t ok = GetNextDDL();
263     if (!ok) 
264     {
265       return kFALSE;
266     }
267     else
268     {
269       return GetNextBlockHeader();
270     }
271   }
272   
273   fCurrentBlockHeaderIndex = i;
274   
275   fCurrentDspHeaderIndex = -1;
276   
277   return kTRUE;
278 }
279
280 //______________________________________________________
281 Bool_t
282 AliMUONRawStreamTracker::GetNextDspHeader()
283 {
284   /// Returns the next Dsp Header present
285
286   assert( fCurrentBlockHeader != 0 );
287   
288   fCurrentDspHeader = 0;
289   
290   Int_t i(fCurrentDspHeaderIndex);
291   
292   while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
293   {
294     ++i;
295     fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
296   }
297   
298   if ( !fCurrentDspHeader ) 
299   {
300     Bool_t ok = GetNextBlockHeader();
301     if (!ok) 
302     {
303       return kFALSE;
304     }
305     else
306     {
307       return GetNextDspHeader();
308     }
309   }
310   
311   fCurrentDspHeaderIndex = i;
312   
313   fCurrentBusStructIndex = -1;
314   
315   return kTRUE;
316 }
317
318 //______________________________________________________
319 Bool_t
320 AliMUONRawStreamTracker::GetNextBusStruct()
321 {
322   /// Find the next non-empty busPatch structure
323   
324   assert( fCurrentDspHeader != 0 );
325   
326   fCurrentBusStruct = 0;
327
328   Int_t i(fCurrentBusStructIndex);
329   
330   while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 ) 
331   {
332     ++i;
333     fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
334   }
335     
336   if ( !fCurrentBusStruct ) 
337   {
338     Bool_t ok = GetNextDspHeader();
339     if (!ok)
340     {
341       return kFALSE;
342     }
343     else
344     {
345       return GetNextBusStruct();
346     }
347   }
348   
349   fCurrentBusStructIndex = i;
350   
351   fCurrentDataIndex = -1;
352   
353   return kTRUE;
354 }
355
356 //______________________________________________________
357 Bool_t AliMUONRawStreamTracker::NextDDL()
358 {
359   /// reading tracker DDL
360   
361   assert( fRawReader != 0 );
362   
363   fPayload->ResetDDL();
364   
365   while ( fDDL < 20 ) 
366   {
367     fRawReader->Reset();
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));
371     ++fDDL;
372   }
373   
374   if ( fDDL == 20 ) 
375   {
376     fDDL = 0;
377     return kFALSE;
378   }
379   
380   AliDebug(3, Form("DDL Number %d\n", fDDL ));
381   
382   Int_t totalDataWord  = fRawReader->GetDataSize(); // in bytes
383   
384   UInt_t *buffer = new UInt_t[totalDataWord/4];
385   
386   if(!fRawReader->ReadNext((UChar_t*)buffer, totalDataWord))
387   {
388     delete[] buffer;
389     return kFALSE;
390   }
391   
392   Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
393
394   if (fEnableErrorLogger) AddErrorMessage();
395
396   delete[] buffer;
397   
398   fDDL++;
399   
400   return ok;
401 }
402
403 //______________________________________________________
404 void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl) 
405 {
406   /// set DDL number
407   if (ddl > 20) ddl = 20;
408   fMaxDDL = ddl;
409 }
410
411 //______________________________________________________
412 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk) 
413 {
414   /// set regional card number
415   fPayload->SetMaxBlock(blk);
416 }
417
418 //______________________________________________________
419 void AliMUONRawStreamTracker::AddErrorMessage()
420 {
421 /// add message into logger of AliRawReader per event
422
423     assert( fRawReader != 0 );
424
425     for (Int_t i = 0; i < fPayload->GetParityErrors(); ++i)
426         fRawReader->AddMinorErrorLog(kParityErr, Form("Parity error for buspatch %s",  
427                                                       fPayload->GetParityErrBus()[i]));
428
429     for (Int_t i = 0; i < fPayload->GetGlitchErrors(); ++i)
430         fRawReader->AddMajorErrorLog(kGlitchErr, "Glitch error occurs skip event");
431
432     for (Int_t i = 0; i < fPayload->GetPaddingErrors(); ++i)
433         fRawReader->AddMinorErrorLog(kPaddingWordErr, "Padding word error");
434
435 }