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