]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawStreamTrigger.cxx
Coding conventions fixed.
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTrigger.cxx
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
16 /* $Id $ */
17
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONRawStreamTrigger
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.
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
26 /// in payload class.
27 /// 
28 /// Version implement for Trigger
29 /// \author Christian Finck
30 //-----------------------------------------------------------------------------
31
32 #include <TArrayS.h>
33
34 #include "AliMUONRawStreamTrigger.h"
35 #include "AliMUONDarcHeader.h"
36 #include "AliMUONRegHeader.h"
37 #include "AliMUONLocalStruct.h"
38 #include "AliMUONDDLTrigger.h"
39 #include "AliMUONLogger.h"
40
41 #include "AliRawReader.h"
42 #include "AliRawDataHeader.h"
43 #include "AliDAQ.h"
44 #include "AliLog.h"
45
46 #include <cassert>
47
48 /// \cond CLASSIMP
49 ClassImp(AliMUONRawStreamTrigger)
50 /// \endcond
51
52 const Int_t AliMUONRawStreamTrigger::fgkMaxDDL = 2;
53
54 //___________________________________________
55 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger()
56 :   AliMUONRawStream(),
57     fPayload(new AliMUONPayloadTrigger()),
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),
67     fNextDDL(kFALSE),
68     fEnableErrorLogger(kFALSE)
69 {
70   ///
71   /// create an object to read MUON raw digits
72   /// Default ctor for monitoring purposes
73   ///
74
75
76 }
77
78 //_________________________________________________________________
79 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger(AliRawReader* rawReader)
80   : AliMUONRawStream(rawReader),
81     fPayload(new AliMUONPayloadTrigger()),
82     fCurrentDDL(0x0),
83     fCurrentDDLIndex(fgkMaxDDL),
84     fCurrentDarcHeader(0x0),
85     fCurrentRegHeader(0x0),
86     fCurrentRegHeaderIndex(0),
87     fCurrentLocalStruct(0x0),
88     fCurrentLocalStructIndex(0),
89     fLocalStructRead(kFALSE),
90     fDDL(0),
91     fNextDDL(kFALSE),
92     fEnableErrorLogger(kFALSE)
93 {
94   ///
95   /// ctor with AliRawReader as argument
96   /// for reconstruction purpose
97   ///
98
99 }
100
101 //___________________________________
102 AliMUONRawStreamTrigger::~AliMUONRawStreamTrigger()
103 {
104   ///
105   /// clean up
106   ///
107   delete fPayload;
108 }
109
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)
115 {
116   ///
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.
120   ///
121   
122   if ( IsDone() ) return kFALSE;
123   
124   if ( fLocalStructRead ) {
125
126     Bool_t ok = GetNextLocalStruct();
127     if (!ok)
128     {
129       // this is the end
130       return kFALSE;
131     } 
132   }
133
134   fLocalStructRead = kTRUE;
135
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();
143
144   triggerX = fCurrentLocalStruct->GetTriggerX();
145   triggerY = fCurrentLocalStruct->GetTriggerY();
146
147   fCurrentLocalStruct->GetXPattern(xPattern);
148   fCurrentLocalStruct->GetYPattern(yPattern);
149
150   return kTRUE;
151 }
152
153 //______________________________________________________
154 Bool_t AliMUONRawStreamTrigger::IsDone() const
155 {
156   /// Whether the iteration is finished or not
157   return (fCurrentLocalStruct==0);
158 }
159
160 //______________________________________________________
161 void AliMUONRawStreamTrigger::First()
162 {
163   /// Initialize the iteration process.
164   
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.
170   fCurrentDDL         = 0;
171   fCurrentDarcHeader  = 0;
172   fCurrentRegHeader   = 0;
173   fCurrentLocalStruct = 0;
174   
175   // Find the first non-empty structure
176   if (not GetNextDDL()) return;
177   if (not GetNextRegHeader()) return;
178   GetNextLocalStruct();
179 }
180
181 //______________________________________________________
182 Bool_t AliMUONRawStreamTrigger::GetNextDDL()
183 {
184   /// Returns the next DDL present
185   
186   assert( GetReader() != 0 );
187   
188   Bool_t kFound(kFALSE);
189   
190   while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound ) 
191   {
192     ++fCurrentDDLIndex;
193     GetReader()->Reset();
194     GetReader()->Select("MUONTRG",fCurrentDDLIndex,fCurrentDDLIndex);
195     if ( GetReader()->ReadHeader() ) 
196     {
197       kFound = kTRUE;
198     }
199   }
200   
201   if ( !kFound ) 
202   {
203     // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
204     // for a subsequent call to this method, unless NextEvent is called in between.
205     fCurrentDDLIndex = fgkMaxDDL;
206     // We have not actually been able to complete the loading of the new DDL so
207     // we are still on the old one. In this case we do not need to reset fCurrentDDL.
208     //fCurrentDDL = 0;
209     if (IsErrorLogger()) AddErrorMessage();
210     return kFALSE;
211   }
212   
213   Int_t totalDataWord  = GetReader()->GetDataSize(); // in bytes
214   
215   AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
216                    totalDataWord));
217
218   UInt_t *buffer = new UInt_t[totalDataWord/4];
219   
220   if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
221   {
222     // We have not actually been able to complete the loading of the new DDL so
223     // we are still on the old one. In this case we do not need to reset fCurrentDDL.
224     //fCurrentDDL = 0;
225     delete [] buffer;
226     return kFALSE;
227   }
228
229 #ifndef R__BYTESWAP  
230   Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
231 #endif
232
233   fPayload->ResetDDL();
234   
235   Bool_t ok = fPayload->Decode(buffer);
236
237   delete[] buffer;
238   
239   fCurrentDDL = fPayload->GetDDLTrigger();
240   
241   fCurrentDarcHeader = fCurrentDDL->GetDarcHeader();
242   
243   fCurrentRegHeaderIndex = -1;
244
245
246   return ok;
247 }
248
249
250 //______________________________________________________
251 Bool_t AliMUONRawStreamTrigger::GetNextRegHeader()
252 {
253   /// Returns the next Reg Header present
254
255   assert( fCurrentDarcHeader != 0 );
256   assert( fCurrentDDL != 0 );
257
258   fCurrentRegHeader = 0;
259   
260   Int_t i = fCurrentRegHeaderIndex;
261   
262   while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
263   {
264     ++i;
265     fCurrentRegHeader = fCurrentDarcHeader->GetRegHeaderEntry(i);
266   }
267      
268   if ( !fCurrentRegHeader ) 
269   {
270     Bool_t ok = GetNextDDL();
271     if (!ok) 
272     {
273       return kFALSE;
274     }
275     else
276     {
277       return GetNextRegHeader();
278     }
279   }
280   
281   fCurrentRegHeaderIndex = i;
282   
283   fCurrentLocalStructIndex = -1;
284   
285   return kTRUE;
286 }
287
288 //______________________________________________________
289 Bool_t AliMUONRawStreamTrigger::GetNextLocalStruct()
290 {
291   /// Find the next non-empty local structure
292   
293   assert( fCurrentRegHeader != 0 );
294   
295   fCurrentLocalStruct = 0;
296
297   Int_t i = fCurrentLocalStructIndex;
298   
299   while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 ) 
300   {
301     ++i;
302     fCurrentLocalStruct = fCurrentRegHeader->GetLocalEntry(i);
303   }
304     
305   if ( !fCurrentLocalStruct ) 
306   {
307     Bool_t ok = GetNextRegHeader();
308     if (!ok)
309     {
310       return kFALSE;
311     }
312     else
313     {
314       return GetNextLocalStruct();
315     }
316   }
317   
318   fCurrentLocalStructIndex = i;
319   
320   fLocalStructRead = kFALSE;
321   
322   return kTRUE;
323 }
324
325 //______________________________________________________
326 Bool_t AliMUONRawStreamTrigger::NextDDL()
327 {
328   /// reading tracker DDL
329   /// store local info into Array
330   /// store only non-empty structures
331
332   // reset TClones
333   fPayload->ResetDDL();
334
335
336   // loop over the two ddl's
337
338   while ( fDDL < fgkMaxDDL ) {
339     GetReader()->Reset();
340     GetReader()->Select("MUONTRG", fDDL, fDDL);  //Select the DDL file to be read  
341     if (GetReader()->ReadHeader()) break;
342     AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
343     ++fDDL;
344   }
345
346   if (fDDL >= fgkMaxDDL) {
347     fDDL = 0;
348     if (IsErrorLogger()) AddErrorMessage();
349     return kFALSE;
350   }
351
352   AliDebug(3, Form("DDL Number %d\n", fDDL ));
353
354   Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
355
356   UInt_t *buffer = new UInt_t[totalDataWord/4];
357
358   // check not necessary yet, but for future developments
359   if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE; 
360   
361 #ifndef R__BYTESWAP
362   Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
363 #endif
364
365   fPayload->Decode(buffer);
366
367
368   fDDL++;
369
370   delete [] buffer;
371
372
373   return kTRUE;
374 }
375
376 // //______________________________________________________
377 // void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg) 
378 // {
379 //   /// set regional card number
380 //   fPayload->SetMaxReg(reg);
381 // }
382
383 //______________________________________________________
384 void AliMUONRawStreamTrigger::SetMaxLoc(Int_t loc) 
385 {
386   /// set local card number
387   fPayload->SetMaxLoc(loc);
388 }
389
390 //______________________________________________________
391 void AliMUONRawStreamTrigger::AddErrorMessage()
392 {
393 /// add message into logger of AliRawReader per event
394
395   TString msg = 0;
396   Int_t occurance = 0;
397   AliMUONLogger* log = fPayload->GetErrorLogger();
398   
399   log->ResetItr();
400   while(log->Next(msg, occurance))
401   { 
402     if (msg.Contains("Darc"))
403       GetReader()->AddMajorErrorLog(kDarcEoWErr, msg.Data());
404
405     if (msg.Contains("Global"))
406       GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
407
408     if (msg.Contains("Regional"))
409       GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
410
411     if (msg.Contains("Local"))
412       GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
413   }
414   
415   log->Clear(); // clear after each event
416 }