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