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