]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawStreamTracker.cxx
No more misaligned_geometry
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTracker.cxx
CommitLineData
c0751163 1/**************************************************************************
33434f31 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**************************************************************************/
c0751163 15
c4ee792d 16/* $Id $ */
17
c0751163 18
19///////////////////////////////////////////////////////////////////////////////
20///
c4ee792d 21/// \class AliMUONRawStreamTracker
c0751163 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)
313a427d 27/// It can loop also over DDL and store the decoded rawdata in TClonesArray
28/// in Payload class.
c0751163 29///
3c7f5307 30/// Version implement for Tracker
c0751163 31///
3c7f5307 32/// \author Christian Finck & Laurent Aphecetche
c0751163 33///////////////////////////////////////////////////////////////////////////////
34
35#include "AliMUONRawStreamTracker.h"
36
37#include "AliRawReader.h"
38#include "AliRawDataHeader.h"
9e378ff4 39#include "AliDAQ.h"
c0751163 40#include "AliLog.h"
33434f31 41#include "AliMUONPayloadTracker.h"
42#include "AliMUONBlockHeader.h"
43#include "AliMUONDspHeader.h"
44#include "AliMUONBusStruct.h"
45#include "AliMUONDDLTracker.h"
46#include "Riostream.h"
c0751163 47
00e86732 48/// \cond CLASSIMP
c0751163 49ClassImp(AliMUONRawStreamTracker)
00e86732 50/// \endcond
c0751163 51
52AliMUONRawStreamTracker::AliMUONRawStreamTracker()
33434f31 53: TObject(),
3c7f5307 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)
c0751163 68{
00e86732 69 ///
70 /// create an object to read MUON raw digits
71 /// Default ctor for monitoring purposes
72 ///
33434f31 73
74
c0751163 75}
76
77//_________________________________________________________________
78AliMUONRawStreamTracker::AliMUONRawStreamTracker(AliRawReader* rawReader)
33434f31 79: TObject(),
3c7f5307 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)
c0751163 94{
00e86732 95 ///
96 /// ctor with AliRawReader as argument
97 /// for reconstruction purpose
98 ///
33434f31 99
100
c0751163 101}
102
c0751163 103//___________________________________
104AliMUONRawStreamTracker::~AliMUONRawStreamTracker()
105{
00e86732 106 ///
107 /// clean up
108 ///
313a427d 109 delete fPayload;
c0751163 110}
111
112//_____________________________________________________________
33434f31 113Bool_t
114AliMUONRawStreamTracker::Next(Int_t& busPatchId,
115 UShort_t& manuId, UChar_t& manuChannel,
116 UShort_t& adc)
c0751163 117{
00e86732 118 ///
119 /// read the next raw digit (buspatch structure)
120 /// returns kFALSE if there is no digit left
33434f31 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;
c0751163 143}
144
145//______________________________________________________
33434f31 146Bool_t
147AliMUONRawStreamTracker::IsDone() const
c0751163 148{
33434f31 149 /// Whether the iteration is finished or not
150 return (fCurrentBusStruct==0);
151}
c0751163 152
33434f31 153//______________________________________________________
154void
155AliMUONRawStreamTracker::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}
c0751163 172
33434f31 173//______________________________________________________
174Bool_t
175AliMUONRawStreamTracker::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;
c0751163 195 return kFALSE;
196 }
33434f31 197
313a427d 198 Int_t totalDataWord = fRawReader->GetDataSize(); // in bytes
33434f31 199
200 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
201 totalDataWord));
202
313a427d 203 UInt_t *buffer = new UInt_t[totalDataWord/4];
33434f31 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
3c7f5307 214 if (fEnableErrorLogger) AddErrorMessage();
ea59383d 215
33434f31 216 delete[] buffer;
217
218 fCurrentDDL = fPayload->GetDDLTracker();
219
220 fCurrentBlockHeaderIndex = -1;
221
222 return ok;
223}
c0751163 224
33434f31 225//______________________________________________________
226Bool_t
227AliMUONRawStreamTracker::GetNextBlockHeader()
228{
229 /// Returns the next block Header present
c0751163 230
33434f31 231 fCurrentBlockHeader = 0;
c0751163 232
33434f31 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}
c0751163 260
33434f31 261//______________________________________________________
262Bool_t
263AliMUONRawStreamTracker::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}
c0751163 296
33434f31 297//______________________________________________________
298Bool_t
299AliMUONRawStreamTracker::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
c0751163 330 return kTRUE;
331}
c0751163 332
33434f31 333//______________________________________________________
334Bool_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 {
ea59383d 363 delete[] buffer;
33434f31 364 return kFALSE;
365 }
366
367 Bool_t ok = fPayload->Decode(buffer, totalDataWord/4);
ea59383d 368
3c7f5307 369 if (fEnableErrorLogger) AddErrorMessage();
ea59383d 370
33434f31 371 delete[] buffer;
372
373 fDDL++;
374
375 return ok;
376}
377
c0751163 378//______________________________________________________
379void AliMUONRawStreamTracker::SetMaxDDL(Int_t ddl)
380{
00e86732 381 /// set DDL number
c0751163 382 if (ddl > 20) ddl = 20;
383 fMaxDDL = ddl;
384}
385
386//______________________________________________________
387void AliMUONRawStreamTracker::SetMaxBlock(Int_t blk)
388{
00e86732 389 /// set regional card number
313a427d 390 fPayload->SetMaxBlock(blk);
c0751163 391}
ea59383d 392
393//______________________________________________________
394void 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}