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 old wrapper interface, frozen since Jul 08
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 ) {
54 if (fState!=kCreated) {
55 HLTError("wrong state (%d): component already initialized", fState);
62 gChainId=GetChainId();
68 if (fState!=kInitialized) {
69 HLTError("wrong state (%d): required %d kInitialized", fState, kInitialized);
76 int DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) {
78 if (fState!=kInitialized) {
79 HLTError("wrong state (%d): component not initialized", fState);
83 HLTInfo("processing event");
84 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
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);
103 int fState; //!transient
106 TestProcessor::TestProcessor()
114 TestProcessor::~TestProcessor()
118 class TestAgent : public AliHLTModuleAgent
121 TestAgent() : AliHLTModuleAgent("TEST") {}
124 int RegisterComponents(AliHLTComponentHandler* pHandler) const
126 pHandler->AddComponent(new TestProcessor);
134 int Logging( void* /*param*/,
135 AliHLTComponentLogSeverity severity,
140 cout << "Logging: "<< severity << " " << origin << " " << keyword << " " << message << endl;
144 void* AllocMemory( void* param, unsigned long size )
146 if (param!=&gDummy) {
147 cerr << "AllocMemoryFunc callback with wrong parameter " << endl;
150 if (size==0) return NULL;
151 return new AliHLTUInt8_t[size];
154 const char* GetComponentDescription(void* param)
156 if (param!=&gDummy) {
157 cerr << "GetComponentDescription callback with wrong parameter " << endl;
160 return "-chainid=test";
163 int main(int /*argc*/, const char** /*argv*/)
166 AliHLTComponentEnvironment environment;
167 memset(&environment, 0, sizeof(environment));
168 environment.fStructSize=sizeof(environment);
169 environment.fAllocMemoryFunc=AllocMemory;
170 environment.fLoggingFunc=Logging;
171 //environment.fGetComponentDescription=GetComponentDescription;
172 if ((iResult=AliHLT_C_Component_InitSystem( &environment ))<0) {
173 cerr << "error: AliHLT_C_Component_InitSystem failed with " << iResult << endl;
177 if ((iResult=AliHLT_C_Component_LoadLibrary("../util/.libs/libAliHLTUtil.so"))<0) {
178 cerr << "error: AliHLT_C_Component_LoadLibrary failed with " << iResult << endl;
183 memset(&desc, 0, sizeof(desc));
184 desc.fStructSize=sizeof(desc);
186 if ((iResult=AliHLT_C_SetRunDescription(&desc, "dummy run"))<0) {
187 cerr << "error: AliHLT_C_Component_SetRunDescription failed with " << iResult << endl;
191 AliHLTComponentHandle handle;
192 if ((iResult=AliHLT_C_CreateComponent("TestProcessor", &gDummy, 0, NULL, &handle ))<0) {
193 cerr << "error: AliHLT_C_Component_CreateComponent failed with " << iResult << endl;
197 if (gRunNo!=0xbeef) {
198 cerr << "error: propagation of run number failed " << hex << gRunNo << " vs. 0xbeef" << endl;
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;
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;
218 AliHLTComponentEventData evtData;
219 memset(&evtData, 0, sizeof(evtData));
220 evtData.fStructSize=sizeof(evtData);
223 AliHLTComponentTriggerData trigData;
224 memset(&trigData, 0, sizeof(trigData));
225 trigData.fStructSize=sizeof(trigData);
227 AliHLTUInt8_t outputPtr[100];
228 AliHLTUInt32_t size=sizeof(outputPtr);
230 AliHLTUInt32_t outputBlockCnt=0;
231 AliHLTComponentBlockData* outputBlocks=NULL;
232 AliHLTComponentEventDoneData* edd=NULL;
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;
240 if (outputBlockCnt<2) {
241 cerr << "error: mismatch in output block count, expecting >2, got " << outputBlockCnt << endl;
245 if (outputBlocks==NULL) {
246 cerr << "error: did not get output block array " << endl;
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;
262 } else if (outputBlocks[i].fDataType==outdt) {
263 if (outputBlocks[i].fSize!=strlen(inputData)/2) {
264 cerr << "error: wrong size of copied block" << endl;
267 if (memcmp(inputData, outputPtr+outputBlocks[i].fOffset, outputBlocks[i].fSize)) {
268 cerr << "error: failed comparing copied block" << endl;
275 if (!bHaveForwarded) {
276 cerr << "error: did not get forwarded data block" << endl;
281 cerr << "error: did not get copied data block" << endl;
285 AliHLT_C_DestroyComponent(handle);
287 if ((iResult=AliHLT_C_Component_DeinitSystem( ))<0) {
288 cerr << "AliHLT_C_Component_DeinitSystem failed with " << iResult << endl;