minor fix in function definition; missing header files added to Makefile.am
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
CommitLineData
f23a6e1a 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
f23a6e1a 8 * for The ALICE Off-line 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
bfccbf68 19/** @file AliHLTComponent.cxx
20 @author Matthias Richter, Timm Steinbeck
21 @date
22 @brief Base class implementation for HLT components. */
f23a6e1a 23
0c0c9d99 24#if __GNUC__>= 3
f23a6e1a 25using namespace std;
26#endif
27
85869391 28#include "AliHLTStdIncludes.h"
f23a6e1a 29#include "AliHLTComponent.h"
30#include "AliHLTComponentHandler.h"
f23a6e1a 31#include "AliHLTSystem.h"
32
b22e91eb 33/** ROOT macro for the implementation of ROOT specific class methods */
f23a6e1a 34ClassImp(AliHLTComponent)
35
f23a6e1a 36AliHLTComponent::AliHLTComponent()
85869391 37 :
53feaef5 38 fEnvironment(),
39 fCurrentEvent(0)
f23a6e1a 40{
41 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
42 if (fpComponentHandler)
43 fpComponentHandler->ScheduleRegister(this);
44}
45
46AliHLTComponent::~AliHLTComponent()
47{
48}
49
b22e91eb 50AliHLTComponentHandler* AliHLTComponent::fpComponentHandler=NULL;
51
85869391 52int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
53{
54 int iResult=0;
55 if (fpComponentHandler==NULL || bOverwrite!=0)
56 fpComponentHandler=pCH;
57 else
58 iResult=-EPERM;
59 return iResult;
60}
61
62int AliHLTComponent::UnsetGlobalComponentHandler() {
63 return SetGlobalComponentHandler(NULL,1);
64}
65
f23a6e1a 66int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv )
67{
68 int iResult=0;
69 if (environ) {
70 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
71 fEnvironment.fParam=environ_param;
72 }
73 iResult=DoInit(argc, argv);
74 return iResult;
75}
76
77int AliHLTComponent::Deinit()
78{
79 int iResult=0;
80 iResult=DoDeinit();
81 return iResult;
82}
fa2e9b7c 83
53feaef5 84int AliHLTComponent::DoInit( int argc, const char** argv )
85{
86 if (argc==0 && argv==NULL) {
87 // this is currently just to get rid of the warning "unused parameter"
88 }
89 return 0;
90}
91
92int AliHLTComponent::DoDeinit()
93{
94 return 0;
95}
96
8ede8717 97void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[14] ) {
fa2e9b7c 98memset( output, 0, 14 );
99strncat( output, type.fOrigin, 4 );
100strcat( output, ":" );
101strncat( output, type.fID, 8 );
102}
103
85869391 104void* AliHLTComponent::AllocMemory( unsigned long size ) {
105 if (fEnvironment.fAllocMemoryFunc)
106 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
107 return NULL;
108}
109
8ede8717 110int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
111 AliHLTComponentBlockData** outputBlocks ) {
fa2e9b7c 112 if ( !blockCount || !outputBlocks )
2d7ff710 113 return -EFAULT;
fa2e9b7c 114 AliHLTUInt32_t count = blocks.size();
115 if ( !count )
116 {
117 *blockCount = 0;
118 *outputBlocks = NULL;
119 return 0;
120 }
8ede8717 121 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
fa2e9b7c 122 if ( !*outputBlocks )
2d7ff710 123 return -ENOMEM;
fa2e9b7c 124 for ( unsigned long i = 0; i < count; i++ )
125 (*outputBlocks)[i] = blocks[i];
126 *blockCount = count;
127 return 0;
128
129}
0c0c9d99 130
8ede8717 131int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) {
85869391 132 if (fEnvironment.fGetEventDoneDataFunc)
133 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
134 return -ENOSYS;
135}
136
8ede8717 137int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 138{
139 int iResult=0;
140 if (pConsumer) {
8ede8717 141 vector<AliHLTComponentDataType> ctlist;
0c0c9d99 142 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
8ede8717 143 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
0c0c9d99 144 while (type!=ctlist.end() && iResult==0) {
145 if ((*type)==GetOutputDataType()) {
146 if (tgtList) tgtList->push_back(*type);
147 iResult++;
148 break;
149 }
150 type++;
151 }
152 } else {
153 iResult=-EINVAL;
154 }
155 return iResult;
156}
2d7ff710 157
158void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) {
159 blockData.fStructSize = sizeof(blockData);
160 FillShmData( blockData.fShmKey );
161 blockData.fOffset = ~(AliHLTUInt32_t)0;
162 blockData.fPtr = NULL;
163 blockData.fSize = 0;
164 FillDataType( blockData.fDataType );
165 blockData.fSpecification = ~(AliHLTUInt32_t)0;
166}
167
168void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) {
169 shmData.fStructSize = sizeof(shmData);
170 shmData.fShmType = gkAliHLTComponentInvalidShmType;
171 shmData.fShmID = gkAliHLTComponentInvalidShmID;
172}
173
174void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) {
175 dataType.fStructSize = sizeof(dataType);
176 memset( dataType.fID, '*', kAliHLTComponentDataTypefIDsize );
177 memset( dataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize );
178}
179
180void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) {
181 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
182 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
183}
184
185void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) {
186 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
187 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
188 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
189
190 if (strlen(id)>kAliHLTComponentDataTypefIDsize) {
191 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
192 }
193 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
194
195 if (strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
196 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
197 }
198 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
199}