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