]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.cxx
eff c++ warnings
[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(),
3cde846d 39 fCurrentEvent(0),
40 fEventCount(-1)
f23a6e1a 41{
42 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
43 if (fpComponentHandler)
44 fpComponentHandler->ScheduleRegister(this);
45}
46
47AliHLTComponent::~AliHLTComponent()
48{
49}
50
b22e91eb 51AliHLTComponentHandler* AliHLTComponent::fpComponentHandler=NULL;
52
85869391 53int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
54{
55 int iResult=0;
56 if (fpComponentHandler==NULL || bOverwrite!=0)
57 fpComponentHandler=pCH;
58 else
59 iResult=-EPERM;
60 return iResult;
61}
62
63int AliHLTComponent::UnsetGlobalComponentHandler() {
64 return SetGlobalComponentHandler(NULL,1);
65}
66
f23a6e1a 67int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv )
68{
69 int iResult=0;
70 if (environ) {
71 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
72 fEnvironment.fParam=environ_param;
73 }
74 iResult=DoInit(argc, argv);
3cde846d 75 if (iResult>=0) fEventCount=0;
f23a6e1a 76 return iResult;
77}
78
79int AliHLTComponent::Deinit()
80{
81 int iResult=0;
82 iResult=DoDeinit();
83 return iResult;
84}
fa2e9b7c 85
53feaef5 86int AliHLTComponent::DoInit( int argc, const char** argv )
87{
88 if (argc==0 && argv==NULL) {
89 // this is currently just to get rid of the warning "unused parameter"
90 }
91 return 0;
92}
93
94int AliHLTComponent::DoDeinit()
95{
96 return 0;
97}
98
9ce4bf4a 99void 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 );
fa2e9b7c 104}
105
9ce4bf4a 106string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
107{
108 string out("");
3cde846d 109
9ce4bf4a 110 if (type==kAliHLTVoidDataType) {
111 out="VOID:VOID";
112 } else {
3cde846d 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
117 string tmp("");
118 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
119 out.append(tmp.c_str());
9ce4bf4a 120 out.append(":");
3cde846d 121 tmp="";
122 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
123 out.append(tmp.c_str());
9ce4bf4a 124 }
125 return out;
126}
127
128
85869391 129void* AliHLTComponent::AllocMemory( unsigned long size ) {
130 if (fEnvironment.fAllocMemoryFunc)
131 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
9ce4bf4a 132 HLTFatal("no memory allocation handler registered");
85869391 133 return NULL;
134}
135
8ede8717 136int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
137 AliHLTComponentBlockData** outputBlocks ) {
9ce4bf4a 138 if ( blockCount==NULL || outputBlocks==NULL )
2d7ff710 139 return -EFAULT;
fa2e9b7c 140 AliHLTUInt32_t count = blocks.size();
141 if ( !count )
142 {
143 *blockCount = 0;
144 *outputBlocks = NULL;
145 return 0;
146 }
8ede8717 147 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
fa2e9b7c 148 if ( !*outputBlocks )
2d7ff710 149 return -ENOMEM;
ca8524df 150 for ( unsigned long i = 0; i < count; i++ ) {
fa2e9b7c 151 (*outputBlocks)[i] = blocks[i];
ca8524df 152 if (blocks[i].fDataType==kAliHLTAnyDataType) {
153 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
154 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
155 }
156 }
fa2e9b7c 157 *blockCount = count;
158 return 0;
159
160}
0c0c9d99 161
8ede8717 162int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) {
85869391 163 if (fEnvironment.fGetEventDoneDataFunc)
164 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
165 return -ENOSYS;
166}
167
8ede8717 168int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 169{
170 int iResult=0;
171 if (pConsumer) {
8ede8717 172 vector<AliHLTComponentDataType> ctlist;
0c0c9d99 173 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
8ede8717 174 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
0c0c9d99 175 while (type!=ctlist.end() && iResult==0) {
9ce4bf4a 176 if ((*type)==GetOutputDataType() ||
177 (*type)==kAliHLTAnyDataType) {
0c0c9d99 178 if (tgtList) tgtList->push_back(*type);
179 iResult++;
9ce4bf4a 180 // this loop has to be changed in case of multiple output types
0c0c9d99 181 break;
182 }
183 type++;
184 }
185 } else {
186 iResult=-EINVAL;
187 }
188 return iResult;
189}
2d7ff710 190
191void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) {
192 blockData.fStructSize = sizeof(blockData);
193 FillShmData( blockData.fShmKey );
194 blockData.fOffset = ~(AliHLTUInt32_t)0;
195 blockData.fPtr = NULL;
196 blockData.fSize = 0;
197 FillDataType( blockData.fDataType );
198 blockData.fSpecification = ~(AliHLTUInt32_t)0;
199}
200
201void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) {
202 shmData.fStructSize = sizeof(shmData);
203 shmData.fShmType = gkAliHLTComponentInvalidShmType;
204 shmData.fShmID = gkAliHLTComponentInvalidShmID;
205}
206
207void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) {
ca8524df 208 dataType=kAliHLTAnyDataType;
2d7ff710 209}
210
211void 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);
214}
215
216void 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);
220
9ce4bf4a 221 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
2d7ff710 222 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
223 }
224 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
225
9ce4bf4a 226 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
2d7ff710 227 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
228 }
229 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
230}
9ce4bf4a 231
232void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
233{
234 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
235 evtData.fStructSize=sizeof(AliHLTComponentEventData);
236}
237
238void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) {
239 TString msg;
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];
243 else msg+="\\0";
244 }
245 msg+="\" Origin=\"";
246 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
247 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
248 else msg+="\\0";
249 }
250 msg+="\"";
3cde846d 251 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
9ce4bf4a 252}
253
3cde846d 254int AliHLTComponent::GetEventCount()
255{
256 return fEventCount;
257}
258
259int AliHLTComponent::IncrementEventCounter()
260{
261 if (fEventCount>=0) fEventCount++;
262 return fEventCount;
263}
264
265int 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 )
273{
274 int iResult=0;
275 fCurrentEvent=evtData.fEventID;
276 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, outputBlockCnt, outputBlocks, edd);
277 IncrementEventCounter();
278 return iResult;
279}