]>
Commit | Line | Data |
---|---|---|
afad6dde | 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 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 | ClassImp(AliHLTControlTask) | |
31 | ||
32 | AliHLTControlTask::AliHLTControlTask() | |
3baf1595 | 33 | : AliHLTTask() |
34 | , fBlocks() | |
35 | , fpData(NULL) | |
36 | , fSize(0) | |
afad6dde | 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 | } | |
44 | ||
45 | AliHLTControlTask::~AliHLTControlTask() | |
46 | { | |
47 | // see header file for class documentation | |
3baf1595 | 48 | ResetBlocks(); |
afad6dde | 49 | } |
50 | ||
51 | int AliHLTControlTask::CreateComponent(AliHLTConfiguration* /*pConf*/, AliHLTComponentHandler* pCH, AliHLTComponent*& pComponent) const | |
52 | { | |
53 | // see header file for class documentation | |
54 | int iResult=0; | |
55 | if ((pComponent=new AliHLTControlEventComponent(this))) { | |
56 | const AliHLTAnalysisEnvironment* pEnv=pCH->GetEnvironment(); | |
57 | if ((iResult=pComponent->Init(pEnv, NULL, 0, NULL))>=0) { | |
58 | //HLTDebug("component %s (%p) created", pComponent->GetComponentID(), pComponent); | |
59 | } else { | |
60 | HLTError("Initialization of component \"%s\" failed with error %d", pComponent->GetComponentID(), iResult); | |
61 | } | |
62 | return iResult; | |
63 | } | |
64 | return -ENOMEM; | |
65 | } | |
66 | ||
3baf1595 | 67 | void AliHLTControlTask::SetBlocks(const AliHLTComponentBlockDataList& list) |
68 | { | |
69 | // see header file for class documentation | |
70 | fBlocks.assign(list.begin(), list.end()); | |
71 | AliHLTComponentBlockDataList::iterator element=fBlocks.begin(); | |
72 | for (;element!=fBlocks.end(); element++) fSize+=element->fSize; | |
73 | ||
74 | // allocate buffer for the payload of all blocks | |
75 | fpData=new AliHLTUInt8_t[fSize]; | |
76 | AliHLTUInt8_t offset=0; | |
77 | ||
78 | // copy and redirect | |
79 | for (element=fBlocks.begin();element!=fBlocks.end(); element++) { | |
80 | memcpy(fpData+offset, element->fPtr, element->fSize); | |
81 | element->fPtr=fpData+offset; | |
82 | offset+=element->fSize; | |
83 | } | |
84 | } | |
85 | ||
86 | void AliHLTControlTask::ResetBlocks() | |
87 | { | |
88 | // see header file for class documentation | |
89 | fBlocks.clear(); | |
90 | if (fpData) delete [] fpData; | |
91 | fpData=NULL; | |
92 | fSize=0; | |
93 | } | |
94 | ||
afad6dde | 95 | AliHLTControlTask::AliHLTControlEventComponent::AliHLTControlEventComponent(const AliHLTControlTask* pParent) |
96 | : | |
97 | fpParent(pParent) | |
98 | { | |
99 | // see header file for class documentation | |
100 | assert(pParent); | |
101 | } | |
102 | ||
103 | AliHLTControlTask::AliHLTControlEventComponent::~AliHLTControlEventComponent() | |
104 | { | |
105 | // see header file for class documentation | |
106 | } | |
107 | ||
108 | AliHLTComponentDataType AliHLTControlTask::AliHLTControlEventComponent::GetOutputDataType() | |
109 | { | |
110 | // see header file for class documentation | |
111 | return kAliHLTMultipleDataType; | |
112 | } | |
113 | ||
114 | int AliHLTControlTask::AliHLTControlEventComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) | |
115 | { | |
116 | // see header file for class documentation | |
117 | tgtList.clear(); | |
118 | tgtList.push_back(kAliHLTDataTypeSOR); | |
119 | tgtList.push_back(kAliHLTDataTypeEOR); | |
120 | return tgtList.size(); | |
121 | } | |
122 | ||
123 | void AliHLTControlTask::AliHLTControlEventComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
124 | { | |
125 | // see header file for class documentation | |
126 | if (fpParent && fpParent->fSize>0) constBase=fpParent->fSize; | |
3baf1595 | 127 | else constBase=0; |
afad6dde | 128 | inputMultiplier=0; |
129 | } | |
130 | ||
131 | int AliHLTControlTask::AliHLTControlEventComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/, | |
132 | AliHLTComponentTriggerData& /*trigData*/, | |
133 | AliHLTUInt8_t* outputPtr, | |
134 | AliHLTUInt32_t& size, | |
135 | vector<AliHLTComponentBlockData>& outputBlocks ) | |
136 | { | |
137 | // see header file for class documentation | |
138 | if (!fpParent) return -ENODEV; | |
139 | const AliHLTControlTask* pParent=fpParent; | |
afad6dde | 140 | // return if no event has been set |
3baf1595 | 141 | if (pParent->fpData==NULL || |
142 | pParent->fBlocks.size()==0) { | |
a472be38 | 143 | //HLTInfo("no control event to send"); |
afad6dde | 144 | return 0; |
145 | } | |
146 | ||
3baf1595 | 147 | AliHLTUInt32_t capacity=size; |
148 | size=0; | |
149 | if (capacity<pParent->fSize) { | |
150 | return -ENOSPC; | |
151 | } | |
152 | ||
153 | for (unsigned int i=0; i<pParent->fBlocks.size(); i++) { | |
154 | HLTDebug("publishing control block %s", DataType2Text(pParent->fBlocks[i].fDataType).c_str()); | |
155 | memcpy(outputPtr+size, pParent->fBlocks[i].fPtr, pParent->fBlocks[i].fSize); | |
156 | AliHLTComponentBlockData bd; | |
157 | FillBlockData(bd); | |
158 | bd.fOffset=size; | |
159 | bd.fSize=pParent->fBlocks[i].fSize; | |
160 | bd.fDataType=pParent->fBlocks[i].fDataType; | |
161 | bd.fSpecification=pParent->fBlocks[i].fSpecification; | |
162 | outputBlocks.push_back( bd ); | |
163 | size+=bd.fSize; | |
164 | } | |
afad6dde | 165 | |
3baf1595 | 166 | return size; |
afad6dde | 167 | } |