]>
Commit | Line | Data |
---|---|---|
62bb3cd4 | 1 | // $Id$ |
2 | ||
0f1882a7 | 3 | //************************************************************************** |
4 | //* This file is property of and copyright by the ALICE HLT Project * | |
5 | //* ALICE Experiment at CERN, All rights reserved. * | |
6 | //* * | |
7 | //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
8 | //* for The ALICE HLT Project. * | |
9 | //* * | |
10 | //* Permission to use, copy, modify and distribute this software and its * | |
11 | //* documentation strictly for non-commercial purposes is hereby granted * | |
12 | //* without fee, provided that the above copyright notice appears in all * | |
13 | //* copies and that both the copyright notice and this permission notice * | |
14 | //* appear in the supporting documentation. The authors make no claims * | |
15 | //* about the suitability of this software for any purpose. It is * | |
16 | //* provided "as is" without express or implied warranty. * | |
17 | //************************************************************************** | |
62bb3cd4 | 18 | |
19 | /** @file AliHLTOUT.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
0f1882a7 | 22 | @brief The control class for HLTOUT data. |
23 | */ | |
62bb3cd4 | 24 | |
4de7334f | 25 | #include <cerrno> |
5db0e774 | 26 | #include <cassert> |
62bb3cd4 | 27 | #include "AliHLTOUT.h" |
e5701dcf | 28 | #include "AliHLTMessage.h" |
466d4e62 | 29 | #include "AliHLTMisc.h" |
c1292031 | 30 | #include "TSystem.h" |
31 | #include "TClass.h" | |
32 | #include "TROOT.h" | |
62bb3cd4 | 33 | |
34 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
35 | ClassImp(AliHLTOUT) | |
36 | ||
37 | AliHLTOUT::AliHLTOUT() | |
4de7334f | 38 | : |
39 | fSearchDataType(kAliHLTVoidDataType), | |
40 | fSearchSpecification(kAliHLTVoidDataSpec), | |
44dc7683 | 41 | fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput), |
0f1882a7 | 42 | fFlags(kSkipProcessed), |
4de7334f | 43 | fBlockDescList(), |
0f1882a7 | 44 | fCurrent(0), |
5db0e774 | 45 | fpBuffer(NULL), |
44dc7683 | 46 | fDataHandlers(), |
b005ef92 | 47 | fbVerbose(true), |
48 | fLog() | |
e5701dcf | 49 | , fpDataObject(NULL) |
50 | , fpObjectBuffer(NULL) | |
51 | , fObjectBufferSize(0) | |
c63e8be4 | 52 | , fCurrentEventId(kAliHLTVoidEventID) |
4de7334f | 53 | { |
62bb3cd4 | 54 | // see header file for class documentation |
55 | // or | |
56 | // refer to README to build package | |
57 | // or | |
58 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
59 | } | |
60 | ||
61 | AliHLTOUT::~AliHLTOUT() | |
4de7334f | 62 | { |
63 | // see header file for class documentation | |
0f1882a7 | 64 | if (CheckStatusFlag(kIsSubCollection)) { |
b005ef92 | 65 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "~AliHLTOUT" , __FILE__ , __LINE__ , "severe internal error: collection has not been released, potential crash due to invalid pointer"); |
0f1882a7 | 66 | } |
e5701dcf | 67 | |
68 | if (fpDataObject) { | |
69 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak"); | |
70 | } | |
71 | fpDataObject=NULL; | |
4de7334f | 72 | } |
b005ef92 | 73 | AliHLTOUT* AliHLTOUT::fgGlobalInstance=NULL; |
4de7334f | 74 | |
5db0e774 | 75 | int AliHLTOUT::Init() |
76 | { | |
77 | // see header file for class documentation | |
78 | int iResult=0; | |
f3c1d403 | 79 | |
80 | // ignore if already initialized | |
81 | if (fBlockDescList.size()>0) { | |
f3c1d403 | 82 | return 0; |
83 | } | |
84 | ||
18b56222 | 85 | SetStatusFlag(kCollecting); |
5db0e774 | 86 | if ((iResult=GenerateIndex())>=0) { |
87 | if ((iResult=InitHandlers())>=0) { | |
88 | } | |
89 | } | |
18b56222 | 90 | ClearStatusFlag(kCollecting); |
5db0e774 | 91 | return iResult; |
92 | } | |
93 | ||
4de7334f | 94 | int AliHLTOUT::GetNofDataBlocks() |
95 | { | |
96 | // see header file for class documentation | |
97 | return fBlockDescList.size(); | |
98 | } | |
99 | ||
5db0e774 | 100 | int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec, |
0f1882a7 | 101 | AliHLTModuleAgent::AliHLTOUTHandlerType handlerType, |
102 | bool skipProcessed) | |
4de7334f | 103 | { |
104 | // see header file for class documentation | |
0f1882a7 | 105 | fCurrent=0; |
4de7334f | 106 | fSearchDataType=dt; |
107 | fSearchSpecification=spec; | |
44dc7683 | 108 | fSearchHandlerType=handlerType; |
0f1882a7 | 109 | if (skipProcessed) SetStatusFlag(kSkipProcessed); |
110 | else ClearStatusFlag(kSkipProcessed); | |
049b43b2 | 111 | return FindAndSelectDataBlock(); |
4de7334f | 112 | } |
113 | ||
114 | int AliHLTOUT::SelectNextDataBlock() | |
115 | { | |
116 | // see header file for class documentation | |
0f1882a7 | 117 | if (fCurrent>=fBlockDescList.size()) return -ENOENT; |
049b43b2 | 118 | fCurrent++; |
119 | return FindAndSelectDataBlock(); | |
120 | } | |
121 | ||
122 | int AliHLTOUT::FindAndSelectDataBlock() | |
123 | { | |
124 | // see header file for class documentation | |
125 | if (CheckStatusFlag(kLocked)) return -EPERM; | |
4de7334f | 126 | int iResult=-ENOENT; |
0f1882a7 | 127 | while (fCurrent<fBlockDescList.size() && iResult==-ENOENT) { |
128 | if (fBlockDescList[fCurrent]==fSearchDataType && | |
129 | (fSearchSpecification==kAliHLTVoidDataSpec || fBlockDescList[fCurrent]==fSearchSpecification) && | |
512302d3 | 130 | (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent)==fSearchHandlerType) && |
0f1882a7 | 131 | (!CheckStatusFlag(kBlockSelection) || fBlockDescList[fCurrent].IsSelected()) && |
132 | (!CheckStatusFlag(kSkipProcessed) || !fBlockDescList[fCurrent].IsProcessed())) { | |
133 | iResult=fBlockDescList[fCurrent].GetIndex(); | |
049b43b2 | 134 | // TODO: check the byte order on the current system and the byte order of the |
c5123824 | 135 | // data block, print warning when mismatch and user did not check |
13398559 | 136 | //AliHLTOUTByteOrder blockBO=CheckByteOrder(); |
06f53caf | 137 | CheckByteOrder(); |
049b43b2 | 138 | /* |
139 | if (blockBO!=fByteOrder) { | |
140 | SetStatusFlag(kByteOrderWarning); | |
141 | ||
142 | } | |
143 | */ | |
144 | ClearStatusFlag(kByteOrderChecked); | |
145 | ||
146 | // TODO: check the alignment on the current system and the alignment of the | |
c5123824 | 147 | // data block, print warning when mismatch and user did not check |
049b43b2 | 148 | ClearStatusFlag(kAlignmentChecked); |
18b56222 | 149 | |
150 | break; | |
4de7334f | 151 | } |
049b43b2 | 152 | fCurrent++; |
4de7334f | 153 | } |
154 | return iResult; | |
155 | } | |
156 | ||
157 | int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec) | |
158 | { | |
159 | // see header file for class documentation | |
160 | int iResult=-ENOENT; | |
0f1882a7 | 161 | if (fCurrent<fBlockDescList.size()) { |
4de7334f | 162 | iResult=0; |
0f1882a7 | 163 | dt=fBlockDescList[fCurrent]; |
164 | spec=fBlockDescList[fCurrent]; | |
4de7334f | 165 | } |
166 | return iResult; | |
167 | } | |
168 | ||
c5123824 | 169 | const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc() |
170 | { | |
171 | // see header file for class documentation | |
512302d3 | 172 | return FindHandlerDesc(fCurrent); |
c5123824 | 173 | } |
174 | ||
175 | AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType() | |
176 | { | |
177 | // see header file for class documentation | |
512302d3 | 178 | AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(fCurrent); |
c5123824 | 179 | AliHLTModuleAgent::AliHLTOUTHandlerType type=desc; |
180 | return type; | |
181 | } | |
182 | ||
5db0e774 | 183 | AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex() |
184 | { | |
185 | // see header file for class documentation | |
0f1882a7 | 186 | if (fCurrent>=fBlockDescList.size()) return AliHLTOUTInvalidIndex; |
187 | return fBlockDescList[fCurrent].GetIndex(); | |
5db0e774 | 188 | } |
189 | ||
4de7334f | 190 | int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size) |
191 | { | |
192 | // see header file for class documentation | |
193 | int iResult=-ENOENT; | |
194 | pBuffer=NULL; | |
195 | size=0; | |
0f1882a7 | 196 | if (fCurrent<fBlockDescList.size()) { |
197 | if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(pBuffer, size))>=0) { | |
4de7334f | 198 | fpBuffer=pBuffer; |
199 | } | |
200 | } | |
201 | return iResult; | |
202 | } | |
203 | ||
204 | int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer) | |
205 | { | |
206 | // see header file for class documentation | |
207 | int iResult=0; | |
208 | if (pBuffer==fpBuffer) { | |
209 | fpBuffer=NULL; | |
210 | } else { | |
b005ef92 | 211 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "ReleaseDataBuffer" , __FILE__ , __LINE__ , "buffer %p does not match the provided one %p", pBuffer, fpBuffer); |
4de7334f | 212 | } |
213 | return iResult; | |
214 | } | |
215 | ||
c5123824 | 216 | AliHLTModuleAgent* AliHLTOUT::GetAgent() |
217 | { | |
218 | // see header file for class documentation | |
219 | AliHLTModuleAgent* pAgent=NULL; | |
512302d3 | 220 | pAgent=FindHandlerDesc(fCurrent); |
c5123824 | 221 | return pAgent; |
222 | } | |
223 | ||
626bfcc1 | 224 | AliHLTOUTHandler* AliHLTOUT::GetHandler() |
225 | { | |
226 | // see header file for class documentation | |
227 | AliHLTOUTHandler* pHandler=NULL; | |
512302d3 | 228 | pHandler=FindHandlerDesc(fCurrent); |
626bfcc1 | 229 | return pHandler; |
230 | } | |
231 | ||
c5123824 | 232 | int AliHLTOUT::WriteESD(const AliHLTUInt8_t* /*pBuffer*/, AliHLTUInt32_t /*size*/, AliHLTComponentDataType /*dt*/, AliESDEvent* /*tgtesd*/) const |
233 | { | |
234 | // see header file for class documentation | |
b005ef92 | 235 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "WriteESD" , __FILE__ , __LINE__ , "method not implemented in base class"); |
c5123824 | 236 | return -ENOSYS; |
237 | } | |
238 | ||
4de7334f | 239 | int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc) |
240 | { | |
62bb3cd4 | 241 | // see header file for class documentation |
049b43b2 | 242 | if (!CheckStatusFlag(kCollecting)) return -EPERM; |
4de7334f | 243 | int iResult=0; |
244 | fBlockDescList.push_back(desc); | |
245 | return iResult; | |
62bb3cd4 | 246 | } |
049b43b2 | 247 | |
13398559 | 248 | AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder() |
049b43b2 | 249 | { |
5db0e774 | 250 | // see header file for class documentation |
0f1882a7 | 251 | if (fCurrent<fBlockDescList.size()) { |
049b43b2 | 252 | SetStatusFlag(kByteOrderChecked); |
0f1882a7 | 253 | AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder(fBlockDescList[fCurrent].GetIndex()); |
049b43b2 | 254 | return order; |
255 | } | |
256 | return kInvalidByteOrder; | |
257 | } | |
258 | ||
13398559 | 259 | int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type) |
049b43b2 | 260 | { |
5db0e774 | 261 | // see header file for class documentation |
0f1882a7 | 262 | if (fCurrent<fBlockDescList.size()) { |
049b43b2 | 263 | SetStatusFlag(kAlignmentChecked); |
0f1882a7 | 264 | int alignment=CheckBlockAlignment(fBlockDescList[fCurrent].GetIndex(), type); |
049b43b2 | 265 | return alignment; |
266 | } | |
267 | return -ENOENT; | |
268 | } | |
5db0e774 | 269 | |
270 | int AliHLTOUT::InitHandlers() | |
271 | { | |
272 | // see header file for class documentation | |
273 | int iResult=0; | |
274 | AliHLTOUTIndexList remnants; | |
44dc7683 | 275 | int iCount=0; |
a3ef3c1d | 276 | for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) { |
44dc7683 | 277 | iCount++; |
5db0e774 | 278 | remnants.push_back(GetDataBlockIndex()); |
279 | AliHLTComponentDataType dt=kAliHLTVoidDataType; | |
280 | AliHLTUInt32_t spec=kAliHLTVoidDataSpec; | |
e94eb049 | 281 | if (GetDataBlockDescription(dt, spec)<0) break; |
f94e8c27 | 282 | bool bHaveHandler=false; |
5db0e774 | 283 | for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) { |
284 | AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc; | |
626bfcc1 | 285 | if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) { |
5db0e774 | 286 | AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex()); |
c5123824 | 287 | InsertHandler(fDataHandlers, entry); |
5db0e774 | 288 | remnants.pop_back(); |
f94e8c27 | 289 | bHaveHandler=true; |
5db0e774 | 290 | break; |
291 | } | |
292 | } | |
f94e8c27 | 293 | if (!bHaveHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) { |
294 | // ESDs are handled by the framework | |
295 | remnants.pop_back(); | |
296 | } | |
5db0e774 | 297 | } |
44dc7683 | 298 | |
299 | // warning if some of the data blocks are not selected by the kAliHLTAnyDataType | |
300 | // criterion | |
301 | if (GetNofDataBlocks()>iCount) { | |
b005ef92 | 302 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, GetNofDataBlocks()); |
44dc7683 | 303 | } |
304 | ||
305 | // warning if handler not found | |
5db0e774 | 306 | if (remnants.size()>0) { |
b005ef92 | 307 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "no handlers found for %d data blocks out of %d", remnants.size(), iCount); |
13398559 | 308 | AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin(); |
8decd484 | 309 | for (AliHLTOUTIndexList::iterator element=remnants.begin(); |
310 | element!=remnants.end() && block!=fBlockDescList.end(); | |
311 | element++) { | |
5db0e774 | 312 | for (int trials=0; trials<2; trials++) { |
313 | do { | |
314 | // we start searching the index from the current position in the block list | |
315 | if ((*block).GetIndex()==*element) break; | |
316 | } while ((++block)!=fBlockDescList.end()); | |
317 | if (block==fBlockDescList.end()) { | |
318 | // rewind and try again | |
319 | block=fBlockDescList.begin(); | |
320 | } | |
321 | } | |
322 | assert(block!=fBlockDescList.end()); | |
5db0e774 | 323 | } |
324 | } | |
325 | return iResult; | |
326 | } | |
327 | ||
c5123824 | 328 | int AliHLTOUT::InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry) |
5db0e774 | 329 | { |
330 | // see header file for class documentation | |
331 | int iResult=0; | |
c5123824 | 332 | AliHLTOUTHandlerListEntryVector::iterator element=list.begin(); |
b005ef92 | 333 | for (; element!=list.end(); |
334 | element++) { | |
5db0e774 | 335 | if (entry==(*element)) break; |
5db0e774 | 336 | } |
c5123824 | 337 | if (element==list.end()) { |
338 | list.push_back(entry); | |
5db0e774 | 339 | } else { |
a3ef3c1d | 340 | element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry)); |
5db0e774 | 341 | } |
342 | return iResult; | |
343 | } | |
344 | ||
b005ef92 | 345 | int AliHLTOUT::FillHandlerList(AliHLTOUTHandlerListEntryVector& list, AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) |
346 | { | |
347 | // see header file for class documentation | |
348 | int iResult=0; | |
349 | for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec, handlerType); | |
350 | iResult>=0; | |
351 | iResult=SelectNextDataBlock()) { | |
352 | AliHLTComponentDataType dt=kAliHLTVoidDataType; | |
353 | AliHLTUInt32_t spec=kAliHLTVoidDataSpec; | |
354 | GetDataBlockDescription(dt, spec); | |
355 | AliHLTOUTHandler* pHandler=GetHandler(); | |
356 | if (!pHandler) { | |
357 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "FillHandlerList" , __FILE__ , __LINE__ , | |
358 | "missing HLTOUT handler for block of type kChain: agent %s, data type %s, specification %#x, ... skipping data block", | |
359 | GetAgent()?GetAgent()->GetModuleId():"invalid", | |
360 | AliHLTComponent::DataType2Text(dt).c_str(), spec); | |
361 | } else { | |
362 | InsertHandler(list, GetDataBlockHandlerDesc()); | |
363 | } | |
364 | } | |
365 | // TODO: the return value of SelectFirst/NextDataBlock must be | |
366 | // changed in order to avoid this check | |
367 | if (iResult==-ENOENT) iResult=0; | |
368 | ||
369 | return iResult; | |
370 | } | |
371 | ||
372 | int AliHLTOUT::RemoveEmptyDuplicateHandlers(AliHLTOUTHandlerListEntryVector& list) | |
373 | { | |
374 | // see header file for class documentation | |
375 | int iResult=0; | |
376 | AliHLTOUTHandlerListEntryVector::iterator element=list.begin(); | |
377 | while (element!=list.end()) { | |
378 | if (element->IsEmpty()) { | |
379 | AliHLTOUTHandler* pHandler=*element; | |
380 | AliHLTModuleAgent* pAgent=*element; | |
381 | AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*element; | |
382 | if (FindHandler(list, desc)>=0) { | |
383 | element=list.erase(element); | |
384 | if (pAgent) { | |
385 | pAgent->DeleteOutputHandler(pHandler); | |
386 | } | |
387 | // we are already at the next element | |
388 | continue; | |
389 | } | |
390 | } | |
391 | element++; | |
392 | } | |
393 | return iResult; | |
394 | } | |
395 | ||
396 | int AliHLTOUT::FindHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) | |
397 | { | |
398 | // see header file for class documentation | |
399 | for (int i=0; i<(int)list.size(); i++) { | |
400 | if (list[i]==desc) return i; | |
401 | } | |
402 | return -ENOENT; | |
403 | } | |
404 | ||
405 | int AliHLTOUT::InvalidateBlocks(AliHLTOUTHandlerListEntryVector& list) | |
406 | { | |
407 | // see header file for class documentation | |
408 | for (AliHLTOUTHandlerListEntryVector::iterator element=list.begin(); | |
409 | element!=list.end(); | |
410 | element++) { | |
411 | element->InvalidateBlocks(); | |
412 | } | |
413 | return 0; | |
414 | } | |
415 | ||
44dc7683 | 416 | const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex) |
626bfcc1 | 417 | { |
418 | // see header file for class documentation | |
f3c1d403 | 419 | if (blockIndex<fBlockDescList.size()) { |
420 | return fBlockDescList[blockIndex].GetHandlerDesc(); | |
626bfcc1 | 421 | } |
44dc7683 | 422 | return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry); |
626bfcc1 | 423 | } |
424 | ||
425 | AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry() | |
426 | : | |
427 | fpHandler(NULL), | |
428 | fpHandlerDesc(NULL), | |
429 | fpAgent(NULL), | |
430 | fBlocks() | |
431 | { | |
432 | // see header file for class documentation | |
433 | } | |
434 | ||
5db0e774 | 435 | AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler, |
436 | AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc, | |
437 | AliHLTModuleAgent* pAgent, | |
438 | AliHLTUInt32_t index) | |
439 | : | |
440 | fpHandler(pHandler), | |
626bfcc1 | 441 | fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc), |
5db0e774 | 442 | fpAgent(pAgent), |
443 | fBlocks() | |
444 | { | |
445 | // see header file for class documentation | |
626bfcc1 | 446 | *fpHandlerDesc=handlerDesc; |
5db0e774 | 447 | fBlocks.push_back(index); |
448 | } | |
449 | ||
450 | AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src) | |
451 | : | |
452 | fpHandler(src.fpHandler), | |
626bfcc1 | 453 | fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc), |
5db0e774 | 454 | fpAgent(src.fpAgent), |
455 | fBlocks() | |
456 | { | |
457 | // see header file for class documentation | |
626bfcc1 | 458 | *fpHandlerDesc=*src.fpHandlerDesc; |
5db0e774 | 459 | fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end()); |
460 | } | |
461 | ||
fb24bec7 | 462 | AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry() |
463 | { | |
464 | // see header file for class documentation | |
626bfcc1 | 465 | if (fpHandlerDesc) delete fpHandlerDesc; |
466 | fpHandlerDesc=NULL; | |
fb24bec7 | 467 | } |
468 | ||
5db0e774 | 469 | AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src) |
470 | { | |
471 | // see header file for class documentation | |
472 | fpHandler=src.fpHandler; | |
44dc7683 | 473 | if (src.fpHandlerDesc) |
474 | *fpHandlerDesc=*src.fpHandlerDesc; | |
5db0e774 | 475 | fpAgent=src.fpAgent; |
476 | fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end()); | |
477 | return *this; | |
478 | } | |
479 | ||
18b56222 | 480 | AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const |
481 | { | |
482 | // see header file for class documentation | |
b0914d2e | 483 | return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex; |
5db0e774 | 484 | } |
485 | ||
fb24bec7 | 486 | bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const |
487 | { | |
18b56222 | 488 | // see header file for class documentation |
a3ef3c1d | 489 | if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false; |
490 | assert(entry.fpAgent==fpAgent); | |
491 | if (entry.fpAgent!=fpAgent) return false; | |
492 | return true; | |
493 | } | |
494 | ||
44dc7683 | 495 | bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const |
496 | { | |
497 | // see header file for class documentation | |
498 | if (!fpHandlerDesc) return false; | |
499 | return *fpHandlerDesc==handlerType; | |
500 | } | |
501 | ||
b005ef92 | 502 | bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) const |
503 | { | |
504 | // see header file for class documentation | |
505 | if (!fpHandlerDesc) return false; | |
506 | return *fpHandlerDesc==desc; | |
507 | } | |
508 | ||
a3ef3c1d | 509 | void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc) |
510 | { | |
511 | // see header file for class documentation | |
512 | AliHLTOUTIndexList::iterator element; | |
513 | for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) { | |
514 | AddIndex(*element); | |
515 | } | |
fb24bec7 | 516 | } |
517 | ||
18b56222 | 518 | void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index) |
519 | { | |
520 | // see header file for class documentation | |
5db0e774 | 521 | fBlocks.push_back(index); |
522 | } | |
626bfcc1 | 523 | |
0f1882a7 | 524 | bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index) const |
200853e2 | 525 | { |
526 | // see header file for class documentation | |
a3ef3c1d | 527 | AliHLTOUTIndexList::iterator element; |
0f1882a7 | 528 | for (unsigned int i=0; i<fBlocks.size(); i++) { |
529 | if (fBlocks[i]==index) return true; | |
a3ef3c1d | 530 | } |
200853e2 | 531 | return false; |
532 | } | |
533 | ||
626bfcc1 | 534 | const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry; |
44dc7683 | 535 | |
ff3b6fed | 536 | AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src) |
44dc7683 | 537 | { |
538 | // see header file for class documentation | |
539 | return ((src & 0xFFULL) << 56) | | |
540 | ((src & 0xFF00ULL) << 40) | | |
541 | ((src & 0xFF0000ULL) << 24) | | |
542 | ((src & 0xFF000000ULL) << 8) | | |
543 | ((src & 0xFF00000000ULL) >> 8) | | |
544 | ((src & 0xFF0000000000ULL) >> 24) | | |
545 | ((src & 0xFF000000000000ULL) >> 40) | | |
546 | ((src & 0xFF00000000000000ULL) >> 56); | |
547 | } | |
548 | ||
ff3b6fed | 549 | AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src) |
44dc7683 | 550 | { |
551 | // see header file for class documentation | |
552 | return ((src & 0xFFULL) << 24) | | |
553 | ((src & 0xFF00ULL) << 8) | | |
554 | ((src & 0xFF0000ULL) >> 8) | | |
555 | ((src & 0xFF000000ULL) >> 24); | |
556 | } | |
c1292031 | 557 | |
558 | AliHLTOUT* AliHLTOUT::New(AliRawReader* pRawReader) | |
559 | { | |
560 | // see header file for class documentation | |
466d4e62 | 561 | AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTRawReader", "libHLTrec.so"); |
c1292031 | 562 | if (instance) { |
563 | instance->SetParam(pRawReader); | |
564 | } | |
565 | return instance; | |
566 | } | |
567 | ||
568 | AliHLTOUT* AliHLTOUT::New(TTree* pDigitTree, int event) | |
569 | { | |
570 | // see header file for class documentation | |
466d4e62 | 571 | AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so"); |
c1292031 | 572 | if (instance) { |
573 | instance->SetParam(pDigitTree, event); | |
574 | } | |
575 | return instance; | |
576 | } | |
577 | ||
466d4e62 | 578 | AliHLTOUT* AliHLTOUT::New(const char* filename, int event) |
579 | { | |
580 | // see header file for class documentation | |
581 | AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so"); | |
582 | if (instance) { | |
583 | instance->SetParam(filename, event); | |
c1292031 | 584 | } |
585 | return instance; | |
586 | } | |
587 | ||
588 | void AliHLTOUT::Delete(AliHLTOUT* pInstance) | |
589 | { | |
590 | // see header file for class documentation | |
591 | if (!pInstance) return; | |
b005ef92 | 592 | if (pInstance==fgGlobalInstance) return; |
c1292031 | 593 | |
594 | // check if the library is still there in order to have the | |
595 | // destructor available | |
596 | TClass* pCl1=TClass::GetClass("AliHLTOUTRawReader"); | |
597 | TClass* pCl2=TClass::GetClass("AliHLTOUTDigitReader"); | |
598 | if (!pCl1 && !pCl2) { | |
599 | AliHLTLogging log; | |
600 | log.Logging(kHLTLogError, "AliHLTOUT::Delete", "HLTOUT handling", "potential memory leak: libHLTrec library not available, skipping destruction %p", pInstance); | |
601 | return; | |
602 | } | |
603 | ||
604 | delete pInstance; | |
605 | } | |
606 | ||
607 | void AliHLTOUT::SetParam(AliRawReader* /*pRawReader*/) | |
608 | { | |
609 | // see header file for class documentation | |
610 | // default implementation, we should never get here | |
611 | // this function can only be called from the class itsself and | |
612 | // is intended to be used with the New functions. If we get into | |
613 | // the default implementation there is a class mismatch. | |
614 | assert(0); | |
b005ef92 | 615 | fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch"); |
c1292031 | 616 | } |
617 | ||
618 | void AliHLTOUT::SetParam(TTree* /*pDigitTree*/, int /*event*/) | |
619 | { | |
620 | // see header file for class documentation | |
621 | // default implementation, we should never get here | |
622 | // this function can only be called from the class itsself and | |
623 | // is intended to be used with the New functions. If we get into | |
624 | // the default implementation there is a class mismatch. | |
625 | assert(0); | |
b005ef92 | 626 | fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch"); |
c1292031 | 627 | } |
0f1882a7 | 628 | |
466d4e62 | 629 | void AliHLTOUT::SetParam(const char* /*filename*/, int /*event*/) |
630 | { | |
631 | // see header file for class documentation | |
632 | // default implementation, we should never get here | |
633 | // this function can only be called from the class itsself and | |
634 | // is intended to be used with the New functions. If we get into | |
635 | // the default implementation there is a class mismatch. | |
636 | assert(0); | |
637 | fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch"); | |
638 | } | |
639 | ||
0f1882a7 | 640 | int AliHLTOUT::SelectDataBlock() |
641 | { | |
642 | // see header file for class documentation | |
643 | int iResult=0; | |
644 | if (fCurrent>=fBlockDescList.size()) return 0; | |
645 | fBlockDescList[fCurrent].Select(true); | |
646 | EnableBlockSelection(); | |
647 | return iResult; | |
648 | } | |
649 | ||
e13512e4 | 650 | int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerEntry) |
0f1882a7 | 651 | { |
652 | // see header file for class documentation | |
653 | int iResult=0; | |
e13512e4 | 654 | if (!pHandlerEntry) return 0; |
0f1882a7 | 655 | |
e13512e4 | 656 | AliHLTModuleAgent* pAgent=*pHandlerEntry; |
657 | AliHLTLogging log; | |
658 | log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", "selecting blocks for handler %s", pAgent->GetModuleId()); | |
0f1882a7 | 659 | AliHLTOUTBlockDescriptorVector::iterator element; |
660 | for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin(); | |
661 | block!=fBlockDescList.end(); | |
662 | block++) { | |
e13512e4 | 663 | if (block->GetHandlerDesc()==*pHandlerEntry && pHandlerEntry->HasIndex(block->GetIndex())) { |
0f1882a7 | 664 | block->Select(true); |
e13512e4 | 665 | log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " select block %s", AliHLTComponent::DataType2Text(*block).c_str()); |
666 | } else { | |
667 | log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " skip block %s", AliHLTComponent::DataType2Text(*block).c_str()); | |
0f1882a7 | 668 | block->Select(false); |
e13512e4 | 669 | } |
0f1882a7 | 670 | } |
671 | EnableBlockSelection(); | |
e13512e4 | 672 | |
673 | // Matthias 2009-07-03 bugfix: the fCurrent position was not reset at that | |
674 | // place. Also I think the data type and specification must be set in order | |
675 | // to make SelectFirst/NextDataBlock working on the selected collection | |
676 | // of data blocks | |
677 | AliHLTModuleAgent::AliHLTOUTHandlerDesc pHandlerDesc=*pHandlerEntry; | |
678 | fSearchDataType=pHandlerDesc; | |
679 | fSearchSpecification=kAliHLTVoidDataSpec; | |
680 | fSearchHandlerType=pHandlerDesc; | |
681 | fCurrent=0; | |
0f1882a7 | 682 | |
683 | return iResult; | |
684 | } | |
685 | ||
686 | int AliHLTOUT::EnableBlockSelection() | |
687 | { | |
688 | // see header file for class documentation | |
689 | SetStatusFlag(kBlockSelection); | |
690 | return 0; | |
691 | } | |
692 | ||
693 | int AliHLTOUT::DisableBlockSelection() | |
694 | { | |
695 | // see header file for class documentation | |
696 | ClearStatusFlag(kBlockSelection); | |
697 | return 0; | |
698 | } | |
699 | ||
700 | int AliHLTOUT::ResetBlockSelection() | |
701 | { | |
702 | // see header file for class documentation | |
703 | for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin(); | |
704 | block!=fBlockDescList.end(); | |
705 | block++) { | |
706 | block->Select(false); | |
707 | } | |
708 | return 0; | |
709 | } | |
710 | ||
711 | int AliHLTOUT::MarkDataBlockProcessed() | |
712 | { | |
713 | // see header file for class documentation | |
714 | int iResult=0; | |
715 | if (fCurrent>=fBlockDescList.size()) return 0; | |
716 | fBlockDescList[fCurrent].MarkProcessed(); | |
717 | return iResult; | |
718 | } | |
719 | ||
720 | int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc) | |
721 | { | |
722 | // see header file for class documentation | |
723 | int iResult=0; | |
724 | if (!pHandlerDesc) return 0; | |
725 | ||
726 | AliHLTOUTBlockDescriptorVector::iterator element; | |
727 | for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin(); | |
728 | block!=fBlockDescList.end(); | |
729 | block++) { | |
f3c1d403 | 730 | if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex())) |
0f1882a7 | 731 | block->MarkProcessed(); |
732 | } | |
733 | ||
734 | return iResult; | |
735 | } | |
736 | ||
737 | int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection) | |
738 | { | |
739 | // see header file for class documentation | |
740 | int iResult=0; | |
741 | if (!pCollection) return 0; | |
742 | ||
d4a18597 | 743 | SetStatusFlag(kCollecting); |
0f1882a7 | 744 | int index=-1; |
745 | for (index=pCollection->SelectFirstDataBlock(); | |
746 | index>=0; | |
747 | index=pCollection->SelectNextDataBlock()) { | |
748 | AliHLTComponentDataType dt=kAliHLTVoidDataType; | |
749 | AliHLTUInt32_t spec=kAliHLTVoidDataSpec; | |
750 | pCollection->GetDataBlockDescription(dt, spec); | |
751 | AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection); | |
752 | AddBlockDescriptor(desc); | |
753 | iResult++; | |
754 | } | |
755 | if (iResult>0) { | |
4562bf66 | 756 | if (CheckStatusFlag(kIsSubCollection)) { |
757 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "AddSubCollection" , __FILE__ , __LINE__ , "HLTOUT object %p has already been added as sub-collection", pCollection); | |
758 | } else { | |
759 | pCollection->SetStatusFlag(kIsSubCollection); | |
760 | } | |
0f1882a7 | 761 | } |
d4a18597 | 762 | ClearStatusFlag(kCollecting); |
0f1882a7 | 763 | |
764 | return iResult; | |
765 | } | |
766 | ||
767 | int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection) | |
768 | { | |
769 | // see header file for class documentation | |
770 | int iResult=0; | |
771 | if (!pCollection) return 0; | |
772 | ||
b005ef92 | 773 | AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin(); |
774 | while (block!=fBlockDescList.end()) { | |
0f1882a7 | 775 | if ((*block)==pCollection) { |
b005ef92 | 776 | block=fBlockDescList.erase(block); |
777 | continue; | |
0f1882a7 | 778 | } |
b005ef92 | 779 | block++; |
0f1882a7 | 780 | } |
4562bf66 | 781 | pCollection->ClearStatusFlag(kIsSubCollection); |
0f1882a7 | 782 | |
783 | return iResult; | |
784 | } | |
b005ef92 | 785 | |
786 | int AliHLTOUT::Reset() | |
787 | { | |
788 | // see header file for class documentation | |
789 | int iResult=0; | |
790 | AliHLTOUTPVector subCollections; | |
791 | AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin(); | |
792 | while (block!=fBlockDescList.end()) { | |
d4a18597 | 793 | if (!((*block)==this)) { |
b005ef92 | 794 | AliHLTOUTPVector::iterator collection=subCollections.begin(); |
795 | for (; collection!=subCollections.end(); collection++) | |
796 | if((*block)==*collection) break; | |
797 | if (collection==subCollections.end()) | |
798 | subCollections.push_back(block->GetCollection()); | |
799 | } | |
800 | block=fBlockDescList.erase(block); | |
801 | } | |
802 | ||
803 | for (AliHLTOUTPVector::iterator collection=subCollections.begin(); | |
4562bf66 | 804 | collection!=subCollections.end(); collection++) { |
b005ef92 | 805 | (*collection)->Reset(); |
4562bf66 | 806 | (*collection)->ClearStatusFlag(kIsSubCollection); |
807 | } | |
b005ef92 | 808 | |
809 | ResetInput(); | |
c63e8be4 | 810 | fCurrentEventId=kAliHLTVoidEventID; |
b005ef92 | 811 | |
812 | return iResult; | |
813 | } | |
814 | ||
815 | int AliHLTOUT::ResetInput() | |
816 | { | |
817 | // default implementation, nothing to do | |
818 | return 0; | |
819 | } | |
f3c1d403 | 820 | |
821 | const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTBlockDescriptor::GetHandlerDesc() | |
822 | { | |
823 | // see header file for class documentation | |
824 | if (fpCollection) { | |
825 | AliHLTOUTHandlerListEntryVector::iterator element=fpCollection->fDataHandlers.begin(); | |
826 | while (element!=fpCollection->fDataHandlers.end()) { | |
827 | if (element->HasIndex(GetIndex())) { | |
828 | return *element; | |
829 | } | |
830 | element++; | |
831 | } | |
832 | } | |
833 | return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry); | |
834 | } | |
e5701dcf | 835 | |
836 | TObject* AliHLTOUT::GetDataObject() | |
837 | { | |
838 | // see header file for class documentation | |
839 | if (fpDataObject) { | |
840 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak"); | |
841 | ReleaseDataBuffer(fpObjectBuffer); | |
842 | } | |
843 | fpObjectBuffer=NULL; | |
844 | fObjectBufferSize=0; | |
845 | fpDataObject=NULL; | |
846 | ||
847 | if (GetDataBuffer(fpObjectBuffer, fObjectBufferSize)>=0) { | |
848 | fpDataObject=AliHLTMessage::Extract(fpObjectBuffer, fObjectBufferSize); | |
849 | } else { | |
850 | fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "can not fetch data buffer"); | |
851 | } | |
852 | ||
853 | return fpDataObject; | |
854 | } | |
855 | ||
856 | int AliHLTOUT::ReleaseDataObject(TObject* pObject) | |
857 | { | |
858 | // see header file for class documentation | |
859 | if (!pObject) return -EINVAL; | |
860 | if (pObject!=fpDataObject) { | |
861 | fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "attempt to release wrong data object %p, expected %p", pObject, fpDataObject); | |
862 | return -EINVAL; | |
863 | } | |
864 | ||
865 | delete fpDataObject; | |
866 | fpDataObject=NULL; | |
867 | ReleaseDataBuffer(fpObjectBuffer); | |
868 | fpObjectBuffer=NULL; | |
869 | fObjectBufferSize=0; | |
870 | ||
871 | return 0; | |
872 | } | |
c63e8be4 | 873 | |
874 | void AliHLTOUT::SetEventId(AliHLTUInt64_t id) | |
875 | { | |
876 | // see header file for class documentation | |
877 | if (fCurrentEventId!=kAliHLTVoidEventID && fCurrentEventId!=id) { | |
878 | fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "SetEventId" , __FILE__ , __LINE__ , "event id was already set to 0x%llx, setting now to 0x%llx", fCurrentEventId, id); | |
879 | } | |
880 | fCurrentEventId=id; | |
881 | } |