- Adding check and flagging for HG present
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTrigger.cxx
CommitLineData
972432c1 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
bf4d93eb 16/* $Id$ */
972432c1 17
3d1463c8 18//-----------------------------------------------------------------------------
c4ee792d 19/// \class AliMUONRawStreamTrigger
972432c1 20/// This class provides access to MUON digits in raw data.
21///
22/// It loops over all MUON digits in the raw data given by the AliRawReader.
b921196a 23/// The Next method goes to the next local response. If there are no local response left
24/// it returns kFALSE.
972432c1 25/// It can loop also over DDL and store the decoded rawdata in TClonesArrays
313a427d 26/// in payload class.
972432c1 27///
b921196a 28/// Version implement for Trigger
c4ee792d 29/// \author Christian Finck
3d1463c8 30//-----------------------------------------------------------------------------
972432c1 31
b921196a 32#include <TArrayS.h>
33
972432c1 34#include "AliMUONRawStreamTrigger.h"
b921196a 35#include "AliMUONDarcHeader.h"
36#include "AliMUONRegHeader.h"
37#include "AliMUONLocalStruct.h"
38#include "AliMUONDDLTrigger.h"
39#include "AliMUONLogger.h"
972432c1 40
41#include "AliRawReader.h"
42#include "AliRawDataHeader.h"
9e378ff4 43#include "AliDAQ.h"
972432c1 44#include "AliLog.h"
45
b921196a 46#include <cassert>
47
00e86732 48/// \cond CLASSIMP
972432c1 49ClassImp(AliMUONRawStreamTrigger)
00e86732 50/// \endcond
972432c1 51
36f90a1a 52const Int_t AliMUONRawStreamTrigger::fgkMaxDDL = 2;
07a5b6b7 53
54//___________________________________________
972432c1 55AliMUONRawStreamTrigger::AliMUONRawStreamTrigger()
1788245f 56: AliMUONVRawStreamTrigger(),
9f5dcca3 57 fPayload(new AliMUONPayloadTrigger()),
b921196a 58 fCurrentDDL(0x0),
59 fCurrentDDLIndex(fgkMaxDDL),
60 fCurrentDarcHeader(0x0),
61 fCurrentRegHeader(0x0),
62 fCurrentRegHeaderIndex(0),
63 fCurrentLocalStruct(0x0),
64 fCurrentLocalStructIndex(0),
65 fLocalStructRead(kFALSE),
4a3224ff 66 fDDL(0),
9ee1d6ff 67 fNextDDL(kFALSE)
972432c1 68{
00e86732 69 ///
70 /// create an object to read MUON raw digits
71 /// Default ctor for monitoring purposes
72 ///
972432c1 73
972432c1 74
75}
76
77//_________________________________________________________________
78AliMUONRawStreamTrigger::AliMUONRawStreamTrigger(AliRawReader* rawReader)
1788245f 79 : AliMUONVRawStreamTrigger(rawReader),
9f5dcca3 80 fPayload(new AliMUONPayloadTrigger()),
b921196a 81 fCurrentDDL(0x0),
82 fCurrentDDLIndex(fgkMaxDDL),
83 fCurrentDarcHeader(0x0),
84 fCurrentRegHeader(0x0),
85 fCurrentRegHeaderIndex(0),
86 fCurrentLocalStruct(0x0),
87 fCurrentLocalStructIndex(0),
88 fLocalStructRead(kFALSE),
4a3224ff 89 fDDL(0),
9ee1d6ff 90 fNextDDL(kFALSE)
972432c1 91{
00e86732 92 ///
93 /// ctor with AliRawReader as argument
94 /// for reconstruction purpose
95 ///
972432c1 96
972432c1 97}
98
99//___________________________________
100AliMUONRawStreamTrigger::~AliMUONRawStreamTrigger()
101{
00e86732 102 ///
103 /// clean up
104 ///
313a427d 105 delete fPayload;
972432c1 106}
107
108//_____________________________________________________________
b921196a 109Bool_t AliMUONRawStreamTrigger::Next(UChar_t& id, UChar_t& dec, Bool_t& trigY,
110 UChar_t& yPos, UChar_t& sXDev, UChar_t& xDev,
111 UChar_t& xPos, Bool_t& triggerY, Bool_t& triggerX,
112 TArrayS& xPattern, TArrayS& yPattern)
113{
114 ///
115 /// read the next raw digit (local structure)
116 /// returns kFALSE if there is no digit left
117 /// Should call First() before this method to start the iteration.
118 ///
119
120 if ( IsDone() ) return kFALSE;
121
122 if ( fLocalStructRead ) {
123
124 Bool_t ok = GetNextLocalStruct();
125 if (!ok)
126 {
127 // this is the end
128 return kFALSE;
129 }
130 }
131
132 fLocalStructRead = kTRUE;
133
134 id = fCurrentLocalStruct->GetId();
135 dec = fCurrentLocalStruct->GetDec();
136 trigY = fCurrentLocalStruct->GetTrigY();
137 yPos = fCurrentLocalStruct->GetYPos();
138 sXDev = fCurrentLocalStruct->GetSXDev();
139 xDev = fCurrentLocalStruct->GetXDev();
140 xPos = fCurrentLocalStruct->GetXPos();
141
142 triggerX = fCurrentLocalStruct->GetTriggerX();
143 triggerY = fCurrentLocalStruct->GetTriggerY();
144
145 fCurrentLocalStruct->GetXPattern(xPattern);
146 fCurrentLocalStruct->GetYPattern(yPattern);
147
148 return kTRUE;
149}
150
151//______________________________________________________
152Bool_t AliMUONRawStreamTrigger::IsDone() const
972432c1 153{
b921196a 154 /// Whether the iteration is finished or not
155 return (fCurrentLocalStruct==0);
156}
157
158//______________________________________________________
159void AliMUONRawStreamTrigger::First()
160{
161 /// Initialize the iteration process.
162
163 fCurrentDDLIndex = -1;
164 // Must reset all the pointers because if we return before calling
165 // GetNextLocalStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
166 // CurrentRegHeader() or CurrentLocalStruct() which should return reasonable
167 // results in that case.
168 fCurrentDDL = 0;
169 fCurrentDarcHeader = 0;
170 fCurrentRegHeader = 0;
171 fCurrentLocalStruct = 0;
172
173 // Find the first non-empty structure
174 if (not GetNextDDL()) return;
175 if (not GetNextRegHeader()) return;
176 GetNextLocalStruct();
177}
178
179//______________________________________________________
180Bool_t AliMUONRawStreamTrigger::GetNextDDL()
181{
182 /// Returns the next DDL present
183
184 assert( GetReader() != 0 );
f4ee80d2 185
b921196a 186
187 Bool_t kFound(kFALSE);
188
189 while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound )
190 {
191 ++fCurrentDDLIndex;
192 GetReader()->Reset();
193 GetReader()->Select("MUONTRG",fCurrentDDLIndex,fCurrentDDLIndex);
194 if ( GetReader()->ReadHeader() )
195 {
196 kFound = kTRUE;
197 }
198 }
199
200 if ( !kFound )
201 {
202 // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
203 // for a subsequent call to this method, unless NextEvent is called in between.
204 fCurrentDDLIndex = fgkMaxDDL;
205 // We have not actually been able to complete the loading of the new DDL so
206 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
207 //fCurrentDDL = 0;
6817de1c 208 if (IsErrorLogger()) AddErrorMessage();
b921196a 209 return kFALSE;
210 }
211
212 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
213
f4ee80d2 214 Bool_t scalerEvent = GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
215
b921196a 216 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
217 totalDataWord));
218
219 UInt_t *buffer = new UInt_t[totalDataWord/4];
f4ee80d2 220
b921196a 221 if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
222 {
223 // We have not actually been able to complete the loading of the new DDL so
224 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
225 //fCurrentDDL = 0;
226 delete [] buffer;
227 return kFALSE;
228 }
229
230#ifndef R__BYTESWAP
47c48013 231 Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
b921196a 232#endif
233
234 fPayload->ResetDDL();
235
f4ee80d2 236
237
238 Bool_t ok = fPayload->Decode(buffer, scalerEvent);
b921196a 239
240 delete[] buffer;
241
242 fCurrentDDL = fPayload->GetDDLTrigger();
243
244 fCurrentDarcHeader = fCurrentDDL->GetDarcHeader();
245
246 fCurrentRegHeaderIndex = -1;
247
248
249 return ok;
250}
251
252
253//______________________________________________________
254Bool_t AliMUONRawStreamTrigger::GetNextRegHeader()
255{
256 /// Returns the next Reg Header present
257
258 assert( fCurrentDarcHeader != 0 );
259 assert( fCurrentDDL != 0 );
260
261 fCurrentRegHeader = 0;
262
263 Int_t i = fCurrentRegHeaderIndex;
264
265 while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
266 {
267 ++i;
268 fCurrentRegHeader = fCurrentDarcHeader->GetRegHeaderEntry(i);
269 }
270
271 if ( !fCurrentRegHeader )
272 {
273 Bool_t ok = GetNextDDL();
274 if (!ok)
275 {
276 return kFALSE;
277 }
278 else
279 {
280 return GetNextRegHeader();
281 }
282 }
283
284 fCurrentRegHeaderIndex = i;
285
286 fCurrentLocalStructIndex = -1;
287
288 return kTRUE;
289}
290
291//______________________________________________________
292Bool_t AliMUONRawStreamTrigger::GetNextLocalStruct()
293{
294 /// Find the next non-empty local structure
295
296 assert( fCurrentRegHeader != 0 );
297
298 fCurrentLocalStruct = 0;
299
300 Int_t i = fCurrentLocalStructIndex;
301
302 while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 )
303 {
304 ++i;
305 fCurrentLocalStruct = fCurrentRegHeader->GetLocalEntry(i);
306 }
307
308 if ( !fCurrentLocalStruct )
309 {
310 Bool_t ok = GetNextRegHeader();
311 if (!ok)
312 {
313 return kFALSE;
314 }
315 else
316 {
317 return GetNextLocalStruct();
318 }
319 }
320
321 fCurrentLocalStructIndex = i;
322
323 fLocalStructRead = kFALSE;
324
325 return kTRUE;
972432c1 326}
327
328//______________________________________________________
329Bool_t AliMUONRawStreamTrigger::NextDDL()
330{
00e86732 331 /// reading tracker DDL
b921196a 332 /// store local info into Array
333 /// store only non-empty structures
972432c1 334
972432c1 335 // reset TClones
313a427d 336 fPayload->ResetDDL();
337
972432c1 338
339 // loop over the two ddl's
07a5b6b7 340
36f90a1a 341 while ( fDDL < fgkMaxDDL ) {
b921196a 342 GetReader()->Reset();
343 GetReader()->Select("MUONTRG", fDDL, fDDL); //Select the DDL file to be read
344 if (GetReader()->ReadHeader()) break;
07a5b6b7 345 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
346 ++fDDL;
347 }
348
36f90a1a 349 if (fDDL >= fgkMaxDDL) {
972432c1 350 fDDL = 0;
6817de1c 351 if (IsErrorLogger()) AddErrorMessage();
972432c1 352 return kFALSE;
353 }
9e378ff4 354
07a5b6b7 355 AliDebug(3, Form("DDL Number %d\n", fDDL ));
972432c1 356
b921196a 357 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
07a5b6b7 358
24b5e881 359 Bool_t scalerEvent = GetReader()->GetDataHeader() && GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
f4ee80d2 360
361
972432c1 362 UInt_t *buffer = new UInt_t[totalDataWord/4];
363
d6ac560d 364 // check not necessary yet, but for future developments
b921196a 365 if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE;
972432c1 366
47c48013 367#ifndef R__BYTESWAP
368 Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
b921196a 369#endif
370
f4ee80d2 371 fPayload->Decode(buffer, scalerEvent);
6817de1c 372
972432c1 373
313a427d 374 fDDL++;
972432c1 375
972432c1 376 delete [] buffer;
377
ea59383d 378
972432c1 379 return kTRUE;
380}
381
bfbfa5da 382// //______________________________________________________
383// void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg)
384// {
385// /// set regional card number
386// fPayload->SetMaxReg(reg);
387// }
972432c1 388
389//______________________________________________________
390void AliMUONRawStreamTrigger::SetMaxLoc(Int_t loc)
391{
00e86732 392 /// set local card number
313a427d 393 fPayload->SetMaxLoc(loc);
972432c1 394}
ea59383d 395
396//______________________________________________________
397void AliMUONRawStreamTrigger::AddErrorMessage()
398{
399/// add message into logger of AliRawReader per event
400
9b4aee57 401 TString msg;
b921196a 402 Int_t occurance = 0;
403 AliMUONLogger* log = fPayload->GetErrorLogger();
404
405 log->ResetItr();
406 while(log->Next(msg, occurance))
407 {
408 if (msg.Contains("Darc"))
409 GetReader()->AddMajorErrorLog(kDarcEoWErr, msg.Data());
ea59383d 410
b921196a 411 if (msg.Contains("Global"))
412 GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
ea59383d 413
b921196a 414 if (msg.Contains("Regional"))
415 GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
ea59383d 416
b921196a 417 if (msg.Contains("Local"))
418 GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
419 }
6817de1c 420
421 log->Clear(); // clear after each event
ea59383d 422}