Adding CreateIterator(void) and GetNeighbours() pure virtual methods,
[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
9ce4bf4a 97void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) {
98 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
99 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
100 strcat( output, ":" );
101 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
fa2e9b7c 102}
103
9ce4bf4a 104string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
105{
106 string out("");
107 if (type==kAliHLTVoidDataType) {
108 out="VOID:VOID";
109 } else {
110 out.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
111 out.append(":");
112 out.append(type.fID, kAliHLTComponentDataTypefIDsize);
113 }
114 return out;
115}
116
117
85869391 118void* AliHLTComponent::AllocMemory( unsigned long size ) {
119 if (fEnvironment.fAllocMemoryFunc)
120 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
9ce4bf4a 121 HLTFatal("no memory allocation handler registered");
85869391 122 return NULL;
123}
124
8ede8717 125int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
126 AliHLTComponentBlockData** outputBlocks ) {
9ce4bf4a 127 if ( blockCount==NULL || outputBlocks==NULL )
2d7ff710 128 return -EFAULT;
fa2e9b7c 129 AliHLTUInt32_t count = blocks.size();
130 if ( !count )
131 {
132 *blockCount = 0;
133 *outputBlocks = NULL;
134 return 0;
135 }
8ede8717 136 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
fa2e9b7c 137 if ( !*outputBlocks )
2d7ff710 138 return -ENOMEM;
ca8524df 139 for ( unsigned long i = 0; i < count; i++ ) {
fa2e9b7c 140 (*outputBlocks)[i] = blocks[i];
ca8524df 141 if (blocks[i].fDataType==kAliHLTAnyDataType) {
142 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
143 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
144 }
145 }
fa2e9b7c 146 *blockCount = count;
147 return 0;
148
149}
0c0c9d99 150
8ede8717 151int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) {
85869391 152 if (fEnvironment.fGetEventDoneDataFunc)
153 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
154 return -ENOSYS;
155}
156
8ede8717 157int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 158{
159 int iResult=0;
160 if (pConsumer) {
8ede8717 161 vector<AliHLTComponentDataType> ctlist;
0c0c9d99 162 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
8ede8717 163 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
0c0c9d99 164 while (type!=ctlist.end() && iResult==0) {
9ce4bf4a 165 if ((*type)==GetOutputDataType() ||
166 (*type)==kAliHLTAnyDataType) {
0c0c9d99 167 if (tgtList) tgtList->push_back(*type);
168 iResult++;
9ce4bf4a 169 // this loop has to be changed in case of multiple output types
0c0c9d99 170 break;
171 }
172 type++;
173 }
174 } else {
175 iResult=-EINVAL;
176 }
177 return iResult;
178}
2d7ff710 179
180void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) {
181 blockData.fStructSize = sizeof(blockData);
182 FillShmData( blockData.fShmKey );
183 blockData.fOffset = ~(AliHLTUInt32_t)0;
184 blockData.fPtr = NULL;
185 blockData.fSize = 0;
186 FillDataType( blockData.fDataType );
187 blockData.fSpecification = ~(AliHLTUInt32_t)0;
188}
189
190void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) {
191 shmData.fStructSize = sizeof(shmData);
192 shmData.fShmType = gkAliHLTComponentInvalidShmType;
193 shmData.fShmID = gkAliHLTComponentInvalidShmID;
194}
195
196void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) {
ca8524df 197 dataType=kAliHLTAnyDataType;
2d7ff710 198}
199
200void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) {
201 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
202 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
203}
204
205void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) {
206 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
207 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
208 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
209
9ce4bf4a 210 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
2d7ff710 211 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
212 }
213 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
214
9ce4bf4a 215 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
2d7ff710 216 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
217 }
218 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
219}
9ce4bf4a 220
221void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
222{
223 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
224 evtData.fStructSize=sizeof(AliHLTComponentEventData);
225}
226
227void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) {
228 TString msg;
229 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
230 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
231 if (dt.fID[i]!=0) msg+=dt.fID[i];
232 else msg+="\\0";
233 }
234 msg+="\" Origin=\"";
235 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
236 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
237 else msg+="\\0";
238 }
239 msg+="\"";
240 HLTMessage(msg.Data());
241}
242