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 testAliHLTExternalInterface.C
20 @author Matthias Richter
22 @brief Test program for the external wrapper interface
25 #include "AliHLTProcessor.h"
26 #include "AliHLTModuleAgent.h"
27 #include "AliHLTExternalInterface.h"
31 const char* gDummy="dummy";
32 AliHLTUInt32_t gRunNo=kAliHLTVoidRunNo;
33 const char* gChainId="<void>";
34 AliHLTComponentDataType gInputDt=kAliHLTVoidDataType;
35 const char* gBasePath="../.libs";
37 class TestProcessor : public AliHLTProcessor
43 const char* GetComponentID() {return "TestProcessor";}
45 void GetInputDataTypes( vector<AliHLTComponentDataType>& list)
46 {list.push_back(kAliHLTAnyDataType);}
48 AliHLTComponentDataType GetOutputDataType() {return kAliHLTAnyDataType;}
50 void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
51 {constBase=100; inputMultiplier=2.0;}
53 AliHLTComponent* Spawn() {return new TestProcessor;}
55 int DoInit( int argc, const char** argv ) {
56 if (fState!=kCreated) {
57 HLTError("wrong state (%d): component already initialized", fState);
64 gChainId=GetChainId();
70 if (fState!=kInitialized) {
71 HLTError("wrong state (%d): required %d kInitialized", fState, kInitialized);
78 int DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) {
80 if (fState!=kInitialized) {
81 HLTError("wrong state (%d): component not initialized", fState);
85 HLTInfo("processing event");
86 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
88 pBlock=GetNextInputBlock()) {
89 gInputDt=pBlock->fDataType;
90 AliHLTComponentDataType dt;
91 SetDataType(dt, "-OUTPUT-", "MYCO");
92 iResult=PushBack(pBlock->fPtr, pBlock->fSize/2, dt, ~pBlock->fSpecification);
105 int fState; //!transient
108 TestProcessor::TestProcessor()
116 TestProcessor::~TestProcessor()
120 class TestAgent : public AliHLTModuleAgent
123 TestAgent() : AliHLTModuleAgent("TEST") {}
126 int RegisterComponents(AliHLTComponentHandler* pHandler) const
128 pHandler->AddComponent(new TestProcessor);
136 int Logging( void* /*param*/,
137 AliHLTComponentLogSeverity severity,
142 cout << "Logging: "<< severity << " " << origin << " " << keyword << " " << message << endl;
146 void* AllocMemory( void* param, unsigned long size )
148 if (param!=&gDummy) {
149 cerr << "AllocMemoryFunc callback with wrong parameter " << endl;
152 if (size==0) return NULL;
153 return new AliHLTUInt8_t[size];
156 int main(int /*argc*/, const char** /*argv*/)
160 string libraryPath=gBasePath;
162 libraryPath+=ALIHLTANALYSIS_INTERFACE_LIBRARY;
164 void* libHandle=dlopen(libraryPath.c_str(), RTLD_NOW);
166 cerr << "error: can not load library " << libraryPath.c_str() << endl;
170 AliHLTAnalysisFctGetInterfaceCall fctGetSystemCall=(AliHLTAnalysisFctGetInterfaceCall)dlsym(libHandle, ALIHLTANALYSIS_FCT_GETINTERFACECALL);
171 if (!fctGetSystemCall) {
172 cerr << "error: can not find function '" << ALIHLTANALYSIS_FCT_GETINTERFACECALL << "' in " << libraryPath.c_str() << endl;
176 AliHLTAnalysisEnvironment environment;
177 memset(&environment, 0, sizeof(environment));
178 environment.fStructSize=sizeof(environment);
179 environment.fAllocMemoryFunc=AllocMemory;
180 environment.fLoggingFunc=Logging;
182 AliHLTExtFctInitSystem fctInitSystem=(AliHLTExtFctInitSystem)fctGetSystemCall("int AliHLTAnalysisInitSystem(unsigned long,AliHLTAnalysisEnvironment*,unsigned long,const char*)");
183 if (!fctInitSystem) {
184 cerr << "error: missing AliHLTAnalysisInitSystem call" << endl;
188 if ((iResult=fctInitSystem( ALIHLT_DATA_TYPES_VERSION, &environment, 0xbeef, "dummy-run" ))<0) {
189 cerr << "InitSystem failed with " << iResult << endl;
193 AliHLTExtFctLoadLibrary fctLoadLibrary=(AliHLTExtFctLoadLibrary)fctGetSystemCall("int AliHLTAnalysisLoadLibrary(const char*)");
194 if (!fctLoadLibrary) {
195 cerr << "error: missing LoadLibrary call" << endl;
199 if ((iResult=fctLoadLibrary("../../util/.libs/libAliHLTUtil.so"))<0) {
200 cerr << "error: AliHLTAnalysisLoadLibrary failed with " << iResult << endl;
204 AliHLTExtFctCreateComponent fctCreateComponent=(AliHLTExtFctCreateComponent)fctGetSystemCall("int AliHLTAnalysisCreateComponent(const char*,void*,int,const char**,AliHLTComponentHandle*,const char*)");
205 if (!fctCreateComponent) {
206 cerr << "error: missing CreateComponent call" << endl;
210 AliHLTComponentHandle handle;
211 if ((iResult=fctCreateComponent("TestProcessor", &gDummy, 0, NULL, &handle, "chainid=test" ))<0) {
212 cerr << "error: AliHLTAnalysisCreateComponent failed with " << iResult << endl;
216 if (gRunNo!=0xbeef) {
217 cerr << "error: propagation of run number failed " << hex << gRunNo << " vs. 0xbeef" << endl;
221 // can be used in the new interface again
222 if (strcmp(gChainId, "test")) {
223 cerr << "propagation of chain id failed: '" << gChainId << "' vs. test" << endl;
227 AliHLTExtFctProcessEvent fctProcessEvent=(AliHLTExtFctProcessEvent)fctGetSystemCall("int AliHLTAnalysisProcessEvent(AliHLTComponentHandle,const AliHLTComponentEventData*,const AliHLTComponentBlockData*,AliHLTComponentTriggerData*,AliHLTUInt8_t*,AliHLTUInt32_t*,AliHLTUInt32_t*,AliHLTComponentBlockData**,AliHLTComponentEventDoneData**)");
228 if (!fctProcessEvent) {
229 cerr << "error: missing ProcessEvent call" << endl;
233 const char* inputData="some data to be copied";
234 AliHLTComponentBlockData inputBlock;
235 memset(&inputBlock, 0, sizeof(inputBlock));
236 inputBlock.fStructSize=sizeof(inputBlock);
237 inputBlock.fPtr=(void*)inputData;
238 inputBlock.fSize=strlen(inputData);
239 inputBlock.fDataType=kAliHLTDataTypeDDLRaw;
240 inputBlock.fSpecification=0xdead;
242 AliHLTComponentEventData evtData;
243 memset(&evtData, 0, sizeof(evtData));
244 evtData.fStructSize=sizeof(evtData);
247 AliHLTComponentTriggerData trigData;
248 memset(&trigData, 0, sizeof(trigData));
249 trigData.fStructSize=sizeof(trigData);
251 AliHLTUInt8_t outputPtr[100];
252 AliHLTUInt32_t size=sizeof(outputPtr);
254 AliHLTUInt32_t outputBlockCnt=0;
255 AliHLTComponentBlockData* outputBlocks=NULL;
256 AliHLTComponentEventDoneData* edd=NULL;
258 if ((iResult=fctProcessEvent( handle, &evtData, &inputBlock, &trigData, outputPtr,
259 &size, &outputBlockCnt, &outputBlocks, &edd ))<0) {
260 cerr << "error: AliHLT_C_Component_ProcessEvent failed with " << iResult << endl;
264 if (outputBlockCnt<2) {
265 cerr << "error: mismatch in output block count, expecting >2, got " << outputBlockCnt << endl;
269 if (outputBlocks==NULL) {
270 cerr << "error: did not get output block array " << endl;
274 AliHLTComponentDataType outdt;
275 AliHLTComponent::SetDataType(outdt, "-OUTPUT-", "MYCO");
276 bool bHaveForwarded=false;
277 bool bHaveCopied=false;
278 for (unsigned int i=0; i<outputBlockCnt; i++) {
279 if (outputBlocks[i].fDataType==kAliHLTDataTypeDDLRaw) {
280 if (outputBlocks[i].fPtr!=inputData ||
281 outputBlocks[i].fSize!=strlen(inputData)) {
282 cerr << "error: failed comparing forwarded input block" << endl;
286 } else if (outputBlocks[i].fDataType==outdt) {
287 if (outputBlocks[i].fSize!=strlen(inputData)/2) {
288 cerr << "error: wrong size of copied block" << endl;
291 if (memcmp(inputData, outputPtr+outputBlocks[i].fOffset, outputBlocks[i].fSize)) {
292 cerr << "error: failed comparing copied block" << endl;
299 if (!bHaveForwarded) {
300 cerr << "error: did not get forwarded data block" << endl;
305 cerr << "error: did not get copied data block" << endl;
309 AliHLTExtFctDestroyComponent fctDestroyComponent=(AliHLTExtFctDestroyComponent)fctGetSystemCall("int AliHLTAnalysisDestroyComponent(AliHLTComponentHandle)");
310 if (!fctDestroyComponent) {
311 cerr << "error: missing DestroyComponent call" << endl;
315 fctDestroyComponent(handle);
317 AliHLTExtFctDeinitSystem fctDeinitSystem=(AliHLTExtFctDeinitSystem)fctGetSystemCall("int AliHLTAnalysisDeinitSystem()");
318 if (!fctDeinitSystem) {
319 cerr << "error: missing DeinitSystem call" << endl;
323 if ((iResult=fctDeinitSystem( ))<0) {
324 cerr << "AliHLTAnalysisDeinitSystem failed with " << iResult << endl;