]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/test/testAliHLT_C_Component_WrapperInterface.C
Adding the new detector MFT (Antonio Uras)
[u/mrichter/AliRoot.git] / HLT / BASE / test / testAliHLT_C_Component_WrapperInterface.C
CommitLineData
273a2e2d 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 testAliHLT_C_Component_WrapperInterface.C
20 @author Matthias Richter
21 @date
8bc1d5fb 22 @brief Test program for the old wrapper interface, frozen since Jul 08
273a2e2d 23 */
24
25#include "AliHLTProcessor.h"
26#include "AliHLTModuleAgent.h"
27#include "AliHLT_C_Component_WrapperInterface.h"
28
29
9a0ef890 30const char* gDummy="dummy";
273a2e2d 31AliHLTUInt32_t gRunNo=kAliHLTVoidRunNo;
9a0ef890 32const char* gChainId="<void>";
3de26b74 33AliHLTComponentDataType gInputDt=kAliHLTVoidDataType;
273a2e2d 34
35class TestProcessor : public AliHLTProcessor
36{
37public:
38 TestProcessor();
39 ~TestProcessor();
40
41 const char* GetComponentID() {return "TestProcessor";}
42
43 void GetInputDataTypes( vector<AliHLTComponentDataType>& list)
44 {list.push_back(kAliHLTAnyDataType);}
45
46 AliHLTComponentDataType GetOutputDataType() {return kAliHLTAnyDataType;}
47
48 void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
49 {constBase=100; inputMultiplier=2.0;}
50
51 AliHLTComponent* Spawn() {return new TestProcessor;}
52private:
53 int DoInit( int argc, const char** argv ) {
63946d82 54 if (fState!=kCreated) {
55 HLTError("wrong state (%d): component already initialized", fState);
56 return -EBUSY;
57 }
58
273a2e2d 59 if (argc>0 && argv) {
60 }
61 gRunNo=GetRunNo();
9a0ef890 62 gChainId=GetChainId();
63946d82 63
64 fState=kInitialized;
273a2e2d 65 return 0;
66 }
67 int DoDeinit() {
63946d82 68 if (fState!=kInitialized) {
69 HLTError("wrong state (%d): required %d kInitialized", fState, kInitialized);
70 return -ENODEV;
71 }
72
273a2e2d 73 return 0;
74 }
75
3de26b74 76 int DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) {
77 int iResult=0;
63946d82 78 if (fState!=kInitialized) {
79 HLTError("wrong state (%d): component not initialized", fState);
80 return -ENODEV;
81 }
82
3de26b74 83 HLTInfo("processing event");
84 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
85 pBlock!=NULL;
86 pBlock=GetNextInputBlock()) {
87 gInputDt=pBlock->fDataType;
88 AliHLTComponentDataType dt;
89 SetDataType(dt, "-OUTPUT-", "MYCO");
90 iResult=PushBack(pBlock->fPtr, pBlock->fSize/2, dt, ~pBlock->fSpecification);
91 Forward();
92 }
63946d82 93
3de26b74 94 return iResult;
273a2e2d 95 }
63946d82 96
97 enum {
98 kCreated =0,
99 kInitialized,
100 kProcessing,
101 };
102
103 int fState; //!transient
273a2e2d 104};
105
106TestProcessor::TestProcessor()
63946d82 107 :
108 AliHLTProcessor(),
109 fState(kCreated)
110
273a2e2d 111{
112}
113
114TestProcessor::~TestProcessor()
115{
116}
117
118class TestAgent : public AliHLTModuleAgent
119{
120public:
121 TestAgent() : AliHLTModuleAgent("TEST") {}
122 ~TestAgent() {}
123
124 int RegisterComponents(AliHLTComponentHandler* pHandler) const
125 {
126 pHandler->AddComponent(new TestProcessor);
127 return 0;
128 }
129
130};
131
132TestAgent gAgent;
133
3de26b74 134int Logging( void* /*param*/,
9a0ef890 135 AliHLTComponentLogSeverity severity,
136 const char* origin,
137 const char* keyword,
138 const char* message)
139{
140 cout << "Logging: "<< severity << " " << origin << " " << keyword << " " << message << endl;
141 return 0;
142}
143
3de26b74 144void* AllocMemory( void* param, unsigned long size )
145{
146 if (param!=&gDummy) {
147 cerr << "AllocMemoryFunc callback with wrong parameter " << endl;
148 abort();
149 }
150 if (size==0) return NULL;
151 return new AliHLTUInt8_t[size];
152}
153
9a0ef890 154const char* GetComponentDescription(void* param)
155{
156 if (param!=&gDummy) {
157 cerr << "GetComponentDescription callback with wrong parameter " << endl;
158 abort();
159 }
160 return "-chainid=test";
161}
162
273a2e2d 163int main(int /*argc*/, const char** /*argv*/)
164{
165 int iResult=0;
166 AliHLTComponentEnvironment environment;
167 memset(&environment, 0, sizeof(environment));
168 environment.fStructSize=sizeof(environment);
3de26b74 169 environment.fAllocMemoryFunc=AllocMemory;
9a0ef890 170 environment.fLoggingFunc=Logging;
3de26b74 171 //environment.fGetComponentDescription=GetComponentDescription;
273a2e2d 172 if ((iResult=AliHLT_C_Component_InitSystem( &environment ))<0) {
3de26b74 173 cerr << "error: AliHLT_C_Component_InitSystem failed with " << iResult << endl;
273a2e2d 174 return iResult;
175 }
176
8bc1d5fb 177 if ((iResult=AliHLT_C_Component_LoadLibrary("../util/.libs/libAliHLTUtil.so"))<0) {
3de26b74 178 cerr << "error: AliHLT_C_Component_LoadLibrary failed with " << iResult << endl;
273a2e2d 179 return iResult;
180 }
181
182 AliHLTRunDesc desc;
183 memset(&desc, 0, sizeof(desc));
184 desc.fStructSize=sizeof(desc);
185 desc.fRunNo=0xbeef;
186 if ((iResult=AliHLT_C_SetRunDescription(&desc, "dummy run"))<0) {
3de26b74 187 cerr << "error: AliHLT_C_Component_SetRunDescription failed with " << iResult << endl;
273a2e2d 188 return iResult;
189 }
190
191 AliHLTComponentHandle handle;
9a0ef890 192 if ((iResult=AliHLT_C_CreateComponent("TestProcessor", &gDummy, 0, NULL, &handle ))<0) {
3de26b74 193 cerr << "error: AliHLT_C_Component_CreateComponent failed with " << iResult << endl;
273a2e2d 194 return iResult;
195 }
196
197 if (gRunNo!=0xbeef) {
3de26b74 198 cerr << "error: propagation of run number failed " << hex << gRunNo << " vs. 0xbeef" << endl;
199 return -1;
200 }
201
202 // can be used in the new interface again
203// if (strcmp(gChainId, "test")) {
204// cerr << "propagation of chain id failed: '" << gChainId << "' vs. test" << endl;
205// return -1;
206// }
207
208
209 const char* inputData="some data to be copied";
210 AliHLTComponentBlockData inputBlock;
211 memset(&inputBlock, 0, sizeof(inputBlock));
212 inputBlock.fStructSize=sizeof(inputBlock);
213 inputBlock.fPtr=(void*)inputData;
214 inputBlock.fSize=strlen(inputData);
215 inputBlock.fDataType=kAliHLTDataTypeDDLRaw;
216 inputBlock.fSpecification=0xdead;
217
218 AliHLTComponentEventData evtData;
219 memset(&evtData, 0, sizeof(evtData));
220 evtData.fStructSize=sizeof(evtData);
221 evtData.fBlockCnt=1;
222
223 AliHLTComponentTriggerData trigData;
224 memset(&trigData, 0, sizeof(trigData));
225 trigData.fStructSize=sizeof(trigData);
226
227 AliHLTUInt8_t outputPtr[100];
228 AliHLTUInt32_t size=sizeof(outputPtr);
229
230 AliHLTUInt32_t outputBlockCnt=0;
231 AliHLTComponentBlockData* outputBlocks=NULL;
232 AliHLTComponentEventDoneData* edd=NULL;
233
234 if ((iResult=AliHLT_C_ProcessEvent( handle, &evtData, &inputBlock, &trigData, outputPtr,
235 &size, &outputBlockCnt, &outputBlocks, &edd ))<0) {
236 cerr << "error: AliHLT_C_Component_ProcessEvent failed with " << iResult << endl;
237 return iResult;
238 }
239
240 if (outputBlockCnt<2) {
241 cerr << "error: mismatch in output block count, expecting >2, got " << outputBlockCnt << endl;
242 return -1;
243 }
244
245 if (outputBlocks==NULL) {
246 cerr << "error: did not get output block array " << endl;
247 return -1;
248 }
249
250 AliHLTComponentDataType outdt;
251 AliHLTComponent::SetDataType(outdt, "-OUTPUT-", "MYCO");
252 bool bHaveForwarded=false;
253 bool bHaveCopied=false;
254 for (unsigned int i=0; i<outputBlockCnt; i++) {
255 if (outputBlocks[i].fDataType==kAliHLTDataTypeDDLRaw) {
256 if (outputBlocks[i].fPtr!=inputData ||
257 outputBlocks[i].fSize!=strlen(inputData)) {
258 cerr << "error: failed comparing forwarded input block" << endl;
259 return -1;
260 }
261 bHaveForwarded=true;
262 } else if (outputBlocks[i].fDataType==outdt) {
263 if (outputBlocks[i].fSize!=strlen(inputData)/2) {
264 cerr << "error: wrong size of copied block" << endl;
265 return -1;
266 }
267 if (memcmp(inputData, outputPtr+outputBlocks[i].fOffset, outputBlocks[i].fSize)) {
268 cerr << "error: failed comparing copied block" << endl;
269 return -1;
270 }
271 bHaveCopied=true;
272 }
273 }
274
275 if (!bHaveForwarded) {
276 cerr << "error: did not get forwarded data block" << endl;
273a2e2d 277 return -1;
278 }
279
3de26b74 280 if (!bHaveCopied) {
281 cerr << "error: did not get copied data block" << endl;
9a0ef890 282 return -1;
283 }
284
3de26b74 285 AliHLT_C_DestroyComponent(handle);
286
273a2e2d 287 if ((iResult=AliHLT_C_Component_DeinitSystem( ))<0) {
288 cerr << "AliHLT_C_Component_DeinitSystem failed with " << iResult << endl;
289 return iResult;
290 }
291
292 return 0;
293}