added new PhosClusterEnergy trigger component (Svein)
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerAgent.cxx
CommitLineData
89858ccc 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 AliHLTTriggerAgent.cxx
20 @author Matthias Richter
21 @date
22 @brief Agent of the libAliHLTTrigger library
23*/
24
25#include <cassert>
26#include "AliHLTTriggerAgent.h"
18a9a5ad 27#include "AliHLTTriggerDecision.h"
28#include "AliHLTOUT.h"
29#include "AliHLTMessage.h"
30#include "AliESDEvent.h"
c86017ac 31#include "TObjString.h"
32#include "TObjArray.h"
18a9a5ad 33#include "TArrayC.h"
89858ccc 34
35// header files of library components
36#include "AliHLTEventSummaryProducerComponent.h"
37#include "AliHLTRunSummaryProducerComponent.h"
c86017ac 38#include "AliHLTTriggerBarrelMultiplicity.h"
39#include "AliHLTTriggerBarrelCosmic.h"
5d79eb88 40#include "AliHLTGlobalTriggerComponent.h"
765d85f8 41#include "AliHLTTriggerPhosClusterEnergy.h"
89858ccc 42
43/** global instance for agent registration */
44AliHLTTriggerAgent gAliHLTTriggerAgent;
45
46/** ROOT macro for the implementation of ROOT specific class methods */
47ClassImp(AliHLTTriggerAgent)
48
49AliHLTTriggerAgent::AliHLTTriggerAgent()
18a9a5ad 50 : AliHLTModuleAgent("Trigger")
51 , fTriggerDecisionHandler(NULL)
89858ccc 52{
53 // see header file for class documentation
54 // or
55 // refer to README to build package
56 // or
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58}
59
60AliHLTTriggerAgent::~AliHLTTriggerAgent()
61{
62 // see header file for class documentation
63}
64
65int AliHLTTriggerAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
66{
67 // see header file for class documentation
68 assert(pHandler);
69 if (!pHandler) return -EINVAL;
5d79eb88 70 pHandler->AddComponent(new AliHLTGlobalTriggerComponent);
c86017ac 71 pHandler->AddComponent(new AliHLTTriggerBarrelMultiplicity);
72 pHandler->AddComponent(new AliHLTTriggerBarrelCosmic);
765d85f8 73 pHandler->AddComponent(new AliHLTTriggerPhosClusterEnergy);
89858ccc 74 return 0;
75}
76
c86017ac 77int AliHLTTriggerAgent::CreateConfigurations(AliHLTConfigurationHandler* pHandler,
78 AliRawReader* /*rawReader*/,
79 AliRunLoader* /*runloader*/) const
80{
81 // see header file for class documentation
82 if (!pHandler) return -EINVAL;
83
84 TString triggerInputs;
85 TString triggerOutputs;
86 TString configurationId;
87 /////////////////////////////////////////////////////////////////////////////////////
88 //
89 // a central barrel charged particle multiplicity trigger
90 configurationId="TRIGGER-Barrel-Multiplicity";
91
92 // define the inputsfor the BarrelMultiplicityTrigger
93 triggerInputs="GLOBAL-esd-converter";
94
95 // check for the availibility
96 TObjArray* pTokens=triggerInputs.Tokenize(" ");
97 triggerInputs="";
98 if (pTokens) {
99 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
100 TString module=((TObjString*)pTokens->At(n))->GetString();
101 if (pHandler->FindConfiguration(module.Data())) {
102 triggerInputs+=module;
103 triggerInputs+=" ";
104 }
105 }
106 delete pTokens;
107 }
108
109 if (triggerInputs.Length()>0) {
110 HLTInfo("Configuring inputs for %s: %s", configurationId.Data(), triggerInputs.Data());
111 pHandler->CreateConfiguration(configurationId.Data(), "BarrelMultiplicityTrigger", triggerInputs.Data(), "");
112 if (triggerOutputs.Length()>0) triggerOutputs+=" ";
113 triggerOutputs+=configurationId;
114 } else {
115 HLTWarning("No inputs for %s found, skipping component", configurationId.Data());
116 }
117
118 /////////////////////////////////////////////////////////////////////////////////////
119 //
120 // the global trigger component
121 configurationId="GLOBAL-Trigger";
122 HLTInfo("setting inputs for %s: %s", configurationId.Data(), triggerOutputs.IsNull()?"none":triggerOutputs.Data());
123 pHandler->CreateConfiguration(configurationId.Data(), "HLTGlobalTrigger", triggerOutputs.Data(), "");
124
125 return 0;
126}
127
128const char* AliHLTTriggerAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
129 AliRunLoader* runloader) const
130{
131 // see header file for class documentation
132 if (runloader) {
133 // reconstruction chains for AliRoot simulation
134 // Note: run loader is only available while running embedded into
135 // AliRoot simulation
136
137 // currently disabled due to a problem compiling the runtime trigger library
18a9a5ad 138 return "GLOBAL-Trigger";
c86017ac 139 }
140 return NULL;
141}
142
143const char* AliHLTTriggerAgent::GetRequiredComponentLibraries() const
144{
145 // see header file for class documentation
146
147 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so libAliHLTITS.so libAliHLTGlobal.so";
148}
149
89858ccc 150int AliHLTTriggerAgent::GetHandlerDescription(AliHLTComponentDataType dt,
151 AliHLTUInt32_t /*spec*/,
152 AliHLTOUTHandlerDesc& desc) const
153{
154 // see header file for class documentation
155
18a9a5ad 156 // handler of the trigger decisions {'ROOTTOBJ':'HLT '}
157 // currently stored as a TObject with the common data type and origin
158 // HLTOUT. However we might need a separate data type in order to
159 // avoid interference with other handlers
160 // the handler produces an ESD object in order to be merged to the
161 // hltEsd afterwards
162 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
163 desc=AliHLTOUTHandlerDesc(AliHLTModuleAgent::kEsd, dt, GetModuleId());
164 return 1;
165 }
166
89858ccc 167 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
168 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
169 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
170 desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
171 return 1;
172 }
173
174 return 0;
175}
176
177AliHLTOUTHandler* AliHLTTriggerAgent::GetOutputHandler(AliHLTComponentDataType dt,
18a9a5ad 178 AliHLTUInt32_t /*spec*/)
89858ccc 179{
180 // see header file for class documentation
181
18a9a5ad 182 // raw data blocks to be fed into offline reconstruction
183 if (dt==(kAliHLTDataTypeTObject|kAliHLTDataOriginOut)) {
184 if (!fTriggerDecisionHandler) {
185 fTriggerDecisionHandler=new AliHLTTriggerAgent::AliHLTTriggerDecisionHandler;
186 }
187 return fTriggerDecisionHandler;
188 }
189
89858ccc 190 // handler for the HLT readou list and trigger data data blocks {'HLTRDLST':'HLT '}
191 if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
192 dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
193 return NULL;
194 }
195
196 return NULL;
197}
198
199int AliHLTTriggerAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
200{
201 // see header file for class documentation
202 if (pInstance==NULL) return -EINVAL;
203
18a9a5ad 204 if (pInstance==fTriggerDecisionHandler) {
205 delete fTriggerDecisionHandler;
206 fTriggerDecisionHandler=NULL;
207 }
208
89858ccc 209 return 0;
210}
18a9a5ad 211
212AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::AliHLTTriggerDecisionHandler()
213 : AliHLTOUTHandler()
214 , fESD(NULL)
215 , fpData(NULL)
216 , fSize(0)
217{
218 // see header file for class documentation
219}
220
221AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::~AliHLTTriggerDecisionHandler()
222{
223 // see header file for class documentation
224 if (fESD) delete fESD;
225 fESD=NULL;
226
227 if (fpData) delete fpData;
228 fpData=NULL;
229 fSize=0;
230}
231
232int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ProcessData(AliHLTOUT* pData)
233{
234 // see header file for class documentation
235 if (!pData) return -EINVAL;
e13512e4 236 pData->SelectFirstDataBlock();
18a9a5ad 237 AliHLTComponentDataType dt=kAliHLTVoidDataType;
238 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
239 int iResult=pData->GetDataBlockDescription(dt, spec);
240 if (iResult>=0) {
241 TObject* pObject=pData->GetDataObject();
242 if (pObject) {
30d84601 243 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(pObject);
244 if (pDecision) {
e13512e4 245 //pDecision->Print();
30d84601 246 HLTDebug("extracted %s", pDecision->GetName());
18a9a5ad 247 if (!fESD) {
248 // create the ESD container, but without std content
249 fESD = new AliESDEvent;
250 }
251 if (!fpData) fpData=new TArrayC;
252 if (fESD && fpData) {
253 fESD->Reset();
30d84601 254 TObject* pESDObject=fESD->FindListObject("HLTGlobalTrigger");
255 if (pESDObject) {
256 // copy the content to the already existing object
257 pObject->Copy(*pESDObject);
258 } else {
259 // add a new object
260 fESD->AddObject(pObject->Clone());
261 }
18a9a5ad 262 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
263 if (pMsg) {
264 if (!pMsg->CompBuffer()) {
265 fSize=pMsg->Length();
266 fpData->Set(fSize, pMsg->Buffer());
267 } else {
268 fSize=pMsg->CompLength();
269 fpData->Set(fSize, pMsg->CompBuffer());
270 }
271 } else {
272 HLTError("streaming of objects failed");
273 }
274 } else {
275 HLTError("memory allocation failed");
276 iResult=-ENOMEM;
277 }
278 } else {
279 HLTError("object %s is not an AliHLTTriggerDecision", pObject->GetName());
280 iResult=-ENODATA;
281 }
282 pData->ReleaseDataObject(pObject);
283 pObject=NULL;
284 } else {
285 HLTError("can not get TObject from HLTOUT buffer");
286 iResult=-ENODATA;
287 }
288 }
e13512e4 289 if (iResult>=0) {
290 if (pData->SelectNextDataBlock()>=0) {
291 HLTWarning("current implementation of trigger decision handler can only handle one block");
292 }
293 return fSize;
294 }
18a9a5ad 295 fSize=0;
296 return iResult;
297}
298
299int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::GetProcessedData(const AliHLTUInt8_t* &pData)
300{
301 // see header file for class documentation
302 if (!fpData) {
303 pData=NULL;
304 return 0;
305 }
306
307 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
308 return fSize;
309}
310
311int AliHLTTriggerAgent::AliHLTTriggerDecisionHandler::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
312{
313 // see header file for class documentation
314 int iResult=0;
315 if (!fpData || size != fSize ||
316 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
317 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);
318 }
319 fSize=0;
320 return iResult;
321}