]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawStreamTrigger.cxx
Coding conventions: adding copy constructor and assignment operator
[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;
6817de1c 205 if (IsErrorLogger()) AddErrorMessage();
b921196a 206 return kFALSE;
207 }
208
209 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
210
211 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
212 totalDataWord));
213
214 UInt_t *buffer = new UInt_t[totalDataWord/4];
215
216 if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
217 {
218 // We have not actually been able to complete the loading of the new DDL so
219 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
220 //fCurrentDDL = 0;
221 delete [] buffer;
222 return kFALSE;
223 }
224
225#ifndef R__BYTESWAP
226 swap(buffer, totalDataWord); // swap needed for mac power pc
227#endif
228
229 fPayload->ResetDDL();
230
231 Bool_t ok = fPayload->Decode(buffer);
b921196a 232
233 delete[] buffer;
234
235 fCurrentDDL = fPayload->GetDDLTrigger();
236
237 fCurrentDarcHeader = fCurrentDDL->GetDarcHeader();
238
239 fCurrentRegHeaderIndex = -1;
240
241
242 return ok;
243}
244
245
246//______________________________________________________
247Bool_t AliMUONRawStreamTrigger::GetNextRegHeader()
248{
249 /// Returns the next Reg Header present
250
251 assert( fCurrentDarcHeader != 0 );
252 assert( fCurrentDDL != 0 );
253
254 fCurrentRegHeader = 0;
255
256 Int_t i = fCurrentRegHeaderIndex;
257
258 while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
259 {
260 ++i;
261 fCurrentRegHeader = fCurrentDarcHeader->GetRegHeaderEntry(i);
262 }
263
264 if ( !fCurrentRegHeader )
265 {
266 Bool_t ok = GetNextDDL();
267 if (!ok)
268 {
269 return kFALSE;
270 }
271 else
272 {
273 return GetNextRegHeader();
274 }
275 }
276
277 fCurrentRegHeaderIndex = i;
278
279 fCurrentLocalStructIndex = -1;
280
281 return kTRUE;
282}
283
284//______________________________________________________
285Bool_t AliMUONRawStreamTrigger::GetNextLocalStruct()
286{
287 /// Find the next non-empty local structure
288
289 assert( fCurrentRegHeader != 0 );
290
291 fCurrentLocalStruct = 0;
292
293 Int_t i = fCurrentLocalStructIndex;
294
295 while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 )
296 {
297 ++i;
298 fCurrentLocalStruct = fCurrentRegHeader->GetLocalEntry(i);
299 }
300
301 if ( !fCurrentLocalStruct )
302 {
303 Bool_t ok = GetNextRegHeader();
304 if (!ok)
305 {
306 return kFALSE;
307 }
308 else
309 {
310 return GetNextLocalStruct();
311 }
312 }
313
314 fCurrentLocalStructIndex = i;
315
316 fLocalStructRead = kFALSE;
317
318 return kTRUE;
972432c1 319}
320
321//______________________________________________________
322Bool_t AliMUONRawStreamTrigger::NextDDL()
323{
00e86732 324 /// reading tracker DDL
b921196a 325 /// store local info into Array
326 /// store only non-empty structures
972432c1 327
972432c1 328 // reset TClones
313a427d 329 fPayload->ResetDDL();
330
972432c1 331
332 // loop over the two ddl's
07a5b6b7 333
36f90a1a 334 while ( fDDL < fgkMaxDDL ) {
b921196a 335 GetReader()->Reset();
336 GetReader()->Select("MUONTRG", fDDL, fDDL); //Select the DDL file to be read
337 if (GetReader()->ReadHeader()) break;
07a5b6b7 338 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
339 ++fDDL;
340 }
341
36f90a1a 342 if (fDDL >= fgkMaxDDL) {
972432c1 343 fDDL = 0;
6817de1c 344 if (IsErrorLogger()) AddErrorMessage();
972432c1 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);
6817de1c 362
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 }
6817de1c 410
411 log->Clear(); // clear after each event
ea59383d 412}