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