- implementation dependence on HAVE_TPC_MAPPING fixed, no defines in header file
[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 )
113 return EFAULT;
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 )
123 return ENOMEM;
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}