]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawStreamTriggerHP.h
coveritiy
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTriggerHP.h
1 #ifndef ALIMUONRAWSTREAMTRIGGERHP_H
2 #define ALIMUONRAWSTREAMTRIGGERHP_H
3 /* This file is property of and copyright by the ALICE HLT Project        *
4  * ALICE Experiment at CERN, All rights reserved.                         *
5  * See cxx source for full Copyright notice                               */
6
7 /* $Id$ */
8
9 /// \ingroup raw
10 /// \class AliMUONRawStreamTriggerHP
11 /// \brief Higher performance decoder stream class for reading MUON raw trigger data.
12 ///
13 //  This provides a streamer interface to the high performance decoder which
14 //  is required for AliRoot.
15 //
16 //  Author Artur Szostak <artursz@iafrica.com>
17
18 #include "AliMUONVRawStreamTrigger.h"
19 #include "AliMUONTriggerDDLDecoder.h"
20 #include "TArrayS.h"
21
22 class AliMUONDDLTrigger;
23
24
25 class AliMUONRawStreamTriggerHP : public AliMUONVRawStreamTrigger
26 {
27 public:
28         class AliLocalStruct;
29
30         AliMUONRawStreamTriggerHP();
31         AliMUONRawStreamTriggerHP(AliRawReader* rawReader);
32         virtual ~AliMUONRawStreamTriggerHP();
33         
34         /// Initialize iterator
35         virtual void First();
36         
37         /// DDL iterator 
38         virtual Bool_t NextDDL();
39         
40         /// Whether the iteration is finished or not
41         virtual Bool_t IsDone() const;
42         
43         /// Nothing is actually done in the AddErrorMessage method because we log
44         /// the error messages as we find them in AliDecoderEventHandler::OnError().
45         virtual void AddErrorMessage() { };
46         
47         /// Advance one step in the iteration. Returns false if finished.
48         virtual Bool_t Next(UChar_t& id,   UChar_t& dec,     Bool_t& trigY,
49                             UChar_t& yPos, UChar_t& sXDev,   UChar_t& xDev,
50                             UChar_t& xPos, Bool_t& triggerY, Bool_t& triggerX,
51                             TArrayS& xPattern, TArrayS& yPattern);
52         
53         /// Construct and return a pointer to the DDL payload object.
54         virtual AliMUONDDLTrigger* GetDDLTrigger() const;
55         
56         /// Returns the next local trigger structure.
57         const AliLocalStruct* Next();
58         
59         /// Return maximum number of DDLs.
60         virtual Int_t GetMaxDDL() const { return fgkMaxDDL; }
61         
62         /// Return maximum number of regional cards in the DDL.
63         virtual Int_t GetMaxReg() const { return (Int_t) fDecoder.MaxRegionals(); }
64         
65         /// Set the maximum number of regional cards in the DDL.
66         virtual void SetMaxReg(Int_t reg);
67         
68         /// Return maximum number of local cards in the DDL.
69         virtual Int_t GetMaxLoc() const { return (Int_t) fDecoder.MaxLocals(); }
70         
71         /// Sets the maximum number of local cards in the DDL.
72         virtual void SetMaxLoc(Int_t loc);
73         
74         /// Return number of the current DDL being handled in the range [0..1] and -1 if no DDL set.
75         virtual Int_t GetDDL() const { return fDDL - 1; }
76         
77         /// check error/Warning presence
78         virtual Bool_t IsErrorMessage() const { return fHadError; }
79         
80         /// Set warnings flag to disable warnings on data errors.
81         virtual void DisableWarnings() { fDecoder.GetHandler().Warnings(kFALSE); }
82         /// Set warnings flag to enable warnings on data errors.
83         virtual void EnableWarnings() { fDecoder.GetHandler().Warnings(kTRUE); }
84         
85         /// Get number of end of DARC word errors in the DDL last decoded.
86         UInt_t GetDarcEoWErrors() const {return fDecoder.GetHandler().GetDarcEoWErrors();}
87         
88         /// Get number of end of Global word errors in the DDL last decoded.
89         UInt_t GetGlobalEoWErrors() const {return fDecoder.GetHandler().GetGlobalEoWErrors();}
90         
91         /// Get number of end of regional word errors in the DDL last decoded.
92         UInt_t GetRegEoWErrors() const {return fDecoder.GetHandler().GetRegEoWErrors();}
93         
94         /// Get number of end of local word errors in the DDL last decoded.
95         UInt_t GetLocalEoWErrors() const {return fDecoder.GetHandler().GetLocalEoWErrors();}
96         
97         /// Number of end of DARC word errors since First() was called.
98         UInt_t NumberOfDarcEoWErrors() const { return fTotalNumberOfDarcEoWErrors; }
99         
100         /// Number of end of global word errors since First() was called.
101         UInt_t NumberOfGlobalEoWErrors() const { return fTotalNumberOfGlobalEoWErrors; }
102         
103         /// Number of end of regional word errors since First() was called.
104         UInt_t NumberOfRegEoWErrors() const { return fTotalNumberOfRegEoWErrors; }
105         
106         /// Number of end of local word errors since First() was called.
107         UInt_t NumberOfLocalEoWErrors() const { return fTotalNumberOfLocalEoWErrors; }
108         
109         /// Whether we got any end of DARC word errors or not since calling First().
110         Bool_t HasDarcEoWError() const { return NumberOfDarcEoWErrors() > 0; }
111         
112         /// Whether we got any end of global word errors or not since calling First().
113         Bool_t HasGlobalEoWError() const { return NumberOfGlobalEoWErrors() > 0; }
114         
115         /// Whether we got any end of regional word errors or not since calling First().
116         Bool_t HasRegEoWError() const { return NumberOfRegEoWErrors() > 0; }
117         
118         /// Whether we got any end of local word errors or not since calling First().
119         Bool_t HasLocalEoWError() const { return NumberOfLocalEoWErrors() > 0; }
120         
121         /// Returns the "try to recover from errors" flag.
122         Bool_t TryRecover() const { return Bool_t(fDecoder.TryRecover()); }
123         
124         /// Sets the "try to recover from errors" flag.
125         /// i.e. should the decoder try to recover from errors found in the
126         /// payload headers.
127         void TryRecover(Bool_t value) { fDecoder.TryRecover(bool(value)); }
128         
129         /// Light weight interface class to the DARC and global header data.
130         class AliHeader
131         {
132         public:
133                 /// Default constructor.
134                 AliHeader(
135                                 UInt_t darcHeader = 0,
136                                 const AliMUONDarcScalarsStruct* darcScalars = NULL,
137                                 const AliMUONGlobalHeaderStruct* globalHeader = NULL,
138                                 const AliMUONGlobalScalarsStruct* globalScalars = NULL
139                         ) :
140                         fDarcHeader(darcHeader), fDarcScalars(darcScalars),
141                         fGlobalHeader(globalHeader), fGlobalScalars(globalScalars)
142                 {
143                 }
144                 
145                 /// Implement shallow copying in the copy constructor.
146                 AliHeader(const AliHeader& o) :
147                         fDarcHeader(o.fDarcHeader), fDarcScalars(o.fDarcScalars),
148                         fGlobalHeader(o.fGlobalHeader), fGlobalScalars(o.fGlobalScalars)
149                 {
150                 }
151                 
152                 /// Implement shallow copying in the assignment operator.
153                 AliHeader& operator = (const AliHeader& object)
154                 {
155                         memcpy(this, &object, sizeof(AliHeader));
156                         return *this;
157                 }
158         
159                 /// Default destructor.
160                 ~AliHeader() {};
161                 
162                 /// Return first word
163                 UInt_t   GetWord()               const {return GetDarcHeader();}
164                 /// Return global input
165                 UInt_t   GetGlobalInput(Int_t n) const {return fGlobalHeader->fInput[n];}
166                 /// Return global output
167                 UChar_t  GetGlobalOutput() const {return AliMUONTriggerDDLDecoderEventHandler::GetGlobalOutput(fGlobalHeader);}
168                 /// Return global config
169                 UShort_t GetGlobalConfig() const {return AliMUONTriggerDDLDecoderEventHandler::GetGlobalConfig(fGlobalHeader);}
170
171                 /// Return event type
172                 UChar_t GetEventType()  const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcEventType(GetDarcHeader());}
173                 /// Returns true if this was a physics event.
174                 Bool_t IsPhysicsEvent() const {return GetEventType() == 0x1;}
175                 /// Return Darc type
176                 UChar_t GetDarcType()   const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcType(GetDarcHeader());}
177                 /// Return serial number
178                 UChar_t GetSerialNb()   const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcSerialNb(GetDarcHeader());}
179                 /// Return version
180                 UChar_t GetVersion()    const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcVersion(GetDarcHeader());}
181                 /// Return VME trig
182                 Bool_t  GetVMETrig()    const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcVMETrig(GetDarcHeader());}
183                 /// Return global flag
184                 Bool_t  GetGlobalFlag() const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcGlobalFlag(GetDarcHeader());}
185                 /// Return CPT trigger
186                 Bool_t  GetCTPTrig()    const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcCTPTrig(GetDarcHeader());}
187                 /// Return DAQ flag
188                 Bool_t  GetDAQFlag()    const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcDAQFlag(GetDarcHeader());}
189                 /// Return reg pattern
190                 UChar_t GetRegPattern() const {return AliMUONTriggerDDLDecoderEventHandler::GetDarcRegPattern(GetDarcHeader());}
191         
192                 // DARC get methods
193                 /// Return DARC L0 received and used
194                 UInt_t  GetDarcL0R()   const {return (fDarcScalars != NULL) ? fDarcScalars->fL0R : 0;}
195                 /// Return DARC L1 physics
196                 UInt_t  GetDarcL1P()   const {return (fDarcScalars != NULL) ? fDarcScalars->fL1P : 0;}
197                 /// Return DARC L1 software
198                 UInt_t  GetDarcL1S()   const {return (fDarcScalars != NULL) ? fDarcScalars->fL1S : 0;}
199                 /// Return DARC L2 accept
200                 UInt_t  GetDarcL2A()   const {return (fDarcScalars != NULL) ? fDarcScalars->fL2A : 0;}
201                 /// Return DARC L2 reject
202                 UInt_t  GetDarcL2R()   const {return (fDarcScalars != NULL) ? fDarcScalars->fL2R : 0;}
203                 /// Return DARC clock
204                 UInt_t  GetDarcClock() const {return (fDarcScalars != NULL) ? fDarcScalars->fClk : 0;}
205                 /// Return DARC hold (dead time)
206                 UInt_t  GetDarcHold()  const {return (fDarcScalars != NULL) ? fDarcScalars->fHold : 0;}
207                 
208                 // global get methods
209                 /// Return global L0
210                 UInt_t  GetGlobalL0()    const {return (fGlobalScalars != NULL) ? fGlobalScalars->fL0 : 0;}
211                 /// Return global clock
212                 UInt_t  GetGlobalClock() const {return (fGlobalScalars != NULL) ? fGlobalScalars->fClk : 0;}
213                 /// Return global scalars or NULL if none exist.
214                 const UInt_t* GetGlobalScaler()  const {return (fGlobalScalars != NULL) ? &fGlobalScalars->fScaler[0] : NULL;}
215                 /// Return global hold (dead time)
216                 UInt_t  GetGlobalHold()  const {return (fGlobalScalars != NULL) ? fGlobalScalars->fHold : 0;}
217                 /// Return global spare
218                 UInt_t  GetGlobalSpare() const {return (fGlobalScalars != NULL) ? fGlobalScalars->fSpare : 0;}
219                 
220                 /// Return true if type for DARC is default.
221                 Bool_t DarcIsDefaultType() const {return GetDarcType() == AliMUONTriggerDDLDecoder<AliMUONTriggerDDLDecoderEventHandler>::DarcDefaultType();}
222                 /// Return true if type for DARC is Vadorh.
223                 Bool_t DarcIsVadohrType()  const {return GetDarcType() == AliMUONTriggerDDLDecoder<AliMUONTriggerDDLDecoderEventHandler>::DarcVadorhType();}
224                 
225                 /// Return the DARC header's raw data.
226                 UInt_t GetDarcHeader() const {return fDarcHeader;}
227                 
228                 /// Return the DARC scalars raw data or NULL if none exist.
229                 const AliMUONDarcScalarsStruct* GetDarcScalars() const {return fDarcScalars;}
230                 
231                 /// Return the global header's raw data.
232                 const AliMUONGlobalHeaderStruct* GetGlobalHeader() const {return fGlobalHeader;}
233                 
234                 /// Return the global scalars raw data or NULL if none exist.
235                 const AliMUONGlobalScalarsStruct* GetGlobalScalars() const {return fGlobalScalars;}
236                 
237                 /// Print the contents of the headers to screen.
238                 void Print() const;
239         
240         private:
241         
242                 UInt_t fDarcHeader;  ///< Pointer to DARC header in DDL payload.
243                 const AliMUONDarcScalarsStruct* fDarcScalars;  ///< Pointer to DARC scalars in DDL payload.
244                 const AliMUONGlobalHeaderStruct* fGlobalHeader;  ///< Pointer to global header in DDL payload.
245                 const AliMUONGlobalScalarsStruct* fGlobalScalars;  ///< Pointer to global scalars in DDL payload.
246         };
247         
248         /// Light weight interface class to the regional card header data.
249         class AliRegionalHeader
250         {
251         public:
252                 /// Default constructor.
253                 AliRegionalHeader(
254                                 const AliLocalStruct* localsArray = NULL,
255                                 const AliMUONRegionalHeaderStruct* header = NULL,
256                                 const AliMUONRegionalScalarsStruct* scalars = NULL
257                         ) :
258                         fNext(NULL), fLocalsCount(0), fFirstLocal(localsArray),
259                         fHeader(header), fScalars(scalars)
260                 {
261                 }
262                 
263                 /// Implement shallow copying in the copy constructor.
264                 AliRegionalHeader(const AliRegionalHeader& o) :
265                         fNext(o.fNext), fLocalsCount(o.fLocalsCount),
266                         fFirstLocal(o.fFirstLocal), fHeader(o.fHeader),
267                         fScalars(o.fScalars)
268                 {
269                 }
270                 
271                 /// Implement shallow copying in the assignment operator.
272                 AliRegionalHeader& operator = (const AliRegionalHeader& object)
273                 {
274                         memcpy(this, &object, sizeof(AliRegionalHeader));
275                         return *this;
276                 }
277                 
278                 /// Default destructor.
279                 ~AliRegionalHeader() {};
280                 
281                 /// Return darc word
282                 UInt_t   GetDarcWord()     const {return fHeader->fDarcWord;}
283                 /// Return first reg word
284                 UInt_t   GetWord()         const {return fHeader->fWord;}
285                 /// Return regional input
286                 UInt_t   GetInput(Int_t n) const {assert(n < 2); return fHeader->fInput[n];}
287                 /// Return L0
288                 UShort_t GetL0()           const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalL0(fHeader);}
289                 /// Return mask
290                 UShort_t GetMask()         const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalMask(fHeader);}
291                 
292                 //word: phys type:1, reset: 6, serialNb:5, Id:4, version: 8, regional output:8
293                 //true for phys, false for soft
294                 /// Return RegPhysFlag
295                 Bool_t    GetRegPhysFlag() const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalPhysFlag(fHeader);}
296                 /// Return ResetNb
297                 UChar_t   GetResetNb()     const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalResetNb(fHeader);}
298                 /// Return SerialNb
299                 UChar_t   GetSerialNb()    const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalSerialNb(fHeader);}
300                 /// Return Id
301                 UChar_t   GetId()          const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalId(fHeader);}
302                 /// Return Version
303                 UChar_t   GetVersion()     const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalVersion(fHeader);}
304                 /// Return Output
305                 UChar_t   GetOutput()      const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalOutput(fHeader);}
306                 
307                 //Darc Status: error:10, #fpag:3, MBZ:3, phys type:1, present:1, not_full:1
308                 // not_empty:1, L2Rej:1, L2Acc:1, L1:1, L0:1, #evt:4, busy:4
309                 /// Return ErrorBits
310                 UShort_t GetErrorBits()       const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalErrorBits(fHeader);}
311                 /// Return FPGANumber
312                 UChar_t  GetFPGANumber()      const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalFPGANumber(fHeader);}
313                 /// Return DarcPhysFlag
314                 Bool_t   GetDarcPhysFlag()    const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalDarcPhysFlag(fHeader);}
315                 /// Return PresentFlag
316                 Bool_t   GetPresentFlag()     const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalPresentFlag(fHeader);}
317                 /// Return RamNotFullFlag
318                 Bool_t   GetRamNotFullFlag()  const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalRamNotFullFlag(fHeader);}
319                 /// Return RamNotEmptyFlag
320                 Bool_t   GetRamNotEmptyFlag() const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalRamNotEmptyFlag(fHeader);}
321                 /// Return L2RejStatus
322                 Bool_t   GetL2RejStatus()     const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalL2RejStatus(fHeader);}
323                 /// Return L2AccStatus
324                 Bool_t   GetL2AccStatus()     const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalL2AccStatus(fHeader);}
325                 /// Return L1Status
326                 Bool_t   GetL1Status()        const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalL1Status(fHeader);}
327                 /// Return L0Status
328                 Bool_t   GetL0Status()        const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalL0Status(fHeader);}
329                 /// Return EventInRam
330                 UChar_t  GetEventInRam()      const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalEventInRam(fHeader);}
331                 /// Return Busy
332                 UChar_t  GetBusy()            const {return AliMUONTriggerDDLDecoderEventHandler::GetRegionalBusy(fHeader);}
333                 
334                 // scalar methods
335                 /// Return regional clock
336                 UInt_t  GetClock()        const {return (fScalars != NULL) ? fScalars->fClk : 0;}
337                 /// Return regional ouput
338                 const UInt_t* GetScaler() const {return (fScalars != NULL) ? &fScalars->fScaler[0] : NULL;}
339                 /// Return regional hold (dead time)
340                 UInt_t  GetHold()         const {return (fScalars != NULL) ? fScalars->fHold : 0;}
341                 
342                 /// Return raw data of regional header.
343                 const AliMUONRegionalHeaderStruct* GetHeader() const { return fHeader; }
344                 
345                 /// Return the raw data of the regional scalars or NULL if none exist.
346                 const AliMUONRegionalScalarsStruct* GetScalars() const { return fScalars; }
347                 
348                 /// Return the next regional structure header.
349                 const AliRegionalHeader* Next() const { return fNext; }
350                 
351                 /// Returns the first AliLocalStruct class in this regional structure.
352                 const AliLocalStruct* GetFirstLocalStruct() const { return fFirstLocal; }
353                 
354                 /// Returns the number of local trigger structures within this regional structure.
355                 UInt_t GetLocalStructCount() const { return fLocalsCount; }
356         
357                 /// Return the i'th local trigger structure in this regional structure.
358                 const AliLocalStruct* GetLocalStruct(UInt_t i) const
359                 {
360                         return i < fLocalsCount ? GetFirstLocalStruct() + i : NULL;
361                 }
362         
363                 /// Sets the next regional structure header.
364                 void SetNext(const AliRegionalHeader* next) { fNext = next; }
365
366                 /// Increments the local trigger structure count.
367                 void IncLocalStructCount() { fLocalsCount++; };
368                 
369                 /// Print the contents of the regional header and scalars to screen.
370                 void Print() const;
371         
372         private:
373         
374                 const AliRegionalHeader* fNext;  ///< Pointer to next regional header.
375                 UInt_t fLocalsCount;  ///< The number of AliLocalStruct objects found in the array pointed to by fFirstLocal.
376                 const AliLocalStruct* fFirstLocal;  ///< The first local trigger structure of this regional structure.
377                 const AliMUONRegionalHeaderStruct* fHeader;  ///< Pointer to the regional header in the DDL payload.
378                 const AliMUONRegionalScalarsStruct* fScalars;  ///< Pointer to the regional scalars in the DDL payload.
379         };
380         
381         /// Light weight interface class to the local trigger card data.
382         class AliLocalStruct
383         {
384         public:
385                 /// Default constructor.
386                 AliLocalStruct(
387                                 const AliRegionalHeader* regionalHeader = NULL,
388                                 const AliMUONLocalInfoStruct* localStruct = NULL,
389                                 const AliMUONLocalScalarsStruct* scalars = NULL
390                         ) :
391                         fRegional(regionalHeader), fNext(NULL),
392                         fLocalStruct(localStruct), fScalars(scalars),
393                         fCalculatedId(0)
394                 {
395                 }
396                 
397                 /// Implement shallow copying in the copy constructor.
398                 AliLocalStruct(const AliLocalStruct& o) :
399                         fRegional(o.fRegional), fNext(o.fNext),
400                         fLocalStruct(o.fLocalStruct), fScalars(o.fScalars),
401                         fCalculatedId(o.fCalculatedId)
402                 {
403                 }
404                 
405                 /// Implement shallow copying in the assignment operator.
406                 AliLocalStruct& operator = (const AliLocalStruct& object)
407                 {
408                         memcpy(this, &object, sizeof(AliLocalStruct));
409                         return *this;
410                 }
411         
412                 /// Default destructor.
413                 ~AliLocalStruct() {};
414                 
415                 /// Return local data
416                 UInt_t GetData(Int_t n) const
417                 {
418                         assert(n < 5);
419                         return (reinterpret_cast<const UInt_t*>(fLocalStruct))[n];
420                 }
421         
422                 /// Return X2
423                 UShort_t GetX2() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalX2(fLocalStruct);}
424                 /// Return X1
425                 UShort_t GetX1() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalX1(fLocalStruct);}
426                 /// Return X4
427                 UShort_t GetX4() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalX4(fLocalStruct);}
428                 /// Return X3
429                 UShort_t GetX3() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalX3(fLocalStruct);}
430         
431                 /// Return Y2
432                 UShort_t GetY2() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalY2(fLocalStruct);}
433                 /// Return Y1
434                 UShort_t GetY1() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalY1(fLocalStruct);}
435                 /// Return Y4
436                 UShort_t GetY4() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalY4(fLocalStruct);}
437                 /// Return Y3
438                 UShort_t GetY3() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalY3(fLocalStruct);}
439                 
440                 /// return X pattern array
441                 void GetXPattern(TArrayS& array) const
442                 {
443                         Short_t vec[4] = {GetX1(), GetX2(), GetX3(), GetX4()};
444                         array.Set(4, vec);
445                 }
446         
447                 /// return Y pattern array
448                 void GetYPattern(TArrayS& array) const
449                 {
450                         Short_t vec[4] = {GetY1(), GetY2(), GetY3(), GetY4()};
451                         array.Set(4, vec);
452                 }
453         
454                 /// Return Id
455                 UChar_t GetId() const {return fgOverrideId ? fCalculatedId : AliMUONTriggerDDLDecoderEventHandler::GetLocalId(fLocalStruct);}
456                 /// Return Dec
457                 UChar_t GetDec() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalDec(fLocalStruct);}
458                 /// Return TrigY
459                 Bool_t GetTrigY() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalTrigY(fLocalStruct);}
460                 /// Return TriggerY
461                 Bool_t GetTriggerY() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalTriggerY(fLocalStruct);}
462                 /// Return Upos
463                 UChar_t GetYPos() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalYPos(fLocalStruct);}
464                 /// Get Sign of X deviation 
465                 Bool_t GetSXDev() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalSXDev(fLocalStruct);}
466                 /// Get X deviation 
467                 UChar_t GetXDev() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalXDev(fLocalStruct);}
468                 /// Return TriggerX
469                 Bool_t GetTriggerX() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalTriggerX(fLocalStruct);}
470                 /// Return Xpos
471                 UChar_t GetXPos() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalXPos(fLocalStruct);}
472                 /// Return LPT
473                 UChar_t GetLpt() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalLpt(fLocalStruct);}
474                 /// Return HPT
475                 UChar_t GetHpt() const {return AliMUONTriggerDDLDecoderEventHandler::GetLocalHpt(fLocalStruct);}
476                 
477                 // Scaler methods
478                 /// Return local L0
479                 UInt_t  GetL0()      const {return (fScalars != NULL) ? fScalars->fL0 : 0;}
480                 /// Return local hold (dead time)
481                 UInt_t  GetHold()    const {return (fScalars != NULL) ? fScalars->fHold : 0;}
482                 /// Return local clock
483                 UInt_t  GetClock()   const {return (fScalars != NULL) ? fScalars->fClk : 0;}
484                 
485                 /// Return switch
486                 UShort_t GetSwitch() const
487                 {
488                         return (fScalars != NULL) ?
489                                 AliMUONTriggerDDLDecoderEventHandler::GetLocalSwitch(fScalars) : 0;
490                 }
491                 
492                 /// Return ComptXY
493                 UChar_t GetComptXY() const
494                 {
495                         return (fScalars != NULL) ?
496                                 AliMUONTriggerDDLDecoderEventHandler::GetLocalComptXY(fScalars) : 0;
497                 }
498         
499                 /// Return XY1
500                 UShort_t GetXY1(Int_t n) const
501                 {
502                         return (fScalars != NULL) ?
503                                 AliMUONTriggerDDLDecoderEventHandler::GetLocalXY1(fScalars, n) : 0;
504                 }
505         
506                 /// Return XY2
507                 UShort_t GetXY2(Int_t n) const
508                 {
509                         return (fScalars != NULL) ?
510                                 AliMUONTriggerDDLDecoderEventHandler::GetLocalXY2(fScalars, n) : 0;
511                 }
512         
513                 /// Return XY3
514                 UShort_t GetXY3(Int_t n) const
515                 {
516                         return (fScalars != NULL) ?
517                                 AliMUONTriggerDDLDecoderEventHandler::GetLocalXY3(fScalars, n) : 0;
518                 }
519         
520                 /// Return XY4
521                 UShort_t GetXY4(Int_t n) const
522                 {
523                         return (fScalars != NULL) ?
524                                 AliMUONTriggerDDLDecoderEventHandler::GetLocalXY4(fScalars, n) : 0;
525                 }
526
527                 /// Return raw data of the local trigger structure.
528                 const AliMUONLocalInfoStruct* GetData() const {return fLocalStruct;}
529                 
530                 /// Return raw data of the local trigger scalars.
531                 /// Could be NULL if no scalars present.
532                 const AliMUONLocalScalarsStruct* GetScalars() const {return fScalars;}
533                 
534                 /// Return the parent regional header.
535                 const AliRegionalHeader* GetRegionalHeader() const { return fRegional; }
536                 
537                 /// Return the next local trigger structure.
538                 const AliLocalStruct* Next() const { return fNext; }
539                 
540                 /// Sets the next local trigger structure.
541                 void SetNext(const AliLocalStruct* next) { fNext = next; }
542         
543                 /// Sets the calculated ID value to be returned by GetId if fgOverrideId is true.
544                 void SetCalculatedId(UChar_t id) { fCalculatedId = id; }
545                 
546                 /// Print the contents of the local trigger structure and contents to screen.
547                 void Print() const;
548                 
549                 /// Returns the override flag indicating if the GetId method should return the calculated Id value or not.
550                 static bool GetOverrideIdFlag() { return fgOverrideId; }
551                 
552                 /// Sets the override flag to control what value the GetId method returns.
553                 static void SetOverrideIdFlag(bool value) { fgOverrideId = value; }
554         
555         private:
556         
557                 const AliRegionalHeader* fRegional;  ///< The regional structure this local trigger structure belongs to.
558                 const AliLocalStruct* fNext;  ///< Next local structure object in the regional structure.
559                 const AliMUONLocalInfoStruct* fLocalStruct;  ///< Pointer to the local trigger structure data in the DDL payload.
560                 const AliMUONLocalScalarsStruct* fScalars;  ///< Pointer to the local trigger scalars data in the DDL payload.
561                 UChar_t fCalculatedId;  ///< Calculated ID value returned by GetId() if fgOverrideId == true.
562                 static bool fgOverrideId; //!< Flag indicating if we should return a calculated number in the GetId method.
563         };
564         
565         /// Returns the DARC and global headers plus scalars if they exist.
566         const AliHeader* GetHeaders() const { return fDecoder.GetHandler().GetHeaders(); }
567         
568         /// Return the number of regional structures in the DDL payload.
569         UInt_t GetRegionalHeaderCount() const
570         {
571                 return fDecoder.GetHandler().RegionalHeaderCount();
572         }
573         
574         /// Return the first regional structure header.
575         const AliRegionalHeader* GetFirstRegionalHeader() const
576         {
577                 return fDecoder.GetHandler().RegionalHeader(0);
578         }
579         
580         /// Return the i'th regional header or NULL if not found.
581         const AliRegionalHeader* GetRegionalHeader(UInt_t i) const
582         {
583                 return fDecoder.GetHandler().RegionalHeader(i);
584         }
585         
586         /// Returns the number of local trigger structures for the given
587         /// regional structure number.
588         UInt_t GetLocalStructCount(UInt_t reg) const
589         {
590                 const AliRegionalHeader* r = GetRegionalHeader(reg);
591                 return r != NULL ? r->GetLocalStructCount() : 0;
592         }
593         
594         /// Returns the i'th local trigger structure for the given regional
595         /// structure number or NULL if not found.
596         const AliLocalStruct* GetLocalStruct(UInt_t reg, UInt_t i) const
597         {
598                 const AliRegionalHeader* r = GetRegionalHeader(reg);
599                 return r != NULL ? r->GetLocalStruct(i) : NULL;
600         }
601
602         /// Returns the current local struct being decoded or NULL if none found.
603         const AliLocalStruct* CurrentLocalStruct() const
604         {
605                 return (fkCurrentLocalStruct != fDecoder.GetHandler().EndOfLocalStructs()) ?
606                         fkCurrentLocalStruct : NULL;
607         }
608
609         /// Returns the current regional structure being decoded
610         /// or NULL if none found.
611         const AliRegionalHeader* CurrentRegionalHeader() const
612         {
613                 const AliLocalStruct* local = CurrentLocalStruct();
614                 return (local != NULL) ? local->GetRegionalHeader() : NULL;
615         }
616         
617 private:
618         /// Not implemented
619         AliMUONRawStreamTriggerHP(const AliMUONRawStreamTriggerHP& stream);
620         /// Not implemented
621         AliMUONRawStreamTriggerHP& operator = (const AliMUONRawStreamTriggerHP& stream);
622         
623         
624         /// This is the custom event handler (callback interface) class which
625         /// unpacks raw data words and fills an internal buffer with decoded digits
626         /// as they are decoded by the high performance decoder.
627         /// Any errors are logged to the parent AliMUONVRawStreamTrigger, so one
628         /// must set this pointer appropriately before decoding and DDL payload.
629         class AliDecoderEventHandler : public AliMUONTriggerDDLDecoderEventHandler
630         {
631         public:
632         
633                 /// Default constructor.
634                 AliDecoderEventHandler();
635                 /// Default destructor.
636                 virtual ~AliDecoderEventHandler();
637                 
638                 /// Sets the internal arrays based on the maximum number of structures allowed.
639                 void SetMaxStructs(UInt_t maxRegionals, UInt_t maxLocals);
640                 
641                 /// Sets the raw stream object which should be the parent of this class.
642                 void SetRawStream(AliMUONVRawStreamTrigger* rawStream) { fRawStream = rawStream; }
643                 
644                 /// Returns the decoded DARC and global headers (and scalars if they exist).
645                 const AliHeader* GetHeaders() const { return &fHeaders; }
646                 
647                 /// Returns the number of regional headers.
648                 UInt_t RegionalHeaderCount() const { return fRegionalsCount; }
649                 
650                 /// Return the i'th regional structure header.
651                 const AliRegionalHeader* RegionalHeader(UInt_t i) const
652                 {
653                         return i < fRegionalsCount ? &fRegionals[i] : NULL;
654                 }
655                 
656                 /// Return the first local structure decoded.
657                 const AliLocalStruct* FirstLocalStruct() const { return fLocals; }
658                 
659                 /// Returns the marker to the end of local structures.
660                 /// i.e. one position past the last local structure in fLocals.
661                 const AliLocalStruct* EndOfLocalStructs() const { return fEndOfLocals; }
662                 
663                 /// Get number of end of DARC word errors.
664                 UInt_t GetDarcEoWErrors() const {return fDarcEoWErrors;}
665                 
666                 /// Get number of end of Global word errors.
667                 UInt_t GetGlobalEoWErrors() const {return fGlobalEoWErrors;}
668                 
669                 /// Get number of end of regional word errors.
670                 UInt_t GetRegEoWErrors() const {return fRegEoWErrors;}
671                 
672                 /// Get number of end of local word errors.
673                 UInt_t GetLocalEoWErrors() const {return fLocalEoWErrors;}
674
675                 /// Returns the warnings flag.
676                 Bool_t Warnings() const { return fWarnings; }
677                 /// Sets the warnings flag.
678                 void Warnings(Bool_t value) { fWarnings = value; }
679                 
680                 // The following methods are inherited from AliMUONTriggerDDLDecoderEventHandler:
681                 
682                 /// New buffer handler.
683                 void OnNewBuffer(const void* buffer, UInt_t bufferSize);
684
685                 /// End of buffer handler marks the end of local trigger structures.
686                 void OnEndOfBuffer(const void* /*buffer*/, UInt_t /*bufferSize*/)
687                 {
688                         fEndOfLocals = fCurrentLocal+1;
689                 }
690                 
691                 /// Handler for the DARC header which just remembers the pointers for later.
692                 void OnDarcHeader(UInt_t header,
693                                   const AliMUONDarcScalarsStruct* scalars,
694                                   const void* /*data*/)
695                 {
696                         fDarcHeader = header;
697                         fDarcScalars = scalars;
698                 }
699                 
700                 /// Handler for the global header which stores the pointer to the headers.
701                 void OnGlobalHeader(const AliMUONGlobalHeaderStruct* header,
702                                     const AliMUONGlobalScalarsStruct* scalars,
703                                     const void* /*data*/)
704                 {
705                         fHeaders = AliHeader(fDarcHeader, fDarcScalars, header, scalars);
706                 }
707                 
708                 /// Handler for new regional card structures.
709                 void OnNewRegionalStructV2(UInt_t iReg,
710                                            const AliMUONRegionalHeaderStruct* header,
711                                            const AliMUONRegionalScalarsStruct* scalars,
712                                            const void* data);
713                 
714                 /// Handler for new local card structures.
715                 void OnLocalStructV2(UInt_t iLoc,
716                                      const AliMUONLocalInfoStruct* localStruct,
717                                      const AliMUONLocalScalarsStruct* scalars);
718                 
719                 /// Error handler.
720                 void OnError(ErrorCode error, const void* location);
721         
722         private:
723         
724                 // Do not allow copying of this class.
725                 /// Not implemented
726                 AliDecoderEventHandler(const AliDecoderEventHandler& /*obj*/);
727                 /// Not implemented
728                 AliDecoderEventHandler& operator = (const AliDecoderEventHandler& /*obj*/);
729
730                 AliMUONVRawStreamTrigger* fRawStream; //!< Pointer to the parent raw stream object.
731                 const void* fBufferStart;   //!< Pointer to the start of the current DDL payload buffer.
732                 UInt_t fDarcHeader; //!< Currently decoded DARC header.
733                 const AliMUONDarcScalarsStruct* fDarcScalars; //!< Currently decoded DARC scalars.
734                 AliHeader fHeaders;  //!< Headers of the DDL payload.
735                 UInt_t fRegionalsCount; //!< Number of regional headers filled in fRegionals.
736                 AliRegionalHeader* fRegionals;  //!< Array of regional headers. [0..fMaxRegionals-1]
737                 AliLocalStruct* fLocals; //!< Array of decoded local structured. [0..fMaxRegionals*fMaxLocals-1]
738                 AliLocalStruct* fEndOfLocals; //!< Marker indicating the position just passed the last filled element in fLocals.
739                 AliRegionalHeader* fCurrentRegional; //!< Current regional header position.
740                 AliLocalStruct* fCurrentLocal; //!< Current local trigger structure.
741                 UInt_t fDarcEoWErrors;    //!< Number of end of DARC word errors.
742                 UInt_t fGlobalEoWErrors;  //!< Number of end of global word errors.
743                 UInt_t fRegEoWErrors;     //!< Number of end of regional word errors.
744                 UInt_t fLocalEoWErrors;   //!< Number of end of local word errors.
745                 Bool_t fWarnings;       //!< Flag indicating if we should generate a warning for errors.
746                 
747                 static const AliMUONRegionalHeaderStruct fgkEmptyHeader;  //!< Empty header for skipped regional structures.
748         };
749         
750         AliMUONTriggerDDLDecoder<AliDecoderEventHandler> fDecoder;  //!< The decoder for the DDL payload.
751         Int_t fDDL;         //!< The current DDL number being handled.
752         Int_t fBufferSize;  //!< This is the buffer size in bytes of fBuffer.
753         UChar_t* fBuffer;   //!< This is the buffer in which we store the DDL payload read from AliRawReader.
754         const AliLocalStruct* fkCurrentLocalStruct;  //!< The current local trigger structure being handled by Next().
755         Bool_t fHadError;   //!< Flag indicating if there was a decoding error or not.
756         Bool_t fDone;       //!< Flag indicating if the iteration is done or not.
757         mutable AliMUONDDLTrigger* fDDLObject; //!< Temporary DDL object used by GetDDLTrigger() for caching.
758         UInt_t fTotalNumberOfDarcEoWErrors; //!< The total number of end of DARC word errors since the last call to First().
759         UInt_t fTotalNumberOfGlobalEoWErrors; //!< The total number of end of global word errors since the last call to First().
760         UInt_t fTotalNumberOfRegEoWErrors; //!< The total number of end of regional word errors since the last call to First().
761         UInt_t fTotalNumberOfLocalEoWErrors; //!< The total number of end of local word errors since the last call to First().
762         
763         static const Int_t  fgkMaxDDL;     //!< Maximum number of DDLs
764         
765         ClassDef(AliMUONRawStreamTriggerHP, 0)  // Higher performance decoder class for MUON trigger rawdata.
766 };
767
768 ////////////////////////////////////////////////////////////////////////////////
769
770 inline const AliMUONRawStreamTriggerHP::AliLocalStruct* AliMUONRawStreamTriggerHP::Next()
771 {
772         /// Iterates through all the local trigger structures for the event.
773         /// When no more local triggers are found then NULL is returned.
774
775         do {
776                 if (fkCurrentLocalStruct != fDecoder.GetHandler().EndOfLocalStructs())
777                         return fkCurrentLocalStruct++;
778         } while (NextDDL());
779         return NULL;
780 }
781
782
783 inline void AliMUONRawStreamTriggerHP::AliDecoderEventHandler::OnNewRegionalStructV2(
784                 UInt_t iReg,
785                 const AliMUONRegionalHeaderStruct* header,
786                 const AliMUONRegionalScalarsStruct* scalars,
787                 const void* /*data*/
788         )
789 {
790         /// New regional structure handler is called by the decoder whenever a
791         /// new regional header is found. We just mark the header and increment
792         /// the appropriate counters.
793         
794         assert( header != NULL );
795         assert( iReg < fRegionalsCount );
796         
797         fCurrentRegional = fRegionals+iReg;
798         *fCurrentRegional = AliRegionalHeader(fCurrentLocal+1, header, scalars);
799         
800         // Link to the next regional structure unless this is the last one.
801         if (iReg+1 < fRegionalsCount)
802         {
803                 fCurrentRegional->SetNext(fCurrentRegional+1);
804         }
805 }
806
807
808 inline void AliMUONRawStreamTriggerHP::AliDecoderEventHandler::OnLocalStructV2(
809                 UInt_t iLoc,
810                 const AliMUONLocalInfoStruct* localStruct,
811                 const AliMUONLocalScalarsStruct* scalars
812         )
813 {
814         /// New local trigger structure handler.
815         /// This is called by the high performance decoder when a new local trigger
816         /// structure is found within the DDL payload.
817         /// We mark the location of the structure in the DDL paytload and increment
818         /// appropriate counters.
819
820         assert( localStruct != NULL );
821         assert( fCurrentLocal != NULL );
822         assert( fCurrentRegional != NULL );
823         assert( fCurrentRegional->GetLocalStructCount() < (UInt_t)fRawStream->GetMaxLoc() );
824         
825         // Link the previous local structure unless it is the first one. 
826         if (fCurrentRegional->GetLocalStructCount() > 0)
827         {
828                 fCurrentLocal->SetNext(fCurrentLocal+1);
829         }
830         
831         fCurrentLocal++;
832         *fCurrentLocal = AliLocalStruct(fCurrentRegional, localStruct, scalars);
833         fCurrentLocal->SetCalculatedId(iLoc);
834         fCurrentRegional->IncLocalStructCount();
835 }
836
837 #endif // ALIMUONRAWSTREAMTRIGGERHP_H