]>
Commit | Line | Data |
---|---|---|
881c4032 | 1 | // $Id$ |
2 | ||
3 | //************************************************************************** | |
4 | //* This file is property of and copyright by the ALICE HLT Project * | |
5 | //* ALICE Experiment at CERN, All rights reserved. * | |
6 | //* * | |
7 | //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> * | |
8 | //* Oystein Djuvsland | |
9 | //* Matthias Richter * | |
10 | //* for The ALICE HLT Project. * | |
11 | //* * | |
12 | //* Permission to use, copy, modify and distribute this software and its * | |
13 | //* documentation strictly for non-commercial purposes is hereby granted * | |
14 | //* without fee, provided that the above copyright notice appears in all * | |
15 | //* copies and that both the copyright notice and this permission notice * | |
16 | //* appear in the supporting documentation. The authors make no claims * | |
17 | //* about the suitability of this software for any purpose. It is * | |
18 | //* provided "as is" without express or implied warranty. * | |
19 | //************************************************************************** | |
20 | ||
21 | /** @file AliHLTAltroTimebinAverageComponent.cxx | |
22 | @author Kalliopi Kanaki, Oystein Djuvsland, Matthias Richter | |
23 | @date 26.08.2008 | |
24 | @brief | |
25 | */ | |
26 | ||
27 | #if __GNUC__>= 3 | |
28 | using namespace std; | |
29 | #endif | |
30 | #include "AliHLTAltroTimebinAverageComponent.h" | |
31 | #include "AliAltroDecoder.h" | |
32 | #include "AliAltroData.h" | |
33 | #include "AliAltroBunch.h" | |
34 | #include "AliHLTAltroEncoder.h" | |
35 | #include "AliRawDataHeader.h" | |
36 | ||
37 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
38 | ClassImp(AliHLTAltroTimebinAverageComponent) | |
39 | ||
40 | AliHLTAltroTimebinAverageComponent::AliHLTAltroTimebinAverageComponent() | |
41 | : | |
42 | fStartTimeBin(0), | |
43 | fEndTimeBin(1024), | |
44 | fNTimeBins(1024) | |
45 | { | |
46 | // see header file for class documentation | |
47 | // or | |
48 | // refer to README to build package | |
49 | // or | |
50 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
51 | } | |
52 | ||
53 | AliHLTAltroTimebinAverageComponent::~AliHLTAltroTimebinAverageComponent() | |
54 | { | |
55 | // see header file for class documentation | |
56 | } | |
57 | ||
58 | // Public functions to implement AliHLTComponent's interface. | |
59 | // These functions are required for the registration process | |
60 | ||
61 | const char* AliHLTAltroTimebinAverageComponent::GetComponentID() | |
62 | { | |
63 | // see header file for class documentation | |
64 | return "AltroTimebinAverager"; | |
65 | } | |
66 | ||
67 | void AliHLTAltroTimebinAverageComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
68 | { | |
69 | // see header file for class documentation | |
70 | list.clear(); | |
71 | list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC ); | |
72 | list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginPHOS ); | |
73 | } | |
74 | ||
75 | AliHLTComponentDataType AliHLTAltroTimebinAverageComponent::GetOutputDataType() | |
76 | { | |
77 | // see header file for class documentation | |
78 | return kAliHLTDataTypeDDLRaw; | |
79 | } | |
80 | ||
81 | int AliHLTAltroTimebinAverageComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) | |
82 | { | |
83 | // see header file for class documentation | |
84 | tgtList.clear(); | |
85 | tgtList.push_back(kAliHLTDataTypeDDLRaw); | |
86 | return tgtList.size(); | |
87 | } | |
88 | ||
89 | void AliHLTAltroTimebinAverageComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
90 | { | |
91 | // see header file for class documentation | |
92 | constBase=0; | |
93 | inputMultiplier=1.0; | |
94 | } | |
95 | ||
96 | AliHLTComponent* AliHLTAltroTimebinAverageComponent::Spawn() | |
97 | { | |
98 | // see header file for class documentation | |
99 | return new AliHLTAltroTimebinAverageComponent; | |
100 | } | |
101 | ||
102 | int AliHLTAltroTimebinAverageComponent::DoInit( int argc, const char** argv ) | |
103 | { | |
104 | // see header file for class documentation | |
105 | ||
106 | Int_t i = 0; | |
107 | Char_t* cpErr; | |
108 | ||
109 | while ( i < argc ) { | |
110 | ||
111 | // -- number of timebins | |
112 | if ( !strcmp( argv[i], "ntimebins" ) ) { | |
113 | fNTimeBins = strtoul( argv[i+1], &cpErr ,0); | |
114 | if ( *cpErr ) { | |
115 | HLTError("Cannot convert ntimebins specifier '%s'.", argv[i+1]); | |
116 | return EINVAL; | |
117 | } | |
118 | i+=2; | |
119 | continue; | |
120 | } | |
121 | ||
122 | // -- first timebin | |
123 | if ( !strcmp( argv[i], "start-timebin" ) ) { | |
124 | fStartTimeBin = strtoul( argv[i+1], &cpErr ,0); | |
125 | if ( *cpErr ) { | |
126 | HLTError("Cannot convert start-timebin specifier '%s'.", argv[i+1]); | |
127 | return EINVAL; | |
128 | } | |
129 | i+=2; | |
130 | continue; | |
131 | } | |
132 | ||
133 | // -- last timebin | |
134 | if ( !strcmp( argv[i], "end-timebin" ) ) { | |
135 | if(strtoul( argv[i+1], &cpErr ,0)<=1024){ | |
136 | fEndTimeBin = strtoul( argv[i+1], &cpErr ,0); | |
137 | } | |
138 | if ( *cpErr ) { | |
139 | HLTError("Cannot convert end-timebin specifier '%s'.", argv[i+1]); | |
140 | return EINVAL; | |
141 | } | |
142 | i+=2; | |
143 | continue; | |
144 | } | |
145 | ||
146 | HLTError("Unknown option '%s'", argv[i]); | |
147 | return -EINVAL; | |
148 | ||
149 | } | |
150 | ||
151 | return 0; | |
152 | } | |
153 | ||
154 | int AliHLTAltroTimebinAverageComponent::DoDeinit() | |
155 | { | |
156 | // see header file for class documentation | |
157 | return 0; | |
158 | } | |
159 | ||
160 | int AliHLTAltroTimebinAverageComponent::DoEvent( const AliHLTComponentEventData& evtData, | |
161 | const AliHLTComponentBlockData* blocks, | |
162 | AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, | |
163 | AliHLTUInt32_t& size, | |
164 | vector<AliHLTComponentBlockData>& outputBlocks ) | |
165 | { | |
166 | // see header file for class documentation | |
167 | int iResult=0; | |
168 | AliHLTUInt32_t capacity=size; | |
169 | size=0; | |
170 | AliHLTUInt32_t offset=0; | |
171 | ||
172 | const AliHLTComponentBlockData* iter = NULL; | |
173 | unsigned long ndx; | |
174 | ||
175 | AliAltroDecoder* decoder=NULL; | |
176 | AliHLTAltroEncoder* altroEncoder=NULL; | |
177 | ||
178 | for(ndx = 0; ndx < evtData.fBlockCnt; ndx++) { | |
179 | iter = blocks+ndx; | |
180 | ||
181 | if ( iter->fDataType != kAliHLTDataTypeDDLRaw) { | |
182 | continue; | |
183 | } | |
184 | ||
185 | if (decoder) delete decoder; | |
186 | decoder=new AliAltroDecoder; | |
187 | if (!decoder) { | |
188 | iResult=-ENOMEM; | |
189 | break; | |
190 | } | |
191 | ||
192 | if (altroEncoder) delete altroEncoder; | |
193 | ||
194 | int localResult=0; | |
195 | if ((localResult=decoder->SetMemory((UChar_t*)iter->fPtr,iter->fSize))<0) { | |
196 | HLTWarning("can not set up AltroDecoder for data block %s 0x%08x: error %d, skipping data block", | |
197 | DataType2Text(iter->fDataType).c_str(), iter->fSpecification, localResult); | |
198 | continue; | |
199 | } | |
200 | ||
201 | if (!decoder->Decode()) { | |
202 | HLTWarning("can not decode data block %s 0x%08x: skipping data block", | |
203 | DataType2Text(iter->fDataType).c_str(), iter->fSpecification); | |
204 | continue; | |
205 | } | |
206 | ||
207 | UChar_t *RCUTrailer=NULL; | |
208 | Int_t RCUTrailerSize=decoder->GetRCUTrailerSize(); | |
209 | if (RCUTrailerSize<=0 || !decoder->GetRCUTrailerData(RCUTrailer) || RCUTrailer==NULL) { | |
210 | HLTWarning("can not find RCU trailer for data block %s 0x%08x: skipping data block", | |
211 | DataType2Text(iter->fDataType).c_str(), iter->fSpecification); | |
212 | continue; | |
213 | } | |
214 | ||
215 | AliAltroData altrochannel; | |
216 | while (iResult>=0 && decoder->NextChannel(&altrochannel) && iResult>=0) { | |
217 | int hwadd=altrochannel.GetHadd(); | |
218 | ||
219 | AliAltroBunch altrobunch; | |
220 | while (iResult>=0 && altrochannel.NextBunch(&altrobunch) && iResult>=0) { | |
221 | int bunchLength=altrobunch.GetBunchSize(); | |
222 | int bunchEndTime=altrobunch.GetEndTimeBin(); | |
223 | int time=bunchEndTime-bunchLength+1; | |
224 | const UInt_t* bunchData=altrobunch.GetData(); | |
225 | for (int bin=bunchLength && iResult>=0; bin>0; ) { | |
226 | bin--; | |
227 | if(bunchData[bin]>0){// disregarding 0 data. | |
228 | ||
229 | if(time+bin>=fStartTimeBin && time+bin<=fEndTimeBin){ | |
230 | if (!altroEncoder) { | |
231 | // set up the encoder | |
232 | altroEncoder=new AliHLTAltroEncoder; | |
233 | if (!altroEncoder) { | |
234 | iResult=-ENOMEM; | |
235 | break; | |
236 | } | |
237 | altroEncoder->SetBuffer(outputPtr+offset,capacity-offset); | |
238 | AliRawDataHeader cdh; | |
239 | altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader)); | |
240 | ||
241 | altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize); | |
242 | } | |
243 | ||
244 | AliHLTUInt16_t signal=bunchData[bin]; | |
245 | if (bin-1>=0) signal+=bunchData[bin-1]; | |
246 | altroEncoder->AddSignal((time+bin)/2,signal/2); | |
247 | bin--; | |
248 | } // end if between start and end time bin | |
249 | } // end if bunchData[i]>0 | |
250 | } // for loop | |
251 | } //while loop over bunches | |
252 | if (altroEncoder) { | |
253 | altroEncoder->SetChannel(hwadd); | |
254 | } | |
255 | } // while loop over channels | |
256 | ||
257 | if (altroEncoder) { | |
258 | int sizeOfData=altroEncoder->SetLength(); | |
259 | ||
260 | if (sizeOfData<0) { | |
261 | HLTError("data encoding failed"); | |
262 | return sizeOfData; | |
263 | } | |
264 | if(sizeOfData>(int)capacity){ | |
265 | HLTWarning("Buffer too small to add the altrodata: %d of %d byte(s) already used", sizeOfData, size); | |
266 | return -ENOSPC; | |
267 | } | |
268 | ||
269 | AliHLTComponentBlockData bd; | |
270 | FillBlockData( bd ); | |
271 | bd.fOffset = offset; | |
272 | bd.fSize = sizeOfData; | |
273 | bd.fDataType = iter->fDataType; | |
274 | bd.fSpecification = iter->fSpecification; | |
275 | outputBlocks.push_back( bd ); | |
276 | ||
277 | offset+=bd.fSize; | |
278 | } | |
279 | ||
280 | } // while over data blocks | |
281 | ||
282 | if (iResult>=0) size=offset; | |
283 | return iResult; | |
284 | } | |
285 |