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