]>
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(), | |
97aca268 | 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(), | |
97aca268 | 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 | ||
97aca268 | 81 | fPeakFinderUnit.SetChargeFluctuation( (config2>>4) & 0xF ); |
82 | ||
83 | fChannelProcessor.SetSingleSeqLimit( (config1) & 0xFF ); | |
84 | fChannelProcessor.SetDeconvolutionTime( (config1>>24) & 0x1 ); | |
85 | fChannelProcessor.SetUseTimeBinWindow( (config2>>4) & 0x1 ); | |
86 | ||
87 | ||
eb62889b | 88 | fChannelMerger.SetByPassMerger( (config1>>27) & 0x1 ); |
eb62889b | 89 | fChannelMerger.SetDeconvolution( (config1>>25) & 0x1 ); |
eb62889b | 90 | fChannelMerger.SetMatchDistance( (config2) & 0xF ); |
91 | ||
97aca268 | 92 | fDivisionUnit.SetClusterLowerLimit( (config1>>8) & 0xFFFF ); |
93 | fDivisionUnit.SetSinglePadSuppression( (config1>>26) & 0x1 ); | |
94 | ||
95 | fPeakFinderUnit.SetDebugLevel(fDebug); | |
b7ea7fe9 | 96 | fChannelProcessor.SetDebugLevel(fDebug); |
97 | fChannelMerger.SetDebugLevel(fDebug); | |
98 | fDivisionUnit.SetDebugLevel(fDebug); | |
c012881c | 99 | } |
100 | ||
101 | ||
102 | int AliHLTTPCHWCFEmulator::FindClusters( const AliHLTUInt32_t *rawEvent, | |
103 | AliHLTUInt32_t rawEventSize32, | |
104 | AliHLTUInt32_t *output, | |
105 | AliHLTUInt32_t &outputSize32, | |
106 | const AliHLTTPCClusterMCLabel *mcLabels, | |
107 | AliHLTUInt32_t nMCLabels, | |
108 | AliHLTTPCClusterMCData *outputMC | |
109 | ) | |
110 | { | |
111 | // Loops over all rows finding the clusters | |
112 | ||
113 | AliHLTUInt32_t maxOutputSize32 = outputSize32; | |
114 | outputSize32 = 0; | |
115 | if( outputMC ) outputMC->fCount = 0; | |
116 | AliHLTUInt32_t maxNMCLabels = nMCLabels; | |
117 | if( !rawEvent ) return -1; | |
118 | ||
119 | // Initialise | |
120 | ||
121 | int ret = 0; | |
97aca268 | 122 | |
c012881c | 123 | fChannelExtractor.Init( fkMapping, mcLabels, 3*rawEventSize32 ); |
97aca268 | 124 | fPeakFinderUnit.Init(); |
c012881c | 125 | fChannelProcessor.Init(); |
126 | fChannelMerger.Init(); | |
127 | fDivisionUnit.Init(); | |
128 | ||
129 | // Read the data, word by word | |
130 | ||
131 | for( AliHLTUInt32_t iWord=0; iWord<=rawEventSize32; iWord++ ){ | |
132 | ||
97aca268 | 133 | const AliHLTTPCHWCFBunch *bunch1=0; |
134 | const AliHLTTPCHWCFBunch *bunch2=0; | |
c012881c | 135 | const AliHLTTPCHWCFClusterFragment *fragment=0; |
136 | const AliHLTTPCHWCFClusterFragment *candidate=0; | |
137 | const AliHLTTPCHWCFCluster *cluster = 0; | |
138 | ||
139 | if( iWord<rawEventSize32 ) fChannelExtractor.InputStream(ReadBigEndian(rawEvent[iWord])); | |
140 | else fChannelExtractor.InputEndOfData(); | |
141 | ||
97aca268 | 142 | while( (bunch1 = fChannelExtractor.OutputStream()) ){ |
143 | fPeakFinderUnit.InputStream(bunch1); | |
144 | while( (bunch2 = fPeakFinderUnit.OutputStream() )){ | |
145 | fChannelProcessor.InputStream(bunch2); | |
146 | while( (fragment = fChannelProcessor.OutputStream() )){ | |
147 | fChannelMerger.InputStream( fragment ); | |
148 | while( (candidate = fChannelMerger.OutputStream()) ){ | |
149 | fDivisionUnit.InputStream(candidate); | |
150 | while( (cluster = fDivisionUnit.OutputStream()) ){ | |
151 | if( cluster->fFlag==1 ){ | |
152 | if( outputSize32+AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize > maxOutputSize32 ){ // No space in the output buffer | |
153 | ret = -2; | |
154 | break; | |
155 | } | |
156 | AliHLTUInt32_t *co = &output[outputSize32]; | |
157 | int i=0; | |
158 | co[i++] = WriteBigEndian(cluster->fRowQ); | |
159 | co[i++] = WriteBigEndian(cluster->fQ); | |
160 | co[i++] = cluster->fP; | |
161 | co[i++] = cluster->fT; | |
162 | co[i++] = cluster->fP2; | |
163 | co[i++] = cluster->fT2; | |
164 | outputSize32+=AliHLTTPCHWCFData::fgkAliHLTTPCHWClusterSize; | |
165 | if( mcLabels && outputMC && outputMC->fCount < maxNMCLabels){ | |
166 | outputMC->fLabels[outputMC->fCount++] = cluster->fMC; | |
167 | } | |
c012881c | 168 | } |
97aca268 | 169 | else if( cluster->fFlag==2 ){ |
170 | if( outputSize32+1 > maxOutputSize32 ){ // No space in the output buffer | |
171 | ret = -2; | |
172 | break; | |
173 | } | |
174 | output[outputSize32++] = cluster->fRowQ; | |
c012881c | 175 | } |
c012881c | 176 | } |
177 | } | |
178 | } | |
179 | } | |
180 | } | |
181 | } | |
182 | return ret; | |
183 | } | |
184 | ||
185 | AliHLTUInt32_t AliHLTTPCHWCFEmulator::ReadBigEndian ( AliHLTUInt32_t word ) | |
186 | { | |
187 | // read the word written in big endian format (lowest byte first) | |
188 | ||
189 | const AliHLTUInt8_t *bytes = reinterpret_cast<const AliHLTUInt8_t *>( &word ); | |
190 | AliHLTUInt32_t i[4] = {bytes[0],bytes[1],bytes[2],bytes[3]}; | |
191 | ||
192 | return (i[3]<<24) | (i[2]<<16) | (i[1]<<8) | i[0]; | |
193 | } | |
194 | ||
195 | AliHLTUInt32_t AliHLTTPCHWCFEmulator::WriteBigEndian ( AliHLTUInt32_t word ) | |
196 | { | |
197 | // write the word in big endian format (least byte first) | |
198 | ||
199 | AliHLTUInt32_t ret = 0; | |
200 | AliHLTUInt8_t *bytes = reinterpret_cast<AliHLTUInt8_t *>( &ret ); | |
201 | bytes[0] = (word ) & 0xFF; | |
202 | bytes[1] = (word >> 8) & 0xFF; | |
203 | bytes[2] = (word >> 16) & 0xFF; | |
204 | bytes[3] = (word >> 24) & 0xFF; | |
205 | return ret; | |
206 | } | |
207 | ||
eb62889b | 208 | void AliHLTTPCHWCFEmulator::CreateConfiguration |
c012881c | 209 | ( |
210 | bool doDeconvTime, bool doDeconvPad, bool doFlowControl, | |
211 | bool doSinglePadSuppression, bool bypassMerger, | |
ee4d1bf0 | 212 | AliHLTUInt32_t clusterLowerLimit, AliHLTUInt32_t singleSeqLimit, |
97aca268 | 213 | AliHLTUInt32_t mergerDistance, bool useTimeBinWindow, AliHLTUInt32_t chargeFluctuation, |
eb62889b | 214 | AliHLTUInt32_t &configWord1, AliHLTUInt32_t &configWord2 |
c012881c | 215 | ) |
216 | { | |
217 | // static method to create configuration word | |
218 | ||
eb62889b | 219 | configWord1 = 0; |
220 | configWord2 = 0; | |
c012881c | 221 | |
eb62889b | 222 | configWord1 |= ( (AliHLTUInt32_t)doFlowControl & 0x1 ) << 29; |
223 | configWord1 |= ( (AliHLTUInt32_t)bypassMerger & 0x1 ) << 27; | |
224 | configWord1 |= ( (AliHLTUInt32_t)doSinglePadSuppression & 0x1 ) << 26; | |
225 | configWord1 |= ( (AliHLTUInt32_t)doDeconvPad & 0x1 ) << 25; | |
226 | configWord1 |= ( (AliHLTUInt32_t)doDeconvTime & 0x1 ) << 24; | |
227 | configWord1 |= ( (AliHLTUInt32_t)clusterLowerLimit & 0xFFFF )<<8; | |
228 | configWord1 |= ( (AliHLTUInt32_t)singleSeqLimit & 0xFF ); | |
c012881c | 229 | |
eb62889b | 230 | configWord2 |= ( (AliHLTUInt32_t)mergerDistance & 0xF ); |
97aca268 | 231 | configWord2 |= ( (AliHLTUInt32_t)chargeFluctuation & 0xF )<<4; |
232 | configWord2 |= ( (AliHLTUInt32_t)useTimeBinWindow & 0x1 )<<8; | |
c012881c | 233 | } |