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),
70 /// create an object to read MUON raw digits
71 /// Default ctor for monitoring purposes
77 //_________________________________________________________________
78 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger(AliRawReader* rawReader)
79 : AliMUONVRawStreamTrigger(rawReader),
80 fPayload(new AliMUONPayloadTrigger()),
82 fCurrentDDLIndex(fgkMaxDDL),
83 fCurrentDarcHeader(0x0),
84 fCurrentRegHeader(0x0),
85 fCurrentRegHeaderIndex(0),
86 fCurrentLocalStruct(0x0),
87 fCurrentLocalStructIndex(0),
88 fLocalStructRead(kFALSE),
93 /// ctor with AliRawReader as argument
94 /// for reconstruction purpose
99 //___________________________________
100 AliMUONRawStreamTrigger::~AliMUONRawStreamTrigger()
108 //_____________________________________________________________
109 Bool_t AliMUONRawStreamTrigger::Next(UChar_t& id, UChar_t& dec, Bool_t& trigY,
110 UChar_t& yPos, UChar_t& sXDev, UChar_t& xDev,
111 UChar_t& xPos, Bool_t& triggerY, Bool_t& triggerX,
112 TArrayS& xPattern, TArrayS& yPattern)
115 /// read the next raw digit (local structure)
116 /// returns kFALSE if there is no digit left
117 /// Should call First() before this method to start the iteration.
120 if ( IsDone() ) return kFALSE;
122 if ( fLocalStructRead ) {
124 Bool_t ok = GetNextLocalStruct();
132 fLocalStructRead = kTRUE;
134 id = fCurrentLocalStruct->GetId();
135 dec = fCurrentLocalStruct->GetDec();
136 trigY = fCurrentLocalStruct->GetTrigY();
137 yPos = fCurrentLocalStruct->GetYPos();
138 sXDev = fCurrentLocalStruct->GetSXDev();
139 xDev = fCurrentLocalStruct->GetXDev();
140 xPos = fCurrentLocalStruct->GetXPos();
142 triggerX = fCurrentLocalStruct->GetTriggerX();
143 triggerY = fCurrentLocalStruct->GetTriggerY();
145 fCurrentLocalStruct->GetXPattern(xPattern);
146 fCurrentLocalStruct->GetYPattern(yPattern);
151 //______________________________________________________
152 Bool_t AliMUONRawStreamTrigger::IsDone() const
154 /// Whether the iteration is finished or not
155 return (fCurrentLocalStruct==0);
158 //______________________________________________________
159 void AliMUONRawStreamTrigger::First()
161 /// Initialize the iteration process.
163 fCurrentDDLIndex = -1;
164 // Must reset all the pointers because if we return before calling
165 // GetNextLocalStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
166 // CurrentRegHeader() or CurrentLocalStruct() which should return reasonable
167 // results in that case.
169 fCurrentDarcHeader = 0;
170 fCurrentRegHeader = 0;
171 fCurrentLocalStruct = 0;
173 // Find the first non-empty structure
174 if (not GetNextDDL()) return;
175 if (not GetNextRegHeader()) return;
176 GetNextLocalStruct();
179 //______________________________________________________
180 Bool_t AliMUONRawStreamTrigger::GetNextDDL()
182 /// Returns the next DDL present
184 assert( GetReader() != 0 );
187 Bool_t kFound(kFALSE);
189 while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound )
192 GetReader()->Reset();
193 GetReader()->Select("MUONTRG",fCurrentDDLIndex,fCurrentDDLIndex);
194 if ( GetReader()->ReadHeader() )
202 // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
203 // for a subsequent call to this method, unless NextEvent is called in between.
204 fCurrentDDLIndex = fgkMaxDDL;
205 // We have not actually been able to complete the loading of the new DDL so
206 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
208 if (IsErrorLogger()) AddErrorMessage();
212 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
214 Bool_t scalerEvent = GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
216 AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
219 UInt_t *buffer = new UInt_t[totalDataWord/4];
221 if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
223 // We have not actually been able to complete the loading of the new DDL so
224 // we are still on the old one. In this case we do not need to reset fCurrentDDL.
231 Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
234 fPayload->ResetDDL();
238 Bool_t ok = fPayload->Decode(buffer, scalerEvent);
242 fCurrentDDL = fPayload->GetDDLTrigger();
244 fCurrentDarcHeader = fCurrentDDL->GetDarcHeader();
246 fCurrentRegHeaderIndex = -1;
253 //______________________________________________________
254 Bool_t AliMUONRawStreamTrigger::GetNextRegHeader()
256 /// Returns the next Reg Header present
258 assert( fCurrentDarcHeader != 0 );
259 assert( fCurrentDDL != 0 );
261 fCurrentRegHeader = 0;
263 Int_t i = fCurrentRegHeaderIndex;
265 while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
268 fCurrentRegHeader = fCurrentDarcHeader->GetRegHeaderEntry(i);
271 if ( !fCurrentRegHeader )
273 Bool_t ok = GetNextDDL();
280 return GetNextRegHeader();
284 fCurrentRegHeaderIndex = i;
286 fCurrentLocalStructIndex = -1;
291 //______________________________________________________
292 Bool_t AliMUONRawStreamTrigger::GetNextLocalStruct()
294 /// Find the next non-empty local structure
296 assert( fCurrentRegHeader != 0 );
298 fCurrentLocalStruct = 0;
300 Int_t i = fCurrentLocalStructIndex;
302 while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 )
305 fCurrentLocalStruct = fCurrentRegHeader->GetLocalEntry(i);
308 if ( !fCurrentLocalStruct )
310 Bool_t ok = GetNextRegHeader();
317 return GetNextLocalStruct();
321 fCurrentLocalStructIndex = i;
323 fLocalStructRead = kFALSE;
328 //______________________________________________________
329 Bool_t AliMUONRawStreamTrigger::NextDDL()
331 /// reading tracker DDL
332 /// store local info into Array
333 /// store only non-empty structures
336 fPayload->ResetDDL();
339 // loop over the two ddl's
341 while ( fDDL < fgkMaxDDL ) {
342 GetReader()->Reset();
343 GetReader()->Select("MUONTRG", fDDL, fDDL); //Select the DDL file to be read
344 if (GetReader()->ReadHeader()) break;
345 AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
349 if (fDDL >= fgkMaxDDL) {
351 if (IsErrorLogger()) AddErrorMessage();
355 AliDebug(3, Form("DDL Number %d\n", fDDL ));
357 Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
359 Bool_t scalerEvent = GetReader()->GetDataHeader() && GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
362 UInt_t *buffer = new UInt_t[totalDataWord/4];
364 // check not necessary yet, but for future developments
365 if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE;
368 Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
371 fPayload->Decode(buffer, scalerEvent);
382 // //______________________________________________________
383 // void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg)
385 // /// set regional card number
386 // fPayload->SetMaxReg(reg);
389 //______________________________________________________
390 void AliMUONRawStreamTrigger::SetMaxLoc(Int_t loc)
392 /// set local card number
393 fPayload->SetMaxLoc(loc);
396 //______________________________________________________
397 void AliMUONRawStreamTrigger::AddErrorMessage()
399 /// add message into logger of AliRawReader per event
403 AliMUONLogger* log = fPayload->GetErrorLogger();
406 while(log->Next(msg, occurance))
408 if (msg.Contains("Darc"))
409 GetReader()->AddMajorErrorLog(kDarcEoWErr, msg.Data());
411 if (msg.Contains("Global"))
412 GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
414 if (msg.Contains("Regional"))
415 GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
417 if (msg.Contains("Local"))
418 GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
421 log->Clear(); // clear after each event