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