3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file testAliHLT_C_Component_WrapperInterface.C
20 @author Matthias Richter
22 @brief Test program for the external wrapper interface
25 #include "AliHLTProcessor.h"
26 #include "AliHLTModuleAgent.h"
27 #include "AliHLT_C_Component_WrapperInterface.h"
30 const char* gDummy="dummy";
31 AliHLTUInt32_t gRunNo=kAliHLTVoidRunNo;
32 const char* gChainId="<void>";
33 AliHLTComponentDataType gInputDt=kAliHLTVoidDataType;
35 class TestProcessor : public AliHLTProcessor
41 const char* GetComponentID() {return "TestProcessor";}
43 void GetInputDataTypes( vector<AliHLTComponentDataType>& list)
44 {list.push_back(kAliHLTAnyDataType);}
46 AliHLTComponentDataType GetOutputDataType() {return kAliHLTAnyDataType;}
48 void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
49 {constBase=100; inputMultiplier=2.0;}
51 AliHLTComponent* Spawn() {return new TestProcessor;}
53 int DoInit( int argc, const char** argv ) {
57 gChainId=GetChainId();
64 int DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) {
66 HLTInfo("processing event");
67 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
69 pBlock=GetNextInputBlock()) {
70 gInputDt=pBlock->fDataType;
71 AliHLTComponentDataType dt;
72 SetDataType(dt, "-OUTPUT-", "MYCO");
73 iResult=PushBack(pBlock->fPtr, pBlock->fSize/2, dt, ~pBlock->fSpecification);
80 TestProcessor::TestProcessor()
85 TestProcessor::~TestProcessor()
89 class TestAgent : public AliHLTModuleAgent
92 TestAgent() : AliHLTModuleAgent("TEST") {}
95 int RegisterComponents(AliHLTComponentHandler* pHandler) const
97 pHandler->AddComponent(new TestProcessor);
105 int Logging( void* /*param*/,
106 AliHLTComponentLogSeverity severity,
111 cout << "Logging: "<< severity << " " << origin << " " << keyword << " " << message << endl;
115 void* AllocMemory( void* param, unsigned long size )
117 if (param!=&gDummy) {
118 cerr << "AllocMemoryFunc callback with wrong parameter " << endl;
121 if (size==0) return NULL;
122 return new AliHLTUInt8_t[size];
125 const char* GetComponentDescription(void* param)
127 if (param!=&gDummy) {
128 cerr << "GetComponentDescription callback with wrong parameter " << endl;
131 return "-chainid=test";
134 int main(int /*argc*/, const char** /*argv*/)
137 AliHLTComponentEnvironment environment;
138 memset(&environment, 0, sizeof(environment));
139 environment.fStructSize=sizeof(environment);
140 environment.fAllocMemoryFunc=AllocMemory;
141 environment.fLoggingFunc=Logging;
142 //environment.fGetComponentDescription=GetComponentDescription;
143 if ((iResult=AliHLT_C_Component_InitSystem( &environment ))<0) {
144 cerr << "error: AliHLT_C_Component_InitSystem failed with " << iResult << endl;
148 if ((iResult=AliHLT_C_Component_LoadLibrary("libAliHLTUtil.so"))<0) {
149 cerr << "error: AliHLT_C_Component_LoadLibrary failed with " << iResult << endl;
154 memset(&desc, 0, sizeof(desc));
155 desc.fStructSize=sizeof(desc);
157 if ((iResult=AliHLT_C_SetRunDescription(&desc, "dummy run"))<0) {
158 cerr << "error: AliHLT_C_Component_SetRunDescription failed with " << iResult << endl;
162 AliHLTComponentHandle handle;
163 if ((iResult=AliHLT_C_CreateComponent("TestProcessor", &gDummy, 0, NULL, &handle ))<0) {
164 cerr << "error: AliHLT_C_Component_CreateComponent failed with " << iResult << endl;
168 if (gRunNo!=0xbeef) {
169 cerr << "error: propagation of run number failed " << hex << gRunNo << " vs. 0xbeef" << endl;
173 // can be used in the new interface again
174 // if (strcmp(gChainId, "test")) {
175 // cerr << "propagation of chain id failed: '" << gChainId << "' vs. test" << endl;
180 const char* inputData="some data to be copied";
181 AliHLTComponentBlockData inputBlock;
182 memset(&inputBlock, 0, sizeof(inputBlock));
183 inputBlock.fStructSize=sizeof(inputBlock);
184 inputBlock.fPtr=(void*)inputData;
185 inputBlock.fSize=strlen(inputData);
186 inputBlock.fDataType=kAliHLTDataTypeDDLRaw;
187 inputBlock.fSpecification=0xdead;
189 AliHLTComponentEventData evtData;
190 memset(&evtData, 0, sizeof(evtData));
191 evtData.fStructSize=sizeof(evtData);
194 AliHLTComponentTriggerData trigData;
195 memset(&trigData, 0, sizeof(trigData));
196 trigData.fStructSize=sizeof(trigData);
198 AliHLTUInt8_t outputPtr[100];
199 AliHLTUInt32_t size=sizeof(outputPtr);
201 AliHLTUInt32_t outputBlockCnt=0;
202 AliHLTComponentBlockData* outputBlocks=NULL;
203 AliHLTComponentEventDoneData* edd=NULL;
205 if ((iResult=AliHLT_C_ProcessEvent( handle, &evtData, &inputBlock, &trigData, outputPtr,
206 &size, &outputBlockCnt, &outputBlocks, &edd ))<0) {
207 cerr << "error: AliHLT_C_Component_ProcessEvent failed with " << iResult << endl;
211 if (outputBlockCnt<2) {
212 cerr << "error: mismatch in output block count, expecting >2, got " << outputBlockCnt << endl;
216 if (outputBlocks==NULL) {
217 cerr << "error: did not get output block array " << endl;
221 AliHLTComponentDataType outdt;
222 AliHLTComponent::SetDataType(outdt, "-OUTPUT-", "MYCO");
223 bool bHaveForwarded=false;
224 bool bHaveCopied=false;
225 for (unsigned int i=0; i<outputBlockCnt; i++) {
226 if (outputBlocks[i].fDataType==kAliHLTDataTypeDDLRaw) {
227 if (outputBlocks[i].fPtr!=inputData ||
228 outputBlocks[i].fSize!=strlen(inputData)) {
229 cerr << "error: failed comparing forwarded input block" << endl;
233 } else if (outputBlocks[i].fDataType==outdt) {
234 if (outputBlocks[i].fSize!=strlen(inputData)/2) {
235 cerr << "error: wrong size of copied block" << endl;
238 if (memcmp(inputData, outputPtr+outputBlocks[i].fOffset, outputBlocks[i].fSize)) {
239 cerr << "error: failed comparing copied block" << endl;
246 if (!bHaveForwarded) {
247 cerr << "error: did not get forwarded data block" << endl;
252 cerr << "error: did not get copied data block" << endl;
256 AliHLT_C_DestroyComponent(handle);
258 if ((iResult=AliHLT_C_Component_DeinitSystem( ))<0) {
259 cerr << "AliHLT_C_Component_DeinitSystem failed with " << iResult << endl;