]>
Commit | Line | Data |
---|---|---|
33861fe0 | 1 | // $Id$ |
c012881c | 2 | //**************************************************************************** |
3 | //* This file is property of and copyright by the ALICE HLT Project * | |
4 | //* ALICE Experiment at CERN, All rights reserved. * | |
5 | //* * | |
6 | //* Primary Authors: Sergey Gorbunov, Torsten Alt * | |
7 | //* Developers: Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de> * | |
8 | //* Torsten Alt <talt@cern.ch> * | |
9 | //* for The ALICE HLT Project. * | |
10 | //* * | |
11 | //* Permission to use, copy, modify and distribute this software and its * | |
12 | //* documentation strictly for non-commercial purposes is hereby granted * | |
13 | //* without fee, provided that the above copyright notice appears in all * | |
14 | //* copies and that both the copyright notice and this permission notice * | |
15 | //* appear in the supporting documentation. The authors make no claims * | |
16 | //* about the suitability of this software for any purpose. It is * | |
17 | //* provided "as is" without express or implied warranty. * | |
18 | //**************************************************************************** | |
19 | ||
20 | // @file AliHLTTPCHWCFEmulator.cxx | |
21 | // @author Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de> | |
22 | // @author Torsten Alt <talt@cern.ch> | |
23 | // @brief FPGA ClusterFinder Emulator for TPC | |
24 | // @note | |
25 | ||
26 | ||
27 | #include "AliHLTTPCHWCFDataTypes.h" | |
28 | #include "AliHLTTPCHWCFEmulator.h" | |
29 | #include "AliHLTTPCClusterMCData.h" | |
33861fe0 | 30 | #include "AliHLTTPCHWCFData.h" |
c012881c | 31 | |
32 | #include <iostream> | |
33 | ||
34 | #if __GNUC__ >= 3 | |
35 | using namespace std; | |
36 | #endif | |
37 | ||
38 | ||
39 | AliHLTTPCHWCFEmulator::AliHLTTPCHWCFEmulator() | |
40 | : | |
b7ea7fe9 | 41 | fDebug(0), |
c012881c | 42 | fkMapping(0), |
43 | fChannelExtractor(), | |
25080052 | 44 | fPeakFinderUnit(), |
c012881c | 45 | fChannelProcessor(), |
46 | fChannelMerger(), | |
47 | fDivisionUnit() | |
48 | { | |
49 | //constructor | |
50 | } | |
51 | ||
52 | AliHLTTPCHWCFEmulator::~AliHLTTPCHWCFEmulator() | |
53 | { | |
54 | //destructor | |
55 | } | |
56 | ||
57 | AliHLTTPCHWCFEmulator::AliHLTTPCHWCFEmulator(const AliHLTTPCHWCFEmulator&) | |
58 | : | |
b7ea7fe9 | 59 | fDebug(0), |
c012881c | 60 | fkMapping(0), |
61 | fChannelExtractor(), | |
25080052 | 62 | fPeakFinderUnit(), |
c012881c | 63 | fChannelProcessor(), |
64 | fChannelMerger(), | |
65 | fDivisionUnit() | |
66 | { | |
67 | // dummy | |
68 | } | |
69 | ||
70 | AliHLTTPCHWCFEmulator& AliHLTTPCHWCFEmulator::operator=(const AliHLTTPCHWCFEmulator&) | |
71 | { | |
72 | // dummy | |
73 | return *this; | |
74 | } | |
75 | ||
eb62889b | 76 | void AliHLTTPCHWCFEmulator::Init( const AliHLTUInt32_t *mapping, AliHLTUInt32_t config1, AliHLTUInt32_t config2 ) |
c012881c | 77 | { |
78 | // Initialisation | |
79 | fkMapping = mapping; | |
80 | ||
25080052 | 81 | fPeakFinderUnit.SetChargeFluctuation( (config2>>4) & 0xF ); |
82 | ||
83 | fChannelProcessor.SetSingleSeqLimit( (config1) & 0xFF ); | |
84 | fChannelProcessor.SetDeconvolutionTime( (config1>>24) & 0x1 ); | |
4d67c3e3 | 85 | fChannelProcessor.SetUseTimeBinWindow( (config2>>8) & 0x1 ); |
25080052 | 86 | |
87 | ||
eb62889b | 88 | fChannelMerger.SetByPassMerger( (config1>>27) & 0x1 ); |
eb62889b | 89 | fChannelMerger.SetDeconvolution( (config1>>25) & 0x1 ); |
87e92eec | 90 | fChannelMerger.SetMatchDistance( (config2) & 0xF ); |
4d67c3e3 | 91 | fChannelMerger.SetMatchTimeFollow( (config2>>9) & 0x1 ); |
97aca268 | 92 | |
25080052 | 93 | fDivisionUnit.SetClusterLowerLimit( (config1>>8) & 0xFFFF ); |
94 | fDivisionUnit.SetSinglePadSuppression( (config1>>26) & 0x1 ); | |
95 | ||
96 | fPeakFinderUnit.SetDebugLevel(fDebug); | |
b7ea7fe9 | 97 | fChannelProcessor.SetDebugLevel(fDebug); |
98 | fChannelMerger.SetDebugLevel(fDebug); | |
99 | fDivisionUnit.SetDebugLevel(fDebug); | |
c012881c | 100 | } |
101 | ||
102 | ||
103 | int AliHLTTPCHWCFEmulator::FindClusters( const AliHLTUInt32_t *rawEvent, | |
104 | AliHLTUInt32_t rawEventSize32, | |
105 | AliHLTUInt32_t *output, | |
106 | AliHLTUInt32_t &outputSize32, | |
107 | const AliHLTTPCClusterMCLabel *mcLabels, | |
108 | AliHLTUInt32_t nMCLabels, | |
109 | AliHLTTPCClusterMCData *outputMC | |
110 | ) | |
111 | { | |
112 | // Loops over all rows finding the clusters | |
113 | ||
114 | AliHLTUInt32_t maxOutputSize32 = outputSize32; | |
115 | outputSize32 = 0; | |
116 | if( outputMC ) outputMC->fCount = 0; | |
117 | AliHLTUInt32_t maxNMCLabels = nMCLabels; | |
118 | if( !rawEvent ) return -1; | |
119 | ||
120 | // Initialise | |
121 | ||
122 | int ret = 0; | |
25080052 | 123 | |
c012881c | 124 | fChannelExtractor.Init( fkMapping, mcLabels, 3*rawEventSize32 ); |
25080052 | 125 | fPeakFinderUnit.Init(); |
c012881c | 126 | fChannelProcessor.Init(); |
127 | fChannelMerger.Init(); | |
128 | fDivisionUnit.Init(); | |
129 | ||
130 | // Read the data, word by word | |
131 | ||
132 | for( AliHLTUInt32_t iWord=0; iWord<=rawEventSize32; iWord++ ){ | |
133 | ||
25080052 | 134 | const AliHLTTPCHWCFBunch *bunch1=0; |
135 | const AliHLTTPCHWCFBunch *bunch2=0; | |
c012881c | 136 | const AliHLTTPCHWCFClusterFragment *fragment=0; |
137 | const AliHLTTPCHWCFClusterFragment *candidate=0; | |
138 | const AliHLTTPCHWCFCluster *cluster = 0; | |
139 | ||
140 | if( iWord<rawEventSize32 ) fChannelExtractor.InputStream(ReadBigEndian(rawEvent[iWord])); | |
141 | else fChannelExtractor.InputEndOfData(); | |
142 | ||
25080052 | 143 | while( (bunch1 = fChannelExtractor.OutputStream()) ){ |
144 | fPeakFinderUnit.InputStream(bunch1); | |
145 | while( (bunch2 = fPeakFinderUnit.OutputStream() )){ | |
146 | fChannelProcessor.InputStream(bunch2); | |
147 | while( (fragment = fChannelProcessor.OutputStream() )){ | |
148 | fChannelMerger.InputStream( fragment ); | |
149 | while( (candidate = fChannelMerger.OutputStream()) ){ | |
150 | fDivisionUnit.InputStream(candidate); | |
151 | while( (cluster = fDivisionUnit.OutputStream()) ){ | |
152 | if( cluster->fFlag==1 ){ | |
153 | if( outputSize32+AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize > maxOutputSize32 ){ // No space in the output buffer | |
154 | ret = -2; | |
155 | break; | |
156 | } | |
157 | AliHLTUInt32_t *co = &output[outputSize32]; | |
158 | int i=0; | |
159 | co[i++] = WriteBigEndian(cluster->fRowQ); | |
160 | co[i++] = WriteBigEndian(cluster->fQ); | |
161 | co[i++] = cluster->fP; | |
162 | co[i++] = cluster->fT; | |
163 | co[i++] = cluster->fP2; | |
164 | co[i++] = cluster->fT2; | |
165 | outputSize32+=AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize; | |
166 | if( mcLabels && outputMC && outputMC->fCount < maxNMCLabels){ | |
167 | outputMC->fLabels[outputMC->fCount++] = cluster->fMC; | |
168 | } | |
c012881c | 169 | } |
25080052 | 170 | else if( cluster->fFlag==2 ){ |
171 | if( outputSize32+1 > maxOutputSize32 ){ // No space in the output buffer | |
172 | ret = -2; | |
173 | break; | |
174 | } | |
175 | output[outputSize32++] = cluster->fRowQ; | |
c012881c | 176 | } |
c012881c | 177 | } |
178 | } | |
179 | } | |
180 | } | |
181 | } | |
182 | } | |
183 | return ret; | |
184 | } | |
185 | ||
186 | AliHLTUInt32_t AliHLTTPCHWCFEmulator::ReadBigEndian ( AliHLTUInt32_t word ) | |
187 | { | |
188 | // read the word written in big endian format (lowest byte first) | |
189 | ||
190 | const AliHLTUInt8_t *bytes = reinterpret_cast<const AliHLTUInt8_t *>( &word ); | |
191 | AliHLTUInt32_t i[4] = {bytes[0],bytes[1],bytes[2],bytes[3]}; | |
192 | ||
193 | return (i[3]<<24) | (i[2]<<16) | (i[1]<<8) | i[0]; | |
194 | } | |
195 | ||
196 | AliHLTUInt32_t AliHLTTPCHWCFEmulator::WriteBigEndian ( AliHLTUInt32_t word ) | |
197 | { | |
198 | // write the word in big endian format (least byte first) | |
199 | ||
200 | AliHLTUInt32_t ret = 0; | |
201 | AliHLTUInt8_t *bytes = reinterpret_cast<AliHLTUInt8_t *>( &ret ); | |
202 | bytes[0] = (word ) & 0xFF; | |
203 | bytes[1] = (word >> 8) & 0xFF; | |
204 | bytes[2] = (word >> 16) & 0xFF; | |
205 | bytes[3] = (word >> 24) & 0xFF; | |
206 | return ret; | |
207 | } | |
208 | ||
eb62889b | 209 | void AliHLTTPCHWCFEmulator::CreateConfiguration |
c012881c | 210 | ( |
211 | bool doDeconvTime, bool doDeconvPad, bool doFlowControl, | |
212 | bool doSinglePadSuppression, bool bypassMerger, | |
ee4d1bf0 | 213 | AliHLTUInt32_t clusterLowerLimit, AliHLTUInt32_t singleSeqLimit, |
4d67c3e3 | 214 | AliHLTUInt32_t mergerDistance, bool useTimeBinWindow, AliHLTUInt32_t chargeFluctuation, bool useTimeFollow, |
eb62889b | 215 | AliHLTUInt32_t &configWord1, AliHLTUInt32_t &configWord2 |
c012881c | 216 | ) |
217 | { | |
218 | // static method to create configuration word | |
219 | ||
eb62889b | 220 | configWord1 = 0; |
221 | configWord2 = 0; | |
c012881c | 222 | |
eb62889b | 223 | configWord1 |= ( (AliHLTUInt32_t)doFlowControl & 0x1 ) << 29; |
224 | configWord1 |= ( (AliHLTUInt32_t)bypassMerger & 0x1 ) << 27; | |
225 | configWord1 |= ( (AliHLTUInt32_t)doSinglePadSuppression & 0x1 ) << 26; | |
226 | configWord1 |= ( (AliHLTUInt32_t)doDeconvPad & 0x1 ) << 25; | |
227 | configWord1 |= ( (AliHLTUInt32_t)doDeconvTime & 0x1 ) << 24; | |
228 | configWord1 |= ( (AliHLTUInt32_t)clusterLowerLimit & 0xFFFF )<<8; | |
229 | configWord1 |= ( (AliHLTUInt32_t)singleSeqLimit & 0xFF ); | |
c012881c | 230 | |
eb62889b | 231 | configWord2 |= ( (AliHLTUInt32_t)mergerDistance & 0xF ); |
25080052 | 232 | configWord2 |= ( (AliHLTUInt32_t)chargeFluctuation & 0xF )<<4; |
233 | configWord2 |= ( (AliHLTUInt32_t)useTimeBinWindow & 0x1 )<<8; | |
4d67c3e3 | 234 | configWord2 |= ( (AliHLTUInt32_t)useTimeFollow & 0x1 )<<9; |
c012881c | 235 | } |