]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTOUTTask.cxx
b7e33efa4335661a17e7093ea2ead4e2abaea371
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUTTask.cxx
1 // $Id$
2
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 //**************************************************************************
18
19 /** @file   AliHLTOUTTask.cxx
20     @author Matthias Richter
21     @date   
22     @brief  A special HLTOUT sibling working as a data sink in chains
23 */
24
25 #include "AliHLTOUTTask.h"
26
27 /** ROOT macro for the implementation of ROOT specific class methods */
28 ClassImp(AliHLTOUTTask)
29
30 AliHLTOUTTask::AliHLTOUTTask(const char* chains)
31   :
32   AliHLTOUT(),
33   AliHLTTask(),
34   fpDummyTask(NULL),
35   fpDummyConfiguration(NULL),
36   fBlockDescList()
37
38   // see header file for class documentation
39   // or
40   // refer to README to build package
41   // or
42   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
43   TString taskname=chains;
44   taskname.ReplaceAll(" ", "_");
45   taskname+="_hltouttask";
46
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
53   // expect.
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);
62   }
63 }
64
65 AliHLTOUTTask::~AliHLTOUTTask()
66 {
67   // see header file for class documentation
68
69   // UnsetTarget called automatically
70   if (fpDummyTask) delete fpDummyTask;
71   fpDummyTask=NULL;
72
73   if (fpDummyConfiguration) delete fpDummyConfiguration;
74   fpDummyConfiguration=NULL;
75
76   if (fpConfiguration) delete fpConfiguration;
77   fpConfiguration=NULL;
78 }
79
80 int AliHLTOUTTask::CustomInit(AliHLTComponentHandler* pCH)
81 {
82   // see header file for class documentation
83   if (!fpDummyTask) return -ENOENT;
84   return fpDummyTask->Init(NULL, pCH);
85 }
86
87 int AliHLTOUTTask::CustomCleanup()
88 {
89   // see header file for class documentation
90   if (!fpDummyTask) return -ENOENT;
91   return fpDummyTask->Deinit();
92 }
93
94 int AliHLTOUTTask::GenerateIndex()
95 {
96   // see header file for class documentation
97   int iResult=0;
98   if (fpDataBuffer) {
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());
104     }
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);
112         }
113       } else {
114         HLTError("failed to subscribe to data buffer");
115       }
116     }
117   } else {
118     HLTWarning("no data buffer available");
119   }
120   return iResult;
121 }
122
123 int AliHLTOUTTask::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, 
124                                  AliHLTUInt32_t& size)
125 {
126   // see header file for class documentation
127   int iResult=0;
128   if (index>=fBlockDescList.size()) return -ENOENT;
129   pBuffer=reinterpret_cast<AliHLTUInt8_t*>(fBlockDescList[index].fPtr);
130   size=fBlockDescList[index].fSize;
131   return iResult;
132 }
133
134 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUTTask::CheckBlockByteOrder(AliHLTUInt32_t /*index*/)
135 {
136   // see header file for class documentation
137   return kInvalidByteOrder;
138 }
139
140 int AliHLTOUTTask::CheckBlockAlignment(AliHLTUInt32_t /*index*/, AliHLTOUT::AliHLTOUTDataType /*type*/)
141 {
142   // see header file for class documentation
143   int iResult=0;
144   return iResult;
145 }
146
147 int AliHLTOUTTask::ResetInput()
148 {
149   // see header file for class documentation
150   int iResult=0;
151   if (!fpDataBuffer) return 0;
152
153   if (fBlockDescList.size()==0 && fpDataBuffer->GetNofPendingConsumers()>0) {
154     // not yet subscribed
155     fpDataBuffer->Subscribe(fpDummyTask->GetComponent(), fBlockDescList);
156   }
157
158   for (unsigned int i=0; i<fBlockDescList.size(); i++) {
159     fpDataBuffer->Release(&(fBlockDescList[i]), fpDummyTask->GetComponent(), this);
160   }
161   fBlockDescList.clear();
162   return iResult;
163 }