]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawStreamTrigger.cxx
Adding 2013 periods
[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(TRootIOCtor* /*dummy*/)
56 :   AliMUONVRawStreamTrigger(),
57 fPayload(0x0),
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 {
69   ///
70   /// create an object to read MUON raw digits
71   /// Default ctor with no mem allocation for I/O
72   ///
73 }
74
75 //___________________________________________
76 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger()
77 :   AliMUONVRawStreamTrigger(),
78     fPayload(new AliMUONPayloadTrigger()),
79     fCurrentDDL(0x0),
80     fCurrentDDLIndex(fgkMaxDDL),
81     fCurrentDarcHeader(0x0),
82     fCurrentRegHeader(0x0),
83     fCurrentRegHeaderIndex(0),
84     fCurrentLocalStruct(0x0),
85     fCurrentLocalStructIndex(0),
86     fLocalStructRead(kFALSE),
87     fDDL(0),
88     fNextDDL(kFALSE)
89 {
90   ///
91   /// create an object to read MUON raw digits
92   /// Default ctor for monitoring purposes
93   ///
94
95
96 }
97
98 //_________________________________________________________________
99 AliMUONRawStreamTrigger::AliMUONRawStreamTrigger(AliRawReader* rawReader)
100   : AliMUONVRawStreamTrigger(rawReader),
101     fPayload(new AliMUONPayloadTrigger()),
102     fCurrentDDL(0x0),
103     fCurrentDDLIndex(fgkMaxDDL),
104     fCurrentDarcHeader(0x0),
105     fCurrentRegHeader(0x0),
106     fCurrentRegHeaderIndex(0),
107     fCurrentLocalStruct(0x0),
108     fCurrentLocalStructIndex(0),
109     fLocalStructRead(kFALSE),
110     fDDL(0),
111     fNextDDL(kFALSE)
112 {
113   ///
114   /// ctor with AliRawReader as argument
115   /// for reconstruction purpose
116   ///
117
118 }
119
120 //___________________________________
121 AliMUONRawStreamTrigger::~AliMUONRawStreamTrigger()
122 {
123   ///
124   /// clean up
125   ///
126   delete fPayload;
127 }
128
129 //_____________________________________________________________
130 Bool_t AliMUONRawStreamTrigger::Next(UChar_t& id,   UChar_t& dec,      Bool_t& trigY, 
131                                      UChar_t& yPos, UChar_t& sXDev,    UChar_t& xDev,
132                                      UChar_t& xPos, Bool_t& triggerY,  Bool_t& triggerX,
133                                      TArrayS& xPattern, TArrayS& yPattern)
134 {
135   ///
136   /// read the next raw digit (local structure)
137   /// returns kFALSE if there is no digit left
138   /// Should call First() before this method to start the iteration.
139   ///
140   
141   if ( IsDone() ) return kFALSE;
142   
143   if ( fLocalStructRead ) {
144
145     Bool_t ok = GetNextLocalStruct();
146     if (!ok)
147     {
148       // this is the end
149       return kFALSE;
150     } 
151   }
152
153   fLocalStructRead = kTRUE;
154
155   id    = fCurrentLocalStruct->GetId();
156   dec   = fCurrentLocalStruct->GetDec(); 
157   trigY = fCurrentLocalStruct->GetTrigY();
158   yPos  = fCurrentLocalStruct->GetYPos();
159   sXDev = fCurrentLocalStruct->GetSXDev();
160   xDev  = fCurrentLocalStruct->GetXDev();
161   xPos  = fCurrentLocalStruct->GetXPos();
162
163   triggerX = fCurrentLocalStruct->GetTriggerX();
164   triggerY = fCurrentLocalStruct->GetTriggerY();
165
166   fCurrentLocalStruct->GetXPattern(xPattern);
167   fCurrentLocalStruct->GetYPattern(yPattern);
168
169   return kTRUE;
170 }
171
172 //______________________________________________________
173 Bool_t AliMUONRawStreamTrigger::IsDone() const
174 {
175   /// Whether the iteration is finished or not
176   return (fCurrentLocalStruct==0);
177 }
178
179 //______________________________________________________
180 void AliMUONRawStreamTrigger::First()
181 {
182   /// Initialize the iteration process.
183   
184   fCurrentDDLIndex = -1;
185   // Must reset all the pointers because if we return before calling
186   // GetNextLocalStruct() the user might call CurrentDDL(), CurrentBlockHeader(),
187   // CurrentRegHeader() or CurrentLocalStruct() which should return reasonable
188   // results in that case.
189   fCurrentDDL         = 0;
190   fCurrentDarcHeader  = 0;
191   fCurrentRegHeader   = 0;
192   fCurrentLocalStruct = 0;
193   
194   // Find the first non-empty structure
195   if (not GetNextDDL()) return;
196   if (not GetNextRegHeader()) return;
197   GetNextLocalStruct();
198 }
199
200 //______________________________________________________
201 Bool_t AliMUONRawStreamTrigger::GetNextDDL()
202 {
203   /// Returns the next DDL present
204   
205   assert( GetReader() != 0 );
206
207   
208   Bool_t kFound(kFALSE);
209   
210   while ( fCurrentDDLIndex < fgkMaxDDL-1 && !kFound ) 
211   {
212     ++fCurrentDDLIndex;
213     GetReader()->Reset();
214     GetReader()->Select("MUONTRG",fCurrentDDLIndex,fCurrentDDLIndex);
215     if ( GetReader()->ReadHeader() ) 
216     {
217       kFound = kTRUE;
218     }
219   }
220   
221   if ( !kFound ) 
222   {
223     // fCurrentDDLIndex is set to fgkMaxDDL so that we exit the above loop immediately
224     // for a subsequent call to this method, unless NextEvent is called in between.
225     fCurrentDDLIndex = fgkMaxDDL;
226     // We have not actually been able to complete the loading of the new DDL so
227     // we are still on the old one. In this case we do not need to reset fCurrentDDL.
228     //fCurrentDDL = 0;
229     if (IsErrorLogger()) AddErrorMessage();
230     return kFALSE;
231   }
232   
233   Int_t totalDataWord  = GetReader()->GetDataSize(); // in bytes
234   
235   Bool_t scalerEvent =  GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
236
237   AliDebug(3, Form("DDL Number %d totalDataWord %d\n", fCurrentDDLIndex,
238                    totalDataWord));
239
240   UInt_t *buffer = new UInt_t[totalDataWord/4];
241
242   if ( !GetReader()->ReadNext((UChar_t*)buffer, totalDataWord) )
243   {
244     // We have not actually been able to complete the loading of the new DDL so
245     // we are still on the old one. In this case we do not need to reset fCurrentDDL.
246     //fCurrentDDL = 0;
247     delete [] buffer;
248     return kFALSE;
249   }
250
251 #ifndef R__BYTESWAP  
252   Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
253 #endif
254
255   fPayload->ResetDDL();
256   
257
258
259   Bool_t ok = fPayload->Decode(buffer, scalerEvent);
260
261   delete[] buffer;
262   
263   fCurrentDDL = fPayload->GetDDLTrigger();
264   
265   fCurrentDarcHeader = fCurrentDDL->GetDarcHeader();
266   
267   fCurrentRegHeaderIndex = -1;
268
269
270   return ok;
271 }
272
273
274 //______________________________________________________
275 Bool_t AliMUONRawStreamTrigger::GetNextRegHeader()
276 {
277   /// Returns the next Reg Header present
278
279   assert( fCurrentDarcHeader != 0 );
280   assert( fCurrentDDL != 0 );
281
282   fCurrentRegHeader = 0;
283   
284   Int_t i = fCurrentRegHeaderIndex;
285   
286   while ( fCurrentRegHeader == 0 && i < fCurrentDarcHeader->GetRegHeaderEntries()-1 )
287   {
288     ++i;
289     fCurrentRegHeader = fCurrentDarcHeader->GetRegHeaderEntry(i);
290   }
291      
292   if ( !fCurrentRegHeader ) 
293   {
294     Bool_t ok = GetNextDDL();
295     if (!ok) 
296     {
297       return kFALSE;
298     }
299     else
300     {
301       return GetNextRegHeader();
302     }
303   }
304   
305   fCurrentRegHeaderIndex = i;
306   
307   fCurrentLocalStructIndex = -1;
308   
309   return kTRUE;
310 }
311
312 //______________________________________________________
313 Bool_t AliMUONRawStreamTrigger::GetNextLocalStruct()
314 {
315   /// Find the next non-empty local structure
316   
317   assert( fCurrentRegHeader != 0 );
318   
319   fCurrentLocalStruct = 0;
320
321   Int_t i = fCurrentLocalStructIndex;
322   
323   while ( fCurrentLocalStruct == 0 && i < fCurrentRegHeader->GetLocalEntries()-1 ) 
324   {
325     ++i;
326     fCurrentLocalStruct = fCurrentRegHeader->GetLocalEntry(i);
327   }
328     
329   if ( !fCurrentLocalStruct ) 
330   {
331     Bool_t ok = GetNextRegHeader();
332     if (!ok)
333     {
334       return kFALSE;
335     }
336     else
337     {
338       return GetNextLocalStruct();
339     }
340   }
341   
342   fCurrentLocalStructIndex = i;
343   
344   fLocalStructRead = kFALSE;
345   
346   return kTRUE;
347 }
348
349 //______________________________________________________
350 Bool_t AliMUONRawStreamTrigger::NextDDL()
351 {
352   /// reading tracker DDL
353   /// store local info into Array
354   /// store only non-empty structures
355
356   // reset TClones
357   fPayload->ResetDDL();
358
359
360   // loop over the two ddl's
361
362   while ( fDDL < fgkMaxDDL ) {
363     GetReader()->Reset();
364     GetReader()->Select("MUONTRG", fDDL, fDDL);  //Select the DDL file to be read  
365     if (GetReader()->ReadHeader()) break;
366     AliDebug(3,Form("Skipping DDL %d which does not seem to be there",fDDL));
367     ++fDDL;
368   }
369
370   if (fDDL >= fgkMaxDDL) {
371     fDDL = 0;
372     if (IsErrorLogger()) AddErrorMessage();
373     return kFALSE;
374   }
375
376   AliDebug(3, Form("DDL Number %d\n", fDDL ));
377
378   Int_t totalDataWord = GetReader()->GetDataSize(); // in bytes
379
380   Bool_t scalerEvent =  GetReader()->GetDataHeader() && GetReader()->GetDataHeader()->GetL1TriggerMessage() & 0x1;
381
382
383   UInt_t *buffer = new UInt_t[totalDataWord/4];
384
385   // check not necessary yet, but for future developments
386   if (!GetReader()->ReadNext((UChar_t*)buffer, totalDataWord)) return kFALSE; 
387   
388 #ifndef R__BYTESWAP
389   Swap(buffer, totalDataWord / sizeof(UInt_t)); // swap needed for mac power pc
390 #endif
391
392   fPayload->Decode(buffer, scalerEvent);
393
394
395   fDDL++;
396
397   delete [] buffer;
398
399
400   return kTRUE;
401 }
402
403 // //______________________________________________________
404 // void AliMUONRawStreamTrigger::SetMaxReg(Int_t reg) 
405 // {
406 //   /// set regional card number
407 //   fPayload->SetMaxReg(reg);
408 // }
409
410 //______________________________________________________
411 void AliMUONRawStreamTrigger::SetMaxLoc(Int_t loc) 
412 {
413   /// set local card number
414   fPayload->SetMaxLoc(loc);
415 }
416
417 //______________________________________________________
418 void AliMUONRawStreamTrigger::AddErrorMessage()
419 {
420 /// add message into logger of AliRawReader per event
421
422   TString msg;
423   Int_t occurance = 0;
424   AliMUONLogger* log = fPayload->GetErrorLogger();
425   
426   log->ResetItr();
427   while(log->Next(msg, occurance))
428   { 
429     if (msg.Contains("Darc"))
430       GetReader()->AddMajorErrorLog(kDarcEoWErr, msg.Data());
431
432     if (msg.Contains("Global"))
433       GetReader()->AddMajorErrorLog(kGlobalEoWErr, msg.Data());
434
435     if (msg.Contains("Regional"))
436       GetReader()->AddMajorErrorLog(kRegEoWErr, msg.Data());
437
438     if (msg.Contains("Local"))
439       GetReader()->AddMajorErrorLog(kLocalEoWErr, msg.Data());
440   }
441   
442   log->Clear(); // clear after each event
443 }