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()
56 : AliMUONVRawStreamTrigger(),
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),
68 fEnableErrorLogger(kFALSE)
71 /// create an object to read MUON raw digits
72 /// Default ctor for monitoring purposes
78 //_________________________________________________________________
79 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger(AliRawReader* rawReader)
80 : AliMUONVRawStreamTrigger(rawReader),
81 fPayload(new AliMUONPayloadTrigger()),
83 fCurrentDDLIndex(fgkMaxDDL),
84 fCurrentDarcHeader(0x0),
85 fCurrentRegHeader(0x0),
86 fCurrentRegHeaderIndex(0),
87 fCurrentLocalStruct(0x0),
88 fCurrentLocalStructIndex(0),
89 fLocalStructRead(kFALSE),
92 fEnableErrorLogger(kFALSE)
95 /// ctor with AliRawReader as argument
96 /// for reconstruction purpose
101 //___________________________________
102 AliMUONRawStreamTrigger::~AliMUONRawStreamTrigger()
110 //_____________________________________________________________
111 Bool_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)
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.
122 if ( IsDone() ) return kFALSE;
124 if ( fLocalStructRead ) {
126 Bool_t ok = GetNextLocalStruct();
134 fLocalStructRead = kTRUE;
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();
144 triggerX = fCurrentLocalStruct->GetTriggerX();
145 triggerY = fCurrentLocalStruct->GetTriggerY();
147 fCurrentLocalStruct->GetXPattern(xPattern);
148 fCurrentLocalStruct->GetYPattern(yPattern);
153 //______________________________________________________
154 Bool_t AliMUONRawStreamTrigger::IsDone() const
156 /// Whether the iteration is finished or not
157 return (fCurrentLocalStruct==0);
160 //______________________________________________________
161 void AliMUONRawStreamTrigger::First()
163 /// Initialize the iteration process.
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.
171 fCurrentDarcHeader = 0;
172 fCurrentRegHeader = 0;
173 fCurrentLocalStruct = 0;
175 // Find the first non-empty structure
176 if (not GetNextDDL()) return;
177 if (not GetNextRegHeader()) return;
178 GetNextLocalStruct();
181 //______________________________________________________
182 Bool_t AliMUONRawStreamTrigger::GetNextDDL()
184 /// Returns the next DDL present
186 assert( GetReader() != 0 );
189 Bool_t kFound(kFALSE);
191 while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound )
194 GetReader()->Reset();
195 GetReader()->Select("MUONTRG",fCurrentDDLIndex,fCurrentDDLIndex);
196 if ( GetReader()->ReadHeader() )
204 // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
205 // for a subsequent call to this method, unless NextEvent is called in between.
206 fCurrentDDLIndex = fgkMaxDDL;
207 // We have not actually been able to complete the loading of the new DDL so
208 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
210 if (IsErrorLogger()) AddErrorMessage();
214 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
216 Bool_t scalerEvent = GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
218 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
221 UInt_t *buffer = new UInt_t[totalDataWord/4];
223 if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
225 // We have not actually been able to complete the loading of the new DDL so
226 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
233 Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
236 fPayload->ResetDDL();
240 Bool_t ok = fPayload->Decode(buffer, scalerEvent);
244 fCurrentDDL = fPayload->GetDDLTrigger();
246 fCurrentDarcHeader = fCurrentDDL->GetDarcHeader();
248 fCurrentRegHeaderIndex = -1;
255 //______________________________________________________
256 Bool_t AliMUONRawStreamTrigger::GetNextRegHeader()
258 /// Returns the next Reg Header present
260 assert( fCurrentDarcHeader != 0 );
261 assert( fCurrentDDL != 0 );
263 fCurrentRegHeader = 0;
265 Int_t i = fCurrentRegHeaderIndex;
267 while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
270 fCurrentRegHeader = fCurrentDarcHeader->GetRegHeaderEntry(i);
273 if ( !fCurrentRegHeader )
275 Bool_t ok = GetNextDDL();
282 return GetNextRegHeader();
286 fCurrentRegHeaderIndex = i;
288 fCurrentLocalStructIndex = -1;
293 //______________________________________________________
294 Bool_t AliMUONRawStreamTrigger::GetNextLocalStruct()
296 /// Find the next non-empty local structure
298 assert( fCurrentRegHeader != 0 );
300 fCurrentLocalStruct = 0;
302 Int_t i = fCurrentLocalStructIndex;
304 while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 )
307 fCurrentLocalStruct = fCurrentRegHeader->GetLocalEntry(i);
310 if ( !fCurrentLocalStruct )
312 Bool_t ok = GetNextRegHeader();
319 return GetNextLocalStruct();
323 fCurrentLocalStructIndex = i;
325 fLocalStructRead = kFALSE;
330 //______________________________________________________
331 Bool_t AliMUONRawStreamTrigger::NextDDL()
333 /// reading tracker DDL
334 /// store local info into Array
335 /// store only non-empty structures
338 fPayload->ResetDDL();
341 // loop over the two ddl's
343 while ( fDDL < fgkMaxDDL ) {
344 GetReader()->Reset();
345 GetReader()->Select("MUONTRG", fDDL, fDDL); //Select the DDL file to be read
346 if (GetReader()->ReadHeader()) break;
347 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
351 if (fDDL >= fgkMaxDDL) {
353 if (IsErrorLogger()) AddErrorMessage();
357 AliDebug(3, Form("DDL Number %d\n", fDDL ));
359 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
361 Bool_t scalerEvent = GetReader()->GetDataHeader() && GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
364 UInt_t *buffer = new UInt_t[totalDataWord/4];
366 // check not necessary yet, but for future developments
367 if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE;
370 Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
373 fPayload->Decode(buffer, scalerEvent);
384 // //______________________________________________________
385 // void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg)
387 // /// set regional card number
388 // fPayload->SetMaxReg(reg);
391 //______________________________________________________
392 void AliMUONRawStreamTrigger::SetMaxLoc(Int_t loc)
394 /// set local card number
395 fPayload->SetMaxLoc(loc);
398 //______________________________________________________
399 void AliMUONRawStreamTrigger::AddErrorMessage()
401 /// add message into logger of AliRawReader per event
405 AliMUONLogger* log = fPayload->GetErrorLogger();
408 while(log->Next(msg, occurance))
410 if (msg.Contains("Darc"))
411 GetReader()->AddMajorErrorLog(kDarcEoWErr, msg.Data());
413 if (msg.Contains("Global"))
414 GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
416 if (msg.Contains("Regional"))
417 GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
419 if (msg.Contains("Local"))
420 GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
423 log->Clear(); // clear after each event