]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.cxx
component documentation
[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"
70ed7d01 31#include "TString.h"
f23a6e1a 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(),
3cde846d 39 fCurrentEvent(0),
40 fEventCount(-1)
70ed7d01 41{
42 // see header file for class documentation
43 // or
44 // refer to README to build package
45 // or
46 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
f23a6e1a 47 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
70ed7d01 48 if (fgpComponentHandler)
49 fgpComponentHandler->ScheduleRegister(this);
50}
51
52AliHLTComponent::AliHLTComponent(const AliHLTComponent&)
53 :
54 fEnvironment(),
55 fCurrentEvent(0),
56 fEventCount(-1)
57{
58 // see header file for class documentation
59 HLTFatal("copy constructor untested");
60}
61
62AliHLTComponent& AliHLTComponent::operator=(const AliHLTComponent&)
63{
64 // see header file for class documentation
65 HLTFatal("assignment operator untested");
66 return *this;
f23a6e1a 67}
68
69AliHLTComponent::~AliHLTComponent()
70{
70ed7d01 71 // see header file for function documentation
f23a6e1a 72}
73
70ed7d01 74AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
b22e91eb 75
85869391 76int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
77{
70ed7d01 78 // see header file for function documentation
85869391 79 int iResult=0;
70ed7d01 80 if (fgpComponentHandler==NULL || bOverwrite!=0)
81 fgpComponentHandler=pCH;
85869391 82 else
83 iResult=-EPERM;
84 return iResult;
85}
86
70ed7d01 87int AliHLTComponent::UnsetGlobalComponentHandler()
88{
89 // see header file for function documentation
85869391 90 return SetGlobalComponentHandler(NULL,1);
91}
92
70ed7d01 93int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv )
f23a6e1a 94{
70ed7d01 95 // see header file for function documentation
f23a6e1a 96 int iResult=0;
97 if (environ) {
98 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
70ed7d01 99 fEnvironment.fParam=environParam;
f23a6e1a 100 }
101 iResult=DoInit(argc, argv);
3cde846d 102 if (iResult>=0) fEventCount=0;
f23a6e1a 103 return iResult;
104}
105
106int AliHLTComponent::Deinit()
107{
70ed7d01 108 // see header file for function documentation
f23a6e1a 109 int iResult=0;
110 iResult=DoDeinit();
111 return iResult;
112}
fa2e9b7c 113
53feaef5 114int AliHLTComponent::DoInit( int argc, const char** argv )
115{
70ed7d01 116 // see header file for function documentation
53feaef5 117 if (argc==0 && argv==NULL) {
118 // this is currently just to get rid of the warning "unused parameter"
119 }
120 return 0;
121}
122
123int AliHLTComponent::DoDeinit()
124{
70ed7d01 125 // see header file for function documentation
53feaef5 126 return 0;
127}
128
70ed7d01 129void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
130{
131 // see header file for function documentation
9ce4bf4a 132 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
133 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
134 strcat( output, ":" );
135 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
fa2e9b7c 136}
137
9ce4bf4a 138string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
139{
70ed7d01 140 // see header file for function documentation
9ce4bf4a 141 string out("");
3cde846d 142
9ce4bf4a 143 if (type==kAliHLTVoidDataType) {
144 out="VOID:VOID";
145 } else {
3cde846d 146 // some gymnastics in order to avoid a '0' which is part of either or both
147 // ID and origin terminating the whole string. Unfortunately, string doesn't
148 // stop appending at the '0' if the number of elements to append was
149 // explicitely specified
150 string tmp("");
151 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
152 out.append(tmp.c_str());
9ce4bf4a 153 out.append(":");
3cde846d 154 tmp="";
155 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
156 out.append(tmp.c_str());
9ce4bf4a 157 }
158 return out;
159}
160
161
70ed7d01 162void* AliHLTComponent::AllocMemory( unsigned long size )
163{
164 // see header file for function documentation
85869391 165 if (fEnvironment.fAllocMemoryFunc)
166 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
9ce4bf4a 167 HLTFatal("no memory allocation handler registered");
85869391 168 return NULL;
169}
170
8ede8717 171int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
70ed7d01 172 AliHLTComponentBlockData** outputBlocks )
173{
174 // see header file for function documentation
9ce4bf4a 175 if ( blockCount==NULL || outputBlocks==NULL )
2d7ff710 176 return -EFAULT;
fa2e9b7c 177 AliHLTUInt32_t count = blocks.size();
178 if ( !count )
179 {
180 *blockCount = 0;
181 *outputBlocks = NULL;
182 return 0;
183 }
8ede8717 184 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
fa2e9b7c 185 if ( !*outputBlocks )
2d7ff710 186 return -ENOMEM;
ca8524df 187 for ( unsigned long i = 0; i < count; i++ ) {
fa2e9b7c 188 (*outputBlocks)[i] = blocks[i];
ca8524df 189 if (blocks[i].fDataType==kAliHLTAnyDataType) {
190 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
191 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
192 }
193 }
fa2e9b7c 194 *blockCount = count;
195 return 0;
196
197}
0c0c9d99 198
70ed7d01 199int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
200{
201 // see header file for function documentation
85869391 202 if (fEnvironment.fGetEventDoneDataFunc)
203 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
204 return -ENOSYS;
205}
206
8ede8717 207int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 208{
70ed7d01 209 // see header file for function documentation
0c0c9d99 210 int iResult=0;
211 if (pConsumer) {
8ede8717 212 vector<AliHLTComponentDataType> ctlist;
0c0c9d99 213 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
8ede8717 214 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
0c0c9d99 215 while (type!=ctlist.end() && iResult==0) {
9ce4bf4a 216 if ((*type)==GetOutputDataType() ||
217 (*type)==kAliHLTAnyDataType) {
0c0c9d99 218 if (tgtList) tgtList->push_back(*type);
219 iResult++;
9ce4bf4a 220 // this loop has to be changed in case of multiple output types
0c0c9d99 221 break;
222 }
223 type++;
224 }
225 } else {
226 iResult=-EINVAL;
227 }
228 return iResult;
229}
2d7ff710 230
70ed7d01 231void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const
232{
233 // see header file for function documentation
2d7ff710 234 blockData.fStructSize = sizeof(blockData);
235 FillShmData( blockData.fShmKey );
236 blockData.fOffset = ~(AliHLTUInt32_t)0;
237 blockData.fPtr = NULL;
238 blockData.fSize = 0;
239 FillDataType( blockData.fDataType );
240 blockData.fSpecification = ~(AliHLTUInt32_t)0;
241}
242
70ed7d01 243void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const
244{
245 // see header file for function documentation
2d7ff710 246 shmData.fStructSize = sizeof(shmData);
247 shmData.fShmType = gkAliHLTComponentInvalidShmType;
248 shmData.fShmID = gkAliHLTComponentInvalidShmID;
249}
250
70ed7d01 251void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const
252{
253 // see header file for function documentation
ca8524df 254 dataType=kAliHLTAnyDataType;
2d7ff710 255}
256
70ed7d01 257void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
258{
259 // see header file for function documentation
2d7ff710 260 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
261 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
262}
263
70ed7d01 264void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
265{
266 // see header file for function documentation
2d7ff710 267 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
268 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
269 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
270
9ce4bf4a 271 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
2d7ff710 272 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
273 }
274 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
275
9ce4bf4a 276 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
2d7ff710 277 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
278 }
279 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
280}
9ce4bf4a 281
282void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
283{
70ed7d01 284 // see header file for function documentation
9ce4bf4a 285 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
286 evtData.fStructSize=sizeof(AliHLTComponentEventData);
287}
288
70ed7d01 289void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
290{
291 // see header file for function documentation
9ce4bf4a 292 TString msg;
293 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
294 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
295 if (dt.fID[i]!=0) msg+=dt.fID[i];
296 else msg+="\\0";
297 }
298 msg+="\" Origin=\"";
299 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
300 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
301 else msg+="\\0";
302 }
303 msg+="\"";
3cde846d 304 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
9ce4bf4a 305}
306
70ed7d01 307int AliHLTComponent::GetEventCount() const
3cde846d 308{
70ed7d01 309 // see header file for function documentation
3cde846d 310 return fEventCount;
311}
312
313int AliHLTComponent::IncrementEventCounter()
314{
70ed7d01 315 // see header file for function documentation
3cde846d 316 if (fEventCount>=0) fEventCount++;
317 return fEventCount;
318}
319
320int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
321 const AliHLTComponentBlockData* blocks,
322 AliHLTComponentTriggerData& trigData,
323 AliHLTUInt8_t* outputPtr,
324 AliHLTUInt32_t& size,
325 AliHLTUInt32_t& outputBlockCnt,
326 AliHLTComponentBlockData*& outputBlocks,
327 AliHLTComponentEventDoneData*& edd )
328{
70ed7d01 329 // see header file for function documentation
3cde846d 330 int iResult=0;
331 fCurrentEvent=evtData.fEventID;
332 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, outputBlockCnt, outputBlocks, edd);
333 IncrementEventCounter();
334 return iResult;
335}