]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONUtils.cxx
Adding more checking and some bit packing routines.
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONUtils.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /**
19  * @file   AliHLTMUONUtils.cxx
20  * @author Artur Szostak <artursz@iafrica.com>
21  * @date   
22  * @brief  Implementation of AliHLTMUONUtils utility routines.
23  */
24
25 #include "AliHLTMUONUtils.h"
26 #include "AliHLTMUONConstants.h"
27
28
29 AliHLTUInt32_t AliHLTMUONUtils::PackTriggerRecordFlags(
30                 AliHLTMUONParticleSign sign, bool hitset[4]
31         )
32 {
33         AliHLTUInt32_t flags;
34         switch (sign)
35         {
36         case kSignMinus: flags = 0x80000000; break;
37         case kSignPlus:  flags = 0x40000000; break;
38         default:         flags = 0x00000000; break;
39         }
40
41         return flags | (hitset[0] ? 0x1 : 0) | (hitset[1] ? 0x2 : 0)
42                 | (hitset[2] ? 0x4 : 0) | (hitset[3] ? 0x8 : 0);
43 }
44
45
46 void AliHLTMUONUtils::UnpackTriggerRecordFlags(
47                 AliHLTUInt32_t flags, // [in]
48                 AliHLTMUONParticleSign& sign, // [out]
49                 bool hitset[4] // [out]
50         )
51 {
52         AliHLTUInt32_t signbits = flags & 0xC0000000;
53         switch (signbits)
54         {
55         case 0x80000000: sign = kSignMinus;   break;
56         case 0x40000000: sign = kSignPlus;    break;
57         default:         sign = kSignUnknown; break;
58         }
59         hitset[0] = (flags & 0x1) == 1;
60         hitset[1] = (flags & 0x2) == 1;
61         hitset[2] = (flags & 0x4) == 1;
62         hitset[3] = (flags & 0x8) == 1;
63 }
64
65
66 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
67 {
68         // The block must have the correct type.
69         if (block.fHeader.fType != kTriggerRecordsDataBlock) return false;
70         // The block's record widths must be the correct size.
71         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONTriggerRecordStruct))
72                 return false;
73         return true;
74 }
75
76 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONRecHitsBlockStruct& block)
77 {
78         // The block must have the correct type.
79         if (block.fHeader.fType != kRecHitsDataBlock) return false;
80         // The block's record widths must be the correct size.
81         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONRecHitStruct))
82                 return false;
83         return true;
84 }
85
86 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONClustersBlockStruct& block)
87 {
88         // The block must have the correct type.
89         if (block.fHeader.fType != kClustersDataBlock) return false;
90         // The block's record widths must be the correct size.
91         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONClusterStruct))
92                 return false;
93         return true;
94 }
95
96 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONChannelsBlockStruct& block)
97 {
98         // The block must have the correct type.
99         if (block.fHeader.fType != kChannelsDataBlock) return false;
100         // The block's record widths must be the correct size.
101         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONChannelStruct))
102                 return false;
103         return true;
104 }
105
106
107 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
108 {
109         if (not HeaderOk(block)) return false;
110
111         // Check if any ID is duplicated.
112         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
113         {
114                 AliHLTUInt32_t id = block.fTriggerRecord[i].fId;
115                 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
116                 {
117                         if (id == block.fTriggerRecord[j].fId)
118                                 return false;
119                 }
120         }
121
122         for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
123         {
124                 const AliHLTMUONTriggerRecordStruct& tr = block.fTriggerRecord[i];
125
126                 // Make sure that the reserved bits in the fFlags field are set
127                 // to zero.
128                 if ((tr.fFlags & 0x3FFFFFF0) != 0) return false;
129
130                 // Make sure the sign is not invalid.
131                 if ((tr.fFlags & 0xC0000000) == 3) return false;
132
133                 // Check that fHit[i] is nil if the corresponding bit in the
134                 // flags word is zero.
135                 const AliHLTMUONRecHitStruct& nilhit
136                         = AliHLTMUONConstants::NilRecHitStruct();
137                 if ((tr.fFlags & 0x1) == 0 and tr.fHit[0] != nilhit) return false;
138                 if ((tr.fFlags & 0x2) == 0 and tr.fHit[1] != nilhit) return false;
139                 if ((tr.fFlags & 0x4) == 0 and tr.fHit[2] != nilhit) return false;
140                 if ((tr.fFlags & 0x8) == 0 and tr.fHit[3] != nilhit) return false;
141         }
142
143         return true;
144 }
145
146
147 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONRecHitsBlockStruct& block)
148 {
149         if (not HeaderOk(block)) return false;
150         return true;
151 }
152
153
154 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONClustersBlockStruct& block)
155 {
156         if (not HeaderOk(block)) return false;
157         // The block must have the correct type.
158         if (block.fHeader.fType != kClustersDataBlock) return false;
159         
160         // The block's record widths must be the correct size.
161         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONClusterStruct))
162                 return false;
163
164         return true;
165 }
166
167 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONChannelsBlockStruct& block)
168 {
169         if (not HeaderOk(block)) return false;
170         // The block must have the correct type.
171         if (block.fHeader.fType != kChannelsDataBlock) return false;
172         
173         // The block's record widths must be the correct size.
174         if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONChannelStruct))
175                 return false;
176
177         return true;
178 }