]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
f23a6e1a | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
9 | * for The ALICE HLT Project. * | |
f23a6e1a | 10 | * * |
11 | * Permission to use, copy, modify and distribute this software and its * | |
12 | * documentation strictly for non-commercial purposes is hereby granted * | |
13 | * without fee, provided that the above copyright notice appears in all * | |
14 | * copies and that both the copyright notice and this permission notice * | |
15 | * appear in the supporting documentation. The authors make no claims * | |
16 | * about the suitability of this software for any purpose. It is * | |
17 | * provided "as is" without express or implied warranty. * | |
18 | **************************************************************************/ | |
19 | ||
bfccbf68 | 20 | /** @file AliHLTComponent.cxx |
21 | @author Matthias Richter, Timm Steinbeck | |
22 | @date | |
23 | @brief Base class implementation for HLT components. */ | |
f23a6e1a | 24 | |
0c0c9d99 | 25 | #if __GNUC__>= 3 |
f23a6e1a | 26 | using namespace std; |
27 | #endif | |
28 | ||
66043029 | 29 | //#include "AliHLTStdIncludes.h" |
f23a6e1a | 30 | #include "AliHLTComponent.h" |
31 | #include "AliHLTComponentHandler.h" | |
a655eae3 | 32 | #include "AliHLTMessage.h" |
70ed7d01 | 33 | #include "TString.h" |
a655eae3 | 34 | #include "TObjArray.h" |
79c114b5 | 35 | #include "TObjectTable.h" |
a655eae3 | 36 | #include "TClass.h" |
90ebac25 | 37 | #include "TStopwatch.h" |
79c114b5 | 38 | #include "AliHLTMemoryFile.h" |
ec25e4ca | 39 | #include <cassert> |
f23a6e1a | 40 | |
b22e91eb | 41 | /** ROOT macro for the implementation of ROOT specific class methods */ |
90ebac25 | 42 | ClassImp(AliHLTComponent); |
43 | ||
44 | /** stopwatch macro using the stopwatch guard */ | |
45 | #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL) | |
46 | //#define ALIHLTCOMPONENT_STOPWATCH(type) | |
47 | ||
48 | /** stopwatch macro for operations of the base class */ | |
49 | #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase) | |
50 | /** stopwatch macro for operations of the detector algorithm (DA) */ | |
51 | #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA) | |
f23a6e1a | 52 | |
f23a6e1a | 53 | AliHLTComponent::AliHLTComponent() |
85869391 | 54 | : |
53feaef5 | 55 | fEnvironment(), |
3cde846d | 56 | fCurrentEvent(0), |
a655eae3 | 57 | fEventCount(-1), |
58 | fFailedEvents(0), | |
59 | fCurrentEventData(), | |
60 | fpInputBlocks(NULL), | |
61 | fCurrentInputBlock(-1), | |
62 | fSearchDataType(kAliHLTVoidDataType), | |
63 | fClassName(), | |
64 | fpInputObjects(NULL), | |
65 | fpOutputBuffer(NULL), | |
66 | fOutputBufferSize(0), | |
67 | fOutputBufferFilled(0), | |
90ebac25 | 68 | fOutputBlocks(), |
79c114b5 | 69 | fpStopwatches(new TObjArray(kSWTypeCount)), |
559631d5 | 70 | fMemFiles(), |
71 | fpRunDesc(NULL), | |
72 | fpDDLList(NULL) | |
73 | ||
70ed7d01 | 74 | { |
75 | // see header file for class documentation | |
76 | // or | |
77 | // refer to README to build package | |
78 | // or | |
79 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
f23a6e1a | 80 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
70ed7d01 | 81 | if (fgpComponentHandler) |
82 | fgpComponentHandler->ScheduleRegister(this); | |
7c781d33 | 83 | //SetLocalLoggingLevel(kHLTLogDefault); |
70ed7d01 | 84 | } |
85 | ||
f23a6e1a | 86 | AliHLTComponent::~AliHLTComponent() |
87 | { | |
70ed7d01 | 88 | // see header file for function documentation |
8451168b | 89 | CleanupInputObjects(); |
4498d7d1 | 90 | if (fpStopwatches!=NULL) delete fpStopwatches; |
91 | fpStopwatches=NULL; | |
79c114b5 | 92 | vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin(); |
93 | while (element!=fMemFiles.end()) { | |
94 | if (*element) { | |
95 | if ((*element)->IsClosed()==0) { | |
96 | HLTWarning("memory file has not been closed, possible data loss or incomplete buffer"); | |
97 | // close but do not flush as we dont know whether the buffer is still valid | |
98 | (*element)->Close(0); | |
99 | } | |
100 | delete *element; | |
101 | *element=NULL; | |
102 | } | |
103 | element++; | |
104 | } | |
f23a6e1a | 105 | } |
106 | ||
70ed7d01 | 107 | AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL; |
b22e91eb | 108 | |
85869391 | 109 | int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) |
110 | { | |
70ed7d01 | 111 | // see header file for function documentation |
85869391 | 112 | int iResult=0; |
70ed7d01 | 113 | if (fgpComponentHandler==NULL || bOverwrite!=0) |
114 | fgpComponentHandler=pCH; | |
85869391 | 115 | else |
116 | iResult=-EPERM; | |
117 | return iResult; | |
118 | } | |
119 | ||
70ed7d01 | 120 | int AliHLTComponent::UnsetGlobalComponentHandler() |
121 | { | |
122 | // see header file for function documentation | |
85869391 | 123 | return SetGlobalComponentHandler(NULL,1); |
124 | } | |
125 | ||
70ed7d01 | 126 | int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv ) |
f23a6e1a | 127 | { |
70ed7d01 | 128 | // see header file for function documentation |
f23a6e1a | 129 | int iResult=0; |
130 | if (environ) { | |
131 | memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment)); | |
70ed7d01 | 132 | fEnvironment.fParam=environParam; |
f23a6e1a | 133 | } |
8451168b | 134 | const char** pArguments=NULL; |
135 | int iNofChildArgs=0; | |
136 | TString argument=""; | |
137 | int bMissingParam=0; | |
138 | if (argc>0) { | |
139 | pArguments=new const char*[argc]; | |
140 | if (pArguments) { | |
141 | for (int i=0; i<argc && iResult>=0; i++) { | |
142 | argument=argv[i]; | |
143 | if (argument.IsNull()) continue; | |
144 | ||
145 | // benchmark | |
146 | if (argument.CompareTo("benchmark")==0) { | |
147 | ||
148 | // loglevel | |
149 | } else if (argument.CompareTo("loglevel")==0) { | |
150 | if ((bMissingParam=(++i>=argc))) break; | |
151 | TString parameter(argv[i]); | |
152 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
153 | if (parameter.BeginsWith("0x") && | |
154 | parameter.Replace(0,2,"",0).IsHex()) { | |
155 | AliHLTComponentLogSeverity loglevel=kHLTLogNone; | |
7a5ccd96 | 156 | sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel); |
8451168b | 157 | SetLocalLoggingLevel(loglevel); |
158 | } else { | |
159 | HLTError("wrong parameter for argument %s, hex number expected", argument.Data()); | |
160 | iResult=-EINVAL; | |
161 | } | |
162 | } else { | |
163 | pArguments[iNofChildArgs++]=argv[i]; | |
164 | } | |
165 | } | |
166 | } else { | |
167 | iResult=-ENOMEM; | |
168 | } | |
169 | } | |
170 | if (bMissingParam) { | |
171 | HLTError("missing parameter for argument %s", argument.Data()); | |
172 | iResult=-EINVAL; | |
173 | } | |
174 | if (iResult>=0) { | |
175 | iResult=DoInit(iNofChildArgs, pArguments); | |
176 | } | |
3cde846d | 177 | if (iResult>=0) fEventCount=0; |
8451168b | 178 | if (pArguments) delete [] pArguments; |
f23a6e1a | 179 | return iResult; |
180 | } | |
181 | ||
182 | int AliHLTComponent::Deinit() | |
183 | { | |
70ed7d01 | 184 | // see header file for function documentation |
f23a6e1a | 185 | int iResult=0; |
186 | iResult=DoDeinit(); | |
559631d5 | 187 | if (fpRunDesc) { |
188 | HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo); | |
189 | AliHLTRunDesc* pRunDesc=fpRunDesc; | |
190 | fpRunDesc=NULL; | |
191 | delete pRunDesc; | |
192 | } | |
f23a6e1a | 193 | return iResult; |
194 | } | |
fa2e9b7c | 195 | |
53feaef5 | 196 | int AliHLTComponent::DoInit( int argc, const char** argv ) |
197 | { | |
70ed7d01 | 198 | // see header file for function documentation |
53feaef5 | 199 | if (argc==0 && argv==NULL) { |
200 | // this is currently just to get rid of the warning "unused parameter" | |
201 | } | |
66043029 | 202 | fEventCount=0; |
53feaef5 | 203 | return 0; |
204 | } | |
205 | ||
206 | int AliHLTComponent::DoDeinit() | |
207 | { | |
70ed7d01 | 208 | // see header file for function documentation |
66043029 | 209 | fEventCount=0; |
53feaef5 | 210 | return 0; |
211 | } | |
212 | ||
de6593d0 | 213 | int AliHLTComponent::GetOutputDataTypes(vector<AliHLTComponentDataType>& /*tgtList*/) |
214 | { | |
215 | return 0; | |
216 | } | |
217 | ||
70ed7d01 | 218 | void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const |
219 | { | |
220 | // see header file for function documentation | |
9ce4bf4a | 221 | memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 ); |
222 | strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize ); | |
223 | strcat( output, ":" ); | |
224 | strncat( output, type.fID, kAliHLTComponentDataTypefIDsize ); | |
fa2e9b7c | 225 | } |
226 | ||
9ce4bf4a | 227 | string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type ) |
228 | { | |
70ed7d01 | 229 | // see header file for function documentation |
9ce4bf4a | 230 | string out(""); |
3cde846d | 231 | |
9ce4bf4a | 232 | if (type==kAliHLTVoidDataType) { |
233 | out="VOID:VOID"; | |
234 | } else { | |
3cde846d | 235 | // some gymnastics in order to avoid a '0' which is part of either or both |
236 | // ID and origin terminating the whole string. Unfortunately, string doesn't | |
237 | // stop appending at the '0' if the number of elements to append was | |
238 | // explicitely specified | |
239 | string tmp(""); | |
240 | tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize); | |
241 | out.append(tmp.c_str()); | |
9ce4bf4a | 242 | out.append(":"); |
3cde846d | 243 | tmp=""; |
244 | tmp.append(type.fID, kAliHLTComponentDataTypefIDsize); | |
245 | out.append(tmp.c_str()); | |
9ce4bf4a | 246 | } |
247 | return out; | |
248 | } | |
249 | ||
250 | ||
70ed7d01 | 251 | void* AliHLTComponent::AllocMemory( unsigned long size ) |
252 | { | |
253 | // see header file for function documentation | |
85869391 | 254 | if (fEnvironment.fAllocMemoryFunc) |
255 | return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); | |
9ce4bf4a | 256 | HLTFatal("no memory allocation handler registered"); |
85869391 | 257 | return NULL; |
258 | } | |
259 | ||
8ede8717 | 260 | int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount, |
70ed7d01 | 261 | AliHLTComponentBlockData** outputBlocks ) |
262 | { | |
263 | // see header file for function documentation | |
9ce4bf4a | 264 | if ( blockCount==NULL || outputBlocks==NULL ) |
2d7ff710 | 265 | return -EFAULT; |
fa2e9b7c | 266 | AliHLTUInt32_t count = blocks.size(); |
267 | if ( !count ) | |
268 | { | |
269 | *blockCount = 0; | |
270 | *outputBlocks = NULL; | |
271 | return 0; | |
272 | } | |
8ede8717 | 273 | *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) ); |
fa2e9b7c | 274 | if ( !*outputBlocks ) |
2d7ff710 | 275 | return -ENOMEM; |
ca8524df | 276 | for ( unsigned long i = 0; i < count; i++ ) { |
fa2e9b7c | 277 | (*outputBlocks)[i] = blocks[i]; |
ca8524df | 278 | if (blocks[i].fDataType==kAliHLTAnyDataType) { |
5f5b708b | 279 | (*outputBlocks)[i].fDataType=GetOutputDataType(); |
280 | /* data type was set to the output data type by the PubSub AliRoot | |
281 | Wrapper component, if data type of the block was ********:****. | |
282 | Now handled by the component base class in order to have same | |
283 | behavior when running embedded in AliRoot | |
ca8524df | 284 | memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize); |
285 | memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize); | |
5f5b708b | 286 | */ |
ca8524df | 287 | } |
288 | } | |
fa2e9b7c | 289 | *blockCount = count; |
290 | return 0; | |
291 | ||
292 | } | |
0c0c9d99 | 293 | |
70ed7d01 | 294 | int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) |
295 | { | |
296 | // see header file for function documentation | |
85869391 | 297 | if (fEnvironment.fGetEventDoneDataFunc) |
298 | return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd ); | |
299 | return -ENOSYS; | |
300 | } | |
301 | ||
8ede8717 | 302 | int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList) |
0c0c9d99 | 303 | { |
70ed7d01 | 304 | // see header file for function documentation |
0c0c9d99 | 305 | int iResult=0; |
306 | if (pConsumer) { | |
8ede8717 | 307 | vector<AliHLTComponentDataType> ctlist; |
0c0c9d99 | 308 | ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist); |
8ede8717 | 309 | vector<AliHLTComponentDataType>::iterator type=ctlist.begin(); |
5f5b708b | 310 | //AliHLTComponentDataType ouptdt=GetOutputDataType(); |
311 | //PrintDataTypeContent(ouptdt, "publisher \'%s\'"); | |
0c0c9d99 | 312 | while (type!=ctlist.end() && iResult==0) { |
5f5b708b | 313 | //PrintDataTypeContent((*type), "consumer \'%s\'"); |
9ce4bf4a | 314 | if ((*type)==GetOutputDataType() || |
315 | (*type)==kAliHLTAnyDataType) { | |
0c0c9d99 | 316 | if (tgtList) tgtList->push_back(*type); |
317 | iResult++; | |
9ce4bf4a | 318 | // this loop has to be changed in case of multiple output types |
0c0c9d99 | 319 | break; |
320 | } | |
321 | type++; | |
322 | } | |
323 | } else { | |
324 | iResult=-EINVAL; | |
325 | } | |
326 | return iResult; | |
327 | } | |
2d7ff710 | 328 | |
5f5b708b | 329 | void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const |
330 | { | |
66043029 | 331 | // see header file for function documentation |
5f5b708b | 332 | const char* fmt="publisher \'%s\'"; |
333 | if (format) fmt=format; | |
334 | HLTMessage(fmt, (DataType2Text(dt)).c_str()); | |
335 | HLTMessage("%x %x %x %x %x %x %x %x : %x %x %x %x", | |
336 | dt.fID[0], | |
337 | dt.fID[1], | |
338 | dt.fID[2], | |
339 | dt.fID[3], | |
340 | dt.fID[4], | |
341 | dt.fID[5], | |
342 | dt.fID[6], | |
343 | dt.fID[7], | |
344 | dt.fOrigin[0], | |
345 | dt.fOrigin[1], | |
346 | dt.fOrigin[2], | |
347 | dt.fOrigin[3]); | |
348 | } | |
349 | ||
70ed7d01 | 350 | void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const |
351 | { | |
352 | // see header file for function documentation | |
2d7ff710 | 353 | blockData.fStructSize = sizeof(blockData); |
354 | FillShmData( blockData.fShmKey ); | |
355 | blockData.fOffset = ~(AliHLTUInt32_t)0; | |
356 | blockData.fPtr = NULL; | |
357 | blockData.fSize = 0; | |
358 | FillDataType( blockData.fDataType ); | |
a655eae3 | 359 | blockData.fSpecification = kAliHLTVoidDataSpec; |
2d7ff710 | 360 | } |
361 | ||
70ed7d01 | 362 | void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const |
363 | { | |
364 | // see header file for function documentation | |
2d7ff710 | 365 | shmData.fStructSize = sizeof(shmData); |
366 | shmData.fShmType = gkAliHLTComponentInvalidShmType; | |
367 | shmData.fShmID = gkAliHLTComponentInvalidShmID; | |
368 | } | |
369 | ||
70ed7d01 | 370 | void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const |
371 | { | |
372 | // see header file for function documentation | |
ca8524df | 373 | dataType=kAliHLTAnyDataType; |
2d7ff710 | 374 | } |
375 | ||
70ed7d01 | 376 | void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) |
377 | { | |
378 | // see header file for function documentation | |
2d7ff710 | 379 | memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize); |
380 | memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize); | |
381 | } | |
382 | ||
70ed7d01 | 383 | void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) |
384 | { | |
385 | // see header file for function documentation | |
2d7ff710 | 386 | tgtdt.fStructSize = sizeof(AliHLTComponentDataType); |
387 | memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize); | |
388 | memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize); | |
389 | ||
9ce4bf4a | 390 | if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) { |
2d7ff710 | 391 | HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize); |
392 | } | |
393 | strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize); | |
394 | ||
9ce4bf4a | 395 | if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) { |
2d7ff710 | 396 | HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize); |
397 | } | |
398 | strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize); | |
399 | } | |
9ce4bf4a | 400 | |
401 | void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData) | |
402 | { | |
70ed7d01 | 403 | // see header file for function documentation |
9ce4bf4a | 404 | memset(&evtData, 0, sizeof(AliHLTComponentEventData)); |
405 | evtData.fStructSize=sizeof(AliHLTComponentEventData); | |
406 | } | |
407 | ||
70ed7d01 | 408 | void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) |
409 | { | |
410 | // see header file for function documentation | |
9ce4bf4a | 411 | TString msg; |
412 | msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize); | |
413 | for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) { | |
414 | if (dt.fID[i]!=0) msg+=dt.fID[i]; | |
415 | else msg+="\\0"; | |
416 | } | |
417 | msg+="\" Origin=\""; | |
418 | for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) { | |
419 | if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i]; | |
420 | else msg+="\\0"; | |
421 | } | |
422 | msg+="\""; | |
3cde846d | 423 | AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data()); |
9ce4bf4a | 424 | } |
425 | ||
70ed7d01 | 426 | int AliHLTComponent::GetEventCount() const |
3cde846d | 427 | { |
70ed7d01 | 428 | // see header file for function documentation |
3cde846d | 429 | return fEventCount; |
430 | } | |
431 | ||
432 | int AliHLTComponent::IncrementEventCounter() | |
433 | { | |
70ed7d01 | 434 | // see header file for function documentation |
3cde846d | 435 | if (fEventCount>=0) fEventCount++; |
436 | return fEventCount; | |
437 | } | |
438 | ||
66043029 | 439 | int AliHLTComponent::GetNumberOfInputBlocks() const |
a655eae3 | 440 | { |
441 | // see header file for function documentation | |
442 | if (fpInputBlocks!=NULL) { | |
443 | return fCurrentEventData.fBlockCnt; | |
444 | } | |
445 | return 0; | |
446 | } | |
447 | ||
448 | const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt, | |
449 | const char* classname, | |
450 | int bForce) | |
451 | { | |
452 | // see header file for function documentation | |
90ebac25 | 453 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 454 | fSearchDataType=dt; |
455 | if (classname) fClassName=classname; | |
456 | else fClassName.clear(); | |
1edbbe49 | 457 | int idx=FindInputBlock(fSearchDataType, 0, 1); |
a655eae3 | 458 | TObject* pObj=NULL; |
459 | if (idx>=0) { | |
79c114b5 | 460 | HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str()); |
a655eae3 | 461 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { |
462 | fCurrentInputBlock=idx; | |
463 | } else { | |
464 | } | |
465 | } | |
466 | return pObj; | |
467 | } | |
468 | ||
469 | const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID, | |
470 | const char* dtOrigin, | |
471 | const char* classname, | |
472 | int bForce) | |
473 | { | |
474 | // see header file for function documentation | |
90ebac25 | 475 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 476 | AliHLTComponentDataType dt; |
477 | SetDataType(dt, dtID, dtOrigin); | |
478 | return GetFirstInputObject(dt, classname, bForce); | |
479 | } | |
480 | ||
481 | const TObject* AliHLTComponent::GetNextInputObject(int bForce) | |
482 | { | |
483 | // see header file for function documentation | |
90ebac25 | 484 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
1edbbe49 | 485 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1); |
a655eae3 | 486 | //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str()); |
487 | TObject* pObj=NULL; | |
488 | if (idx>=0) { | |
489 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { | |
490 | fCurrentInputBlock=idx; | |
491 | } | |
492 | } | |
493 | return pObj; | |
494 | } | |
495 | ||
1edbbe49 | 496 | int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const |
a655eae3 | 497 | { |
498 | // see header file for function documentation | |
499 | int iResult=-ENOENT; | |
500 | if (fpInputBlocks!=NULL) { | |
501 | int idx=startIdx<0?0:startIdx; | |
4b98eadb | 502 | for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) { |
1edbbe49 | 503 | if (bObject!=0) { |
504 | if (fpInputBlocks[idx].fPtr==NULL) continue; | |
505 | AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr); | |
506 | if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue; | |
507 | } | |
a655eae3 | 508 | if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) { |
509 | iResult=idx; | |
510 | } | |
511 | } | |
512 | } | |
513 | return iResult; | |
514 | } | |
515 | ||
516 | TObject* AliHLTComponent::CreateInputObject(int idx, int bForce) | |
517 | { | |
518 | // see header file for function documentation | |
519 | TObject* pObj=NULL; | |
520 | if (fpInputBlocks!=NULL) { | |
4b98eadb | 521 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 522 | if (fpInputBlocks[idx].fPtr) { |
523 | AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr); | |
524 | if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) { | |
8451168b | 525 | HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize); |
a655eae3 | 526 | AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize); |
66043029 | 527 | TClass* objclass=msg.GetClass(); |
528 | pObj=msg.ReadObject(objclass); | |
529 | if (pObj && objclass) { | |
530 | HLTDebug("object %p type %s created", pObj, objclass->GetName()); | |
a655eae3 | 531 | } else { |
532 | } | |
1edbbe49 | 533 | //} else { |
534 | } else if (bForce!=0) { | |
a655eae3 | 535 | HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t)); |
536 | } | |
537 | } else { | |
538 | HLTFatal("block descriptor empty"); | |
539 | } | |
540 | } else { | |
541 | HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt); | |
542 | } | |
543 | } else { | |
544 | HLTError("no input blocks available"); | |
545 | } | |
546 | ||
547 | return pObj; | |
548 | } | |
549 | ||
550 | TObject* AliHLTComponent::GetInputObject(int idx, const char* classname, int bForce) | |
551 | { | |
552 | // see header file for function documentation | |
553 | if (fpInputObjects==NULL) { | |
554 | fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt); | |
555 | } | |
556 | TObject* pObj=NULL; | |
557 | if (fpInputObjects) { | |
558 | pObj=fpInputObjects->At(idx); | |
559 | if (pObj==NULL) { | |
560 | pObj=CreateInputObject(idx, bForce); | |
561 | if (pObj) { | |
562 | fpInputObjects->AddAt(pObj, idx); | |
563 | } | |
564 | } | |
565 | } else { | |
566 | HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt); | |
567 | } | |
568 | return pObj; | |
569 | } | |
570 | ||
8451168b | 571 | int AliHLTComponent::CleanupInputObjects() |
572 | { | |
66043029 | 573 | // see header file for function documentation |
8451168b | 574 | if (!fpInputObjects) return 0; |
575 | TObjArray* array=fpInputObjects; | |
576 | fpInputObjects=NULL; | |
577 | for (int i=0; i<array->GetEntries(); i++) { | |
578 | TObject* pObj=array->At(i); | |
79c114b5 | 579 | // grrr, garbage collection strikes back: When read via AliHLTMessage |
580 | // (CreateInputObject), and written to a TFile afterwards, the | |
581 | // TFile::Close calls ROOOT's garbage collection. No clue why the | |
582 | // object ended up in the key list and needs to be deleted | |
583 | if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj; | |
8451168b | 584 | } |
585 | delete array; | |
90ebac25 | 586 | return 0; |
8451168b | 587 | } |
588 | ||
a655eae3 | 589 | AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject) |
590 | { | |
591 | // see header file for function documentation | |
90ebac25 | 592 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 593 | AliHLTComponentDataType dt=kAliHLTVoidDataType; |
594 | int idx=fCurrentInputBlock; | |
595 | if (pObject) { | |
596 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
597 | } else { | |
598 | HLTError("unknown object %p", pObject); | |
599 | } | |
600 | } | |
601 | if (idx>=0) { | |
4b98eadb | 602 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 603 | dt=fpInputBlocks[idx].fDataType; |
604 | } else { | |
605 | HLTFatal("severe internal error, index out of range"); | |
606 | } | |
607 | } | |
608 | return dt; | |
609 | } | |
610 | ||
611 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject) | |
612 | { | |
613 | // see header file for function documentation | |
90ebac25 | 614 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 615 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; |
616 | int idx=fCurrentInputBlock; | |
617 | if (pObject) { | |
618 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
619 | } else { | |
620 | HLTError("unknown object %p", pObject); | |
621 | } | |
622 | } | |
623 | if (idx>=0) { | |
4b98eadb | 624 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 625 | iSpec=fpInputBlocks[idx].fSpecification; |
626 | } else { | |
627 | HLTFatal("severe internal error, index out of range"); | |
628 | } | |
629 | } | |
630 | return iSpec; | |
631 | } | |
632 | ||
633 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt) | |
634 | { | |
635 | // see header file for function documentation | |
90ebac25 | 636 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 637 | fSearchDataType=dt; |
638 | fClassName.clear(); | |
639 | int idx=FindInputBlock(fSearchDataType, 0); | |
640 | const AliHLTComponentBlockData* pBlock=NULL; | |
641 | if (idx>=0) { | |
642 | // check for fpInputBlocks pointer done in FindInputBlock | |
643 | pBlock=&fpInputBlocks[idx]; | |
1edbbe49 | 644 | fCurrentInputBlock=idx; |
a655eae3 | 645 | } |
646 | return pBlock; | |
647 | } | |
648 | ||
649 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID, | |
650 | const char* dtOrigin) | |
651 | { | |
652 | // see header file for function documentation | |
90ebac25 | 653 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 654 | AliHLTComponentDataType dt; |
655 | SetDataType(dt, dtID, dtOrigin); | |
656 | return GetFirstInputBlock(dt); | |
657 | } | |
658 | ||
ec25e4ca | 659 | const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) |
660 | { | |
661 | // see header file for function documentation | |
662 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
663 | assert( 0 <= index and index < fCurrentEventData.fBlockCnt ); | |
664 | return &fpInputBlocks[index]; | |
665 | } | |
666 | ||
a655eae3 | 667 | const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock() |
668 | { | |
669 | // see header file for function documentation | |
90ebac25 | 670 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 671 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1); |
672 | const AliHLTComponentBlockData* pBlock=NULL; | |
673 | if (idx>=0) { | |
674 | // check for fpInputBlocks pointer done in FindInputBlock | |
675 | pBlock=&fpInputBlocks[idx]; | |
1edbbe49 | 676 | fCurrentInputBlock=idx; |
a655eae3 | 677 | } |
678 | return pBlock; | |
679 | } | |
680 | ||
66043029 | 681 | int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const |
a655eae3 | 682 | { |
683 | // see header file for function documentation | |
684 | int iResult=-ENOENT; | |
685 | if (fpInputBlocks!=NULL) { | |
686 | if (pBlock) { | |
687 | if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) { | |
132ca004 | 688 | iResult=(int)(pBlock-fpInputBlocks); |
a655eae3 | 689 | } |
690 | } else { | |
691 | iResult=-EINVAL; | |
692 | } | |
693 | } | |
694 | return iResult; | |
695 | } | |
696 | ||
697 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock) | |
698 | { | |
699 | // see header file for function documentation | |
90ebac25 | 700 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 701 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; |
702 | int idx=fCurrentInputBlock; | |
703 | if (pBlock) { | |
704 | if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) { | |
705 | } else { | |
706 | HLTError("unknown Block %p", pBlock); | |
707 | } | |
708 | } | |
709 | if (idx>=0) { | |
710 | // check for fpInputBlocks pointer done in FindInputBlock | |
711 | iSpec=fpInputBlocks[idx].fSpecification; | |
712 | } | |
713 | return iSpec; | |
714 | } | |
715 | ||
79c114b5 | 716 | int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, |
717 | void* pHeader, int headerSize) | |
a655eae3 | 718 | { |
719 | // see header file for function documentation | |
90ebac25 | 720 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 721 | int iResult=0; |
722 | if (pObject) { | |
723 | AliHLTMessage msg(kMESS_OBJECT); | |
724 | msg.WriteObject(pObject); | |
725 | Int_t iMsgLength=msg.Length(); | |
726 | if (iMsgLength>0) { | |
727 | msg.SetLength(); // sets the length to the first (reserved) word | |
79c114b5 | 728 | iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize); |
a655eae3 | 729 | if (iResult>=0) { |
8451168b | 730 | HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength); |
a655eae3 | 731 | } |
732 | } else { | |
733 | HLTError("object serialization failed for object %p", pObject); | |
734 | iResult=-ENOMSG; | |
735 | } | |
736 | } else { | |
737 | iResult=-EINVAL; | |
738 | } | |
739 | return iResult; | |
740 | } | |
741 | ||
79c114b5 | 742 | int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec, |
743 | void* pHeader, int headerSize) | |
a655eae3 | 744 | { |
745 | // see header file for function documentation | |
90ebac25 | 746 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 747 | AliHLTComponentDataType dt; |
748 | SetDataType(dt, dtID, dtOrigin); | |
79c114b5 | 749 | return PushBack(pObject, dt, spec, pHeader, headerSize); |
a655eae3 | 750 | } |
751 | ||
9d9ffd37 | 752 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, |
753 | void* pHeader, int headerSize) | |
a655eae3 | 754 | { |
755 | // see header file for function documentation | |
90ebac25 | 756 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
9d9ffd37 | 757 | return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize); |
a655eae3 | 758 | } |
759 | ||
9d9ffd37 | 760 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec, |
761 | void* pHeader, int headerSize) | |
a655eae3 | 762 | { |
763 | // see header file for function documentation | |
90ebac25 | 764 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 765 | AliHLTComponentDataType dt; |
766 | SetDataType(dt, dtID, dtOrigin); | |
9d9ffd37 | 767 | return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize); |
a655eae3 | 768 | } |
769 | ||
79c114b5 | 770 | int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, |
771 | void* pHeader, int iHeaderSize) | |
a655eae3 | 772 | { |
773 | // see header file for function documentation | |
774 | int iResult=0; | |
79c114b5 | 775 | int iBlkSize = iBufferSize + iHeaderSize; |
a655eae3 | 776 | if (pBuffer) { |
79c114b5 | 777 | if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) { |
a655eae3 | 778 | AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled; |
779 | AliHLTComponentBlockData bd; | |
780 | FillBlockData( bd ); | |
781 | bd.fOffset = fOutputBufferFilled; | |
782 | bd.fPtr = pTgt; | |
79c114b5 | 783 | bd.fSize = iBlkSize; |
a655eae3 | 784 | bd.fDataType = dt; |
785 | bd.fSpecification = spec; | |
79c114b5 | 786 | if (pHeader!=NULL && pHeader!=pTgt) { |
787 | memcpy(pTgt, pHeader, iHeaderSize); | |
788 | } | |
789 | ||
790 | pTgt += (AliHLTUInt8_t) iHeaderSize; | |
791 | ||
a655eae3 | 792 | if (pBuffer!=NULL && pBuffer!=pTgt) { |
79c114b5 | 793 | memcpy(pTgt, pBuffer, iBufferSize); |
794 | ||
4b98eadb | 795 | //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer); |
79c114b5 | 796 | //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord); |
a655eae3 | 797 | } |
798 | fOutputBufferFilled+=bd.fSize; | |
799 | fOutputBlocks.push_back( bd ); | |
79c114b5 | 800 | //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec); |
a655eae3 | 801 | } else { |
802 | if (fpOutputBuffer) { | |
79c114b5 | 803 | HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize); |
a655eae3 | 804 | } else { |
805 | HLTError("output buffer not available"); | |
806 | } | |
807 | iResult=-ENOSPC; | |
808 | } | |
809 | } else { | |
810 | iResult=-EINVAL; | |
811 | } | |
812 | return iResult; | |
813 | } | |
814 | ||
8451168b | 815 | int AliHLTComponent::EstimateObjectSize(TObject* pObject) const |
816 | { | |
66043029 | 817 | // see header file for function documentation |
8451168b | 818 | if (!pObject) return -EINVAL; |
819 | AliHLTMessage msg(kMESS_OBJECT); | |
820 | msg.WriteObject(pObject); | |
821 | return msg.Length(); | |
822 | } | |
823 | ||
79c114b5 | 824 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID, |
825 | const char* dtOrigin, | |
826 | AliHLTUInt32_t spec) | |
827 | { | |
828 | // see header file for function documentation | |
829 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
830 | AliHLTComponentDataType dt; | |
831 | SetDataType(dt, dtID, dtOrigin); | |
832 | return CreateMemoryFile(capacity, dt, spec); | |
833 | } | |
834 | ||
835 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, | |
836 | const AliHLTComponentDataType& dt, | |
837 | AliHLTUInt32_t spec) | |
838 | { | |
839 | // see header file for function documentation | |
840 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
841 | AliHLTMemoryFile* pFile=NULL; | |
83fec083 | 842 | if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){ |
79c114b5 | 843 | AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled; |
844 | pFile=new AliHLTMemoryFile((char*)pTgt, capacity); | |
845 | if (pFile) { | |
83fec083 | 846 | unsigned int nofBlocks=fOutputBlocks.size(); |
79c114b5 | 847 | if (nofBlocks+1>fMemFiles.size()) { |
848 | fMemFiles.resize(nofBlocks+1, NULL); | |
849 | } | |
850 | if (nofBlocks<fMemFiles.size()) { | |
851 | fMemFiles[nofBlocks]=pFile; | |
852 | AliHLTComponentBlockData bd; | |
853 | FillBlockData( bd ); | |
854 | bd.fOffset = fOutputBufferFilled; | |
855 | bd.fPtr = pTgt; | |
856 | bd.fSize = capacity; | |
857 | bd.fDataType = dt; | |
858 | bd.fSpecification = spec; | |
859 | fOutputBufferFilled+=bd.fSize; | |
860 | fOutputBlocks.push_back( bd ); | |
861 | } else { | |
862 | HLTError("can not allocate/grow object array"); | |
863 | pFile->Close(0); | |
864 | delete pFile; | |
865 | pFile=NULL; | |
866 | } | |
867 | } | |
868 | } else { | |
869 | HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled); | |
870 | } | |
871 | return pFile; | |
872 | } | |
873 | ||
874 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID, | |
875 | const char* dtOrigin, | |
876 | AliHLTUInt32_t spec, | |
877 | float capacity) | |
878 | { | |
879 | // see header file for function documentation | |
880 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
881 | AliHLTComponentDataType dt; | |
882 | SetDataType(dt, dtID, dtOrigin); | |
883 | int size=fOutputBufferSize-fOutputBufferFilled; | |
884 | if (capacity<0 || capacity>1.0) { | |
885 | HLTError("invalid parameter: capacity %f", capacity); | |
886 | return NULL; | |
887 | } | |
888 | size=(int)(size*capacity); | |
889 | return CreateMemoryFile(size, dt, spec); | |
890 | } | |
891 | ||
892 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt, | |
893 | AliHLTUInt32_t spec, | |
894 | float capacity) | |
895 | { | |
896 | // see header file for function documentation | |
897 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
898 | int size=fOutputBufferSize-fOutputBufferFilled; | |
899 | if (capacity<0 || capacity>1.0) { | |
900 | HLTError("invalid parameter: capacity %f", capacity); | |
901 | return NULL; | |
902 | } | |
903 | size=(int)(size*capacity); | |
904 | return CreateMemoryFile(size, dt, spec); | |
905 | } | |
906 | ||
907 | int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject, | |
908 | const char* key, int option) | |
909 | { | |
910 | int iResult=0; | |
911 | if (pFile && pObject) { | |
912 | pFile->cd(); | |
913 | iResult=pObject->Write(key, option); | |
914 | if (iResult>0) { | |
915 | // success | |
916 | } else { | |
917 | iResult=-pFile->GetErrno(); | |
918 | if (iResult==-ENOSPC) { | |
919 | HLTError("error writing memory file, buffer too small"); | |
920 | } | |
921 | } | |
922 | } else { | |
923 | iResult=-EINVAL; | |
924 | } | |
925 | return iResult; | |
926 | } | |
927 | ||
928 | int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile) | |
929 | { | |
930 | int iResult=0; | |
931 | if (pFile) { | |
932 | vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin(); | |
933 | int i=0; | |
934 | while (element!=fMemFiles.end() && iResult>=0) { | |
935 | if (*element && *element==pFile) { | |
936 | iResult=pFile->Close(); | |
937 | ||
938 | // sync memory files and descriptors | |
939 | if (iResult>=0) { | |
940 | fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize(); | |
941 | } | |
942 | delete *element; | |
943 | *element=NULL; | |
944 | return iResult; | |
945 | } | |
946 | element++; i++; | |
947 | } | |
948 | HLTError("can not find memory file %p", pFile); | |
949 | iResult=-ENOENT; | |
950 | } else { | |
951 | iResult=-EINVAL; | |
952 | } | |
953 | return iResult; | |
954 | } | |
955 | ||
a655eae3 | 956 | int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd) |
957 | { | |
958 | // see header file for function documentation | |
959 | int iResult=-ENOSYS; | |
960 | //#warning function not yet implemented | |
961 | HLTWarning("function not yet implemented"); | |
962 | return iResult; | |
963 | } | |
964 | ||
3cde846d | 965 | int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData, |
966 | const AliHLTComponentBlockData* blocks, | |
967 | AliHLTComponentTriggerData& trigData, | |
968 | AliHLTUInt8_t* outputPtr, | |
969 | AliHLTUInt32_t& size, | |
970 | AliHLTUInt32_t& outputBlockCnt, | |
971 | AliHLTComponentBlockData*& outputBlocks, | |
972 | AliHLTComponentEventDoneData*& edd ) | |
973 | { | |
70ed7d01 | 974 | // see header file for function documentation |
90ebac25 | 975 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
3cde846d | 976 | int iResult=0; |
977 | fCurrentEvent=evtData.fEventID; | |
a655eae3 | 978 | fCurrentEventData=evtData; |
979 | fpInputBlocks=blocks; | |
980 | fCurrentInputBlock=-1; | |
981 | fSearchDataType=kAliHLTAnyDataType; | |
982 | fpOutputBuffer=outputPtr; | |
983 | fOutputBufferSize=size; | |
984 | fOutputBufferFilled=0; | |
985 | fOutputBlocks.clear(); | |
559631d5 | 986 | |
987 | // find special events | |
988 | if (fpInputBlocks) { | |
83fec083 | 989 | for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) { |
559631d5 | 990 | if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) { |
991 | // start of run | |
992 | if (fpRunDesc==NULL) { | |
993 | fpRunDesc=new AliHLTRunDesc; | |
994 | if (fpRunDesc) { | |
995 | if ((iResult=CopyStruct(fpRunDesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) { | |
996 | HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo); | |
997 | } | |
998 | } else { | |
999 | iResult=-ENOMEM; | |
1000 | } | |
1001 | } else { | |
1002 | HLTWarning("already received SOR event run no %d, ignoring SOR", fpRunDesc->fRunNo); | |
1003 | } | |
1004 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) { | |
1005 | if (fpRunDesc!=NULL) { | |
1006 | if (fpRunDesc) { | |
1007 | AliHLTRunDesc rundesc; | |
1008 | if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) { | |
1009 | if (fpRunDesc->fRunNo!=rundesc.fRunNo) { | |
1010 | HLTWarning("run no missmatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo); | |
1011 | } else { | |
1012 | HLTDebug("EOR run no %d", fpRunDesc->fRunNo); | |
1013 | } | |
1014 | } | |
1015 | AliHLTRunDesc* pRunDesc=fpRunDesc; | |
1016 | fpRunDesc=NULL; | |
1017 | delete pRunDesc; | |
1018 | } | |
1019 | } else { | |
1020 | HLTWarning("did not receive SOR, ignoring EOR"); | |
1021 | } | |
1022 | // end of run | |
1023 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) { | |
1024 | // DDL list | |
1025 | } | |
1026 | } | |
1027 | } | |
a655eae3 | 1028 | |
1029 | vector<AliHLTComponentBlockData> blockData; | |
90ebac25 | 1030 | { // dont delete, sets the scope for the stopwatch guard |
1031 | ALIHLTCOMPONENT_DA_STOPWATCH(); | |
1032 | iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd); | |
1033 | } // end of the scope of the stopwatch guard | |
a655eae3 | 1034 | if (iResult>=0) { |
1035 | if (fOutputBlocks.size()>0) { | |
1036 | //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size()); | |
79c114b5 | 1037 | |
1038 | // sync memory files and descriptors | |
1039 | vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin(); | |
1040 | int i=0; | |
1041 | while (element!=fMemFiles.end() && iResult>=0) { | |
1042 | if (*element) { | |
1043 | if ((*element)->IsClosed()==0) { | |
1044 | HLTWarning("memory file has not been closed, force flush"); | |
1045 | iResult=CloseMemoryFile(*element); | |
1046 | } | |
1047 | } | |
1048 | element++; i++; | |
1049 | } | |
1050 | ||
1051 | if (iResult>=0) { | |
1052 | // create the descriptor list | |
1053 | if (blockData.size()>0) { | |
1054 | HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks"); | |
1055 | iResult=-EFAULT; | |
1056 | } else { | |
1057 | iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks); | |
1058 | size=fOutputBufferFilled; | |
1059 | } | |
a655eae3 | 1060 | } |
1061 | } else { | |
1062 | iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks); | |
1063 | } | |
1064 | if (iResult<0) { | |
1065 | HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this); | |
1066 | } | |
1067 | } | |
1068 | if (iResult<0) { | |
1069 | outputBlockCnt=0; | |
1070 | outputBlocks=NULL; | |
1071 | } | |
8451168b | 1072 | CleanupInputObjects(); |
f8bc6d99 | 1073 | if (iResult>=0) { |
1074 | IncrementEventCounter(); | |
1075 | } | |
3cde846d | 1076 | return iResult; |
1077 | } | |
a655eae3 | 1078 | |
90ebac25 | 1079 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard() |
1080 | : | |
1081 | fpStopwatch(NULL), | |
1082 | fpPrec(NULL) | |
1083 | { | |
1084 | // standard constructor (not for use) | |
1085 | } | |
1086 | ||
1087 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch) | |
1088 | : | |
1089 | fpStopwatch(pStopwatch), | |
1090 | fpPrec(NULL) | |
1091 | { | |
1092 | // constructor | |
1093 | ||
1094 | // check for already existing guard | |
1095 | if (fgpCurrent) fpPrec=fgpCurrent; | |
1096 | fgpCurrent=this; | |
1097 | ||
1098 | // stop the preceeding guard if it controls a different stopwatch | |
1099 | int bStart=1; | |
1100 | if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch); | |
1101 | ||
1102 | // start the stopwatch if the current guard controls a different one | |
1103 | if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE); | |
1104 | } | |
1105 | ||
e419b223 | 1106 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&) |
90ebac25 | 1107 | : |
1108 | fpStopwatch(NULL), | |
1109 | fpPrec(NULL) | |
1110 | { | |
e419b223 | 1111 | // |
1112 | // copy constructor not for use | |
1113 | // | |
1114 | } | |
1115 | ||
1116 | AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&) | |
1117 | { | |
1118 | // | |
1119 | // assignment operator not for use | |
1120 | // | |
1121 | fpStopwatch=NULL; | |
1122 | fpPrec=NULL; | |
1123 | return *this; | |
90ebac25 | 1124 | } |
1125 | ||
1126 | AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL; | |
1127 | ||
1128 | AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard() | |
1129 | { | |
1130 | // destructor | |
1131 | ||
1132 | // resume the preceeding guard if it controls a different stopwatch | |
1133 | int bStop=1; | |
1134 | if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch); | |
1135 | ||
1136 | // stop the stopwatch if the current guard controls a different one | |
1137 | if (fpStopwatch && bStop==1) fpStopwatch->Stop(); | |
1138 | ||
1139 | // resume to the preceeding guard | |
1140 | fgpCurrent=fpPrec; | |
1141 | } | |
1142 | ||
1143 | int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc) | |
1144 | { | |
1145 | // see header file for function documentation | |
1146 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop(); | |
1147 | return fpStopwatch!=pSucc?1:0; | |
1148 | } | |
1149 | ||
1150 | int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc) | |
1151 | { | |
1152 | // see header file for function documentation | |
1153 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE); | |
1154 | return fpStopwatch!=pSucc?1:0; | |
1155 | } | |
1156 | ||
1157 | int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type) | |
1158 | { | |
1159 | // see header file for function documentation | |
1160 | int iResult=0; | |
1161 | if (pSW!=NULL && type<kSWTypeCount) { | |
1162 | if (fpStopwatches) { | |
1163 | TObject* pObj=fpStopwatches->At((int)type); | |
1164 | if (pSW==NULL // explicit reset | |
1165 | || pObj==NULL) { // explicit set | |
1166 | fpStopwatches->AddAt(pSW, (int)type); | |
1167 | } else if (pObj!=pSW) { | |
1168 | HLTWarning("stopwatch %d already set, reset first", (int)type); | |
1169 | iResult=-EBUSY; | |
1170 | } | |
1171 | } | |
1172 | } else { | |
1173 | iResult=-EINVAL; | |
1174 | } | |
1175 | return iResult; | |
1176 | } | |
1177 | ||
1178 | int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches) | |
1179 | { | |
1180 | // see header file for function documentation | |
1181 | if (pStopwatches==NULL) return -EINVAL; | |
1182 | ||
1183 | int iResult=0; | |
1184 | for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++) | |
1185 | SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i); | |
1186 | return iResult; | |
1187 | } | |
559631d5 | 1188 | |
1189 | AliHLTUInt32_t AliHLTComponent::GetRunNo() const | |
1190 | { | |
1191 | if (fpRunDesc==NULL) return 0; | |
1192 | return fpRunDesc->fRunNo; | |
1193 | } | |
1194 | ||
1195 | AliHLTUInt32_t AliHLTComponent::GetRunType() const | |
1196 | { | |
1197 | if (fpRunDesc==NULL) return 0; | |
1198 | return fpRunDesc->fRunType; | |
1199 | } | |
1200 | ||
83fec083 | 1201 | int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo, |
559631d5 | 1202 | const char* structname, const char* eventname) |
1203 | { | |
1204 | int iResult=0; | |
1205 | if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) { | |
1206 | if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) { | |
1207 | AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct; | |
1208 | if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) { | |
1209 | AliHLTUInt8_t* pSrc=((AliHLTUInt8_t*)fpInputBlocks[iBlockNo].fPtr)+fpInputBlocks[iBlockNo].fOffset; | |
1210 | AliHLTUInt32_t copy=*((AliHLTUInt32_t*)pSrc); | |
1211 | if (fpInputBlocks[iBlockNo].fSize!=copy) { | |
1212 | HLTWarning("%s event: missmatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy); | |
1213 | if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize; | |
1214 | } | |
1215 | if (copy!=iStructSize) { | |
1216 | HLTWarning("%s event: missmatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION); | |
1217 | if (copy>iStructSize) { | |
1218 | copy=iStructSize; | |
1219 | } else { | |
1220 | memset(pTgt, 0, iStructSize); | |
1221 | } | |
1222 | } | |
1223 | memcpy(pTgt, pSrc, copy); | |
1224 | *pTgt=iStructSize; | |
1225 | iResult=copy; | |
1226 | } else { | |
1227 | HLTWarning("%s event: missing data block", eventname); | |
1228 | } | |
1229 | } else { | |
1230 | iResult=-ENODATA; | |
1231 | } | |
1232 | } else { | |
1233 | HLTError("invalid struct"); | |
1234 | iResult=-EINVAL; | |
1235 | } | |
1236 | return iResult; | |
1237 | } |