]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTOUT.cxx
adding support for EventDoneData to AliHLTSystem
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.cxx
CommitLineData
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"
c1292031 29#include "TSystem.h"
30#include "TClass.h"
31#include "TROOT.h"
62bb3cd4 32
33/** ROOT macro for the implementation of ROOT specific class methods */
34ClassImp(AliHLTOUT)
35
36AliHLTOUT::AliHLTOUT()
4de7334f 37 :
38 fSearchDataType(kAliHLTVoidDataType),
39 fSearchSpecification(kAliHLTVoidDataSpec),
44dc7683 40 fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput),
0f1882a7 41 fFlags(kSkipProcessed),
4de7334f 42 fBlockDescList(),
0f1882a7 43 fCurrent(0),
5db0e774 44 fpBuffer(NULL),
44dc7683 45 fDataHandlers(),
b005ef92 46 fbVerbose(true),
47 fLog()
e5701dcf 48 , fpDataObject(NULL)
49 , fpObjectBuffer(NULL)
50 , fObjectBufferSize(0)
4de7334f 51{
62bb3cd4 52 // see header file for class documentation
53 // or
54 // refer to README to build package
55 // or
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57}
58
59AliHLTOUT::~AliHLTOUT()
4de7334f 60{
61 // see header file for class documentation
0f1882a7 62 if (CheckStatusFlag(kIsSubCollection)) {
b005ef92 63 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "~AliHLTOUT" , __FILE__ , __LINE__ , "severe internal error: collection has not been released, potential crash due to invalid pointer");
0f1882a7 64 }
e5701dcf 65
66 if (fpDataObject) {
67 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak");
68 }
69 fpDataObject=NULL;
4de7334f 70}
b005ef92 71AliHLTOUT* AliHLTOUT::fgGlobalInstance=NULL;
4de7334f 72
5db0e774 73int AliHLTOUT::Init()
74{
75 // see header file for class documentation
76 int iResult=0;
f3c1d403 77
78 // ignore if already initialized
79 if (fBlockDescList.size()>0) {
80 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "Init" , __FILE__ , __LINE__ , "instance %p already initialized, skipping ...", this);
81 return 0;
82 }
83
18b56222 84 SetStatusFlag(kCollecting);
5db0e774 85 if ((iResult=GenerateIndex())>=0) {
86 if ((iResult=InitHandlers())>=0) {
87 }
88 }
18b56222 89 ClearStatusFlag(kCollecting);
5db0e774 90 return iResult;
91}
92
4de7334f 93int AliHLTOUT::GetNofDataBlocks()
94{
95 // see header file for class documentation
96 return fBlockDescList.size();
97}
98
5db0e774 99int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
0f1882a7 100 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType,
101 bool skipProcessed)
4de7334f 102{
103 // see header file for class documentation
0f1882a7 104 fCurrent=0;
4de7334f 105 fSearchDataType=dt;
106 fSearchSpecification=spec;
44dc7683 107 fSearchHandlerType=handlerType;
0f1882a7 108 if (skipProcessed) SetStatusFlag(kSkipProcessed);
109 else ClearStatusFlag(kSkipProcessed);
049b43b2 110 return FindAndSelectDataBlock();
4de7334f 111}
112
113int AliHLTOUT::SelectNextDataBlock()
114{
115 // see header file for class documentation
0f1882a7 116 if (fCurrent>=fBlockDescList.size()) return -ENOENT;
049b43b2 117 fCurrent++;
118 return FindAndSelectDataBlock();
119}
120
121int AliHLTOUT::FindAndSelectDataBlock()
122{
123 // see header file for class documentation
124 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 125 int iResult=-ENOENT;
0f1882a7 126 while (fCurrent<fBlockDescList.size() && iResult==-ENOENT) {
127 if (fBlockDescList[fCurrent]==fSearchDataType &&
128 (fSearchSpecification==kAliHLTVoidDataSpec || fBlockDescList[fCurrent]==fSearchSpecification) &&
512302d3 129 (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent)==fSearchHandlerType) &&
0f1882a7 130 (!CheckStatusFlag(kBlockSelection) || fBlockDescList[fCurrent].IsSelected()) &&
131 (!CheckStatusFlag(kSkipProcessed) || !fBlockDescList[fCurrent].IsProcessed())) {
132 iResult=fBlockDescList[fCurrent].GetIndex();
049b43b2 133 // TODO: check the byte order on the current system and the byte order of the
c5123824 134 // data block, print warning when mismatch and user did not check
13398559 135 //AliHLTOUTByteOrder blockBO=CheckByteOrder();
06f53caf 136 CheckByteOrder();
049b43b2 137 /*
138 if (blockBO!=fByteOrder) {
139 SetStatusFlag(kByteOrderWarning);
140
141 }
142 */
143 ClearStatusFlag(kByteOrderChecked);
144
145 // TODO: check the alignment on the current system and the alignment of the
c5123824 146 // data block, print warning when mismatch and user did not check
049b43b2 147 ClearStatusFlag(kAlignmentChecked);
18b56222 148
149 break;
4de7334f 150 }
049b43b2 151 fCurrent++;
4de7334f 152 }
153 return iResult;
154}
155
156int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
157{
158 // see header file for class documentation
159 int iResult=-ENOENT;
0f1882a7 160 if (fCurrent<fBlockDescList.size()) {
4de7334f 161 iResult=0;
0f1882a7 162 dt=fBlockDescList[fCurrent];
163 spec=fBlockDescList[fCurrent];
4de7334f 164 }
165 return iResult;
166}
167
c5123824 168const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc()
169{
170 // see header file for class documentation
512302d3 171 return FindHandlerDesc(fCurrent);
c5123824 172}
173
174AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
175{
176 // see header file for class documentation
512302d3 177 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(fCurrent);
c5123824 178 AliHLTModuleAgent::AliHLTOUTHandlerType type=desc;
179 return type;
180}
181
5db0e774 182AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
183{
184 // see header file for class documentation
0f1882a7 185 if (fCurrent>=fBlockDescList.size()) return AliHLTOUTInvalidIndex;
186 return fBlockDescList[fCurrent].GetIndex();
5db0e774 187}
188
4de7334f 189int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
190{
191 // see header file for class documentation
192 int iResult=-ENOENT;
193 pBuffer=NULL;
194 size=0;
0f1882a7 195 if (fCurrent<fBlockDescList.size()) {
196 if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(pBuffer, size))>=0) {
4de7334f 197 fpBuffer=pBuffer;
198 }
199 }
200 return iResult;
201}
202
203int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
204{
205 // see header file for class documentation
206 int iResult=0;
207 if (pBuffer==fpBuffer) {
208 fpBuffer=NULL;
209 } else {
b005ef92 210 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "ReleaseDataBuffer" , __FILE__ , __LINE__ , "buffer %p does not match the provided one %p", pBuffer, fpBuffer);
4de7334f 211 }
212 return iResult;
213}
214
c5123824 215AliHLTModuleAgent* AliHLTOUT::GetAgent()
216{
217 // see header file for class documentation
218 AliHLTModuleAgent* pAgent=NULL;
512302d3 219 pAgent=FindHandlerDesc(fCurrent);
c5123824 220 return pAgent;
221}
222
626bfcc1 223AliHLTOUTHandler* AliHLTOUT::GetHandler()
224{
225 // see header file for class documentation
226 AliHLTOUTHandler* pHandler=NULL;
512302d3 227 pHandler=FindHandlerDesc(fCurrent);
626bfcc1 228 return pHandler;
229}
230
c5123824 231int AliHLTOUT::WriteESD(const AliHLTUInt8_t* /*pBuffer*/, AliHLTUInt32_t /*size*/, AliHLTComponentDataType /*dt*/, AliESDEvent* /*tgtesd*/) const
232{
233 // see header file for class documentation
b005ef92 234 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "WriteESD" , __FILE__ , __LINE__ , "method not implemented in base class");
c5123824 235 return -ENOSYS;
236}
237
4de7334f 238int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
239{
62bb3cd4 240 // see header file for class documentation
049b43b2 241 if (!CheckStatusFlag(kCollecting)) return -EPERM;
4de7334f 242 int iResult=0;
243 fBlockDescList.push_back(desc);
244 return iResult;
62bb3cd4 245}
049b43b2 246
13398559 247AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
049b43b2 248{
5db0e774 249 // see header file for class documentation
0f1882a7 250 if (fCurrent<fBlockDescList.size()) {
049b43b2 251 SetStatusFlag(kByteOrderChecked);
0f1882a7 252 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder(fBlockDescList[fCurrent].GetIndex());
049b43b2 253 return order;
254 }
255 return kInvalidByteOrder;
256}
257
13398559 258int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
049b43b2 259{
5db0e774 260 // see header file for class documentation
0f1882a7 261 if (fCurrent<fBlockDescList.size()) {
049b43b2 262 SetStatusFlag(kAlignmentChecked);
0f1882a7 263 int alignment=CheckBlockAlignment(fBlockDescList[fCurrent].GetIndex(), type);
049b43b2 264 return alignment;
265 }
266 return -ENOENT;
267}
5db0e774 268
269int AliHLTOUT::InitHandlers()
270{
271 // see header file for class documentation
272 int iResult=0;
273 AliHLTOUTIndexList remnants;
44dc7683 274 int iCount=0;
a3ef3c1d 275 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
44dc7683 276 iCount++;
5db0e774 277 remnants.push_back(GetDataBlockIndex());
278 AliHLTComponentDataType dt=kAliHLTVoidDataType;
279 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
e94eb049 280 if (GetDataBlockDescription(dt, spec)<0) break;
f94e8c27 281 bool bHaveHandler=false;
5db0e774 282 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
283 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
626bfcc1 284 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
5db0e774 285 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
c5123824 286 InsertHandler(fDataHandlers, entry);
5db0e774 287 remnants.pop_back();
f94e8c27 288 bHaveHandler=true;
5db0e774 289 break;
290 }
291 }
f94e8c27 292 if (!bHaveHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
293 // ESDs are handled by the framework
294 remnants.pop_back();
295 }
5db0e774 296 }
44dc7683 297
298 // warning if some of the data blocks are not selected by the kAliHLTAnyDataType
299 // criterion
300 if (GetNofDataBlocks()>iCount) {
b005ef92 301 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, GetNofDataBlocks());
44dc7683 302 }
303
304 // warning if handler not found
5db0e774 305 if (remnants.size()>0) {
b005ef92 306 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "no handlers found for %d data blocks out of %d", remnants.size(), iCount);
13398559 307 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
5db0e774 308 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
309 for (int trials=0; trials<2; trials++) {
310 do {
311 // we start searching the index from the current position in the block list
312 if ((*block).GetIndex()==*element) break;
313 } while ((++block)!=fBlockDescList.end());
314 if (block==fBlockDescList.end()) {
315 // rewind and try again
316 block=fBlockDescList.begin();
317 }
318 }
319 assert(block!=fBlockDescList.end());
320 if (block!=fBlockDescList.end()) {
b005ef92 321 //HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
5db0e774 322 }
323 }
324 }
325 return iResult;
326}
327
c5123824 328int 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 345int 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
372int 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
396int 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
405int 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 416const 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
425AliHLTOUT::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 435AliHLTOUT::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
450AliHLTOUT::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 462AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
463{
464 // see header file for class documentation
626bfcc1 465 if (fpHandlerDesc) delete fpHandlerDesc;
466 fpHandlerDesc=NULL;
fb24bec7 467}
468
5db0e774 469AliHLTOUT::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 480AliHLTUInt32_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 486bool 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 495bool 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 502bool 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 509void 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 518void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
519{
520 // see header file for class documentation
5db0e774 521 fBlocks.push_back(index);
522}
626bfcc1 523
0f1882a7 524bool 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 534const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
44dc7683 535
ff3b6fed 536AliHLTUInt64_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 549AliHLTUInt32_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
558AliHLTOUT* AliHLTOUT::New(AliRawReader* pRawReader)
559{
560 // see header file for class documentation
561 AliHLTOUT* instance=New("AliHLTOUTRawReader");
562 if (instance) {
563 instance->SetParam(pRawReader);
564 }
565 return instance;
566}
567
568AliHLTOUT* AliHLTOUT::New(TTree* pDigitTree, int event)
569{
570 // see header file for class documentation
571 AliHLTOUT* instance=New("AliHLTOUTDigitReader");
572 if (instance) {
573 instance->SetParam(pDigitTree, event);
574 }
575 return instance;
576}
577
578AliHLTOUT* AliHLTOUT::New(const char* classname)
579{
580 // see header file for class documentation
581 int iLibResult=0;
582 AliHLTOUT* instance=NULL;
583 AliHLTLogging log;
584 TClass* pCl=NULL;
585 ROOT::NewFunc_t pNewFunc=NULL;
586 do {
587 pCl=TClass::GetClass(classname);
a33afc42 588 } while (!pCl && (iLibResult=gSystem->Load("libHLTrec.so"))==0);
c1292031 589 if (iLibResult>=0) {
590 if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
591 void* p=(*pNewFunc)(NULL);
592 if (p) {
593 instance=reinterpret_cast<AliHLTOUT*>(p);
594 if (!instance) {
595 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "type cast to AliHLTOUT instance failed");
596 }
597 } else {
598 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not create AliHLTOUT instance from class descriptor");
599 }
600 } else {
601 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not find AliHLTOUT class descriptor");
602 }
603 } else {
604 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not load libHLTrec library");
605 }
606 return instance;
607}
608
609void AliHLTOUT::Delete(AliHLTOUT* pInstance)
610{
611 // see header file for class documentation
612 if (!pInstance) return;
b005ef92 613 if (pInstance==fgGlobalInstance) return;
c1292031 614
615 // check if the library is still there in order to have the
616 // destructor available
617 TClass* pCl1=TClass::GetClass("AliHLTOUTRawReader");
618 TClass* pCl2=TClass::GetClass("AliHLTOUTDigitReader");
619 if (!pCl1 && !pCl2) {
620 AliHLTLogging log;
621 log.Logging(kHLTLogError, "AliHLTOUT::Delete", "HLTOUT handling", "potential memory leak: libHLTrec library not available, skipping destruction %p", pInstance);
622 return;
623 }
624
625 delete pInstance;
626}
627
628void AliHLTOUT::SetParam(AliRawReader* /*pRawReader*/)
629{
630 // see header file for class documentation
631 // default implementation, we should never get here
632 // this function can only be called from the class itsself and
633 // is intended to be used with the New functions. If we get into
634 // the default implementation there is a class mismatch.
635 assert(0);
b005ef92 636 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
c1292031 637}
638
639void AliHLTOUT::SetParam(TTree* /*pDigitTree*/, int /*event*/)
640{
641 // see header file for class documentation
642 // default implementation, we should never get here
643 // this function can only be called from the class itsself and
644 // is intended to be used with the New functions. If we get into
645 // the default implementation there is a class mismatch.
646 assert(0);
b005ef92 647 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
c1292031 648}
0f1882a7 649
650int AliHLTOUT::SelectDataBlock()
651{
652 // see header file for class documentation
653 int iResult=0;
654 if (fCurrent>=fBlockDescList.size()) return 0;
655 fBlockDescList[fCurrent].Select(true);
656 EnableBlockSelection();
657 return iResult;
658}
659
e13512e4 660int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerEntry)
0f1882a7 661{
662 // see header file for class documentation
663 int iResult=0;
e13512e4 664 if (!pHandlerEntry) return 0;
0f1882a7 665
e13512e4 666 AliHLTModuleAgent* pAgent=*pHandlerEntry;
667 AliHLTLogging log;
668 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", "selecting blocks for handler %s", pAgent->GetModuleId());
0f1882a7 669 AliHLTOUTBlockDescriptorVector::iterator element;
670 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
671 block!=fBlockDescList.end();
672 block++) {
e13512e4 673 if (block->GetHandlerDesc()==*pHandlerEntry && pHandlerEntry->HasIndex(block->GetIndex())) {
0f1882a7 674 block->Select(true);
e13512e4 675 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " select block %s", AliHLTComponent::DataType2Text(*block).c_str());
676 } else {
677 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " skip block %s", AliHLTComponent::DataType2Text(*block).c_str());
0f1882a7 678 block->Select(false);
e13512e4 679 }
0f1882a7 680 }
681 EnableBlockSelection();
e13512e4 682
683 // Matthias 2009-07-03 bugfix: the fCurrent position was not reset at that
684 // place. Also I think the data type and specification must be set in order
685 // to make SelectFirst/NextDataBlock working on the selected collection
686 // of data blocks
687 AliHLTModuleAgent::AliHLTOUTHandlerDesc pHandlerDesc=*pHandlerEntry;
688 fSearchDataType=pHandlerDesc;
689 fSearchSpecification=kAliHLTVoidDataSpec;
690 fSearchHandlerType=pHandlerDesc;
691 fCurrent=0;
0f1882a7 692
693 return iResult;
694}
695
696int AliHLTOUT::EnableBlockSelection()
697{
698 // see header file for class documentation
699 SetStatusFlag(kBlockSelection);
700 return 0;
701}
702
703int AliHLTOUT::DisableBlockSelection()
704{
705 // see header file for class documentation
706 ClearStatusFlag(kBlockSelection);
707 return 0;
708}
709
710int AliHLTOUT::ResetBlockSelection()
711{
712 // see header file for class documentation
713 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
714 block!=fBlockDescList.end();
715 block++) {
716 block->Select(false);
717 }
718 return 0;
719}
720
721int AliHLTOUT::MarkDataBlockProcessed()
722{
723 // see header file for class documentation
724 int iResult=0;
725 if (fCurrent>=fBlockDescList.size()) return 0;
726 fBlockDescList[fCurrent].MarkProcessed();
727 return iResult;
728}
729
730int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc)
731{
732 // see header file for class documentation
733 int iResult=0;
734 if (!pHandlerDesc) return 0;
735
736 AliHLTOUTBlockDescriptorVector::iterator element;
737 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
738 block!=fBlockDescList.end();
739 block++) {
f3c1d403 740 if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
0f1882a7 741 block->MarkProcessed();
742 }
743
744 return iResult;
745}
746
747int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection)
748{
749 // see header file for class documentation
750 int iResult=0;
751 if (!pCollection) return 0;
752
d4a18597 753 SetStatusFlag(kCollecting);
0f1882a7 754 int index=-1;
755 for (index=pCollection->SelectFirstDataBlock();
756 index>=0;
757 index=pCollection->SelectNextDataBlock()) {
758 AliHLTComponentDataType dt=kAliHLTVoidDataType;
759 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
760 pCollection->GetDataBlockDescription(dt, spec);
761 AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection);
762 AddBlockDescriptor(desc);
763 iResult++;
764 }
765 if (iResult>0) {
4562bf66 766 if (CheckStatusFlag(kIsSubCollection)) {
767 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "AddSubCollection" , __FILE__ , __LINE__ , "HLTOUT object %p has already been added as sub-collection", pCollection);
768 } else {
769 pCollection->SetStatusFlag(kIsSubCollection);
770 }
0f1882a7 771 }
d4a18597 772 ClearStatusFlag(kCollecting);
0f1882a7 773
774 return iResult;
775}
776
777int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection)
778{
779 // see header file for class documentation
780 int iResult=0;
781 if (!pCollection) return 0;
782
b005ef92 783 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
784 while (block!=fBlockDescList.end()) {
0f1882a7 785 if ((*block)==pCollection) {
b005ef92 786 block=fBlockDescList.erase(block);
787 continue;
0f1882a7 788 }
b005ef92 789 block++;
0f1882a7 790 }
4562bf66 791 pCollection->ClearStatusFlag(kIsSubCollection);
0f1882a7 792
793 return iResult;
794}
b005ef92 795
796int AliHLTOUT::Reset()
797{
798 // see header file for class documentation
799 int iResult=0;
800 AliHLTOUTPVector subCollections;
801 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
802 while (block!=fBlockDescList.end()) {
d4a18597 803 if (!((*block)==this)) {
b005ef92 804 AliHLTOUTPVector::iterator collection=subCollections.begin();
805 for (; collection!=subCollections.end(); collection++)
806 if((*block)==*collection) break;
807 if (collection==subCollections.end())
808 subCollections.push_back(block->GetCollection());
809 }
810 block=fBlockDescList.erase(block);
811 }
812
813 for (AliHLTOUTPVector::iterator collection=subCollections.begin();
4562bf66 814 collection!=subCollections.end(); collection++) {
b005ef92 815 (*collection)->Reset();
4562bf66 816 (*collection)->ClearStatusFlag(kIsSubCollection);
817 }
b005ef92 818
819 ResetInput();
820
821 return iResult;
822}
823
824int AliHLTOUT::ResetInput()
825{
826 // default implementation, nothing to do
827 return 0;
828}
f3c1d403 829
830const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTBlockDescriptor::GetHandlerDesc()
831{
832 // see header file for class documentation
833 if (fpCollection) {
834 AliHLTOUTHandlerListEntryVector::iterator element=fpCollection->fDataHandlers.begin();
835 while (element!=fpCollection->fDataHandlers.end()) {
836 if (element->HasIndex(GetIndex())) {
837 return *element;
838 }
839 element++;
840 }
841 }
842 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
843}
e5701dcf 844
845TObject* AliHLTOUT::GetDataObject()
846{
847 // see header file for class documentation
848 if (fpDataObject) {
849 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak");
850 ReleaseDataBuffer(fpObjectBuffer);
851 }
852 fpObjectBuffer=NULL;
853 fObjectBufferSize=0;
854 fpDataObject=NULL;
855
856 if (GetDataBuffer(fpObjectBuffer, fObjectBufferSize)>=0) {
857 fpDataObject=AliHLTMessage::Extract(fpObjectBuffer, fObjectBufferSize);
858 } else {
859 fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "can not fetch data buffer");
860 }
861
862 return fpDataObject;
863}
864
865int AliHLTOUT::ReleaseDataObject(TObject* pObject)
866{
867 // see header file for class documentation
868 if (!pObject) return -EINVAL;
869 if (pObject!=fpDataObject) {
870 fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "attempt to release wrong data object %p, expected %p", pObject, fpDataObject);
871 return -EINVAL;
872 }
873
874 delete fpDataObject;
875 fpDataObject=NULL;
876 ReleaseDataBuffer(fpObjectBuffer);
877 fpObjectBuffer=NULL;
878 fObjectBufferSize=0;
879
880 return 0;
881}