3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line 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 AliHLTComponent.cxx
20 @author Matthias Richter, Timm Steinbeck
22 @brief Base class implementation for HLT components. */
28 #include "AliHLTStdIncludes.h"
29 #include "AliHLTComponent.h"
30 #include "AliHLTComponentHandler.h"
31 #include "AliHLTSystem.h"
33 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTComponent)
36 AliHLTComponent::AliHLTComponent()
41 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
42 if (fpComponentHandler)
43 fpComponentHandler->ScheduleRegister(this);
46 AliHLTComponent::~AliHLTComponent()
50 AliHLTComponentHandler* AliHLTComponent::fpComponentHandler=NULL;
52 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
55 if (fpComponentHandler==NULL || bOverwrite!=0)
56 fpComponentHandler=pCH;
62 int AliHLTComponent::UnsetGlobalComponentHandler() {
63 return SetGlobalComponentHandler(NULL,1);
66 int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv )
70 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
71 fEnvironment.fParam=environ_param;
73 iResult=DoInit(argc, argv);
77 int AliHLTComponent::Deinit()
84 int AliHLTComponent::DoInit( int argc, const char** argv )
86 if (argc==0 && argv==NULL) {
87 // this is currently just to get rid of the warning "unused parameter"
92 int AliHLTComponent::DoDeinit()
97 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[14] ) {
98 memset( output, 0, 14 );
99 strncat( output, type.fOrigin, 4 );
100 strcat( output, ":" );
101 strncat( output, type.fID, 8 );
104 void* AliHLTComponent::AllocMemory( unsigned long size ) {
105 if (fEnvironment.fAllocMemoryFunc)
106 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
110 int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
111 AliHLTComponentBlockData** outputBlocks ) {
112 if ( !blockCount || !outputBlocks )
114 AliHLTUInt32_t count = blocks.size();
118 *outputBlocks = NULL;
121 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
122 if ( !*outputBlocks )
124 for ( unsigned long i = 0; i < count; i++ )
125 (*outputBlocks)[i] = blocks[i];
131 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) {
132 if (fEnvironment.fGetEventDoneDataFunc)
133 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
137 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
141 vector<AliHLTComponentDataType> ctlist;
142 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
143 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
144 while (type!=ctlist.end() && iResult==0) {
145 if ((*type)==GetOutputDataType()) {
146 if (tgtList) tgtList->push_back(*type);