1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 * @file AliHLTMUONUtils.cxx
20 * @author Artur Szostak <artursz@iafrica.com>
22 * @brief Implementation of AliHLTMUONUtils utility routines.
25 #include "AliHLTMUONUtils.h"
26 #include "AliHLTMUONConstants.h"
29 AliHLTUInt32_t AliHLTMUONUtils::PackTriggerRecordFlags(
30 AliHLTMUONParticleSign sign, bool hitset[4]
36 case kSignMinus: flags = 0x80000000; break;
37 case kSignPlus: flags = 0x40000000; break;
38 default: flags = 0x00000000; break;
41 return flags | (hitset[0] ? 0x1 : 0) | (hitset[1] ? 0x2 : 0)
42 | (hitset[2] ? 0x4 : 0) | (hitset[3] ? 0x8 : 0);
46 void AliHLTMUONUtils::UnpackTriggerRecordFlags(
47 AliHLTUInt32_t flags, // [in]
48 AliHLTMUONParticleSign& sign, // [out]
49 bool hitset[4] // [out]
52 AliHLTUInt32_t signbits = flags & 0xC0000000;
55 case 0x80000000: sign = kSignMinus; break;
56 case 0x40000000: sign = kSignPlus; break;
57 default: sign = kSignUnknown; break;
59 hitset[0] = (flags & 0x1) == 1;
60 hitset[1] = (flags & 0x2) == 1;
61 hitset[2] = (flags & 0x4) == 1;
62 hitset[3] = (flags & 0x8) == 1;
66 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
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))
76 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONRecHitsBlockStruct& block)
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))
86 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONClustersBlockStruct& block)
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))
96 bool AliHLTMUONUtils::HeaderOk(const AliHLTMUONChannelsBlockStruct& block)
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))
107 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONTriggerRecordsBlockStruct& block)
109 if (not HeaderOk(block)) return false;
111 // Check if any ID is duplicated.
112 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
114 AliHLTUInt32_t id = block.fTriggerRecord[i].fId;
115 for (AliHLTUInt32_t j = i+1; i < block.fHeader.fNrecords; j++)
117 if (id == block.fTriggerRecord[j].fId)
122 for (AliHLTUInt32_t i = 0; i < block.fHeader.fNrecords; i++)
124 const AliHLTMUONTriggerRecordStruct& tr = block.fTriggerRecord[i];
126 // Make sure that the reserved bits in the fFlags field are set
128 if ((tr.fFlags & 0x3FFFFFF0) != 0) return false;
130 // Make sure the sign is not invalid.
131 if ((tr.fFlags & 0xC0000000) == 3) return false;
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;
147 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONRecHitsBlockStruct& block)
149 if (not HeaderOk(block)) return false;
154 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONClustersBlockStruct& block)
156 if (not HeaderOk(block)) return false;
157 // The block must have the correct type.
158 if (block.fHeader.fType != kClustersDataBlock) return false;
160 // The block's record widths must be the correct size.
161 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONClusterStruct))
167 bool AliHLTMUONUtils::IntegrityOk(const AliHLTMUONChannelsBlockStruct& block)
169 if (not HeaderOk(block)) return false;
170 // The block must have the correct type.
171 if (block.fHeader.fType != kChannelsDataBlock) return false;
173 // The block's record widths must be the correct size.
174 if (block.fHeader.fRecordWidth != sizeof(AliHLTMUONChannelStruct))