AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONRawStreamTrigger.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
31 
32 #include <TArrayS.h>
33 
35 #include "AliMUONDarcHeader.h"
36 #include "AliMUONRegHeader.h"
37 #include "AliMUONLocalStruct.h"
38 #include "AliMUONDDLTrigger.h"
39 #include "AliMUONLogger.h"
40 
41 #include "AliRawReader.h"
42 #include "AliRawDataHeader.h"
43 #include "AliRawDataHeaderV3.h"
44 #include "AliDAQ.h"
45 #include "AliLog.h"
46 
47 #include <cassert>
48 
52 
53 const Int_t AliMUONRawStreamTrigger::fgkMaxDDL = 2;
54 
55 //___________________________________________
58 fPayload(0x0),
59 fCurrentDDL(0x0),
60 fCurrentDDLIndex(fgkMaxDDL),
61 fCurrentDarcHeader(0x0),
62 fCurrentRegHeader(0x0),
63 fCurrentRegHeaderIndex(0),
64 fCurrentLocalStruct(0x0),
65 fCurrentLocalStructIndex(0),
66 fLocalStructRead(kFALSE),
67 fDDL(0),
68 fNextDDL(kFALSE)
69 {
74 }
75 
76 //___________________________________________
79  fPayload(new AliMUONPayloadTrigger()),
80  fCurrentDDL(0x0),
81  fCurrentDDLIndex(fgkMaxDDL),
82  fCurrentDarcHeader(0x0),
83  fCurrentRegHeader(0x0),
84  fCurrentRegHeaderIndex(0),
85  fCurrentLocalStruct(0x0),
86  fCurrentLocalStructIndex(0),
87  fLocalStructRead(kFALSE),
88  fDDL(0),
89  fNextDDL(kFALSE)
90 {
95 
96 
97 }
98 
99 //_________________________________________________________________
101  : AliMUONVRawStreamTrigger(rawReader),
102  fPayload(new AliMUONPayloadTrigger()),
103  fCurrentDDL(0x0),
104  fCurrentDDLIndex(fgkMaxDDL),
105  fCurrentDarcHeader(0x0),
106  fCurrentRegHeader(0x0),
107  fCurrentRegHeaderIndex(0),
108  fCurrentLocalStruct(0x0),
109  fCurrentLocalStructIndex(0),
110  fLocalStructRead(kFALSE),
111  fDDL(0),
112  fNextDDL(kFALSE)
113 {
118 
119 }
120 
121 //___________________________________
123 {
127  delete fPayload;
128 }
129 
130 //_____________________________________________________________
131 Bool_t AliMUONRawStreamTrigger::Next(UChar_t& id, UChar_t& dec, Bool_t& trigY,
132  UChar_t& yPos, UChar_t& sXDev, UChar_t& xDev,
133  UChar_t& xPos, Bool_t& triggerY, Bool_t& triggerX,
134  TArrayS& xPattern, TArrayS& yPattern)
135 {
141 
142  if ( IsDone() ) return kFALSE;
143 
144  if ( fLocalStructRead ) {
145 
146  Bool_t ok = GetNextLocalStruct();
147  if (!ok)
148  {
149  // this is the end
150  return kFALSE;
151  }
152  }
153 
154  fLocalStructRead = kTRUE;
155 
156  id = fCurrentLocalStruct->GetId();
157  dec = fCurrentLocalStruct->GetDec();
158  trigY = fCurrentLocalStruct->GetTrigY();
159  yPos = fCurrentLocalStruct->GetYPos();
160  sXDev = fCurrentLocalStruct->GetSXDev();
161  xDev = fCurrentLocalStruct->GetXDev();
162  xPos = fCurrentLocalStruct->GetXPos();
163 
164  triggerX = fCurrentLocalStruct->GetTriggerX();
165  triggerY = fCurrentLocalStruct->GetTriggerY();
166 
167  fCurrentLocalStruct->GetXPattern(xPattern);
168  fCurrentLocalStruct->GetYPattern(yPattern);
169 
170  return kTRUE;
171 }
172 
173 //______________________________________________________
175 {
177  return (fCurrentLocalStruct==0);
178 }
179 
180 //______________________________________________________
182 {
184 
185  fCurrentDDLIndex = -1;
186  // Must reset all the pointers because if we return before calling
187  // GetNextLocalStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
188  // CurrentRegHeader() or CurrentLocalStruct() which should return reasonable
189  // results in that case.
190  fCurrentDDL = 0;
191  fCurrentDarcHeader = 0;
192  fCurrentRegHeader = 0;
194 
195  // Find the first non-empty structure
196  if (not GetNextDDL()) return;
197  if (not GetNextRegHeader()) return;
199 }
200 
201 //______________________________________________________
203 {
205 
206  assert( GetReader() != 0 );
207 
208 
209  Bool_t kFound(kFALSE);
210 
211  while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound )
212  {
214  GetReader()->Reset();
215  GetReader()->Select("MUONTRG",fCurrentDDLIndex,fCurrentDDLIndex);
216  if ( GetReader()->ReadHeader() )
217  {
218  kFound = kTRUE;
219  }
220  }
221 
222  if ( !kFound )
223  {
224  // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
225  // for a subsequent call to this method, unless NextEvent is called in between.
227  // We have not actually been able to complete the loading of the new DDL so
228  // we are still on the old one. In this case we do not need to reset fCurrentDDL.
229  //fCurrentDDL = 0;
231  return kFALSE;
232  }
233 
234  Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
235 
236  AliRawReader * reader = GetReader();
237  if (!reader) return kFALSE;
238 
239  const AliRawDataHeader * cdh = reader->GetDataHeader();
240  const AliRawDataHeaderV3 * cdh3 = reader->GetDataHeaderV3();
241 
242  if (!cdh && !cdh3) return kFALSE;
243 
244  Bool_t scalerEvent = ((cdh ? cdh->GetL1TriggerMessage() : cdh3->GetL1TriggerMessage()) & 0x1) == 0x1;
245 
246  AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
247  totalDataWord));
248 
249  UInt_t *buffer = new UInt_t[totalDataWord/4];
250 
251  if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
252  {
253  // We have not actually been able to complete the loading of the new DDL so
254  // we are still on the old one. In this case we do not need to reset fCurrentDDL.
255  //fCurrentDDL = 0;
256  delete [] buffer;
257  return kFALSE;
258  }
259 
260 #ifndef R__BYTESWAP
261  Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
262 #endif
263 
264  fPayload->ResetDDL();
265 
266 
267 
268  Bool_t ok = fPayload->Decode(buffer, scalerEvent);
269 
270  delete[] buffer;
271 
273 
275 
277 
278 
279  return ok;
280 }
281 
282 
283 //______________________________________________________
285 {
287 
288  assert( fCurrentDarcHeader != 0 );
289  assert( fCurrentDDL != 0 );
290 
291  fCurrentRegHeader = 0;
292 
293  Int_t i = fCurrentRegHeaderIndex;
294 
295  while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
296  {
297  ++i;
299  }
300 
301  if ( !fCurrentRegHeader )
302  {
303  Bool_t ok = GetNextDDL();
304  if (!ok)
305  {
306  return kFALSE;
307  }
308  else
309  {
310  return GetNextRegHeader();
311  }
312  }
313 
315 
317 
318  return kTRUE;
319 }
320 
321 //______________________________________________________
323 {
325 
326  assert( fCurrentRegHeader != 0 );
327 
329 
330  Int_t i = fCurrentLocalStructIndex;
331 
332  while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 )
333  {
334  ++i;
336  }
337 
338  if ( !fCurrentLocalStruct )
339  {
340  Bool_t ok = GetNextRegHeader();
341  if (!ok)
342  {
343  return kFALSE;
344  }
345  else
346  {
347  return GetNextLocalStruct();
348  }
349  }
350 
352 
353  fLocalStructRead = kFALSE;
354 
355  return kTRUE;
356 }
357 
358 //______________________________________________________
360 {
364 
365  // reset TClones
366  fPayload->ResetDDL();
367 
368 
369  // loop over the two ddl's
370 
371  while ( fDDL < fgkMaxDDL ) {
372  GetReader()->Reset();
373  GetReader()->Select("MUONTRG", fDDL, fDDL); //Select the DDL file to be read
374  if (GetReader()->ReadHeader()) break;
375  AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
376  ++fDDL;
377  }
378 
379  if (fDDL >= fgkMaxDDL) {
380  fDDL = 0;
382  return kFALSE;
383  }
384 
385  AliDebug(3, Form("DDL Number %d\n", fDDL ));
386 
387  Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
388 
389  AliRawReader * reader = GetReader();
390  if (!reader) return kFALSE;
391 
392  const AliRawDataHeader * cdh = reader->GetDataHeader();
393  const AliRawDataHeaderV3 * cdh3 = reader->GetDataHeaderV3();
394 
395  if (!cdh && !cdh3) return kFALSE;
396 
397  Bool_t scalerEvent = ((cdh ? cdh->GetL1TriggerMessage() : cdh3->GetL1TriggerMessage()) & 0x1) == 0x1;
398 
399 
400  UInt_t *buffer = new UInt_t[totalDataWord/4];
401 
402  // check not necessary yet, but for future developments
403  if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE;
404 
405 #ifndef R__BYTESWAP
406  Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
407 #endif
408 
409  fPayload->Decode(buffer, scalerEvent);
410 
411 
412  fDDL++;
413 
414  delete [] buffer;
415 
416 
417  return kTRUE;
418 }
419 
420 // //______________________________________________________
421 // void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg)
422 // {
423 // /// set regional card number
424 // fPayload->SetMaxReg(reg);
425 // }
426 
427 //______________________________________________________
429 {
431  fPayload->SetMaxLoc(loc);
432 }
433 
434 //______________________________________________________
436 {
438 
439  TString msg;
440  Int_t occurance = 0;
442 
443  log->ResetItr();
444  while(log->Next(msg, occurance))
445  {
446  if (msg.Contains("Darc"))
447  GetReader()->AddMajorErrorLog(kDarcEoWErr, msg.Data());
448 
449  if (msg.Contains("Global"))
450  GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
451 
452  if (msg.Contains("Regional"))
453  GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
454 
455  if (msg.Contains("Local"))
456  GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
457  }
458 
459  log->Clear(); // clear after each event
460 }
virtual Bool_t Next(UChar_t &id, UChar_t &dec, Bool_t &trigY, UChar_t &yPos, UChar_t &sXDev, UChar_t &xDev, UChar_t &xPos, Bool_t &triggerY, Bool_t &triggerX, TArrayS &xPattern, TArrayS &yPattern)
Advance one step in the iteration. Returns false if finished.
AliMUONLocalStruct * GetLocalEntry(Int_t i) const
get entry
virtual void Swap(UInt_t *buffer, Int_t size) const
swap method for Power PC
UChar_t GetSXDev() const
Get Sign of X deviation.
AliMUONLogger * GetErrorLogger() const
Get Error logger.
UChar_t GetDec() const
Return Dec.
AliMUONPayloadTrigger * fPayload
pointer to payload decoder
AliMUONDDLTrigger * GetDDLTrigger() const
Return pointer for DDL structure.
Bool_t GetTrigY() const
Return TrigY.
Bool_t Next(TString &msg, Int_t &occurance)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
A logger that keeps track of the number of times a message appeared.
Definition: AliMUONLogger.h:29
Class for reading MUON raw digits.
Int_t fCurrentDDLIndex
! for iterator: current ddl index
void AddErrorMessage()
add error message into error logger
AliMUONDarcHeader * GetDarcHeader() const
get AliMUONDarcHeader
Base class for reading MUON raw trigger data.
virtual Bool_t IsErrorLogger() const
Check if error info logger enable.
Bool_t GetTriggerY() const
Return TriggerY.
AliMUONRegHeader * fCurrentRegHeader
! for iterator: current reg ptr
Int_t fCurrentRegHeaderIndex
! for iterator: current reg index
Bool_t GetTriggerX() const
Return TriggerX.
void SetMaxLoc(Int_t loc)
Should set the maximum number of local cards expected in the DDL stream.
Bool_t fLocalStructRead
! flag for read out local structure
void GetXPattern(TArrayS &array) const
return X pattern array
AliMUONDDLTrigger * fCurrentDDL
! for iterator: current ddl ptr
void GetYPattern(TArrayS &array) const
return Y pattern array
Bool_t IsDone() const
Whether the iteration is finished or not.
void Clear(Option_t *="")
AliMUONRegHeader * GetRegHeaderEntry(Int_t i) const
get entry
void First()
Initialize iterator.
AliMUONLocalStruct * fCurrentLocalStruct
! for iterator: current local ptr
AliMUONDarcHeader * fCurrentDarcHeader
! for iterator: current darc ptr
static const Int_t fgkMaxDDL
maximum number of DDLs
UChar_t GetXPos() const
Return Xpos.
UChar_t GetId() const
Return Id.
UChar_t GetXDev() const
Get X deviation.
Int_t fCurrentLocalStructIndex
! for iterator: current local index
Class for decoding the payload for trigger raw data.
Bool_t Decode(UInt_t *buffer, Bool_t scalerEvent=kFALSE)
virtual Bool_t NextDDL()
DDL iterator.
virtual AliRawReader * GetReader()
Get object for reading the raw data.
UChar_t GetYPos() const
Return Upos.