3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTOUTTask.cxx
20 @author Matthias Richter
22 @brief A special HLTOUT sibling working as a data sink in chains
25 #include "AliHLTOUTTask.h"
27 /** ROOT macro for the implementation of ROOT specific class methods */
28 ClassImp(AliHLTOUTTask)
30 AliHLTOUTTask::AliHLTOUTTask(const char* chains)
35 fpDummyConfiguration(NULL),
38 // see header file for class documentation
40 // refer to README to build package
42 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
43 TString taskname=chains;
44 taskname.ReplaceAll(" ", "_");
45 taskname+="_hltouttask";
47 // This is just a trick to use the existing Task handling, especially the
48 // ProcessTask function.
49 // 1. The 'BlockFilter' just forwards the data blocks of all specified chains
50 // 2. A dummy task is added to the target list in order to set the data segments
51 // after forwarding. In case of an empty target list the data is just discarded.
52 // That's maybe not the most elegant solution but far less awkward as one would
54 fpConfiguration=new AliHLTConfiguration(taskname.Data(), "BlockFilter", chains, NULL);
55 TString dummyname=chains;
56 dummyname.ReplaceAll(" ", "_");
57 dummyname+="_never_used_dummy_";
58 fpDummyConfiguration=new AliHLTConfiguration(dummyname.Data(), "BlockFilter", taskname.Data(), NULL);
59 if (fpDummyConfiguration) {
60 fpDummyTask=new AliHLTTask(fpDummyConfiguration);
61 SetTarget(fpDummyTask);
65 AliHLTOUTTask::~AliHLTOUTTask()
67 // see header file for class documentation
69 // UnsetTarget called automatically
70 if (fpDummyTask) delete fpDummyTask;
73 if (fpDummyConfiguration) delete fpDummyConfiguration;
74 fpDummyConfiguration=NULL;
76 if (fpConfiguration) delete fpConfiguration;
80 int AliHLTOUTTask::CustomInit(AliHLTComponentHandler* pCH)
82 // see header file for class documentation
83 if (!fpDummyTask) return -ENOENT;
84 return fpDummyTask->Init(NULL, pCH);
87 int AliHLTOUTTask::CustomCleanup()
89 // see header file for class documentation
90 if (!fpDummyTask) return -ENOENT;
91 return fpDummyTask->Deinit();
94 int AliHLTOUTTask::GenerateIndex()
96 // see header file for class documentation
99 if (!fpDataBuffer->FindConsumer(fpDummyTask->GetComponent())) {
100 // in order to subscribe to the buffers the dummy consumer
101 // needs to be set. The dummy task is not in the AliHLTSystem chain
102 // and therefor not automatically set.
103 fpDataBuffer->SetConsumer(fpDummyTask->GetComponent());
105 fBlockDescList.clear();
106 if (fpDataBuffer->GetNofSegments()>0) {
107 if ((iResult=fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlockDescList))>=0) {
108 for (unsigned int i=0; i<fBlockDescList.size(); i++) {
109 AliHLTOUTBlockDescriptor desc(fBlockDescList[i].fDataType, fBlockDescList[i].fSpecification, i, this);
110 //HLTDebug("adding block %d: %s %#x", i, AliHLTComponent::DataType2Text(fBlockDescList[i].fDataType).c_str(), fBlockDescList[i].fSpecification);
111 iResult=AddBlockDescriptor(desc);
114 HLTError("failed to subscribe to data buffer");
118 HLTWarning("no data buffer available");
123 int AliHLTOUTTask::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
124 AliHLTUInt32_t& size)
126 // see header file for class documentation
128 if (index>=fBlockDescList.size()) return -ENOENT;
129 pBuffer=reinterpret_cast<AliHLTUInt8_t*>(fBlockDescList[index].fPtr);
130 size=fBlockDescList[index].fSize;
134 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUTTask::CheckBlockByteOrder(AliHLTUInt32_t /*index*/)
136 // see header file for class documentation
137 return kInvalidByteOrder;
140 int AliHLTOUTTask::CheckBlockAlignment(AliHLTUInt32_t /*index*/, AliHLTOUT::AliHLTOUTDataType /*type*/)
142 // see header file for class documentation
147 int AliHLTOUTTask::ResetInput()
149 // see header file for class documentation
151 if (!fpDataBuffer) return 0;
153 if (fBlockDescList.size()==0 && fpDataBuffer->GetNofPendingConsumers()>0) {
154 // not yet subscribed
155 fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlockDescList);
158 for (unsigned int i=0; i<fBlockDescList.size(); i++) {
159 fpDataBuffer->Release(&(fBlockDescList[i]), fpDummyTask->GetComponent(), this);
161 fBlockDescList.clear();