]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawStreamTrigger.cxx
The changes to perform the trigger chamber efficiency determination from ESD
[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 {
68   ///
69   /// create an object to read MUON raw digits
70   /// Default ctor for monitoring purposes
71   ///
72
73
74 }
75
76 //_________________________________________________________________
77 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger(AliRawReader* rawReader)
78   : AliMUONRawStream(rawReader),
79     fPayload(new AliMUONPayloadTrigger()),
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)
89 {
90   ///
91   /// ctor with AliRawReader as argument
92   /// for reconstruction purpose
93   ///
94
95 }
96
97 //___________________________________
98 AliMUONRawStreamTrigger::~AliMUONRawStreamTrigger()
99 {
100   ///
101   /// clean up
102   ///
103   delete fPayload;
104 }
105
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)
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 //______________________________________________________
150 Bool_t AliMUONRawStreamTrigger::IsDone() const
151 {
152   /// Whether the iteration is finished or not
153   return (fCurrentLocalStruct==0);
154 }
155
156 //______________________________________________________
157 void 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 //______________________________________________________
178 Bool_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;
205     if (IsErrorLogger()) AddErrorMessage();
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);
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 //______________________________________________________
247 Bool_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 //______________________________________________________
285 Bool_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;
319 }
320
321 //______________________________________________________
322 Bool_t AliMUONRawStreamTrigger::NextDDL()
323 {
324   /// reading tracker DDL
325   /// store local info into Array
326   /// store only non-empty structures
327
328   // reset TClones
329   fPayload->ResetDDL();
330
331
332   // loop over the two ddl's
333
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));
339     ++fDDL;
340   }
341
342   if (fDDL >= fgkMaxDDL) {
343     fDDL = 0;
344     if (IsErrorLogger()) AddErrorMessage();
345     return kFALSE;
346   }
347
348   AliDebug(3, Form("DDL Number %d\n", fDDL ));
349
350   Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
351
352   UInt_t *buffer = new UInt_t[totalDataWord/4];
353
354   // check not necessary yet, but for future developments
355   if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE; 
356   
357 #ifndef R__BYTESWAP  
358   swap(buffer, totalDataWord); // swap needed for mac power pc
359 #endif
360
361   fPayload->Decode(buffer);
362
363
364   fDDL++;
365
366   delete [] buffer;
367
368
369   return kTRUE;
370 }
371
372 //______________________________________________________
373 void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg) 
374 {
375   /// set regional card number
376   fPayload->SetMaxReg(reg);
377 }
378
379 //______________________________________________________
380 void AliMUONRawStreamTrigger::SetMaxLoc(Int_t loc) 
381 {
382   /// set local card number
383   fPayload->SetMaxLoc(loc);
384 }
385
386 //______________________________________________________
387 void AliMUONRawStreamTrigger::AddErrorMessage()
388 {
389 /// add message into logger of AliRawReader per event
390
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());
400
401     if (msg.Contains("Global"))
402       GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
403
404     if (msg.Contains("Regional"))
405       GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
406
407     if (msg.Contains("Local"))
408       GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
409   }
410   
411   log->Clear(); // clear after each event
412 }