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