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