]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawStreamTracker.cxx
8904bbb6d6840123c8f380dca665ddbcdc862ddb
[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 #include <cassert>
48
49 /// \cond CLASSIMP
50 ClassImp(AliMUONRawStreamTracker)
51 /// \endcond
52
53 AliMUONRawStreamTracker::AliMUONRawStreamTracker()
54 : TObject(),
55   fRawReader(0x0),
56   fDDL(0),
57   fMaxDDL(20),
58   fPayload(new AliMUONPayloadTracker()),
59   fCurrentDDL(0),
60   fCurrentDDLIndex(fMaxDDL),
61   fCurrentBlockHeader(0),
62   fCurrentBlockHeaderIndex(0),
63   fCurrentDspHeader(0),
64   fCurrentDspHeaderIndex(0),
65   fCurrentBusStruct(0),
66   fCurrentBusStructIndex(0),
67   fCurrentDataIndex(0),
68   fEnableErrorLogger(kFALSE)
69 {
70   ///
71   /// create an object to read MUON raw digits
72   /// Default ctor for monitoring purposes
73   ///
74   
75   
76 }
77
78 //_________________________________________________________________
79 AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
80 : TObject(),
81   fRawReader(rawReader),
82   fDDL(0),
83   fMaxDDL(20),
84   fPayload(new AliMUONPayloadTracker()),
85   fCurrentDDL(0L),
86   fCurrentDDLIndex(fMaxDDL),
87   fCurrentBlockHeader(0),
88   fCurrentBlockHeaderIndex(0),
89   fCurrentDspHeader(0),
90   fCurrentDspHeaderIndex(0),
91   fCurrentBusStruct(0),
92   fCurrentBusStructIndex(0),
93   fCurrentDataIndex(0),
94   fEnableErrorLogger(kFALSE)
95 {
96   ///
97   /// ctor with AliRawReader as argument
98   /// for reconstruction purpose
99   ///
100   
101   
102 }
103
104 //___________________________________
105 AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
106 {
107   ///
108   /// clean up
109   ///
110   delete fPayload;
111 }
112
113 //_____________________________________________________________
114 Bool_t 
115 AliMUONRawStreamTracker::Next(Int_t& busPatchId,
116                               UShort_t& manuId, UChar_t& manuChannel,
117                               UShort_t& adc)
118 {
119   ///
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.
123   ///
124   
125   if ( IsDone() ) return kFALSE;
126   
127   if ( fCurrentDataIndex >= fCurrentBusStruct->GetLength()-1 )
128   {
129     Bool_t ok = GetNextBusStruct();
130     if (!ok)
131     {
132       // this is the end
133       return kFALSE;
134     } 
135   }
136
137   ++fCurrentDataIndex;
138
139   busPatchId = fCurrentBusStruct->GetBusPatchId();
140   manuId = fCurrentBusStruct->GetManuId(fCurrentDataIndex);
141   manuChannel = fCurrentBusStruct->GetChannelId(fCurrentDataIndex);
142   adc = fCurrentBusStruct->GetCharge(fCurrentDataIndex);
143
144   return kTRUE;
145 }
146
147 //______________________________________________________
148 Bool_t
149 AliMUONRawStreamTracker::IsDone() const
150 {
151   /// Whether the iteration is finished or not
152   return (fCurrentBusStruct==0);
153 }
154
155 //______________________________________________________
156 void
157 AliMUONRawStreamTracker::First()
158 {
159   /// Initialize the iteration process.
160   
161   fCurrentDDLIndex = -1;
162 //  fCurrentDspHeaderIndex = -1; // Not necessary since this gets reset in the GetNextXXX methods.
163 //  fCurrentBusStructIndex = -1;
164
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.
169   fCurrentDDL = 0;
170   fCurrentBlockHeader = 0;
171   fCurrentDspHeader = 0;
172   fCurrentBusStruct = 0;
173   
174   // Find the first non-empty structure
175   if (not GetNextDDL()) return;
176   if (not GetNextBlockHeader()) return;
177   if (not GetNextDspHeader()) return;
178   GetNextBusStruct();
179 }
180
181 //______________________________________________________
182 Bool_t
183 AliMUONRawStreamTracker::GetNextDDL()
184 {
185   /// Returns the next DDL present
186   
187   assert( fRawReader != 0 );
188   
189   Bool_t kFound(kFALSE);
190   
191   while ( fCurrentDDLIndex < fMaxDDL-1 && !kFound ) 
192   {
193     ++fCurrentDDLIndex;
194     fRawReader->Reset();
195     fRawReader->Select("MUONTRK",fCurrentDDLIndex,fCurrentDDLIndex);
196     if ( fRawReader->ReadHeader() ) 
197     {
198       kFound = kTRUE;
199     }
200   }
201   
202   if ( !kFound ) 
203   {
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.
209     //fCurrentDDL = 0;
210     return kFALSE;
211   }
212   
213   Int_t totalDataWord  = fRawReader->GetDataSize(); // in bytes
214   
215   AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
216                    totalDataWord));
217   
218   UInt_t *buffer = new UInt_t[totalDataWord/4];
219   
220   if ( !fRawReader->ReadNext((UChar_t*)buffer, totalDataWord) )
221   {
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.
224     //fCurrentDDL = 0;
225     delete [] buffer;
226     return kFALSE;
227   }
228   fPayload->ResetDDL();
229   
230   Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
231   
232   if (fEnableErrorLogger) AddErrorMessage();
233
234   delete[] buffer;
235   
236   fCurrentDDL = fPayload->GetDDLTracker();
237   
238   fCurrentBlockHeaderIndex = -1;
239   
240   return ok;
241 }
242
243 //______________________________________________________
244 Bool_t
245 AliMUONRawStreamTracker::GetNextBlockHeader()
246 {
247   /// Returns the next block Header present
248   
249   assert( fCurrentDDL != 0 );
250
251   fCurrentBlockHeader = 0;
252
253   Int_t i(fCurrentBlockHeaderIndex);
254   
255   while ( fCurrentBlockHeader == 0 && i < fCurrentDDL->GetBlkHeaderEntries()-1 ) 
256   {
257     ++i;
258     fCurrentBlockHeader = fCurrentDDL->GetBlkHeaderEntry(i);
259   }
260   
261   if ( !fCurrentBlockHeader ) 
262   {
263     Bool_t ok = GetNextDDL();
264     if (!ok) 
265     {
266       return kFALSE;
267     }
268     else
269     {
270       return GetNextBlockHeader();
271     }
272   }
273   
274   fCurrentBlockHeaderIndex = i;
275   
276   fCurrentDspHeaderIndex = -1;
277   
278   return kTRUE;
279 }
280
281 //______________________________________________________
282 Bool_t
283 AliMUONRawStreamTracker::GetNextDspHeader()
284 {
285   /// Returns the next Dsp Header present
286
287   assert( fCurrentBlockHeader != 0 );
288   
289   fCurrentDspHeader = 0;
290   
291   Int_t i(fCurrentDspHeaderIndex);
292   
293   while ( fCurrentDspHeader == 0 && i < fCurrentBlockHeader->GetDspHeaderEntries()-1 )
294   {
295     ++i;
296     fCurrentDspHeader = fCurrentBlockHeader->GetDspHeaderEntry(i);
297   }
298   
299   if ( !fCurrentDspHeader ) 
300   {
301     Bool_t ok = GetNextBlockHeader();
302     if (!ok) 
303     {
304       return kFALSE;
305     }
306     else
307     {
308       return GetNextDspHeader();
309     }
310   }
311   
312   fCurrentDspHeaderIndex = i;
313   
314   fCurrentBusStructIndex = -1;
315   
316   return kTRUE;
317 }
318
319 //______________________________________________________
320 Bool_t
321 AliMUONRawStreamTracker::GetNextBusStruct()
322 {
323   /// Find the next non-empty busPatch structure
324   
325   assert( fCurrentDspHeader != 0 );
326   
327   fCurrentBusStruct = 0;
328
329   Int_t i(fCurrentBusStructIndex);
330   
331   while ( fCurrentBusStruct == 0 && i < fCurrentDspHeader->GetBusPatchEntries()-1 ) 
332   {
333     ++i;
334     fCurrentBusStruct = fCurrentDspHeader->GetBusPatchEntry(i);
335   }
336     
337   if ( !fCurrentBusStruct ) 
338   {
339     Bool_t ok = GetNextDspHeader();
340     if (!ok)
341     {
342       return kFALSE;
343     }
344     else
345     {
346       return GetNextBusStruct();
347     }
348   }
349   
350   fCurrentBusStructIndex = i;
351   
352   fCurrentDataIndex = -1;
353   
354   return kTRUE;
355 }
356
357 //______________________________________________________
358 Bool_t AliMUONRawStreamTracker::NextDDL()
359 {
360   /// reading tracker DDL
361   
362   assert( fRawReader != 0 );
363   
364   fPayload->ResetDDL();
365   
366   while ( fDDL < 20 ) 
367   {
368     fRawReader->Reset();
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));
372     ++fDDL;
373   }
374   
375   if ( fDDL == 20 ) 
376   {
377     fDDL = 0;
378     return kFALSE;
379   }
380   
381   AliDebug(3, Form("DDL Number %d\n", fDDL ));
382   
383   Int_t totalDataWord  = fRawReader->GetDataSize(); // in bytes
384   
385   UInt_t *buffer = new UInt_t[totalDataWord/4];
386   
387   if(!fRawReader->ReadNext((UChar_t*)buffer, totalDataWord))
388   {
389     delete[] buffer;
390     return kFALSE;
391   }
392   
393   Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
394
395   if (fEnableErrorLogger) AddErrorMessage();
396
397   delete[] buffer;
398   
399   fDDL++;
400   
401   return ok;
402 }
403
404 //______________________________________________________
405 void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl) 
406 {
407   /// set DDL number
408   if (ddl > 20) ddl = 20;
409   fMaxDDL = ddl;
410 }
411
412 //______________________________________________________
413 void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk) 
414 {
415   /// set regional card number
416   fPayload->SetMaxBlock(blk);
417 }
418
419 //______________________________________________________
420 void AliMUONRawStreamTracker::AddErrorMessage()
421 {
422 /// add message into logger of AliRawReader per event
423
424     assert( fRawReader != 0 );
425
426     for (Int_t i = 0; i < fPayload->GetParityErrors(); ++i)
427         fRawReader->AddMinorErrorLog(kParityErr, Form("Parity error for buspatch %s",  
428                                                       fPayload->GetParityErrBus()[i]));
429
430     for (Int_t i = 0; i < fPayload->GetGlitchErrors(); ++i)
431         fRawReader->AddMajorErrorLog(kGlitchErr, "Glitch error occurs skip event");
432
433     for (Int_t i = 0; i < fPayload->GetPaddingErrors(); ++i)
434         fRawReader->AddMinorErrorLog(kPaddingWordErr, "Padding word error");
435
436 }