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()
42 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
43 if (fpComponentHandler)
44 fpComponentHandler->ScheduleRegister(this);
47 AliHLTComponent::~AliHLTComponent()
51 AliHLTComponentHandler* AliHLTComponent::fpComponentHandler=NULL;
53 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
56 if (fpComponentHandler==NULL || bOverwrite!=0)
57 fpComponentHandler=pCH;
63 int AliHLTComponent::UnsetGlobalComponentHandler() {
64 return SetGlobalComponentHandler(NULL,1);
67 int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv )
71 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
72 fEnvironment.fParam=environ_param;
74 iResult=DoInit(argc, argv);
75 if (iResult>=0) fEventCount=0;
79 int AliHLTComponent::Deinit()
86 int AliHLTComponent::DoInit( int argc, const char** argv )
88 if (argc==0 && argv==NULL) {
89 // this is currently just to get rid of the warning "unused parameter"
94 int AliHLTComponent::DoDeinit()
99 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) {
100 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
101 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
102 strcat( output, ":" );
103 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
106 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
110 if (type==kAliHLTVoidDataType) {
113 // some gymnastics in order to avoid a '0' which is part of either or both
114 // ID and origin terminating the whole string. Unfortunately, string doesn't
115 // stop appending at the '0' if the number of elements to append was
116 // explicitely specified
118 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
119 out.append(tmp.c_str());
122 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
123 out.append(tmp.c_str());
129 void* AliHLTComponent::AllocMemory( unsigned long size ) {
130 if (fEnvironment.fAllocMemoryFunc)
131 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
132 HLTFatal("no memory allocation handler registered");
136 int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
137 AliHLTComponentBlockData** outputBlocks ) {
138 if ( blockCount==NULL || outputBlocks==NULL )
140 AliHLTUInt32_t count = blocks.size();
144 *outputBlocks = NULL;
147 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
148 if ( !*outputBlocks )
150 for ( unsigned long i = 0; i < count; i++ ) {
151 (*outputBlocks)[i] = blocks[i];
152 if (blocks[i].fDataType==kAliHLTAnyDataType) {
153 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
154 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
162 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) {
163 if (fEnvironment.fGetEventDoneDataFunc)
164 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
168 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
172 vector<AliHLTComponentDataType> ctlist;
173 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
174 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
175 while (type!=ctlist.end() && iResult==0) {
176 if ((*type)==GetOutputDataType() ||
177 (*type)==kAliHLTAnyDataType) {
178 if (tgtList) tgtList->push_back(*type);
180 // this loop has to be changed in case of multiple output types
191 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) {
192 blockData.fStructSize = sizeof(blockData);
193 FillShmData( blockData.fShmKey );
194 blockData.fOffset = ~(AliHLTUInt32_t)0;
195 blockData.fPtr = NULL;
197 FillDataType( blockData.fDataType );
198 blockData.fSpecification = ~(AliHLTUInt32_t)0;
201 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) {
202 shmData.fStructSize = sizeof(shmData);
203 shmData.fShmType = gkAliHLTComponentInvalidShmType;
204 shmData.fShmID = gkAliHLTComponentInvalidShmID;
207 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) {
208 dataType=kAliHLTAnyDataType;
211 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) {
212 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
213 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
216 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) {
217 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
218 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
219 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
221 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
222 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
224 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
226 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
227 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
229 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
232 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
234 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
235 evtData.fStructSize=sizeof(AliHLTComponentEventData);
238 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) {
240 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
241 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
242 if (dt.fID[i]!=0) msg+=dt.fID[i];
246 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
247 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
251 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
254 int AliHLTComponent::GetEventCount()
259 int AliHLTComponent::IncrementEventCounter()
261 if (fEventCount>=0) fEventCount++;
265 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
266 const AliHLTComponentBlockData* blocks,
267 AliHLTComponentTriggerData& trigData,
268 AliHLTUInt8_t* outputPtr,
269 AliHLTUInt32_t& size,
270 AliHLTUInt32_t& outputBlockCnt,
271 AliHLTComponentBlockData*& outputBlocks,
272 AliHLTComponentEventDoneData*& edd )
275 fCurrentEvent=evtData.fEventID;
276 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, outputBlockCnt, outputBlocks, edd);
277 IncrementEventCounter();