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