Line data Source code
1 : // $Id$
2 :
3 : //**************************************************************************
4 : //* This file is property of and copyright by the *
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 AliHLTControlTask.cxx
20 : /// @author Matthias Richter
21 : /// @date
22 : /// @brief Special task to produce the control events.
23 : ///
24 :
25 : #include "AliHLTControlTask.h"
26 : #include "AliHLTComponentHandler.h"
27 : #include <cassert>
28 :
29 : /** ROOT macro for the implementation of ROOT specific class methods */
30 126 : ClassImp(AliHLTControlTask)
31 :
32 : AliHLTControlTask::AliHLTControlTask()
33 0 : : AliHLTTask()
34 0 : , fBlocks()
35 0 : , fpData(NULL)
36 0 : , fSize(0)
37 0 : {
38 : // constructor
39 : //
40 : // This task is automatically added to the beginning of each chain and
41 : // produces the special steering events. The first component in every
42 : // branch get the special events from the task.
43 0 : }
44 :
45 0 : AliHLTControlTask::~AliHLTControlTask()
46 0 : {
47 : // destructor
48 0 : ResetBlocks();
49 0 : }
50 :
51 : int AliHLTControlTask::CreateComponent(AliHLTConfiguration* /*pConf*/, AliHLTComponentHandler* pCH, AliHLTComponent*& pComponent) const
52 : {
53 : // create component
54 : int iResult=0;
55 0 : if ((pComponent=new AliHLTControlEventComponent(this))) {
56 0 : const AliHLTAnalysisEnvironment* pEnv=pCH->GetEnvironment();
57 0 : const char* argv[]={
58 : "-disable-component-stat"
59 : };
60 : int argc=sizeof(argv)/sizeof(const char*);
61 0 : if ((iResult=pComponent->Init(pEnv, NULL, argc, argv))>=0) {
62 : //HLTDebug("component %s (%p) created", pComponent->GetComponentID(), pComponent);
63 : } else {
64 0 : HLTError("Initialization of component \"%s\" failed with error %d", pComponent->GetComponentID(), iResult);
65 : }
66 : return iResult;
67 0 : }
68 0 : return -ENOMEM;
69 0 : }
70 :
71 : void AliHLTControlTask::SetBlocks(const AliHLTComponentBlockDataList& list)
72 : {
73 : // see header file for class documentation
74 0 : fBlocks.assign(list.begin(), list.end());
75 0 : AliHLTComponentBlockDataList::iterator element=fBlocks.begin();
76 0 : for (;element!=fBlocks.end(); element++) fSize+=element->fSize;
77 :
78 : // allocate buffer for the payload of all blocks
79 0 : fpData=new AliHLTUInt8_t[fSize];
80 : AliHLTUInt8_t offset=0;
81 :
82 : // copy and redirect
83 0 : for (element=fBlocks.begin();element!=fBlocks.end(); element++) {
84 0 : memcpy(fpData+offset, element->fPtr, element->fSize);
85 0 : element->fPtr=fpData+offset;
86 0 : offset+=element->fSize;
87 : }
88 0 : }
89 :
90 : void AliHLTControlTask::ResetBlocks()
91 : {
92 : // see header file for class documentation
93 0 : fBlocks.clear();
94 0 : if (fpData) delete [] fpData;
95 0 : fpData=NULL;
96 0 : fSize=0;
97 0 : }
98 :
99 0 : AliHLTControlTask::AliHLTControlEventComponent::AliHLTControlEventComponent(const AliHLTControlTask* pParent)
100 : :
101 0 : fpParent(pParent)
102 0 : {
103 : // see header file for class documentation
104 0 : assert(pParent);
105 0 : }
106 :
107 : AliHLTControlTask::AliHLTControlEventComponent::~AliHLTControlEventComponent()
108 0 : {
109 : // see header file for class documentation
110 0 : }
111 :
112 : AliHLTComponentDataType AliHLTControlTask::AliHLTControlEventComponent::GetOutputDataType()
113 : {
114 : // see header file for class documentation
115 0 : return kAliHLTMultipleDataType;
116 : }
117 :
118 : int AliHLTControlTask::AliHLTControlEventComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
119 : {
120 : // see header file for class documentation
121 0 : tgtList.clear();
122 0 : tgtList.push_back(kAliHLTDataTypeSOR);
123 0 : tgtList.push_back(kAliHLTDataTypeEOR);
124 0 : return tgtList.size();
125 : }
126 :
127 : void AliHLTControlTask::AliHLTControlEventComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
128 : {
129 : // see header file for class documentation
130 0 : if (fpParent && fpParent->fSize>0) constBase=fpParent->fSize;
131 0 : else constBase=0;
132 0 : inputMultiplier=0;
133 0 : }
134 :
135 : int AliHLTControlTask::AliHLTControlEventComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
136 : AliHLTComponentTriggerData& /*trigData*/,
137 : AliHLTUInt8_t* outputPtr,
138 : AliHLTUInt32_t& size,
139 : vector<AliHLTComponentBlockData>& outputBlocks )
140 : {
141 : // see header file for class documentation
142 0 : if (!fpParent) return -ENODEV;
143 : const AliHLTControlTask* pParent=fpParent;
144 :
145 0 : AliHLTUInt32_t capacity=size;
146 0 : size=0;
147 0 : if (capacity<pParent->fSize) {
148 0 : return -ENOSPC;
149 : }
150 :
151 : // return if no event has been set
152 0 : if (pParent->fpData==NULL ||
153 0 : pParent->fBlocks.size()==0) {
154 : //HLTInfo("no control event to send");
155 0 : return 0;
156 : }
157 :
158 0 : for (unsigned int i=0; i<pParent->fBlocks.size(); i++) {
159 : HLTDebug("publishing control block %s", DataType2Text(pParent->fBlocks[i].fDataType).c_str());
160 0 : memcpy(outputPtr+size, pParent->fBlocks[i].fPtr, pParent->fBlocks[i].fSize);
161 0 : AliHLTComponentBlockData bd;
162 0 : FillBlockData(bd);
163 0 : bd.fOffset=size;
164 0 : bd.fSize=pParent->fBlocks[i].fSize;
165 0 : bd.fDataType=pParent->fBlocks[i].fDataType;
166 0 : bd.fSpecification=pParent->fBlocks[i].fSpecification;
167 0 : outputBlocks.push_back( bd );
168 0 : size+=bd.fSize;
169 0 : }
170 :
171 0 : return size;
172 0 : }
|