]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSAltroChannelSelectorComponent.cxx
Updating CMake files
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSAltroChannelSelectorComponent.cxx
CommitLineData
8678cfc2 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: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTPHOSAltroChannelSelectorComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief A filter/selective readout component for TPC Altro data. */
23
24// see header file for class documentation
25// or
26// refer to README to build package
27// or
28// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30#include <cassert>
31#include "AliHLTPHOSAltroChannelSelectorComponent.h"
32#include "AliHLTTPCTransform.h"
33#include "AliHLTTPCDigitReaderRaw.h"
34#include "AliHLTTPCDefinitions.h"
35//#include "AliHLTTPCPadArray.h"
36//#include "AliHLTTPCPadArray.h"
37
38/** ROOT macro for the implementation of ROOT specific class methods */
39ClassImp(AliHLTPHOSAltroChannelSelectorComponent)
40
41AliHLTPHOSAltroChannelSelectorComponent::AliHLTPHOSAltroChannelSelectorComponent()
42 :
43 AliHLTProcessor(),
44 fRawreaderMode(0)
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
53AliHLTPHOSAltroChannelSelectorComponent::~AliHLTPHOSAltroChannelSelectorComponent()
54{
55 // see header file for class documentation
56}
57
58const char* AliHLTPHOSAltroChannelSelectorComponent::GetComponentID()
59{
60 // see header file for class documentation
61 return "AltroChannelSelector";
62}
63
64
65
66
67void AliHLTPHOSAltroChannelSelectorComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
68{
69 // see header file for class documentation
70 list.clear();
71 list.push_back(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC);
72 list.push_back(AliHLTTPCDefinitions::fgkActivePadsDataType);
73 list.push_back(kAliHLTDataTypeHwAddr16);
74}
75
76AliHLTComponentDataType AliHLTPHOSAltroChannelSelectorComponent::GetOutputDataType()
77{
78 // see header file for class documentation
79 return kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC;
80}
81
82void AliHLTPHOSAltroChannelSelectorComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
83{
84 // see header file for class documentation
85 constBase=0;
86 inputMultiplier=1.0;
87}
88
89AliHLTComponent* AliHLTPHOSAltroChannelSelectorComponent::Spawn()
90{
91 // see header file for class documentation
92 return new AliHLTPHOSAltroChannelSelectorComponent;
93}
94
95int AliHLTPHOSAltroChannelSelectorComponent::DoInit(int argc, const char** argv)
96{
97 int iResult=0;
98 TString argument="";
99 bool bMissingParam=0;
100 for (int i=0; i<argc && iResult>=0; i++) {
101 argument=argv[i];
102 if (argument.IsNull()) continue;
103
104 // -rawreadermode
105 if (argument.CompareTo("-rawreadermode")==0) {
106 if ((bMissingParam=(++i>=argc))) break;
107 int mode=AliHLTTPCDigitReaderRaw::DecodeMode(argv[i]);
108 if (mode<0) {
109 HLTError("invalid rawreadermode specifier '%s'", argv[i]);
110 iResult=-EINVAL;
111 } else {
112 fRawreaderMode=static_cast<unsigned>(mode);
113 // always use the reader in unsorted mode regardless of the
114 // argument
115 if (fRawreaderMode%2==0) fRawreaderMode++;
116 }
117 } else {
118 iResult=-EINVAL;
119 }
120 }
121
122 if (bMissingParam) {
123 HLTError("missing parameter for argument %s", argument.Data());
124 iResult=-EINVAL;
125 }
126
127
128 return iResult;
129
130
131}
132
133int AliHLTPHOSAltroChannelSelectorComponent::DoDeinit()
134{
135 // see header file for class documentation
136 return 0;
137}
138
139int AliHLTPHOSAltroChannelSelectorComponent::DoEvent(const AliHLTComponentEventData& evtData,
140 const AliHLTComponentBlockData* blocks,
141 AliHLTComponentTriggerData& /*trigData*/,
142 AliHLTUInt8_t* outputPtr,
143 AliHLTUInt32_t& size,
144 AliHLTComponentBlockDataList& outputBlocks )
145{
146 int iResult=0;
147 int blockno=0;
148 const AliHLTComponentBlockData* pDesc=NULL;
149
150 for (pDesc=GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); pDesc!=NULL; pDesc=GetNextInputBlock(), blockno++)
151 {
152 AliHLTUInt16_t* pActiveHwAddressArray=NULL;
153 int iArraySize=0;
154
155 for (int i=0; i<(int)evtData.fBlockCnt; i++ )
156 {
157 const AliHLTComponentBlockData* iter=NULL;
158
159 for (iter=GetFirstInputBlock(kAliHLTDataTypeHwAddr16); iter!=NULL; iter=GetNextInputBlock())
160 {
161 if (iter->fSpecification==pDesc->fSpecification)
162 {
163 pActiveHwAddressArray=reinterpret_cast<AliHLTUInt16_t*>(iter->fPtr);
164 iArraySize=iter->fSize/sizeof(AliHLTUInt16_t);
165 break;
166 }
167 }
168 }
169
170
171 /*
172 if (pActivePadsArray==NULL && pActiveHwAddressArray==NULL)
173 {
174 HLTWarning("no block of type %s or %s for specification 0x%08x available, data block unchanged",
175 DataType2Text(AliHLTTPCDefinitions::fgkActivePadsDataType).c_str(),
176 DataType2Text(kAliHLTDataTypeHwAddr16).c_str(),
177 pDesc->fSpecification);
178 // forward the whole block
179 outputBlocks.push_back(*pDesc);
180 continue;
181 }
182 */
183
184 AliHLTTPCDigitReaderRaw reader(fRawreaderMode);
185 HLTDebug("init reader %p size %d", pDesc->fPtr,pDesc->fSize);
186
187 int iSelected=0;
188 int iTotal=0;
189 AliHLTUInt32_t iOutputSize=0;
190 AliHLTUInt32_t iCapacity=size;
191
192 while (reader.NextAltroBlock()) {
193 iTotal++;
194 void* pChannel=NULL;
195 AliHLTUInt16_t hwAddress=~(AliHLTUInt16_t)0;
196 int channelSize=reader.GetAltroChannelRawData(pChannel, hwAddress);
197 int active=0;
198
199 // if (pActivePadsArray) {
200 // for (; active<iArraySize; active++) {
201 // if ((int)pActivePadsArray[active].fRow==reader.GetRow() &&
202 // (int)pActivePadsArray[active].fPad==reader.GetPad()) {
203 // break;
204 // }
205 // }
206 // } else {
207 // for (; active<iArraySize; active++) {
208 // if (pActiveHwAddressArray[active]==hwAddress) {
209 // break;
210 // }
211 // }
212 // }
213 // if (active>=iArraySize) {
214 // HLTDebug("ALTRO block Row %d, Pad %d discarded (inactive)", reader.GetRow(), reader.GetPad());
215 // continue;
216 // }
217
218 iSelected++;
219 // HLTDebug("ALTRO block hwAddress 0x%08x Row/Pad %d/%d selected (active), size %d", hwAddress, reader.GetRow(), reader.GetPad(), channelSize);
220
221 if (channelSize>0 && pChannel!=NULL) {
222 if (iOutputSize==0) {
223 // first add the RCU trailer
224 unsigned rcuTrailerLength=reader.GetRCUDataBlockLength();
225 AliHLTUInt8_t* pSrc=reinterpret_cast<AliHLTUInt8_t*>(pDesc->fPtr);
226 pSrc+=pDesc->fSize-rcuTrailerLength;
227 if ((iResult=CopyBlockToEnd(outputPtr, iCapacity, iOutputSize, pSrc, rcuTrailerLength))>=0) {
228 assert(iResult==rcuTrailerLength);
229 iOutputSize+=rcuTrailerLength;
230 } else {
231 HLTError("failed to write RCU trailer of length %d for block %d", rcuTrailerLength, blockno);
232 break;
233 }
234 }
235 }
236
237 if ((iResult=CopyBlockToEnd(outputPtr, iCapacity, iOutputSize, pChannel, channelSize))>=0)
238 {
239 assert(iResult==channelSize);
240 iOutputSize+=channelSize;
241 } else
242 {
243 HLTError("failed to write ALTRO channel of length %d for block %d", channelSize, blockno);
244 break;
245 }
246 }
247
248
249 if (iResult>=0)
250 {
251 // write the common data header
252 int cdhSize=reader.GetCommonDataHeaderSize();
253 if ((iResult=CopyBlockToEnd(outputPtr, iCapacity, iOutputSize, pDesc->fPtr, cdhSize))>=0)
254 {
255 assert(iResult==cdhSize);
256 iOutputSize+=cdhSize;
257 // set new length of the data block
258 AliHLTUInt32_t* pCdhSize=reinterpret_cast<AliHLTUInt32_t*>(outputPtr+iCapacity-iOutputSize+1);
259 *pCdhSize=iOutputSize;
260 // insert block descriptor
261 AliHLTComponentBlockData bd;
262 FillBlockData(bd);
263 bd.fOffset=iCapacity-iOutputSize;
264 bd.fSize=iOutputSize;
265 bd.fDataType=pDesc->fDataType;
266 bd.fSpecification=pDesc->fSpecification;
267 outputBlocks.push_back(bd);
268 iCapacity-=iOutputSize;
269 } else
270 {
271 HLTError("failed to write CDH of length %d for block %d", cdhSize, blockno);
272 break;
273 }
274 }
275 HLTInfo("data block %d (0x%08x): selected %d out of %d ALTRO channels", blockno, pDesc->fSpecification, iSelected, iTotal);
276 }
277
278 if (iResult<0)
279 {
280 outputBlocks.clear();
281 }
282 // !!! do not change the size since the output buffer is filled from the end !!!
283 return iResult;
284}
285
286
287int
288AliHLTPHOSAltroChannelSelectorComponent::CopyBlockToEnd(AliHLTUInt8_t* pTgt, unsigned capacity, unsigned position, void* pSrc, unsigned size)
289{
290 int iResult=0;
291 if (pTgt==NULL || pSrc==NULL) return -EINVAL;
292 if (capacity-position<size) return -ENOSPC;
293
294 memcpy(pTgt+(capacity-position-size), pSrc, size);
295 iResult=size;
296
297 return iResult;
298}
299
300
301