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