1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONRawStreamTrigger
20 /// This class provides access to MUON digits in raw data.
22 /// It loops over all MUON digits in the raw data given by the AliRawReader.
23 /// The Next method goes to the next local response. If there are no local response left
24 /// it returns kFALSE.
25 /// It can loop also over DDL and store the decoded rawdata in TClonesArrays
28 /// Version implement for Trigger
29 /// \author Christian Finck
30 //-----------------------------------------------------------------------------
34 #include "AliMUONRawStreamTrigger.h"
35 #include "AliMUONDarcHeader.h"
36 #include "AliMUONRegHeader.h"
37 #include "AliMUONLocalStruct.h"
38 #include "AliMUONDDLTrigger.h"
39 #include "AliMUONLogger.h"
41 #include "AliRawReader.h"
42 #include "AliRawDataHeader.h"
49 ClassImp(AliMUONRawStreamTrigger)
52 const Int_t AliMUONRawStreamTrigger::fgkMaxDDL = 2;
54 //___________________________________________
55 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger()
57 fPayload(new AliMUONPayloadTrigger()),
59 fCurrentDDLIndex(fgkMaxDDL),
60 fCurrentDarcHeader(0x0),
61 fCurrentRegHeader(0x0),
62 fCurrentRegHeaderIndex(0),
63 fCurrentLocalStruct(0x0),
64 fCurrentLocalStructIndex(0),
65 fLocalStructRead(kFALSE),
69 /// create an object to read MUON raw digits
70 /// Default ctor for monitoring purposes
76 //_________________________________________________________________
77 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger(AliRawReader* rawReader)
78 : AliMUONRawStream(rawReader),
79 fPayload(new AliMUONPayloadTrigger()),
81 fCurrentDDLIndex(fgkMaxDDL),
82 fCurrentDarcHeader(0x0),
83 fCurrentRegHeader(0x0),
84 fCurrentRegHeaderIndex(0),
85 fCurrentLocalStruct(0x0),
86 fCurrentLocalStructIndex(0),
87 fLocalStructRead(kFALSE),
91 /// ctor with AliRawReader as argument
92 /// for reconstruction purpose
97 //___________________________________
98 AliMUONRawStreamTrigger::~AliMUONRawStreamTrigger()
106 //_____________________________________________________________
107 Bool_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)
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.
118 if ( IsDone() ) return kFALSE;
120 if ( fLocalStructRead ) {
122 Bool_t ok = GetNextLocalStruct();
130 fLocalStructRead = kTRUE;
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();
140 triggerX = fCurrentLocalStruct->GetTriggerX();
141 triggerY = fCurrentLocalStruct->GetTriggerY();
143 fCurrentLocalStruct->GetXPattern(xPattern);
144 fCurrentLocalStruct->GetYPattern(yPattern);
149 //______________________________________________________
150 Bool_t AliMUONRawStreamTrigger::IsDone() const
152 /// Whether the iteration is finished or not
153 return (fCurrentLocalStruct==0);
156 //______________________________________________________
157 void AliMUONRawStreamTrigger::First()
159 /// Initialize the iteration process.
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.
167 fCurrentDarcHeader = 0;
168 fCurrentRegHeader = 0;
169 fCurrentLocalStruct = 0;
171 // Find the first non-empty structure
172 if (not GetNextDDL()) return;
173 if (not GetNextRegHeader()) return;
174 GetNextLocalStruct();
177 //______________________________________________________
178 Bool_t AliMUONRawStreamTrigger::GetNextDDL()
180 /// Returns the next DDL present
182 assert( GetReader() != 0 );
184 Bool_t kFound(kFALSE);
186 while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound )
189 GetReader()->Reset();
190 GetReader()->Select("MUONTRG",fCurrentDDLIndex,fCurrentDDLIndex);
191 if ( GetReader()->ReadHeader() )
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.
205 if (IsErrorLogger()) AddErrorMessage();
209 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
211 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
214 UInt_t *buffer = new UInt_t[totalDataWord/4];
216 if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
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.
226 swap(buffer, totalDataWord); // swap needed for mac power pc
229 fPayload->ResetDDL();
231 Bool_t ok = fPayload->Decode(buffer);
235 fCurrentDDL = fPayload->GetDDLTrigger();
237 fCurrentDarcHeader = fCurrentDDL->GetDarcHeader();
239 fCurrentRegHeaderIndex = -1;
246 //______________________________________________________
247 Bool_t AliMUONRawStreamTrigger::GetNextRegHeader()
249 /// Returns the next Reg Header present
251 assert( fCurrentDarcHeader != 0 );
252 assert( fCurrentDDL != 0 );
254 fCurrentRegHeader = 0;
256 Int_t i = fCurrentRegHeaderIndex;
258 while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
261 fCurrentRegHeader = fCurrentDarcHeader->GetRegHeaderEntry(i);
264 if ( !fCurrentRegHeader )
266 Bool_t ok = GetNextDDL();
273 return GetNextRegHeader();
277 fCurrentRegHeaderIndex = i;
279 fCurrentLocalStructIndex = -1;
284 //______________________________________________________
285 Bool_t AliMUONRawStreamTrigger::GetNextLocalStruct()
287 /// Find the next non-empty local structure
289 assert( fCurrentRegHeader != 0 );
291 fCurrentLocalStruct = 0;
293 Int_t i = fCurrentLocalStructIndex;
295 while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 )
298 fCurrentLocalStruct = fCurrentRegHeader->GetLocalEntry(i);
301 if ( !fCurrentLocalStruct )
303 Bool_t ok = GetNextRegHeader();
310 return GetNextLocalStruct();
314 fCurrentLocalStructIndex = i;
316 fLocalStructRead = kFALSE;
321 //______________________________________________________
322 Bool_t AliMUONRawStreamTrigger::NextDDL()
324 /// reading tracker DDL
325 /// store local info into Array
326 /// store only non-empty structures
329 fPayload->ResetDDL();
332 // loop over the two ddl's
334 while ( fDDL < fgkMaxDDL ) {
335 GetReader()->Reset();
336 GetReader()->Select("MUONTRG", fDDL, fDDL); //Select the DDL file to be read
337 if (GetReader()->ReadHeader()) break;
338 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
342 if (fDDL >= fgkMaxDDL) {
344 if (IsErrorLogger()) AddErrorMessage();
348 AliDebug(3, Form("DDL Number %d\n", fDDL ));
350 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
352 UInt_t *buffer = new UInt_t[totalDataWord/4];
354 // check not necessary yet, but for future developments
355 if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE;
358 swap(buffer, totalDataWord); // swap needed for mac power pc
361 fPayload->Decode(buffer);
372 //______________________________________________________
373 void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg)
375 /// set regional card number
376 fPayload->SetMaxReg(reg);
379 //______________________________________________________
380 void AliMUONRawStreamTrigger::SetMaxLoc(Int_t loc)
382 /// set local card number
383 fPayload->SetMaxLoc(loc);
386 //______________________________________________________
387 void AliMUONRawStreamTrigger::AddErrorMessage()
389 /// add message into logger of AliRawReader per event
393 AliMUONLogger* log = fPayload->GetErrorLogger();
396 while(log->Next(msg, occurance))
398 if (msg.Contains("Darc"))
399 GetReader()->AddMajorErrorLog(kDarcEoWErr, msg.Data());
401 if (msg.Contains("Global"))
402 GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
404 if (msg.Contains("Regional"))
405 GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
407 if (msg.Contains("Local"))
408 GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
411 log->Clear(); // clear after each event